* select.cc (allocfd_set): Zero allocated fd_set.

(cygwin_select): Move fd_set copying logic from ::wait to here.  Use common
return through sell.poll.
(select_stuff::wait): Just return success or failure and let caller fill in
fd_set.
* pinfo.h (pinfo): Eliminate self-referential pointer to sidbuf since pinfo
structure exists at random locations now.
* fork.cc (fork): Use 'use_psid' element to control when the psid is relevant.
* shared.cc (sec_user): Ditto.
* spawn.cc (spawn_guts): Ditto.
* uinfo.cc (internal_getlogin): Ditto.
* syscall.cc (seteuid): Ditto.  Set use_psid element.
This commit is contained in:
Christopher Faylor 2000-08-09 02:33:47 +00:00
parent c51a2a8ba4
commit 0072fdab86
8 changed files with 69 additions and 68 deletions

View File

@ -1,3 +1,19 @@
Tue Aug 8 22:25:39 2000 Christopher Faylor <cgf@cygnus.com>
* select.cc (allocfd_set): Zero allocated fd_set.
(cygwin_select): Move fd_set copying logic from ::wait to here. Use
common return through sell.poll.
(select_stuff::wait): Just return success or failure and let caller
fill in fd_set.
* pinfo.h (pinfo): Eliminate self-referential pointer to sidbuf since
pinfo structure exists at random locations now.
* fork.cc (fork): Use 'use_psid' element to control when the psid is
relevant.
* shared.cc (sec_user): Ditto.
* spawn.cc (spawn_guts): Ditto.
* uinfo.cc (internal_getlogin): Ditto.
* syscall.cc (seteuid): Ditto. Set use_psid element.
Tue Aug 8 13:20:00 2000 Bob Wilson <bwilson@tensilica.com>
* fhandler_serial.cc (tcsendbreak): "sleeptime" argument to usleep()

View File

@ -423,9 +423,11 @@ fork ()
forked->process_state |= PID_INITIALIZING |
(myself->process_state & PID_USETTY);
memcpy (forked->username, myself->username, MAX_USER_NAME);
memcpy (forked->sidbuf, myself->sidbuf, MAX_SID_LEN);
if (myself->psid)
forked->psid = forked->sidbuf;
if (myself->use_psid)
{
memcpy (forked->psid, myself->psid, MAX_SID_LEN);
forked->use_psid = 1;
}
memcpy (forked->logsrv, myself->logsrv, MAX_HOST_NAME);
memcpy (forked->domain, myself->domain, MAX_COMPUTERNAME_LENGTH+1);
forked->token = myself->token;

View File

@ -49,19 +49,19 @@ public:
if not found. This data resides in the shared data area (allowing
tasks to store whatever they want here) so it's for informational
purposes only. */
uid_t uid; /* User ID */
gid_t gid; /* Group ID */
pid_t pgid; /* Process group ID */
pid_t sid; /* Session ID */
int ctty; /* Control tty */
uid_t uid; /* User ID */
gid_t gid; /* Group ID */
pid_t pgid; /* Process group ID */
pid_t sid; /* Session ID */
int ctty; /* Control tty */
mode_t umask;
char username[MAX_USER_NAME]; /* user's name */
/* Extendend user information.
The information is derived from the internal_getlogin call
when on a NT system. */
PSID psid; /* user's SID */
char sidbuf[MAX_SID_LEN]; /* buffer for user's SID */
int use_psid; /* TRUE if psid contains valid data */
char psid[MAX_SID_LEN]; /* buffer for user's SID */
char logsrv[MAX_HOST_NAME]; /* Logon server, may be FQDN */
char domain[MAX_COMPUTERNAME_LENGTH+1]; /* Logon domain of the user */

View File

@ -1,6 +1,6 @@
/* select.cc
Copyright 1996, 1997, 1998, 1999, 2000 Cygnus Solutions.
Copyright 1996, 1997, 1998, 1999, 2000 Red Hat, Inc.
Written by Christopher Faylor of Cygnus Solutions
cgf@cygnus.com
@ -71,7 +71,7 @@ typedef long fd_mask;
#define UNIX_FD_ZERO(p, n) \
bzero ((caddr_t)(p), sizeof_fd_set ((n)))
#define allocfd_set(n) ((fd_set *) alloca (sizeof_fd_set (n)))
#define allocfd_set(n) ((fd_set *) memset (alloca (sizeof_fd_set (n)), 0, sizeof_fd_set (n)))
#define copyfd_set(to, from, n) memcpy (to, from, sizeof_fd_set (n));
/* Make a fhandler_foo::ready_for_ready method.
@ -105,13 +105,13 @@ fhandler_##what::ready_for_read (int fd, DWORD howlong, int ignra) \
*/
extern "C"
int
cygwin_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *to)
cygwin_select (int maxfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
struct timeval *to)
{
select_stuff sel;
fd_set *dummy_readfds = allocfd_set (n);
fd_set *dummy_writefds = allocfd_set (n);
fd_set *dummy_exceptfds = allocfd_set (n);
fd_set *dummy_readfds = allocfd_set (maxfds);
fd_set *dummy_writefds = allocfd_set (maxfds);
fd_set *dummy_exceptfds = allocfd_set (maxfds);
sigframe thisframe (mainthread, 0);
#if 0
@ -122,25 +122,16 @@ cygwin_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
}
#endif
select_printf ("%d, %p, %p, %p, %p", n, readfds, writefds, exceptfds, to);
select_printf ("%d, %p, %p, %p, %p", maxfds, readfds, writefds, exceptfds, to);
if (!readfds)
{
UNIX_FD_ZERO (dummy_readfds, n);
readfds = dummy_readfds;
}
readfds = dummy_readfds;
if (!writefds)
{
UNIX_FD_ZERO (dummy_writefds, n);
writefds = dummy_writefds;
}
writefds = dummy_writefds;
if (!exceptfds)
{
UNIX_FD_ZERO (dummy_exceptfds, n);
exceptfds = dummy_exceptfds;
}
exceptfds = dummy_exceptfds;
for (int i = 0; i < n; i++)
for (int i = 0; i < maxfds; i++)
if (!sel.test_and_set (i, readfds, writefds, exceptfds))
{
select_printf ("aborting due to test_and_set error");
@ -171,18 +162,19 @@ cygwin_select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
return 0;
}
/* If one of the selected fds is "always ready" just poll everything and return
the result. There is no need to wait. */
if (sel.always_ready || ms == 0)
{
UNIX_FD_ZERO (readfds, n);
UNIX_FD_ZERO (writefds, n);
UNIX_FD_ZERO (exceptfds, n);
return sel.poll (readfds, writefds, exceptfds);
}
/* Allocate some fd_set structures using the number of fds as a guide. */
fd_set *r = allocfd_set (maxfds);
fd_set *w = allocfd_set (maxfds);
fd_set *e = allocfd_set (maxfds);
/* Wait for an fd to come alive */
return sel.wait (readfds, writefds, exceptfds, ms);
/* Don't bother waiting if one of the selected fds is "always ready". */
if ((!sel.always_ready || ms != 0) && sel.wait (r, w, e, ms))
return -1; /* some kind of error */
copyfd_set (readfds, r, maxfds);
copyfd_set (writefds, w, maxfds);
copyfd_set (exceptfds, e, maxfds);
return sel.poll (readfds, writefds, exceptfds);
}
/* Cleanup */
@ -273,17 +265,9 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
continue;
}
int n = m - 1;
DWORD start_time = GetTickCount (); /* Record the current time for later use. */
/* Allocate some fd_set structures using the number of fds as a guide. */
fd_set *r = allocfd_set (n);
fd_set *w = allocfd_set (n);
fd_set *e = allocfd_set (n);
UNIX_FD_ZERO (r, n);
UNIX_FD_ZERO (w, n);
UNIX_FD_ZERO (e, n);
debug_printf ("n %d, ms %u", n, ms);
debug_printf ("m %d, ms %u", m, ms);
for (;;)
{
if (!windows_used)
@ -313,7 +297,7 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
if (s->saw_error)
return -1; /* Somebody detected an error */
else if ((((wait_ret >= m && s->windows_handle) || s->h == w4[wait_ret])) &&
s->verify (s, r, w, e))
s->verify (s, readfds, writefds, exceptfds))
gotone = TRUE;
select_printf ("gotone %d", gotone);
@ -339,11 +323,8 @@ select_stuff::wait (fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
}
out:
copyfd_set (readfds, r, n);
copyfd_set (writefds, w, n);
copyfd_set (exceptfds, e, n);
return poll (readfds, writefds, exceptfds);
select_printf ("returning 0");
return 0;
}
static int

View File

@ -212,7 +212,7 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit)
char sid_buf[MAX_SID_LEN];
PSID sid = (PSID) sid_buf;
if (myself->psid)
if (myself->use_psid)
CopySid (MAX_SID_LEN, sid, myself->psid);
else if (! lookup_name (getlogin (), myself->logsrv, sid))
return inherit ? &sec_none_nih : &sec_none;

View File

@ -670,9 +670,11 @@ skip_arg_parsing:
child->ctty = myself->ctty;
child->umask = myself->umask;
child->process_state |= PID_INITIALIZING;
memcpy (child->sidbuf, myself->sidbuf, MAX_SID_LEN);
if (myself->psid)
child->psid = child->sidbuf;
if (myself->use_psid)
{
child->use_psid = 1;
memcpy (child->psid, myself->psid, MAX_SID_LEN);
}
memcpy (child->logsrv, myself->logsrv, MAX_HOST_NAME);
memcpy (child->domain, myself->domain, MAX_COMPUTERNAME_LENGTH+1);
memcpy (child->root, myself->root, MAX_PATH+1);
@ -691,7 +693,7 @@ skip_arg_parsing:
/* Set child->uid to USHRT_MAX to force calling internal_getlogin()
from child process. Clear username and psid to play it safe. */
child->uid = USHRT_MAX;
child->psid = NULL;
child->use_psid = 0;
}
child.remember ();
}

View File

@ -1865,7 +1865,6 @@ seteuid (uid_t uid)
}
struct _pinfo pi;
pi.psid = (PSID) pi.sidbuf;
/* pi.token is used in internal_getlogin() to determine if
impersonation is active. If so, the token is used for
retrieving user's SID. */
@ -1884,7 +1883,8 @@ seteuid (uid_t uid)
strcpy (myself->username, pi.username);
strcpy (myself->logsrv, pi.logsrv);
strcpy (myself->domain, pi.domain);
memcpy (myself->sidbuf, pi.sidbuf, MAX_SID_LEN);
memcpy (myself->psid, pi.psid, MAX_SID_LEN);
myself->use_psid = 1;
}
}
else

View File

@ -112,7 +112,7 @@ internal_getlogin (_pinfo *pi)
else if (!GetTokenInformation (ptok, TokenUser, (LPVOID) &tu,
sizeof tu, &siz))
debug_printf ("GetTokenInformation(): %E");
else if (!(ret = CopySid (MAX_SID_LEN, (PSID) pi->sidbuf,
else if (!(ret = CopySid (MAX_SID_LEN, (PSID) pi->psid,
((TOKEN_USER *) &tu)->User.Sid)))
debug_printf ("Couldn't retrieve SID from access token!");
/* Close token only if it's a result from OpenProcessToken(). */
@ -126,14 +126,14 @@ internal_getlogin (_pinfo *pi)
{
/* Concat DOMAIN\USERNAME for the next lookup */
strcat (strcat (strcpy (buf, pi->domain), "\\"), pi->username);
if (!(ret = lookup_name (buf, NULL, (PSID) pi->sidbuf)))
if (!(ret = lookup_name (buf, NULL, (PSID) pi->psid)))
debug_printf ("Couldn't retrieve SID locally!");
}
/* If that failes, too, as a last resort try to get the SID from
the logon server. */
if (!ret && !(ret = lookup_name(pi->username, pi->logsrv,
(PSID)pi->sidbuf)))
(PSID)pi->psid)))
debug_printf ("Couldn't retrieve SID from '%s'!", pi->logsrv);
/* If we have a SID, try to get the corresponding Cygwin user name
@ -144,7 +144,7 @@ internal_getlogin (_pinfo *pi)
char psidbuf[MAX_SID_LEN];
PSID psid = (PSID) psidbuf;
pi->psid = (PSID) pi->sidbuf;
pi->use_psid = 1;
if (!strcasematch (pi->username, "SYSTEM")
&& pi->domain[0] && pi->logsrv[0])
{