From 0e8dd88459cd23baa31f9c6bf97a4424d7c30742 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Fri, 7 Mar 2014 20:38:48 +0000 Subject: [PATCH] * pwdgrp.h (pwdgrp::is_passwd): New inline method. (pwdgrp::is_group): New inline method. (add_account_from_windows): Drop group argument from declaration. (fetch_account_from_windows): Ditto. (check_file): Ditto. (add_user_from_windows): Call add_account_from_windows accordingly. (add_group_from_windows): Ditto. * uinfo.cc (pwdgrp::add_account_from_windows): Drop group argument. Use is_group method instead. (pwdgrp::check_file): Ditto. (pwdgrp::fetch_account_from_windows): Ditto. * grp.cc: Accommodate aforementioned changes. * passwd.cc: Ditto. --- winsup/cygwin/ChangeLog | 16 +++++++++++++++ winsup/cygwin/grp.cc | 10 +++++----- winsup/cygwin/passwd.cc | 16 +++++++-------- winsup/cygwin/pwdgrp.h | 27 +++++++++++++------------- winsup/cygwin/uinfo.cc | 43 ++++++++++++++++++++--------------------- 5 files changed, 63 insertions(+), 49 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 9dabf5c77..74b65588d 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,19 @@ +2014-03-07 Corinna Vinschen + + * pwdgrp.h (pwdgrp::is_passwd): New inline method. + (pwdgrp::is_group): New inline method. + (add_account_from_windows): Drop group argument from declaration. + (fetch_account_from_windows): Ditto. + (check_file): Ditto. + (add_user_from_windows): Call add_account_from_windows accordingly. + (add_group_from_windows): Ditto. + * uinfo.cc (pwdgrp::add_account_from_windows): Drop group argument. + Use is_group method instead. + (pwdgrp::check_file): Ditto. + (pwdgrp::fetch_account_from_windows): Ditto. + * grp.cc: Accommodate aforementioned changes. + * passwd.cc: Ditto. + 2014-03-06 Corinna Vinschen * passwd.cc (pg_ent::enumerate_builtin): Convert pwd_builtins and diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index cd4afd4a1..be752a100 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -124,7 +124,7 @@ internal_getgrsid (cygpsid &sid, cyg_ldap *pldap) cygheap->pg.nss_init (); if (cygheap->pg.nss_grp_files ()) { - cygheap->pg.grp_cache.file.check_file (true); + 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))) @@ -155,7 +155,7 @@ internal_getgrnam (const char *name, cyg_ldap *pldap) cygheap->pg.nss_init (); if (cygheap->pg.nss_grp_files ()) { - cygheap->pg.grp_cache.file.check_file (true); + 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))) @@ -178,7 +178,7 @@ internal_getgrgid (gid_t gid, cyg_ldap *pldap) cygheap->pg.nss_init (); if (cygheap->pg.nss_grp_files ()) { - cygheap->pg.grp_cache.file.check_file (true); + 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))) @@ -330,7 +330,7 @@ gr_ent::enumerate_caches () if (!max && from_files) { pwdgrp &grf = cygheap->pg.grp_cache.file; - grf.check_file (true); + grf.check_file (); if (cnt < grf.cached_groups ()) return &grf.group ()[cnt++].g; cnt = 0; @@ -389,7 +389,7 @@ gr_ent::enumerate_local () fetch_user_arg_t arg; arg.type = SID_arg; arg.sid = &sid; - char *line = pg.fetch_account_from_windows (arg, true); + char *line = pg.fetch_account_from_windows (arg); if (line) return pg.add_account_post_fetch (line, false); } diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index cbe0945d6..fff5a0d81 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -108,7 +108,7 @@ internal_getpwsid (cygpsid &sid, cyg_ldap *pldap) cygheap->pg.nss_init (); if (cygheap->pg.nss_pwd_files ()) { - cygheap->pg.pwd_cache.file.check_file (false); + 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))) @@ -139,7 +139,7 @@ internal_getpwnam (const char *name, cyg_ldap *pldap) cygheap->pg.nss_init (); if (cygheap->pg.nss_pwd_files ()) { - cygheap->pg.pwd_cache.file.check_file (false); + 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))) @@ -162,7 +162,7 @@ internal_getpwuid (uid_t uid, cyg_ldap *pldap) cygheap->pg.nss_init (); if (cygheap->pg.nss_pwd_files ()) { - cygheap->pg.pwd_cache.file.check_file (false); + 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))) @@ -442,7 +442,7 @@ pg_ent::enumerate_file () { pwdgrp &prf = group ? cygheap->pg.grp_cache.file : cygheap->pg.pwd_cache.file; - if (prf.check_file (group)) + if (prf.check_file ()) { if (!buf) buf = (char *) malloc (NT_MAX_PATH); @@ -491,7 +491,7 @@ pg_ent::enumerate_builtin () fetch_user_arg_t arg; arg.type = SID_arg; arg.sid = &sid; - char *line = pg.fetch_account_from_windows (arg, group); + char *line = pg.fetch_account_from_windows (arg); return pg.add_account_post_fetch (line, false); } @@ -538,7 +538,7 @@ pg_ent::enumerate_sam () fetch_user_arg_t arg; arg.type = SID_arg; arg.sid = &sid; - char *line = pg.fetch_account_from_windows (arg, group); + char *line = pg.fetch_account_from_windows (arg); if (line) return pg.add_account_post_fetch (line, false); } @@ -585,7 +585,7 @@ pg_ent::enumerate_ad () fetch_user_arg_t arg; arg.type = SID_arg; arg.sid = &sid; - char *line = pg.fetch_account_from_windows (arg, group, &cldap); + char *line = pg.fetch_account_from_windows (arg, &cldap); if (line) return pg.add_account_post_fetch (line, false); } @@ -599,7 +599,7 @@ pw_ent::enumerate_caches () if (!max && from_files) { pwdgrp &prf = cygheap->pg.pwd_cache.file; - prf.check_file (false); + prf.check_file (); if (cnt < prf.cached_users ()) return &prf.passwd ()[cnt++].p; cnt = 0; diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h index 41098de6e..0d2d9cc20 100644 --- a/winsup/cygwin/pwdgrp.h +++ b/winsup/cygwin/pwdgrp.h @@ -108,15 +108,12 @@ class pwdgrp void *add_account_from_file (cygpsid &sid); void *add_account_from_file (const char *name); void *add_account_from_file (uint32_t id); - void *add_account_from_windows (cygpsid &sid, bool group, - cyg_ldap *pldap = NULL); - void *add_account_from_windows (const char *name, bool group, - cyg_ldap *pldap = NULL); - void *add_account_from_windows (uint32_t id, bool group, - cyg_ldap *pldap = NULL); + 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); 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, bool group, + char *fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap = NULL); pwdgrp *prep_tls_pwbuf (); pwdgrp *prep_tls_grbuf (); @@ -125,9 +122,10 @@ public: ULONG cached_users () const { return curr_lines; } ULONG cached_groups () const { return curr_lines; } POBJECT_ATTRIBUTES file_attr () { return &attr; } - bool check_file (bool group); + bool check_file (); 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) { return (struct passwd *) add_account_from_file (sid); } @@ -136,17 +134,18 @@ public: struct passwd *add_user_from_file (uint32_t id) { return (struct passwd *) add_account_from_file (id); } struct passwd *add_user_from_windows (cygpsid &sid, cyg_ldap *pldap = NULL) - { return (struct passwd *) add_account_from_windows (sid, false, pldap); } + { return (struct passwd *) add_account_from_windows (sid, pldap); } struct passwd *add_user_from_windows (const char *name, cyg_ldap* pldap = NULL) - { return (struct passwd *) add_account_from_windows (name, false, pldap); } + { return (struct passwd *) add_account_from_windows (name, pldap); } struct passwd *add_user_from_windows (uint32_t id, cyg_ldap *pldap = NULL) - { return (struct passwd *) add_account_from_windows (id, false, pldap); } + { return (struct passwd *) add_account_from_windows (id, pldap); } struct passwd *find_user (cygpsid &sid); struct passwd *find_user (const char *name); struct passwd *find_user (uid_t uid); 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_file (cygpsid &sid) { return (struct group *) add_account_from_file (sid); } @@ -155,12 +154,12 @@ public: struct group *add_group_from_file (uint32_t id) { return (struct group *) add_account_from_file (id); } struct group *add_group_from_windows (cygpsid &sid, cyg_ldap *pldap = NULL) - { return (struct group *) add_account_from_windows (sid, true, pldap); } + { return (struct group *) add_account_from_windows (sid, pldap); } struct group *add_group_from_windows (const char *name, cyg_ldap *pldap = NULL) - { return (struct group *) add_account_from_windows (name, true, pldap); } + { return (struct group *) add_account_from_windows (name, pldap); } struct group *add_group_from_windows (uint32_t id, cyg_ldap *pldap = NULL) - { return (struct group *) add_account_from_windows (id, true, pldap); } + { return (struct group *) add_account_from_windows (id, pldap); } struct group *find_group (cygpsid &sid); struct group *find_group (const char *name); struct group *find_group (gid_t gid); diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc index efda17a1f..d1304ebff 100644 --- a/winsup/cygwin/uinfo.cc +++ b/winsup/cygwin/uinfo.cc @@ -993,49 +993,49 @@ pwdgrp::add_account_from_file (uint32_t id) } void * -pwdgrp::add_account_from_windows (cygpsid &sid, bool group, cyg_ldap *pldap) +pwdgrp::add_account_from_windows (cygpsid &sid, cyg_ldap *pldap) { fetch_user_arg_t arg; arg.type = SID_arg; arg.sid = &sid; - char *line = fetch_account_from_windows (arg, group, 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 (group) + if (is_group ()) return (prep_tls_grbuf ())->add_account_post_fetch (line, false); return (prep_tls_pwbuf ())->add_account_post_fetch (line, false); } void * -pwdgrp::add_account_from_windows (const char *name, bool group, cyg_ldap *pldap) +pwdgrp::add_account_from_windows (const char *name, cyg_ldap *pldap) { fetch_user_arg_t arg; arg.type = NAME_arg; arg.name = name; - char *line = fetch_account_from_windows (arg, group, 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 (group) + if (is_group ()) return (prep_tls_grbuf ())->add_account_post_fetch (line, false); return (prep_tls_pwbuf ())->add_account_post_fetch (line, false); } void * -pwdgrp::add_account_from_windows (uint32_t id, bool group, cyg_ldap *pldap) +pwdgrp::add_account_from_windows (uint32_t id, cyg_ldap *pldap) { fetch_user_arg_t arg; arg.type = ID_arg; arg.id = id; - char *line = fetch_account_from_windows (arg, group, 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 (group) + if (is_group ()) return (prep_tls_grbuf ())->add_account_post_fetch (line, false); return (prep_tls_pwbuf ())->add_account_post_fetch (line, false); } @@ -1054,14 +1054,14 @@ pwdgrp::add_account_from_windows (uint32_t id, bool group, cyg_ldap *pldap) The return code indicates to the calling function if the file exists. */ bool -pwdgrp::check_file (bool group) +pwdgrp::check_file () { FILE_BASIC_INFORMATION fbi; NTSTATUS status; if (!path.Buffer) { - PCWSTR rel_path = group ? L"\\etc\\group" : L"\\etc\\passwd"; + PCWSTR rel_path = is_group () ? L"\\etc\\group" : L"\\etc\\passwd"; path.Buffer = (PWCHAR) cmalloc_abort (HEAP_BUF, (wcslen (cygheap->installation_root) + wcslen (rel_path) + 1) @@ -1091,7 +1091,7 @@ pwdgrp::check_file (bool group) int curr = curr_lines; curr_lines = 0; for (int i = 0; i < curr; ++i) - cfree (group ? this->group ()[i].g.gr_name + cfree (is_group () ? this->group ()[i].g.gr_name : this->passwd ()[i].p.pw_name); pglock.release (); } @@ -1186,8 +1186,7 @@ fetch_posix_offset (PDS_DOMAIN_TRUSTSW td, cyg_ldap *cldap) } char * -pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group, - cyg_ldap *pldap) +pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap) { /* Used in LookupAccount calls. */ WCHAR namebuf[UNLEN + 1], *name = namebuf; @@ -1244,7 +1243,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group, PWCHAR val; if (cldap->open (NULL) - && cldap->fetch_ad_account (sid, group) + && cldap->fetch_ad_account (sid, is_group ()) && (val = cldap->get_group_name ())) { wcpcpy (name, val); @@ -1367,7 +1366,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group, { /* UNIX (unknown NFS or Samba) user account. */ __small_swprintf (sidstr, L"S-1-22-%u-%u", - group ? 2 : 1, arg.id & UNIX_POSIX_MASK); + is_group () ? 2 : 1, arg.id & UNIX_POSIX_MASK); /* LookupAccountSidW will fail. */ sid = csid = sidstr; break; @@ -1503,7 +1502,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group, { /* We only care for the extended user information if we're creating a passwd entry and the account is, in fact, a user. */ - if (group || acc_type != SidTypeUser) + if (is_group () || acc_type != SidTypeUser) break; /* Default primary group. If the sid is the current user, fetch @@ -1519,7 +1518,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group, /* Use LDAP to fetch domain account infos. */ if (!cldap->open (NULL)) break; - if (cldap->fetch_ad_account (sid, group)) + if (cldap->fetch_ad_account (sid, is_group ())) { PWCHAR val; @@ -1780,14 +1779,14 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group, sid_sub_auth_count (sid) = sid_sub_auth_count (sid) + 1; wcscpy (dom, domain); __small_swprintf (name = namebuf, L"%W(%u)", - group ? L"Group" : L"User", + is_group () ? L"Group" : L"User", sid_sub_auth_rid (sid)); uid = posix_offset + sid_sub_auth_rid (sid); } else { wcpcpy (dom, L"Unknown"); - wcpcpy (name = namebuf, group ? L"Group" : L"User"); + wcpcpy (name = namebuf, is_group () ? L"Group" : L"User"); } name_style = fully_qualified; acc_type = SidTypeUnknown; @@ -1802,12 +1801,12 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, bool group, if (gid == ILLEGAL_GID) gid = uid; if (name_style >= fully_qualified) - p = wcpcpy (p, user ? group ? L"Posix_Group" : L"Posix_User" : dom); + p = wcpcpy (p, user ? is_group () ? L"Posix_Group" : L"Posix_User" : dom); if (name_style >= plus_prepended) p = wcpcpy (p, cygheap->pg.nss_separator ()); wcpcpy (p, user ?: name); - if (group) + if (is_group ()) __small_swprintf (linebuf, L"%W:%W:%u:", posix_name, sid.string (sidstr), uid); /* For non-users, create a passwd entry which doesn't allow interactive