* 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:
Christopher Faylor 2002-06-27 20:44:27 +00:00
parent 54be629f41
commit 179cae11d7
8 changed files with 89 additions and 52 deletions

View File

@ -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>
* dcrt0.cc (dll_crt0_1): Let __progname point to the applications

View File

@ -327,6 +327,14 @@ cfree (void *s)
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
ccalloc (cygheap_types x, DWORD n, DWORD size)
{
@ -453,15 +461,11 @@ cygheap_user::set_name (const char *new_name)
if (!allocated)
return; /* Initializing. Don't bother with other stuff. */
homedrive = NULL;
homepath = NULL;
if (plogsrv)
cfree (plogsrv);
if (pdomain)
cfree (pdomain);
if (winname)
cfree (winname);
plogsrv = pdomain = winname = NULL;
cfree_and_set (homedrive);
cfree_and_set (homepath);
cfree_and_set (plogsrv);
cfree_and_set (pdomain);
cfree_and_set (winname);
}
BOOL

View File

@ -104,15 +104,9 @@ class cygheap_user
char *homedrive; /* User's home drive */
char *homepath; /* User's home path */
char *winname; /* User's name as far as Windows knows it */
char *puserprof; /* User profile */
PSID psid; /* buffer for user's SID */
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:
__uid32_t orig_uid; /* Remains intact even after impersonation */
__gid32_t orig_gid; /* Ditto */
@ -124,9 +118,17 @@ public:
HANDLE token;
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),
homedrive (NULL), homepath (NULL),
psid (NULL), token (INVALID_HANDLE_VALUE) {}
homedrive (NULL), homepath (NULL), psid (NULL),
token (INVALID_HANDLE_VALUE) {}
*/
~cygheap_user ();
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)));
char *__stdcall cstrdup (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 ();
}

View File

@ -75,6 +75,8 @@ MTinterface _mtinterf;
bool NO_COPY _cygwin_testing;
unsigned NO_COPY _cygwin_testing_magic;
char NO_COPY almost_null[1];
extern "C"
{
void *export_malloc (unsigned int);

View File

@ -759,7 +759,7 @@ struct spenv
__attribute__ ((regparm (3)));
};
char env_dontadd[] = "";
#define env_dontadd almost_null
/* Keep this list in upper case and sorted */
static NO_COPY spenv spenvs[] =

View File

@ -1969,7 +1969,6 @@ seteuid32 (__uid32_t uid)
BOOL sav_impersonated, sav_token_is_internal_token;
BOOL process_ok, explicitly_created_token = FALSE;
struct passwd * pw_new;
cygheap_user user;
PSID origpsid, psid2 = NO_SID;
debug_printf ("uid: %d myself->gid: %d", uid, myself->gid);

View File

@ -187,31 +187,26 @@ cuserid (char *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 *
cygheap_user::ontherange (homebodies what, struct passwd *pw)
{
LPUSER_INFO_3 ui = NULL;
WCHAR wuser[UNLEN + 1];
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)
{
char *p;
if ((p = getenv ("HOMEDRIVE")))
{
memcpy (homedrive_env_buf, p, 2);
homedrive = homedrive_env_buf;
}
newhomedrive = p;
if ((p = getenv ("HOMEPATH")))
{
strcpy (homepath_env_buf, p);
homepath = homepath_env_buf;
}
newhomepath = p;
if ((p = getenv ("HOME")))
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);
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 buf[MAX_PATH + 1];
strcpy (buf, homedrive);
strcat (buf, homepath);
strcpy (buf, newhomedrive);
strcat (buf, newhomepath);
cygwin_conv_to_full_posix_path (buf, home);
setenv ("HOME", home, 1);
debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home);
}
}
return NULL;
}
if (homedrive == NULL || !homedrive[0])
if (homepath == NULL && newhomepath == NULL)
{
if (!pw)
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);
else
{
homepath_env_buf[0] = homepath_env_buf[1] = '\0';
if (env_logsrv ())
{
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] != ':')
{
homedrive_env_buf[0] = homedrive_env_buf[1] = '\0';
homepath = homepath_env_buf;
newhomedrive = almost_null;
newhomepath = homepath_env_buf;
}
else
{
homedrive_env_buf[0] = homepath_env_buf[0];
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)
{
case CH_HOMEDRIVE:
@ -308,9 +311,10 @@ cygheap_user::env_logsrv ()
return NULL;
char logsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
if (!get_logon_server (env_domain (), logsrv, NULL))
return NULL;
return plogsrv = cstrdup (logsrv);
cfree_and_set (plogsrv, almost_null);
if (get_logon_server (env_domain (), logsrv, NULL))
plogsrv = cstrdup (logsrv);
return plogsrv;
}
const char *
@ -325,27 +329,30 @@ cygheap_user::env_domain ()
DWORD dlen = sizeof (userdomain);
SID_NAME_USE use;
cfree_and_set (winname, almost_null);
cfree_and_set (pdomain, almost_null);
if (!LookupAccountSid (NULL, sid (), username, &ulen,
userdomain, &dlen, &use))
__seterrno ();
else
{
__seterrno ();
return NULL;
winname = cstrdup (username);
pdomain = cstrdup (userdomain);
}
if (winname)
cfree (winname);
winname = cstrdup (username);
return pdomain = cstrdup (userdomain);
return pdomain;
}
const char *
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? */
if (!strcasematch (env_name (), "SYSTEM")
&& get_registry_hive_path (sid (), userprofile_env_buf))
return userprofile_env_buf;
puserprof = cstrdup (userprofile_env_buf);
return NULL;
return puserprof;
}
const char *

View File

@ -288,6 +288,8 @@ extern bool cygwin_testing;
extern unsigned _cygwin_testing_magic;
extern HMODULE cygwin_hmodule;
extern char almost_null[];
#define winsock2_active (wsadata.wVersion >= 512)
#define winsock_active (wsadata.wVersion < 512)
extern struct WSAData wsadata;