2000-02-17 20:38:33 +01:00
|
|
|
/* uinfo.cc: user info (uid, gid, etc...)
|
|
|
|
|
2003-01-17 06:43:43 +01:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-17 20:38:33 +01: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-02 18:28:18 +02:00
|
|
|
#include <pwd.h>
|
2000-07-29 18:24:59 +02:00
|
|
|
#include <unistd.h>
|
2000-07-27 19:30:51 +02:00
|
|
|
#include <winnls.h>
|
2001-04-30 20:21:48 +02:00
|
|
|
#include <wininet.h>
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <utmp.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <lm.h>
|
2000-11-16 10:53:26 +01:00
|
|
|
#include <sys/cygwin.h>
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "pinfo.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2001-04-18 23:10:15 +02:00
|
|
|
#include "fhandler.h"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include "path.h"
|
2001-04-18 23:10:15 +02:00
|
|
|
#include "dtable.h"
|
2001-10-16 01:39:33 +02:00
|
|
|
#include "cygerrno.h"
|
2000-11-15 01:13:09 +01:00
|
|
|
#include "cygheap.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "registry.h"
|
2002-06-14 20:01:21 +02:00
|
|
|
#include "child_info.h"
|
2002-06-29 04:36:08 +02:00
|
|
|
#include "environ.h"
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 13:43:49 +01:00
|
|
|
#include "pwdgrp.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-06-14 20:01:21 +02:00
|
|
|
void
|
2000-11-15 22:14:27 +01:00
|
|
|
internal_getlogin (cygheap_user &user)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2001-04-25 14:54:21 +02:00
|
|
|
struct passwd *pw = NULL;
|
2002-11-20 18:10:05 +01:00
|
|
|
HANDLE ptok = INVALID_HANDLE_VALUE;
|
2000-11-15 01:13:09 +01:00
|
|
|
|
2003-02-06 15:01:54 +01:00
|
|
|
myself->gid = UNKNOWN_GID;
|
* 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-12 19:46:37 +02:00
|
|
|
if (wincap.has_security ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-02-10 12:15:56 +01:00
|
|
|
DWORD siz;
|
|
|
|
cygsid tu;
|
2002-06-14 20:01:21 +02:00
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
/* Try to get the SID either from current process and
|
|
|
|
store it in user.psid */
|
2002-06-19 17:27:27 +02:00
|
|
|
if (!OpenProcessToken (hMainProc, TOKEN_ADJUST_DEFAULT | TOKEN_QUERY,
|
2002-06-14 20:01:21 +02:00
|
|
|
&ptok))
|
2002-09-30 06:35:18 +02:00
|
|
|
system_printf ("OpenProcessToken(): %E");
|
2002-02-10 12:15:56 +01:00
|
|
|
else if (!GetTokenInformation (ptok, TokenUser, &tu, sizeof tu, &siz))
|
2002-07-29 14:51:52 +02:00
|
|
|
system_printf ("GetTokenInformation (TokenUser): %E");
|
2002-02-10 12:15:56 +01:00
|
|
|
else if (!(ret = user.set_sid (tu)))
|
2002-06-21 07:01:17 +02:00
|
|
|
system_printf ("Couldn't retrieve SID from access token!");
|
2002-07-29 14:51:52 +02:00
|
|
|
else if (!GetTokenInformation (ptok, TokenPrimaryGroup,
|
|
|
|
&user.groups.pgsid, sizeof tu, &siz))
|
|
|
|
system_printf ("GetTokenInformation (TokenPrimaryGroup): %E");
|
2002-06-14 20:01:21 +02: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 */
|
2002-11-20 18:10:05 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
2002-11-25 16:11:39 +01:00
|
|
|
pw = internal_getpwsid (tu);
|
2002-11-20 18:10:05 +01:00
|
|
|
/* Set token owner to the same value as token user */
|
2002-02-10 12:15:56 +01:00
|
|
|
if (!SetTokenInformation (ptok, TokenOwner, &tu, sizeof tu))
|
|
|
|
debug_printf ("SetTokenInformation(TokenOwner): %E");
|
2002-06-14 20:01:21 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2002-02-10 12:15:56 +01:00
|
|
|
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 13:43:49 +01:00
|
|
|
if (!pw && !(pw = internal_getpwnam (user.name ()))
|
|
|
|
&& !(pw = internal_getpwuid (DEFAULT_UID)))
|
2002-11-25 16:11:39 +01:00
|
|
|
debug_printf("user not found in augmented /etc/passwd");
|
2002-11-20 18:10:05 +01:00
|
|
|
else
|
2002-06-14 20:01:21 +02:00
|
|
|
{
|
2002-06-24 17:40:57 +02:00
|
|
|
myself->uid = pw->pw_uid;
|
|
|
|
myself->gid = pw->pw_gid;
|
2002-11-25 16:11:39 +01:00
|
|
|
user.set_name (pw->pw_name);
|
2002-11-20 18:10:05 +01:00
|
|
|
if (wincap.has_security ())
|
2002-11-27 03:26:44 +01:00
|
|
|
{
|
2002-11-20 18:10:05 +01:00
|
|
|
cygsid gsid;
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 13:43:49 +01:00
|
|
|
if (gsid.getfromgr (internal_getgrgid (pw->pw_gid)))
|
2002-11-20 18:10:05 +01:00
|
|
|
{
|
|
|
|
/* Set primary group to the group in /etc/passwd. */
|
|
|
|
if (!SetTokenInformation (ptok, TokenPrimaryGroup,
|
|
|
|
&gsid, sizeof gsid))
|
|
|
|
debug_printf ("SetTokenInformation(TokenPrimaryGroup): %E");
|
2003-02-27 18:41:15 +01:00
|
|
|
else
|
|
|
|
user.groups.pgsid = gsid;
|
2002-11-20 18:10:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
debug_printf ("gsid not found in augmented /etc/group");
|
|
|
|
}
|
2002-06-14 20:01:21 +02:00
|
|
|
}
|
2002-11-20 18:10:05 +01:00
|
|
|
if (ptok != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (ptok);
|
2002-06-14 20:01:21 +02:00
|
|
|
(void) cygheap->user.ontherange (CH_HOME, pw);
|
2002-06-12 07:13:54 +02:00
|
|
|
|
2002-06-14 20:01:21 +02:00
|
|
|
return;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uinfo_init ()
|
|
|
|
{
|
2003-06-30 15:07:36 +02:00
|
|
|
if (child_proc_info && !cygheap->user.has_impersonation_tokens ())
|
2003-06-09 15:29:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!child_proc_info)
|
|
|
|
internal_getlogin (cygheap->user); /* Set the cygheap->user. */
|
|
|
|
/* Conditions must match those in spawn to allow starting child
|
|
|
|
processes with ruid != euid and rgid != egid. */
|
|
|
|
else if (cygheap->user.issetuid ()
|
|
|
|
&& cygheap->user.orig_uid == cygheap->user.real_uid
|
|
|
|
&& cygheap->user.orig_gid == cygheap->user.real_gid
|
|
|
|
&& !cygheap->user.groups.issetgroups ())
|
2003-01-25 11:36:46 +01:00
|
|
|
{
|
2003-06-30 15:07:36 +02:00
|
|
|
cygheap->user.reimpersonate ();
|
2003-06-09 15:29:12 +02:00
|
|
|
return;
|
2003-01-25 11:36:46 +01:00
|
|
|
}
|
2003-06-09 15:29:12 +02:00
|
|
|
else
|
2003-06-30 15:07:36 +02:00
|
|
|
cygheap->user.close_impersonation_tokens ();
|
2003-06-09 15:29:12 +02:00
|
|
|
|
2002-06-24 17:40:57 +02:00
|
|
|
cygheap->user.orig_uid = cygheap->user.real_uid = myself->uid;
|
|
|
|
cygheap->user.orig_gid = cygheap->user.real_gid = myself->gid;
|
2003-07-14 19:04:21 +02:00
|
|
|
cygheap->user.external_token = INVALID_HANDLE_VALUE;
|
|
|
|
cygheap->user.internal_token = INVALID_HANDLE_VALUE;
|
|
|
|
cygheap->user.current_token = INVALID_HANDLE_VALUE;
|
2003-06-09 15:29:12 +02:00
|
|
|
cygheap->user.set_orig_sid (); /* Update the original sid */
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" char *
|
|
|
|
getlogin (void)
|
|
|
|
{
|
|
|
|
#ifdef _MT_SAFE
|
2001-03-18 22:11:25 +01:00
|
|
|
char *this_username=_reent_winsup ()->_username;
|
2000-02-17 20:38:33 +01:00
|
|
|
#else
|
2002-02-17 05:59:55 +01:00
|
|
|
static char this_username[UNLEN + 1] NO_COPY;
|
2000-02-17 20:38:33 +01:00
|
|
|
#endif
|
|
|
|
|
2000-11-15 01:13:09 +01:00
|
|
|
return strcpy (this_username, cygheap->user.name ());
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-05-29 17:04:29 +02: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 14:38:51 +01:00
|
|
|
extern "C" __uid16_t
|
2000-02-17 20:38:33 +01:00
|
|
|
getuid (void)
|
|
|
|
{
|
2000-11-15 01:13:09 +01:00
|
|
|
return cygheap->user.real_uid;
|
2000-02-17 20:38:33 +01: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 16:10:55 +02: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 14:38:51 +01:00
|
|
|
extern "C" __gid16_t
|
2000-02-17 20:38:33 +01:00
|
|
|
getgid (void)
|
|
|
|
{
|
2000-11-15 01:13:09 +01:00
|
|
|
return cygheap->user.real_gid;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-05-29 17:04:29 +02: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 14:38:51 +01:00
|
|
|
extern "C" __uid16_t
|
2000-02-17 20:38:33 +01:00
|
|
|
geteuid (void)
|
|
|
|
{
|
2000-06-16 21:36:07 +02:00
|
|
|
return myself->uid;
|
2000-02-17 20:38:33 +01: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 16:10:55 +02: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 14:38:51 +01:00
|
|
|
extern "C" __gid16_t
|
2000-02-17 20:38:33 +01:00
|
|
|
getegid (void)
|
|
|
|
{
|
2000-06-16 21:36:07 +02:00
|
|
|
return myself->gid;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Not quite right - cuserid can change, getlogin can't */
|
|
|
|
extern "C" char *
|
|
|
|
cuserid (char *src)
|
|
|
|
{
|
2002-06-12 07:13:54 +02:00
|
|
|
if (!src)
|
|
|
|
return getlogin ();
|
|
|
|
|
|
|
|
strcpy (src, getlogin ());
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
|
|
|
{
|
|
|
|
LPUSER_INFO_3 ui = NULL;
|
|
|
|
WCHAR wuser[UNLEN + 1];
|
|
|
|
NET_API_STATUS ret;
|
2002-06-27 22:44:27 +02:00
|
|
|
char homepath_env_buf[MAX_PATH + 1];
|
|
|
|
char homedrive_env_buf[3];
|
|
|
|
char *newhomedrive = NULL;
|
|
|
|
char *newhomepath = NULL;
|
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
|
2002-06-29 04:36:08 +02:00
|
|
|
debug_printf ("what %d, pw %p", what, pw);
|
2002-06-12 07:13:54 +02:00
|
|
|
if (what == CH_HOME)
|
|
|
|
{
|
|
|
|
char *p;
|
2002-07-01 05:57:17 +02:00
|
|
|
if (homedrive)
|
|
|
|
newhomedrive = homedrive;
|
|
|
|
else if ((p = getenv ("HOMEDRIVE")))
|
2002-06-27 22:44:27 +02:00
|
|
|
newhomedrive = p;
|
2002-06-16 07:26:14 +02:00
|
|
|
|
2002-07-01 05:57:17 +02:00
|
|
|
if (homepath)
|
|
|
|
newhomepath = homepath;
|
|
|
|
else if ((p = getenv ("HOMEPATH")))
|
2002-06-27 22:44:27 +02:00
|
|
|
newhomepath = p;
|
2002-06-16 07:26:14 +02:00
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
if ((p = getenv ("HOME")))
|
|
|
|
debug_printf ("HOME is already in the environment %s", p);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pw && pw->pw_dir && *pw->pw_dir)
|
|
|
|
{
|
|
|
|
debug_printf ("Set HOME (from /etc/passwd) to %s", pw->pw_dir);
|
2002-07-01 05:57:17 +02:00
|
|
|
setenv ("HOME", pw->pw_dir, 1);
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
2002-07-01 05:57:17 +02:00
|
|
|
else if (!newhomedrive || !newhomepath)
|
|
|
|
setenv ("HOME", "/", 1);
|
|
|
|
else
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
|
|
|
char home[MAX_PATH];
|
2002-06-14 22:36:42 +02:00
|
|
|
char buf[MAX_PATH + 1];
|
2002-06-27 22:44:27 +02:00
|
|
|
strcpy (buf, newhomedrive);
|
|
|
|
strcat (buf, newhomepath);
|
2002-06-12 07:13:54 +02:00
|
|
|
cygwin_conv_to_full_posix_path (buf, home);
|
|
|
|
debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home);
|
2002-07-01 05:57:17 +02:00
|
|
|
setenv ("HOME", home, 1);
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 04:36:08 +02:00
|
|
|
if (what != CH_HOME && homepath == NULL && newhomepath == NULL)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-06-12 07:13:54 +02:00
|
|
|
if (!pw)
|
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* pwdgrp.h (pwdgrp_check::pwdgrp_state): Replace by
pwdgrp_check::isinitializing ().
(pwdgrp_check::isinitializing): Create.
* passwd.cc (grab_int): Change type to unsigned, use strtoul and
set the pointer content to 0 if the field is invalid.
(parse_pwd): Move validity test after getting pw_gid.
(read_etc_passwd): Replace "passwd_state <= " by
passwd_state::isinitializing ().
(internal_getpwuid): Ditto.
(internal_getpwnam): Ditto.
(getpwent): Ditto.
(getpass): Ditto.
* grp.cc (parse_grp): Use strtoul for gr_gid and verify the validity.
(read_etc_group): Replace "group_state <= " by
group_state::isinitializing ().
(internal_getgrgid): Ditto.
(getgrent32): Ditto.
(internal_getgrent): Ditto.
2002-12-10 Pierre Humblet <pierre.humblet@ieee.org>
* security.h: Move declarations of internal_getgrent,
internal_getpwsid and internal_getgrsid to pwdgrp.h.
* pwdgrp.h: Declare internal_getpwsid, internal_getpwnam,
internal_getpwuid, internal_getgrsid, internal_getgrgid,
internal_getgrnam, internal_getgrent and internal_getgroups.
Delete "emulated" from enum pwdgrp_state.
(pwdgrp_check::isuninitialized): Create.
(pwdgrp_check::pwdgrp_state): Change state to initializing
rather than to uninitialized.
(pwdgrp_read::gets): Remove trailing CRs.
* passwd.cc (grab_string): Don't look for NLs.
(grab_int): Ditto.
(parse_pwd): Don't look for CRs. Return 0 if entry is too short.
(search_for): Delete.
(read_etc_passwd): Simplify tests to actually read the file.
Set state to loaded before making internal_getpwXX calls.
Replace search_for calls by equivalent internal_pwgetXX calls.
(internal_getpwsid): Use passwd_state.isuninitialized to decide
to call read_etc_passwd.
(internal_getpwuid): Create.
(internal_getpwnam): Create.
(getpwuid32): Simply call internal_getpwuid.
(getpwuid_r32): Call internal_getpwuid.
(getpwnam): Simply call internal_getpwnam.
(getpwnam_r): Call internal_getpwnam.
* grp.cc (parse_grp): Don't look for CRs. Adjust blank space.
(add_grp_line): Adjust blank space.
(class group_lock): Ditto.
(read_etc_group): Simplify tests to actually read the file.
Set state to loaded before making internal_getgrXX calls.
Replace getgrXX calls by equivalent internal calls.
(internal_getgrsid): Use group_state.isuninitialized to decide
to call read_etc_group.
(internal_getgrgid): Create.
(internal_getgrnam): Create.
(getgroups32): Simply call internal_getgrgid.
(getgrnam32): Simply call internal_getgrnam.
(internal_getgrent): Call group_state.isuninitialized.
(internal_getgroups): Create from the former getgroups32, using
two of the four arguments. Set gid to myself->gid and username
to cygheap->user.name ().
(getgroups32): Simply call internal_getgroup.
(getgroups): Call internal_getgroup instead of getgroups32.
(setgroups32): Call internal versions of get{pw,gr}XX.
* sec_helper.cc: Include pwdgrp.h.
(is_grp_member): Call internal versions of get{pw,gr}XX.
* security.cc: Include pwdgrp.h.
(alloc_sd): Call internal versions of get{pw,gr}XX.
* syscalls.cc: Include pwdgrp.h.
(seteuid32): Call internal versions of get{pw,gr}XX.
(setegid32): Ditto.
* uinfo.cc: Include pwdgrp.h.
(internal_getlogin): Call internal versions of get{pw,gr}XX.
(cygheap_user::ontherange): Ditto.
* sec_acl.cc: Include pwdgrp.h.
(setacl): Call internal versions of get{pw,gr}XX.
(acl_access): Ditto and simplify logic.
(aclfromtext): Ditto.
2002-12-10 13:43:49 +01:00
|
|
|
pw = internal_getpwnam (name ());
|
2002-06-12 07:13:54 +02:00
|
|
|
if (pw && pw->pw_dir && *pw->pw_dir)
|
2002-06-14 22:36:42 +02:00
|
|
|
cygwin_conv_to_full_win32_path (pw->pw_dir, homepath_env_buf);
|
2002-06-12 07:13:54 +02:00
|
|
|
else
|
|
|
|
{
|
2002-06-27 22:44:27 +02:00
|
|
|
homepath_env_buf[0] = homepath_env_buf[1] = '\0';
|
2002-06-29 04:36:08 +02:00
|
|
|
if (logsrv ())
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
2002-06-19 15:56:34 +02:00
|
|
|
WCHAR wlogsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
2002-06-29 04:36:08 +02:00
|
|
|
sys_mbstowcs (wlogsrv, logsrv (),
|
2002-09-22 05:38:57 +02:00
|
|
|
sizeof (wlogsrv) / sizeof (*wlogsrv));
|
2002-06-29 04:36:08 +02:00
|
|
|
sys_mbstowcs (wuser, winname (), sizeof (wuser) / sizeof (*wuser));
|
2002-06-19 15:56:34 +02:00
|
|
|
if (!(ret = NetUserGetInfo (wlogsrv, wuser, 3,(LPBYTE *)&ui)))
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
2002-06-19 15:56:34 +02:00
|
|
|
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, "\\");
|
2002-07-01 17:50:02 +02:00
|
|
|
else
|
2002-07-01 18:37:46 +02:00
|
|
|
cygwin_conv_to_full_win32_path ("/", homepath_env_buf);
|
2002-06-19 15:56:34 +02:00
|
|
|
}
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ui)
|
|
|
|
NetApiBufferFree (ui);
|
|
|
|
}
|
|
|
|
|
2002-06-14 22:36:42 +02:00
|
|
|
if (homepath_env_buf[1] != ':')
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
2002-06-27 22:44:27 +02:00
|
|
|
newhomedrive = almost_null;
|
|
|
|
newhomepath = homepath_env_buf;
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-14 22:36:42 +02:00
|
|
|
homedrive_env_buf[0] = homepath_env_buf[0];
|
|
|
|
homedrive_env_buf[1] = homepath_env_buf[1];
|
2002-06-27 22:44:27 +02:00
|
|
|
homedrive_env_buf[2] = '\0';
|
|
|
|
newhomedrive = homedrive_env_buf;
|
|
|
|
newhomepath = homepath_env_buf + 2;
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2002-06-12 07:13:54 +02:00
|
|
|
|
2002-07-01 05:57:17 +02:00
|
|
|
if (newhomedrive && newhomedrive != homedrive)
|
2002-06-27 22:44:27 +02:00
|
|
|
cfree_and_set (homedrive, (newhomedrive == almost_null)
|
2002-09-19 05:30:20 +02:00
|
|
|
? almost_null : cstrdup (newhomedrive));
|
2002-06-27 22:44:27 +02:00
|
|
|
|
2002-07-01 05:57:17 +02:00
|
|
|
if (newhomepath && newhomepath != homepath)
|
2002-06-27 22:44:27 +02:00
|
|
|
cfree_and_set (homepath, cstrdup (newhomepath));
|
|
|
|
|
2002-06-12 07:13:54 +02:00
|
|
|
switch (what)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-06-12 07:13:54 +02:00
|
|
|
case CH_HOMEDRIVE:
|
|
|
|
return homedrive;
|
|
|
|
case CH_HOMEPATH:
|
|
|
|
return homepath;
|
|
|
|
default:
|
|
|
|
return homepath;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
2002-06-12 07:13:54 +02:00
|
|
|
|
|
|
|
const char *
|
2002-06-29 04:36:08 +02:00
|
|
|
cygheap_user::test_uid (char *&what, const char *name, size_t namelen)
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
2002-07-01 05:57:17 +02:00
|
|
|
if (!what && !issetuid ())
|
2002-06-29 08:50:17 +02:00
|
|
|
what = getwinenveq (name, namelen, HEAP_STR);
|
2002-06-29 04:36:08 +02:00
|
|
|
return what;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_logsrv (const char *name, size_t namelen)
|
|
|
|
{
|
|
|
|
if (test_uid (plogsrv, name, namelen))
|
2002-06-14 20:01:21 +02:00
|
|
|
return plogsrv;
|
2002-06-12 07:13:54 +02:00
|
|
|
|
2002-06-30 00:05:30 +02:00
|
|
|
const char *mydomain = domain ();
|
|
|
|
const char *myname = winname ();
|
|
|
|
if (!mydomain || strcasematch (myname, "SYSTEM"))
|
2002-06-29 05:14:12 +02:00
|
|
|
return almost_null;
|
2002-06-16 07:26:14 +02:00
|
|
|
|
2002-06-14 20:01:21 +02:00
|
|
|
char logsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
2002-06-27 22:44:27 +02:00
|
|
|
cfree_and_set (plogsrv, almost_null);
|
2002-06-30 00:05:30 +02:00
|
|
|
if (get_logon_server (mydomain, logsrv, NULL))
|
2002-06-27 22:44:27 +02:00
|
|
|
plogsrv = cstrdup (logsrv);
|
|
|
|
return plogsrv;
|
2002-06-14 20:01:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 04:36:08 +02:00
|
|
|
cygheap_user::env_domain (const char *name, size_t namelen)
|
2002-06-14 20:01:21 +02:00
|
|
|
{
|
2002-06-29 08:50:17 +02:00
|
|
|
if (pwinname && test_uid (pdomain, name, namelen))
|
2002-06-14 20:01:21 +02:00
|
|
|
return pdomain;
|
|
|
|
|
|
|
|
char username[UNLEN + 1];
|
|
|
|
DWORD ulen = sizeof (username);
|
|
|
|
char userdomain[DNLEN + 1];
|
|
|
|
DWORD dlen = sizeof (userdomain);
|
|
|
|
SID_NAME_USE use;
|
|
|
|
|
2002-06-29 04:36:08 +02:00
|
|
|
cfree_and_set (pwinname, almost_null);
|
2002-06-27 22:44:27 +02:00
|
|
|
cfree_and_set (pdomain, almost_null);
|
2002-06-14 20:01:21 +02:00
|
|
|
if (!LookupAccountSid (NULL, sid (), username, &ulen,
|
|
|
|
userdomain, &dlen, &use))
|
2002-06-27 22:44:27 +02:00
|
|
|
__seterrno ();
|
|
|
|
else
|
2002-06-14 20:01:21 +02:00
|
|
|
{
|
2002-06-29 04:36:08 +02:00
|
|
|
pwinname = cstrdup (username);
|
2002-06-27 22:44:27 +02:00
|
|
|
pdomain = cstrdup (userdomain);
|
2002-06-14 20:01:21 +02:00
|
|
|
}
|
2002-06-27 22:44:27 +02:00
|
|
|
return pdomain;
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 04:36:08 +02:00
|
|
|
cygheap_user::env_userprofile (const char *name, size_t namelen)
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
2002-06-29 04:36:08 +02:00
|
|
|
if (test_uid (puserprof, name, namelen))
|
|
|
|
return puserprof;
|
|
|
|
|
2002-06-27 22:44:27 +02:00
|
|
|
char userprofile_env_buf[MAX_PATH + 1];
|
|
|
|
cfree_and_set (puserprof, almost_null);
|
2002-06-16 07:26:14 +02:00
|
|
|
/* FIXME: Should this just be setting a puserprofile like everything else? */
|
2002-06-30 00:05:30 +02:00
|
|
|
const char *myname = winname ();
|
|
|
|
if (myname && strcasematch (myname, "SYSTEM")
|
2002-06-16 07:26:14 +02:00
|
|
|
&& get_registry_hive_path (sid (), userprofile_env_buf))
|
2002-06-27 22:44:27 +02:00
|
|
|
puserprof = cstrdup (userprofile_env_buf);
|
2002-06-16 07:26:14 +02:00
|
|
|
|
2002-06-27 22:44:27 +02:00
|
|
|
return puserprof;
|
2002-06-12 07:13:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 04:36:08 +02:00
|
|
|
cygheap_user::env_homepath (const char *name, size_t namelen)
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEPATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 04:36:08 +02:00
|
|
|
cygheap_user::env_homedrive (const char *name, size_t namelen)
|
2002-06-12 07:13:54 +02:00
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEDRIVE);
|
|
|
|
}
|
2002-06-14 20:01:21 +02:00
|
|
|
|
|
|
|
const char *
|
2002-06-29 04:36:08 +02:00
|
|
|
cygheap_user::env_name (const char *name, size_t namelen)
|
2002-06-14 20:01:21 +02:00
|
|
|
{
|
2002-06-29 04:36:08 +02:00
|
|
|
if (!test_uid (pwinname, name, namelen))
|
|
|
|
(void) domain ();
|
|
|
|
return pwinname;
|
2002-06-14 20:01:21 +02:00
|
|
|
}
|
2003-01-17 06:18:30 +01:00
|
|
|
|
2003-01-20 03:57:54 +01:00
|
|
|
char *
|
2003-01-24 04:53:46 +01:00
|
|
|
pwdgrp::next_str (char c)
|
2003-01-17 06:18:30 +01:00
|
|
|
{
|
2003-01-24 04:53:46 +01:00
|
|
|
char *res = lptr;
|
2003-01-27 01:16:01 +01:00
|
|
|
lptr = strechr (lptr, c);
|
|
|
|
if (*lptr)
|
|
|
|
*lptr++ = '\0';
|
2003-01-24 04:53:46 +01:00
|
|
|
return res;
|
2003-01-20 03:57:54 +01:00
|
|
|
}
|
2003-01-17 06:18:30 +01:00
|
|
|
|
2003-01-26 06:38:38 +01:00
|
|
|
bool
|
|
|
|
pwdgrp::next_num (unsigned long& n)
|
2003-01-24 04:53:46 +01:00
|
|
|
{
|
2003-01-27 01:16:01 +01:00
|
|
|
char *p = next_str (':');
|
2003-01-24 04:53:46 +01:00
|
|
|
char *cp;
|
2003-01-26 06:38:38 +01:00
|
|
|
n = strtoul (p, &cp, 10);
|
|
|
|
return p != cp && !*cp;
|
2003-01-24 04:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
pwdgrp::add_line (char *eptr)
|
2003-01-20 03:57:54 +01:00
|
|
|
{
|
2003-01-24 04:53:46 +01:00
|
|
|
if (eptr)
|
2003-01-20 03:57:54 +01:00
|
|
|
{
|
2003-01-24 04:53:46 +01:00
|
|
|
lptr = eptr;
|
2003-01-27 01:31:30 +01:00
|
|
|
eptr = strchr (lptr, '\n');
|
|
|
|
if (eptr)
|
2003-01-24 04:53:46 +01:00
|
|
|
{
|
|
|
|
if (eptr > lptr && eptr[-1] == '\r')
|
2003-01-27 01:16:01 +01:00
|
|
|
eptr[-1] = '\0';
|
|
|
|
else
|
|
|
|
*eptr = '\0';
|
2003-01-24 04:53:46 +01:00
|
|
|
eptr++;
|
|
|
|
}
|
|
|
|
if (curr_lines >= max_lines)
|
|
|
|
{
|
|
|
|
max_lines += 10;
|
|
|
|
*pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
|
|
|
|
}
|
2003-01-26 06:38:38 +01:00
|
|
|
if ((this->*parse) ())
|
|
|
|
curr_lines++;
|
2003-01-20 03:57:54 +01:00
|
|
|
}
|
2003-01-24 04:53:46 +01:00
|
|
|
return eptr;
|
2003-01-17 06:18:30 +01:00
|
|
|
}
|
|
|
|
|
2003-01-26 06:38:38 +01:00
|
|
|
void
|
2003-01-20 03:57:54 +01:00
|
|
|
pwdgrp::load (const char *posix_fname)
|
2003-01-17 06:18:30 +01:00
|
|
|
{
|
2003-01-26 06:38:38 +01:00
|
|
|
const char *res;
|
|
|
|
static const char failed[] = "failed";
|
|
|
|
static const char succeeded[] = "succeeded";
|
|
|
|
|
2003-01-20 03:57:54 +01:00
|
|
|
if (buf)
|
|
|
|
free (buf);
|
|
|
|
buf = NULL;
|
2003-08-17 19:50:40 +02:00
|
|
|
curr_lines = 0;
|
2003-01-20 03:57:54 +01:00
|
|
|
|
|
|
|
pc.check (posix_fname);
|
2003-01-21 07:58:11 +01:00
|
|
|
etc_ix = etc::init (etc_ix, pc);
|
2003-01-20 03:57:54 +01:00
|
|
|
|
|
|
|
paranoid_printf ("%s", posix_fname);
|
2003-01-17 06:18:30 +01:00
|
|
|
|
2003-01-20 03:57:54 +01:00
|
|
|
if (pc.error || !pc.exists () || !pc.isdisk () || pc.isdir ())
|
2003-01-26 06:38:38 +01:00
|
|
|
{
|
|
|
|
paranoid_printf ("strange path_conv problem");
|
|
|
|
res = failed;
|
|
|
|
}
|
2003-01-20 03:57:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
HANDLE fh = CreateFile (pc, GENERIC_READ, wincap.shared (), NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
|
|
|
|
if (fh == INVALID_HANDLE_VALUE)
|
2003-01-26 07:42:40 +01:00
|
|
|
{
|
|
|
|
paranoid_printf ("%s CreateFile failed, %E");
|
|
|
|
res = failed;
|
|
|
|
}
|
2003-01-17 06:18:30 +01:00
|
|
|
else
|
|
|
|
{
|
2003-01-20 03:57:54 +01:00
|
|
|
DWORD size = GetFileSize (fh, NULL), read_bytes;
|
|
|
|
buf = (char *) malloc (size + 1);
|
|
|
|
if (!ReadFile (fh, buf, size, &read_bytes, NULL))
|
|
|
|
{
|
2003-01-26 06:38:38 +01:00
|
|
|
paranoid_printf ("ReadFile failed, %E");
|
2003-01-20 03:57:54 +01:00
|
|
|
CloseHandle (fh);
|
|
|
|
if (buf)
|
|
|
|
free (buf);
|
|
|
|
buf = NULL;
|
2003-01-26 06:38:38 +01:00
|
|
|
res = failed;
|
2003-01-20 03:57:54 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CloseHandle (fh);
|
|
|
|
buf[read_bytes] = '\0';
|
|
|
|
char *eptr = buf;
|
2003-01-24 04:53:46 +01:00
|
|
|
while ((eptr = add_line (eptr)))
|
|
|
|
continue;
|
2003-01-20 03:57:54 +01:00
|
|
|
debug_printf ("%s curr_lines %d", posix_fname, curr_lines);
|
2003-01-26 06:38:38 +01:00
|
|
|
res = succeeded;
|
2003-01-20 03:57:54 +01:00
|
|
|
}
|
2003-01-17 06:18:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-26 07:42:40 +01:00
|
|
|
debug_printf ("%s load %s", posix_fname, res);
|
2003-01-21 07:58:11 +01:00
|
|
|
initialized = true;
|
2003-01-26 06:38:38 +01:00
|
|
|
return;
|
2003-01-17 06:18:30 +01:00
|
|
|
}
|