4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-20 13:29:24 +08:00

Change internal uid datatype from __uid16_t to __uid32_t

throughout.
	* cygwin.din: Export new symbols getpwuid32, getpwuid_r32, getuid32,
	geteuid32, setuid32, seteuid32.
	* passwd.cc (getpwuid32): New function.
	(getpwuid_r32): Ditto.
	* syscalls.cc (seteuid32): Ditto.
	(setuid32): Ditto.
	* uinfo.cc (getuid32): Ditto.
	(geteuid32): Ditto.
	* winsup.h (uid16touid32): New macro, correclt casting from __uid16_t
	to __uid32_t.
	(gid16togid32): Ditto fir gids.
	(getuid32): Declare.
	(geteuid32): Ditto.
	(getpwuid32): Ditto.
	* include/sys/cygwin.h (struct external_pinfo): Add members uid32 and
	gid32.
This commit is contained in:
Corinna Vinschen 2002-05-29 15:04:29 +00:00
parent 9854c44c43
commit a8d7ae61e7
17 changed files with 135 additions and 55 deletions

View File

@ -1,3 +1,24 @@
2002-05-29 Corinna Vinschen <corinna@vinschen.de>
Change internal uid datatype from __uid16_t to __uid32_t
throughout.
* cygwin.din: Export new symbols getpwuid32, getpwuid_r32, getuid32,
geteuid32, setuid32, seteuid32.
* passwd.cc (getpwuid32): New function.
(getpwuid_r32): Ditto.
* syscalls.cc (seteuid32): Ditto.
(setuid32): Ditto.
* uinfo.cc (getuid32): Ditto.
(geteuid32): Ditto.
* winsup.h (uid16touid32): New macro, correclt casting from __uid16_t
to __uid32_t.
(gid16togid32): Ditto fir gids.
(getuid32): Declare.
(geteuid32): Ditto.
(getpwuid32): Ditto.
* include/sys/cygwin.h (struct external_pinfo): Add members uid32 and
gid32.
2002-05-29 Corinna Vinschen <corinna@vinschen.de> 2002-05-29 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/socket.h: Protect some symbols against multiple * include/cygwin/socket.h: Protect some symbols against multiple

View File

@ -70,7 +70,7 @@ class fhandler_base;
class cygheap_exec_info class cygheap_exec_info
{ {
public: public:
__uid16_t uid; __uid32_t uid;
char *old_title; char *old_title;
int argc; int argc;
char **argv; char **argv;

View File

@ -96,9 +96,9 @@ class cygheap_user
PSID psid; /* buffer for user's SID */ PSID psid; /* buffer for user's SID */
PSID orig_psid; /* Remains intact even after impersonation */ PSID orig_psid; /* Remains intact even after impersonation */
public: public:
__uid16_t orig_uid; /* Remains intact even after impersonation */ __uid32_t orig_uid; /* Remains intact even after impersonation */
__gid32_t orig_gid; /* Ditto */ __gid32_t orig_gid; /* Ditto */
__uid16_t real_uid; /* Remains intact on seteuid, replaced by setuid */ __uid32_t real_uid; /* Remains intact on seteuid, replaced by setuid */
__gid32_t real_gid; /* Ditto */ __gid32_t real_gid; /* Ditto */
/* token is needed if set(e)uid should be called. It can be set by a call /* token is needed if set(e)uid should be called. It can be set by a call

View File

@ -349,6 +349,7 @@ _getegid = getegid
getegid32 getegid32
geteuid geteuid
_geteuid = geteuid _geteuid = geteuid
geteuid32
getgid getgid
_getgid = getgid _getgid = getgid
getgid32 getgid32
@ -389,6 +390,7 @@ gettimeofday
_gettimeofday = gettimeofday _gettimeofday = gettimeofday
getuid getuid
_getuid = getuid _getuid = getuid
getuid32
getutent getutent
_getutent = getutent _getutent = getutent
getutid getutid
@ -682,11 +684,13 @@ settimeofday
_settimeofday = settimeofday _settimeofday = settimeofday
seteuid seteuid
_seteuid = seteuid _seteuid = seteuid
seteuid32
setegid setegid
_setegid = setegid _setegid = setegid
setegid32 setegid32
setuid setuid
_setuid = setuid _setuid = setuid
setuid32
setutent setutent
_setutent = setutent _setutent = setutent
chroot chroot
@ -1019,7 +1023,9 @@ _getpwnam = getpwnam
getpwnam_r getpwnam_r
getpwuid getpwuid
_getpwuid = getpwuid _getpwuid = getpwuid
getpwuid32
getpwuid_r getpwuid_r
getpwuid_r32
getpgrp getpgrp
_getpgrp = getpgrp _getpgrp = getpgrp
getgrent getgrent

View File

@ -86,6 +86,9 @@ fillout_pinfo (pid_t pid, int winpid)
ep.strace_file = 0; ep.strace_file = 0;
ep.process_state = p->process_state; ep.process_state = p->process_state;
ep.uid32 = p->uid;
ep.gid32 = p->gid;
break; break;
} }
} }

View File

@ -126,7 +126,7 @@ fhandler_disk_file::fstat (struct __stat64 *buf, path_conv *pc)
{ {
int res = -1; int res = -1;
int oret; int oret;
__uid16_t uid; __uid32_t uid;
__gid32_t gid; __gid32_t gid;
int open_flags = O_RDONLY | O_BINARY | O_DIROPEN; int open_flags = O_RDONLY | O_BINARY | O_DIROPEN;
bool query_open_already; bool query_open_already;
@ -237,7 +237,7 @@ fhandler_disk_file::fstat_helper (struct __stat64 *buf, path_conv *pc,
else if (pc->issocket ()) else if (pc->issocket ())
buf->st_mode = S_IFSOCK; buf->st_mode = S_IFSOCK;
__uid16_t uid; __uid32_t uid;
__gid32_t gid; __gid32_t gid;
if (get_file_attribute (pc->has_acls (), get_win32_name (), &buf->st_mode, if (get_file_attribute (pc->has_acls (), get_win32_name (), &buf->st_mode,
&uid, &gid) == 0) &uid, &gid) == 0)

View File

@ -211,6 +211,8 @@ extern int cygwin_attach_handle_to_fd (char *, int, HANDLE, mode_t, DWORD);
#ifndef _SYS_TYPES_H #ifndef _SYS_TYPES_H
typedef unsigned short __uid16_t; typedef unsigned short __uid16_t;
typedef unsigned short __gid16_t; typedef unsigned short __gid16_t;
typedef unsigned long __uid32_t;
typedef unsigned long __gid32_t;
#endif #endif
struct external_pinfo struct external_pinfo
@ -236,6 +238,9 @@ struct external_pinfo
HANDLE strace_file; HANDLE strace_file;
DWORD process_state; DWORD process_state;
__uid32_t uid32;
__gid32_t gid32;
}; };
DWORD cygwin_internal (cygwin_getinfo_types, ...); DWORD cygwin_internal (cygwin_getinfo_types, ...);

View File

@ -186,7 +186,7 @@ read_etc_passwd ()
/* Cygwin internal */ /* Cygwin internal */
/* If this ever becomes non-reentrant, update all the getpw*_r functions */ /* If this ever becomes non-reentrant, update all the getpw*_r functions */
static struct passwd * static struct passwd *
search_for (__uid16_t uid, const char *name) search_for (__uid32_t uid, const char *name)
{ {
struct passwd *res = 0; struct passwd *res = 0;
struct passwd *default_pw = 0; struct passwd *default_pw = 0;
@ -202,7 +202,7 @@ search_for (__uid16_t uid, const char *name)
if (strcasematch (name, res->pw_name)) if (strcasematch (name, res->pw_name))
return res; return res;
} }
else if (uid == res->pw_uid) else if (uid == (__uid32_t) res->pw_uid)
return res; return res;
} }
@ -217,7 +217,7 @@ search_for (__uid16_t uid, const char *name)
} }
extern "C" struct passwd * extern "C" struct passwd *
getpwuid (__uid16_t uid) getpwuid32 (__uid32_t uid)
{ {
if (passwd_state <= initializing) if (passwd_state <= initializing)
read_etc_passwd (); read_etc_passwd ();
@ -227,8 +227,14 @@ getpwuid (__uid16_t uid)
return search_for (uid, 0); return search_for (uid, 0);
} }
extern "C" struct passwd *
getpwuid (__uid16_t uid)
{
return getpwuid32 (uid16touid32 (uid));
}
extern "C" int extern "C" int
getpwuid_r (__uid16_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) getpwuid_r32 (__uid32_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
{ {
*result = NULL; *result = NULL;
@ -269,6 +275,12 @@ getpwuid_r (__uid16_t uid, struct passwd *pwd, char *buffer, size_t bufsize, str
return 0; return 0;
} }
extern "C" int
getpwuid_r (__uid16_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
{
return getpwuid_r32 (uid16touid32 (uid), pwd, buffer, bufsize, result);
}
extern "C" struct passwd * extern "C" struct passwd *
getpwnam (const char *name) getpwnam (const char *name)
{ {

View File

@ -158,7 +158,7 @@ setacl (const char *file, int nentries, __aclent16_t *aclbufp)
break; break;
case USER: case USER:
case DEF_USER: case DEF_USER:
if (!(pw = getpwuid (aclbufp[i].a_id)) if (!(pw = getpwuid32 (aclbufp[i].a_id))
|| !sid.getfrompw (pw) || !sid.getfrompw (pw)
|| !add_access_allowed_ace (acl, ace_off++, allow, || !add_access_allowed_ace (acl, ace_off++, allow,
sid, acl_len, inheritance)) sid, acl_len, inheritance))
@ -255,7 +255,7 @@ getacl (const char *file, DWORD attr, int nentries, __aclent16_t *aclbufp)
PSID owner_sid; PSID owner_sid;
PSID group_sid; PSID group_sid;
BOOL dummy; BOOL dummy;
__uid16_t uid; __uid32_t uid;
__gid32_t gid; __gid32_t gid;
if (!GetSecurityDescriptorOwner (psd, &owner_sid, &dummy)) if (!GetSecurityDescriptorOwner (psd, &owner_sid, &dummy))
@ -426,7 +426,7 @@ acl_access (const char *path, int flags)
struct passwd *pw; struct passwd *pw;
struct __group32 *gr = NULL; struct __group32 *gr = NULL;
if ((pw = getpwuid (acls[i].a_id)) != NULL if ((pw = getpwuid32 (acls[i].a_id)) != NULL
&& owner.getfrompw (pw)) && owner.getfrompw (pw))
{ {
for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx) for (int gidx = 0; (gr = internal_getgrent (gidx)); ++gidx)

View File

@ -244,7 +244,7 @@ cygsid::get_id (BOOL search_grp, int *type)
} }
} }
if (id == -1) if (id == -1)
id = getuid (); id = getuid32 ();
return id; return id;
} }
@ -254,7 +254,7 @@ is_grp_member (__uid32_t uid, __gid32_t gid)
extern int getgroups32 (int, __gid32_t *, __gid32_t, const char *); extern int getgroups32 (int, __gid32_t *, __gid32_t, const char *);
BOOL grp_member = TRUE; BOOL grp_member = TRUE;
struct passwd *pw = getpwuid (uid); struct passwd *pw = getpwuid32 (uid);
__gid32_t grps[NGROUPS_MAX]; __gid32_t grps[NGROUPS_MAX];
int cnt = getgroups32 (NGROUPS_MAX, grps, int cnt = getgroups32 (NGROUPS_MAX, grps,
pw ? pw->pw_gid : myself->gid, pw ? pw->pw_gid : myself->gid,

View File

@ -1130,7 +1130,7 @@ write_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, DWORD sd_size)
static int static int
get_nt_attribute (const char *file, int *attribute, get_nt_attribute (const char *file, int *attribute,
__uid16_t *uidret, __gid32_t *gidret) __uid32_t *uidret, __gid32_t *gidret)
{ {
if (!wincap.has_security ()) if (!wincap.has_security ())
return 0; return 0;
@ -1168,7 +1168,7 @@ get_nt_attribute (const char *file, int *attribute,
return -1; return -1;
} }
__uid16_t uid = cygsid(owner_sid).get_uid (); __uid32_t uid = cygsid(owner_sid).get_uid ();
__gid32_t gid = cygsid(group_sid).get_gid (); __gid32_t gid = cygsid(group_sid).get_gid ();
if (uidret) if (uidret)
*uidret = uid; *uidret = uid;
@ -1279,7 +1279,7 @@ get_nt_attribute (const char *file, int *attribute,
int int
get_file_attribute (int use_ntsec, const char *file, get_file_attribute (int use_ntsec, const char *file,
int *attribute, __uid16_t *uidret, __gid32_t *gidret) int *attribute, __uid32_t *uidret, __gid32_t *gidret)
{ {
int res; int res;
@ -1292,7 +1292,7 @@ get_file_attribute (int use_ntsec, const char *file,
} }
if (uidret) if (uidret)
*uidret = getuid (); *uidret = getuid32 ();
if (gidret) if (gidret)
*gidret = getgid32 (); *gidret = getgid32 ();
@ -1350,7 +1350,7 @@ add_access_denied_ace (PACL acl, int offset, DWORD attributes,
} }
PSECURITY_DESCRIPTOR PSECURITY_DESCRIPTOR
alloc_sd (__uid16_t uid, __gid32_t gid, const char *logsrv, int attribute, alloc_sd (__uid32_t uid, __gid32_t gid, const char *logsrv, int attribute,
PSECURITY_DESCRIPTOR sd_ret, DWORD *sd_size_ret) PSECURITY_DESCRIPTOR sd_ret, DWORD *sd_size_ret)
{ {
BOOL dummy; BOOL dummy;
@ -1367,7 +1367,7 @@ alloc_sd (__uid16_t uid, __gid32_t gid, const char *logsrv, int attribute,
/* Get SID and name of new owner. */ /* Get SID and name of new owner. */
char owner[UNLEN + 1]; char owner[UNLEN + 1];
cygsid owner_sid; cygsid owner_sid;
struct passwd *pw = getpwuid (uid); struct passwd *pw = getpwuid32 (uid);
strcpy (owner, pw ? pw->pw_name : getlogin ()); strcpy (owner, pw ? pw->pw_name : getlogin ());
if ((!pw || !owner_sid.getfrompw (pw)) if ((!pw || !owner_sid.getfrompw (pw))
&& !lookup_name (owner, logsrv, owner_sid)) && !lookup_name (owner, logsrv, owner_sid))
@ -1612,14 +1612,14 @@ set_security_attribute (int attribute, PSECURITY_ATTRIBUTES psa,
psa->lpSecurityDescriptor = sd_buf; psa->lpSecurityDescriptor = sd_buf;
InitializeSecurityDescriptor ((PSECURITY_DESCRIPTOR)sd_buf, InitializeSecurityDescriptor ((PSECURITY_DESCRIPTOR)sd_buf,
SECURITY_DESCRIPTOR_REVISION); SECURITY_DESCRIPTOR_REVISION);
psa->lpSecurityDescriptor = alloc_sd (geteuid (), getegid32 (), psa->lpSecurityDescriptor = alloc_sd (geteuid32 (), getegid32 (),
cygheap->user.logsrv (), cygheap->user.logsrv (),
attribute, (PSECURITY_DESCRIPTOR)sd_buf, attribute, (PSECURITY_DESCRIPTOR)sd_buf,
&sd_buf_size); &sd_buf_size);
} }
static int static int
set_nt_attribute (const char *file, __uid16_t uid, __gid32_t gid, set_nt_attribute (const char *file, __uid32_t uid, __gid32_t gid,
const char *logsrv, int attribute) const char *logsrv, int attribute)
{ {
if (!wincap.has_security ()) if (!wincap.has_security ())
@ -1645,7 +1645,7 @@ set_nt_attribute (const char *file, __uid16_t uid, __gid32_t gid,
int int
set_file_attribute (int use_ntsec, const char *file, set_file_attribute (int use_ntsec, const char *file,
__uid16_t uid, __gid32_t gid, __uid32_t uid, __gid32_t gid,
int attribute, const char *logsrv) int attribute, const char *logsrv)
{ {
int ret = 0; int ret = 0;

View File

@ -166,9 +166,9 @@ extern struct __group32 *internal_getgrent (int);
/* File manipulation */ /* File manipulation */
int __stdcall set_process_privileges (); int __stdcall set_process_privileges ();
int __stdcall get_file_attribute (int, const char *, int *, int __stdcall get_file_attribute (int, const char *, int *,
__uid16_t * = NULL, __gid32_t * = NULL); __uid32_t * = NULL, __gid32_t * = NULL);
int __stdcall set_file_attribute (int, const char *, int); int __stdcall set_file_attribute (int, const char *, int);
int __stdcall set_file_attribute (int, const char *, __uid16_t, __gid32_t, int, const char *); int __stdcall set_file_attribute (int, const char *, __uid32_t, __gid32_t, int, const char *);
LONG __stdcall read_sd(const char *file, PSECURITY_DESCRIPTOR sd_buf, LPDWORD sd_size); 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); 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_allowed_ace (PACL acl, int offset, DWORD attributes, PSID sid, size_t &len_add, DWORD inherit);
@ -209,7 +209,7 @@ extern BOOL sec_acl (PACL acl, BOOL admins, PSID sid1 = NO_SID, PSID sid2 = NO_S
int __stdcall NTReadEA (const char *file, const char *attrname, char *buf, int len); int __stdcall NTReadEA (const char *file, const char *attrname, char *buf, int len);
BOOL __stdcall NTWriteEA (const char *file, const char *attrname, const char *buf, int len); BOOL __stdcall NTWriteEA (const char *file, const char *attrname, const char *buf, int len);
PSECURITY_DESCRIPTOR alloc_sd (__uid16_t uid, __gid32_t gid, const char *logsrv, int attribute, PSECURITY_DESCRIPTOR alloc_sd (__uid32_t uid, __gid32_t gid, const char *logsrv, int attribute,
PSECURITY_DESCRIPTOR sd_ret, DWORD *sd_size_ret); PSECURITY_DESCRIPTOR sd_ret, DWORD *sd_size_ret);
extern inline SECURITY_ATTRIBUTES * extern inline SECURITY_ATTRIBUTES *

View File

@ -442,7 +442,7 @@ shmctl (int shmid, int cmd, struct shmid_ds *buf)
return 0; return 0;
} }
/* FIXME: evaluate getuid() and getgid32() against the requested mode. Then /* FIXME: evaluate getuid32() and getgid32() against the requested mode. Then
* choose PAGE_READWRITE | PAGE_READONLY and FILE_MAP_WRITE | FILE_MAP_READ * choose PAGE_READWRITE | PAGE_READONLY and FILE_MAP_WRITE | FILE_MAP_READ
* appropriately * appropriately
*/ */
@ -461,7 +461,7 @@ shmget (key_t key, size_t size, int shmflg)
/* create a sd for our open requests based on shmflag & 0x01ff */ /* create a sd for our open requests based on shmflag & 0x01ff */
InitializeSecurityDescriptor (psd, InitializeSecurityDescriptor (psd,
SECURITY_DESCRIPTOR_REVISION); SECURITY_DESCRIPTOR_REVISION);
psd = alloc_sd (getuid (), getgid32 (), cygheap->user.logsrv (), psd = alloc_sd (getuid32 (), getgid32 (), cygheap->user.logsrv (),
shmflg & 0x01ff, psd, &sd_size); shmflg & 0x01ff, psd, &sd_size);
if (key == (key_t) - 1) if (key == (key_t) - 1)
@ -538,7 +538,7 @@ shmget (key_t key, size_t size, int shmflg)
#if 0 #if 0
/* fill out the node data */ /* fill out the node data */
shmtemp->shm_perm.cuid = getuid (); shmtemp->shm_perm.cuid = getuid32 ();
shmtemp->shm_perm.uid = shmtemp->shm_perm.cuid; shmtemp->shm_perm.uid = shmtemp->shm_perm.cuid;
shmtemp->shm_perm.cgid = getgid32 (); shmtemp->shm_perm.cgid = getgid32 ();
shmtemp->shm_perm.gid = shmtemp->shm_perm.cgid; shmtemp->shm_perm.gid = shmtemp->shm_perm.cgid;

View File

@ -627,7 +627,7 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
cygbench ("spawn-guts"); cygbench ("spawn-guts");
if (!hToken) if (!hToken)
{ {
ciresrv.moreinfo->uid = getuid (); ciresrv.moreinfo->uid = getuid32 ();
/* FIXME: This leaks a handle in the CreateProcessAsUser case since the /* FIXME: This leaks a handle in the CreateProcessAsUser case since the
child process doesn't know about cygwin_mount_h. */ child process doesn't know about cygwin_mount_h. */
ciresrv.mount_h = cygwin_mount_h; ciresrv.mount_h = cygwin_mount_h;

View File

@ -750,10 +750,10 @@ done:
* systems, it is only a stub that always returns zero. * systems, it is only a stub that always returns zero.
*/ */
static int static int
chown_worker (const char *name, unsigned fmode, __uid16_t uid, __gid32_t gid) chown_worker (const char *name, unsigned fmode, __uid32_t uid, __gid32_t gid)
{ {
int res; int res;
__uid16_t old_uid; __uid32_t old_uid;
__gid32_t old_gid; __gid32_t old_gid;
if (check_null_empty_str_errno (name)) if (check_null_empty_str_errno (name))
@ -815,7 +815,7 @@ done:
} }
extern "C" int extern "C" int
chown32 (const char * name, __uid16_t uid, __gid32_t gid) chown32 (const char * name, __uid32_t uid, __gid32_t gid)
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
return chown_worker (name, PC_SYM_FOLLOW, uid, gid); return chown_worker (name, PC_SYM_FOLLOW, uid, gid);
@ -825,11 +825,11 @@ extern "C" int
chown (const char * name, __uid16_t uid, __gid16_t gid) chown (const char * name, __uid16_t uid, __gid16_t gid)
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
return chown_worker (name, PC_SYM_FOLLOW, uid, (__gid32_t) gid); return chown_worker (name, PC_SYM_FOLLOW, uid, gid16togid32 (gid));
} }
extern "C" int extern "C" int
lchown32 (const char * name, __uid16_t uid, __gid32_t gid) lchown32 (const char * name, __uid32_t uid, __gid32_t gid)
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
return chown_worker (name, PC_SYM_NOFOLLOW, uid, gid); return chown_worker (name, PC_SYM_NOFOLLOW, uid, gid);
@ -839,11 +839,11 @@ extern "C" int
lchown (const char * name, __uid16_t uid, __gid16_t gid) lchown (const char * name, __uid16_t uid, __gid16_t gid)
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
return chown_worker (name, PC_SYM_NOFOLLOW, uid, (__gid32_t) gid); return chown_worker (name, PC_SYM_NOFOLLOW, uid, gid16togid32 (gid));
} }
extern "C" int extern "C" int
fchown32 (int fd, __uid16_t uid, __gid32_t gid) fchown32 (int fd, __uid32_t uid, __gid32_t gid)
{ {
sigframe thisframe (mainthread); sigframe thisframe (mainthread);
cygheap_fdget cfd (fd); cygheap_fdget cfd (fd);
@ -870,7 +870,7 @@ fchown32 (int fd, __uid16_t uid, __gid32_t gid)
extern "C" int extern "C" int
fchown (int fd, __uid16_t uid, __gid16_t gid) fchown (int fd, __uid16_t uid, __gid16_t gid)
{ {
return fchown32 (fd, uid, (__gid32_t) gid); return fchown32 (fd, uid, gid16togid32 (gid));
} }
/* umask: POSIX 5.3.3.1 */ /* umask: POSIX 5.3.3.1 */
@ -914,7 +914,7 @@ chmod (const char *path, mode_t mode)
/* temporary erase read only bit, to be able to set file security */ /* temporary erase read only bit, to be able to set file security */
SetFileAttributes (win32_path, (DWORD) win32_path & ~FILE_ATTRIBUTE_READONLY); SetFileAttributes (win32_path, (DWORD) win32_path & ~FILE_ATTRIBUTE_READONLY);
__uid16_t uid; __uid32_t uid;
__gid32_t gid; __gid32_t gid;
if (win32_path.isdir ()) if (win32_path.isdir ())
@ -1932,22 +1932,11 @@ mkfifo (const char *_path, mode_t mode)
return -1; return -1;
} }
/* setuid: POSIX 4.2.2.1 */
extern "C" int
setuid (__uid16_t uid)
{
int ret = seteuid (uid);
if (!ret)
cygheap->user.real_uid = myself->uid;
debug_printf ("real: %d, effective: %d", cygheap->user.real_uid, myself->uid);
return ret;
}
extern struct passwd *internal_getlogin (cygheap_user &user); extern struct passwd *internal_getlogin (cygheap_user &user);
/* seteuid: standards? */ /* seteuid: standards? */
extern "C" int extern "C" int
seteuid (__uid16_t uid) seteuid32 (__uid32_t uid)
{ {
if (!wincap.has_security ()) return 0; if (!wincap.has_security ()) return 0;
@ -1974,7 +1963,7 @@ seteuid (__uid16_t uid)
debug_printf ("uid: %d myself->gid: %d", uid, myself->gid); debug_printf ("uid: %d myself->gid: %d", uid, myself->gid);
pw_new = getpwuid (uid); pw_new = getpwuid32 (uid);
if (!usersid.getfrompw (pw_new) || if (!usersid.getfrompw (pw_new) ||
(!pgrpsid.getfromgr (getgrgid32 (myself->gid)))) (!pgrpsid.getfromgr (getgrgid32 (myself->gid))))
{ {
@ -2145,6 +2134,29 @@ seteuid (__uid16_t uid)
return -1; return -1;
} }
extern "C" int
seteuid (__uid16_t uid)
{
return seteuid32 (uid16touid32 (uid));
}
/* setuid: POSIX 4.2.2.1 */
extern "C" int
setuid32 (__uid32_t uid)
{
int ret = seteuid32 (uid);
if (!ret)
cygheap->user.real_uid = myself->uid;
debug_printf ("real: %d, effective: %d", cygheap->user.real_uid, myself->uid);
return ret;
}
extern "C" int
setuid (__uid16_t uid)
{
return setuid32 (uid16touid32 (uid));
}
/* setegid: from System V. */ /* setegid: from System V. */
extern "C" int extern "C" int
setegid32 (__gid32_t gid) setegid32 (__gid32_t gid)
@ -2197,7 +2209,7 @@ setegid32 (__gid32_t gid)
extern "C" int extern "C" int
setegid (__gid16_t gid) setegid (__gid16_t gid)
{ {
return setegid32 ((__gid32_t) gid); return setegid32 (gid16togid32 (gid));
} }
/* setgid: POSIX 4.2.2.1 */ /* setgid: POSIX 4.2.2.1 */
@ -2213,7 +2225,7 @@ setgid32 (__gid32_t gid)
extern "C" int extern "C" int
setgid (__gid16_t gid) setgid (__gid16_t gid)
{ {
int ret = setegid32 ((__gid32_t) gid); int ret = setegid32 (gid16togid32 (gid));
if (!ret) if (!ret)
cygheap->user.real_gid = myself->gid; cygheap->user.real_gid = myself->gid;
return ret; return ret;

View File

@ -282,6 +282,12 @@ getlogin (void)
return strcpy (this_username, cygheap->user.name ()); return strcpy (this_username, cygheap->user.name ());
} }
extern "C" __uid32_t
getuid32 (void)
{
return cygheap->user.real_uid;
}
extern "C" __uid16_t extern "C" __uid16_t
getuid (void) getuid (void)
{ {
@ -300,6 +306,12 @@ getgid (void)
return cygheap->user.real_gid; return cygheap->user.real_gid;
} }
extern "C" __uid32_t
geteuid32 (void)
{
return myself->uid;
}
extern "C" __uid16_t extern "C" __uid16_t
geteuid (void) geteuid (void)
{ {

View File

@ -147,10 +147,19 @@ extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
/* UID/GID */ /* UID/GID */
void uinfo_init (void); void uinfo_init (void);
#define ILLEGAL_UID ((__uid16_t)-1) #define ILLEGAL_UID16 ((__uid16_t)-1)
#define ILLEGAL_UID ((__uid32_t)-1)
#define ILLEGAL_GID16 ((__gid16_t)-1)
#define ILLEGAL_GID ((__gid32_t)-1) #define ILLEGAL_GID ((__gid32_t)-1)
#define ILLEGAL_SEEK ((__off64_t)-1) #define ILLEGAL_SEEK ((__off64_t)-1)
#define uid16touid32(u16) ((u16)==ILLEGAL_UID16?ILLEGAL_UID:(__uid32_t)(u16))
#define gid16togid32(g16) ((g16)==ILLEGAL_GID16?ILLEGAL_GID:(__gid32_t)(g16))
extern "C" __uid32_t getuid32 (void);
extern "C" __uid32_t geteuid32 (void);
extern "C" struct passwd *getpwuid32 (__uid32_t);
/* various events */ /* various events */
void events_init (void); void events_init (void);
void events_terminate (void); void events_terminate (void);