2000-09-08 10:56:55 +08:00
|
|
|
/* security.h: security declarations
|
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
Copyright 2000, 2001 Red Hat, Inc.
|
2000-09-08 10:56:55 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
#define DONT_INHERIT (0)
|
|
|
|
#define INHERIT_ALL (CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE)
|
|
|
|
#define INHERIT_ONLY (INHERIT_ONLY_ACE|CONTAINER_INHERIT_ACE|OBJECT_INHERIT_ACE)
|
|
|
|
|
2001-05-01 02:21:48 +08:00
|
|
|
#define DEFAULT_UID DOMAIN_USER_RID_ADMIN
|
|
|
|
#define DEFAULT_GID DOMAIN_ALIAS_RID_ADMINS
|
|
|
|
|
* 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-16 03:23:31 +08:00
|
|
|
#define MAX_SID_LEN 40
|
|
|
|
|
|
|
|
#define NO_SID ((PSID)NULL)
|
|
|
|
|
2001-04-25 17:43:25 +08:00
|
|
|
class cygsid {
|
|
|
|
PSID psid;
|
|
|
|
char sbuf[MAX_SID_LEN];
|
* 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-16 03:23:31 +08:00
|
|
|
|
|
|
|
const PSID getfromstr (const char *nsidstr);
|
|
|
|
PSID get_sid (DWORD s, DWORD cnt, DWORD *r);
|
|
|
|
|
2001-04-25 17:43:25 +08:00
|
|
|
public:
|
|
|
|
inline cygsid () : psid ((PSID) sbuf) {}
|
* 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-16 03:23:31 +08:00
|
|
|
inline cygsid (const PSID nsid) { *this = nsid; }
|
|
|
|
inline cygsid (const char *nstrsid) { *this = nstrsid; }
|
2001-04-25 17:43:25 +08:00
|
|
|
|
|
|
|
inline PSID set () { return psid = (PSID) sbuf; }
|
|
|
|
|
* 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-16 03:23:31 +08:00
|
|
|
BOOL getfrompw (struct passwd *pw);
|
|
|
|
BOOL getfromgr (struct group *gr);
|
|
|
|
|
|
|
|
int get_id (BOOL search_grp, int *type = NULL);
|
|
|
|
inline int get_uid () { return get_id (FALSE); }
|
|
|
|
inline int get_gid () { return get_id (TRUE); }
|
|
|
|
|
|
|
|
char *string (char *nsidstr);
|
|
|
|
|
|
|
|
inline const PSID operator= (const PSID nsid)
|
2001-04-25 17:43:25 +08:00
|
|
|
{
|
|
|
|
if (!nsid)
|
|
|
|
psid = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
psid = (PSID) sbuf;
|
|
|
|
CopySid (MAX_SID_LEN, psid, nsid);
|
|
|
|
}
|
|
|
|
return psid;
|
|
|
|
}
|
* fork.cc (fork): Eliminate superfluous call to getuid().
* security.h: New define `NO_SID'. Remove declarations of functions
moved to methods into class cygsid.
(class cygsid): Declare new methods `getfromstr', `get_sid',
`getfrompw', `getfromgr', `get_rid', `get_uid', `get_gid', `string'
and new constructors and operators =, == and !=.
Declare new global cygsids `well_known_XXX_sid' substituting the
corresponding `get_XXX_sid' functions. Remove declarations of
these functions.
* sec_helper.cc (well_known_admin_sid): New global variable.
(well_known_system_sid): Ditto
(well_known_creator_owner_sid): Ditto
(well_known_world_sid): Ditto
(cygsid::string): New method, substituting `convert_sid_to_string_sid'.
(cygsid::get_sid): New method, substituting `get_sid'.
(cygsid::getfromstr): New method, substituting
`convert_string_sid_to_sid'.
(cygsid::getfrompw): New method, substituting `get_pw_sid'.
(cygsid::getfromgr): New method, substituting `get_gr_sid'.
(cygsid::get_id): New method, substituting `get_id_from_sid'.
(get_admin_sid): Eliminated.
(get_system_sid): Ditto.
(get_creator_owner_sid): Ditto.
(get_world_sid): Ditto.
* grp.cc: Use new cygsid methods and well known sids throughout.
* registry.cc: Ditto.
* sec_acl.cc: Ditto.
* security.cc: Ditto.
* shared.cc: Ditto.
* syscalls.cc (seteuid): Ditto. Eliminate redundant conditional.
* uinfo.cc (internal_getlogin): Ditto.
* spawn.cc (spawn_guts) Revert previous patch.
2001-05-16 03:23:31 +08:00
|
|
|
inline const PSID operator= (const char *nsidstr)
|
|
|
|
{ return getfromstr (nsidstr); }
|
|
|
|
|
|
|
|
inline BOOL operator== (const PSID nsid) const
|
2001-04-25 17:43:25 +08:00
|
|
|
{
|
|
|
|
if (!psid || !nsid)
|
|
|
|
return nsid == psid;
|
|
|
|
return EqualSid (psid, nsid);
|
|
|
|
}
|
* 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-16 03:23:31 +08:00
|
|
|
inline BOOL operator== (const char *nsidstr) const
|
|
|
|
{
|
|
|
|
cygsid nsid (nsidstr);
|
|
|
|
return *this == nsid;
|
|
|
|
}
|
|
|
|
inline BOOL operator!= (const PSID nsid) const
|
|
|
|
{ return !(*this == nsid); }
|
|
|
|
inline BOOL operator!= (const char *nsidstr) const
|
|
|
|
{ return !(*this == nsidstr); }
|
|
|
|
|
2001-04-25 17:43:25 +08:00
|
|
|
inline operator const PSID () { return psid; }
|
|
|
|
};
|
|
|
|
|
* fork.cc (fork): Eliminate superfluous call to getuid().
* security.h: New define `NO_SID'. Remove declarations of functions
moved to methods into class cygsid.
(class cygsid): Declare new methods `getfromstr', `get_sid',
`getfrompw', `getfromgr', `get_rid', `get_uid', `get_gid', `string'
and new constructors and operators =, == and !=.
Declare new global cygsids `well_known_XXX_sid' substituting the
corresponding `get_XXX_sid' functions. Remove declarations of
these functions.
* sec_helper.cc (well_known_admin_sid): New global variable.
(well_known_system_sid): Ditto
(well_known_creator_owner_sid): Ditto
(well_known_world_sid): Ditto
(cygsid::string): New method, substituting `convert_sid_to_string_sid'.
(cygsid::get_sid): New method, substituting `get_sid'.
(cygsid::getfromstr): New method, substituting
`convert_string_sid_to_sid'.
(cygsid::getfrompw): New method, substituting `get_pw_sid'.
(cygsid::getfromgr): New method, substituting `get_gr_sid'.
(cygsid::get_id): New method, substituting `get_id_from_sid'.
(get_admin_sid): Eliminated.
(get_system_sid): Ditto.
(get_creator_owner_sid): Ditto.
(get_world_sid): Ditto.
* grp.cc: Use new cygsid methods and well known sids throughout.
* registry.cc: Ditto.
* sec_acl.cc: Ditto.
* security.cc: Ditto.
* shared.cc: Ditto.
* syscalls.cc (seteuid): Ditto. Eliminate redundant conditional.
* uinfo.cc (internal_getlogin): Ditto.
* spawn.cc (spawn_guts) Revert previous patch.
2001-05-16 03:23:31 +08:00
|
|
|
extern cygsid well_known_admin_sid;
|
|
|
|
extern cygsid well_known_system_sid;
|
|
|
|
extern cygsid well_known_creator_owner_sid;
|
|
|
|
extern cygsid well_known_world_sid;
|
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
extern BOOL allow_ntsec;
|
|
|
|
extern BOOL allow_smbntsec;
|
|
|
|
|
2001-04-25 17:43:25 +08:00
|
|
|
/* These both functions are needed to allow walking through the passwd
|
|
|
|
and group lists so they are somehow security related. Besides that
|
|
|
|
I didn't find a better place to declare them. */
|
|
|
|
extern struct passwd *internal_getpwent (int);
|
|
|
|
extern struct group *internal_getgrent (int);
|
|
|
|
|
2000-09-08 10:56:55 +08:00
|
|
|
/* File manipulation */
|
|
|
|
int __stdcall set_process_privileges ();
|
|
|
|
int __stdcall get_file_attribute (int, const char *, int *,
|
|
|
|
uid_t * = NULL, gid_t * = NULL);
|
|
|
|
int __stdcall set_file_attribute (int, const char *, int);
|
|
|
|
int __stdcall set_file_attribute (int, const char *, uid_t, gid_t, int, const char *);
|
2001-04-20 21:02:32 +08:00
|
|
|
LONG __stdcall read_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, LPDWORD sd_size);
|
|
|
|
LONG __stdcall write_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, DWORD sd_size);
|
|
|
|
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);
|
|
|
|
|
2001-05-01 05:19:42 +08:00
|
|
|
/* Try a subauthentication. */
|
|
|
|
HANDLE subauth (struct passwd *pw);
|
2001-04-20 21:02:32 +08:00
|
|
|
|
|
|
|
/* sec_helper.cc: Security helper functions. */
|
|
|
|
BOOL __stdcall is_grp_member (uid_t uid, gid_t gid);
|
2000-09-08 10:56:55 +08:00
|
|
|
/* `lookup_name' should be called instead of LookupAccountName.
|
|
|
|
* logsrv may be NULL, in this case only the local system is used for lookup.
|
|
|
|
* The buffer for ret_sid (40 Bytes) has to be allocated by the caller! */
|
|
|
|
BOOL __stdcall lookup_name (const char *, const char *, PSID);
|
2001-04-21 04:36:13 +08:00
|
|
|
int set_process_privilege (const char *privilege, BOOL enable = TRUE);
|
2000-09-08 10:56:55 +08:00
|
|
|
|
2001-04-20 21:02:32 +08:00
|
|
|
/* shared.cc: */
|
|
|
|
/* Retrieve a security descriptor that allows all access */
|
|
|
|
SECURITY_DESCRIPTOR *__stdcall get_null_sd (void);
|
|
|
|
|
2000-09-08 10:56:55 +08:00
|
|
|
/* 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 sid2 = NULL, BOOL inherit = TRUE);
|
|
|
|
extern SECURITY_ATTRIBUTES *__stdcall sec_user_nih (PVOID sa_buf, PSID sid2 = NULL);
|
|
|
|
|
|
|
|
int __stdcall NTReadEA (const char *file, const char *attrname, char *buf, int len);
|
|
|
|
BOOL __stdcall NTWriteEA (const char *file, const char *attrname, char *buf, int len);
|