This is the mail archive of the cygwin-cvs@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[newlib-cygwin/cygwin-2.0] Introduce sidfromuid and sidfromgid


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=853fcd8936b5ffdc465e4ce31af51b8ae223d247

commit 853fcd8936b5ffdc465e4ce31af51b8ae223d247
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Apr 8 11:00:08 2015 +0200

    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>

Diff:
---
 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 659f568..aa60192 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,12 @@
 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...
 	* sec_acl.cc: ...to here.
 
diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 6a42567..f5edb03 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 dc718c5..a64cb0f 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 96c6134..f4c325b 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;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]