diff options
author | Christopher Faylor <me@cgf.cx> | 2003-01-17 08:18:30 +0300 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2003-01-17 08:18:30 +0300 |
commit | 14ea50290a1f9f3954cc562ab877c1950ab8a2bb (patch) | |
tree | 2d4965c5bb977b8e1b41f5125aa4b24ba7c7ba38 /winsup/cygwin/grp.cc | |
parent | d4d80d8c65042953c8bd5514c44c8bb2d31dd227 (diff) |
* grp.cc (read_etc_group): On NT, add a line for gid = -1. Change name
"unknown" to "mkgroup".
(internal_getgrgid): Do not return default in nontsec case.
(internal_getgroups): Add argument srchsid and look for it in groups if not
NULL.
* passwd.cc (read_etc_passwd): On NT, add a line for uid = -1. Use same
default uid for Win95 and NT. Call cygheap_user::ontherange to initialize
HOME.
* cygheap.cc (init_cygheap::etc_changed): Move to uinfo.cc.
* cygheap.h (init_cygheap::etc_changed_h): Remove.
(init_cygheap::etc_changed): Ditto.
* grp.cc (group_state): Remove. Use gr instead throughout.
(gr): Define as class pwdgrp.
(read_etc_group): Remove gr definition. Remove calls to set_last_modified and
close. Pass add_grp to gr.load to load file.
* passwd.cc (passwd_state): Remove. Use pr instead, throughout.
(pr): Define as class pwdgrp.
(read_etc_passwd): Remove pr definition. Remove calls to set_last_modified and
close. Pass add_pwd_line to pr.load to load file.
* pwdgrp.h (etc): New helper class for pwdgrp.
(pwdgrp): Combine pwdgrp_check and pwdgrp_read into one class. Remove file_w32
and last_modified fields.
(pwdgrp::set_last_modified): Remove.
(pwdgrp::isinitializing): Remove FindFirstFile stuff. Move to
etc::file_changed.
(pwdgrp::load): Rename from 'open'. Call etc::init to initialize etc scanning.
Close file handle after reading buffer into memory. Parse buffer by calling
second argument.
(pwdgrp::gets): Reorganize slightly to rely on eptr starting at beginning of
buffer. Free buffer when memory exhausted.
(pwdgrp::close): Remove.
* uinfo.cc (etc::dir_changed): New function.
(etc::init): Ditto.
(etc::file_changed): Ditto.
(etc::set_last_modified): Ditto.
Diffstat (limited to 'winsup/cygwin/grp.cc')
-rw-r--r-- | winsup/cygwin/grp.cc | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc index 51ccd066c..9ce2787d0 100644 --- a/winsup/cygwin/grp.cc +++ b/winsup/cygwin/grp.cc @@ -40,8 +40,8 @@ static int max_lines; static int grp_pos = 0; #endif -static pwdgrp_check group_state; -static char * NO_COPY null_ptr = NULL; +static pwdgrp gr; +static char * NO_COPY null_ptr; static int parse_grp (struct __group32 &grp, char *line) @@ -129,35 +129,24 @@ pthread_mutex_t NO_COPY group_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INIT static void read_etc_group () { - static pwdgrp_read gr; - group_lock here (cygwin_finished_initializing); /* if we got blocked by the mutex, then etc_group may have been processed */ - if (group_state.isinitializing ()) + if (gr.isinitializing ()) { for (int i = 0; i < curr_lines; i++) if ((group_buf + i)->gr_mem != &null_ptr) free ((group_buf + i)->gr_mem); curr_lines = 0; - if (gr.open ("/etc/group")) - { - char *line; - while ((line = gr.gets ()) != NULL) - add_grp_line (line); - - group_state.set_last_modified (gr.get_fhandle (), gr.get_fname ()); - gr.close (); - debug_printf ("Read /etc/group, %d lines", curr_lines); - } - group_state = loaded; + if (!gr.load ("/etc/group", add_grp_line)) + debug_printf ("gr.load failed"); /* Complete /etc/group in memory if needed */ if (!internal_getgrgid (myself->gid)) { static char linebuf [200]; - char group_name [UNLEN + 1] = "unknown"; + char group_name [UNLEN + 1] = "mkgroup"; char strbuf[128] = ""; if (wincap.has_security ()) @@ -173,6 +162,9 @@ read_etc_group () debug_printf ("Completing /etc/group: %s", linebuf); add_grp_line (linebuf); } + static char pretty_ls[] = "????????::-1:"; + if (wincap.has_security ()) + add_grp_line (pretty_ls); } return; } @@ -182,7 +174,7 @@ internal_getgrsid (cygsid &sid) { char sid_string[128]; - if (group_state.isuninitialized ()) + if (gr.isuninitialized ()) read_etc_group (); if (sid.string (sid_string)) @@ -195,27 +187,19 @@ internal_getgrsid (cygsid &sid) struct __group32 * internal_getgrgid (__gid32_t gid, BOOL check) { - struct __group32 * default_grp = NULL; - - if (group_state.isuninitialized () - || (check && group_state.isinitializing ())) + if (gr.isuninitialized () || (check && gr.isinitializing ())) read_etc_group (); for (int i = 0; i < curr_lines; i++) - { - if (group_buf[i].gr_gid == myself->gid) - default_grp = group_buf + i; - if (group_buf[i].gr_gid == gid) - return group_buf + i; - } - return allow_ntsec || gid != ILLEGAL_GID ? NULL : default_grp; + if (group_buf[i].gr_gid == gid) + return group_buf + i; + return NULL; } struct __group32 * internal_getgrnam (const char *name, BOOL check) { - if (group_state.isuninitialized () - || (check && group_state.isinitializing ())) + if (gr.isuninitialized () || (check && gr.isinitializing ())) read_etc_group (); for (int i = 0; i < curr_lines; i++) @@ -280,7 +264,7 @@ endgrent () extern "C" struct __group32 * getgrent32 () { - if (group_state.isinitializing ()) + if (gr.isinitializing ()) read_etc_group (); if (grp_pos < curr_lines) @@ -307,7 +291,7 @@ setgrent () struct __group32 * internal_getgrent (int pos) { - if (group_state.isuninitialized ()) + if (gr.isuninitialized ()) read_etc_group (); if (pos < curr_lines) @@ -316,7 +300,7 @@ internal_getgrent (int pos) } int -internal_getgroups (int gidsetsize, __gid32_t *grouplist) +internal_getgroups (int gidsetsize, __gid32_t *grouplist, cygsid * srchsid) { HANDLE hToken = NULL; DWORD size; @@ -345,6 +329,13 @@ internal_getgroups (int gidsetsize, __gid32_t *grouplist) { cygsid sid; + if (srchsid) + { + for (DWORD pg = 0; pg < groups->GroupCount; ++pg) + if (*srchsid == groups->Groups[pg].Sid) + return 1; + return 0; + } for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx) if (sid.getfromgr (gr)) for (DWORD pg = 0; pg < groups->GroupCount; ++pg) |