* grp.cc (getgroups32): Revert previous patch. Use impersonation
token if process is in impersonated state. * sec_helper.cc (is_grp_member): Rewrite. Call getgroups32 only for current user. Scan passwd and group info otherwise.
This commit is contained in:
parent
69920bb5bd
commit
4ce377c9d4
|
@ -1,3 +1,10 @@
|
||||||
|
2002-11-14 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* grp.cc (getgroups32): Revert previous patch. Use impersonation
|
||||||
|
token if process is in impersonated state.
|
||||||
|
* sec_helper.cc (is_grp_member): Rewrite. Call getgroups32 only
|
||||||
|
for current user. Scan passwd and group info otherwise.
|
||||||
|
|
||||||
2002-11-14 Christopher Faylor <cgf@redhat.com>
|
2002-11-14 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
* fhandler_console.cc (fhandler_console::write): Allow characters >=
|
* fhandler_console.cc (fhandler_console::write): Allow characters >=
|
||||||
|
|
|
@ -341,9 +341,15 @@ getgroups32 (int gidsetsize, __gid32_t *grouplist, __gid32_t gid,
|
||||||
if (group_state <= initializing)
|
if (group_state <= initializing)
|
||||||
read_etc_group ();
|
read_etc_group ();
|
||||||
|
|
||||||
if (allow_ntsec &&
|
if (allow_ntsec)
|
||||||
strcasematch (username, cygheap->user.name ()) &&
|
{
|
||||||
OpenProcessToken (hMainProc, TOKEN_QUERY, &hToken))
|
/* If impersonated, use impersonation token. */
|
||||||
|
if (cygheap->user.issetuid ())
|
||||||
|
hToken = cygheap->user.token;
|
||||||
|
else if (!OpenProcessToken (hMainProc, TOKEN_QUERY, &hToken))
|
||||||
|
hToken = NULL;
|
||||||
|
}
|
||||||
|
if (hToken)
|
||||||
{
|
{
|
||||||
if (GetTokenInformation (hToken, TokenGroups, NULL, 0, &size)
|
if (GetTokenInformation (hToken, TokenGroups, NULL, 0, &size)
|
||||||
|| GetLastError () == ERROR_INSUFFICIENT_BUFFER)
|
|| GetLastError () == ERROR_INSUFFICIENT_BUFFER)
|
||||||
|
@ -375,7 +381,8 @@ getgroups32 (int gidsetsize, __gid32_t *grouplist, __gid32_t gid,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
debug_printf ("%d = GetTokenInformation(NULL) %E", size);
|
debug_printf ("%d = GetTokenInformation(NULL) %E", size);
|
||||||
CloseHandle (hToken);
|
if (hToken != cygheap->user.token)
|
||||||
|
CloseHandle (hToken);
|
||||||
if (cnt)
|
if (cnt)
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,19 +183,50 @@ BOOL
|
||||||
is_grp_member (__uid32_t uid, __gid32_t gid)
|
is_grp_member (__uid32_t uid, __gid32_t gid)
|
||||||
{
|
{
|
||||||
extern int getgroups32 (int, __gid32_t *, __gid32_t, const char *);
|
extern int getgroups32 (int, __gid32_t *, __gid32_t, const char *);
|
||||||
BOOL grp_member = TRUE;
|
struct passwd *pw;
|
||||||
|
struct __group32 *gr;
|
||||||
|
int idx;
|
||||||
|
|
||||||
struct passwd *pw = getpwuid32 (uid);
|
/* Evaluate current user info by examining the info given in cygheap and
|
||||||
__gid32_t grps[NGROUPS_MAX];
|
the current access token if ntsec is on. */
|
||||||
int cnt = getgroups32 (NGROUPS_MAX, grps,
|
if (uid == myself->uid)
|
||||||
pw ? pw->pw_gid : myself->gid,
|
{
|
||||||
pw ? pw->pw_name : cygheap->user.name ());
|
/* If gid == primary group of current user, return immediately. */
|
||||||
int i;
|
if (gid == myself->gid)
|
||||||
for (i = 0; i < cnt; ++i)
|
return TRUE;
|
||||||
if (grps[i] == gid)
|
/* Calling getgroups32 only makes sense when reading the access token. */
|
||||||
break;
|
if (allow_ntsec)
|
||||||
grp_member = (i < cnt);
|
{
|
||||||
return grp_member;
|
__gid32_t grps[NGROUPS_MAX];
|
||||||
|
int cnt = getgroups32 (NGROUPS_MAX, grps, myself->gid,
|
||||||
|
cygheap->user.name ());
|
||||||
|
for (idx = 0; idx < cnt; ++idx)
|
||||||
|
if (grps[idx] == gid)
|
||||||
|
return TRUE;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Otherwise try getting info from examining passwd and group files. */
|
||||||
|
for (int idx = 0; (pw = internal_getpwent (idx)); ++idx)
|
||||||
|
if ((__uid32_t) pw->pw_uid == uid)
|
||||||
|
{
|
||||||
|
/* If gid == primary group of uid, return immediately. */
|
||||||
|
if ((__gid32_t) pw->pw_gid == gid)
|
||||||
|
return TRUE;
|
||||||
|
/* Otherwise search for supplementary user list of this group. */
|
||||||
|
for (idx = 0; (gr = internal_getgrent (idx)); ++idx)
|
||||||
|
if ((__gid32_t) gr->gr_gid == gid)
|
||||||
|
{
|
||||||
|
if (gr->gr_mem)
|
||||||
|
for (idx = 0; gr->gr_mem[idx]; ++idx)
|
||||||
|
if (strcasematch (cygheap->user.name (), gr->gr_mem[idx]))
|
||||||
|
return TRUE;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // unused
|
#if 0 // unused
|
||||||
|
|
Loading…
Reference in New Issue