2000-02-17 20:38:33 +01:00
|
|
|
/* passwd.cc: getpwnam () and friends
|
|
|
|
|
* child_info.h, cygheap.h, fhandler_clipboard.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, thread.h, uinfo.cc, include/cygwin/acl.h: Fix copyright.
2002-02-10 14:50:13 +01:00
|
|
|
Copyright 1996, 1997, 1998, 2001, 2002 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "cygerrno.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "fhandler.h"
|
2001-08-07 10:56:22 +02:00
|
|
|
#include "path.h"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include "dtable.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "pinfo.h"
|
2000-11-15 01:13:09 +01:00
|
|
|
#include "cygheap.h"
|
2000-09-07 18:23:51 +02:00
|
|
|
#include <sys/termios.h>
|
2001-09-09 18:52:37 +02:00
|
|
|
#include "pwdgrp.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Read /etc/passwd only once for better performance. This is done
|
|
|
|
on the first call that needs information from it. */
|
|
|
|
|
2001-09-06 05:39:18 +02:00
|
|
|
static struct passwd *passwd_buf; /* passwd contents in memory */
|
2002-11-20 18:10:05 +01:00
|
|
|
static int curr_lines = -1;
|
2001-09-06 05:39:18 +02:00
|
|
|
static int max_lines;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-09-09 18:52:37 +02:00
|
|
|
static pwdgrp_check passwd_state;
|
2001-08-07 10:56:22 +02:00
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Position in the passwd cache */
|
|
|
|
#ifdef _MT_SAFE
|
2001-01-28 06:51:15 +01:00
|
|
|
#define pw_pos _reent_winsup ()->_pw_pos
|
2000-02-17 20:38:33 +01:00
|
|
|
#else
|
|
|
|
static int pw_pos = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Remove a : teminated string from the buffer, and increment the pointer */
|
|
|
|
static char *
|
|
|
|
grab_string (char **p)
|
|
|
|
{
|
|
|
|
char *src = *p;
|
|
|
|
char *res = src;
|
|
|
|
|
|
|
|
while (*src && *src != ':' && *src != '\n')
|
|
|
|
src++;
|
|
|
|
|
|
|
|
if (*src == ':')
|
|
|
|
{
|
|
|
|
*src = 0;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
*p = src;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* same, for ints */
|
|
|
|
static int
|
|
|
|
grab_int (char **p)
|
|
|
|
{
|
|
|
|
char *src = *p;
|
2000-07-01 19:30:35 +02:00
|
|
|
int val = strtol (src, NULL, 10);
|
2000-02-17 20:38:33 +01:00
|
|
|
while (*src && *src != ':' && *src != '\n')
|
|
|
|
src++;
|
|
|
|
if (*src == ':')
|
|
|
|
src++;
|
|
|
|
*p = src;
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse /etc/passwd line into passwd structure. */
|
2002-11-20 18:10:05 +01:00
|
|
|
static int
|
2000-02-17 20:38:33 +01:00
|
|
|
parse_pwd (struct passwd &res, char *buf)
|
|
|
|
{
|
|
|
|
/* Allocate enough room for the passwd struct and all the strings
|
|
|
|
in it in one go */
|
|
|
|
size_t len = strlen (buf);
|
2002-06-05 13:10:15 +02:00
|
|
|
if (buf[--len] == '\r')
|
|
|
|
buf[len] = '\0';
|
2002-11-20 18:10:05 +01:00
|
|
|
if (len < 6)
|
|
|
|
return 0;
|
2002-06-05 13:10:15 +02:00
|
|
|
|
|
|
|
res.pw_name = grab_string (&buf);
|
|
|
|
res.pw_passwd = grab_string (&buf);
|
|
|
|
res.pw_uid = grab_int (&buf);
|
|
|
|
res.pw_gid = grab_int (&buf);
|
2000-02-17 20:38:33 +01:00
|
|
|
res.pw_comment = 0;
|
2002-06-05 13:10:15 +02:00
|
|
|
res.pw_gecos = grab_string (&buf);
|
|
|
|
res.pw_dir = grab_string (&buf);
|
|
|
|
res.pw_shell = grab_string (&buf);
|
2002-11-20 18:10:05 +01:00
|
|
|
return 1;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add one line from /etc/passwd into the password cache */
|
|
|
|
static void
|
|
|
|
add_pwd_line (char *line)
|
|
|
|
{
|
|
|
|
if (curr_lines >= max_lines)
|
|
|
|
{
|
|
|
|
max_lines += 10;
|
|
|
|
passwd_buf = (struct passwd *) realloc (passwd_buf, max_lines * sizeof (struct passwd));
|
|
|
|
}
|
2002-11-20 18:10:05 +01:00
|
|
|
if (parse_pwd (passwd_buf[curr_lines], line))
|
|
|
|
curr_lines++;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2001-09-28 09:01:22 +02:00
|
|
|
class passwd_lock
|
|
|
|
{
|
2002-02-17 05:59:55 +01:00
|
|
|
bool armed;
|
|
|
|
static NO_COPY pthread_mutex_t mutex;
|
2001-09-28 09:01:22 +02:00
|
|
|
public:
|
2002-02-17 05:59:55 +01:00
|
|
|
passwd_lock (bool doit)
|
|
|
|
{
|
|
|
|
if (doit)
|
|
|
|
pthread_mutex_lock (&mutex);
|
|
|
|
armed = doit;
|
|
|
|
}
|
2001-09-28 09:23:18 +02:00
|
|
|
~passwd_lock ()
|
|
|
|
{
|
2002-02-17 05:59:55 +01:00
|
|
|
if (armed)
|
2001-09-28 09:23:18 +02:00
|
|
|
pthread_mutex_unlock (&mutex);
|
|
|
|
}
|
2001-09-28 09:01:22 +02:00
|
|
|
};
|
|
|
|
|
2002-02-17 05:59:55 +01:00
|
|
|
pthread_mutex_t NO_COPY passwd_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
2002-11-20 18:10:05 +01:00
|
|
|
/* Cygwin internal */
|
|
|
|
/* If this ever becomes non-reentrant, update all the getpw*_r functions */
|
|
|
|
static struct passwd *
|
|
|
|
search_for (__uid32_t uid, const char *name)
|
|
|
|
{
|
|
|
|
struct passwd *res = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < curr_lines; i++)
|
|
|
|
{
|
|
|
|
res = passwd_buf + i;
|
|
|
|
/* on Windows NT user names are case-insensitive */
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
if (strcasematch (name, res->pw_name))
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
else if (uid == (__uid32_t) res->pw_uid)
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-17 20:38:33 +01:00
|
|
|
/* Read in /etc/passwd and save contents in the password cache.
|
2000-07-26 13:48:38 +02:00
|
|
|
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. */
|
2002-11-20 18:10:05 +01:00
|
|
|
static void
|
2000-02-17 20:38:33 +01:00
|
|
|
read_etc_passwd ()
|
|
|
|
{
|
2002-06-05 13:10:15 +02:00
|
|
|
static pwdgrp_read pr;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-06-05 13:10:15 +02:00
|
|
|
/* 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
|
|
|
|
* 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 != uninitialized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (passwd_state != initializing)
|
|
|
|
{
|
|
|
|
passwd_state = initializing;
|
2002-11-20 18:10:05 +01:00
|
|
|
curr_lines = 0;
|
2002-06-05 13:10:15 +02:00
|
|
|
if (pr.open ("/etc/passwd"))
|
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
while ((line = pr.gets ()) != NULL)
|
2002-11-20 18:10:05 +01:00
|
|
|
add_pwd_line (line);
|
2002-06-05 13:10:15 +02:00
|
|
|
|
2002-09-22 05:38:57 +02:00
|
|
|
passwd_state.set_last_modified (pr.get_fhandle (), pr.get_fname ());
|
2002-06-05 13:10:15 +02:00
|
|
|
pr.close ();
|
|
|
|
debug_printf ("Read /etc/passwd, %d lines", curr_lines);
|
|
|
|
}
|
2002-11-20 18:10:05 +01:00
|
|
|
|
|
|
|
static char linebuf[1024];
|
|
|
|
char strbuf[128] = "";
|
|
|
|
BOOL searchentry = TRUE;
|
|
|
|
__uid32_t default_uid = DEFAULT_UID;
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
if (wincap.has_security ())
|
2002-06-05 13:10:15 +02:00
|
|
|
{
|
2002-11-20 18:10:05 +01:00
|
|
|
cygsid tu = cygheap->user.sid ();
|
|
|
|
tu.string (strbuf);
|
|
|
|
if (myself->uid == ILLEGAL_UID
|
|
|
|
&& (searchentry = !internal_getpwsid (tu)))
|
|
|
|
default_uid = DEFAULT_UID_NT;
|
2002-06-05 13:10:15 +02:00
|
|
|
}
|
2002-11-20 18:10:05 +01:00
|
|
|
if (searchentry &&
|
|
|
|
(!(pw = search_for (0, cygheap->user.name ())) ||
|
|
|
|
(myself->uid != ILLEGAL_UID &&
|
|
|
|
myself->uid != (__uid32_t) pw->pw_uid &&
|
|
|
|
!search_for (myself->uid, NULL))))
|
|
|
|
{
|
|
|
|
snprintf (linebuf, sizeof (linebuf), "%s:*:%lu:%lu:,%s:%s:/bin/sh",
|
|
|
|
cygheap->user.name (),
|
|
|
|
myself->uid == ILLEGAL_UID ? default_uid : myself->uid,
|
|
|
|
myself->gid,
|
|
|
|
strbuf, getenv ("HOME") ?: "/");
|
|
|
|
debug_printf ("Completing /etc/passwd: %s", linebuf);
|
|
|
|
add_pwd_line (linebuf);
|
|
|
|
}
|
|
|
|
passwd_state = loaded;
|
2002-06-05 13:10:15 +02:00
|
|
|
}
|
2001-09-28 09:01:22 +02:00
|
|
|
return;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-11-20 18:10:05 +01:00
|
|
|
struct passwd *
|
|
|
|
internal_getpwsid (cygsid &sid)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-11-20 18:10:05 +01:00
|
|
|
struct passwd *pw;
|
|
|
|
char *ptr1, *ptr2, *endptr;
|
|
|
|
char sid_string[128] = {0,','};
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-11-20 18:10:05 +01:00
|
|
|
if (curr_lines < 0 && passwd_state <= initializing)
|
|
|
|
read_etc_passwd ();
|
|
|
|
|
|
|
|
if (sid.string (sid_string + 2))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-11-20 18:10:05 +01:00
|
|
|
endptr = strchr (sid_string + 2, 0) - 1;
|
|
|
|
for (int i = 0; i < curr_lines; i++)
|
|
|
|
if ((pw = passwd_buf + i)->pw_dir > pw->pw_gecos + 8)
|
|
|
|
for (ptr1 = endptr, ptr2 = pw->pw_dir - 2;
|
|
|
|
*ptr1 == *ptr2; ptr2--)
|
|
|
|
if (!*--ptr1)
|
|
|
|
return pw;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2000-07-26 13:48:38 +02:00
|
|
|
return NULL;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" struct passwd *
|
2002-05-29 17:04:29 +02:00
|
|
|
getpwuid32 (__uid32_t uid)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-04-18 23:10:15 +02:00
|
|
|
if (passwd_state <= initializing)
|
2001-01-28 06:51:15 +01:00
|
|
|
read_etc_passwd ();
|
2001-06-26 16:47:48 +02:00
|
|
|
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_testcancel ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
return search_for (uid, 0);
|
|
|
|
}
|
|
|
|
|
2002-05-29 17:04:29 +02:00
|
|
|
extern "C" struct passwd *
|
|
|
|
getpwuid (__uid16_t uid)
|
|
|
|
{
|
|
|
|
return getpwuid32 (uid16touid32 (uid));
|
|
|
|
}
|
|
|
|
|
2001-06-26 16:47:48 +02:00
|
|
|
extern "C" int
|
2002-05-29 17:04:29 +02:00
|
|
|
getpwuid_r32 (__uid32_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
2001-04-18 23:10:15 +02:00
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if (!pwd || !buffer)
|
|
|
|
return ERANGE;
|
|
|
|
|
|
|
|
if (passwd_state <= initializing)
|
|
|
|
read_etc_passwd ();
|
|
|
|
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_testcancel ();
|
2001-04-21 16:23:47 +02:00
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
struct passwd *temppw = search_for (uid, 0);
|
|
|
|
|
|
|
|
if (!temppw)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check needed buffer size. */
|
2001-04-24 23:45:20 +02:00
|
|
|
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
|
2001-06-26 16:47:48 +02:00
|
|
|
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
|
2001-04-24 23:52:57 +02:00
|
|
|
strlen (temppw->pw_passwd) + 5;
|
2001-04-18 23:10:15 +02:00
|
|
|
if (needsize > bufsize)
|
|
|
|
return ERANGE;
|
|
|
|
|
|
|
|
/* make a copy of temppw */
|
|
|
|
*result = pwd;
|
|
|
|
pwd->pw_uid = temppw->pw_uid;
|
|
|
|
pwd->pw_gid = temppw->pw_gid;
|
|
|
|
pwd->pw_name = buffer;
|
2001-04-24 23:45:20 +02:00
|
|
|
pwd->pw_dir = pwd->pw_name + strlen (temppw->pw_name) + 1;
|
|
|
|
pwd->pw_shell = pwd->pw_dir + strlen (temppw->pw_dir) + 1;
|
|
|
|
pwd->pw_gecos = pwd->pw_shell + strlen (temppw->pw_shell) + 1;
|
2001-04-24 23:52:57 +02:00
|
|
|
pwd->pw_passwd = pwd->pw_gecos + strlen (temppw->pw_gecos) + 1;
|
2001-04-18 23:10:15 +02:00
|
|
|
strcpy (pwd->pw_name, temppw->pw_name);
|
|
|
|
strcpy (pwd->pw_dir, temppw->pw_dir);
|
|
|
|
strcpy (pwd->pw_shell, temppw->pw_shell);
|
2001-04-24 23:45:20 +02:00
|
|
|
strcpy (pwd->pw_gecos, temppw->pw_gecos);
|
2001-04-24 23:52:57 +02:00
|
|
|
strcpy (pwd->pw_passwd, temppw->pw_passwd);
|
2001-04-18 23:10:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-05-29 17:04:29 +02:00
|
|
|
extern "C" int
|
|
|
|
getpwuid_r (__uid16_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
|
|
|
{
|
|
|
|
return getpwuid_r32 (uid16touid32 (uid), pwd, buffer, bufsize, result);
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" struct passwd *
|
2000-02-17 20:38:33 +01:00
|
|
|
getpwnam (const char *name)
|
|
|
|
{
|
2001-04-18 23:10:15 +02:00
|
|
|
if (passwd_state <= initializing)
|
2001-01-28 06:51:15 +01:00
|
|
|
read_etc_passwd ();
|
2001-06-26 16:47:48 +02:00
|
|
|
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_testcancel ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
return search_for (0, name);
|
|
|
|
}
|
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
|
2001-06-26 16:47:48 +02:00
|
|
|
/* the max size buffer we can expect to
|
2001-04-18 23:10:15 +02:00
|
|
|
* use is returned via sysconf with _SC_GETPW_R_SIZE_MAX.
|
|
|
|
* This may need updating! - Rob Collins April 2001.
|
|
|
|
*/
|
|
|
|
extern "C" int
|
|
|
|
getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
|
|
|
{
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if (!pwd || !buffer || !nam)
|
|
|
|
return ERANGE;
|
|
|
|
|
|
|
|
if (passwd_state <= initializing)
|
|
|
|
read_etc_passwd ();
|
|
|
|
|
2002-09-22 05:38:57 +02:00
|
|
|
pthread_testcancel ();
|
2001-04-21 16:23:47 +02:00
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
struct passwd *temppw = search_for (0, nam);
|
|
|
|
|
|
|
|
if (!temppw)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* check needed buffer size. */
|
2001-04-24 23:45:20 +02:00
|
|
|
size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) +
|
2001-06-26 16:47:48 +02:00
|
|
|
strlen (temppw->pw_shell) + strlen (temppw->pw_gecos) +
|
2001-04-24 23:52:57 +02:00
|
|
|
strlen (temppw->pw_passwd) + 5;
|
2001-04-18 23:10:15 +02:00
|
|
|
if (needsize > bufsize)
|
|
|
|
return ERANGE;
|
2001-06-26 16:47:48 +02:00
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
/* make a copy of temppw */
|
|
|
|
*result = pwd;
|
|
|
|
pwd->pw_uid = temppw->pw_uid;
|
|
|
|
pwd->pw_gid = temppw->pw_gid;
|
|
|
|
pwd->pw_name = buffer;
|
2001-04-24 23:45:20 +02:00
|
|
|
pwd->pw_dir = pwd->pw_name + strlen (temppw->pw_name) + 1;
|
|
|
|
pwd->pw_shell = pwd->pw_dir + strlen (temppw->pw_dir) + 1;
|
|
|
|
pwd->pw_gecos = pwd->pw_shell + strlen (temppw->pw_shell) + 1;
|
2001-04-24 23:52:57 +02:00
|
|
|
pwd->pw_passwd = pwd->pw_gecos + strlen (temppw->pw_gecos) + 1;
|
2001-04-18 23:10:15 +02:00
|
|
|
strcpy (pwd->pw_name, temppw->pw_name);
|
|
|
|
strcpy (pwd->pw_dir, temppw->pw_dir);
|
|
|
|
strcpy (pwd->pw_shell, temppw->pw_shell);
|
2001-04-24 23:45:20 +02:00
|
|
|
strcpy (pwd->pw_gecos, temppw->pw_gecos);
|
2001-04-24 23:52:57 +02:00
|
|
|
strcpy (pwd->pw_passwd, temppw->pw_passwd);
|
2001-04-18 23:10:15 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" struct passwd *
|
2000-02-17 20:38:33 +01:00
|
|
|
getpwent (void)
|
|
|
|
{
|
2001-04-18 23:10:15 +02:00
|
|
|
if (passwd_state <= initializing)
|
2001-01-28 06:51:15 +01:00
|
|
|
read_etc_passwd ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (pw_pos < curr_lines)
|
|
|
|
return passwd_buf + pw_pos++;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" struct passwd *
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 14:38:51 +01:00
|
|
|
getpwduid (__uid16_t)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" void
|
2000-02-17 20:38:33 +01:00
|
|
|
setpwent (void)
|
|
|
|
{
|
|
|
|
pw_pos = 0;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" void
|
2000-02-17 20:38:33 +01:00
|
|
|
endpwent (void)
|
|
|
|
{
|
|
|
|
pw_pos = 0;
|
|
|
|
}
|
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" int
|
2000-02-17 20:38:33 +01:00
|
|
|
setpassent ()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-11-20 18:10:05 +01:00
|
|
|
#if 0 /* Unused */
|
2001-04-25 11:43:25 +02:00
|
|
|
/* Internal function. ONLY USE THIS INTERNALLY, NEVER `getpwent'!!! */
|
|
|
|
struct passwd *
|
|
|
|
internal_getpwent (int pos)
|
|
|
|
{
|
|
|
|
if (passwd_state <= initializing)
|
|
|
|
read_etc_passwd ();
|
|
|
|
|
|
|
|
if (pos < curr_lines)
|
|
|
|
return passwd_buf + pos;
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-11-20 18:10:05 +01:00
|
|
|
#endif
|
2001-04-25 11:43:25 +02:00
|
|
|
|
2000-02-21 06:20:38 +01:00
|
|
|
extern "C" char *
|
2000-02-17 20:38:33 +01:00
|
|
|
getpass (const char * prompt)
|
|
|
|
{
|
|
|
|
#ifdef _MT_SAFE
|
2001-01-28 06:51:15 +01:00
|
|
|
char *pass=_reent_winsup ()->_pass;
|
2000-02-17 20:38:33 +01:00
|
|
|
#else
|
|
|
|
static char pass[_PASSWORD_LEN];
|
|
|
|
#endif
|
|
|
|
struct termios ti, newti;
|
|
|
|
|
2001-04-18 23:10:15 +02:00
|
|
|
if (passwd_state <= initializing)
|
2001-01-28 06:51:15 +01:00
|
|
|
read_etc_passwd ();
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-10-16 01:39:33 +02:00
|
|
|
cygheap_fdget fhstdin (0);
|
|
|
|
|
|
|
|
if (fhstdin < 0)
|
|
|
|
pass[0] = '\0';
|
2000-02-17 20:38:33 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fhstdin->tcgetattr (&ti);
|
|
|
|
newti = ti;
|
|
|
|
newti.c_lflag &= ~ECHO;
|
|
|
|
fhstdin->tcsetattr (TCSANOW, &newti);
|
|
|
|
fputs (prompt, stderr);
|
|
|
|
fgets (pass, _PASSWORD_LEN, stdin);
|
|
|
|
fprintf (stderr, "\n");
|
|
|
|
for (int i=0; pass[i]; i++)
|
|
|
|
if (pass[i] == '\r' || pass[i] == '\n')
|
|
|
|
pass[i] = '\0';
|
|
|
|
fhstdin->tcsetattr (TCSANOW, &ti);
|
|
|
|
}
|
|
|
|
return pass;
|
|
|
|
}
|