70e476d27b
* include/cygwin/version.h: Bump DLL version to 1.7.0. 2006-07-25 Corinna Vinschen <corinna@vinschen.de> * select.h: Remove. * fhandler_socket.cc: Don't include select.h. * select.cc: Ditto. 2006-07-25 Corinna Vinschen <corinna@vinschen.de> * cygtls.h: Drop socket related includes. (struct _local_storage): Remove exitsock and exitsock_sin. Add select_sockevt. * cygtls.cc: Accomodate above change throughout. * fhandler.h (class fhandler_socket): Make wsock_evt public. * fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate reordering members. (fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as it gets read once. Never remove FD_WRITE event here. (fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for socket events. (fhandler_socket::accept): Fix conditional. Set wsock_events members of accepted socket to useful start values. (fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from wsock_events after the call to WSARecvFrom. (fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value condition. * select.cc (struct socketinf): Change to accomodate using socket event handling. (peek_socket): Use event handling for peeking socket. (thread_socket): Ditto. (start_thread_socket): Ditto. (socket_cleanup): Same here. * tlsoffsets.h: Regenerate. 2006-07-20 Corinna Vinschen <corinna@vinschen.de> * fhandler.h (class fhandler_socket): Rearrange slightly to keep event handling methods and members together. Drop owner status flag. Split wait method. Rename event handling methods for readability. * fhandler_socket.cc (struct wsa_event): Add owner field. (LOCK_EVENTS): New macro. (UNLOCK_EVENTS): Ditto. (fhandler_socket::init_events): rename from prepare. (fhandler_socket::evaluate_events): First half of former wait method. Do everything but wait. Allow specifiying whether or not events from event_mask should be erased from wsock_events->events. Simplify OOB handling. Allow sending SIGURG to any process (group). (fhandler_socket::wait_for_events): Second half of former wait method. Call evaluate_events and wait in a loop if socket is blocking. (fhandler_socket::release_events): Rename from release. (fhandler_socket::connect): Accomodate above name changes. (fhandler_socket::accept): Ditto. (fhandler_socket::recv_internal): Ditto. (fhandler_socket::send_internal): Ditto. (fhandler_socket::close): Ditto. (fhandler_socket::fcntl): Always set owner to given input value on F_SETOWN. Handle F_GETOWN. * net.cc (fdsock): Accomodate above name changes. 2006-07-20 Corinna Vinschen <corinna@vinschen.de> * fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to WSAEWOULDBLOCK instead of WSAEINPROGRESS. 2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com> Corinna Vinschen <corinna@vinschen.de> * winsup.h (mmap_region_status): New enum. (mmap_is_attached_or_noreserve_page): Adjust prototype and rename as below. * mmap.cc (mmap_is_attached_or_noreserve_page): Rename mmap_is_attached_or_noreserve. Add region length parameter. Return enum above. * exceptions.cc (_cygtls::handle_exceptions): Accomodate above. * fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS errors and retry on success to allow reads into untouched MAP_NORESERVE buffers. 2006-07-18 Corinna Vinschen <corinna@vinschen.de> * cygwin.din (posix_openpt): Export. * tty.cc (posix_openpt): New function. * include/cygwin/stdlib.h (posix_openpt): Declare. * include/cygwin/version.h: Bump API minor number. 2006-07-14 Corinna Vinschen <corinna@vinschen.de> * security.cc (get_token_group_sidlist): Always add the interactive group to the token. Add comment. Create logon_id group SID by copying it from incoming group list. (create_token): Add subauth_token parameter. Use information in subauth_token if present. Tweak SourceIdentifier if subauth_token is present for debugging purposes. * security.h (create_token): Add subauth_token parameter in declaration. * syscalls.cc (seteuid32): Call subauth first. Call create_token regardless. Use subauth token in call to create_token if subauth succeeded. 2006-07-13 Corinna Vinschen <corinna@vinschen.de> * include/netinet/in.h: Update copyright. 2006-07-13 Corinna Vinschen <corinna@vinschen.de> * fhandler_socket.cc (fhandler_socket::wait): Rework function so that WaitForMultipleObjects is really only called when necessary. 2006-07-12 Corinna Vinschen <corinna@vinschen.de> * include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport, rresvport_af, iruserok, iruserok_sa, ruserok. 2006-07-12 Corinna Vinschen <corinna@vinschen.de> * Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o. * autoload.cc (rcmd): Drop definition. * cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa, rcmd_af, rresvport_af. * net.cc (cygwin_rcmd): Remove. (last_used_bindresvport): Rename from last_used_rrecvport. (cygwin_bindresvport_sa): New function implementing bindresvport_sa. (cygwin_bindresvport): New function implementing bindresvport. (cygwin_rresvport): Remove. * include/cygwin/version.h: Bump API minor number. * include/netinet/in.h: Declare bindresvport and bindresvport_sa. * libc/iruserok.c: Remove file. * libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport, rresvport_af, iruserok_sa, iruserok and ruserok. 2006-07-12 Corinna Vinschen <corinna@vinschen.de> * fhandler_socket.cc (fhandler_socket::getsockname): Return valid result for unbound sockets. 2006-07-11 Corinna Vinschen <corinna@vinschen.de> * fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly. (fhandler_socket::fixup_after_exec): Drop misguided attempt to handle close_on_exec here. (fhandler_socket::dup): Call fixup_after_fork with NULL parent. Add comment. (fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt. 2006-07-10 Corinna Vinschen <corinna@vinschen.de> * fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt and wsock_events members. Remove closed status flag, add listener status flag. Accomodate new implementation of socket event handling methods. Declare recv* and send* functions ssize_t as the POSIX equivalents. (fhandler_socket::recv_internal): Declare. (fhandler_socket::send_internal): Ditto. * fhandler_socket.cc (EVENT_MASK): Define mask of selected events. (fhandler_socket::fhandler_socket): Initialize new members. (fhandler_socket::af_local_setblocking): Don't actually set the socket to blocking mode. Keep sane event selection. (fhandler_socket::af_local_unsetblocking): Don't actually set the socket to previous blocking setting, just remember it. (struct wsa_event): New structure to keep event data per shared socket. (NUM_SOCKS): Define number of shared sockets concurrently handled by all active Cygwin processes. (wsa_events): New shared datastructure keeping all wsa_event records. (socket_serial_number): New shared variable to identify shared sockets. (wsa_slot_mtx): Global mutex to serialize wsa_events access. (search_wsa_event_slot): New static function to select a new wsa_event slot for a new socket. (fhandler_socket::prepare): Rewrite. Prepare event selection per new socket. (fhandler_socket::wait): Rewrite. Wait for socket events in thread safe and multiple process safe. (fhandler_socket::release): Rewrite. Close per-socket descriptor mutex handle and event handle. (fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix copy-paste error in debug output. (fhandler_socket::connect): Accomodate new event handling. (fhandler_socket::listen): Set listener flag on successful listen. (fhandler_socket::accept): Accomodate new event handling. (fhandler_socket::recv_internal): New inline method centralizing common recv code. (fhandler_socket::recvfrom): Call recv_internal now. (fhandler_socket::recvmsg): Ditto. Streamline copying from iovec to WSABUF. (fhandler_socket::send_internal): New inline method centralizing common send code. (fhandler_socket::sendto): Call send_internal now. (fhandler_socket::sendmsg): Ditto. Streamline copying from iovec to WSABUF. (fhandler_socket::close): Call release now. (fhandler_socket::ioctl): Never actually switch to blocking mode. Just keep track of the setting. * net.cc (fdsock): Call prepare now. (cygwin_connect): Revert again to event driven technique. (cygwin_accept): Ditto. * poll.cc (poll): Don't call recvfrom on a listening socket. Remove special case for failing recvfrom. * include/sys/socket.h: Declare recv* and send* functions ssize_t as requested by POSIX. 2006-07-07 Corinna Vinschen <corinna@vinschen.de> * net.cc (cygwin_inet_ntop): Fix data type of forth parameter. 2006-07-06 Corinna Vinschen <corinna@vinschen.de> * include/cygwin/in6.h (struct in6_addr): Fix typo. 2006-07-06 Corinna Vinschen <corinna@vinschen.de> * cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo, gai_strerror, getaddrinfo, getnameinfo. * fhandler_socket.cc: Include cygwin/in6.h. (get_inet_addr): Accomodate AF_INET6 usage. (fhandler_socket::connect): Ditto. (fhandler_socket::listen): Ditto. (fhandler_socket::sendto): Ditto. * net.cc: Include cygwin/in6.h. (in6addr_any): Define. (in6addr_loopback): Define. (cygwin_socket): Accomodate AF_INET6 usage. (socketpair): Bind socketpairs only to loopback for security. (inet_pton4): New static function. (inet_pton6): Ditto. (cygwin_inet_pton): New AF_INET6 aware inet_pton implementation. (inet_ntop4): New static function. (inet_ntop6): Ditto. (cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation. (ga_aistruct): New static function. (ga_clone): Ditto. (ga_echeck): Ditto. (ga_nsearch): Ditto. (ga_port): Ditto. (ga_serv): Ditto. (ga_unix): Ditto. (gn_ipv46): Ditto. (ipv4_freeaddrinfo): Ditto. (ipv4_getaddrinfo): Ditto. (ipv4_getnameinfo): Ditto. (gai_errmap_t): New structure holding error code - error string mapping. (cygwin_gai_strerror): New function implementing gai_strerror. (w32_to_gai_err): New static function. (get_ipv6_funcs): Ditto. (load_ipv6_funcs): Ditto. (cygwin_freeaddrinfo): New function implementing freeaddrinfo. (cygwin_getaddrinfo): New function implementing getaddrinfo. (cygwin_getnameinfo): New function implementing getnameinfo. * include/netdb.h: Include stdint.h and cygwin/socket.h. Define data types and macros used by getaddrinfo and friends. Declare freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo. * include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition of struct sockaddr_in6. Include cygwin/in6.h instead. * include/cygwin/in6.h: New header file defining IPv6 releated data types and macros. * include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add IPv6 related socket options. * include/cygwin/version.h: Bump API minor number. 2006-07-06 Corinna Vinschen <corinna@vinschen.de> * autoload.cc (DsGetDcNameA): Define. (NetGetAnyDCName): Define. * security.cc: Include dsgetdc.h. (DsGetDcNameA): Declare. (DS_FORCE_REDISCOVERY): Define. (get_logon_server): Add bool parameter to control rediscovery of DC. Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName otherwise. (get_server_groups): Rediscover DC if get_user_groups fails and try again. (get_reg_security): Use correct error code macro when testing RegGetKeySecurity return value. * security.h (get_logon_server): Remove default vaue from wserver parameter. Add rediscovery parameter. * uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter in call to get_logon_server.
404 lines
12 KiB
C++
404 lines
12 KiB
C++
/* security.h: security declarations
|
|
|
|
Copyright 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
|
|
|
|
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. */
|
|
|
|
#ifndef _SECURITY_H
|
|
#define _SECURITY_H
|
|
|
|
#include <accctrl.h>
|
|
|
|
#define DEFAULT_UID DOMAIN_USER_RID_ADMIN
|
|
#define UNKNOWN_UID 400 /* Non conflicting number */
|
|
#define UNKNOWN_GID 401
|
|
|
|
#define MAX_SID_LEN 40
|
|
#define MAX_DACL_LEN(n) (sizeof (ACL) \
|
|
+ (n) * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD) + MAX_SID_LEN))
|
|
#define ACL_DEFAULT_SIZE 3072
|
|
#define NO_SID ((PSID)NULL)
|
|
|
|
/* Macro to define variable length SID structures */
|
|
#define SID(name, comment, authority, count, rid...) \
|
|
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;
|
|
|
|
#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)
|
|
|
|
class cygpsid {
|
|
protected:
|
|
PSID psid;
|
|
public:
|
|
cygpsid () {}
|
|
cygpsid (PSID nsid) { psid = nsid; }
|
|
operator const PSID () { return psid; }
|
|
const PSID operator= (PSID nsid) { return psid = nsid;}
|
|
__uid32_t get_id (BOOL search_grp, int *type = NULL);
|
|
int get_uid () { return get_id (FALSE); }
|
|
int get_gid () { return get_id (TRUE); }
|
|
|
|
char *string (char *nsidstr) const;
|
|
|
|
bool operator== (const PSID nsid) const
|
|
{
|
|
if (!psid || !nsid)
|
|
return nsid == psid;
|
|
return EqualSid (psid, nsid);
|
|
}
|
|
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
|
|
{
|
|
char buf[256] __attribute__ ((unused));
|
|
debug_printf ("%s %s", prefix ?: "", string (buf) ?: "NULL");
|
|
}
|
|
};
|
|
|
|
class cygsid : public cygpsid {
|
|
char sbuf[MAX_SID_LEN];
|
|
|
|
const PSID getfromstr (const char *nsidstr);
|
|
PSID get_sid (DWORD s, DWORD cnt, DWORD *r);
|
|
|
|
inline const PSID assign (const PSID nsid)
|
|
{
|
|
if (!nsid)
|
|
psid = NO_SID;
|
|
else
|
|
{
|
|
psid = (PSID) sbuf;
|
|
CopySid (MAX_SID_LEN, psid, nsid);
|
|
}
|
|
return psid;
|
|
}
|
|
|
|
public:
|
|
inline operator const PSID () { return psid; }
|
|
|
|
inline const PSID operator= (cygsid &nsid)
|
|
{ return assign (nsid); }
|
|
inline const PSID operator= (const PSID nsid)
|
|
{ return assign (nsid); }
|
|
inline const PSID operator= (const char *nsidstr)
|
|
{ return getfromstr (nsidstr); }
|
|
|
|
inline cygsid () : cygpsid ((PSID) sbuf) {}
|
|
inline cygsid (const PSID nsid) { *this = nsid; }
|
|
inline cygsid (const char *nstrsid) { *this = nstrsid; }
|
|
|
|
inline PSID set () { return psid = (PSID) sbuf; }
|
|
|
|
BOOL getfrompw (const struct passwd *pw);
|
|
BOOL getfromgr (const struct __group32 *gr);
|
|
};
|
|
|
|
typedef enum { cygsidlist_empty, cygsidlist_alloc, cygsidlist_auto } cygsidlist_type;
|
|
class cygsidlist {
|
|
int maxcount;
|
|
public:
|
|
int count;
|
|
cygsid *sids;
|
|
cygsidlist_type type;
|
|
|
|
cygsidlist (cygsidlist_type t, int m)
|
|
{
|
|
type = t;
|
|
count = 0;
|
|
maxcount = m;
|
|
if (t == cygsidlist_alloc)
|
|
sids = alloc_sids (m);
|
|
else
|
|
sids = new cygsid [m];
|
|
}
|
|
~cygsidlist () { if (type == cygsidlist_auto) delete [] sids; }
|
|
|
|
BOOL add (const PSID nsi) /* Only with auto for now */
|
|
{
|
|
if (count >= maxcount)
|
|
{
|
|
cygsid *tmp = new cygsid [ 2 * maxcount];
|
|
if (!tmp)
|
|
return FALSE;
|
|
maxcount *= 2;
|
|
for (int i = 0; i < count; ++i)
|
|
tmp[i] = sids[i];
|
|
delete [] sids;
|
|
sids = tmp;
|
|
}
|
|
sids[count++] = nsi;
|
|
return TRUE;
|
|
}
|
|
BOOL add (cygsid &nsi) { return add ((PSID) nsi); }
|
|
BOOL add (const char *sidstr)
|
|
{ cygsid nsi (sidstr); return add (nsi); }
|
|
BOOL addfromgr (struct __group32 *gr) /* Only with alloc */
|
|
{ return sids[count].getfromgr (gr) && ++count; }
|
|
|
|
BOOL operator+= (cygsid &si) { return add (si); }
|
|
BOOL operator+= (const char *sidstr) { return add (sidstr); }
|
|
BOOL operator+= (const PSID psid) { return add (psid); }
|
|
|
|
int position (const PSID sid) const
|
|
{
|
|
for (int i = 0; i < count; ++i)
|
|
if (sids[i] == sid)
|
|
return i;
|
|
return -1;
|
|
}
|
|
|
|
BOOL contains (const PSID sid) const { return position (sid) >= 0; }
|
|
cygsid *alloc_sids (int n);
|
|
void free_sids ();
|
|
void debug_print (const char *prefix = NULL) const
|
|
{
|
|
debug_printf ("-- begin sidlist ---");
|
|
if (!count)
|
|
debug_printf ("No elements");
|
|
for (int i = 0; i < count; ++i)
|
|
sids[i].debug_print (prefix);
|
|
debug_printf ("-- ende sidlist ---");
|
|
}
|
|
};
|
|
|
|
/* Wrapper class to allow simple deleting of buffer space allocated
|
|
by read_sd() */
|
|
class security_descriptor {
|
|
protected:
|
|
PSECURITY_DESCRIPTOR psd;
|
|
DWORD sd_size;
|
|
public:
|
|
security_descriptor () : psd (NULL), sd_size (0) {}
|
|
~security_descriptor () { free (); }
|
|
|
|
PSECURITY_DESCRIPTOR malloc (size_t nsize);
|
|
PSECURITY_DESCRIPTOR realloc (size_t nsize);
|
|
void free ();
|
|
|
|
inline DWORD size () const { return sd_size; }
|
|
inline operator const PSECURITY_DESCRIPTOR () { return psd; }
|
|
};
|
|
|
|
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;
|
|
}
|
|
void clear_supp ()
|
|
{
|
|
if (issetgroups ())
|
|
{
|
|
sgsids.free_sids ();
|
|
ischanged = TRUE;
|
|
}
|
|
}
|
|
void update_pgrp (const PSID sid)
|
|
{
|
|
pgsid = sid;
|
|
ischanged = TRUE;
|
|
}
|
|
};
|
|
|
|
extern cygpsid well_known_null_sid;
|
|
extern cygpsid well_known_world_sid;
|
|
extern cygpsid well_known_local_sid;
|
|
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;
|
|
extern cygpsid well_known_system_sid;
|
|
extern cygpsid well_known_admins_sid;
|
|
|
|
/* Order must be same as cygpriv in sec_helper.cc. */
|
|
enum cygpriv_idx {
|
|
SE_CREATE_TOKEN_PRIV = 0,
|
|
SE_ASSIGNPRIMARYTOKEN_PRIV,
|
|
SE_LOCK_MEMORY_PRIV,
|
|
SE_INCREASE_QUOTA_PRIV,
|
|
SE_UNSOLICITED_INPUT_PRIV,
|
|
SE_MACHINE_ACCOUNT_PRIV,
|
|
SE_TCB_PRIV,
|
|
SE_SECURITY_PRIV,
|
|
SE_TAKE_OWNERSHIP_PRIV,
|
|
SE_LOAD_DRIVER_PRIV,
|
|
SE_SYSTEM_PROFILE_PRIV,
|
|
SE_SYSTEMTIME_PRIV,
|
|
SE_PROF_SINGLE_PROCESS_PRIV,
|
|
SE_INC_BASE_PRIORITY_PRIV,
|
|
SE_CREATE_PAGEFILE_PRIV,
|
|
SE_CREATE_PERMANENT_PRIV,
|
|
SE_BACKUP_PRIV,
|
|
SE_RESTORE_PRIV,
|
|
SE_SHUTDOWN_PRIV,
|
|
SE_DEBUG_PRIV,
|
|
SE_AUDIT_PRIV,
|
|
SE_SYSTEM_ENVIRONMENT_PRIV,
|
|
SE_CHANGE_NOTIFY_PRIV,
|
|
SE_REMOTE_SHUTDOWN_PRIV,
|
|
SE_CREATE_GLOBAL_PRIV,
|
|
SE_UNDOCK_PRIV,
|
|
SE_MANAGE_VOLUME_PRIV,
|
|
SE_IMPERSONATE_PRIV,
|
|
SE_ENABLE_DELEGATION_PRIV,
|
|
SE_SYNC_AGENT_PRIV,
|
|
|
|
SE_NUM_PRIVS
|
|
};
|
|
|
|
const LUID *privilege_luid (enum cygpriv_idx idx);
|
|
const LUID *privilege_luid_by_name (const char *pname);
|
|
const char *privilege_name (enum cygpriv_idx idx);
|
|
|
|
inline BOOL
|
|
legal_sid_type (SID_NAME_USE type)
|
|
{
|
|
return type == SidTypeUser || type == SidTypeGroup
|
|
|| type == SidTypeAlias || type == SidTypeWellKnownGroup;
|
|
}
|
|
|
|
extern bool allow_ntea;
|
|
extern bool allow_ntsec;
|
|
extern bool allow_smbntsec;
|
|
extern bool allow_traverse;
|
|
|
|
/* File manipulation */
|
|
int __stdcall get_file_attribute (int, HANDLE, const char *, mode_t *,
|
|
__uid32_t * = NULL, __gid32_t * = NULL);
|
|
int __stdcall set_file_attribute (bool, HANDLE, const char *, int);
|
|
int __stdcall set_file_attribute (bool, HANDLE, const char *, __uid32_t, __gid32_t, int);
|
|
int __stdcall get_nt_object_security (HANDLE, SE_OBJECT_TYPE,
|
|
security_descriptor &);
|
|
int __stdcall get_object_attribute (HANDLE handle, SE_OBJECT_TYPE object_type, mode_t *,
|
|
__uid32_t * = NULL, __gid32_t * = NULL);
|
|
LONG __stdcall read_sd (const char *file, security_descriptor &sd);
|
|
LONG __stdcall write_sd (HANDLE fh, const char *file, security_descriptor &sd);
|
|
bool __stdcall add_access_allowed_ace (PACL acl, int offset, DWORD attributes, PSID sid, size_t &len_add, DWORD inherit);
|
|
bool __stdcall add_access_denied_ace (PACL acl, int offset, DWORD attributes, PSID sid, size_t &len_add, DWORD inherit);
|
|
int __stdcall check_file_access (const char *, int);
|
|
|
|
void set_security_attribute (int attribute, PSECURITY_ATTRIBUTES psa,
|
|
security_descriptor &sd_buf);
|
|
|
|
bool get_sids_info (cygpsid, cygpsid, __uid32_t * , __gid32_t *);
|
|
|
|
/* sec_acl.cc */
|
|
struct __acl32;
|
|
extern "C" int aclsort32 (int, int, __acl32 *);
|
|
extern "C" int acl32 (const char *, int, int, __acl32 *);
|
|
int getacl (HANDLE, const char *, DWORD, int, __acl32 *);
|
|
int setacl (HANDLE, const char *, int, __acl32 *);
|
|
|
|
struct _UNICODE_STRING;
|
|
void __stdcall str2buf2uni (_UNICODE_STRING &, WCHAR *, const char *) __attribute__ ((regparm (3)));
|
|
void __stdcall str2uni_cat (_UNICODE_STRING &, const char *) __attribute__ ((regparm (2)));
|
|
|
|
/* Try a subauthentication. */
|
|
HANDLE subauth (struct passwd *pw);
|
|
/* Try creating a token directly. */
|
|
HANDLE create_token (cygsid &usersid, user_groups &groups, struct passwd * pw,
|
|
HANDLE subauth_token);
|
|
/* Verify an existing token */
|
|
bool verify_token (HANDLE token, cygsid &usersid, user_groups &groups, bool *pintern = NULL);
|
|
/* Get groups of a user */
|
|
bool get_server_groups (cygsidlist &grp_list, PSID usersid, struct passwd *pw);
|
|
|
|
/* Extract U-domain\user field from passwd entry. */
|
|
void extract_nt_dom_user (const struct passwd *pw, char *domain, char *user);
|
|
/* Get default logonserver for a domain. */
|
|
bool get_logon_server (const char * domain, char * server, WCHAR *wserver,
|
|
bool rediscovery);
|
|
|
|
/* sec_helper.cc: Security helper functions. */
|
|
int set_privilege (HANDLE token, enum cygpriv_idx privilege, bool enable);
|
|
void set_cygwin_privileges (HANDLE token);
|
|
|
|
#define set_process_privilege(p,v) set_privilege (hProcImpToken, (p), (v))
|
|
|
|
#define _push_thread_privilege(_priv, _val, _check) { \
|
|
HANDLE _token = NULL, _dup_token = NULL; \
|
|
if (wincap.has_security ()) \
|
|
{ \
|
|
_token = (cygheap->user.issetuid () && (_check)) \
|
|
? cygheap->user.token () : hProcImpToken; \
|
|
if (!DuplicateTokenEx (_token, MAXIMUM_ALLOWED, NULL, \
|
|
SecurityImpersonation, TokenImpersonation, \
|
|
&_dup_token)) \
|
|
debug_printf ("DuplicateTokenEx: %E"); \
|
|
else if (!ImpersonateLoggedOnUser (_dup_token)) \
|
|
debug_printf ("ImpersonateLoggedOnUser: %E"); \
|
|
else \
|
|
set_privilege (_dup_token, (_priv), (_val)); \
|
|
}
|
|
#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) \
|
|
{ \
|
|
ImpersonateLoggedOnUser (_token); \
|
|
CloseHandle (_dup_token); \
|
|
} \
|
|
}
|
|
#define pop_self_privilege() pop_thread_privilege()
|
|
|
|
/* shared.cc: */
|
|
/* Retrieve a security descriptor that allows all access */
|
|
SECURITY_DESCRIPTOR *__stdcall get_null_sd ();
|
|
|
|
/* Various types of security attributes for use in Create* functions. */
|
|
extern SECURITY_ATTRIBUTES sec_none, sec_none_nih, sec_all, sec_all_nih;
|
|
extern SECURITY_ATTRIBUTES *__stdcall __sec_user (PVOID sa_buf, PSID sid1, PSID sid2,
|
|
DWORD access2, BOOL inherit)
|
|
__attribute__ ((regparm (3)));
|
|
extern bool sec_acl (PACL acl, bool original, bool admins, PSID sid1 = NO_SID,
|
|
PSID sid2 = NO_SID, DWORD access2 = 0);
|
|
|
|
int __stdcall read_ea (HANDLE hdl, const char *file, const char *attrname,
|
|
char *buf, int len);
|
|
BOOL __stdcall write_ea (HANDLE hdl, const char *file, const char *attrname,
|
|
const char *buf, int len);
|
|
|
|
/* Note: sid1 is usually (read: currently always) the current user's
|
|
effective sid (cygheap->user.sid ()). */
|
|
extern inline SECURITY_ATTRIBUTES *
|
|
sec_user_nih (SECURITY_ATTRIBUTES *sa_buf, PSID sid1, PSID sid2 = NULL,
|
|
DWORD access2 = 0)
|
|
{
|
|
return __sec_user (sa_buf, sid1, sid2, access2, FALSE);
|
|
}
|
|
|
|
extern inline SECURITY_ATTRIBUTES *
|
|
sec_user (SECURITY_ATTRIBUTES *sa_buf, PSID sid1, PSID sid2 = NULL,
|
|
DWORD access2 = 0)
|
|
{
|
|
return __sec_user (sa_buf, sid1, sid2, access2, TRUE);
|
|
}
|
|
#endif /*_SECURITY_H*/
|