2001-04-20 15:02:32 +02:00
|
|
|
/* sec_helper.cc: NT security helper functions
|
|
|
|
|
2006-10-22 21:31:33 +02:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2006 Red Hat, Inc.
|
2001-04-20 15:02:32 +02:00
|
|
|
|
|
|
|
Written by Corinna Vinschen <corinna@vinschen.de>
|
|
|
|
|
|
|
|
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"
|
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/acl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2001-04-30 20:21:48 +02:00
|
|
|
#include <wininet.h>
|
2001-04-20 15:02:32 +02:00
|
|
|
#include "cygerrno.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2001-04-20 15:02:32 +02: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 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2001-04-20 15:02:32 +02:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "pinfo.h"
|
|
|
|
#include "cygheap.h"
|
2005-04-03 15:06:43 +02:00
|
|
|
#include "cygtls.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"
|
2001-04-20 15:02:32 +02:00
|
|
|
|
2002-07-01 16:31:28 +02:00
|
|
|
/* General purpose security attribute objects for global use. */
|
|
|
|
SECURITY_ATTRIBUTES NO_COPY sec_none;
|
|
|
|
SECURITY_ATTRIBUTES NO_COPY sec_none_nih;
|
|
|
|
SECURITY_ATTRIBUTES NO_COPY sec_all;
|
|
|
|
SECURITY_ATTRIBUTES NO_COPY sec_all_nih;
|
|
|
|
|
2006-11-23 17:44:55 +01:00
|
|
|
MKSID (well_known_null_sid, "S-1-0-0",
|
|
|
|
SECURITY_NULL_SID_AUTHORITY, 1, SECURITY_NULL_RID);
|
|
|
|
MKSID (well_known_world_sid, "S-1-1-0",
|
|
|
|
SECURITY_WORLD_SID_AUTHORITY, 1, SECURITY_WORLD_RID);
|
|
|
|
MKSID (well_known_local_sid, "S-1-2-0",
|
|
|
|
SECURITY_LOCAL_SID_AUTHORITY, 1, SECURITY_LOCAL_RID);
|
|
|
|
MKSID (well_known_creator_owner_sid, "S-1-3-0",
|
|
|
|
SECURITY_CREATOR_SID_AUTHORITY, 1, SECURITY_CREATOR_OWNER_RID);
|
|
|
|
MKSID (well_known_creator_group_sid, "S-1-3-1",
|
|
|
|
SECURITY_CREATOR_SID_AUTHORITY, 1, SECURITY_CREATOR_GROUP_RID);
|
|
|
|
MKSID (well_known_dialup_sid, "S-1-5-1",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, SECURITY_DIALUP_RID);
|
|
|
|
MKSID (well_known_network_sid, "S-1-5-2",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, SECURITY_NETWORK_RID);
|
|
|
|
MKSID (well_known_batch_sid, "S-1-5-3",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, SECURITY_BATCH_RID);
|
|
|
|
MKSID (well_known_interactive_sid, "S-1-5-4",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, SECURITY_INTERACTIVE_RID);
|
|
|
|
MKSID (well_known_service_sid, "S-1-5-6",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, SECURITY_SERVICE_RID);
|
|
|
|
MKSID (well_known_authenticated_users_sid, "S-1-5-11",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, SECURITY_AUTHENTICATED_USER_RID);
|
|
|
|
MKSID (well_known_this_org_sid, "S-1-5-15",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, 15);
|
|
|
|
MKSID (well_known_system_sid, "S-1-5-18",
|
|
|
|
SECURITY_NT_AUTHORITY, 1, SECURITY_LOCAL_SYSTEM_RID);
|
|
|
|
MKSID (well_known_admins_sid, "S-1-5-32-544",
|
|
|
|
SECURITY_NT_AUTHORITY, 2, SECURITY_BUILTIN_DOMAIN_RID,
|
|
|
|
DOMAIN_ALIAS_RID_ADMINS);
|
2006-11-27 13:59:59 +01:00
|
|
|
MKSID (fake_logon_sid, "S-1-5-5-0-0",
|
|
|
|
SECURITY_NT_AUTHORITY, 3, SECURITY_LOGON_IDS_RID, 0, 0);
|
2006-11-08 12:38:05 +01:00
|
|
|
|
2003-02-04 15:58:04 +01:00
|
|
|
bool
|
|
|
|
cygpsid::operator== (const char *nsidstr) const
|
|
|
|
{
|
|
|
|
cygsid nsid (nsidstr);
|
|
|
|
return psid == nsid;
|
|
|
|
}
|
|
|
|
|
|
|
|
__uid32_t
|
|
|
|
cygpsid::get_id (BOOL search_grp, int *type)
|
|
|
|
{
|
|
|
|
/* First try to get SID from group, then passwd */
|
|
|
|
__uid32_t id = ILLEGAL_UID;
|
|
|
|
|
|
|
|
if (search_grp)
|
|
|
|
{
|
|
|
|
struct __group32 *gr;
|
|
|
|
if (cygheap->user.groups.pgsid == psid)
|
|
|
|
id = myself->gid;
|
|
|
|
else if ((gr = internal_getgrsid (*this)))
|
|
|
|
id = gr->gr_gid;
|
|
|
|
if (id != ILLEGAL_UID)
|
2003-03-09 21:31:07 +01:00
|
|
|
{
|
2003-02-04 15:58:04 +01:00
|
|
|
if (type)
|
|
|
|
*type = GROUP;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!search_grp || type)
|
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
if (*this == cygheap->user.sid ())
|
|
|
|
id = myself->uid;
|
|
|
|
else if ((pw = internal_getpwsid (*this)))
|
|
|
|
id = pw->pw_uid;
|
|
|
|
if (id != ILLEGAL_UID && type)
|
2003-03-09 21:31:07 +01:00
|
|
|
*type = USER;
|
2003-02-04 15:58:04 +01:00
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
cygpsid::string (char *nsidstr) const
|
|
|
|
{
|
|
|
|
char *t;
|
|
|
|
DWORD i;
|
|
|
|
|
|
|
|
if (!psid || !nsidstr)
|
|
|
|
return NULL;
|
|
|
|
strcpy (nsidstr, "S-1-");
|
|
|
|
t = nsidstr + sizeof ("S-1-") - 1;
|
|
|
|
t += __small_sprintf (t, "%u", GetSidIdentifierAuthority (psid)->Value[5]);
|
|
|
|
for (i = 0; i < *GetSidSubAuthorityCount (psid); ++i)
|
|
|
|
t += __small_sprintf (t, "-%lu", *GetSidSubAuthority (psid, i));
|
|
|
|
return nsidstr;
|
|
|
|
}
|
|
|
|
|
2001-04-20 15:02:32 +02:00
|
|
|
PSID
|
2006-11-27 13:59:59 +01:00
|
|
|
cygsid::get_sid (DWORD s, DWORD cnt, DWORD *r, bool well_known)
|
2001-04-20 15:02:32 +02:00
|
|
|
{
|
|
|
|
DWORD i;
|
2006-11-08 12:38:05 +01:00
|
|
|
SID_IDENTIFIER_AUTHORITY sid_auth = {0,0,0,0,0,0};
|
2001-04-20 15:02:32 +02:00
|
|
|
|
2006-11-08 12:38:05 +01:00
|
|
|
if (s > 255 || cnt < 1 || cnt > 8)
|
* autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
`LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
`NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
`NtCreateToken'.
* ntdll.h: Add declaration for `NtCreateToken'.
* sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
`well_known_network_sid', `well_known_batch_sid',
`well_known_interactive_sid', `well_known_service_sid' and
`well_known_authenticated_users_sid'.
(cygsid::string): Define as const method.
(cygsid::get_sid): Set psid to NO_SID on error.
(cygsid::getfromstr): Ditto.
(cygsid::getfrompw): Simplify.
(cygsid::getfromgr): Check for gr == NULL.
(legal_sid_type): Move to security.h.
(set_process_privilege): Return -1 on error, otherwise 0 or 1 related
to previous privilege setting.
* security.cc (extract_nt_dom_user): Remove `static'.
(lsa2wchar): New function.
(open_local_policy): Ditto.
(close_local_policy): Ditto.
(get_lsa_srv_inf): Ditto.
(get_logon_server): Ditto.
(get_logon_server_and_user_domain): Ditto.
(get_user_groups): Ditto.
(is_group_member): Ditto.
(get_user_local_groups): Ditto.
(sid_in_token_groups): Ditto.
(get_user_primary_group): Ditto.
(get_group_sidlist): Ditto.
(get_system_priv_list): Ditto.
(get_priv_list): Ditto.
(get_dacl): Ditto.
(create_token): Ditto.
(subauth): Return immediately if SE_TCB_NAME can't be assigned.
Change all return statements in case of error to jumps to `out'
label. Add `out' label to support cleanup.
* security.h: Add extern declarations for `well_known_local_sid',
`well_known_dialup_sid', `well_known_network_sid',
`well_known_batch_sid', `well_known_interactive_sid',
`well_known_service_sid' and `well_known_authenticated_users_sid'.
Add extern declarations for functions `create_token',
`extract_nt_dom_user' and `get_logon_server_and_user_domain'.
(class cygsid): Add method `assign'. Change operator= to call new
`assign' method. Add `debug_print' method.
(class cygsidlist): New class.
(legal_sid_type): Moved from sec_helper.cc to here.
* spawn.cc (spawn_guts) Revert reversion of previous patch.
Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
again.
* syscalls.cc (seteuid): Rearranged. Call `create_token' now when
needed. Call `subauth' if `create_token' fails. Try setting token
owner and primary group only if token was not explicitely created
by `create_token'.
* uinfo.cc (internal_getlogin): Try harder to generate correct user
information. Especially don't trust return value of `GetUserName'.
2001-05-20 10:10:47 +02:00
|
|
|
{
|
|
|
|
psid = NO_SID;
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-08 12:38:05 +01:00
|
|
|
sid_auth.Value[5] = s;
|
* fork.cc (fork): Eliminate superfluous call to getuid().
* security.h: New define `NO_SID'. Remove declarations of functions
moved to methods into class cygsid.
(class cygsid): Declare new methods `getfromstr', `get_sid',
`getfrompw', `getfromgr', `get_rid', `get_uid', `get_gid', `string'
and new constructors and operators =, == and !=.
Declare new global cygsids `well_known_XXX_sid' substituting the
corresponding `get_XXX_sid' functions. Remove declarations of
these functions.
* sec_helper.cc (well_known_admin_sid): New global variable.
(well_known_system_sid): Ditto
(well_known_creator_owner_sid): Ditto
(well_known_world_sid): Ditto
(cygsid::string): New method, substituting `convert_sid_to_string_sid'.
(cygsid::get_sid): New method, substituting `get_sid'.
(cygsid::getfromstr): New method, substituting
`convert_string_sid_to_sid'.
(cygsid::getfrompw): New method, substituting `get_pw_sid'.
(cygsid::getfromgr): New method, substituting `get_gr_sid'.
(cygsid::get_id): New method, substituting `get_id_from_sid'.
(get_admin_sid): Eliminated.
(get_system_sid): Ditto.
(get_creator_owner_sid): Ditto.
(get_world_sid): Ditto.
* grp.cc: Use new cygsid methods and well known sids throughout.
* registry.cc: Ditto.
* sec_acl.cc: Ditto.
* security.cc: Ditto.
* shared.cc: Ditto.
* syscalls.cc (seteuid): Ditto. Eliminate redundant conditional.
* uinfo.cc (internal_getlogin): Ditto.
* spawn.cc (spawn_guts) Revert previous patch.
2001-05-15 21:23:31 +02:00
|
|
|
set ();
|
2006-11-08 12:38:05 +01:00
|
|
|
InitializeSid (psid, &sid_auth, cnt);
|
2001-04-20 15:02:32 +02:00
|
|
|
for (i = 0; i < cnt; ++i)
|
|
|
|
memcpy ((char *) psid + 8 + sizeof (DWORD) * i, &r[i], sizeof (DWORD));
|
2006-11-27 13:59:59 +01:00
|
|
|
well_known_sid = well_known;
|
2001-04-20 15:02:32 +02:00
|
|
|
return psid;
|
|
|
|
}
|
|
|
|
|
* fork.cc (fork): Eliminate superfluous call to getuid().
* security.h: New define `NO_SID'. Remove declarations of functions
moved to methods into class cygsid.
(class cygsid): Declare new methods `getfromstr', `get_sid',
`getfrompw', `getfromgr', `get_rid', `get_uid', `get_gid', `string'
and new constructors and operators =, == and !=.
Declare new global cygsids `well_known_XXX_sid' substituting the
corresponding `get_XXX_sid' functions. Remove declarations of
these functions.
* sec_helper.cc (well_known_admin_sid): New global variable.
(well_known_system_sid): Ditto
(well_known_creator_owner_sid): Ditto
(well_known_world_sid): Ditto
(cygsid::string): New method, substituting `convert_sid_to_string_sid'.
(cygsid::get_sid): New method, substituting `get_sid'.
(cygsid::getfromstr): New method, substituting
`convert_string_sid_to_sid'.
(cygsid::getfrompw): New method, substituting `get_pw_sid'.
(cygsid::getfromgr): New method, substituting `get_gr_sid'.
(cygsid::get_id): New method, substituting `get_id_from_sid'.
(get_admin_sid): Eliminated.
(get_system_sid): Ditto.
(get_creator_owner_sid): Ditto.
(get_world_sid): Ditto.
* grp.cc: Use new cygsid methods and well known sids throughout.
* registry.cc: Ditto.
* sec_acl.cc: Ditto.
* security.cc: Ditto.
* shared.cc: Ditto.
* syscalls.cc (seteuid): Ditto. Eliminate redundant conditional.
* uinfo.cc (internal_getlogin): Ditto.
* spawn.cc (spawn_guts) Revert previous patch.
2001-05-15 21:23:31 +02:00
|
|
|
const PSID
|
2006-11-27 13:59:59 +01:00
|
|
|
cygsid::getfromstr (const char *nsidstr, bool well_known)
|
2001-04-20 15:02:32 +02:00
|
|
|
{
|
2002-11-12 16:51:11 +01:00
|
|
|
char *lasts;
|
|
|
|
DWORD s, cnt = 0;
|
|
|
|
DWORD r[8];
|
2001-04-20 15:02:32 +02:00
|
|
|
|
2002-11-12 16:51:11 +01:00
|
|
|
if (nsidstr && !strncmp (nsidstr, "S-1-", 4))
|
* autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
`LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
`NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
`NtCreateToken'.
* ntdll.h: Add declaration for `NtCreateToken'.
* sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
`well_known_network_sid', `well_known_batch_sid',
`well_known_interactive_sid', `well_known_service_sid' and
`well_known_authenticated_users_sid'.
(cygsid::string): Define as const method.
(cygsid::get_sid): Set psid to NO_SID on error.
(cygsid::getfromstr): Ditto.
(cygsid::getfrompw): Simplify.
(cygsid::getfromgr): Check for gr == NULL.
(legal_sid_type): Move to security.h.
(set_process_privilege): Return -1 on error, otherwise 0 or 1 related
to previous privilege setting.
* security.cc (extract_nt_dom_user): Remove `static'.
(lsa2wchar): New function.
(open_local_policy): Ditto.
(close_local_policy): Ditto.
(get_lsa_srv_inf): Ditto.
(get_logon_server): Ditto.
(get_logon_server_and_user_domain): Ditto.
(get_user_groups): Ditto.
(is_group_member): Ditto.
(get_user_local_groups): Ditto.
(sid_in_token_groups): Ditto.
(get_user_primary_group): Ditto.
(get_group_sidlist): Ditto.
(get_system_priv_list): Ditto.
(get_priv_list): Ditto.
(get_dacl): Ditto.
(create_token): Ditto.
(subauth): Return immediately if SE_TCB_NAME can't be assigned.
Change all return statements in case of error to jumps to `out'
label. Add `out' label to support cleanup.
* security.h: Add extern declarations for `well_known_local_sid',
`well_known_dialup_sid', `well_known_network_sid',
`well_known_batch_sid', `well_known_interactive_sid',
`well_known_service_sid' and `well_known_authenticated_users_sid'.
Add extern declarations for functions `create_token',
`extract_nt_dom_user' and `get_logon_server_and_user_domain'.
(class cygsid): Add method `assign'. Change operator= to call new
`assign' method. Add `debug_print' method.
(class cygsidlist): New class.
(legal_sid_type): Moved from sec_helper.cc to here.
* spawn.cc (spawn_guts) Revert reversion of previous patch.
Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
again.
* syscalls.cc (seteuid): Rearranged. Call `create_token' now when
needed. Call `subauth' if `create_token' fails. Try setting token
owner and primary group only if token was not explicitely created
by `create_token'.
* uinfo.cc (internal_getlogin): Try harder to generate correct user
information. Especially don't trust return value of `GetUserName'.
2001-05-20 10:10:47 +02:00
|
|
|
{
|
2002-11-12 16:51:11 +01:00
|
|
|
s = strtoul (nsidstr + 4, &lasts, 10);
|
2003-09-25 05:51:51 +02:00
|
|
|
while (cnt < 8 && *lasts == '-')
|
2002-11-12 16:51:11 +01:00
|
|
|
r[cnt++] = strtoul (lasts + 1, &lasts, 10);
|
|
|
|
if (!*lasts)
|
2006-11-27 13:59:59 +01:00
|
|
|
return get_sid (s, cnt, r, well_known);
|
* autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
`LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
`NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
`NtCreateToken'.
* ntdll.h: Add declaration for `NtCreateToken'.
* sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
`well_known_network_sid', `well_known_batch_sid',
`well_known_interactive_sid', `well_known_service_sid' and
`well_known_authenticated_users_sid'.
(cygsid::string): Define as const method.
(cygsid::get_sid): Set psid to NO_SID on error.
(cygsid::getfromstr): Ditto.
(cygsid::getfrompw): Simplify.
(cygsid::getfromgr): Check for gr == NULL.
(legal_sid_type): Move to security.h.
(set_process_privilege): Return -1 on error, otherwise 0 or 1 related
to previous privilege setting.
* security.cc (extract_nt_dom_user): Remove `static'.
(lsa2wchar): New function.
(open_local_policy): Ditto.
(close_local_policy): Ditto.
(get_lsa_srv_inf): Ditto.
(get_logon_server): Ditto.
(get_logon_server_and_user_domain): Ditto.
(get_user_groups): Ditto.
(is_group_member): Ditto.
(get_user_local_groups): Ditto.
(sid_in_token_groups): Ditto.
(get_user_primary_group): Ditto.
(get_group_sidlist): Ditto.
(get_system_priv_list): Ditto.
(get_priv_list): Ditto.
(get_dacl): Ditto.
(create_token): Ditto.
(subauth): Return immediately if SE_TCB_NAME can't be assigned.
Change all return statements in case of error to jumps to `out'
label. Add `out' label to support cleanup.
* security.h: Add extern declarations for `well_known_local_sid',
`well_known_dialup_sid', `well_known_network_sid',
`well_known_batch_sid', `well_known_interactive_sid',
`well_known_service_sid' and `well_known_authenticated_users_sid'.
Add extern declarations for functions `create_token',
`extract_nt_dom_user' and `get_logon_server_and_user_domain'.
(class cygsid): Add method `assign'. Change operator= to call new
`assign' method. Add `debug_print' method.
(class cygsidlist): New class.
(legal_sid_type): Moved from sec_helper.cc to here.
* spawn.cc (spawn_guts) Revert reversion of previous patch.
Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
again.
* syscalls.cc (seteuid): Rearranged. Call `create_token' now when
needed. Call `subauth' if `create_token' fails. Try setting token
owner and primary group only if token was not explicitely created
by `create_token'.
* uinfo.cc (internal_getlogin): Try harder to generate correct user
information. Especially don't trust return value of `GetUserName'.
2001-05-20 10:10:47 +02:00
|
|
|
}
|
2002-11-12 16:51:11 +01:00
|
|
|
return psid = NO_SID;
|
2001-04-20 15:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
2001-05-29 22:43:40 +02:00
|
|
|
cygsid::getfrompw (const struct passwd *pw)
|
2001-04-20 15:02:32 +02:00
|
|
|
{
|
* autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
`LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
`NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
`NtCreateToken'.
* ntdll.h: Add declaration for `NtCreateToken'.
* sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
`well_known_network_sid', `well_known_batch_sid',
`well_known_interactive_sid', `well_known_service_sid' and
`well_known_authenticated_users_sid'.
(cygsid::string): Define as const method.
(cygsid::get_sid): Set psid to NO_SID on error.
(cygsid::getfromstr): Ditto.
(cygsid::getfrompw): Simplify.
(cygsid::getfromgr): Check for gr == NULL.
(legal_sid_type): Move to security.h.
(set_process_privilege): Return -1 on error, otherwise 0 or 1 related
to previous privilege setting.
* security.cc (extract_nt_dom_user): Remove `static'.
(lsa2wchar): New function.
(open_local_policy): Ditto.
(close_local_policy): Ditto.
(get_lsa_srv_inf): Ditto.
(get_logon_server): Ditto.
(get_logon_server_and_user_domain): Ditto.
(get_user_groups): Ditto.
(is_group_member): Ditto.
(get_user_local_groups): Ditto.
(sid_in_token_groups): Ditto.
(get_user_primary_group): Ditto.
(get_group_sidlist): Ditto.
(get_system_priv_list): Ditto.
(get_priv_list): Ditto.
(get_dacl): Ditto.
(create_token): Ditto.
(subauth): Return immediately if SE_TCB_NAME can't be assigned.
Change all return statements in case of error to jumps to `out'
label. Add `out' label to support cleanup.
* security.h: Add extern declarations for `well_known_local_sid',
`well_known_dialup_sid', `well_known_network_sid',
`well_known_batch_sid', `well_known_interactive_sid',
`well_known_service_sid' and `well_known_authenticated_users_sid'.
Add extern declarations for functions `create_token',
`extract_nt_dom_user' and `get_logon_server_and_user_domain'.
(class cygsid): Add method `assign'. Change operator= to call new
`assign' method. Add `debug_print' method.
(class cygsidlist): New class.
(legal_sid_type): Moved from sec_helper.cc to here.
* spawn.cc (spawn_guts) Revert reversion of previous patch.
Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
again.
* syscalls.cc (seteuid): Rearranged. Call `create_token' now when
needed. Call `subauth' if `create_token' fails. Try setting token
owner and primary group only if token was not explicitely created
by `create_token'.
* uinfo.cc (internal_getlogin): Try harder to generate correct user
information. Especially don't trust return value of `GetUserName'.
2001-05-20 10:10:47 +02:00
|
|
|
char *sp = (pw && pw->pw_gecos) ? strrchr (pw->pw_gecos, ',') : NULL;
|
2002-11-20 18:10:05 +01:00
|
|
|
return (*this = sp ? sp + 1 : sp) != NULL;
|
2001-04-20 15:02:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
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
|
|
|
cygsid::getfromgr (const struct __group32 *gr)
|
2001-04-20 15:02:32 +02:00
|
|
|
{
|
* autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
`LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
`NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
`NtCreateToken'.
* ntdll.h: Add declaration for `NtCreateToken'.
* sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
`well_known_network_sid', `well_known_batch_sid',
`well_known_interactive_sid', `well_known_service_sid' and
`well_known_authenticated_users_sid'.
(cygsid::string): Define as const method.
(cygsid::get_sid): Set psid to NO_SID on error.
(cygsid::getfromstr): Ditto.
(cygsid::getfrompw): Simplify.
(cygsid::getfromgr): Check for gr == NULL.
(legal_sid_type): Move to security.h.
(set_process_privilege): Return -1 on error, otherwise 0 or 1 related
to previous privilege setting.
* security.cc (extract_nt_dom_user): Remove `static'.
(lsa2wchar): New function.
(open_local_policy): Ditto.
(close_local_policy): Ditto.
(get_lsa_srv_inf): Ditto.
(get_logon_server): Ditto.
(get_logon_server_and_user_domain): Ditto.
(get_user_groups): Ditto.
(is_group_member): Ditto.
(get_user_local_groups): Ditto.
(sid_in_token_groups): Ditto.
(get_user_primary_group): Ditto.
(get_group_sidlist): Ditto.
(get_system_priv_list): Ditto.
(get_priv_list): Ditto.
(get_dacl): Ditto.
(create_token): Ditto.
(subauth): Return immediately if SE_TCB_NAME can't be assigned.
Change all return statements in case of error to jumps to `out'
label. Add `out' label to support cleanup.
* security.h: Add extern declarations for `well_known_local_sid',
`well_known_dialup_sid', `well_known_network_sid',
`well_known_batch_sid', `well_known_interactive_sid',
`well_known_service_sid' and `well_known_authenticated_users_sid'.
Add extern declarations for functions `create_token',
`extract_nt_dom_user' and `get_logon_server_and_user_domain'.
(class cygsid): Add method `assign'. Change operator= to call new
`assign' method. Add `debug_print' method.
(class cygsidlist): New class.
(legal_sid_type): Moved from sec_helper.cc to here.
* spawn.cc (spawn_guts) Revert reversion of previous patch.
Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
again.
* syscalls.cc (seteuid): Rearranged. Call `create_token' now when
needed. Call `subauth' if `create_token' fails. Try setting token
owner and primary group only if token was not explicitely created
by `create_token'.
* uinfo.cc (internal_getlogin): Try harder to generate correct user
information. Especially don't trust return value of `GetUserName'.
2001-05-20 10:10:47 +02:00
|
|
|
char *sp = (gr && gr->gr_passwd) ? gr->gr_passwd : NULL;
|
2002-11-20 18:10:05 +01:00
|
|
|
return (*this = sp) != NULL;
|
2001-04-20 15:02:32 +02:00
|
|
|
}
|
|
|
|
|
2006-11-27 13:59:59 +01:00
|
|
|
cygsid *
|
|
|
|
cygsidlist::alloc_sids (int n)
|
|
|
|
{
|
|
|
|
if (n > 0)
|
|
|
|
return (cygsid *) cmalloc (HEAP_STR, n * sizeof (cygsid));
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cygsidlist::free_sids ()
|
|
|
|
{
|
|
|
|
if (sids)
|
|
|
|
cfree (sids);
|
|
|
|
sids = NULL;
|
|
|
|
cnt = maxcnt = 0;
|
|
|
|
type = cygsidlist_empty;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
cygsidlist::add (const PSID nsi, bool well_known)
|
|
|
|
{
|
|
|
|
if (contains (nsi))
|
|
|
|
return TRUE;
|
|
|
|
if (cnt >= maxcnt)
|
|
|
|
{
|
|
|
|
cygsid *tmp = new cygsid [2 * maxcnt];
|
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
|
|
|
maxcnt *= 2;
|
|
|
|
for (int i = 0; i < cnt; ++i)
|
|
|
|
tmp[i] = sids[i];
|
|
|
|
delete [] sids;
|
|
|
|
sids = tmp;
|
|
|
|
}
|
|
|
|
if (well_known)
|
|
|
|
sids[cnt++] *= nsi;
|
|
|
|
else
|
|
|
|
sids[cnt++] = nsi;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-02-05 14:47:47 +01:00
|
|
|
bool
|
|
|
|
get_sids_info (cygpsid owner_sid, cygpsid group_sid, __uid32_t * uidret, __gid32_t * gidret)
|
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
struct __group32 *gr = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
|
2003-02-26 09:34:34 +01:00
|
|
|
owner_sid.debug_print ("get_sids_info: owner SID =");
|
|
|
|
group_sid.debug_print ("get_sids_info: group SID =");
|
|
|
|
|
2003-02-05 14:47:47 +01:00
|
|
|
if (group_sid == cygheap->user.groups.pgsid)
|
|
|
|
*gidret = myself->gid;
|
|
|
|
else if ((gr = internal_getgrsid (group_sid)))
|
|
|
|
*gidret = gr->gr_gid;
|
|
|
|
else
|
|
|
|
*gidret = ILLEGAL_GID;
|
|
|
|
|
|
|
|
if (owner_sid == cygheap->user.sid ())
|
|
|
|
{
|
|
|
|
*uidret = myself->uid;
|
|
|
|
if (*gidret == myself->gid)
|
|
|
|
ret = true;
|
|
|
|
else
|
|
|
|
ret = (internal_getgroups (0, NULL, &group_sid) > 0);
|
|
|
|
}
|
|
|
|
else if ((pw = internal_getpwsid (owner_sid)))
|
|
|
|
{
|
|
|
|
*uidret = pw->pw_uid;
|
|
|
|
if (gr || (*gidret != ILLEGAL_GID
|
|
|
|
&& (gr = internal_getgrgid (*gidret))))
|
|
|
|
for (int idx = 0; gr->gr_mem[idx]; ++idx)
|
|
|
|
if ((ret = strcasematch (pw->pw_name, gr->gr_mem[idx])))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*uidret = ILLEGAL_UID;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-11-26 14:23:27 +01:00
|
|
|
PSECURITY_DESCRIPTOR
|
|
|
|
security_descriptor::malloc (size_t nsize)
|
|
|
|
{
|
2006-10-22 16:57:43 +02:00
|
|
|
free ();
|
|
|
|
if ((psd = (PSECURITY_DESCRIPTOR) ::malloc (nsize)))
|
|
|
|
{
|
|
|
|
sd_size = nsize;
|
|
|
|
type = malloced;
|
|
|
|
}
|
2003-11-26 14:23:27 +01:00
|
|
|
return psd;
|
|
|
|
}
|
|
|
|
|
|
|
|
PSECURITY_DESCRIPTOR
|
|
|
|
security_descriptor::realloc (size_t nsize)
|
|
|
|
{
|
2006-10-22 16:57:43 +02:00
|
|
|
PSECURITY_DESCRIPTOR tmp;
|
|
|
|
|
|
|
|
if (type == malloced)
|
|
|
|
{
|
|
|
|
if (!(tmp = (PSECURITY_DESCRIPTOR) ::realloc (psd, nsize)))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!(tmp = (PSECURITY_DESCRIPTOR) ::malloc (nsize)))
|
|
|
|
return NULL;
|
|
|
|
if (psd)
|
|
|
|
{
|
|
|
|
memcpy (tmp, psd, LocalSize (psd));
|
|
|
|
LocalFree (psd);
|
|
|
|
}
|
|
|
|
}
|
2003-11-26 14:23:27 +01:00
|
|
|
sd_size = nsize;
|
2006-10-22 16:57:43 +02:00
|
|
|
type = malloced;
|
2003-11-26 14:23:27 +01:00
|
|
|
return psd = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-05 05:16:46 +02:00
|
|
|
security_descriptor::free ()
|
2003-11-26 14:23:27 +01:00
|
|
|
{
|
|
|
|
if (psd)
|
2006-10-22 16:57:43 +02:00
|
|
|
{
|
|
|
|
if (type == local_alloced)
|
|
|
|
LocalFree (psd);
|
|
|
|
else
|
|
|
|
::free (psd);
|
|
|
|
}
|
2003-11-26 14:23:27 +01:00
|
|
|
psd = NULL;
|
|
|
|
sd_size = 0;
|
2006-10-22 16:57:43 +02:00
|
|
|
type = local_alloced;
|
2003-11-26 14:23:27 +01:00
|
|
|
}
|
|
|
|
|
2002-06-06 13:17:51 +02:00
|
|
|
#if 0 // unused
|
2001-04-30 20:21:48 +02:00
|
|
|
#define SIDLEN (sidlen = MAX_SID_LEN, &sidlen)
|
|
|
|
#define DOMLEN (domlen = INTERNET_MAX_HOST_NAME_LENGTH, &domlen)
|
|
|
|
|
2001-04-20 15:02:32 +02:00
|
|
|
BOOL
|
|
|
|
lookup_name (const char *name, const char *logsrv, PSID ret_sid)
|
|
|
|
{
|
2001-04-25 11:43:25 +02:00
|
|
|
cygsid sid;
|
2001-04-20 15:02:32 +02:00
|
|
|
DWORD sidlen;
|
2001-04-30 20:21:48 +02:00
|
|
|
char domuser[INTERNET_MAX_HOST_NAME_LENGTH + UNLEN + 2];
|
|
|
|
char dom[INTERNET_MAX_HOST_NAME_LENGTH + 1];
|
2001-04-20 15:02:32 +02:00
|
|
|
DWORD domlen;
|
|
|
|
SID_NAME_USE acc_type;
|
|
|
|
|
|
|
|
debug_printf ("name : %s", name ? name : "NULL");
|
|
|
|
|
|
|
|
if (!name)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (cygheap->user.domain ())
|
|
|
|
{
|
|
|
|
strcat (strcat (strcpy (domuser, cygheap->user.domain ()), "\\"), name);
|
2001-04-30 20:21:48 +02:00
|
|
|
if (LookupAccountName (NULL, domuser, sid, SIDLEN, dom, DOMLEN, &acc_type)
|
2001-04-20 15:02:32 +02:00
|
|
|
&& legal_sid_type (acc_type))
|
|
|
|
goto got_it;
|
|
|
|
if (logsrv && *logsrv
|
2001-04-30 20:21:48 +02:00
|
|
|
&& LookupAccountName (logsrv, domuser, sid, SIDLEN,
|
|
|
|
dom, DOMLEN, &acc_type)
|
2001-04-20 15:02:32 +02:00
|
|
|
&& legal_sid_type (acc_type))
|
|
|
|
goto got_it;
|
|
|
|
}
|
|
|
|
if (logsrv && *logsrv)
|
|
|
|
{
|
2001-04-30 20:21:48 +02:00
|
|
|
if (LookupAccountName (logsrv, name, sid, SIDLEN, dom, DOMLEN, &acc_type)
|
2001-04-20 15:02:32 +02:00
|
|
|
&& legal_sid_type (acc_type))
|
|
|
|
goto got_it;
|
|
|
|
if (acc_type == SidTypeDomain)
|
|
|
|
{
|
|
|
|
strcat (strcat (strcpy (domuser, dom), "\\"), name);
|
2001-04-30 20:21:48 +02:00
|
|
|
if (LookupAccountName (logsrv, domuser, sid, SIDLEN,
|
|
|
|
dom, DOMLEN, &acc_type))
|
2001-04-20 15:02:32 +02:00
|
|
|
goto got_it;
|
|
|
|
}
|
|
|
|
}
|
2001-04-30 20:21:48 +02:00
|
|
|
if (LookupAccountName (NULL, name, sid, SIDLEN, dom, DOMLEN, &acc_type)
|
2001-04-20 15:02:32 +02:00
|
|
|
&& legal_sid_type (acc_type))
|
|
|
|
goto got_it;
|
|
|
|
if (acc_type == SidTypeDomain)
|
|
|
|
{
|
|
|
|
strcat (strcat (strcpy (domuser, dom), "\\"), name);
|
2001-04-30 20:21:48 +02:00
|
|
|
if (LookupAccountName (NULL, domuser, sid, SIDLEN, dom, DOMLEN,&acc_type))
|
2001-04-20 15:02:32 +02:00
|
|
|
goto got_it;
|
|
|
|
}
|
2002-09-22 05:38:57 +02:00
|
|
|
debug_printf ("LookupAccountName (%s) %E", name);
|
2001-04-20 15:02:32 +02:00
|
|
|
__seterrno ();
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
got_it:
|
2002-09-22 05:38:57 +02:00
|
|
|
debug_printf ("sid : [%d]", *GetSidSubAuthority ((PSID) sid,
|
|
|
|
*GetSidSubAuthorityCount ((PSID) sid) - 1));
|
2001-04-20 15:02:32 +02:00
|
|
|
|
|
|
|
if (ret_sid)
|
|
|
|
memcpy (ret_sid, sid, sidlen);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-04-20 22:36:13 +02:00
|
|
|
|
2001-04-30 20:21:48 +02:00
|
|
|
#undef SIDLEN
|
|
|
|
#undef DOMLEN
|
2002-06-06 13:17:51 +02:00
|
|
|
#endif //unused
|
2001-04-30 20:21:48 +02:00
|
|
|
|
2006-11-01 10:00:14 +01:00
|
|
|
/* Order must be same as cygpriv_idx in security.h. */
|
2005-04-03 15:06:43 +02:00
|
|
|
static const char *cygpriv[] =
|
2001-04-20 22:36:13 +02:00
|
|
|
{
|
2005-04-03 15:06:43 +02:00
|
|
|
SE_CREATE_TOKEN_NAME,
|
|
|
|
SE_ASSIGNPRIMARYTOKEN_NAME,
|
|
|
|
SE_LOCK_MEMORY_NAME,
|
|
|
|
SE_INCREASE_QUOTA_NAME,
|
|
|
|
SE_UNSOLICITED_INPUT_NAME,
|
|
|
|
SE_MACHINE_ACCOUNT_NAME,
|
|
|
|
SE_TCB_NAME,
|
|
|
|
SE_SECURITY_NAME,
|
|
|
|
SE_TAKE_OWNERSHIP_NAME,
|
|
|
|
SE_LOAD_DRIVER_NAME,
|
|
|
|
SE_SYSTEM_PROFILE_NAME,
|
|
|
|
SE_SYSTEMTIME_NAME,
|
|
|
|
SE_PROF_SINGLE_PROCESS_NAME,
|
|
|
|
SE_INC_BASE_PRIORITY_NAME,
|
|
|
|
SE_CREATE_PAGEFILE_NAME,
|
|
|
|
SE_CREATE_PERMANENT_NAME,
|
|
|
|
SE_BACKUP_NAME,
|
|
|
|
SE_RESTORE_NAME,
|
|
|
|
SE_SHUTDOWN_NAME,
|
|
|
|
SE_DEBUG_NAME,
|
|
|
|
SE_AUDIT_NAME,
|
|
|
|
SE_SYSTEM_ENVIRONMENT_NAME,
|
|
|
|
SE_CHANGE_NOTIFY_NAME,
|
|
|
|
SE_REMOTE_SHUTDOWN_NAME,
|
|
|
|
SE_CREATE_GLOBAL_NAME,
|
|
|
|
SE_UNDOCK_NAME,
|
|
|
|
SE_MANAGE_VOLUME_NAME,
|
|
|
|
SE_IMPERSONATE_NAME,
|
|
|
|
SE_ENABLE_DELEGATION_NAME,
|
2006-11-01 10:00:14 +01:00
|
|
|
SE_SYNC_AGENT_NAME,
|
|
|
|
SE_RELABEL_NAME,
|
|
|
|
SE_INCREASE_WORKING_SET_NAME,
|
|
|
|
SE_TIME_ZONE_NAME,
|
|
|
|
SE_CREATE_SYMBOLIC_LINK_NAME
|
2005-04-03 15:06:43 +02:00
|
|
|
};
|
2001-04-20 22:36:13 +02:00
|
|
|
|
2005-04-03 15:06:43 +02:00
|
|
|
const LUID *
|
|
|
|
privilege_luid (cygpriv_idx idx)
|
|
|
|
{
|
|
|
|
if (idx < 0 || idx >= SE_NUM_PRIVS)
|
|
|
|
return NULL;
|
|
|
|
if (!cygheap->luid[idx].LowPart && !cygheap->luid[idx].HighPart
|
|
|
|
&& !LookupPrivilegeValue (NULL, cygpriv[idx], &cygheap->luid[idx]))
|
2003-11-26 15:29:22 +01:00
|
|
|
{
|
|
|
|
__seterrno ();
|
2005-04-03 15:06:43 +02:00
|
|
|
return NULL;
|
2003-11-26 15:29:22 +01:00
|
|
|
}
|
2005-04-03 15:06:43 +02:00
|
|
|
return &cygheap->luid[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
const LUID *
|
|
|
|
privilege_luid_by_name (const char *pname)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
|
|
|
|
if (!pname)
|
|
|
|
return NULL;
|
|
|
|
for (idx = 0; idx < SE_NUM_PRIVS; ++idx)
|
|
|
|
if (!strcmp (pname, cygpriv[idx]))
|
|
|
|
return privilege_luid ((cygpriv_idx) idx);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
privilege_name (cygpriv_idx idx)
|
|
|
|
{
|
|
|
|
if (idx < 0 || idx >= SE_NUM_PRIVS)
|
|
|
|
return "<unknown privilege>";
|
|
|
|
return cygpriv[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
set_privilege (HANDLE token, cygpriv_idx privilege, bool enable)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
const LUID *priv_luid;
|
|
|
|
TOKEN_PRIVILEGES new_priv, orig_priv;
|
|
|
|
DWORD size;
|
2003-11-26 15:29:22 +01:00
|
|
|
|
2005-04-03 15:06:43 +02:00
|
|
|
if (!(priv_luid = privilege_luid (privilege)))
|
2001-04-20 22:36:13 +02:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_priv.PrivilegeCount = 1;
|
2005-04-03 15:06:43 +02:00
|
|
|
new_priv.Privileges[0].Luid = *priv_luid;
|
2001-04-20 22:36:13 +02:00
|
|
|
new_priv.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED : 0;
|
|
|
|
|
2005-04-03 15:06:43 +02:00
|
|
|
if (!AdjustTokenPrivileges (token, FALSE, &new_priv,
|
2001-09-07 23:32:07 +02:00
|
|
|
sizeof orig_priv, &orig_priv, &size))
|
* autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
`LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
`NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
`NtCreateToken'.
* ntdll.h: Add declaration for `NtCreateToken'.
* sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
`well_known_network_sid', `well_known_batch_sid',
`well_known_interactive_sid', `well_known_service_sid' and
`well_known_authenticated_users_sid'.
(cygsid::string): Define as const method.
(cygsid::get_sid): Set psid to NO_SID on error.
(cygsid::getfromstr): Ditto.
(cygsid::getfrompw): Simplify.
(cygsid::getfromgr): Check for gr == NULL.
(legal_sid_type): Move to security.h.
(set_process_privilege): Return -1 on error, otherwise 0 or 1 related
to previous privilege setting.
* security.cc (extract_nt_dom_user): Remove `static'.
(lsa2wchar): New function.
(open_local_policy): Ditto.
(close_local_policy): Ditto.
(get_lsa_srv_inf): Ditto.
(get_logon_server): Ditto.
(get_logon_server_and_user_domain): Ditto.
(get_user_groups): Ditto.
(is_group_member): Ditto.
(get_user_local_groups): Ditto.
(sid_in_token_groups): Ditto.
(get_user_primary_group): Ditto.
(get_group_sidlist): Ditto.
(get_system_priv_list): Ditto.
(get_priv_list): Ditto.
(get_dacl): Ditto.
(create_token): Ditto.
(subauth): Return immediately if SE_TCB_NAME can't be assigned.
Change all return statements in case of error to jumps to `out'
label. Add `out' label to support cleanup.
* security.h: Add extern declarations for `well_known_local_sid',
`well_known_dialup_sid', `well_known_network_sid',
`well_known_batch_sid', `well_known_interactive_sid',
`well_known_service_sid' and `well_known_authenticated_users_sid'.
Add extern declarations for functions `create_token',
`extract_nt_dom_user' and `get_logon_server_and_user_domain'.
(class cygsid): Add method `assign'. Change operator= to call new
`assign' method. Add `debug_print' method.
(class cygsidlist): New class.
(legal_sid_type): Moved from sec_helper.cc to here.
* spawn.cc (spawn_guts) Revert reversion of previous patch.
Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
again.
* syscalls.cc (seteuid): Rearranged. Call `create_token' now when
needed. Call `subauth' if `create_token' fails. Try setting token
owner and primary group only if token was not explicitely created
by `create_token'.
* uinfo.cc (internal_getlogin): Try harder to generate correct user
information. Especially don't trust return value of `GetUserName'.
2001-05-20 10:10:47 +02:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* AdjustTokenPrivileges returns TRUE even if the privilege could not
|
2002-09-22 05:38:57 +02:00
|
|
|
be enabled. GetLastError () returns an correct error code, though. */
|
* autoload.cc: Add load statements for `LookupAccountNameW',
`LsaClose', `LsaEnumerateAccountRights', `LsaFreeMemory',
`LsaOpenPolicy', `LsaQueryInformationPolicy', `NetLocalGroupEnum',
`NetLocalGroupGetMembers', `NetServerEnum', `NetUserGetGroups' and
`NtCreateToken'.
* ntdll.h: Add declaration for `NtCreateToken'.
* sec_helper.cc: Add `well_known_local_sid', `well_known_dialup_sid',
`well_known_network_sid', `well_known_batch_sid',
`well_known_interactive_sid', `well_known_service_sid' and
`well_known_authenticated_users_sid'.
(cygsid::string): Define as const method.
(cygsid::get_sid): Set psid to NO_SID on error.
(cygsid::getfromstr): Ditto.
(cygsid::getfrompw): Simplify.
(cygsid::getfromgr): Check for gr == NULL.
(legal_sid_type): Move to security.h.
(set_process_privilege): Return -1 on error, otherwise 0 or 1 related
to previous privilege setting.
* security.cc (extract_nt_dom_user): Remove `static'.
(lsa2wchar): New function.
(open_local_policy): Ditto.
(close_local_policy): Ditto.
(get_lsa_srv_inf): Ditto.
(get_logon_server): Ditto.
(get_logon_server_and_user_domain): Ditto.
(get_user_groups): Ditto.
(is_group_member): Ditto.
(get_user_local_groups): Ditto.
(sid_in_token_groups): Ditto.
(get_user_primary_group): Ditto.
(get_group_sidlist): Ditto.
(get_system_priv_list): Ditto.
(get_priv_list): Ditto.
(get_dacl): Ditto.
(create_token): Ditto.
(subauth): Return immediately if SE_TCB_NAME can't be assigned.
Change all return statements in case of error to jumps to `out'
label. Add `out' label to support cleanup.
* security.h: Add extern declarations for `well_known_local_sid',
`well_known_dialup_sid', `well_known_network_sid',
`well_known_batch_sid', `well_known_interactive_sid',
`well_known_service_sid' and `well_known_authenticated_users_sid'.
Add extern declarations for functions `create_token',
`extract_nt_dom_user' and `get_logon_server_and_user_domain'.
(class cygsid): Add method `assign'. Change operator= to call new
`assign' method. Add `debug_print' method.
(class cygsidlist): New class.
(legal_sid_type): Moved from sec_helper.cc to here.
* spawn.cc (spawn_guts) Revert reversion of previous patch.
Call `RevertToSelf' and `ImpersonateLoggedOnUser' instead of `seteuid'
again.
* syscalls.cc (seteuid): Rearranged. Call `create_token' now when
needed. Call `subauth' if `create_token' fails. Try setting token
owner and primary group only if token was not explicitely created
by `create_token'.
* uinfo.cc (internal_getlogin): Try harder to generate correct user
information. Especially don't trust return value of `GetUserName'.
2001-05-20 10:10:47 +02:00
|
|
|
if (enable && GetLastError () == ERROR_NOT_ALL_ASSIGNED)
|
2001-04-20 22:36:13 +02:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-04-03 15:06:43 +02:00
|
|
|
/* If orig_priv.PrivilegeCount is 0, the privilege hasn't been changed. */
|
|
|
|
if (!orig_priv.PrivilegeCount)
|
|
|
|
ret = enable ? 1 : 0;
|
|
|
|
else
|
|
|
|
ret = (orig_priv.Privileges[0].Attributes & SE_PRIVILEGE_ENABLED) ? 1 : 0;
|
2001-04-20 22:36:13 +02:00
|
|
|
|
|
|
|
out:
|
2005-04-03 15:06:43 +02:00
|
|
|
syscall_printf ("%d = set_privilege ((token %x) %s, %d)",
|
|
|
|
ret, token, privilege_name (privilege), enable);
|
2001-04-20 22:36:13 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2002-07-01 16:31:28 +02:00
|
|
|
|
2004-04-16 23:22:13 +02:00
|
|
|
void
|
2005-04-03 15:06:43 +02:00
|
|
|
set_cygwin_privileges (HANDLE token)
|
2004-04-16 23:22:13 +02:00
|
|
|
{
|
2005-04-03 15:06:43 +02:00
|
|
|
set_privilege (token, SE_RESTORE_PRIV, true);
|
2006-03-02 00:14:25 +01:00
|
|
|
set_privilege (token, SE_BACKUP_PRIV, true);
|
2005-04-03 15:06:43 +02:00
|
|
|
set_privilege (token, SE_CHANGE_NOTIFY_PRIV, !allow_traverse);
|
2004-04-16 23:22:13 +02:00
|
|
|
}
|
|
|
|
|
2006-07-17 21:30:30 +02:00
|
|
|
/* Function to return a common SECURITY_DESCRIPTOR that
|
|
|
|
allows all access. */
|
2002-07-01 16:31:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
SECURITY_DESCRIPTOR *__stdcall
|
|
|
|
get_null_sd ()
|
|
|
|
{
|
|
|
|
static NO_COPY SECURITY_DESCRIPTOR sd;
|
2006-07-17 21:30:30 +02:00
|
|
|
static NO_COPY SECURITY_DESCRIPTOR *null_sdp;
|
2002-07-01 16:31:28 +02:00
|
|
|
|
2006-07-17 21:30:30 +02:00
|
|
|
if (!null_sdp)
|
2002-07-01 16:31:28 +02:00
|
|
|
{
|
|
|
|
InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
|
|
|
|
SetSecurityDescriptorDacl (&sd, TRUE, 0, FALSE);
|
|
|
|
null_sdp = &sd;
|
|
|
|
}
|
|
|
|
return null_sdp;
|
|
|
|
}
|
|
|
|
|
2006-07-17 21:30:30 +02:00
|
|
|
/* Initialize global security attributes.
|
|
|
|
Called from dcrt0.cc (_dll_crt0). */
|
2003-11-04 16:48:19 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
init_global_security ()
|
|
|
|
{
|
|
|
|
sec_none.nLength = sec_none_nih.nLength =
|
|
|
|
sec_all.nLength = sec_all_nih.nLength = sizeof (SECURITY_ATTRIBUTES);
|
|
|
|
sec_none.bInheritHandle = sec_all.bInheritHandle = TRUE;
|
|
|
|
sec_none_nih.bInheritHandle = sec_all_nih.bInheritHandle = FALSE;
|
|
|
|
sec_none.lpSecurityDescriptor = sec_none_nih.lpSecurityDescriptor = NULL;
|
|
|
|
sec_all.lpSecurityDescriptor = sec_all_nih.lpSecurityDescriptor =
|
|
|
|
get_null_sd ();
|
|
|
|
}
|
|
|
|
|
2003-12-07 23:37:12 +01:00
|
|
|
bool
|
2003-09-16 02:45:50 +02:00
|
|
|
sec_acl (PACL acl, bool original, bool admins, PSID sid1, PSID sid2, DWORD access2)
|
2002-07-01 16:31:28 +02:00
|
|
|
{
|
|
|
|
size_t acl_len = MAX_DACL_LEN(5);
|
2003-09-27 03:56:36 +02:00
|
|
|
LPVOID pAce;
|
2003-09-16 02:45:50 +02:00
|
|
|
cygpsid psid;
|
2002-07-01 16:31:28 +02:00
|
|
|
|
2005-06-07 21:31:42 +02:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
if ((unsigned long) acl % 4)
|
|
|
|
api_fatal ("Incorrectly aligned incoming ACL buffer!");
|
|
|
|
#endif
|
2002-07-01 16:31:28 +02:00
|
|
|
if (!InitializeAcl (acl, acl_len, ACL_REVISION))
|
|
|
|
{
|
|
|
|
debug_printf ("InitializeAcl %E");
|
2003-12-07 23:37:12 +01:00
|
|
|
return false;
|
2002-07-01 16:31:28 +02:00
|
|
|
}
|
|
|
|
if (sid1)
|
|
|
|
if (!AddAccessAllowedAce (acl, ACL_REVISION,
|
|
|
|
GENERIC_ALL, sid1))
|
2002-08-08 16:16:14 +02:00
|
|
|
debug_printf ("AddAccessAllowedAce(sid1) %E");
|
2003-09-16 11:24:52 +02:00
|
|
|
if (original && (psid = cygheap->user.saved_sid ())
|
2003-09-16 02:45:50 +02:00
|
|
|
&& psid != sid1 && psid != well_known_system_sid)
|
|
|
|
if (!AddAccessAllowedAce (acl, ACL_REVISION,
|
|
|
|
GENERIC_ALL, psid))
|
|
|
|
debug_printf ("AddAccessAllowedAce(original) %E");
|
|
|
|
if (sid2)
|
|
|
|
if (!AddAccessAllowedAce (acl, ACL_REVISION,
|
|
|
|
access2, sid2))
|
|
|
|
debug_printf ("AddAccessAllowedAce(sid2) %E");
|
2002-07-01 16:31:28 +02:00
|
|
|
if (admins)
|
|
|
|
if (!AddAccessAllowedAce (acl, ACL_REVISION,
|
|
|
|
GENERIC_ALL, well_known_admins_sid))
|
|
|
|
debug_printf ("AddAccessAllowedAce(admin) %E");
|
|
|
|
if (!AddAccessAllowedAce (acl, ACL_REVISION,
|
|
|
|
GENERIC_ALL, well_known_system_sid))
|
|
|
|
debug_printf ("AddAccessAllowedAce(system) %E");
|
2003-09-27 03:56:36 +02:00
|
|
|
FindFirstFreeAce (acl, &pAce);
|
|
|
|
if (pAce)
|
|
|
|
acl->AclSize = (char *) pAce - (char *) acl;
|
|
|
|
else
|
|
|
|
debug_printf ("FindFirstFreeAce %E");
|
|
|
|
|
2003-12-07 23:37:12 +01:00
|
|
|
return true;
|
2002-07-01 16:31:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PSECURITY_ATTRIBUTES __stdcall
|
2003-09-16 02:45:50 +02:00
|
|
|
__sec_user (PVOID sa_buf, PSID sid1, PSID sid2, DWORD access2, BOOL inherit)
|
2002-07-01 16:31:28 +02:00
|
|
|
{
|
|
|
|
PSECURITY_ATTRIBUTES psa = (PSECURITY_ATTRIBUTES) sa_buf;
|
|
|
|
PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR)
|
|
|
|
((char *) sa_buf + sizeof (*psa));
|
|
|
|
PACL acl = (PACL) ((char *) sa_buf + sizeof (*psa) + sizeof (*psd));
|
|
|
|
|
2005-06-07 21:31:42 +02:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
if ((unsigned long) sa_buf % 4)
|
|
|
|
api_fatal ("Incorrectly aligned incoming SA buffer!");
|
|
|
|
#endif
|
|
|
|
if (!wincap.has_security ()
|
|
|
|
|| !sec_acl (acl, true, true, sid1, sid2, access2))
|
2002-07-01 16:31:28 +02:00
|
|
|
return inherit ? &sec_none : &sec_none_nih;
|
|
|
|
|
|
|
|
if (!InitializeSecurityDescriptor (psd, SECURITY_DESCRIPTOR_REVISION))
|
|
|
|
debug_printf ("InitializeSecurityDescriptor %E");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting the owner lets the created security attribute not work
|
|
|
|
* on NT4 SP3 Server. Don't know why, but the function still does
|
|
|
|
* what it should do also if the owner isn't set.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
if (!SetSecurityDescriptorOwner (psd, sid, FALSE))
|
|
|
|
debug_printf ("SetSecurityDescriptorOwner %E");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!SetSecurityDescriptorDacl (psd, TRUE, acl, FALSE))
|
|
|
|
debug_printf ("SetSecurityDescriptorDacl %E");
|
|
|
|
|
|
|
|
psa->nLength = sizeof (SECURITY_ATTRIBUTES);
|
|
|
|
psa->lpSecurityDescriptor = psd;
|
|
|
|
psa->bInheritHandle = inherit;
|
|
|
|
return psa;
|
|
|
|
}
|