2000-02-18 03:38:33 +08:00
|
|
|
/* uinfo.cc: user info (uid, gid, etc...)
|
|
|
|
|
* child_info.h, cygheap.h, fhandler_clipboard.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, thread.h, uinfo.cc, include/cygwin/acl.h: Fix copyright.
2002-02-10 21:50:13 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#include "winsup.h"
|
2000-08-03 00:28:18 +08:00
|
|
|
#include <pwd.h>
|
2000-07-30 00:24:59 +08:00
|
|
|
#include <unistd.h>
|
2000-07-28 01:30:51 +08:00
|
|
|
#include <winnls.h>
|
2001-05-01 02:21:48 +08:00
|
|
|
#include <wininet.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <utmp.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <lm.h>
|
2001-10-16 07:39:33 +08:00
|
|
|
#include <errno.h>
|
2000-11-16 17:53:26 +08:00
|
|
|
#include <sys/cygwin.h>
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "fhandler.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "dtable.h"
|
2001-10-16 07:39:33 +08:00
|
|
|
#include "cygerrno.h"
|
2000-11-15 08:13:09 +08:00
|
|
|
#include "cygheap.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "registry.h"
|
2002-06-15 02:01:21 +08:00
|
|
|
#include "child_info.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
void
|
2000-11-16 05:14:27 +08:00
|
|
|
internal_getlogin (cygheap_user &user)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-25 20:54:21 +08:00
|
|
|
struct passwd *pw = NULL;
|
2000-11-15 08:13:09 +08:00
|
|
|
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (wincap.has_security ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-06-15 02:01:21 +08:00
|
|
|
HANDLE ptok = INVALID_HANDLE_VALUE;
|
2002-02-10 19:15:56 +08:00
|
|
|
DWORD siz;
|
|
|
|
cygsid tu;
|
2002-06-15 02:01:21 +08:00
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
/* Try to get the SID either from current process and
|
|
|
|
store it in user.psid */
|
2002-06-19 23:27:27 +08:00
|
|
|
if (!OpenProcessToken (hMainProc, TOKEN_ADJUST_DEFAULT | TOKEN_QUERY,
|
2002-06-15 02:01:21 +08:00
|
|
|
&ptok))
|
|
|
|
system_printf ("OpenProcessToken(): %E\n");
|
2002-02-10 19:15:56 +08:00
|
|
|
else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz))
|
2002-06-15 02:01:21 +08:00
|
|
|
system_printf ("GetTokenInformation(): %E");
|
2002-02-10 19:15:56 +08:00
|
|
|
else if (!(ret = user.set_sid (tu)))
|
2002-06-21 13:01:17 +08:00
|
|
|
system_printf ("Couldn't retrieve SID from access token!");
|
2002-06-15 02:01:21 +08:00
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
cygsid gsid (NO_SID);
|
2002-02-10 19:15:56 +08:00
|
|
|
cygsid psid;
|
2001-06-10 05:25:55 +08:00
|
|
|
|
2002-02-10 19:15:56 +08:00
|
|
|
for (int pidx = 0; (pw = internal_getpwent (pidx)); ++pidx)
|
|
|
|
if (psid.getfrompw (pw) && EqualSid (user.sid (), psid))
|
|
|
|
{
|
|
|
|
user.set_name (pw->pw_name);
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
struct __group32 *gr = getgrgid32 (pw->pw_gid);
|
2002-02-10 19:15:56 +08:00
|
|
|
if (gr)
|
|
|
|
if (!gsid.getfromgr (gr))
|
|
|
|
gsid = NO_SID;
|
|
|
|
break;
|
|
|
|
}
|
2001-06-10 05:25:55 +08:00
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
/* Set token owner to the same value as token user and
|
|
|
|
primary group to the group in /etc/passwd. */
|
2002-02-10 19:15:56 +08:00
|
|
|
if (!SetTokenInformation (ptok, TokenOwner, &tu, sizeof tu))
|
|
|
|
debug_printf ("SetTokenInformation(TokenOwner): %E");
|
|
|
|
if (gsid && !SetTokenInformation (ptok, TokenPrimaryGroup,
|
|
|
|
&gsid, sizeof gsid))
|
|
|
|
debug_printf ("SetTokenInformation(TokenPrimaryGroup): %E");
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
2002-02-10 19:15:56 +08:00
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
if (ptok != INVALID_HANDLE_VALUE)
|
2002-02-10 19:15:56 +08:00
|
|
|
CloseHandle (ptok);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-02-10 19:15:56 +08:00
|
|
|
|
2001-10-29 19:53:52 +08:00
|
|
|
if (!pw)
|
2002-06-12 13:13:54 +08:00
|
|
|
pw = getpwnam (user.name ());
|
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
if (pw)
|
|
|
|
{
|
|
|
|
user.real_uid = pw->pw_uid;
|
|
|
|
user.real_gid = pw->pw_gid;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
user.real_uid = DEFAULT_UID;
|
|
|
|
user.real_gid = DEFAULT_GID;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void) cygheap->user.ontherange (CH_HOME, pw);
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
return;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uinfo_init ()
|
|
|
|
{
|
2002-06-15 02:01:21 +08:00
|
|
|
if (!child_proc_info)
|
|
|
|
internal_getlogin (cygheap->user); /* Set the cygheap->user. */
|
|
|
|
|
|
|
|
/* Real and effective uid/gid are identical on process start up. */
|
|
|
|
myself->uid = cygheap->user.orig_uid = cygheap->user.real_uid;
|
|
|
|
myself->gid = cygheap->user.orig_gid = cygheap->user.real_gid;
|
|
|
|
cygheap->user.set_orig_sid(); /* Update the original sid */
|
|
|
|
|
|
|
|
cygheap->user.token = INVALID_HANDLE_VALUE; /* No token present */
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" char *
|
|
|
|
getlogin (void)
|
|
|
|
{
|
|
|
|
#ifdef _MT_SAFE
|
2001-03-19 05:11:25 +08:00
|
|
|
char *this_username=_reent_winsup ()->_username;
|
2000-02-18 03:38:33 +08:00
|
|
|
#else
|
2002-02-17 12:59:55 +08:00
|
|
|
static char this_username[UNLEN + 1] NO_COPY;
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
|
|
|
|
2000-11-15 08:13:09 +08:00
|
|
|
return strcpy (this_username, cygheap->user.name ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-05-29 23:04:29 +08:00
|
|
|
extern "C" __uid32_t
|
|
|
|
getuid32 (void)
|
|
|
|
{
|
|
|
|
return cygheap->user.real_uid;
|
|
|
|
}
|
|
|
|
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
extern "C" __uid16_t
|
2000-02-18 03:38:33 +08:00
|
|
|
getuid (void)
|
|
|
|
{
|
2000-11-15 08:13:09 +08:00
|
|
|
return cygheap->user.real_uid;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
extern "C" __gid32_t
|
|
|
|
getgid32 (void)
|
|
|
|
{
|
|
|
|
return cygheap->user.real_gid;
|
|
|
|
}
|
|
|
|
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
extern "C" __gid16_t
|
2000-02-18 03:38:33 +08:00
|
|
|
getgid (void)
|
|
|
|
{
|
2000-11-15 08:13:09 +08:00
|
|
|
return cygheap->user.real_gid;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-05-29 23:04:29 +08:00
|
|
|
extern "C" __uid32_t
|
|
|
|
geteuid32 (void)
|
|
|
|
{
|
|
|
|
return myself->uid;
|
|
|
|
}
|
|
|
|
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
extern "C" __uid16_t
|
2000-02-18 03:38:33 +08:00
|
|
|
geteuid (void)
|
|
|
|
{
|
2000-06-17 03:36:07 +08:00
|
|
|
return myself->uid;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
Change internal gid datatype from __gid16_t to __gid32_t
throughout.
* cygwin.din: Export new symbols chown32, fchown32, getegid32,
getgid32, getgrgid32, getgrnam32, getgroups32, initgroups32, lchown32,
setgid32, setegid32, getgrent32.
* grp.cc (grp32togrp16): New static function.
(getgrgid32): New function.
(getgrnam32): Ditto.
(getgrent32): Ditto.
(getgroups32): Change name of internal function from getgroups.
(getgroups32): New function.
(initgroups32): Ditto.
* syscalls.cc (chown32): Ditto.
(lchown32): Ditto.
(fchown32): Ditto.
(setegid32): Ditto.
(setgid32): Ditto.
* uinfo.cc (getgid32): Ditto.
(getegid32): Ditto.
* include/cygwin/grp.h: Remove declaration of getgrgid() and getgrnam().
Declare getgrgid32() and getgrnam32() instead. Declare getgid32().
2002-05-28 22:10:55 +08:00
|
|
|
extern "C" __gid32_t
|
|
|
|
getegid32 (void)
|
|
|
|
{
|
|
|
|
return myself->gid;
|
|
|
|
}
|
|
|
|
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
extern "C" __gid16_t
|
2000-02-18 03:38:33 +08:00
|
|
|
getegid (void)
|
|
|
|
{
|
2000-06-17 03:36:07 +08:00
|
|
|
return myself->gid;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Not quite right - cuserid can change, getlogin can't */
|
|
|
|
extern "C" char *
|
|
|
|
cuserid (char *src)
|
|
|
|
{
|
2002-06-12 13:13:54 +08:00
|
|
|
if (!src)
|
|
|
|
return getlogin ();
|
|
|
|
|
|
|
|
strcpy (src, getlogin ());
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
2002-06-15 04:36:42 +08:00
|
|
|
char cygheap_user::homepath_env_buf[MAX_PATH + 1];
|
|
|
|
char cygheap_user::homedrive_env_buf[3];
|
2002-06-15 05:46:19 +08:00
|
|
|
char cygheap_user::userprofile_env_buf[MAX_PATH + 1];
|
2002-06-15 04:36:42 +08:00
|
|
|
|
2002-06-12 13:13:54 +08:00
|
|
|
const char *
|
|
|
|
cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
|
|
|
{
|
|
|
|
LPUSER_INFO_3 ui = NULL;
|
|
|
|
WCHAR wuser[UNLEN + 1];
|
|
|
|
NET_API_STATUS ret;
|
|
|
|
|
|
|
|
if (what == CH_HOME)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
if ((p = getenv ("HOMEDRIVE")))
|
|
|
|
{
|
2002-06-15 04:36:42 +08:00
|
|
|
memcpy (homedrive_env_buf, p, 2);
|
|
|
|
homedrive = homedrive_env_buf;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2002-06-12 13:13:54 +08:00
|
|
|
if ((p = getenv ("HOMEPATH")))
|
|
|
|
{
|
2002-06-15 04:36:42 +08:00
|
|
|
strcpy (homepath_env_buf, p);
|
|
|
|
homepath = homepath_env_buf;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2002-06-12 13:13:54 +08:00
|
|
|
if ((p = getenv ("HOME")))
|
|
|
|
debug_printf ("HOME is already in the environment %s", p);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!pw)
|
|
|
|
pw = getpwnam (name ());
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
else if (homedrive && homepath)
|
|
|
|
{
|
|
|
|
char home[MAX_PATH];
|
2002-06-15 04:36:42 +08:00
|
|
|
char buf[MAX_PATH + 1];
|
2002-06-12 13:13:54 +08:00
|
|
|
strcpy (buf, homedrive);
|
|
|
|
strcat (buf, homepath);
|
|
|
|
cygwin_conv_to_full_posix_path (buf, home);
|
|
|
|
setenv ("HOME", home, 1);
|
|
|
|
debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home);
|
|
|
|
}
|
|
|
|
}
|
2002-06-15 09:17:45 +08:00
|
|
|
return NULL;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
if (homedrive == NULL || !homedrive[0])
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-06-12 13:13:54 +08:00
|
|
|
if (!pw)
|
|
|
|
pw = getpwnam (name ());
|
|
|
|
if (pw && pw->pw_dir && *pw->pw_dir)
|
2002-06-15 04:36:42 +08:00
|
|
|
cygwin_conv_to_full_win32_path (pw->pw_dir, homepath_env_buf);
|
2002-06-12 13:13:54 +08:00
|
|
|
else
|
|
|
|
{
|
2002-06-19 21:56:34 +08:00
|
|
|
if (env_logsrv ())
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-06-19 21:56:34 +08:00
|
|
|
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
|
|
|
sys_mbstowcs (wlogsrv, env_logsrv (),
|
|
|
|
sizeof (wlogsrv) / sizeof(*wlogsrv));
|
2002-06-21 13:01:17 +08:00
|
|
|
sys_mbstowcs (wuser, env_name (), sizeof (wuser) / sizeof (*wuser));
|
2002-06-19 21:56:34 +08:00
|
|
|
if (!(ret = NetUserGetInfo (wlogsrv, wuser, 3,(LPBYTE *)&ui)))
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-06-19 21:56:34 +08:00
|
|
|
char *p;
|
|
|
|
sys_wcstombs (homepath_env_buf, ui->usri3_home_dir, MAX_PATH);
|
|
|
|
if (!homepath_env_buf[0])
|
|
|
|
{
|
|
|
|
sys_wcstombs (homepath_env_buf, ui->usri3_home_dir_drive,
|
|
|
|
MAX_PATH);
|
|
|
|
if (homepath_env_buf[0])
|
|
|
|
strcat (homepath_env_buf, "\\");
|
|
|
|
else if (!GetSystemDirectory (homepath_env_buf, MAX_PATH))
|
|
|
|
strcpy (homepath_env_buf, "c:\\");
|
|
|
|
else if ((p = strchr (homepath_env_buf, '\\')))
|
|
|
|
p[1] = '\0';
|
|
|
|
}
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ui)
|
|
|
|
NetApiBufferFree (ui);
|
|
|
|
}
|
|
|
|
|
2002-06-15 04:36:42 +08:00
|
|
|
if (homepath_env_buf[1] != ':')
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-06-15 04:36:42 +08:00
|
|
|
homedrive_env_buf[0] = homedrive_env_buf[1] = '\0';
|
|
|
|
homepath = homepath_env_buf;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-15 04:36:42 +08:00
|
|
|
homedrive_env_buf[0] = homepath_env_buf[0];
|
|
|
|
homedrive_env_buf[1] = homepath_env_buf[1];
|
|
|
|
homepath = homepath_env_buf + 2;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2002-06-15 04:36:42 +08:00
|
|
|
homedrive = homedrive_env_buf;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-06-12 13:13:54 +08:00
|
|
|
|
|
|
|
switch (what)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-06-12 13:13:54 +08:00
|
|
|
case CH_HOMEDRIVE:
|
|
|
|
return homedrive;
|
|
|
|
case CH_HOMEPATH:
|
|
|
|
return homepath;
|
|
|
|
default:
|
|
|
|
return homepath;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
2002-06-12 13:13:54 +08:00
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_logsrv ()
|
|
|
|
{
|
2002-06-15 02:01:21 +08:00
|
|
|
if (plogsrv)
|
|
|
|
return plogsrv;
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-06-21 13:01:17 +08:00
|
|
|
if (!env_domain () || strcasematch (env_name (), "SYSTEM"))
|
2002-06-16 13:26:14 +08:00
|
|
|
return NULL;
|
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
char logsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
|
|
|
if (!get_logon_server (env_domain (), logsrv, NULL))
|
|
|
|
return NULL;
|
|
|
|
return plogsrv = cstrdup (logsrv);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_domain ()
|
|
|
|
{
|
|
|
|
if (pdomain)
|
|
|
|
return pdomain;
|
|
|
|
|
|
|
|
char username[UNLEN + 1];
|
|
|
|
DWORD ulen = sizeof (username);
|
|
|
|
char userdomain[DNLEN + 1];
|
|
|
|
DWORD dlen = sizeof (userdomain);
|
|
|
|
SID_NAME_USE use;
|
|
|
|
|
|
|
|
if (!LookupAccountSid (NULL, sid (), username, &ulen,
|
|
|
|
userdomain, &dlen, &use))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-06-16 13:26:14 +08:00
|
|
|
if (winname)
|
|
|
|
cfree (winname);
|
|
|
|
winname = cstrdup (username);
|
2002-06-15 02:01:21 +08:00
|
|
|
return pdomain = cstrdup (userdomain);
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_userprofile ()
|
|
|
|
{
|
2002-06-16 13:26:14 +08:00
|
|
|
/* FIXME: Should this just be setting a puserprofile like everything else? */
|
|
|
|
if (!strcasematch (env_name (), "SYSTEM")
|
|
|
|
&& get_registry_hive_path (sid (), userprofile_env_buf))
|
2002-06-15 05:46:19 +08:00
|
|
|
return userprofile_env_buf;
|
2002-06-16 13:26:14 +08:00
|
|
|
|
|
|
|
return NULL;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_homepath ()
|
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEPATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_homedrive ()
|
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEDRIVE);
|
|
|
|
}
|
2002-06-15 02:01:21 +08:00
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_name ()
|
|
|
|
{
|
2002-06-16 13:26:14 +08:00
|
|
|
(void) env_domain ();
|
|
|
|
return winname;
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|