From: Corinna Vinschen Date: Wed, 12 Mar 2014 17:36:56 +0000 (+0000) Subject: * cygheap.h (enum cygheap_pwdgrp::cache_t): Remove. X-Git-Tag: sid-snapshot-20140501~43 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=29b7313d2225eb4468170b94f80acc473b06b7ea;p=newlib-cygwin.git * cygheap.h (enum cygheap_pwdgrp::cache_t): Remove. (cygheap_pwdgrp::caching): Convert to bool. (cygheap_pwdgrp::pwd_cache): Add cygserver member. (cygheap_pwdgrp::grp_cache): Ditto. (cygheap_pwdgrp::nss_db_caching): Drop. (cygheap_pwdgrp::nss_db_full_caching): Drop. (cygheap_pwdgrp::nss_cygserver_caching): New method. (cygheap_pwdgrp::nss_disable_cygserver_caching): New method. * cygserver.h (client_request::request_code_t): Add CYGSERVER_REQUEST_PWDGRP. * cygserver_pwdgrp.h: New file. * cygtls.h (struct _local_storage): Remove pwbuf and grbuf members. * grp.cc (pwdgrp::prep_tls_grbuf): Drop. (internal_getgrsid): Handle cygserver caching and rearrange to check the caches first. (internal_getgrnam): Ditto. (internal_getgrgid): Ditto. (gr_ent::enumerate_caches): Handle cygserver cache. * passwd.cc (pwdgrp::prep_tls_pwbuf): Drop. (internal_getpwsid): Handle cygserver caching and rearrange to check the caches first. (internal_getpwnam): Ditto. (internal_getpwuid): Ditto. (pw_ent::enumerate_caches): Handle cygserver cache. * pwdgrp.h (pwdgrp::add_account_from_cygserver): New method declaration. (pwdgrp::fetch_account_from_cygserver): New method declaration. (pwdgrp::prep_tls_pwbuf): Drop declaration. (pwdgrp::prep_tls_grbuf): Drop declaration. (pwdgrp::add_user_from_cygserver): New inline methods. (pwdgrp::add_group_from_cygserver): New inline methods. * tlsoffsets.h: Regenerate. * tlsoffsets64.h: Regenerate. * uinfo.cc (internal_getlogin): Call internal_getgroups if cygserver caching is not available. (cygheap_pwdgrp::init): Initialize pwd_cache.cygserver and grp_cache.cygserver. Set caching to true. (cygheap_pwdgrp::nss_init_line): Drop db_cache handling entirely. (pwdgrp::add_account_from_windows): Drop no caching handling. (client_request_pwdgrp::client_request_pwdgrp): New method. (pwdgrp::fetch_account_from_cygserver): New method. (pwdgrp::add_account_from_cygserver): New method. * fhandler_disk_file.cc (fhandler_base::fstat_helper): Fix formatting. * include/sys/cygwin.h: Ditto. --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 65c7328e7..6f71531b4 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,50 @@ +2014-03-12 Corinna Vinschen + + * cygheap.h (enum cygheap_pwdgrp::cache_t): Remove. + (cygheap_pwdgrp::caching): Convert to bool. + (cygheap_pwdgrp::pwd_cache): Add cygserver member. + (cygheap_pwdgrp::grp_cache): Ditto. + (cygheap_pwdgrp::nss_db_caching): Drop. + (cygheap_pwdgrp::nss_db_full_caching): Drop. + (cygheap_pwdgrp::nss_cygserver_caching): New method. + (cygheap_pwdgrp::nss_disable_cygserver_caching): New method. + * cygserver.h (client_request::request_code_t): Add + CYGSERVER_REQUEST_PWDGRP. + * cygserver_pwdgrp.h: New file. + * cygtls.h (struct _local_storage): Remove pwbuf and grbuf members. + * grp.cc (pwdgrp::prep_tls_grbuf): Drop. + (internal_getgrsid): Handle cygserver caching and rearrange to check + the caches first. + (internal_getgrnam): Ditto. + (internal_getgrgid): Ditto. + (gr_ent::enumerate_caches): Handle cygserver cache. + * passwd.cc (pwdgrp::prep_tls_pwbuf): Drop. + (internal_getpwsid): Handle cygserver caching and rearrange to check + the caches first. + (internal_getpwnam): Ditto. + (internal_getpwuid): Ditto. + (pw_ent::enumerate_caches): Handle cygserver cache. + * pwdgrp.h (pwdgrp::add_account_from_cygserver): New method declaration. + (pwdgrp::fetch_account_from_cygserver): New method declaration. + (pwdgrp::prep_tls_pwbuf): Drop declaration. + (pwdgrp::prep_tls_grbuf): Drop declaration. + (pwdgrp::add_user_from_cygserver): New inline methods. + (pwdgrp::add_group_from_cygserver): New inline methods. + * tlsoffsets.h: Regenerate. + * tlsoffsets64.h: Regenerate. + * uinfo.cc (internal_getlogin): Call internal_getgroups if cygserver + caching is not available. + (cygheap_pwdgrp::init): Initialize pwd_cache.cygserver and + grp_cache.cygserver. Set caching to true. + (cygheap_pwdgrp::nss_init_line): Drop db_cache handling entirely. + (pwdgrp::add_account_from_windows): Drop no caching handling. + (client_request_pwdgrp::client_request_pwdgrp): New method. + (pwdgrp::fetch_account_from_cygserver): New method. + (pwdgrp::add_account_from_cygserver): New method. + + * fhandler_disk_file.cc (fhandler_base::fstat_helper): Fix formatting. + * include/sys/cygwin.h: Ditto. + 2014-03-12 Corinna Vinschen * uinfo.cc (pwdgrp::fetch_account_from_windows): Avoid crash on diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h index 66603c0c7..c4b2ed9ad 100644 --- a/winsup/cygwin/cygheap.h +++ b/winsup/cygwin/cygheap.h @@ -400,17 +400,12 @@ class cygheap_pwdgrp NSS_PRIMARY, NSS_ALWAYS }; - enum cache_t { - NSS_NO_CACHING = 0, - NSS_CACHING, - NSS_FULL_CACHING - }; bool nss_inited; int pwd_src; int grp_src; pfx_t prefix; WCHAR separator[2]; - cache_t caching; + bool caching; int enums; PWCHAR enum_tdoms; @@ -419,10 +414,12 @@ class cygheap_pwdgrp public: struct { + pwdgrp cygserver; pwdgrp file; pwdgrp win; } pwd_cache; struct { + pwdgrp cygserver; pwdgrp file; pwdgrp win; } grp_cache; @@ -438,9 +435,8 @@ public: inline bool nss_prefix_primary () const { return prefix == NSS_PRIMARY; } inline bool nss_prefix_always () const { return prefix == NSS_ALWAYS; } inline PCWSTR nss_separator () const { return separator; } - inline bool nss_db_caching () const { return caching != NSS_NO_CACHING; } - inline bool nss_db_full_caching () const - { return caching == NSS_FULL_CACHING; } + inline bool nss_cygserver_caching () const { return caching; } + inline void nss_disable_cygserver_caching () { caching = false; } inline int nss_db_enums () const { return enums; } inline PCWSTR nss_db_enum_tdoms () const { return enum_tdoms; } }; diff --git a/winsup/cygwin/cygserver.h b/winsup/cygwin/cygserver.h index 8bcc271f3..1313d3c1e 100644 --- a/winsup/cygwin/cygserver.h +++ b/winsup/cygwin/cygserver.h @@ -52,6 +52,7 @@ protected: CYGSERVER_REQUEST_SEM, CYGSERVER_REQUEST_SHM, CYGSERVER_REQUEST_SETPWD, + CYGSERVER_REQUEST_PWDGRP, CYGSERVER_REQUEST_LAST } request_code_t; diff --git a/winsup/cygwin/cygserver_pwdgrp.h b/winsup/cygwin/cygserver_pwdgrp.h new file mode 100644 index 000000000..52b9b42ba --- /dev/null +++ b/winsup/cygwin/cygserver_pwdgrp.h @@ -0,0 +1,73 @@ +/* cygserver_pwdgrp.h: Request account information + + Copyright 2014 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#ifndef __CYGSERVER_PWDGRP_H__ +#define __CYGSERVER_PWDGRP_H__ + +#include +#include "cygserver.h" + +class transport_layer_base; +class process_cache; + +#ifdef __INSIDE_CYGWIN__ +#include "pwdgrp.h" +#else +/* Don't include pwdgrp.h, but keep this in sync. */ +enum fetch_user_arg_type_t { + SID_arg, + NAME_arg, + ID_arg +}; +#endif + +class client_request_pwdgrp : public client_request +{ + friend class client_request; + +private: + union _pwdgrp_param_t + { + struct _pwdgrp_in_t + { + bool group; + fetch_user_arg_type_t type; + union + { + BYTE sid[40]; + char name[UNLEN + 1]; + uint32_t id; + } arg; + } in; + + struct + { + char line[1024]; + } out; + } _parameters; + +#ifndef __INSIDE_CYGWIN__ + client_request_pwdgrp (); + virtual void serve (transport_layer_base *, process_cache *); + void pwd_serve (); + void grp_serve (); +#endif + +public: + +#ifdef __INSIDE_CYGWIN__ + client_request_pwdgrp (fetch_user_arg_t &arg, bool group); +#endif + + const char *line () const { return (msglen () > 0) ? _parameters.out.line + : NULL; } +}; + +#endif /* __CYGSERVER_PWDGRP_H__ */ diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index fd464f4ce..b76dd2441 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -80,12 +80,8 @@ public: struct _local_storage { /* passwd.cc */ - void *pwbuf; char pass[_PASSWORD_LEN]; - /* grp.cc */ - void *grbuf; - /* dlfcn.cc */ int dl_error; char dl_buffer[256]; diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc index a44bfb8b6..b03e9c7fd 100644 --- a/winsup/cygwin/fhandler_disk_file.cc +++ b/winsup/cygwin/fhandler_disk_file.cc @@ -534,8 +534,7 @@ fhandler_base::fstat_fs (struct stat *buf) } int __reg3 -fhandler_base::fstat_helper (struct stat *buf, - DWORD nNumberOfLinks) +fhandler_base::fstat_helper (struct stat *buf, DWORD nNumberOfLinks) { IO_STATUS_BLOCK st; FILE_COMPRESSION_INFORMATION fci; diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index be752a100..d941c0f9b 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -68,27 +68,6 @@ pwdgrp::init_grp () parse = &pwdgrp::parse_group; } -pwdgrp * -pwdgrp::prep_tls_grbuf () -{ - if (!_my_tls.locals.grbuf) - { - _my_tls.locals.grbuf = ccalloc_abort (HEAP_BUF, 1, - sizeof (pwdgrp) + sizeof (pg_grp)); - pwdgrp *gr = (pwdgrp *) _my_tls.locals.grbuf; - gr->init_grp (); - gr->pwdgrp_buf = (void *) (gr + 1); - gr->max_lines = 1; - } - pwdgrp *gr = (pwdgrp *) _my_tls.locals.grbuf; - if (gr->curr_lines) - { - cfree (gr->group ()[0].g.gr_name); - gr->curr_lines = 0; - } - return gr; -} - struct group * pwdgrp::find_group (cygpsid &sid) { @@ -122,20 +101,28 @@ internal_getgrsid (cygpsid &sid, cyg_ldap *pldap) struct group *ret; cygheap->pg.nss_init (); + /* Check caches first. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.grp_cache.cygserver.find_group (sid))) + return ret; + if (cygheap->pg.nss_grp_files () + && (ret = cygheap->pg.grp_cache.file.find_group (sid))) + return ret; + if (cygheap->pg.nss_grp_db () + && (ret = cygheap->pg.grp_cache.win.find_group (sid))) + return ret; + /* Ask sources afterwards. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.grp_cache.cygserver.add_group_from_cygserver (sid))) + return ret; if (cygheap->pg.nss_grp_files ()) { cygheap->pg.grp_cache.file.check_file (); - if ((ret = cygheap->pg.grp_cache.file.find_group (sid))) - return ret; if ((ret = cygheap->pg.grp_cache.file.add_group_from_file (sid))) return ret; } if (cygheap->pg.nss_grp_db ()) - { - if ((ret = cygheap->pg.grp_cache.win.find_group (sid))) - return ret; - return cygheap->pg.grp_cache.win.add_group_from_windows (sid, pldap); - } + return cygheap->pg.grp_cache.win.add_group_from_windows (sid, pldap); return NULL; } @@ -153,20 +140,28 @@ internal_getgrnam (const char *name, cyg_ldap *pldap) struct group *ret; cygheap->pg.nss_init (); + /* Check caches first. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.grp_cache.cygserver.find_group (name))) + return ret; + if (cygheap->pg.nss_grp_files () + && (ret = cygheap->pg.grp_cache.file.find_group (name))) + return ret; + if (cygheap->pg.nss_grp_db () + && (ret = cygheap->pg.grp_cache.win.find_group (name))) + return ret; + /* Ask sources afterwards. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.grp_cache.cygserver.add_group_from_cygserver (name))) + return ret; if (cygheap->pg.nss_grp_files ()) { cygheap->pg.grp_cache.file.check_file (); - if ((ret = cygheap->pg.grp_cache.file.find_group (name))) - return ret; if ((ret = cygheap->pg.grp_cache.file.add_group_from_file (name))) return ret; } if (cygheap->pg.nss_grp_db ()) - { - if ((ret = cygheap->pg.grp_cache.win.find_group (name))) - return ret; - return cygheap->pg.grp_cache.win.add_group_from_windows (name, pldap); - } + return cygheap->pg.grp_cache.win.add_group_from_windows (name, pldap); return NULL; } @@ -176,21 +171,27 @@ internal_getgrgid (gid_t gid, cyg_ldap *pldap) struct group *ret; cygheap->pg.nss_init (); + /* Check caches first. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.grp_cache.cygserver.find_group (gid))) + return ret; + if (cygheap->pg.nss_grp_files () + && (ret = cygheap->pg.grp_cache.file.find_group (gid))) + return ret; + if (cygheap->pg.nss_grp_db () + && (ret = cygheap->pg.grp_cache.win.find_group (gid))) + return ret; + /* Ask sources afterwards. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.grp_cache.cygserver.add_group_from_cygserver (gid))) + return ret; if (cygheap->pg.nss_grp_files ()) { cygheap->pg.grp_cache.file.check_file (); - if ((ret = cygheap->pg.grp_cache.file.find_group (gid))) - return ret; if ((ret = cygheap->pg.grp_cache.file.add_group_from_file (gid))) return ret; } - if (cygheap->pg.nss_grp_db ()) - { - if ((ret = cygheap->pg.grp_cache.win.find_group (gid))) - return ret; - return cygheap->pg.grp_cache.win.add_group_from_windows (gid); - } - else if (gid == ILLEGAL_GID) + if (cygheap->pg.nss_grp_db () || gid == ILLEGAL_GID) return cygheap->pg.grp_cache.win.add_group_from_windows (gid, pldap); return NULL; } @@ -327,20 +328,37 @@ static gr_ent grent; void * gr_ent::enumerate_caches () { - if (!max && from_files) + switch (max) { - pwdgrp &grf = cygheap->pg.grp_cache.file; - grf.check_file (); - if (cnt < grf.cached_groups ()) - return &grf.group ()[cnt++].g; + case 0: + if (cygheap->pg.nss_cygserver_caching ()) + { + pwdgrp &grc = cygheap->pg.grp_cache.cygserver; + if (cnt < grc.cached_groups ()) + return &grc.group ()[cnt++].g; + } cnt = 0; max = 1; - } - if (from_db && cygheap->pg.nss_db_caching ()) - { - pwdgrp &grw = cygheap->pg.grp_cache.win; - if (cnt < grw.cached_groups ()) - return &grw.group ()[cnt++].g; + /*FALLTHRU*/ + case 1: + if (from_files) + { + pwdgrp &grf = cygheap->pg.grp_cache.file; + grf.check_file (); + if (cnt < grf.cached_groups ()) + return &grf.group ()[cnt++].g; + } + cnt = 0; + max = 1; + /*FALLTHRU*/ + case 2: + if (from_db) + { + pwdgrp &grw = cygheap->pg.grp_cache.win; + if (cnt < grw.cached_groups ()) + return &grw.group ()[cnt++].g; + } + break; } cnt = max = 0; return NULL; diff --git a/winsup/cygwin/include/sys/cygwin.h b/winsup/cygwin/include/sys/cygwin.h index 32b9172a8..17fa12d43 100644 --- a/winsup/cygwin/include/sys/cygwin.h +++ b/winsup/cygwin/include/sys/cygwin.h @@ -210,8 +210,8 @@ typedef enum /* Token type for CW_SET_EXTERNAL_TOKEN */ enum { -CW_TOKEN_IMPERSONATION = 0, -CW_TOKEN_RESTRICTED = 1 + CW_TOKEN_IMPERSONATION = 0, + CW_TOKEN_RESTRICTED = 1 }; /* Enumeration source constants for CW_SETENT called from mkpasswd/mkgroup. */ diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index fff5a0d81..35a7ecf0b 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -51,27 +51,6 @@ pwdgrp::init_pwd () parse = &pwdgrp::parse_passwd; } -pwdgrp * -pwdgrp::prep_tls_pwbuf () -{ - if (!_my_tls.locals.pwbuf) - { - _my_tls.locals.pwbuf = ccalloc_abort (HEAP_BUF, 1, - sizeof (pwdgrp) + sizeof (pg_pwd)); - pwdgrp *pw = (pwdgrp *) _my_tls.locals.pwbuf; - pw->init_pwd (); - pw->pwdgrp_buf = (void *) (pw + 1); - pw->max_lines = 1; - } - pwdgrp *pw = (pwdgrp *) _my_tls.locals.pwbuf; - if (pw->curr_lines) - { - cfree (pw->passwd ()[0].p.pw_name); - pw->curr_lines = 0; - } - return pw; -} - struct passwd * pwdgrp::find_user (cygpsid &sid) { @@ -106,20 +85,28 @@ internal_getpwsid (cygpsid &sid, cyg_ldap *pldap) struct passwd *ret; cygheap->pg.nss_init (); + /* Check caches first. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.pwd_cache.cygserver.find_user (sid))) + return ret; + if (cygheap->pg.nss_pwd_files () + && (ret = cygheap->pg.pwd_cache.file.find_user (sid))) + return ret; + if (cygheap->pg.nss_pwd_db () + && (ret = cygheap->pg.pwd_cache.win.find_user (sid))) + return ret; + /* Ask sources afterwards. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.pwd_cache.cygserver.add_user_from_cygserver (sid))) + return ret; if (cygheap->pg.nss_pwd_files ()) { cygheap->pg.pwd_cache.file.check_file (); - if ((ret = cygheap->pg.pwd_cache.file.find_user (sid))) - return ret; if ((ret = cygheap->pg.pwd_cache.file.add_user_from_file (sid))) return ret; } if (cygheap->pg.nss_pwd_db ()) - { - if ((ret = cygheap->pg.pwd_cache.win.find_user (sid))) - return ret; - return cygheap->pg.pwd_cache.win.add_user_from_windows (sid, pldap); - } + return cygheap->pg.pwd_cache.win.add_user_from_windows (sid, pldap); return NULL; } @@ -137,20 +124,28 @@ internal_getpwnam (const char *name, cyg_ldap *pldap) struct passwd *ret; cygheap->pg.nss_init (); + /* Check caches first. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.pwd_cache.cygserver.find_user (name))) + return ret; + if (cygheap->pg.nss_pwd_files () + && (ret = cygheap->pg.pwd_cache.file.find_user (name))) + return ret; + if (cygheap->pg.nss_pwd_db () + && (ret = cygheap->pg.pwd_cache.win.find_user (name))) + return ret; + /* Ask sources afterwards. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.pwd_cache.cygserver.add_user_from_cygserver (name))) + return ret; if (cygheap->pg.nss_pwd_files ()) { cygheap->pg.pwd_cache.file.check_file (); - if ((ret = cygheap->pg.pwd_cache.file.find_user (name))) - return ret; if ((ret = cygheap->pg.pwd_cache.file.add_user_from_file (name))) return ret; } if (cygheap->pg.nss_pwd_db ()) - { - if ((ret = cygheap->pg.pwd_cache.win.find_user (name))) - return ret; - return cygheap->pg.pwd_cache.win.add_user_from_windows (name, pldap); - } + return cygheap->pg.pwd_cache.win.add_user_from_windows (name, pldap); return NULL; } @@ -160,22 +155,28 @@ internal_getpwuid (uid_t uid, cyg_ldap *pldap) struct passwd *ret; cygheap->pg.nss_init (); + /* Check caches first. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.pwd_cache.cygserver.find_user (uid))) + return ret; + if (cygheap->pg.nss_pwd_files () + && (ret = cygheap->pg.pwd_cache.file.find_user (uid))) + return ret; + if (cygheap->pg.nss_pwd_db () + && (ret = cygheap->pg.pwd_cache.win.find_user (uid))) + return ret; + /* Ask sources afterwards. */ + if (cygheap->pg.nss_cygserver_caching () + && (ret = cygheap->pg.pwd_cache.cygserver.add_user_from_cygserver (uid))) + return ret; if (cygheap->pg.nss_pwd_files ()) { cygheap->pg.pwd_cache.file.check_file (); - if ((ret = cygheap->pg.pwd_cache.file.find_user (uid))) - return ret; if ((ret = cygheap->pg.pwd_cache.file.add_user_from_file (uid))) return ret; } - if (cygheap->pg.nss_pwd_db ()) - { - if ((ret = cygheap->pg.pwd_cache.win.find_user (uid))) - return ret; - return cygheap->pg.pwd_cache.win.add_user_from_windows (uid, pldap); - } - else if (uid == ILLEGAL_UID) - return cygheap->pg.pwd_cache.win.add_user_from_windows (uid); + if (cygheap->pg.nss_pwd_db () || uid == ILLEGAL_UID) + return cygheap->pg.pwd_cache.win.add_user_from_windows (uid, pldap); return NULL; } @@ -596,20 +597,37 @@ pg_ent::enumerate_ad () void * pw_ent::enumerate_caches () { - if (!max && from_files) + switch (max) { - pwdgrp &prf = cygheap->pg.pwd_cache.file; - prf.check_file (); - if (cnt < prf.cached_users ()) - return &prf.passwd ()[cnt++].p; + case 0: + if (cygheap->pg.nss_cygserver_caching ()) + { + pwdgrp &prc = cygheap->pg.pwd_cache.cygserver; + if (cnt < prc.cached_users ()) + return &prc.passwd ()[cnt++].p; + } cnt = 0; max = 1; - } - if (from_db && cygheap->pg.nss_db_caching ()) - { - pwdgrp &prw = cygheap->pg.pwd_cache.win; - if (cnt < prw.cached_users ()) - return &prw.passwd ()[cnt++].p; + /*FALLTHRU*/ + case 1: + if (from_files) + { + pwdgrp &prf = cygheap->pg.pwd_cache.file; + prf.check_file (); + if (cnt < prf.cached_users ()) + return &prf.passwd ()[cnt++].p; + } + cnt = 0; + max = 2; + /*FALLTHRU*/ + default: + if (from_db) + { + pwdgrp &prw = cygheap->pg.pwd_cache.win; + if (cnt < prw.cached_users ()) + return &prw.passwd ()[cnt++].p; + } + break; } cnt = max = 0; return NULL; diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h index 0d2d9cc20..1a964def3 100644 --- a/winsup/cygwin/pwdgrp.h +++ b/winsup/cygwin/pwdgrp.h @@ -111,12 +111,14 @@ class pwdgrp void *add_account_from_windows (cygpsid &sid, cyg_ldap *pldap = NULL); void *add_account_from_windows (const char *name, cyg_ldap *pldap = NULL); void *add_account_from_windows (uint32_t id, cyg_ldap *pldap = NULL); + void *add_account_from_cygserver (cygpsid &sid); + void *add_account_from_cygserver (const char *name); + void *add_account_from_cygserver (uint32_t id); char *fetch_account_from_line (fetch_user_arg_t &arg, const char *line); char *fetch_account_from_file (fetch_user_arg_t &arg); char *fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap = NULL); - pwdgrp *prep_tls_pwbuf (); - pwdgrp *prep_tls_grbuf (); + char *fetch_account_from_cygserver (fetch_user_arg_t &arg); public: ULONG cached_users () const { return curr_lines; } @@ -127,7 +129,13 @@ public: void init_pwd (); bool is_passwd () const { return pwdgrp_buf_elem_size == sizeof (pg_pwd); } pg_pwd *passwd () const { return (pg_pwd *) pwdgrp_buf; }; - inline struct passwd *add_user_from_file (cygpsid &sid) + struct passwd *add_user_from_cygserver (cygpsid &sid) + { return (struct passwd *) add_account_from_cygserver (sid); } + struct passwd *add_user_from_cygserver (const char *name) + { return (struct passwd *) add_account_from_cygserver (name); } + struct passwd *add_user_from_cygserver (uint32_t id) + { return (struct passwd *) add_account_from_cygserver (id); } + struct passwd *add_user_from_file (cygpsid &sid) { return (struct passwd *) add_account_from_file (sid); } struct passwd *add_user_from_file (const char *name) { return (struct passwd *) add_account_from_file (name); } @@ -147,6 +155,12 @@ public: void init_grp (); bool is_group () const { return pwdgrp_buf_elem_size == sizeof (pg_grp); } pg_grp *group () const { return (pg_grp *) pwdgrp_buf; }; + struct group *add_group_from_cygserver (cygpsid &sid) + { return (struct group *) add_account_from_cygserver (sid); } + struct group *add_group_from_cygserver (const char *name) + { return (struct group *) add_account_from_cygserver (name); } + struct group *add_group_from_cygserver (uint32_t id) + { return (struct group *) add_account_from_cygserver (id); } struct group *add_group_from_file (cygpsid &sid) { return (struct group *) add_account_from_file (sid); } struct group *add_group_from_file (const char *name) diff --git a/winsup/cygwin/tlsoffsets.h b/winsup/cygwin/tlsoffsets.h index 8edc86c18..e59ea7430 100644 --- a/winsup/cygwin/tlsoffsets.h +++ b/winsup/cygwin/tlsoffsets.h @@ -3,115 +3,115 @@ //; $tls::start_offset = -12700; //; $tls::locals = -12700; //; $tls::plocals = 0; -//; $tls::local_clib = -11292; -//; $tls::plocal_clib = 1408; -//; $tls::__dontuse = -11292; -//; $tls::p__dontuse = 1408; -//; $tls::func = -10204; -//; $tls::pfunc = 2496; -//; $tls::saved_errno = -10200; -//; $tls::psaved_errno = 2500; -//; $tls::sa_flags = -10196; -//; $tls::psa_flags = 2504; -//; $tls::oldmask = -10192; -//; $tls::poldmask = 2508; -//; $tls::deltamask = -10188; -//; $tls::pdeltamask = 2512; -//; $tls::errno_addr = -10184; -//; $tls::perrno_addr = 2516; -//; $tls::sigmask = -10180; -//; $tls::psigmask = 2520; -//; $tls::sigwait_mask = -10176; -//; $tls::psigwait_mask = 2524; -//; $tls::sigwait_info = -10172; -//; $tls::psigwait_info = 2528; -//; $tls::signal_arrived = -10168; -//; $tls::psignal_arrived = 2532; -//; $tls::will_wait_for_signal = -10164; -//; $tls::pwill_wait_for_signal = 2536; -//; $tls::thread_context = -10160; -//; $tls::pthread_context = 2540; -//; $tls::thread_id = -9948; -//; $tls::pthread_id = 2752; -//; $tls::infodata = -9944; -//; $tls::pinfodata = 2756; -//; $tls::tid = -9796; -//; $tls::ptid = 2904; -//; $tls::_ctinfo = -9792; -//; $tls::p_ctinfo = 2908; -//; $tls::andreas = -9788; -//; $tls::pandreas = 2912; -//; $tls::wq = -9784; -//; $tls::pwq = 2916; -//; $tls::sig = -9756; -//; $tls::psig = 2944; -//; $tls::incyg = -9752; -//; $tls::pincyg = 2948; -//; $tls::spinning = -9748; -//; $tls::pspinning = 2952; -//; $tls::stacklock = -9744; -//; $tls::pstacklock = 2956; -//; $tls::stackptr = -9740; -//; $tls::pstackptr = 2960; -//; $tls::stack = -9736; -//; $tls::pstack = 2964; -//; $tls::initialized = -8712; -//; $tls::pinitialized = 3988; +//; $tls::local_clib = -11300; +//; $tls::plocal_clib = 1400; +//; $tls::__dontuse = -11300; +//; $tls::p__dontuse = 1400; +//; $tls::func = -10212; +//; $tls::pfunc = 2488; +//; $tls::saved_errno = -10208; +//; $tls::psaved_errno = 2492; +//; $tls::sa_flags = -10204; +//; $tls::psa_flags = 2496; +//; $tls::oldmask = -10200; +//; $tls::poldmask = 2500; +//; $tls::deltamask = -10196; +//; $tls::pdeltamask = 2504; +//; $tls::errno_addr = -10192; +//; $tls::perrno_addr = 2508; +//; $tls::sigmask = -10188; +//; $tls::psigmask = 2512; +//; $tls::sigwait_mask = -10184; +//; $tls::psigwait_mask = 2516; +//; $tls::sigwait_info = -10180; +//; $tls::psigwait_info = 2520; +//; $tls::signal_arrived = -10176; +//; $tls::psignal_arrived = 2524; +//; $tls::will_wait_for_signal = -10172; +//; $tls::pwill_wait_for_signal = 2528; +//; $tls::thread_context = -10168; +//; $tls::pthread_context = 2532; +//; $tls::thread_id = -9956; +//; $tls::pthread_id = 2744; +//; $tls::infodata = -9952; +//; $tls::pinfodata = 2748; +//; $tls::tid = -9804; +//; $tls::ptid = 2896; +//; $tls::_ctinfo = -9800; +//; $tls::p_ctinfo = 2900; +//; $tls::andreas = -9796; +//; $tls::pandreas = 2904; +//; $tls::wq = -9792; +//; $tls::pwq = 2908; +//; $tls::sig = -9764; +//; $tls::psig = 2936; +//; $tls::incyg = -9760; +//; $tls::pincyg = 2940; +//; $tls::spinning = -9756; +//; $tls::pspinning = 2944; +//; $tls::stacklock = -9752; +//; $tls::pstacklock = 2948; +//; $tls::stackptr = -9748; +//; $tls::pstackptr = 2952; +//; $tls::stack = -9744; +//; $tls::pstack = 2956; +//; $tls::initialized = -8720; +//; $tls::pinitialized = 3980; //; __DATA__ #define tls_locals (-12700) #define tls_plocals (0) -#define tls_local_clib (-11292) -#define tls_plocal_clib (1408) -#define tls___dontuse (-11292) -#define tls_p__dontuse (1408) -#define tls_func (-10204) -#define tls_pfunc (2496) -#define tls_saved_errno (-10200) -#define tls_psaved_errno (2500) -#define tls_sa_flags (-10196) -#define tls_psa_flags (2504) -#define tls_oldmask (-10192) -#define tls_poldmask (2508) -#define tls_deltamask (-10188) -#define tls_pdeltamask (2512) -#define tls_errno_addr (-10184) -#define tls_perrno_addr (2516) -#define tls_sigmask (-10180) -#define tls_psigmask (2520) -#define tls_sigwait_mask (-10176) -#define tls_psigwait_mask (2524) -#define tls_sigwait_info (-10172) -#define tls_psigwait_info (2528) -#define tls_signal_arrived (-10168) -#define tls_psignal_arrived (2532) -#define tls_will_wait_for_signal (-10164) -#define tls_pwill_wait_for_signal (2536) -#define tls_thread_context (-10160) -#define tls_pthread_context (2540) -#define tls_thread_id (-9948) -#define tls_pthread_id (2752) -#define tls_infodata (-9944) -#define tls_pinfodata (2756) -#define tls_tid (-9796) -#define tls_ptid (2904) -#define tls__ctinfo (-9792) -#define tls_p_ctinfo (2908) -#define tls_andreas (-9788) -#define tls_pandreas (2912) -#define tls_wq (-9784) -#define tls_pwq (2916) -#define tls_sig (-9756) -#define tls_psig (2944) -#define tls_incyg (-9752) -#define tls_pincyg (2948) -#define tls_spinning (-9748) -#define tls_pspinning (2952) -#define tls_stacklock (-9744) -#define tls_pstacklock (2956) -#define tls_stackptr (-9740) -#define tls_pstackptr (2960) -#define tls_stack (-9736) -#define tls_pstack (2964) -#define tls_initialized (-8712) -#define tls_pinitialized (3988) +#define tls_local_clib (-11300) +#define tls_plocal_clib (1400) +#define tls___dontuse (-11300) +#define tls_p__dontuse (1400) +#define tls_func (-10212) +#define tls_pfunc (2488) +#define tls_saved_errno (-10208) +#define tls_psaved_errno (2492) +#define tls_sa_flags (-10204) +#define tls_psa_flags (2496) +#define tls_oldmask (-10200) +#define tls_poldmask (2500) +#define tls_deltamask (-10196) +#define tls_pdeltamask (2504) +#define tls_errno_addr (-10192) +#define tls_perrno_addr (2508) +#define tls_sigmask (-10188) +#define tls_psigmask (2512) +#define tls_sigwait_mask (-10184) +#define tls_psigwait_mask (2516) +#define tls_sigwait_info (-10180) +#define tls_psigwait_info (2520) +#define tls_signal_arrived (-10176) +#define tls_psignal_arrived (2524) +#define tls_will_wait_for_signal (-10172) +#define tls_pwill_wait_for_signal (2528) +#define tls_thread_context (-10168) +#define tls_pthread_context (2532) +#define tls_thread_id (-9956) +#define tls_pthread_id (2744) +#define tls_infodata (-9952) +#define tls_pinfodata (2748) +#define tls_tid (-9804) +#define tls_ptid (2896) +#define tls__ctinfo (-9800) +#define tls_p_ctinfo (2900) +#define tls_andreas (-9796) +#define tls_pandreas (2904) +#define tls_wq (-9792) +#define tls_pwq (2908) +#define tls_sig (-9764) +#define tls_psig (2936) +#define tls_incyg (-9760) +#define tls_pincyg (2940) +#define tls_spinning (-9756) +#define tls_pspinning (2944) +#define tls_stacklock (-9752) +#define tls_pstacklock (2948) +#define tls_stackptr (-9748) +#define tls_pstackptr (2952) +#define tls_stack (-9744) +#define tls_pstack (2956) +#define tls_initialized (-8720) +#define tls_pinitialized (3980) diff --git a/winsup/cygwin/tlsoffsets64.h b/winsup/cygwin/tlsoffsets64.h index e04fca103..d518f9d8c 100644 --- a/winsup/cygwin/tlsoffsets64.h +++ b/winsup/cygwin/tlsoffsets64.h @@ -3,115 +3,115 @@ //; $tls::start_offset = -12800; //; $tls::locals = -12800; //; $tls::plocals = 0; -//; $tls::local_clib = -11248; -//; $tls::plocal_clib = 1552; -//; $tls::__dontuse = -11248; -//; $tls::p__dontuse = 1552; -//; $tls::func = -9360; -//; $tls::pfunc = 3440; -//; $tls::saved_errno = -9352; -//; $tls::psaved_errno = 3448; -//; $tls::sa_flags = -9348; -//; $tls::psa_flags = 3452; -//; $tls::oldmask = -9344; -//; $tls::poldmask = 3456; -//; $tls::deltamask = -9336; -//; $tls::pdeltamask = 3464; -//; $tls::errno_addr = -9328; -//; $tls::perrno_addr = 3472; -//; $tls::sigmask = -9320; -//; $tls::psigmask = 3480; -//; $tls::sigwait_mask = -9312; -//; $tls::psigwait_mask = 3488; -//; $tls::sigwait_info = -9304; -//; $tls::psigwait_info = 3496; -//; $tls::signal_arrived = -9296; -//; $tls::psignal_arrived = 3504; -//; $tls::will_wait_for_signal = -9288; -//; $tls::pwill_wait_for_signal = 3512; -//; $tls::thread_context = -9280; -//; $tls::pthread_context = 3520; -//; $tls::thread_id = -8448; -//; $tls::pthread_id = 4352; -//; $tls::infodata = -8444; -//; $tls::pinfodata = 4356; -//; $tls::tid = -8296; -//; $tls::ptid = 4504; -//; $tls::_ctinfo = -8288; -//; $tls::p_ctinfo = 4512; -//; $tls::andreas = -8280; -//; $tls::pandreas = 4520; -//; $tls::wq = -8272; -//; $tls::pwq = 4528; -//; $tls::sig = -8224; -//; $tls::psig = 4576; -//; $tls::incyg = -8220; -//; $tls::pincyg = 4580; -//; $tls::spinning = -8216; -//; $tls::pspinning = 4584; -//; $tls::stacklock = -8212; -//; $tls::pstacklock = 4588; -//; $tls::stackptr = -8208; -//; $tls::pstackptr = 4592; -//; $tls::stack = -8200; -//; $tls::pstack = 4600; -//; $tls::initialized = -6152; -//; $tls::pinitialized = 6648; +//; $tls::local_clib = -11264; +//; $tls::plocal_clib = 1536; +//; $tls::__dontuse = -11264; +//; $tls::p__dontuse = 1536; +//; $tls::func = -9376; +//; $tls::pfunc = 3424; +//; $tls::saved_errno = -9368; +//; $tls::psaved_errno = 3432; +//; $tls::sa_flags = -9364; +//; $tls::psa_flags = 3436; +//; $tls::oldmask = -9360; +//; $tls::poldmask = 3440; +//; $tls::deltamask = -9352; +//; $tls::pdeltamask = 3448; +//; $tls::errno_addr = -9344; +//; $tls::perrno_addr = 3456; +//; $tls::sigmask = -9336; +//; $tls::psigmask = 3464; +//; $tls::sigwait_mask = -9328; +//; $tls::psigwait_mask = 3472; +//; $tls::sigwait_info = -9320; +//; $tls::psigwait_info = 3480; +//; $tls::signal_arrived = -9312; +//; $tls::psignal_arrived = 3488; +//; $tls::will_wait_for_signal = -9304; +//; $tls::pwill_wait_for_signal = 3496; +//; $tls::thread_context = -9296; +//; $tls::pthread_context = 3504; +//; $tls::thread_id = -8464; +//; $tls::pthread_id = 4336; +//; $tls::infodata = -8460; +//; $tls::pinfodata = 4340; +//; $tls::tid = -8312; +//; $tls::ptid = 4488; +//; $tls::_ctinfo = -8304; +//; $tls::p_ctinfo = 4496; +//; $tls::andreas = -8296; +//; $tls::pandreas = 4504; +//; $tls::wq = -8288; +//; $tls::pwq = 4512; +//; $tls::sig = -8240; +//; $tls::psig = 4560; +//; $tls::incyg = -8236; +//; $tls::pincyg = 4564; +//; $tls::spinning = -8232; +//; $tls::pspinning = 4568; +//; $tls::stacklock = -8228; +//; $tls::pstacklock = 4572; +//; $tls::stackptr = -8224; +//; $tls::pstackptr = 4576; +//; $tls::stack = -8216; +//; $tls::pstack = 4584; +//; $tls::initialized = -6168; +//; $tls::pinitialized = 6632; //; __DATA__ #define tls_locals (-12800) #define tls_plocals (0) -#define tls_local_clib (-11248) -#define tls_plocal_clib (1552) -#define tls___dontuse (-11248) -#define tls_p__dontuse (1552) -#define tls_func (-9360) -#define tls_pfunc (3440) -#define tls_saved_errno (-9352) -#define tls_psaved_errno (3448) -#define tls_sa_flags (-9348) -#define tls_psa_flags (3452) -#define tls_oldmask (-9344) -#define tls_poldmask (3456) -#define tls_deltamask (-9336) -#define tls_pdeltamask (3464) -#define tls_errno_addr (-9328) -#define tls_perrno_addr (3472) -#define tls_sigmask (-9320) -#define tls_psigmask (3480) -#define tls_sigwait_mask (-9312) -#define tls_psigwait_mask (3488) -#define tls_sigwait_info (-9304) -#define tls_psigwait_info (3496) -#define tls_signal_arrived (-9296) -#define tls_psignal_arrived (3504) -#define tls_will_wait_for_signal (-9288) -#define tls_pwill_wait_for_signal (3512) -#define tls_thread_context (-9280) -#define tls_pthread_context (3520) -#define tls_thread_id (-8448) -#define tls_pthread_id (4352) -#define tls_infodata (-8444) -#define tls_pinfodata (4356) -#define tls_tid (-8296) -#define tls_ptid (4504) -#define tls__ctinfo (-8288) -#define tls_p_ctinfo (4512) -#define tls_andreas (-8280) -#define tls_pandreas (4520) -#define tls_wq (-8272) -#define tls_pwq (4528) -#define tls_sig (-8224) -#define tls_psig (4576) -#define tls_incyg (-8220) -#define tls_pincyg (4580) -#define tls_spinning (-8216) -#define tls_pspinning (4584) -#define tls_stacklock (-8212) -#define tls_pstacklock (4588) -#define tls_stackptr (-8208) -#define tls_pstackptr (4592) -#define tls_stack (-8200) -#define tls_pstack (4600) -#define tls_initialized (-6152) -#define tls_pinitialized (6648) +#define tls_local_clib (-11264) +#define tls_plocal_clib (1536) +#define tls___dontuse (-11264) +#define tls_p__dontuse (1536) +#define tls_func (-9376) +#define tls_pfunc (3424) +#define tls_saved_errno (-9368) +#define tls_psaved_errno (3432) +#define tls_sa_flags (-9364) +#define tls_psa_flags (3436) +#define tls_oldmask (-9360) +#define tls_poldmask (3440) +#define tls_deltamask (-9352) +#define tls_pdeltamask (3448) +#define tls_errno_addr (-9344) +#define tls_perrno_addr (3456) +#define tls_sigmask (-9336) +#define tls_psigmask (3464) +#define tls_sigwait_mask (-9328) +#define tls_psigwait_mask (3472) +#define tls_sigwait_info (-9320) +#define tls_psigwait_info (3480) +#define tls_signal_arrived (-9312) +#define tls_psignal_arrived (3488) +#define tls_will_wait_for_signal (-9304) +#define tls_pwill_wait_for_signal (3496) +#define tls_thread_context (-9296) +#define tls_pthread_context (3504) +#define tls_thread_id (-8464) +#define tls_pthread_id (4336) +#define tls_infodata (-8460) +#define tls_pinfodata (4340) +#define tls_tid (-8312) +#define tls_ptid (4488) +#define tls__ctinfo (-8304) +#define tls_p_ctinfo (4496) +#define tls_andreas (-8296) +#define tls_pandreas (4504) +#define tls_wq (-8288) +#define tls_pwq (4512) +#define tls_sig (-8240) +#define tls_psig (4560) +#define tls_incyg (-8236) +#define tls_pincyg (4564) +#define tls_spinning (-8232) +#define tls_pspinning (4568) +#define tls_stacklock (-8228) +#define tls_pstacklock (4572) +#define tls_stackptr (-8224) +#define tls_pstackptr (4576) +#define tls_stack (-8216) +#define tls_pstack (4584) +#define tls_initialized (-6168) +#define tls_pinitialized (6632) diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index 10d335644..3b42754ed 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -32,8 +32,8 @@ details. */ #include "tls_pbuf.h" #include "miscfuncs.h" #include "ntdll.h" - #include "ldap.h" +#include "cygserver_pwdgrp.h" /* Initialize the part of cygheap_user that does not depend on files. The information is used in shared.cc for the user shared. @@ -124,7 +124,7 @@ internal_getlogin (cygheap_user &user) and the primary group in the token. */ pwd = internal_getpwsid (user.sid (), &cldap); pgrp = internal_getgrsid (user.groups.pgsid, &cldap); - if (cygheap->pg.nss_db_full_caching ()) + if (!cygheap->pg.nss_cygserver_caching ()) internal_getgroups (0, NULL, &cldap); if (!pwd) debug_printf ("user not found in passwd DB"); @@ -567,8 +567,10 @@ pwdgrp::add_line (char *eptr) void cygheap_pwdgrp::init () { + pwd_cache.cygserver.init_pwd (); pwd_cache.file.init_pwd (); pwd_cache.win.init_pwd (); + grp_cache.cygserver.init_grp (); grp_cache.file.init_grp (); grp_cache.win.init_grp (); /* Default settings: @@ -584,7 +586,7 @@ cygheap_pwdgrp::init () grp_src = (NSS_FILES | NSS_DB); prefix = NSS_AUTO; separator[0] = L'+'; - caching = NSS_FULL_CACHING; + caching = true; enums = (ENUM_CACHE | ENUM_BUILTIN); enum_tdoms = NULL; } @@ -670,19 +672,6 @@ cygheap_pwdgrp::nss_init_line (const char *line) else debug_printf ("Invalid nsswitch.conf content: %s", line); } - else if (!strncmp (c, "cache:", 6)) - { - c += 6; - c += strspn (c, " \t"); - if (!strncmp (c, "full", 3) && strchr (" \t", c[3])) - caching = NSS_FULL_CACHING; - else if (!strncmp (c, "yes", 3) && strchr (" \t", c[3])) - caching = NSS_CACHING; - else if (!strncmp (c, "no", 2) && strchr (" \t", c[2])) - caching = NSS_NO_CACHING; - else - debug_printf ("Invalid nsswitch.conf content: %s", line); - } else if (!strncmp (c, "enum:", 5)) { tmp_pathbuf tp; @@ -1001,11 +990,7 @@ pwdgrp::add_account_from_windows (cygpsid &sid, cyg_ldap *pldap) char *line = fetch_account_from_windows (arg, pldap); if (!line) return NULL; - if (cygheap->pg.nss_db_caching ()) - return add_account_post_fetch (line, true); - if (is_group ()) - return (prep_tls_grbuf ())->add_account_post_fetch (line, false); - return (prep_tls_pwbuf ())->add_account_post_fetch (line, false); + return add_account_post_fetch (line, true); } void * @@ -1017,11 +1002,7 @@ pwdgrp::add_account_from_windows (const char *name, cyg_ldap *pldap) char *line = fetch_account_from_windows (arg, pldap); if (!line) return NULL; - if (cygheap->pg.nss_db_caching ()) - return add_account_post_fetch (line, true); - if (is_group ()) - return (prep_tls_grbuf ())->add_account_post_fetch (line, false); - return (prep_tls_pwbuf ())->add_account_post_fetch (line, false); + return add_account_post_fetch (line, true); } void * @@ -1033,11 +1014,7 @@ pwdgrp::add_account_from_windows (uint32_t id, cyg_ldap *pldap) char *line = fetch_account_from_windows (arg, pldap); if (!line) return NULL; - if (cygheap->pg.nss_db_caching ()) - return add_account_post_fetch (line, true); - if (is_group ()) - return (prep_tls_grbuf ())->add_account_post_fetch (line, false); - return (prep_tls_pwbuf ())->add_account_post_fetch (line, false); + return add_account_post_fetch (line, true); } /* Check if file exists and if it has been written to since last checked. @@ -1828,3 +1805,79 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap) debug_printf ("line: <%s>", line); return line; } + +client_request_pwdgrp::client_request_pwdgrp (fetch_user_arg_t &arg, bool group) + : client_request (CYGSERVER_REQUEST_PWDGRP, &_parameters, sizeof (_parameters)) +{ + size_t len = 0; + char *p; + + _parameters.in.group = group; + _parameters.in.type = arg.type; + switch (arg.type) + { + case SID_arg: + RtlCopySid (sizeof (DBGSID), (PSID) &_parameters.in.arg.sid, *arg.sid); + len = RtlLengthSid (*arg.sid); + break; + case NAME_arg: + p = stpcpy (_parameters.in.arg.name, arg.name); + len = p - _parameters.in.arg.name; + break; + case ID_arg: + _parameters.in.arg.id = arg.id; + len = sizeof (uint32_t); + } + msglen (__builtin_offsetof (struct _pwdgrp_param_t::_pwdgrp_in_t, arg) + len); +} + +char * +pwdgrp::fetch_account_from_cygserver (fetch_user_arg_t &arg) +{ + client_request_pwdgrp request (arg, is_group ()); + if (request.make_request () == -1 || request.error_code ()) + { + /* Cygserver not running? Don't try again. This will automatically + avoid an endless loop in cygserver itself. */ + if (request.error_code () == ENOSYS) + cygheap->pg.nss_disable_cygserver_caching (); + return NULL; + } + if (!request.line ()) + return NULL; + return cstrdup (request.line ()); +} + +void * +pwdgrp::add_account_from_cygserver (cygpsid &sid) +{ + /* No, Everyone is no group in terms of POSIX. */ + if (sid_id_auth (sid) == 1 /* SECURITY_WORLD_SID_AUTHORITY */ + && sid_sub_auth (sid, 0) == SECURITY_WORLD_RID) + return NULL; + fetch_user_arg_t arg; + arg.type = SID_arg; + arg.sid = &sid; + char *line = fetch_account_from_cygserver (arg); + return (struct passwd *) add_account_post_fetch (line, true); +} + +void * +pwdgrp::add_account_from_cygserver (const char *name) +{ + fetch_user_arg_t arg; + arg.type = NAME_arg; + arg.name = name; + char *line = fetch_account_from_cygserver (arg); + return (struct passwd *) add_account_post_fetch (line, true); +} + +void * +pwdgrp::add_account_from_cygserver (uint32_t id) +{ + fetch_user_arg_t arg; + arg.type = ID_arg; + arg.id = id; + char *line = fetch_account_from_cygserver (arg); + return (struct passwd *) add_account_post_fetch (line, true); +}