2000-09-08 04:56:55 +02:00
|
|
|
/* security.h: security declarations
|
|
|
|
|
2013-01-21 05:34:52 +01:00
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
|
|
|
2011, 2012, 2013 Red Hat, Inc.
|
2000-09-08 04:56:55 +02: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. */
|
|
|
|
|
2012-07-22 00:58:20 +02:00
|
|
|
#pragma once
|
2003-09-10 04:12:26 +02:00
|
|
|
|
2002-07-02 03:36:15 +02:00
|
|
|
#include <accctrl.h>
|
2001-04-20 15:02:32 +02:00
|
|
|
|
2009-10-30 20:58:53 +01:00
|
|
|
/* Special file attribute set, for instance, in open() and mkdir() to
|
|
|
|
flag that a file has just been created. Used in alloc_sd, see there. */
|
|
|
|
#define S_JUSTCREATED 0x80000000
|
|
|
|
|
2001-04-30 20:21:48 +02:00
|
|
|
#define DEFAULT_UID DOMAIN_USER_RID_ADMIN
|
2003-02-06 15:01:54 +01:00
|
|
|
#define UNKNOWN_UID 400 /* Non conflicting number */
|
|
|
|
#define UNKNOWN_GID 401
|
2001-04-30 20:21:48 +02:00
|
|
|
|
* 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
|
|
|
#define MAX_SID_LEN 40
|
2002-05-13 14:10:49 +02:00
|
|
|
#define MAX_DACL_LEN(n) (sizeof (ACL) \
|
|
|
|
+ (n) * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD) + MAX_SID_LEN))
|
2008-04-18 22:13:37 +02:00
|
|
|
#define SD_MIN_SIZE (sizeof (SECURITY_DESCRIPTOR) + MAX_DACL_LEN (1))
|
2010-09-10 16:53:44 +02:00
|
|
|
#define ACL_MAXIMUM_SIZE 65532 /* Yeah, right. 64K - sizeof (DWORD). */
|
|
|
|
#define SD_MAXIMUM_SIZE 65536
|
* 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
|
|
|
#define NO_SID ((PSID)NULL)
|
|
|
|
|
2007-07-19 10:33:22 +02:00
|
|
|
#ifndef SE_CREATE_TOKEN_PRIVILEGE
|
2013-04-24 12:16:13 +02:00
|
|
|
#define SE_CREATE_TOKEN_PRIVILEGE 2U
|
|
|
|
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE 3U
|
|
|
|
#define SE_LOCK_MEMORY_PRIVILEGE 4U
|
|
|
|
#define SE_INCREASE_QUOTA_PRIVILEGE 5U
|
|
|
|
#define SE_MACHINE_ACCOUNT_PRIVILEGE 6U
|
|
|
|
#define SE_TCB_PRIVILEGE 7U
|
|
|
|
#define SE_SECURITY_PRIVILEGE 8U
|
|
|
|
#define SE_TAKE_OWNERSHIP_PRIVILEGE 9U
|
|
|
|
#define SE_LOAD_DRIVER_PRIVILEGE 10U
|
|
|
|
#define SE_SYSTEM_PROFILE_PRIVILEGE 11U
|
|
|
|
#define SE_SYSTEMTIME_PRIVILEGE 12U
|
|
|
|
#define SE_PROF_SINGLE_PROCESS_PRIVILEGE 13U
|
|
|
|
#define SE_INC_BASE_PRIORITY_PRIVILEGE 14U
|
|
|
|
#define SE_CREATE_PAGEFILE_PRIVILEGE 15U
|
|
|
|
#define SE_CREATE_PERMANENT_PRIVILEGE 16U
|
|
|
|
#define SE_BACKUP_PRIVILEGE 17U
|
|
|
|
#define SE_RESTORE_PRIVILEGE 18U
|
|
|
|
#define SE_SHUTDOWN_PRIVILEGE 19U
|
|
|
|
#define SE_DEBUG_PRIVILEGE 20U
|
|
|
|
#define SE_AUDIT_PRIVILEGE 21U
|
|
|
|
#define SE_SYSTEM_ENVIRONMENT_PRIVILEGE 22U
|
|
|
|
#define SE_CHANGE_NOTIFY_PRIVILEGE 23U
|
|
|
|
#define SE_REMOTE_SHUTDOWN_PRIVILEGE 24U
|
|
|
|
#define SE_UNDOCK_PRIVILEGE 25U
|
|
|
|
#define SE_SYNC_AGENT_PRIVILEGE 26U
|
|
|
|
#define SE_ENABLE_DELEGATION_PRIVILEGE 27U
|
|
|
|
#define SE_MANAGE_VOLUME_PRIVILEGE 28U
|
|
|
|
#define SE_IMPERSONATE_PRIVILEGE 29U
|
|
|
|
#define SE_CREATE_GLOBAL_PRIVILEGE 30U
|
2007-07-19 10:33:22 +02:00
|
|
|
/* Starting with Vista */
|
2013-04-24 12:16:13 +02:00
|
|
|
#define SE_TRUSTED_CREDMAN_ACCESS_PRIVILEGE 31U
|
|
|
|
#define SE_RELABEL_PRIVILEGE 32U
|
|
|
|
#define SE_INCREASE_WORKING_SET_PRIVILEGE 33U
|
|
|
|
#define SE_TIME_ZONE_PRIVILEGE 34U
|
|
|
|
#define SE_CREATE_SYMBOLIC_LINK_PRIVILEGE 35U
|
2007-07-19 10:33:22 +02:00
|
|
|
|
|
|
|
#define SE_MAX_WELL_KNOWN_PRIVILEGE SE_CREATE_SYMBOLIC_LINK_PRIVILEGE
|
|
|
|
|
|
|
|
#endif /* ! SE_CREATE_TOKEN_PRIVILEGE */
|
|
|
|
|
2006-11-23 17:44:55 +01:00
|
|
|
/* Added for debugging purposes. */
|
|
|
|
typedef struct {
|
|
|
|
BYTE Revision;
|
|
|
|
BYTE SubAuthorityCount;
|
|
|
|
SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
|
|
|
|
DWORD SubAuthority[8];
|
|
|
|
} DBGSID, *PDBGSID;
|
|
|
|
|
2004-02-05 18:23:19 +01:00
|
|
|
/* Macro to define variable length SID structures */
|
2006-11-23 17:44:55 +01:00
|
|
|
#define MKSID(name, comment, authority, count, rid...) \
|
2004-02-05 18:23:19 +01:00
|
|
|
static NO_COPY struct { \
|
|
|
|
BYTE Revision; \
|
|
|
|
BYTE SubAuthorityCount; \
|
|
|
|
SID_IDENTIFIER_AUTHORITY IdentifierAuthority; \
|
|
|
|
DWORD SubAuthority[count]; \
|
|
|
|
} name##_struct = { SID_REVISION, count, {authority}, {rid}}; \
|
|
|
|
cygpsid NO_COPY name = (PSID) &name##_struct;
|
|
|
|
|
2003-11-26 11:52:21 +01:00
|
|
|
#define FILE_READ_BITS (FILE_READ_DATA | GENERIC_READ | GENERIC_ALL)
|
|
|
|
#define FILE_WRITE_BITS (FILE_WRITE_DATA | GENERIC_WRITE | GENERIC_ALL)
|
|
|
|
#define FILE_EXEC_BITS (FILE_EXECUTE | GENERIC_EXECUTE | GENERIC_ALL)
|
|
|
|
|
2011-04-29 12:38:12 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
/* We need these declarations, otherwise g++ complains that the below
|
|
|
|
inline methods use an undefined function, if ntdll.h isn't included. */
|
|
|
|
BOOLEAN NTAPI RtlEqualSid (PSID, PSID);
|
|
|
|
NTSTATUS NTAPI RtlCopySid (ULONG, PSID, PSID);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-02-04 15:58:04 +01:00
|
|
|
class cygpsid {
|
|
|
|
protected:
|
2001-04-25 11:43:25 +02:00
|
|
|
PSID psid;
|
2003-02-04 15:58:04 +01:00
|
|
|
public:
|
|
|
|
cygpsid () {}
|
|
|
|
cygpsid (PSID nsid) { psid = nsid; }
|
2006-10-22 16:57:43 +02:00
|
|
|
operator PSID () const { return psid; }
|
2003-02-04 15:58:04 +01:00
|
|
|
const PSID operator= (PSID nsid) { return psid = nsid;}
|
2013-04-23 11:44:36 +02:00
|
|
|
uid_t get_id (BOOL search_grp, int *type = NULL);
|
2003-02-04 15:58:04 +01:00
|
|
|
int get_uid () { return get_id (FALSE); }
|
|
|
|
int get_gid () { return get_id (TRUE); }
|
|
|
|
|
2008-02-14 17:47:11 +01:00
|
|
|
PWCHAR string (PWCHAR nsidstr) const;
|
2003-02-04 15:58:04 +01:00
|
|
|
char *string (char *nsidstr) const;
|
|
|
|
|
|
|
|
bool operator== (const PSID nsid) const
|
|
|
|
{
|
|
|
|
if (!psid || !nsid)
|
|
|
|
return nsid == psid;
|
2011-04-29 12:38:12 +02:00
|
|
|
return RtlEqualSid (psid, nsid);
|
2003-02-04 15:58:04 +01:00
|
|
|
}
|
|
|
|
bool operator!= (const PSID nsid) const
|
|
|
|
{ return !(*this == nsid); }
|
|
|
|
bool operator== (const char *nsidstr) const;
|
|
|
|
bool operator!= (const char *nsidstr) const
|
|
|
|
{ return !(*this == nsidstr); }
|
|
|
|
|
|
|
|
void debug_print (const char *prefix = NULL) const
|
|
|
|
{
|
2003-10-26 11:58:11 +01:00
|
|
|
char buf[256] __attribute__ ((unused));
|
2003-02-04 15:58:04 +01:00
|
|
|
debug_printf ("%s %s", prefix ?: "", string (buf) ?: "NULL");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class cygsid : public cygpsid {
|
2001-04-25 11:43:25 +02:00
|
|
|
char sbuf[MAX_SID_LEN];
|
2006-11-27 13:59:59 +01:00
|
|
|
bool well_known_sid;
|
* 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
|
|
|
|
2006-11-27 13:59:59 +01:00
|
|
|
const PSID getfromstr (const char *nsidstr, bool well_known);
|
|
|
|
PSID get_sid (DWORD s, DWORD cnt, DWORD *r, bool well_known);
|
* 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
|
|
|
|
2006-11-27 13:59:59 +01:00
|
|
|
inline const PSID assign (const PSID nsid, bool 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
|
|
|
{
|
|
|
|
if (!nsid)
|
2001-09-07 23:32:07 +02:00
|
|
|
psid = NO_SID;
|
* 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
|
|
|
else
|
2001-09-07 23:32:07 +02:00
|
|
|
{
|
|
|
|
psid = (PSID) sbuf;
|
2011-04-29 12:38:12 +02:00
|
|
|
RtlCopySid (MAX_SID_LEN, psid, nsid);
|
2006-11-27 13:59:59 +01:00
|
|
|
well_known_sid = well_known;
|
2001-09-07 23:32:07 +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
|
|
|
return psid;
|
|
|
|
}
|
|
|
|
|
2001-04-25 11:43:25 +02:00
|
|
|
public:
|
2001-11-03 04:32:27 +01:00
|
|
|
inline operator const PSID () { return psid; }
|
2006-11-27 13:59:59 +01:00
|
|
|
inline bool is_well_known_sid () { return well_known_sid; }
|
2001-11-03 04:32:27 +01:00
|
|
|
|
2006-11-27 13:59:59 +01:00
|
|
|
/* Both, = and *= are assignment operators. = creates a "normal" SID,
|
|
|
|
*= marks the SID as being a well-known SID. This difference is
|
|
|
|
important when creating a SID list for LSA authentication. */
|
2001-11-03 04:32:27 +01:00
|
|
|
inline const PSID operator= (cygsid &nsid)
|
2006-11-27 13:59:59 +01:00
|
|
|
{ return assign (nsid, nsid.well_known_sid); }
|
2001-11-03 04:32:27 +01:00
|
|
|
inline const PSID operator= (const PSID nsid)
|
2006-11-27 13:59:59 +01:00
|
|
|
{ return assign (nsid, false); }
|
2001-11-03 04:32:27 +01:00
|
|
|
inline const PSID operator= (const char *nsidstr)
|
2006-11-27 13:59:59 +01:00
|
|
|
{ return getfromstr (nsidstr, false); }
|
|
|
|
inline const PSID operator*= (cygsid &nsid)
|
|
|
|
{ return assign (nsid, true); }
|
|
|
|
inline const PSID operator*= (const PSID nsid)
|
|
|
|
{ return assign (nsid, true); }
|
|
|
|
inline const PSID operator*= (const char *nsidstr)
|
|
|
|
{ return getfromstr (nsidstr, true); }
|
|
|
|
|
|
|
|
inline cygsid () : cygpsid ((PSID) sbuf), well_known_sid (false) {}
|
* 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
|
|
|
inline cygsid (const PSID nsid) { *this = nsid; }
|
|
|
|
inline cygsid (const char *nstrsid) { *this = nstrsid; }
|
2001-04-25 11:43:25 +02:00
|
|
|
|
|
|
|
inline PSID set () { return psid = (PSID) sbuf; }
|
|
|
|
|
2001-05-29 22:43:40 +02:00
|
|
|
BOOL getfrompw (const struct passwd *pw);
|
2013-04-23 11:44:36 +02:00
|
|
|
BOOL getfromgr (const struct group *gr);
|
2006-11-27 13:59:59 +01:00
|
|
|
|
|
|
|
void debug_print (const char *prefix = NULL) const
|
|
|
|
{
|
|
|
|
char buf[256] __attribute__ ((unused));
|
|
|
|
debug_printf ("%s %s%s", prefix ?: "", string (buf) ?: "NULL", well_known_sid ? " (*)" : " (+)");
|
|
|
|
}
|
* 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-09-11 12:37:11 +02:00
|
|
|
typedef enum { cygsidlist_empty, cygsidlist_alloc, cygsidlist_auto } cygsidlist_type;
|
* 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
|
|
|
class cygsidlist {
|
2006-11-27 13:59:59 +01:00
|
|
|
int maxcnt;
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
BOOL add (const PSID nsi, bool well_known); /* Only with auto for now */
|
|
|
|
|
* 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
|
|
|
public:
|
|
|
|
cygsid *sids;
|
2002-07-29 14:51:52 +02:00
|
|
|
cygsidlist_type type;
|
* 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-07-29 14:51:52 +02:00
|
|
|
cygsidlist (cygsidlist_type t, int m)
|
2006-11-27 13:59:59 +01:00
|
|
|
: maxcnt (m), cnt (0), type (t)
|
2002-07-29 14:51:52 +02:00
|
|
|
{
|
|
|
|
if (t == cygsidlist_alloc)
|
|
|
|
sids = alloc_sids (m);
|
|
|
|
else
|
|
|
|
sids = new cygsid [m];
|
|
|
|
}
|
|
|
|
~cygsidlist () { if (type == cygsidlist_auto) delete [] sids; }
|
* 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
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
BOOL addfromgr (struct group *gr) /* Only with alloc */
|
2006-11-27 13:59:59 +01:00
|
|
|
{ return sids[cnt].getfromgr (gr) && ++cnt; }
|
|
|
|
|
|
|
|
/* += adds a "normal" SID, *= adds a well-known SID. See comment in class
|
|
|
|
cygsid above. */
|
2012-05-29 15:01:50 +02:00
|
|
|
BOOL operator+= (cygsid &si) { return add ((PSID) si,
|
|
|
|
si.is_well_known_sid ()); }
|
2006-11-27 13:59:59 +01:00
|
|
|
BOOL operator+= (const char *sidstr) { cygsid nsi (sidstr);
|
2012-05-29 15:01:50 +02:00
|
|
|
return add ((PSID) nsi,
|
|
|
|
nsi.is_well_known_sid ());
|
|
|
|
}
|
2006-11-27 13:59:59 +01:00
|
|
|
BOOL operator+= (const PSID psid) { return add (psid, false); }
|
|
|
|
BOOL operator*= (cygsid &si) { return add ((PSID) si, true); }
|
|
|
|
BOOL operator*= (const char *sidstr) { cygsid nsi (sidstr);
|
2008-02-15 18:53:11 +01:00
|
|
|
return add ((PSID) nsi, true); }
|
2006-11-27 13:59:59 +01:00
|
|
|
BOOL operator*= (const PSID psid) { return add (psid, true); }
|
|
|
|
|
|
|
|
void count (int ncnt)
|
|
|
|
{ cnt = ncnt; }
|
|
|
|
int count () const { return cnt; }
|
|
|
|
int non_well_known_count () const
|
* 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
|
|
|
{
|
2006-11-27 13:59:59 +01:00
|
|
|
int wcnt = 0;
|
|
|
|
for (int i = 0; i < cnt; ++i)
|
2008-02-15 18:53:11 +01:00
|
|
|
if (!sids[i].is_well_known_sid ())
|
2006-11-27 13:59:59 +01:00
|
|
|
++wcnt;
|
|
|
|
return wcnt;
|
* 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-07-29 14:51:52 +02:00
|
|
|
int position (const PSID sid) const
|
* 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
|
|
|
{
|
2006-11-27 13:59:59 +01:00
|
|
|
for (int i = 0; i < cnt; ++i)
|
2001-09-07 23:32:07 +02:00
|
|
|
if (sids[i] == sid)
|
2002-07-29 14:51:52 +02:00
|
|
|
return i;
|
|
|
|
return -1;
|
* 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-07-29 14:51:52 +02:00
|
|
|
|
2006-11-27 13:59:59 +01:00
|
|
|
int next_non_well_known_sid (int idx)
|
|
|
|
{
|
|
|
|
while (++idx < cnt)
|
2008-02-15 18:53:11 +01:00
|
|
|
if (!sids[idx].is_well_known_sid ())
|
2006-11-27 13:59:59 +01:00
|
|
|
return idx;
|
|
|
|
return -1;
|
|
|
|
}
|
2002-07-29 14:51:52 +02:00
|
|
|
BOOL contains (const PSID sid) const { return position (sid) >= 0; }
|
|
|
|
cygsid *alloc_sids (int n);
|
|
|
|
void free_sids ();
|
* 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
|
|
|
void debug_print (const char *prefix = NULL) const
|
|
|
|
{
|
|
|
|
debug_printf ("-- begin sidlist ---");
|
2006-11-27 13:59:59 +01:00
|
|
|
if (!cnt)
|
2001-09-07 23:32:07 +02:00
|
|
|
debug_printf ("No elements");
|
2006-11-27 13:59:59 +01:00
|
|
|
for (int i = 0; i < cnt; ++i)
|
2001-09-07 23:32:07 +02:00
|
|
|
sids[i].debug_print (prefix);
|
* 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
|
|
|
debug_printf ("-- ende sidlist ---");
|
|
|
|
}
|
2001-04-25 11:43:25 +02:00
|
|
|
};
|
|
|
|
|
2003-11-26 14:23:27 +01:00
|
|
|
/* Wrapper class to allow simple deleting of buffer space allocated
|
|
|
|
by read_sd() */
|
|
|
|
class security_descriptor {
|
|
|
|
protected:
|
|
|
|
PSECURITY_DESCRIPTOR psd;
|
|
|
|
DWORD sd_size;
|
|
|
|
public:
|
2006-12-20 18:14:23 +01:00
|
|
|
security_descriptor () : psd (NULL), sd_size (0) {}
|
2003-11-26 14:23:27 +01:00
|
|
|
~security_descriptor () { free (); }
|
|
|
|
|
|
|
|
PSECURITY_DESCRIPTOR malloc (size_t nsize);
|
|
|
|
PSECURITY_DESCRIPTOR realloc (size_t nsize);
|
2005-07-05 05:16:46 +02:00
|
|
|
void free ();
|
2003-11-26 14:23:27 +01:00
|
|
|
|
2006-12-20 18:14:23 +01:00
|
|
|
inline DWORD size () const { return sd_size; }
|
|
|
|
inline DWORD copy (void *buf, DWORD buf_size) const {
|
2006-10-22 16:57:43 +02:00
|
|
|
if (buf_size < size ())
|
|
|
|
return sd_size;
|
|
|
|
memcpy (buf, psd, sd_size);
|
|
|
|
return 0;
|
|
|
|
}
|
2003-11-26 14:23:27 +01:00
|
|
|
inline operator const PSECURITY_DESCRIPTOR () { return psd; }
|
2006-10-22 16:57:43 +02:00
|
|
|
inline operator PSECURITY_DESCRIPTOR *() { return &psd; }
|
2009-10-30 20:58:53 +01:00
|
|
|
inline void operator =(PSECURITY_DESCRIPTOR nsd) { psd = nsd; }
|
2003-11-26 14:23:27 +01:00
|
|
|
};
|
|
|
|
|
2002-07-29 14:51:52 +02:00
|
|
|
class user_groups {
|
|
|
|
public:
|
|
|
|
cygsid pgsid;
|
|
|
|
cygsidlist sgsids;
|
|
|
|
BOOL ischanged;
|
|
|
|
|
|
|
|
BOOL issetgroups () const { return (sgsids.type == cygsidlist_alloc); }
|
|
|
|
void update_supp (const cygsidlist &newsids)
|
|
|
|
{
|
|
|
|
sgsids.free_sids ();
|
|
|
|
sgsids = newsids;
|
|
|
|
ischanged = TRUE;
|
|
|
|
}
|
2002-09-11 12:37:11 +02:00
|
|
|
void clear_supp ()
|
|
|
|
{
|
2003-02-04 15:58:04 +01:00
|
|
|
if (issetgroups ())
|
2003-03-09 21:31:07 +01:00
|
|
|
{
|
2003-02-04 15:58:04 +01:00
|
|
|
sgsids.free_sids ();
|
|
|
|
ischanged = TRUE;
|
|
|
|
}
|
2002-09-11 12:37:11 +02:00
|
|
|
}
|
2002-07-29 14:51:52 +02:00
|
|
|
void update_pgrp (const PSID sid)
|
|
|
|
{
|
|
|
|
pgsid = sid;
|
|
|
|
ischanged = TRUE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-02-05 18:23:19 +01:00
|
|
|
extern cygpsid well_known_null_sid;
|
|
|
|
extern cygpsid well_known_world_sid;
|
|
|
|
extern cygpsid well_known_local_sid;
|
2011-10-15 18:31:57 +02:00
|
|
|
extern cygpsid well_known_console_logon_sid;
|
2004-02-05 18:23:19 +01:00
|
|
|
extern cygpsid well_known_creator_owner_sid;
|
|
|
|
extern cygpsid well_known_creator_group_sid;
|
|
|
|
extern cygpsid well_known_dialup_sid;
|
|
|
|
extern cygpsid well_known_network_sid;
|
|
|
|
extern cygpsid well_known_batch_sid;
|
|
|
|
extern cygpsid well_known_interactive_sid;
|
|
|
|
extern cygpsid well_known_service_sid;
|
|
|
|
extern cygpsid well_known_authenticated_users_sid;
|
2006-11-08 12:38:05 +01:00
|
|
|
extern cygpsid well_known_this_org_sid;
|
2004-02-05 18:23:19 +01:00
|
|
|
extern cygpsid well_known_system_sid;
|
2010-02-12 18:40:42 +01:00
|
|
|
extern cygpsid well_known_builtin_sid;
|
2004-02-05 18:23:19 +01:00
|
|
|
extern cygpsid well_known_admins_sid;
|
2010-01-08 16:55:27 +01:00
|
|
|
extern cygpsid well_known_users_sid;
|
2008-04-22 12:45:34 +02:00
|
|
|
extern cygpsid mandatory_medium_integrity_sid;
|
|
|
|
extern cygpsid mandatory_high_integrity_sid;
|
|
|
|
extern cygpsid mandatory_system_integrity_sid;
|
2009-04-09 11:19:03 +02:00
|
|
|
extern cygpsid well_known_samba_unix_user_fake_sid;
|
* 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
|
|
|
|
2011-10-15 18:31:57 +02:00
|
|
|
bool privilege_luid (const PWCHAR pname, LUID &luid, bool &high_integrity);
|
2005-04-03 15:06:43 +02:00
|
|
|
|
2012-12-21 22:30:56 +01:00
|
|
|
extern inline BOOL
|
2011-04-04 11:00:02 +02:00
|
|
|
well_known_sid_type (SID_NAME_USE type)
|
|
|
|
{
|
|
|
|
return type == SidTypeAlias || type == SidTypeWellKnownGroup;
|
|
|
|
}
|
|
|
|
|
2012-12-21 22:30:56 +01:00
|
|
|
extern inline BOOL
|
* 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
|
|
|
legal_sid_type (SID_NAME_USE type)
|
|
|
|
{
|
|
|
|
return type == SidTypeUser || type == SidTypeGroup
|
|
|
|
|| type == SidTypeAlias || type == SidTypeWellKnownGroup;
|
|
|
|
}
|
* 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
|
|
|
|
2009-01-03 06:12:22 +01:00
|
|
|
class path_conv;
|
2000-09-08 04:56:55 +02:00
|
|
|
/* File manipulation */
|
2013-01-21 05:34:52 +01:00
|
|
|
int __reg3 get_file_attribute (HANDLE, path_conv &, mode_t *,
|
2013-04-23 11:44:36 +02:00
|
|
|
uid_t *, gid_t *);
|
2013-01-21 05:34:52 +01:00
|
|
|
int __reg3 set_file_attribute (HANDLE, path_conv &,
|
2013-04-23 11:44:36 +02:00
|
|
|
uid_t, gid_t, mode_t);
|
2013-01-21 05:34:52 +01:00
|
|
|
int __reg2 get_object_sd (HANDLE, security_descriptor &);
|
2013-04-23 11:44:36 +02:00
|
|
|
int __reg3 get_object_attribute (HANDLE, uid_t *, gid_t *, mode_t *);
|
|
|
|
int __reg3 set_object_attribute (HANDLE, uid_t, gid_t, mode_t);
|
|
|
|
int __reg3 create_object_sd_from_attribute (HANDLE, uid_t, gid_t,
|
2013-01-21 05:34:52 +01:00
|
|
|
mode_t, security_descriptor &);
|
|
|
|
int __reg3 set_object_sd (HANDLE, security_descriptor &, bool);
|
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
int __reg3 get_reg_attribute (HKEY hkey, mode_t *, uid_t *, gid_t *);
|
2013-01-21 05:34:52 +01:00
|
|
|
LONG __reg3 get_file_sd (HANDLE fh, path_conv &, security_descriptor &, bool);
|
|
|
|
LONG __reg3 set_file_sd (HANDLE fh, path_conv &, security_descriptor &, bool);
|
|
|
|
bool __reg3 add_access_allowed_ace (PACL, int, DWORD, PSID, size_t &, DWORD);
|
|
|
|
bool __reg3 add_access_denied_ace (PACL, int, DWORD, PSID, size_t &, DWORD);
|
|
|
|
int __reg3 check_file_access (path_conv &, int, bool);
|
|
|
|
int __reg3 check_registry_access (HANDLE, int, bool);
|
2001-04-20 15:02:32 +02:00
|
|
|
|
2008-08-14 16:05:04 +02:00
|
|
|
void set_security_attribute (path_conv &pc, int attribute,
|
|
|
|
PSECURITY_ATTRIBUTES psa,
|
2003-11-26 14:23:27 +01:00
|
|
|
security_descriptor &sd_buf);
|
2001-08-07 17:09:54 +02:00
|
|
|
|
2013-04-23 11:44:36 +02:00
|
|
|
bool get_sids_info (cygpsid, cygpsid, uid_t * , gid_t *);
|
2003-02-04 15:58:04 +01:00
|
|
|
|
2004-04-14 18:36:26 +02:00
|
|
|
/* sec_acl.cc */
|
2013-04-23 11:44:36 +02:00
|
|
|
struct acl;
|
|
|
|
extern "C" int aclsort32 (int, int, struct acl *);
|
|
|
|
extern "C" int acl32 (const char *, int, int, struct acl *);
|
|
|
|
int getacl (HANDLE, path_conv &, int, struct acl *);
|
|
|
|
int setacl (HANDLE, path_conv &, int, struct acl *, bool &);
|
2004-04-14 18:36:26 +02:00
|
|
|
|
2009-10-13 12:23:31 +02:00
|
|
|
/* Set impersonation or restricted token. */
|
|
|
|
void set_imp_token (HANDLE token, int type);
|
2006-11-27 13:59:59 +01:00
|
|
|
/* Function creating a token by calling NtCreateToken. */
|
2006-12-12 20:18:56 +01:00
|
|
|
HANDLE create_token (cygsid &usersid, user_groups &groups, struct passwd * pw);
|
2006-11-27 13:59:59 +01:00
|
|
|
/* LSA authentication function. */
|
|
|
|
HANDLE lsaauth (cygsid &, user_groups &, struct passwd *);
|
2008-11-26 11:18:10 +01:00
|
|
|
/* LSA private key storage authentication, same as when using service logons. */
|
|
|
|
HANDLE lsaprivkeyauth (struct passwd *pw);
|
2002-05-16 11:30:48 +02:00
|
|
|
/* Verify an existing token */
|
2003-12-07 23:37:12 +01:00
|
|
|
bool verify_token (HANDLE token, cygsid &usersid, user_groups &groups, bool *pintern = NULL);
|
2005-04-16 17:21:47 +02:00
|
|
|
/* Get groups of a user */
|
|
|
|
bool get_server_groups (cygsidlist &grp_list, PSID usersid, struct passwd *pw);
|
* 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
|
|
|
|
|
|
|
/* Extract U-domain\user field from passwd entry. */
|
2008-07-30 14:10:20 +02:00
|
|
|
void extract_nt_dom_user (const struct passwd *pw, PWCHAR domain, PWCHAR user);
|
2002-06-03 19:04:03 +02:00
|
|
|
/* Get default logonserver for a domain. */
|
2008-07-09 13:58:38 +02:00
|
|
|
bool get_logon_server (PWCHAR domain, PWCHAR wserver, bool rediscovery);
|
2001-04-20 15:02:32 +02:00
|
|
|
|
2008-11-26 11:18:10 +01:00
|
|
|
HANDLE open_local_policy (ACCESS_MASK access);
|
|
|
|
|
2001-04-20 15:02:32 +02:00
|
|
|
/* sec_helper.cc: Security helper functions. */
|
2007-07-19 10:33:22 +02:00
|
|
|
int set_privilege (HANDLE token, DWORD privilege, bool enable);
|
2005-04-03 15:06:43 +02:00
|
|
|
void set_cygwin_privileges (HANDLE token);
|
|
|
|
|
|
|
|
#define _push_thread_privilege(_priv, _val, _check) { \
|
2007-02-23 16:15:50 +01:00
|
|
|
HANDLE _dup_token = NULL; \
|
|
|
|
HANDLE _token = (cygheap->user.issetuid () && (_check)) \
|
2007-07-16 22:01:15 +02:00
|
|
|
? cygheap->user.primary_token () : hProcToken; \
|
2007-02-23 16:15:50 +01:00
|
|
|
if (!DuplicateTokenEx (_token, MAXIMUM_ALLOWED, NULL, \
|
|
|
|
SecurityImpersonation, TokenImpersonation, \
|
|
|
|
&_dup_token)) \
|
|
|
|
debug_printf ("DuplicateTokenEx: %E"); \
|
|
|
|
else if (!ImpersonateLoggedOnUser (_dup_token)) \
|
|
|
|
debug_printf ("ImpersonateLoggedOnUser: %E"); \
|
|
|
|
else \
|
2007-07-19 10:33:22 +02:00
|
|
|
set_privilege (_dup_token, (_priv), (_val));
|
2007-02-23 16:15:50 +01:00
|
|
|
|
2005-04-03 15:06:43 +02:00
|
|
|
#define push_thread_privilege(_priv, _val) _push_thread_privilege(_priv,_val,1)
|
|
|
|
#define push_self_privilege(_priv, _val) _push_thread_privilege(_priv,_val,0)
|
|
|
|
|
|
|
|
#define pop_thread_privilege() \
|
|
|
|
if (_dup_token) \
|
|
|
|
{ \
|
2007-01-24 13:14:54 +01:00
|
|
|
if (!cygheap->user.issetuid ()) \
|
2006-12-12 17:27:32 +01:00
|
|
|
RevertToSelf (); \
|
|
|
|
else \
|
2007-01-24 13:14:54 +01:00
|
|
|
cygheap->user.reimpersonate (); \
|
2005-04-03 15:06:43 +02:00
|
|
|
CloseHandle (_dup_token); \
|
|
|
|
} \
|
|
|
|
}
|
2007-02-23 16:15:50 +01:00
|
|
|
|
2005-04-03 15:06:43 +02:00
|
|
|
#define pop_self_privilege() pop_thread_privilege()
|
2000-09-08 04:56:55 +02:00
|
|
|
|
2001-04-20 15:02:32 +02:00
|
|
|
/* shared.cc: */
|
|
|
|
|
2000-09-08 04:56:55 +02:00
|
|
|
/* Various types of security attributes for use in Create* functions. */
|
|
|
|
extern SECURITY_ATTRIBUTES sec_none, sec_none_nih, sec_all, sec_all_nih;
|
2013-01-21 05:34:52 +01:00
|
|
|
extern SECURITY_ATTRIBUTES *__reg3 __sec_user (PVOID, PSID, PSID,
|
|
|
|
DWORD, BOOL);
|
2012-06-03 18:46:53 +02:00
|
|
|
|
|
|
|
extern PSECURITY_DESCRIPTOR _recycler_sd (void *buf, bool users, bool dir);
|
|
|
|
#define recycler_sd(users,dir) \
|
|
|
|
(_recycler_sd (alloca (sizeof (SECURITY_DESCRIPTOR) + MAX_DACL_LEN (3)), \
|
|
|
|
(users), \
|
|
|
|
(dir)))
|
|
|
|
|
2008-04-18 22:13:37 +02:00
|
|
|
extern PSECURITY_DESCRIPTOR _everyone_sd (void *buf, ACCESS_MASK access);
|
|
|
|
#define everyone_sd(access) (_everyone_sd (alloca (SD_MIN_SIZE), (access)))
|
|
|
|
|
2010-01-14 19:46:02 +01:00
|
|
|
#define sec_none_cloexec(f) (((f) & O_CLOEXEC ? &sec_none_nih : &sec_none))
|
|
|
|
|
2005-02-13 19:17:29 +01:00
|
|
|
extern bool sec_acl (PACL acl, bool original, bool admins, PSID sid1 = NO_SID,
|
2003-09-16 02:45:50 +02:00
|
|
|
PSID sid2 = NO_SID, DWORD access2 = 0);
|
2000-09-08 04:56:55 +02:00
|
|
|
|
2013-01-21 05:34:52 +01:00
|
|
|
ssize_t __reg3 read_ea (HANDLE, path_conv &, const char *,
|
|
|
|
char *, size_t);
|
|
|
|
int __reg3 write_ea (HANDLE, path_conv &, const char *, const char *,
|
|
|
|
size_t, int);
|
2002-02-19 06:58:44 +01:00
|
|
|
|
2006-03-30 18:08:50 +02:00
|
|
|
/* Note: sid1 is usually (read: currently always) the current user's
|
|
|
|
effective sid (cygheap->user.sid ()). */
|
2002-02-19 06:58:44 +01:00
|
|
|
extern inline SECURITY_ATTRIBUTES *
|
2006-03-30 18:08:50 +02:00
|
|
|
sec_user_nih (SECURITY_ATTRIBUTES *sa_buf, PSID sid1, PSID sid2 = NULL,
|
2005-06-07 21:31:42 +02:00
|
|
|
DWORD access2 = 0)
|
2002-02-19 06:58:44 +01:00
|
|
|
{
|
2003-09-16 02:45:50 +02:00
|
|
|
return __sec_user (sa_buf, sid1, sid2, access2, FALSE);
|
2002-02-19 06:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extern inline SECURITY_ATTRIBUTES *
|
2006-03-30 18:08:50 +02:00
|
|
|
sec_user (SECURITY_ATTRIBUTES *sa_buf, PSID sid1, PSID sid2 = NULL,
|
2005-06-07 21:31:42 +02:00
|
|
|
DWORD access2 = 0)
|
2002-02-19 06:58:44 +01:00
|
|
|
{
|
2003-09-16 02:45:50 +02:00
|
|
|
return __sec_user (sa_buf, sid1, sid2, access2, TRUE);
|
2002-02-19 06:58:44 +01:00
|
|
|
}
|