diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d6e94f0c5..bd9e71ffa 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,19 @@ +2015-03-18 Corinna Vinschen + + * grp.cc (pwdgrp::parse_group): Call cygsid::getfromgr_passwd. + * passwd.cc (pwdgrp::parse_passwd): Call cygsid::getfrompw_gecos. + * pwdgrp.h (cygsid::getfrompw): Implement as inline method here, + accessing pg_pwd's sid member directly. + (cygsid::getfromgr): Implement as inline method here, accessing + pg_grp's sid member directly. + * sec_auth.cc (extract_nt_dom_user): Call cygsid::getfrompw_gecos. + Explain why. + * sec_helper.cc (cygsid::getfrompw): Drop implementation. + (cygsid::getfromgr): Ditto. + * security.h (cygsid::getfrompw_gecos): Implement former getfrompw + inline here. + (cygsid::getfromgr_passwd): Implement former getfromgr inline here. + 2015-03-18 Corinna Vinschen * sec_auth.cc (get_server_groups): Drop unused passwd argument. Adjust diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 53551161a..ea20e926c 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -47,7 +47,7 @@ pwdgrp::parse_group () return false; /* Don't generate gr_mem entries. */ grp.g.gr_mem = &null_ptr; - grp.sid.getfromgr (&grp.g); + grp.sid.getfromgr_passwd (&grp.g); return true; } diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index 825b2e0a8..7493aa443 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -40,7 +40,7 @@ pwdgrp::parse_passwd () res.p.pw_gecos = next_str (':'); res.p.pw_dir = next_str (':'); res.p.pw_shell = next_str (':'); - res.sid.getfrompw (&res.p); + res.sid.getfrompw_gecos (&res.p); /* lptr points to the \0 after pw_shell. Increment by one to get the correct required buffer len in getpw_cp. */ res.len = lptr - res.p.pw_name + 1; diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h index 8a78d305f..dc718c596 100644 --- a/winsup/cygwin/pwdgrp.h +++ b/winsup/cygwin/pwdgrp.h @@ -246,3 +246,11 @@ public: struct group *getgrent (); inline void endgrent () { endent (true); } }; + +/* These inline methods have to be defined here so that pg_pwd and pg_grp + are defined. */ +inline BOOL cygsid::getfrompw (const struct passwd *pw) + { return (*this = pw ? (PSID) ((pg_pwd *) pw)->sid : NO_SID) != NO_SID; } + +inline BOOL cygsid::getfromgr (const struct group *gr) + { return (*this = gr ? (PSID) ((pg_grp *) gr)->sid : NO_SID) != NO_SID; } diff --git a/winsup/cygwin/sec_auth.cc b/winsup/cygwin/sec_auth.cc index aeb571de6..d5fa76def 100644 --- a/winsup/cygwin/sec_auth.cc +++ b/winsup/cygwin/sec_auth.cc @@ -119,7 +119,10 @@ extract_nt_dom_user (const struct passwd *pw, PWCHAR domain, PWCHAR user) debug_printf ("pw_gecos %p (%s)", pw->pw_gecos, pw->pw_gecos); - if (psid.getfrompw (pw) + /* The incoming passwd entry is not necessarily a pointer to the + internal passwd buffers, thus we must not rely on being able to + cast it to pg_pwd. */ + if (psid.getfrompw_gecos (pw) && LookupAccountSidW (NULL, psid, user, &ulen, domain, &dlen, &use)) return; diff --git a/winsup/cygwin/sec_helper.cc b/winsup/cygwin/sec_helper.cc index 946e78a8e..679f3a858 100644 --- a/winsup/cygwin/sec_helper.cc +++ b/winsup/cygwin/sec_helper.cc @@ -1,7 +1,7 @@ /* sec_helper.cc: NT security helper functions Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, - 2011, 2012, 2013, 2014 Red Hat, Inc. + 2011, 2012, 2013, 2014, 2015 Red Hat, Inc. Written by Corinna Vinschen @@ -279,20 +279,6 @@ cygsid::getfromstr (const char *nsidstr, bool well_known) return psid = NO_SID; } -BOOL -cygsid::getfrompw (const struct passwd *pw) -{ - char *sp = (pw && pw->pw_gecos) ? strrchr (pw->pw_gecos, ',') : NULL; - return (*this = sp ? sp + 1 : sp) != NULL; -} - -BOOL -cygsid::getfromgr (const struct group *gr) -{ - char *sp = (gr && gr->gr_passwd) ? gr->gr_passwd : NULL; - return (*this = sp) != NULL; -} - cygsid * cygsidlist::alloc_sids (int n) { diff --git a/winsup/cygwin/security.h b/winsup/cygwin/security.h index 6af87e0d4..867345774 100644 --- a/winsup/cygwin/security.h +++ b/winsup/cygwin/security.h @@ -237,6 +237,18 @@ public: inline PSID set () { return psid = (PSID) sbuf; } + inline BOOL getfrompw_gecos (const struct passwd *pw) + { + char *sp = (pw && pw->pw_gecos) ? strrchr (pw->pw_gecos, ',') : NULL; + return (*this = sp ? sp + 1 : sp) != NO_SID; + } + inline BOOL getfromgr_passwd (const struct group *gr) + { + char *sp = (gr && gr->gr_passwd) ? gr->gr_passwd : NULL; + return (*this = sp) != NO_SID; + } + + /* Implemented in pwdgrp.h. */ BOOL getfrompw (const struct passwd *pw); BOOL getfromgr (const struct group *gr);