From 853fcd8936b5ffdc465e4ce31af51b8ae223d247 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 8 Apr 2015 11:00:08 +0200 Subject: [PATCH] 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 --- winsup/cygwin/ChangeLog | 7 +++++++ winsup/cygwin/fhandler_disk_file.cc | 4 ++-- winsup/cygwin/pwdgrp.h | 16 ++++++++++++++++ winsup/cygwin/quotactl.cc | 17 +++++------------ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 659f56823..aa6019278 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,10 @@ +2015-04-08 Corinna Vinschen + + * 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 * include/cyggwin/acl.h (struct __acl16): Move from here... diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index 6a425674a..f5edb03de 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -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))) { diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h index dc718c596..a64cb0f5f 100644 --- a/winsup/cygwin/pwdgrp.h +++ b/winsup/cygwin/pwdgrp.h @@ -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; + } diff --git a/winsup/cygwin/quotactl.cc b/winsup/cygwin/quotactl.cc index 96c6134e8..f4c325bd5 100644 --- a/winsup/cygwin/quotactl.cc +++ b/winsup/cygwin/quotactl.cc @@ -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;