* 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.
This commit is contained in:
parent
00edcbb0cb
commit
1d8fc847ee
@ -1,3 +1,12 @@
|
|||||||
|
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>
|
Tue Jul 25 21:50:42 2000 Christopher Faylor <cgf@cygnus.com>
|
||||||
|
|
||||||
* syscalls.cc (statfs): Use path_conv method to convert input path.
|
* syscalls.cc (statfs): Use path_conv method to convert input path.
|
||||||
|
@ -21,10 +21,16 @@ static struct passwd *passwd_buf = NULL; /* passwd contents in memory */
|
|||||||
static int curr_lines = 0;
|
static int curr_lines = 0;
|
||||||
static int max_lines = 0;
|
static int max_lines = 0;
|
||||||
|
|
||||||
/* Set to 1 when /etc/passwd has been read in by read_etc_passwd (). */
|
/* Set to loaded 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 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. */
|
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 */
|
/* Position in the passwd cache */
|
||||||
#ifdef _MT_SAFE
|
#ifdef _MT_SAFE
|
||||||
@ -101,8 +107,8 @@ add_pwd_line (char *line)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read in /etc/passwd and save contents in the password cache.
|
/* 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
|
This sets passwd_state to loaded or emulated so functions in this file can
|
||||||
tell that /etc/passwd has been read in */
|
tell that /etc/passwd has been read in or will be emulated. */
|
||||||
void
|
void
|
||||||
read_etc_passwd ()
|
read_etc_passwd ()
|
||||||
{
|
{
|
||||||
@ -121,6 +127,7 @@ read_etc_passwd ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose (f);
|
fclose (f);
|
||||||
|
passwd_state = loaded;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -135,8 +142,8 @@ read_etc_passwd ()
|
|||||||
snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh", user_name,
|
snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh", user_name,
|
||||||
DEFAULT_UID, DEFAULT_GID, getenv ("HOME") ?: "/");
|
DEFAULT_UID, DEFAULT_GID, getenv ("HOME") ?: "/");
|
||||||
add_pwd_line (linebuf);
|
add_pwd_line (linebuf);
|
||||||
|
passwd_state = emulated;
|
||||||
}
|
}
|
||||||
passwd_in_memory_p = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Cygwin internal */
|
/* Cygwin internal */
|
||||||
@ -161,13 +168,20 @@ search_for (uid_t uid, const char *name)
|
|||||||
return res;
|
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 *
|
extern "C" struct passwd *
|
||||||
getpwuid (uid_t uid)
|
getpwuid (uid_t uid)
|
||||||
{
|
{
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
return search_for (uid, 0);
|
return search_for (uid, 0);
|
||||||
@ -176,7 +190,7 @@ getpwuid (uid_t uid)
|
|||||||
extern "C" struct passwd *
|
extern "C" struct passwd *
|
||||||
getpwnam (const char *name)
|
getpwnam (const char *name)
|
||||||
{
|
{
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
return search_for (0, name);
|
return search_for (0, name);
|
||||||
@ -185,7 +199,7 @@ getpwnam (const char *name)
|
|||||||
extern "C" struct passwd *
|
extern "C" struct passwd *
|
||||||
getpwent (void)
|
getpwent (void)
|
||||||
{
|
{
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
if (pw_pos < curr_lines)
|
if (pw_pos < curr_lines)
|
||||||
@ -197,7 +211,7 @@ getpwent (void)
|
|||||||
extern "C" struct passwd *
|
extern "C" struct passwd *
|
||||||
getpwduid (uid_t)
|
getpwduid (uid_t)
|
||||||
{
|
{
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -206,7 +220,7 @@ getpwduid (uid_t)
|
|||||||
extern "C" void
|
extern "C" void
|
||||||
setpwent (void)
|
setpwent (void)
|
||||||
{
|
{
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
pw_pos = 0;
|
pw_pos = 0;
|
||||||
@ -215,7 +229,7 @@ setpwent (void)
|
|||||||
extern "C" void
|
extern "C" void
|
||||||
endpwent (void)
|
endpwent (void)
|
||||||
{
|
{
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
pw_pos = 0;
|
pw_pos = 0;
|
||||||
@ -224,7 +238,7 @@ endpwent (void)
|
|||||||
extern "C" int
|
extern "C" int
|
||||||
setpassent ()
|
setpassent ()
|
||||||
{
|
{
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -240,7 +254,7 @@ getpass (const char * prompt)
|
|||||||
#endif
|
#endif
|
||||||
struct termios ti, newti;
|
struct termios ti, newti;
|
||||||
|
|
||||||
if (!passwd_in_memory_p)
|
if (passwd_state == uninitialized)
|
||||||
read_etc_passwd();
|
read_etc_passwd();
|
||||||
|
|
||||||
if (dtable.not_open (0))
|
if (dtable.not_open (0))
|
||||||
|
Loading…
Reference in New Issue
Block a user