Introduce sidfromuid and sidfromgid

* pwdgrp.h (sidfromuid): New inline function.
	(sidfromgid): Ditto.
	* fhandler_disk_file.cc (fhandler_disk_file::fchown): Use sidfromuid.
	* quotactl.cc (quotactl): Use sidfromuid and sidfromgid.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2015-04-08 11:00:08 +02:00
parent 651bb62ae2
commit 853fcd8936
4 changed files with 30 additions and 14 deletions

View File

@ -1,3 +1,10 @@
2015-04-08 Corinna Vinschen <corinna@vinschen.de>
* pwdgrp.h (sidfromuid): New inline function.
(sidfromgid): Ditto.
* fhandler_disk_file.cc (fhandler_disk_file::fchown): Use sidfromuid.
* quotactl.cc (quotactl): Use sidfromuid and sidfromgid.
2015-04-08 Corinna Vinschen <corinna@vinschen.de>
* include/cyggwin/acl.h (struct __acl16): Move from here...

View File

@ -989,10 +989,10 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
the standard UNIX accounts, we're faking success. */
if (res == -1 && pc.fs_is_samba ())
{
cygsid sid;
PSID sid;
if (old_uid == ILLEGAL_UID
|| (sid.getfrompw (internal_getpwuid (old_uid))
|| ((sid = sidfromuid (old_uid, NULL)) != NO_SID
&& RtlEqualPrefixSid (sid,
well_known_samba_unix_user_fake_sid)))
{

View File

@ -254,3 +254,19 @@ inline BOOL cygsid::getfrompw (const struct passwd *pw)
inline BOOL cygsid::getfromgr (const struct group *gr)
{ return (*this = gr ? (PSID) ((pg_grp *) gr)->sid : NO_SID) != NO_SID; }
/* Use these functions if you just need the PSID. */
inline PSID sidfromuid (uid_t uid, cyg_ldap *pldap)
{
struct passwd *pw = internal_getpwuid (uid, pldap);
if (pw)
return (PSID) ((pg_pwd *) pw)->sid;
return NO_SID;
}
inline PSID sidfromgid (gid_t gid, cyg_ldap *pldap)
{
struct group *gr = internal_getgrgid (gid, pldap);
if (gr)
return (PSID) ((pg_grp *) gr)->sid;
return NO_SID;
}

View File

@ -1,6 +1,6 @@
/* quotactl.cc: code for manipulating disk quotas
Copyright 2014 Red Hat, Inc.
Copyright 2014, 2015 Red Hat, Inc.
This file is part of Cygwin.
@ -28,7 +28,7 @@ extern "C" int
quotactl (int cmd, const char *special, int id, caddr_t addr)
{
ACCESS_MASK access = FILE_READ_DATA;
cygsid sid;
PSID sid = NO_SID;
path_conv pc;
tmp_pathbuf tp;
UNICODE_STRING path;
@ -75,18 +75,11 @@ quotactl (int cmd, const char *special, int id, caddr_t addr)
/* Windows feature: Default limits. Get or set them with id == -1. */
if (id != -1)
{
struct passwd *pw = NULL;
struct group *gr = NULL;
if (type == USRQUOTA)
pw = internal_getpwuid (id);
else
gr = internal_getgrgid (id);
if (pw)
sid.getfrompw (pw);
else if (gr)
sid.getfromgr (gr);
sid = sidfromuid (id, NULL);
else
sid = sidfromgid (id, NULL);
if (sid == NO_SID)
{
set_errno (EINVAL);
return -1;