2000-02-18 03:38:33 +08:00
|
|
|
/* uinfo.cc: user info (uid, gid, etc...)
|
|
|
|
|
2004-02-09 12:04:24 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 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>
|
2000-11-16 17:53:26 +08:00
|
|
|
#include <sys/cygwin.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "dtable.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"
|
2002-06-29 10:36:08 +08: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 20:43:49 +08:00
|
|
|
#include "pwdgrp.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-09-11 05:01:40 +08:00
|
|
|
/* Initialize the part of cygheap_user that does not depend on files.
|
|
|
|
The information is used in shared.cc for the user shared.
|
|
|
|
Final initialization occurs in uinfo_init */
|
2002-06-15 02:01:21 +08:00
|
|
|
void
|
2003-11-29 04:55:59 +08:00
|
|
|
cygheap_user::init ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-09-11 05:01:40 +08:00
|
|
|
char user_name[UNLEN + 1];
|
|
|
|
DWORD user_name_len = UNLEN + 1;
|
|
|
|
|
|
|
|
set_name (GetUserName (user_name, &user_name_len) ? user_name : "unknown");
|
2000-11-15 08:13:09 +08:00
|
|
|
|
2003-09-27 09:56:36 +08:00
|
|
|
if (!wincap.has_security ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
DWORD siz;
|
2004-02-06 18:37:37 +08:00
|
|
|
PSECURITY_DESCRIPTOR psd;
|
2003-09-27 09:56:36 +08:00
|
|
|
|
2005-04-03 21:06:43 +08:00
|
|
|
if (!GetTokenInformation (hProcToken, TokenPrimaryGroup,
|
2003-09-27 09:56:36 +08:00
|
|
|
&groups.pgsid, sizeof (cygsid), &siz))
|
2004-09-03 09:53:12 +08:00
|
|
|
system_printf ("GetTokenInformation (TokenPrimaryGroup), %E");
|
2003-09-27 09:56:36 +08:00
|
|
|
|
|
|
|
/* Get the SID from current process and store it in effec_cygsid */
|
2005-04-03 21:06:43 +08:00
|
|
|
if (!GetTokenInformation (hProcToken, TokenUser, &effec_cygsid,
|
|
|
|
sizeof (cygsid), &siz))
|
2003-09-27 09:56:36 +08:00
|
|
|
{
|
2004-09-03 09:53:12 +08:00
|
|
|
system_printf ("GetTokenInformation (TokenUser), %E");
|
2005-04-03 21:06:43 +08:00
|
|
|
return;
|
2003-09-27 09:56:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set token owner to the same value as token user */
|
2005-04-03 21:06:43 +08:00
|
|
|
if (!SetTokenInformation (hProcToken, TokenOwner, &effec_cygsid,
|
|
|
|
sizeof (cygsid)))
|
2004-09-03 09:53:12 +08:00
|
|
|
debug_printf ("SetTokenInformation(TokenOwner), %E");
|
2003-09-27 09:56:36 +08:00
|
|
|
|
2004-02-06 18:37:37 +08:00
|
|
|
/* Standard way to build a security descriptor with the usual DACL */
|
2005-06-08 03:31:42 +08:00
|
|
|
PSECURITY_ATTRIBUTES sa_buf = (PSECURITY_ATTRIBUTES) alloca (1024);
|
2005-04-03 21:06:43 +08:00
|
|
|
psd = (PSECURITY_DESCRIPTOR)
|
|
|
|
(sec_user_nih (sa_buf, sid()))->lpSecurityDescriptor;
|
2003-09-27 09:56:36 +08:00
|
|
|
|
2004-02-06 18:37:37 +08:00
|
|
|
BOOL acl_exists, dummy;
|
|
|
|
TOKEN_DEFAULT_DACL dacl;
|
2005-04-03 21:06:43 +08:00
|
|
|
if (GetSecurityDescriptorDacl (psd, &acl_exists, &dacl.DefaultDacl, &dummy)
|
2004-02-06 18:37:37 +08:00
|
|
|
&& acl_exists && dacl.DefaultDacl)
|
|
|
|
{
|
|
|
|
/* Set the default DACL and the process DACL */
|
2005-04-03 21:06:43 +08:00
|
|
|
if (!SetTokenInformation (hProcToken, TokenDefaultDacl, &dacl,
|
|
|
|
sizeof (dacl)))
|
2004-09-03 09:53:12 +08:00
|
|
|
system_printf ("SetTokenInformation (TokenDefaultDacl), %E");
|
2004-02-06 18:37:37 +08:00
|
|
|
if (!SetKernelObjectSecurity (hMainProc, DACL_SECURITY_INFORMATION, psd))
|
2004-09-03 09:53:12 +08:00
|
|
|
system_printf ("SetKernelObjectSecurity, %E");
|
2003-09-11 05:01:40 +08:00
|
|
|
}
|
2004-02-06 18:37:37 +08:00
|
|
|
else
|
2004-09-03 09:53:12 +08:00
|
|
|
system_printf("Cannot get dacl, %E");
|
2003-09-11 05:01:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
internal_getlogin (cygheap_user &user)
|
|
|
|
{
|
|
|
|
struct passwd *pw = NULL;
|
|
|
|
|
|
|
|
if (wincap.has_security ())
|
|
|
|
{
|
|
|
|
cygpsid psid = user.sid ();
|
|
|
|
pw = internal_getpwsid (psid);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-02-10 19:15:56 +08: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 20:43:49 +08:00
|
|
|
if (!pw && !(pw = internal_getpwnam (user.name ()))
|
|
|
|
&& !(pw = internal_getpwuid (DEFAULT_UID)))
|
2003-11-29 04:55:59 +08:00
|
|
|
debug_printf ("user not found in augmented /etc/passwd");
|
2002-11-21 01:10:05 +08:00
|
|
|
else
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2002-06-24 23:40:57 +08:00
|
|
|
myself->uid = pw->pw_uid;
|
|
|
|
myself->gid = pw->pw_gid;
|
2002-11-25 23:11:39 +08:00
|
|
|
user.set_name (pw->pw_name);
|
2002-11-21 01:10:05 +08:00
|
|
|
if (wincap.has_security ())
|
2002-11-27 10:26:44 +08:00
|
|
|
{
|
2002-11-21 01:10:05 +08: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 20:43:49 +08:00
|
|
|
if (gsid.getfromgr (internal_getgrgid (pw->pw_gid)))
|
2002-11-21 01:10:05 +08:00
|
|
|
{
|
2005-04-03 21:06:43 +08:00
|
|
|
if (gsid != user.groups.pgsid)
|
2004-05-29 03:50:07 +08:00
|
|
|
{
|
2003-09-11 05:01:40 +08:00
|
|
|
/* Set primary group to the group in /etc/passwd. */
|
2005-04-03 21:06:43 +08:00
|
|
|
if (!SetTokenInformation (hProcToken, TokenPrimaryGroup,
|
|
|
|
&gsid, sizeof gsid))
|
|
|
|
debug_printf ("SetTokenInformation(TokenPrimaryGroup), %E");
|
|
|
|
if (!SetTokenInformation (hProcImpToken, TokenPrimaryGroup,
|
2003-09-11 05:01:40 +08:00
|
|
|
&gsid, sizeof gsid))
|
2004-09-03 09:53:12 +08:00
|
|
|
debug_printf ("SetTokenInformation(TokenPrimaryGroup), %E");
|
2003-09-11 05:01:40 +08:00
|
|
|
else
|
|
|
|
user.groups.pgsid = gsid;
|
|
|
|
}
|
2002-11-21 01:10:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
debug_printf ("gsid not found in augmented /etc/group");
|
|
|
|
}
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
2005-07-07 04:05:03 +08:00
|
|
|
cygheap->user.ontherange (CH_HOME, pw);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
uinfo_init ()
|
|
|
|
{
|
2003-06-30 21:07:36 +08:00
|
|
|
if (child_proc_info && !cygheap->user.has_impersonation_tokens ())
|
2003-06-09 21:29:12 +08: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 ()
|
2004-05-29 03:50:07 +08:00
|
|
|
&& cygheap->user.saved_uid == cygheap->user.real_uid
|
2003-09-16 17:24:52 +08:00
|
|
|
&& cygheap->user.saved_gid == cygheap->user.real_gid
|
2003-06-09 21:29:12 +08:00
|
|
|
&& !cygheap->user.groups.issetgroups ())
|
2003-01-25 18:36:46 +08:00
|
|
|
{
|
2003-06-30 21:07:36 +08:00
|
|
|
cygheap->user.reimpersonate ();
|
2003-06-09 21:29:12 +08:00
|
|
|
return;
|
2003-01-25 18:36:46 +08:00
|
|
|
}
|
2003-06-09 21:29:12 +08:00
|
|
|
else
|
2003-06-30 21:07:36 +08:00
|
|
|
cygheap->user.close_impersonation_tokens ();
|
2003-06-09 21:29:12 +08:00
|
|
|
|
2003-09-16 17:24:52 +08:00
|
|
|
cygheap->user.saved_uid = cygheap->user.real_uid = myself->uid;
|
|
|
|
cygheap->user.saved_gid = cygheap->user.real_gid = myself->gid;
|
2004-10-28 09:46:01 +08:00
|
|
|
cygheap->user.external_token = NO_IMPERSONATION;
|
|
|
|
cygheap->user.internal_token = NO_IMPERSONATION;
|
2005-04-03 21:06:43 +08:00
|
|
|
cygheap->user.curr_primary_token = NO_IMPERSONATION;
|
2004-10-28 09:46:01 +08:00
|
|
|
cygheap->user.current_token = NO_IMPERSONATION;
|
2003-09-16 17:24:52 +08:00
|
|
|
cygheap->user.set_saved_sid (); /* Update the original sid */
|
2005-06-22 04:09:31 +08:00
|
|
|
cygheap->user.reimpersonate ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2004-05-18 00:06:02 +08:00
|
|
|
extern "C" int
|
|
|
|
getlogin_r (char *name, size_t namesize)
|
|
|
|
{
|
|
|
|
char *login = getlogin ();
|
|
|
|
size_t len = strlen (login) + 1;
|
|
|
|
if (len > namesize)
|
|
|
|
return ERANGE;
|
2005-07-03 10:40:30 +08:00
|
|
|
myfault efault;
|
|
|
|
if (efault.faulted ())
|
|
|
|
return EFAULT;
|
2004-05-18 00:06:02 +08:00
|
|
|
strncpy (name, login, len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
extern "C" char *
|
|
|
|
getlogin (void)
|
|
|
|
{
|
2003-12-24 00:26:31 +08:00
|
|
|
return strcpy (_my_tls.locals.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::ontherange (homebodies what, struct passwd *pw)
|
|
|
|
{
|
|
|
|
LPUSER_INFO_3 ui = NULL;
|
|
|
|
WCHAR wuser[UNLEN + 1];
|
|
|
|
NET_API_STATUS ret;
|
2005-04-03 16:45:21 +08:00
|
|
|
char homepath_env_buf[CYG_MAX_PATH];
|
2002-06-28 04:44:27 +08:00
|
|
|
char homedrive_env_buf[3];
|
|
|
|
char *newhomedrive = NULL;
|
|
|
|
char *newhomepath = NULL;
|
|
|
|
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-06-29 10:36:08 +08:00
|
|
|
debug_printf ("what %d, pw %p", what, pw);
|
2002-06-12 13:13:54 +08:00
|
|
|
if (what == CH_HOME)
|
|
|
|
{
|
|
|
|
char *p;
|
2002-07-01 11:57:17 +08:00
|
|
|
if (homedrive)
|
|
|
|
newhomedrive = homedrive;
|
|
|
|
else if ((p = getenv ("HOMEDRIVE")))
|
2002-06-28 04:44:27 +08:00
|
|
|
newhomedrive = p;
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2002-07-01 11:57:17 +08:00
|
|
|
if (homepath)
|
|
|
|
newhomepath = homepath;
|
|
|
|
else if ((p = getenv ("HOMEPATH")))
|
2002-06-28 04:44:27 +08:00
|
|
|
newhomepath = p;
|
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->pw_dir && *pw->pw_dir)
|
|
|
|
{
|
|
|
|
debug_printf ("Set HOME (from /etc/passwd) to %s", pw->pw_dir);
|
2002-07-01 11:57:17 +08:00
|
|
|
setenv ("HOME", pw->pw_dir, 1);
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2002-07-01 11:57:17 +08:00
|
|
|
else if (!newhomedrive || !newhomepath)
|
|
|
|
setenv ("HOME", "/", 1);
|
|
|
|
else
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2003-11-15 07:40:06 +08:00
|
|
|
char home[CYG_MAX_PATH];
|
2005-04-03 16:45:21 +08:00
|
|
|
char buf[CYG_MAX_PATH];
|
2002-06-28 04:44:27 +08:00
|
|
|
strcpy (buf, newhomedrive);
|
|
|
|
strcat (buf, newhomepath);
|
2002-06-12 13:13:54 +08:00
|
|
|
cygwin_conv_to_full_posix_path (buf, home);
|
|
|
|
debug_printf ("Set HOME (from HOMEDRIVE/HOMEPATH) to %s", home);
|
2002-07-01 11:57:17 +08:00
|
|
|
setenv ("HOME", home, 1);
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-29 10:36:08 +08:00
|
|
|
if (what != CH_HOME && homepath == NULL && newhomepath == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-06-12 13:13:54 +08: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 20:43:49 +08:00
|
|
|
pw = internal_getpwnam (name ());
|
2002-06-12 13:13:54 +08:00
|
|
|
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-28 04:44:27 +08:00
|
|
|
homepath_env_buf[0] = homepath_env_buf[1] = '\0';
|
2002-06-29 10:36:08 +08:00
|
|
|
if (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];
|
2002-06-29 10:36:08 +08:00
|
|
|
sys_mbstowcs (wlogsrv, logsrv (),
|
2002-09-22 11:38:57 +08:00
|
|
|
sizeof (wlogsrv) / sizeof (*wlogsrv));
|
2002-06-29 10:36:08 +08:00
|
|
|
sys_mbstowcs (wuser, winname (), sizeof (wuser) / sizeof (*wuser));
|
2003-11-29 04:55:59 +08:00
|
|
|
if (!(ret = NetUserGetInfo (wlogsrv, wuser, 3, (LPBYTE *) &ui)))
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2006-02-07 23:49:08 +08:00
|
|
|
sys_wcstombs (homepath_env_buf, CYG_MAX_PATH,
|
|
|
|
ui->usri3_home_dir);
|
2002-06-19 21:56:34 +08:00
|
|
|
if (!homepath_env_buf[0])
|
|
|
|
{
|
2006-02-07 23:49:08 +08:00
|
|
|
sys_wcstombs (homepath_env_buf, CYG_MAX_PATH,
|
|
|
|
ui->usri3_home_dir_drive);
|
2002-06-19 21:56:34 +08:00
|
|
|
if (homepath_env_buf[0])
|
|
|
|
strcat (homepath_env_buf, "\\");
|
2002-07-01 23:50:02 +08:00
|
|
|
else
|
2002-07-02 00:37:46 +08:00
|
|
|
cygwin_conv_to_full_win32_path ("/", homepath_env_buf);
|
2002-06-19 21:56:34 +08:00
|
|
|
}
|
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-28 04:44:27 +08:00
|
|
|
newhomedrive = almost_null;
|
|
|
|
newhomepath = 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];
|
2002-06-28 04:44:27 +08:00
|
|
|
homedrive_env_buf[2] = '\0';
|
|
|
|
newhomedrive = homedrive_env_buf;
|
|
|
|
newhomepath = homepath_env_buf + 2;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-07-01 11:57:17 +08:00
|
|
|
if (newhomedrive && newhomedrive != homedrive)
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (homedrive, (newhomedrive == almost_null)
|
2002-09-19 11:30:20 +08:00
|
|
|
? almost_null : cstrdup (newhomedrive));
|
2002-06-28 04:44:27 +08:00
|
|
|
|
2002-07-01 11:57:17 +08:00
|
|
|
if (newhomepath && newhomepath != homepath)
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (homepath, cstrdup (newhomepath));
|
|
|
|
|
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 *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::test_uid (char *&what, const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-07-01 11:57:17 +08:00
|
|
|
if (!what && !issetuid ())
|
2002-06-29 14:50:17 +08:00
|
|
|
what = getwinenveq (name, namelen, HEAP_STR);
|
2002-06-29 10:36:08 +08:00
|
|
|
return what;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
cygheap_user::env_logsrv (const char *name, size_t namelen)
|
|
|
|
{
|
|
|
|
if (test_uid (plogsrv, name, namelen))
|
2002-06-15 02:01:21 +08:00
|
|
|
return plogsrv;
|
2002-06-12 13:13:54 +08:00
|
|
|
|
2002-06-30 06:05:30 +08:00
|
|
|
const char *mydomain = domain ();
|
|
|
|
const char *myname = winname ();
|
|
|
|
if (!mydomain || strcasematch (myname, "SYSTEM"))
|
2002-06-29 11:14:12 +08:00
|
|
|
return almost_null;
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2002-06-15 02:01:21 +08:00
|
|
|
char logsrv[INTERNET_MAX_HOST_NAME_LENGTH + 3];
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (plogsrv, almost_null);
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
if (get_logon_server (mydomain, logsrv, NULL, false))
|
2002-06-28 04:44:27 +08:00
|
|
|
plogsrv = cstrdup (logsrv);
|
|
|
|
return plogsrv;
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_domain (const char *name, size_t namelen)
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2002-06-29 14:50:17 +08:00
|
|
|
if (pwinname && test_uid (pdomain, name, namelen))
|
2002-06-15 02:01:21 +08: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 10:36:08 +08:00
|
|
|
cfree_and_set (pwinname, almost_null);
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (pdomain, almost_null);
|
2002-06-15 02:01:21 +08:00
|
|
|
if (!LookupAccountSid (NULL, sid (), username, &ulen,
|
|
|
|
userdomain, &dlen, &use))
|
2002-06-28 04:44:27 +08:00
|
|
|
__seterrno ();
|
|
|
|
else
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2002-06-29 10:36:08 +08:00
|
|
|
pwinname = cstrdup (username);
|
2002-06-28 04:44:27 +08:00
|
|
|
pdomain = cstrdup (userdomain);
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
2002-06-28 04:44:27 +08:00
|
|
|
return pdomain;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_userprofile (const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
2002-06-29 10:36:08 +08:00
|
|
|
if (test_uid (puserprof, name, namelen))
|
|
|
|
return puserprof;
|
|
|
|
|
2005-04-03 16:45:21 +08:00
|
|
|
char userprofile_env_buf[CYG_MAX_PATH];
|
2004-11-21 03:09:19 +08:00
|
|
|
char win_id[UNLEN + 1]; /* Large enough for SID */
|
|
|
|
|
2002-06-28 04:44:27 +08:00
|
|
|
cfree_and_set (puserprof, almost_null);
|
2004-11-21 03:09:19 +08:00
|
|
|
if (get_registry_hive_path (get_windows_id (win_id), userprofile_env_buf))
|
2002-06-28 04:44:27 +08:00
|
|
|
puserprof = cstrdup (userprofile_env_buf);
|
2002-06-16 13:26:14 +08:00
|
|
|
|
2002-06-28 04:44:27 +08:00
|
|
|
return puserprof;
|
2002-06-12 13:13:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_homepath (const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEPATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_homedrive (const char *name, size_t namelen)
|
2002-06-12 13:13:54 +08:00
|
|
|
{
|
|
|
|
return ontherange (CH_HOMEDRIVE);
|
|
|
|
}
|
2002-06-15 02:01:21 +08:00
|
|
|
|
|
|
|
const char *
|
2002-06-29 10:36:08 +08:00
|
|
|
cygheap_user::env_name (const char *name, size_t namelen)
|
2002-06-15 02:01:21 +08:00
|
|
|
{
|
2002-06-29 10:36:08 +08:00
|
|
|
if (!test_uid (pwinname, name, namelen))
|
2005-07-07 04:05:03 +08:00
|
|
|
domain ();
|
2002-06-29 10:36:08 +08:00
|
|
|
return pwinname;
|
2002-06-15 02:01:21 +08:00
|
|
|
}
|
2003-01-17 13:18:30 +08:00
|
|
|
|
2004-10-08 05:28:57 +08:00
|
|
|
const char *
|
|
|
|
cygheap_user::env_systemroot (const char *name, size_t namelen)
|
|
|
|
{
|
|
|
|
if (!psystemroot)
|
|
|
|
{
|
|
|
|
int size = GetWindowsDirectory (NULL, 0);
|
|
|
|
if (size > 0)
|
2005-05-02 11:50:11 +08:00
|
|
|
{
|
2004-10-08 05:28:57 +08:00
|
|
|
psystemroot = (char *) cmalloc (HEAP_STR, ++size);
|
|
|
|
size = GetWindowsDirectory (psystemroot, size);
|
|
|
|
if (size <= 0)
|
|
|
|
{
|
|
|
|
cfree (psystemroot);
|
|
|
|
psystemroot = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (size <= 0)
|
2005-05-02 11:50:11 +08:00
|
|
|
debug_printf ("GetWindowsDirectory(), %E");
|
2004-10-08 05:28:57 +08:00
|
|
|
}
|
|
|
|
return psystemroot;
|
|
|
|
}
|
|
|
|
|
2003-01-20 10:57:54 +08:00
|
|
|
char *
|
2003-01-24 11:53:46 +08:00
|
|
|
pwdgrp::next_str (char c)
|
2003-01-17 13:18:30 +08:00
|
|
|
{
|
2003-01-24 11:53:46 +08:00
|
|
|
char *res = lptr;
|
2003-01-27 08:16:01 +08:00
|
|
|
lptr = strechr (lptr, c);
|
|
|
|
if (*lptr)
|
|
|
|
*lptr++ = '\0';
|
2003-01-24 11:53:46 +08:00
|
|
|
return res;
|
2003-01-20 10:57:54 +08:00
|
|
|
}
|
2003-01-17 13:18:30 +08:00
|
|
|
|
2003-01-26 13:38:38 +08:00
|
|
|
bool
|
|
|
|
pwdgrp::next_num (unsigned long& n)
|
2003-01-24 11:53:46 +08:00
|
|
|
{
|
2003-01-27 08:16:01 +08:00
|
|
|
char *p = next_str (':');
|
2003-01-24 11:53:46 +08:00
|
|
|
char *cp;
|
2003-01-26 13:38:38 +08:00
|
|
|
n = strtoul (p, &cp, 10);
|
|
|
|
return p != cp && !*cp;
|
2003-01-24 11:53:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
pwdgrp::add_line (char *eptr)
|
2003-01-20 10:57:54 +08:00
|
|
|
{
|
2003-01-24 11:53:46 +08:00
|
|
|
if (eptr)
|
2003-01-20 10:57:54 +08:00
|
|
|
{
|
2003-01-24 11:53:46 +08:00
|
|
|
lptr = eptr;
|
2003-01-27 08:31:30 +08:00
|
|
|
eptr = strchr (lptr, '\n');
|
|
|
|
if (eptr)
|
2003-01-24 11:53:46 +08:00
|
|
|
{
|
|
|
|
if (eptr > lptr && eptr[-1] == '\r')
|
2003-01-27 08:16:01 +08:00
|
|
|
eptr[-1] = '\0';
|
|
|
|
else
|
|
|
|
*eptr = '\0';
|
2003-01-24 11:53:46 +08:00
|
|
|
eptr++;
|
|
|
|
}
|
|
|
|
if (curr_lines >= max_lines)
|
|
|
|
{
|
|
|
|
max_lines += 10;
|
|
|
|
*pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
|
|
|
|
}
|
2003-01-26 13:38:38 +08:00
|
|
|
if ((this->*parse) ())
|
|
|
|
curr_lines++;
|
2003-01-20 10:57:54 +08:00
|
|
|
}
|
2003-01-24 11:53:46 +08:00
|
|
|
return eptr;
|
2003-01-17 13:18:30 +08:00
|
|
|
}
|
|
|
|
|
2003-01-26 13:38:38 +08:00
|
|
|
void
|
2003-01-20 10:57:54 +08:00
|
|
|
pwdgrp::load (const char *posix_fname)
|
2003-01-17 13:18:30 +08:00
|
|
|
{
|
2003-01-26 13:38:38 +08:00
|
|
|
const char *res;
|
|
|
|
static const char failed[] = "failed";
|
|
|
|
static const char succeeded[] = "succeeded";
|
|
|
|
|
2003-01-20 10:57:54 +08:00
|
|
|
if (buf)
|
|
|
|
free (buf);
|
|
|
|
buf = NULL;
|
2003-08-18 01:50:40 +08:00
|
|
|
curr_lines = 0;
|
2003-01-20 10:57:54 +08:00
|
|
|
|
|
|
|
pc.check (posix_fname);
|
2003-01-21 14:58:11 +08:00
|
|
|
etc_ix = etc::init (etc_ix, pc);
|
2003-01-20 10:57:54 +08:00
|
|
|
|
|
|
|
paranoid_printf ("%s", posix_fname);
|
2003-01-17 13:18:30 +08:00
|
|
|
|
2004-10-02 10:20:21 +08:00
|
|
|
if (pc.error || !pc.exists () || pc.isdir ())
|
2003-01-26 13:38:38 +08:00
|
|
|
{
|
|
|
|
paranoid_printf ("strange path_conv problem");
|
|
|
|
res = failed;
|
|
|
|
}
|
2003-01-20 10:57:54 +08: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 14:42:40 +08:00
|
|
|
{
|
|
|
|
paranoid_printf ("%s CreateFile failed, %E");
|
|
|
|
res = failed;
|
|
|
|
}
|
2003-01-17 13:18:30 +08:00
|
|
|
else
|
|
|
|
{
|
2003-01-20 10:57:54 +08:00
|
|
|
DWORD size = GetFileSize (fh, NULL), read_bytes;
|
|
|
|
buf = (char *) malloc (size + 1);
|
|
|
|
if (!ReadFile (fh, buf, size, &read_bytes, NULL))
|
|
|
|
{
|
2003-01-26 13:38:38 +08:00
|
|
|
paranoid_printf ("ReadFile failed, %E");
|
2003-01-20 10:57:54 +08:00
|
|
|
CloseHandle (fh);
|
|
|
|
if (buf)
|
|
|
|
free (buf);
|
|
|
|
buf = NULL;
|
2003-01-26 13:38:38 +08:00
|
|
|
res = failed;
|
2003-01-20 10:57:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CloseHandle (fh);
|
|
|
|
buf[read_bytes] = '\0';
|
|
|
|
char *eptr = buf;
|
2003-01-24 11:53:46 +08:00
|
|
|
while ((eptr = add_line (eptr)))
|
|
|
|
continue;
|
2003-01-20 10:57:54 +08:00
|
|
|
debug_printf ("%s curr_lines %d", posix_fname, curr_lines);
|
2003-01-26 13:38:38 +08:00
|
|
|
res = succeeded;
|
2003-01-20 10:57:54 +08:00
|
|
|
}
|
2003-01-17 13:18:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-26 14:42:40 +08:00
|
|
|
debug_printf ("%s load %s", posix_fname, res);
|
2003-01-21 14:58:11 +08:00
|
|
|
initialized = true;
|
2003-01-17 13:18:30 +08:00
|
|
|
}
|