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/passwd.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/passwd.cc')
-rw-r--r-- | winsup/cygwin/passwd.cc | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc index 2aca84c5d..d87864f52 100644 --- a/winsup/cygwin/passwd.cc +++ b/winsup/cygwin/passwd.cc @@ -30,8 +30,7 @@ static struct passwd *passwd_buf; /* passwd contents in memory */ static int curr_lines; static int max_lines; -static pwdgrp_check passwd_state; - +static pwdgrp pr; /* Position in the passwd cache */ #ifdef _MT_SAFE @@ -40,7 +39,7 @@ static pwdgrp_check passwd_state; static int pw_pos = 0; #endif -/* Remove a : teminated string from the buffer, and increment the pointer */ +/* Remove a : terminated string from the buffer, and increment the pointer */ static char * grab_string (char **p) { @@ -122,48 +121,37 @@ class passwd_lock pthread_mutex_t NO_COPY passwd_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER; /* Read in /etc/passwd and save contents in the password cache. - This sets passwd_state to loaded or emulated so functions in this file can + This sets pr to loaded or emulated so functions in this file can tell that /etc/passwd has been read in or will be emulated. */ static void read_etc_passwd () { - static pwdgrp_read pr; - /* A mutex is ok for speed here - pthreads will use critical sections not * mutexes for non-shared mutexes in the future. Also, this function will - * at most be called once from each thread, after that the passwd_state + * at most be called once from each thread, after that the pr * test will succeed */ passwd_lock here (cygwin_finished_initializing); /* if we got blocked by the mutex, then etc_passwd may have been processed */ - if (passwd_state.isinitializing ()) + if (pr.isinitializing ()) { curr_lines = 0; - if (pr.open ("/etc/passwd")) - { - char *line; - while ((line = pr.gets ()) != NULL) - add_pwd_line (line); - - passwd_state.set_last_modified (pr.get_fhandle (), pr.get_fname ()); - pr.close (); - debug_printf ("Read /etc/passwd, %d lines", curr_lines); - } - passwd_state = loaded; + if (!pr.load ("/etc/passwd", add_pwd_line)) + debug_printf ("pr.load failed"); static char linebuf[1024]; char strbuf[128] = ""; BOOL searchentry = TRUE; - __uid32_t default_uid = DEFAULT_UID; struct passwd *pw; if (wincap.has_security ()) { + static char pretty_ls[] = "????????:*:-1:-1:"; + add_pwd_line (pretty_ls); cygsid tu = cygheap->user.sid (); tu.string (strbuf); - if (myself->uid == ILLEGAL_UID - && (searchentry = !internal_getpwsid (tu))) - default_uid = DEFAULT_UID_NT; + if (myself->uid == ILLEGAL_UID) + searchentry = !internal_getpwsid (tu); } else if (myself->uid == ILLEGAL_UID) searchentry = !internal_getpwuid (DEFAULT_UID); @@ -173,11 +161,12 @@ read_etc_passwd () myself->uid != (__uid32_t) pw->pw_uid && !internal_getpwuid (myself->uid)))) { + (void) cygheap->user.ontherange (CH_HOME, NULL); snprintf (linebuf, sizeof (linebuf), "%s:*:%lu:%lu:,%s:%s:/bin/sh", cygheap->user.name (), - myself->uid == ILLEGAL_UID ? default_uid : myself->uid, + myself->uid == ILLEGAL_UID ? DEFAULT_UID_NT : myself->uid, myself->gid, - strbuf, getenv ("HOME") ?: "/"); + strbuf, getenv ("HOME") ?: ""); debug_printf ("Completing /etc/passwd: %s", linebuf); add_pwd_line (linebuf); } @@ -192,7 +181,7 @@ internal_getpwsid (cygsid &sid) char *ptr1, *ptr2, *endptr; char sid_string[128] = {0,','}; - if (passwd_state.isuninitialized ()) + if (pr.isuninitialized ()) read_etc_passwd (); if (sid.string (sid_string + 2)) @@ -211,8 +200,8 @@ internal_getpwsid (cygsid &sid) struct passwd * internal_getpwuid (__uid32_t uid, BOOL check) { - if (passwd_state.isuninitialized () - || (check && passwd_state.isinitializing ())) + if (pr.isuninitialized () + || (check && pr.isinitializing ())) read_etc_passwd (); for (int i = 0; i < curr_lines; i++) @@ -224,8 +213,8 @@ internal_getpwuid (__uid32_t uid, BOOL check) struct passwd * internal_getpwnam (const char *name, BOOL check) { - if (passwd_state.isuninitialized () - || (check && passwd_state.isinitializing ())) + if (pr.isuninitialized () + || (check && pr.isinitializing ())) read_etc_passwd (); for (int i = 0; i < curr_lines; i++) @@ -347,7 +336,7 @@ getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, s extern "C" struct passwd * getpwent (void) { - if (passwd_state.isinitializing ()) + if (pr.isinitializing ()) read_etc_passwd (); if (pw_pos < curr_lines) @@ -390,7 +379,7 @@ getpass (const char * prompt) #endif struct termios ti, newti; - if (passwd_state.isinitializing ()) + if (pr.isinitializing ()) read_etc_passwd (); cygheap_fdget fhstdin (0); |