* cygheap.cc (cfree_and_set): New function.
(cygheap_user::set_name): Use cfree_and_set to reset members. * cygheap.h (cygheap_user): Delete static members. (cygheap_user::puserprof): New member. (cfree_and_set): Declare. * dcrt0.cc (almost_null): Define. * winsup.h (almost_null): Declare. * syscalls.cc (cfree_and_set): Remove unused variable. * uinfo.cc (cygheap_user::homepath_env_buf): Eliminate. (cygheap_user::homedrive_env_buf): Ditto. (cygheap_user::userprofile_env_buf): Ditto. (cygheap_user::ontherange): YA change to try to preserve existing HOMEPATH and HOMEDRIVE. Return almost_null values when variables should not actually exist. (cygheap_user::env_logsrv): Ditto. (cygheap_user::env_domain): Ditto. (cygheap_user::env_userprofile): Ditto.
This commit is contained in:
parent
54be629f41
commit
179cae11d7
|
@ -1,3 +1,23 @@
|
||||||
|
2002-06-27 Christopher Faylor <cgf@redhat.com>
|
||||||
|
|
||||||
|
* cygheap.cc (cfree_and_set): New function.
|
||||||
|
(cygheap_user::set_name): Use cfree_and_set to reset members.
|
||||||
|
* cygheap.h (cygheap_user): Delete static members.
|
||||||
|
(cygheap_user::puserprof): New member.
|
||||||
|
(cfree_and_set): Declare.
|
||||||
|
* dcrt0.cc (almost_null): Define.
|
||||||
|
* winsup.h (almost_null): Declare.
|
||||||
|
* syscalls.cc (cfree_and_set): Remove unused variable.
|
||||||
|
* uinfo.cc (cygheap_user::homepath_env_buf): Eliminate.
|
||||||
|
(cygheap_user::homedrive_env_buf): Ditto.
|
||||||
|
(cygheap_user::userprofile_env_buf): Ditto.
|
||||||
|
(cygheap_user::ontherange): YA change to try to preserve existing
|
||||||
|
HOMEPATH and HOMEDRIVE. Return almost_null values when variables
|
||||||
|
should not actually exist.
|
||||||
|
(cygheap_user::env_logsrv): Ditto.
|
||||||
|
(cygheap_user::env_domain): Ditto.
|
||||||
|
(cygheap_user::env_userprofile): Ditto.
|
||||||
|
|
||||||
2002-06-27 Corinna Vinschen <corinna@vinschen.de>
|
2002-06-27 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* dcrt0.cc (dll_crt0_1): Let __progname point to the applications
|
* dcrt0.cc (dll_crt0_1): Let __progname point to the applications
|
||||||
|
|
|
@ -327,6 +327,14 @@ cfree (void *s)
|
||||||
MALLOC_CHECK;
|
MALLOC_CHECK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" void __stdcall
|
||||||
|
cfree_and_set (char *&s, char *what)
|
||||||
|
{
|
||||||
|
if (s && s != almost_null)
|
||||||
|
cfree (s);
|
||||||
|
s = what;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void *__stdcall
|
extern "C" void *__stdcall
|
||||||
ccalloc (cygheap_types x, DWORD n, DWORD size)
|
ccalloc (cygheap_types x, DWORD n, DWORD size)
|
||||||
{
|
{
|
||||||
|
@ -453,15 +461,11 @@ cygheap_user::set_name (const char *new_name)
|
||||||
if (!allocated)
|
if (!allocated)
|
||||||
return; /* Initializing. Don't bother with other stuff. */
|
return; /* Initializing. Don't bother with other stuff. */
|
||||||
|
|
||||||
homedrive = NULL;
|
cfree_and_set (homedrive);
|
||||||
homepath = NULL;
|
cfree_and_set (homepath);
|
||||||
if (plogsrv)
|
cfree_and_set (plogsrv);
|
||||||
cfree (plogsrv);
|
cfree_and_set (pdomain);
|
||||||
if (pdomain)
|
cfree_and_set (winname);
|
||||||
cfree (pdomain);
|
|
||||||
if (winname)
|
|
||||||
cfree (winname);
|
|
||||||
plogsrv = pdomain = winname = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL
|
BOOL
|
||||||
|
|
|
@ -104,15 +104,9 @@ class cygheap_user
|
||||||
char *homedrive; /* User's home drive */
|
char *homedrive; /* User's home drive */
|
||||||
char *homepath; /* User's home path */
|
char *homepath; /* User's home path */
|
||||||
char *winname; /* User's name as far as Windows knows it */
|
char *winname; /* User's name as far as Windows knows it */
|
||||||
|
char *puserprof; /* User profile */
|
||||||
PSID psid; /* buffer for user's SID */
|
PSID psid; /* buffer for user's SID */
|
||||||
PSID orig_psid; /* Remains intact even after impersonation */
|
PSID orig_psid; /* Remains intact even after impersonation */
|
||||||
static char homedrive_env_buf[3]; /* Where the HOMEDRIVE environment variable
|
|
||||||
info may live. */
|
|
||||||
static char homepath_env_buf[MAX_PATH + 1]; /* Where the HOMEPATH environment
|
|
||||||
variable info may live. */
|
|
||||||
static char userprofile_env_buf[MAX_PATH + 1]; /* Where the USERPROFILE
|
|
||||||
environment variable info
|
|
||||||
may live. */
|
|
||||||
public:
|
public:
|
||||||
__uid32_t orig_uid; /* Remains intact even after impersonation */
|
__uid32_t orig_uid; /* Remains intact even after impersonation */
|
||||||
__gid32_t orig_gid; /* Ditto */
|
__gid32_t orig_gid; /* Ditto */
|
||||||
|
@ -124,9 +118,17 @@ public:
|
||||||
HANDLE token;
|
HANDLE token;
|
||||||
BOOL impersonated;
|
BOOL impersonated;
|
||||||
|
|
||||||
|
/* CGF 2002-06-27. I removed the initializaton from this constructor
|
||||||
|
since this class is always allocated statically. That means that everything
|
||||||
|
is zero anyway so there is no need to initialize it to zero. Since the
|
||||||
|
token initialization is always handled during process startup as well,
|
||||||
|
I've removed the constructor entirely. Please reinstate this f this
|
||||||
|
situation ever changes.
|
||||||
cygheap_user () : pname (NULL), plogsrv (NULL), pdomain (NULL),
|
cygheap_user () : pname (NULL), plogsrv (NULL), pdomain (NULL),
|
||||||
homedrive (NULL), homepath (NULL),
|
homedrive (NULL), homepath (NULL), psid (NULL),
|
||||||
psid (NULL), token (INVALID_HANDLE_VALUE) {}
|
token (INVALID_HANDLE_VALUE) {}
|
||||||
|
*/
|
||||||
|
|
||||||
~cygheap_user ();
|
~cygheap_user ();
|
||||||
|
|
||||||
void set_name (const char *new_name);
|
void set_name (const char *new_name);
|
||||||
|
@ -289,5 +291,6 @@ void *__stdcall crealloc (void *, DWORD) __attribute__ ((regparm(2)));
|
||||||
void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
|
void *__stdcall ccalloc (cygheap_types, DWORD, DWORD) __attribute__ ((regparm(3)));
|
||||||
char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
|
char *__stdcall cstrdup (const char *) __attribute__ ((regparm(1)));
|
||||||
char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
|
char *__stdcall cstrdup1 (const char *) __attribute__ ((regparm(1)));
|
||||||
|
void __stdcall cfree_and_set (char *&, char * = NULL) __attribute__ ((regparm(2)));
|
||||||
void __stdcall cygheap_init ();
|
void __stdcall cygheap_init ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,6 +75,8 @@ MTinterface _mtinterf;
|
||||||
bool NO_COPY _cygwin_testing;
|
bool NO_COPY _cygwin_testing;
|
||||||
unsigned NO_COPY _cygwin_testing_magic;
|
unsigned NO_COPY _cygwin_testing_magic;
|
||||||
|
|
||||||
|
char NO_COPY almost_null[1];
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
void *export_malloc (unsigned int);
|
void *export_malloc (unsigned int);
|
||||||
|
|
|
@ -759,7 +759,7 @@ struct spenv
|
||||||
__attribute__ ((regparm (3)));
|
__attribute__ ((regparm (3)));
|
||||||
};
|
};
|
||||||
|
|
||||||
char env_dontadd[] = "";
|
#define env_dontadd almost_null
|
||||||
|
|
||||||
/* Keep this list in upper case and sorted */
|
/* Keep this list in upper case and sorted */
|
||||||
static NO_COPY spenv spenvs[] =
|
static NO_COPY spenv spenvs[] =
|
||||||
|
|
|
@ -1969,7 +1969,6 @@ seteuid32 (__uid32_t uid)
|
||||||
BOOL sav_impersonated, sav_token_is_internal_token;
|
BOOL sav_impersonated, sav_token_is_internal_token;
|
||||||
BOOL process_ok, explicitly_created_token = FALSE;
|
BOOL process_ok, explicitly_created_token = FALSE;
|
||||||
struct passwd * pw_new;
|
struct passwd * pw_new;
|
||||||
cygheap_user user;
|
|
||||||
PSID origpsid, psid2 = NO_SID;
|
PSID origpsid, psid2 = NO_SID;
|
||||||
|
|
||||||
debug_printf ("uid: %d myself->gid: %d", uid, myself->gid);
|
debug_printf ("uid: %d myself->gid: %d", uid, myself->gid);
|
||||||
|
|
|
@ -187,31 +187,26 @@ cuserid (char *src)
|
||||||
return src;
|
return src;
|
||||||
}
|
}
|
||||||
|
|
||||||
char cygheap_user::homepath_env_buf[MAX_PATH + 1];
|
|
||||||
char cygheap_user::homedrive_env_buf[3];
|
|
||||||
char cygheap_user::userprofile_env_buf[MAX_PATH + 1];
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
||||||
{
|
{
|
||||||
LPUSER_INFO_3 ui = NULL;
|
LPUSER_INFO_3 ui = NULL;
|
||||||
WCHAR wuser[UNLEN + 1];
|
WCHAR wuser[UNLEN + 1];
|
||||||
NET_API_STATUS ret;
|
NET_API_STATUS ret;
|
||||||
|
char homepath_env_buf[MAX_PATH + 1];
|
||||||
|
char homedrive_env_buf[3];
|
||||||
|
char *newhomedrive = NULL;
|
||||||
|
char *newhomepath = NULL;
|
||||||
|
|
||||||
|
|
||||||
if (what == CH_HOME)
|
if (what == CH_HOME)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
if ((p = getenv ("HOMEDRIVE")))
|
if ((p = getenv ("HOMEDRIVE")))
|
||||||
{
|
newhomedrive = p;
|
||||||
memcpy (homedrive_env_buf, p, 2);
|
|
||||||
homedrive = homedrive_env_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((p = getenv ("HOMEPATH")))
|
if ((p = getenv ("HOMEPATH")))
|
||||||
{
|
newhomepath = p;
|
||||||
strcpy (homepath_env_buf, p);
|
|
||||||
homepath = homepath_env_buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((p = getenv ("HOME")))
|
if ((p = getenv ("HOME")))
|
||||||
debug_printf ("HOME is already in the environment %s", p);
|
debug_printf ("HOME is already in the environment %s", p);
|
||||||
|
@ -224,21 +219,20 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
||||||
setenv ("HOME", pw->pw_dir, 1);
|
setenv ("HOME", pw->pw_dir, 1);
|
||||||
debug_printf ("Set HOME (from /etc/passwd) to %s", pw->pw_dir);
|
debug_printf ("Set HOME (from /etc/passwd) to %s", pw->pw_dir);
|
||||||
}
|
}
|
||||||
else if (homedrive && homepath)
|
else if (newhomedrive && newhomepath)
|
||||||
{
|
{
|
||||||
char home[MAX_PATH];
|
char home[MAX_PATH];
|
||||||
char buf[MAX_PATH + 1];
|
char buf[MAX_PATH + 1];
|
||||||
strcpy (buf, homedrive);
|
strcpy (buf, newhomedrive);
|
||||||
strcat (buf, homepath);
|
strcat (buf, newhomepath);
|
||||||
cygwin_conv_to_full_posix_path (buf, home);
|
cygwin_conv_to_full_posix_path (buf, home);
|
||||||
setenv ("HOME", home, 1);
|
setenv ("HOME", home, 1);
|
||||||
debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home);
|
debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (homedrive == NULL || !homedrive[0])
|
if (homepath == NULL && newhomepath == NULL)
|
||||||
{
|
{
|
||||||
if (!pw)
|
if (!pw)
|
||||||
pw = getpwnam (name ());
|
pw = getpwnam (name ());
|
||||||
|
@ -246,6 +240,7 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
||||||
cygwin_conv_to_full_win32_path (pw->pw_dir, homepath_env_buf);
|
cygwin_conv_to_full_win32_path (pw->pw_dir, homepath_env_buf);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
homepath_env_buf[0] = homepath_env_buf[1] = '\0';
|
||||||
if (env_logsrv ())
|
if (env_logsrv ())
|
||||||
{
|
{
|
||||||
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
||||||
|
@ -275,18 +270,26 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
||||||
|
|
||||||
if (homepath_env_buf[1] != ':')
|
if (homepath_env_buf[1] != ':')
|
||||||
{
|
{
|
||||||
homedrive_env_buf[0] = homedrive_env_buf[1] = '\0';
|
newhomedrive = almost_null;
|
||||||
homepath = homepath_env_buf;
|
newhomepath = homepath_env_buf;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
homedrive_env_buf[0] = homepath_env_buf[0];
|
homedrive_env_buf[0] = homepath_env_buf[0];
|
||||||
homedrive_env_buf[1] = homepath_env_buf[1];
|
homedrive_env_buf[1] = homepath_env_buf[1];
|
||||||
homepath = homepath_env_buf + 2;
|
homedrive_env_buf[2] = '\0';
|
||||||
|
newhomedrive = homedrive_env_buf;
|
||||||
|
newhomepath = homepath_env_buf + 2;
|
||||||
}
|
}
|
||||||
homedrive = homedrive_env_buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newhomedrive)
|
||||||
|
cfree_and_set (homedrive, (newhomedrive == almost_null)
|
||||||
|
? almost_null : cstrdup (newhomedrive));
|
||||||
|
|
||||||
|
if (newhomepath)
|
||||||
|
cfree_and_set (homepath, cstrdup (newhomepath));
|
||||||
|
|
||||||
switch (what)
|
switch (what)
|
||||||
{
|
{
|
||||||
case CH_HOMEDRIVE:
|
case CH_HOMEDRIVE:
|
||||||
|
@ -308,9 +311,10 @@ cygheap_user::env_logsrv ()
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
char logsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
char logsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
||||||
if (!get_logon_server (env_domain (), logsrv, NULL))
|
cfree_and_set (plogsrv, almost_null);
|
||||||
return NULL;
|
if (get_logon_server (env_domain (), logsrv, NULL))
|
||||||
return plogsrv = cstrdup (logsrv);
|
plogsrv = cstrdup (logsrv);
|
||||||
|
return plogsrv;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -325,27 +329,30 @@ cygheap_user::env_domain ()
|
||||||
DWORD dlen = sizeof (userdomain);
|
DWORD dlen = sizeof (userdomain);
|
||||||
SID_NAME_USE use;
|
SID_NAME_USE use;
|
||||||
|
|
||||||
|
cfree_and_set (winname, almost_null);
|
||||||
|
cfree_and_set (pdomain, almost_null);
|
||||||
if (!LookupAccountSid (NULL, sid (), username, &ulen,
|
if (!LookupAccountSid (NULL, sid (), username, &ulen,
|
||||||
userdomain, &dlen, &use))
|
userdomain, &dlen, &use))
|
||||||
{
|
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
return NULL;
|
else
|
||||||
}
|
{
|
||||||
if (winname)
|
|
||||||
cfree (winname);
|
|
||||||
winname = cstrdup (username);
|
winname = cstrdup (username);
|
||||||
return pdomain = cstrdup (userdomain);
|
pdomain = cstrdup (userdomain);
|
||||||
|
}
|
||||||
|
return pdomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
cygheap_user::env_userprofile ()
|
cygheap_user::env_userprofile ()
|
||||||
{
|
{
|
||||||
|
char userprofile_env_buf[MAX_PATH + 1];
|
||||||
|
cfree_and_set (puserprof, almost_null);
|
||||||
/* FIXME: Should this just be setting a puserprofile like everything else? */
|
/* FIXME: Should this just be setting a puserprofile like everything else? */
|
||||||
if (!strcasematch (env_name (), "SYSTEM")
|
if (!strcasematch (env_name (), "SYSTEM")
|
||||||
&& get_registry_hive_path (sid (), userprofile_env_buf))
|
&& get_registry_hive_path (sid (), userprofile_env_buf))
|
||||||
return userprofile_env_buf;
|
puserprof = cstrdup (userprofile_env_buf);
|
||||||
|
|
||||||
return NULL;
|
return puserprof;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
|
@ -288,6 +288,8 @@ extern bool cygwin_testing;
|
||||||
extern unsigned _cygwin_testing_magic;
|
extern unsigned _cygwin_testing_magic;
|
||||||
extern HMODULE cygwin_hmodule;
|
extern HMODULE cygwin_hmodule;
|
||||||
|
|
||||||
|
extern char almost_null[];
|
||||||
|
|
||||||
#define winsock2_active (wsadata.wVersion >= 512)
|
#define winsock2_active (wsadata.wVersion >= 512)
|
||||||
#define winsock_active (wsadata.wVersion < 512)
|
#define winsock_active (wsadata.wVersion < 512)
|
||||||
extern struct WSAData wsadata;
|
extern struct WSAData wsadata;
|
||||||
|
|
Loading…
Reference in New Issue