1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

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
* 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; }
Inode* inode = SafeGetInode(fs, msg->ino);
if ( !inode ) { RespondError(chl, errno); return; }
inode->SetUserId((uint32_t) msg->uid);
inode->SetGroupId((uint32_t) msg->gid);
if ( msg->uid != (uid_t) -1 )
inode->SetUserId((uint32_t) msg->uid);
if ( msg->gid != (gid_t) -1 )
inode->SetGroupId((uint32_t) msg->gid);
inode->Unref();
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
* 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)
{
ScopedLock lock(&metalock);
stat_uid = owner;
stat_gid= group;
if ( owner != (uid_t) -1 )
stat_uid = owner;
if ( group != (gid_t) -1 )
stat_gid = group;
return 0;
}