https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=4a9636b1d6d3380eaff53621498445f6adcfc18e
commit 4a9636b1d6d3380eaff53621498445f6adcfc18e Author: Corinna Vinschen <cori...@vinschen.de> Date: Wed Mar 18 17:15:27 2015 +0100 Implmenet faster getfrompw/getfromgr * 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. Signed-off-by: Corinna Vinschen <cori...@vinschen.de> Diff: --- winsup/cygwin/ChangeLog | 16 ++++++++++++++++ winsup/cygwin/grp.cc | 2 +- winsup/cygwin/passwd.cc | 2 +- winsup/cygwin/pwdgrp.h | 8 ++++++++ winsup/cygwin/sec_auth.cc | 5 ++++- winsup/cygwin/sec_helper.cc | 16 +--------------- winsup/cygwin/security.h | 12 ++++++++++++ 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index d6e94f0..bd9e71f 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,21 @@ 2015-03-18 Corinna Vinschen <cori...@vinschen.de> + * 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 <cori...@vinschen.de> + * sec_auth.cc (get_server_groups): Drop unused passwd argument. Adjust calls throughout. (get_initgroups_sidlist): Ditto. diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 5355116..ea20e92 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 825b2e0..7493aa4 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 8a78d30..dc718c5 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 aeb571d..d5fa76d 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 946e78a..679f3a8 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 <cori...@vinschen.de> @@ -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 6af87e0..8673457 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);