* 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.
This commit is contained in:
Christopher Faylor
2003-01-17 05:18:30 +00:00
parent d4d80d8c65
commit 14ea50290a
7 changed files with 258 additions and 190 deletions

View File

@ -389,3 +389,88 @@ cygheap_user::env_name (const char *name, size_t namelen)
(void) domain ();
return pwinname;
}
int NO_COPY etc::curr_ix = -1;
bool NO_COPY etc::sawchange[MAX_ETC_FILES];
const NO_COPY char *etc::fn[MAX_ETC_FILES];
FILETIME NO_COPY etc::last_modified[MAX_ETC_FILES];
int
etc::init (int n, const char *etc_fn)
{
if (n >= 0)
/* ok */;
else if (++curr_ix < MAX_ETC_FILES)
n = curr_ix;
else
api_fatal ("internal error");
fn[n] = etc_fn;
sawchange[n] = false;
paranoid_printf ("curr_ix %d, n %d", curr_ix, n);
return curr_ix;
}
bool
etc::dir_changed (int n)
{
bool res = sawchange[n];
if (!res)
{
static HANDLE NO_COPY changed_h;
if (!changed_h)
{
path_conv pwd ("/etc");
changed_h = FindFirstChangeNotification (pwd, FALSE,
FILE_NOTIFY_CHANGE_LAST_WRITE);
if (changed_h == INVALID_HANDLE_VALUE)
system_printf ("Can't open /etc for checking, %E", (char *) pwd,
changed_h);
}
if (changed_h == INVALID_HANDLE_VALUE)
res = true;
else if (WaitForSingleObject (changed_h, 0) == WAIT_OBJECT_0)
{
(void) FindNextChangeNotification (changed_h);
memset (sawchange, true, sizeof sawchange);
res = true;
}
}
paranoid_printf ("%s res %d", fn[n], res);
return res;
}
bool
etc::file_changed (int n)
{
bool res = false;
if (!fn[n])
res = true;
else if (dir_changed (n))
{
HANDLE h;
WIN32_FIND_DATA data;
if ((h = FindFirstFile (fn[n], &data)) == INVALID_HANDLE_VALUE)
res = true;
else
{
FindClose (h);
if (CompareFileTime (&data.ftLastWriteTime, last_modified + n) > 0)
res = true;
}
}
sawchange[n] = false;
paranoid_printf ("%s res %d", fn[n], res);
return res;
}
void
etc::set_last_modified (int n, FILETIME& ft)
{
last_modified[n] = ft;
sawchange[n] = false;
}