Use hMainProc where appropriate, throughout.

* environ.cc (spenv::retrieve): Add debugging statements.
* pinfo.cc (set_myself): Don't call strace.hello if already stracing.
* strace.cc (strace): Move NO_COPY keyword so that it will actually take
effect.
This commit is contained in:
Christopher Faylor 2002-06-19 15:27:27 +00:00
parent 834224ab85
commit 03a2ce9a36
9 changed files with 112 additions and 86 deletions

View File

@ -1,3 +1,12 @@
2002-06-19 Christopher Faylor <cgf@redhat.com>
Use hMainProc where appropriate, throughout.
* environ.cc (spenv::retrieve): Add debugging statements.
* pinfo.cc (set_myself): Don't call strace.hello if already stracing.
* strace.cc (strace): Move NO_COPY keyword so that it will actually
take effect.
2002-06-19 Corinna Vinschen <corinna@vinschen.de> 2002-06-19 Corinna Vinschen <corinna@vinschen.de>
* uinfo.cc (cygheap_user::ontherange): Call NetUserGetInfo() only with * uinfo.cc (cygheap_user::ontherange): Call NetUserGetInfo() only with

View File

@ -58,16 +58,16 @@ static NO_COPY win_env conv_envvars[] =
cygwin_posix_to_win32_path_list, cygwin_posix_to_win32_path_list,
cygwin_win32_to_posix_path_list_buf_size, cygwin_win32_to_posix_path_list_buf_size,
cygwin_posix_to_win32_path_list_buf_size}, cygwin_posix_to_win32_path_list_buf_size},
{NL ("HOME="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path, {NL ("HOME="), NULL, NULL, cygwin_conv_to_full_posix_path,
return_MAX_PATH, return_MAX_PATH}, cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
{NL ("LD_LIBRARY_PATH="), NULL, NULL, cygwin_conv_to_full_posix_path, {NL ("LD_LIBRARY_PATH="), NULL, NULL, cygwin_conv_to_full_posix_path,
cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH}, cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
{NL ("TMPDIR="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path, {NL ("TMPDIR="), NULL, NULL, cygwin_conv_to_full_posix_path,
return_MAX_PATH, return_MAX_PATH}, cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
{NL ("TMP="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path, {NL ("TMP="), NULL, NULL, cygwin_conv_to_full_posix_path,
return_MAX_PATH, return_MAX_PATH}, cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
{NL ("TEMP="), NULL, NULL, cygwin_conv_to_full_posix_path, cygwin_conv_to_full_win32_path, {NL ("TEMP="), NULL, NULL, cygwin_conv_to_full_posix_path,
return_MAX_PATH, return_MAX_PATH}, cygwin_conv_to_full_win32_path, return_MAX_PATH, return_MAX_PATH},
{NULL, 0, NULL, NULL, NULL, NULL, 0, 0} {NULL, 0, NULL, NULL, NULL, NULL, 0, 0}
}; };
@ -780,19 +780,31 @@ spenv::retrieve (bool no_envblock, const char *const envname)
{ {
if (envname && !strncasematch (envname, name, namelen)) if (envname && !strncasematch (envname, name, namelen))
return NULL; return NULL;
debug_printf ("no_envblock %d", no_envblock);
if (from_cygheap) if (from_cygheap)
{ {
const char *p; const char *p;
if (!cygheap->user.issetuid ()) if (cygheap->user.issetuid ())
debug_printf ("calculating for setuid");
else
{ {
debug_printf ("calculating for non-setuid");
if (!envname) if (!envname)
{
debug_printf ("not adding %s to windows environment", name);
return NULL; /* No need to force these into the return NULL; /* No need to force these into the
environment */ environment */
}
if (no_envblock) if (no_envblock)
{
debug_printf ("duping existing value for '%s'", name);
return cstrdup1 (envname);/* Don't really care what it's set to return cstrdup1 (envname);/* Don't really care what it's set to
if we're calling a cygwin program */ if we're calling a cygwin program */
} }
}
/* Calculate (potentially) value for given environment variable. */ /* Calculate (potentially) value for given environment variable. */
p = (cygheap->user.*from_cygheap) (); p = (cygheap->user.*from_cygheap) ();
@ -801,6 +813,7 @@ spenv::retrieve (bool no_envblock, const char *const envname)
char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1); char *s = (char *) cmalloc (HEAP_1_STR, namelen + strlen (p) + 1);
strcpy (s, name); strcpy (s, name);
(void) strcpy (s + namelen, p); (void) strcpy (s + namelen, p);
debug_printf ("using computed value for '%s'", name);
return s; return s;
} }
@ -814,7 +827,11 @@ spenv::retrieve (bool no_envblock, const char *const envname)
char *p = (char *) cmalloc (HEAP_1_STR, namelen + ++vallen); char *p = (char *) cmalloc (HEAP_1_STR, namelen + ++vallen);
strcpy (p, name); strcpy (p, name);
if (GetEnvironmentVariable (name, p + namelen, vallen)) if (GetEnvironmentVariable (name, p + namelen, vallen))
{
debug_printf ("using value from GetEnvironmentVariable for '%s'",
envname);
return p; return p;
}
else else
cfree (p); cfree (p);
} }

View File

@ -177,7 +177,7 @@ read_etc_group ()
cygsid tg; cygsid tg;
DWORD siz; DWORD siz;
if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok)) if (OpenProcessToken (hMainProc, TOKEN_QUERY, &ptok))
{ {
if (GetTokenInformation (ptok, TokenPrimaryGroup, &tg, if (GetTokenInformation (ptok, TokenPrimaryGroup, &tg,
sizeof tg, &siz) sizeof tg, &siz)

View File

@ -168,7 +168,7 @@ read_etc_passwd ()
cygsid tu, tg; cygsid tu, tg;
DWORD siz; DWORD siz;
if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &ptok)) if (OpenProcessToken (hMainProc, TOKEN_QUERY, &ptok))
{ {
if (GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, if (GetTokenInformation (ptok, TokenUser, &tu, sizeof tu,
&siz) &siz)

View File

@ -63,6 +63,7 @@ set_myself (pid_t pid, HANDLE h)
(void) GetModuleFileName (NULL, myself->progname, (void) GetModuleFileName (NULL, myself->progname,
sizeof(myself->progname)); sizeof(myself->progname));
if (!strace.active)
strace.hello (); strace.hello ();
return; return;
} }

View File

@ -726,8 +726,10 @@ verify_token (HANDLE token, cygsid &usersid, cygsid &pgrpsid, BOOL * pintern)
debug_printf ("malloc (my_grps) failed."); debug_printf ("malloc (my_grps) failed.");
else if (!GetTokenInformation (token, TokenGroups, my_grps, size, &size)) else if (!GetTokenInformation (token, TokenGroups, my_grps, size, &size))
debug_printf ("GetTokenInformation(my_token, TokenGroups): %E\n"); debug_printf ("GetTokenInformation(my_token, TokenGroups): %E\n");
else ret = sid_in_token_groups (my_grps, pgrpsid); else
if (my_grps) free (my_grps); ret = sid_in_token_groups (my_grps, pgrpsid);
if (my_grps)
free (my_grps);
return ret; return ret;
} }
@ -784,7 +786,7 @@ create_token (cygsid &usersid, cygsid &pgrpsid)
owner.Owner = usersid; owner.Owner = usersid;
/* Retrieve authentication id and group list from own process. */ /* Retrieve authentication id and group list from own process. */
if (!OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &my_token)) if (!OpenProcessToken (hMainProc, TOKEN_QUERY, &my_token))
debug_printf ("OpenProcessToken(my_token): %E\n"); debug_printf ("OpenProcessToken(my_token): %E\n");
else else
{ {

View File

@ -22,7 +22,7 @@ details. */
#define PROTECT(x) x[sizeof(x)-1] = 0 #define PROTECT(x) x[sizeof(x)-1] = 0
#define CHECK(x) if (x[sizeof(x)-1] != 0) { small_printf("array bound exceeded %d\n", __LINE__); ExitProcess(1); } #define CHECK(x) if (x[sizeof(x)-1] != 0) { small_printf("array bound exceeded %d\n", __LINE__); ExitProcess(1); }
class NO_COPY strace strace; class strace NO_COPY strace;
#ifndef NOSTRACE #ifndef NOSTRACE

View File

@ -1978,8 +1978,7 @@ seteuid32 (__uid32_t uid)
sav_impersonated = cygheap->user.impersonated; sav_impersonated = cygheap->user.impersonated;
RevertToSelf(); RevertToSelf();
if (!OpenProcessToken (GetCurrentProcess (), if (!OpenProcessToken (hMainProc, TOKEN_QUERY | TOKEN_ADJUST_DEFAULT, &ptok))
TOKEN_QUERY | TOKEN_ADJUST_DEFAULT, &ptok))
{ {
__seterrno (); __seterrno ();
goto failed; goto failed;
@ -1991,13 +1990,13 @@ seteuid32 (__uid32_t uid)
debug_printf("Process token %sverified", process_ok ? "" : "not "); debug_printf("Process token %sverified", process_ok ? "" : "not ");
if (process_ok) if (process_ok)
{ {
if (cygheap->user.token == INVALID_HANDLE_VALUE || if (cygheap->user.issetuid ())
!cygheap->user.impersonated) cygheap->user.impersonated = FALSE;
else
{ {
CloseHandle (ptok); CloseHandle (ptok);
return 0; /* No change */ return 0; /* No change */
} }
else cygheap->user.impersonated = FALSE;
} }
if (!process_ok && cygheap->user.token != INVALID_HANDLE_VALUE) if (!process_ok && cygheap->user.token != INVALID_HANDLE_VALUE)
@ -2007,7 +2006,9 @@ seteuid32 (__uid32_t uid)
& sav_token_is_internal_token); & sav_token_is_internal_token);
debug_printf("Thread token %d %sverified", debug_printf("Thread token %d %sverified",
cygheap->user.token, token_ok?"":"not "); cygheap->user.token, token_ok?"":"not ");
if (token_ok) if (!token_ok)
cygheap->user.token = INVALID_HANDLE_VALUE;
else
{ {
/* Return if current token is valid */ /* Return if current token is valid */
if (cygheap->user.impersonated) if (cygheap->user.impersonated)
@ -2018,7 +2019,6 @@ seteuid32 (__uid32_t uid)
return 0; /* No change */ return 0; /* No change */
} }
} }
else cygheap->user.token = INVALID_HANDLE_VALUE;
} }
/* Set process def dacl to allow access to impersonated token */ /* Set process def dacl to allow access to impersonated token */
@ -2152,9 +2152,7 @@ setegid32 (__gid32_t gid)
"TokenPrimaryGroup): %E"); "TokenPrimaryGroup): %E");
RevertToSelf (); RevertToSelf ();
} }
if (!OpenProcessToken (GetCurrentProcess (), if (!OpenProcessToken (hMainProc, TOKEN_ADJUST_DEFAULT, &ptok))
TOKEN_ADJUST_DEFAULT,
&ptok))
debug_printf ("OpenProcessToken(): %E\n"); debug_printf ("OpenProcessToken(): %E\n");
else else
{ {

View File

@ -43,8 +43,7 @@ internal_getlogin (cygheap_user &user)
/* Try to get the SID either from current process and /* Try to get the SID either from current process and
store it in user.psid */ store it in user.psid */
if (!OpenProcessToken (GetCurrentProcess (), if (!OpenProcessToken (hMainProc, TOKEN_ADJUST_DEFAULT | TOKEN_QUERY,
TOKEN_ADJUST_DEFAULT | TOKEN_QUERY,
&ptok)) &ptok))
system_printf ("OpenProcessToken(): %E\n"); system_printf ("OpenProcessToken(): %E\n");
else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz)) else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz))