Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-09-11 01:01:40 +0400
committerChristopher Faylor <me@cgf.cx>2003-09-11 01:01:40 +0400
commit0efafbfb8cfd1fedfb5361c98544545c1c648733 (patch)
tree0ed8c59da86fa4c0352aedcd3e1552c86d7718c1 /winsup/cygwin/uinfo.cc
parent1aa76ad568b4dc7b0a68137fc7f2b6dedbcae492 (diff)
* shared_info.h (shared_info::initialize): Remove argument.
* cygheap.h (cygheap_user::init): New declaration. * uinfo.cc (cygheap_user::init): New. (internal_getlogin): Move functionality to cygheap_user::init. Open the process token to update the group sid. * shared.cc (user_shared_initialize): Get the user information from cygheap->user. (shared_info::initialize): Remove argument. Call cygheap->user.init instead of cygheap->user.set_name. (memory_init): Do not get the user name and do not pass it to shared_info::initialize. * registry.cc (get_registry_hive_path): Make csid a cygpsid. (load_registry_hive): Ditto.
Diffstat (limited to 'winsup/cygwin/uinfo.cc')
-rw-r--r--winsup/cygwin/uinfo.cc80
1 files changed, 49 insertions, 31 deletions
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 0b106eec7..342c398ae 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -30,42 +30,55 @@ details. */
#include "environ.h"
#include "pwdgrp.h"
+/* Initialize the part of cygheap_user that does not depend on files.
+ The information is used in shared.cc for the user shared.
+ Final initialization occurs in uinfo_init */
void
-internal_getlogin (cygheap_user &user)
+cygheap_user::init()
{
- struct passwd *pw = NULL;
- HANDLE ptok = INVALID_HANDLE_VALUE;
+ char user_name[UNLEN + 1];
+ DWORD user_name_len = UNLEN + 1;
+
+ set_name (GetUserName (user_name, &user_name_len) ? user_name : "unknown");
- myself->gid = UNKNOWN_GID;
if (wincap.has_security ())
{
- DWORD siz;
+ HANDLE ptok = NULL;
+ DWORD siz, ret;
cygsid tu;
- DWORD ret = 0;
- /* Try to get the SID either from current process and
- store it in user.psid */
+ /* Get the SID from current process and store it in user.psid */
if (!OpenProcessToken (hMainProc, TOKEN_ADJUST_DEFAULT | TOKEN_QUERY,
&ptok))
system_printf ("OpenProcessToken(): %E");
- else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz))
- system_printf ("GetTokenInformation (TokenUser): %E");
- else if (!(ret = user.set_sid (tu)))
- system_printf ("Couldn't retrieve SID from access token!");
- else if (!GetTokenInformation (ptok, TokenPrimaryGroup,
- &user.groups.pgsid, sizeof tu, &siz))
- system_printf ("GetTokenInformation (TokenPrimaryGroup): %E");
- /* We must set the user name, uid and gid.
- If we have a SID, try to get the corresponding Cygwin
- password entry. Set user name which can be different
- from the Windows user name */
- if (ret)
+ else
{
- pw = internal_getpwsid (tu);
+ if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz))
+ system_printf ("GetTokenInformation (TokenUser): %E");
+ else if (!(ret = set_sid (tu)))
+ system_printf ("Couldn't retrieve SID from access token!");
/* Set token owner to the same value as token user */
- if (!SetTokenInformation (ptok, TokenOwner, &tu, sizeof tu))
+ else if (!SetTokenInformation (ptok, TokenOwner, &tu, sizeof tu))
debug_printf ("SetTokenInformation(TokenOwner): %E");
- }
+ if (!GetTokenInformation (ptok, TokenPrimaryGroup,
+ &groups.pgsid, sizeof tu, &siz))
+ system_printf ("GetTokenInformation (TokenPrimaryGroup): %E");
+ CloseHandle (ptok);
+ }
+ }
+}
+
+void
+internal_getlogin (cygheap_user &user)
+{
+ struct passwd *pw = NULL;
+
+ myself->gid = UNKNOWN_GID;
+
+ if (wincap.has_security ())
+ {
+ cygpsid psid = user.sid ();
+ pw = internal_getpwsid (psid);
}
if (!pw && !(pw = internal_getpwnam (user.name ()))
@@ -81,19 +94,24 @@ internal_getlogin (cygheap_user &user)
cygsid gsid;
if (gsid.getfromgr (internal_getgrgid (pw->pw_gid)))
{
- /* Set primary group to the group in /etc/passwd. */
- if (!SetTokenInformation (ptok, TokenPrimaryGroup,
- &gsid, sizeof gsid))
- debug_printf ("SetTokenInformation(TokenPrimaryGroup): %E");
- else
- user.groups.pgsid = gsid;
+ HANDLE ptok;
+ if (gsid != user.groups.pgsid
+ && OpenProcessToken (hMainProc, TOKEN_ADJUST_DEFAULT | TOKEN_QUERY,
+ &ptok))
+ {
+ /* Set primary group to the group in /etc/passwd. */
+ if (!SetTokenInformation (ptok, TokenPrimaryGroup,
+ &gsid, sizeof gsid))
+ debug_printf ("SetTokenInformation(TokenPrimaryGroup): %E");
+ else
+ user.groups.pgsid = gsid;
+ CloseHandle (ptok);
+ }
}
else
debug_printf ("gsid not found in augmented /etc/group");
}
}
- if (ptok != INVALID_HANDLE_VALUE)
- CloseHandle (ptok);
(void) cygheap->user.ontherange (CH_HOME, pw);
return;