+Wed Jul 26 10:59:00 2000 Corinna Vinschen <corinna@vinschen.de>
+
+ * passwd.cc: Change name of passwd_in_memory_p to passwd_state.
+ Change type to enum. Change storage class to static. Adjust comments.
+ (read_etc_passwd): Set passwd_state to different values when loaded
+ from file in contrast to being emulated.
+ (search_for): Return default passwd entry if passwd is emulated or
+ it's a request for the current user. Otherwise return NULL.
+
Tue Jul 25 21:50:42 2000 Christopher Faylor <cgf@cygnus.com>
* syscalls.cc (statfs): Use path_conv method to convert input path.
static int curr_lines = 0;
static int max_lines = 0;
-/* Set to 1 when /etc/passwd has been read in by read_etc_passwd (). */
-/* Functions in this file need to check the value of passwd_in_memory_p
+/* Set to loaded when /etc/passwd has been read in by read_etc_passwd ().
+ Set to emulated if passwd is emulated. */
+/* Functions in this file need to check the value of passwd_state
and read in the password file if it isn't set. */
-int passwd_in_memory_p = 0;
+enum pwd_state {
+ uninitialized = 0,
+ emulated,
+ loaded
+};
+static pwd_state passwd_state = uninitialized;
/* Position in the passwd cache */
#ifdef _MT_SAFE
}
/* Read in /etc/passwd and save contents in the password cache.
- This sets passwd_in_memory_p to 1 so functions in this file can
- tell that /etc/passwd has been read in */
+ This sets passwd_state to loaded or emulated so functions in this file can
+ tell that /etc/passwd has been read in or will be emulated. */
void
read_etc_passwd ()
{
}
fclose (f);
+ passwd_state = loaded;
}
else
{
snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh", user_name,
DEFAULT_UID, DEFAULT_GID, getenv ("HOME") ?: "/");
add_pwd_line (linebuf);
+ passwd_state = emulated;
}
- passwd_in_memory_p = 1;
}
/* Cygwin internal */
return res;
}
- return default_pw;
+ /* Return default passwd entry if passwd is emulated or it's a
+ request for the current user. */
+ if (passwd_state != loaded
+ || (! name && uid == myself->uid)
+ || ( name && strcasematch(name, myself->username)))
+ return default_pw;
+
+ return NULL;
}
extern "C" struct passwd *
getpwuid (uid_t uid)
{
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
return search_for (uid, 0);
extern "C" struct passwd *
getpwnam (const char *name)
{
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
return search_for (0, name);
extern "C" struct passwd *
getpwent (void)
{
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
if (pw_pos < curr_lines)
extern "C" struct passwd *
getpwduid (uid_t)
{
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
return NULL;
extern "C" void
setpwent (void)
{
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
pw_pos = 0;
extern "C" void
endpwent (void)
{
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
pw_pos = 0;
extern "C" int
setpassent ()
{
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
return 0;
#endif
struct termios ti, newti;
- if (!passwd_in_memory_p)
+ if (passwd_state == uninitialized)
read_etc_passwd();
if (dtable.not_open (0))