* uinfo.cc (cygheap_user::ontherange): Potentially set HOME from existing

homepath and homedrive cygheap_user fields (not currently used yet).  Set HOME
to / if no other alternative.
(cygheap_user::test_uid): Simplify.
This commit is contained in:
Christopher Faylor 2002-07-01 03:57:17 +00:00
parent fad1c3a8e0
commit 8297bda005
2 changed files with 21 additions and 10 deletions

View File

@ -1,3 +1,10 @@
2002-06-30 Christopher Faylor <cgf@redhat.com>
* uinfo.cc (cygheap_user::ontherange): Potentially set HOME from
existing homepath and homedrive cygheap_user fields (not currently used
yet). Set HOME to / if no other alternative.
(cygheap_user::test_uid): Simplify.
2002-06-30 Christopher Faylor <cgf@redhat.com> 2002-06-30 Christopher Faylor <cgf@redhat.com>
* environ.cc (parse_options): Use setenv to potentially replace CYGWIN * environ.cc (parse_options): Use setenv to potentially replace CYGWIN

View File

@ -204,10 +204,14 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
if (what == CH_HOME) if (what == CH_HOME)
{ {
char *p; char *p;
if ((p = getenv ("HOMEDRIVE"))) if (homedrive)
newhomedrive = homedrive;
else if ((p = getenv ("HOMEDRIVE")))
newhomedrive = p; newhomedrive = p;
if ((p = getenv ("HOMEPATH"))) if (homepath)
newhomepath = homepath;
else if ((p = getenv ("HOMEPATH")))
newhomepath = p; newhomepath = p;
if ((p = getenv ("HOME"))) if ((p = getenv ("HOME")))
@ -218,18 +222,20 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
pw = getpwnam (name ()); pw = getpwnam (name ());
if (pw && pw->pw_dir && *pw->pw_dir) if (pw && pw->pw_dir && *pw->pw_dir)
{ {
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);
setenv ("HOME", pw->pw_dir, 1);
} }
else if (newhomedrive && newhomepath) else if (!newhomedrive || !newhomepath)
setenv ("HOME", "/", 1);
else
{ {
char home[MAX_PATH]; char home[MAX_PATH];
char buf[MAX_PATH + 1]; char buf[MAX_PATH + 1];
strcpy (buf, newhomedrive); strcpy (buf, newhomedrive);
strcat (buf, newhomepath); strcat (buf, newhomepath);
cygwin_conv_to_full_posix_path (buf, home); cygwin_conv_to_full_posix_path (buf, home);
setenv ("HOME", home, 1);
debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home); debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home);
setenv ("HOME", home, 1);
} }
} }
} }
@ -285,11 +291,11 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
} }
} }
if (newhomedrive) if (newhomedrive && newhomedrive != homedrive)
cfree_and_set (homedrive, (newhomedrive == almost_null) cfree_and_set (homedrive, (newhomedrive == almost_null)
? almost_null : cstrdup (newhomedrive)); ? almost_null : cstrdup (newhomedrive));
if (newhomepath) if (newhomepath && newhomepath != homepath)
cfree_and_set (homepath, cstrdup (newhomepath)); cfree_and_set (homepath, cstrdup (newhomepath));
switch (what) switch (what)
@ -306,9 +312,7 @@ cygheap_user::ontherange (homebodies what, struct passwd *pw)
const char * const char *
cygheap_user::test_uid (char *&what, const char *name, size_t namelen) cygheap_user::test_uid (char *&what, const char *name, size_t namelen)
{ {
if (what) if (!what && !issetuid ())
return what;
if (!issetuid ())
what = getwinenveq (name, namelen, HEAP_STR); what = getwinenveq (name, namelen, HEAP_STR);
return what; return what;
} }