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>
* include/cygwin/socket.h: Protect some symbols against multiple

View File

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

View File

@ -96,9 +96,9 @@ class cygheap_user
PSID psid; /* buffer for user's SID */
PSID orig_psid; /* Remains intact even after impersonation */
public:
__uid16_t orig_uid; /* Remains intact even after impersonation */
__uid32_t orig_uid; /* Remains intact even after impersonation */
__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 */
/* 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
geteuid
_geteuid = geteuid
geteuid32
getgid
_getgid = getgid
getgid32
@ -389,6 +390,7 @@ gettimeofday
_gettimeofday = gettimeofday
getuid
_getuid = getuid
getuid32
getutent
_getutent = getutent
getutid
@ -682,11 +684,13 @@ settimeofday
_settimeofday = settimeofday
seteuid
_seteuid = seteuid
seteuid32
setegid
_setegid = setegid
setegid32
setuid
_setuid = setuid
setuid32
setutent
_setutent = setutent
chroot
@ -1019,7 +1023,9 @@ _getpwnam = getpwnam
getpwnam_r
getpwuid
_getpwuid = getpwuid
getpwuid32
getpwuid_r
getpwuid_r32
getpgrp
_getpgrp = getpgrp
getgrent

View File

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

View File

@ -126,7 +126,7 @@ fhandler_disk_file::fstat (struct __stat64 *buf, path_conv *pc)
{
int res = -1;
int oret;
__uid16_t uid;
__uid32_t uid;
__gid32_t gid;
int open_flags = O_RDONLY | O_BINARY | O_DIROPEN;
bool query_open_already;
@ -237,7 +237,7 @@ fhandler_disk_file::fstat_helper (struct __stat64 *buf, path_conv *pc,
else if (pc->issocket ())
buf->st_mode = S_IFSOCK;
__uid16_t uid;
__uid32_t uid;
__gid32_t gid;
if (get_file_attribute (pc->has_acls (), get_win32_name (), &buf->st_mode,
&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
typedef unsigned short __uid16_t;
typedef unsigned short __gid16_t;
typedef unsigned long __uid32_t;
typedef unsigned long __gid32_t;
#endif
struct external_pinfo
@ -236,6 +238,9 @@ struct external_pinfo
HANDLE strace_file;
DWORD process_state;
__uid32_t uid32;
__gid32_t gid32;
};
DWORD cygwin_internal (cygwin_getinfo_types, ...);

View File

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

View File

@ -158,7 +158,7 @@ setacl (const char *file, int nentries, __aclent16_t *aclbufp)
break;
case USER:
case DEF_USER:
if (!(pw = getpwuid (aclbufp[i].a_id))
if (!(pw = getpwuid32 (aclbufp[i].a_id))
|| !sid.getfrompw (pw)
|| !add_access_allowed_ace (acl, ace_off++, allow,
sid, acl_len, inheritance))
@ -255,7 +255,7 @@ getacl (const char *file, DWORD attr, int nentries, __aclent16_t *aclbufp)
PSID owner_sid;
PSID group_sid;
BOOL dummy;
__uid16_t uid;
__uid32_t uid;
__gid32_t gid;
if (!GetSecurityDescriptorOwner (psd, &owner_sid, &dummy))
@ -426,7 +426,7 @@ acl_access (const char *path, int flags)
struct passwd *pw;
struct __group32 *gr = NULL;
if ((pw = getpwuid (acls[i].a_id)) != NULL
if ((pw = getpwuid32 (acls[i].a_id)) != NULL
&& owner.getfrompw (pw))
{
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)
id = getuid ();
id = getuid32 ();
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 *);
BOOL grp_member = TRUE;
struct passwd *pw = getpwuid (uid);
struct passwd *pw = getpwuid32 (uid);
__gid32_t grps[NGROUPS_MAX];
int cnt = getgroups32 (NGROUPS_MAX, grps,
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
get_nt_attribute (const char *file, int *attribute,
__uid16_t *uidret, __gid32_t *gidret)
__uid32_t *uidret, __gid32_t *gidret)
{
if (!wincap.has_security ())
return 0;
@ -1168,7 +1168,7 @@ get_nt_attribute (const char *file, int *attribute,
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 ();
if (uidret)
*uidret = uid;
@ -1279,7 +1279,7 @@ get_nt_attribute (const char *file, int *attribute,
int
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;
@ -1292,7 +1292,7 @@ get_file_attribute (int use_ntsec, const char *file,
}
if (uidret)
*uidret = getuid ();
*uidret = getuid32 ();
if (gidret)
*gidret = getgid32 ();
@ -1350,7 +1350,7 @@ add_access_denied_ace (PACL acl, int offset, DWORD attributes,
}
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)
{
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. */
char owner[UNLEN + 1];
cygsid owner_sid;
struct passwd *pw = getpwuid (uid);
struct passwd *pw = getpwuid32 (uid);
strcpy (owner, pw ? pw->pw_name : getlogin ());
if ((!pw || !owner_sid.getfrompw (pw))
&& !lookup_name (owner, logsrv, owner_sid))
@ -1612,14 +1612,14 @@ set_security_attribute (int attribute, PSECURITY_ATTRIBUTES psa,
psa->lpSecurityDescriptor = sd_buf;
InitializeSecurityDescriptor ((PSECURITY_DESCRIPTOR)sd_buf,
SECURITY_DESCRIPTOR_REVISION);
psa->lpSecurityDescriptor = alloc_sd (geteuid (), getegid32 (),
psa->lpSecurityDescriptor = alloc_sd (geteuid32 (), getegid32 (),
cygheap->user.logsrv (),
attribute, (PSECURITY_DESCRIPTOR)sd_buf,
&sd_buf_size);
}
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)
{
if (!wincap.has_security ())
@ -1645,7 +1645,7 @@ set_nt_attribute (const char *file, __uid16_t uid, __gid32_t gid,
int
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 ret = 0;

View File

@ -166,9 +166,9 @@ extern struct __group32 *internal_getgrent (int);
/* File manipulation */
int __stdcall set_process_privileges ();
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 *, __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 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);
@ -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);
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);
extern inline SECURITY_ATTRIBUTES *

View File

@ -442,7 +442,7 @@ shmctl (int shmid, int cmd, struct shmid_ds *buf)
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
* 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 */
InitializeSecurityDescriptor (psd,
SECURITY_DESCRIPTOR_REVISION);
psd = alloc_sd (getuid (), getgid32 (), cygheap->user.logsrv (),
psd = alloc_sd (getuid32 (), getgid32 (), cygheap->user.logsrv (),
shmflg & 0x01ff, psd, &sd_size);
if (key == (key_t) - 1)
@ -538,7 +538,7 @@ shmget (key_t key, size_t size, int shmflg)
#if 0
/* 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.cgid = getgid32 ();
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");
if (!hToken)
{
ciresrv.moreinfo->uid = getuid ();
ciresrv.moreinfo->uid = getuid32 ();
/* FIXME: This leaks a handle in the CreateProcessAsUser case since the
child process doesn't know about 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.
*/
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;
__uid16_t old_uid;
__uid32_t old_uid;
__gid32_t old_gid;
if (check_null_empty_str_errno (name))
@ -815,7 +815,7 @@ done:
}
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);
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)
{
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
lchown32 (const char * name, __uid16_t uid, __gid32_t gid)
lchown32 (const char * name, __uid32_t uid, __gid32_t gid)
{
sigframe thisframe (mainthread);
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)
{
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
fchown32 (int fd, __uid16_t uid, __gid32_t gid)
fchown32 (int fd, __uid32_t uid, __gid32_t gid)
{
sigframe thisframe (mainthread);
cygheap_fdget cfd (fd);
@ -870,7 +870,7 @@ fchown32 (int fd, __uid16_t uid, __gid32_t gid)
extern "C" int
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 */
@ -914,7 +914,7 @@ chmod (const char *path, mode_t mode)
/* temporary erase read only bit, to be able to set file security */
SetFileAttributes (win32_path, (DWORD) win32_path & ~FILE_ATTRIBUTE_READONLY);
__uid16_t uid;
__uid32_t uid;
__gid32_t gid;
if (win32_path.isdir ())
@ -1932,22 +1932,11 @@ mkfifo (const char *_path, mode_t mode)
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);
/* seteuid: standards? */
extern "C" int
seteuid (__uid16_t uid)
seteuid32 (__uid32_t uid)
{
if (!wincap.has_security ()) return 0;
@ -1974,7 +1963,7 @@ seteuid (__uid16_t uid)
debug_printf ("uid: %d myself->gid: %d", uid, myself->gid);
pw_new = getpwuid (uid);
pw_new = getpwuid32 (uid);
if (!usersid.getfrompw (pw_new) ||
(!pgrpsid.getfromgr (getgrgid32 (myself->gid))))
{
@ -2145,6 +2134,29 @@ seteuid (__uid16_t uid)
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. */
extern "C" int
setegid32 (__gid32_t gid)
@ -2197,7 +2209,7 @@ setegid32 (__gid32_t gid)
extern "C" int
setegid (__gid16_t gid)
{
return setegid32 ((__gid32_t) gid);
return setegid32 (gid16togid32 (gid));
}
/* setgid: POSIX 4.2.2.1 */
@ -2213,7 +2225,7 @@ setgid32 (__gid32_t gid)
extern "C" int
setgid (__gid16_t gid)
{
int ret = setegid32 ((__gid32_t) gid);
int ret = setegid32 (gid16togid32 (gid));
if (!ret)
cygheap->user.real_gid = myself->gid;
return ret;

View File

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

View File

@ -147,10 +147,19 @@ extern "C" void __stdcall do_exit (int) __attribute__ ((noreturn));
/* UID/GID */
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_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 */
void events_init (void);
void events_terminate (void);