Fix chown(2) not supporting -1 to not set the owner and group.

This commit is contained in:
Jonas 'Sortie' Termansen 2022-01-15 20:42:43 +01:00
parent 432e5ddeaf
commit 23832546d5
2 changed files with 10 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2014, 2015, 2016 Jonas 'Sortie' Termansen. * Copyright (c) 2013, 2014, 2015, 2016, 2022 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -229,8 +229,10 @@ void HandleChangeOwner(int chl, struct fsm_req_chown* msg, Filesystem* fs)
if ( !fs->device->write ) { RespondError(chl, EROFS); return; } if ( !fs->device->write ) { RespondError(chl, EROFS); return; }
Inode* inode = SafeGetInode(fs, msg->ino); Inode* inode = SafeGetInode(fs, msg->ino);
if ( !inode ) { RespondError(chl, errno); return; } if ( !inode ) { RespondError(chl, errno); return; }
inode->SetUserId((uint32_t) msg->uid); if ( msg->uid != (uid_t) -1 )
inode->SetGroupId((uint32_t) msg->gid); inode->SetUserId((uint32_t) msg->uid);
if ( msg->gid != (gid_t) -1 )
inode->SetGroupId((uint32_t) msg->gid);
inode->Unref(); inode->Unref();
RespondSuccess(chl); RespondSuccess(chl);
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012-2017, 2021 Jonas 'Sortie' Termansen. * Copyright (c) 2012-2017, 2021, 2022 Jonas 'Sortie' Termansen.
* *
* Permission to use, copy, modify, and distribute this software for any * Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above * purpose with or without fee is hereby granted, provided that the above
@ -144,8 +144,10 @@ int AbstractInode::chmod(ioctx_t* /*ctx*/, mode_t mode)
int AbstractInode::chown(ioctx_t* /*ctx*/, uid_t owner, gid_t group) int AbstractInode::chown(ioctx_t* /*ctx*/, uid_t owner, gid_t group)
{ {
ScopedLock lock(&metalock); ScopedLock lock(&metalock);
stat_uid = owner; if ( owner != (uid_t) -1 )
stat_gid= group; stat_uid = owner;
if ( group != (gid_t) -1 )
stat_gid = group;
return 0; return 0;
} }