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>
+ 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
definition.
* include/netinet/ip.h: Ditto.
class cygheap_exec_info
{
public:
- __uid16_t uid;
+ __uid32_t uid;
char *old_title;
int argc;
char **argv;
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
getegid32
geteuid
_geteuid = geteuid
+geteuid32
getgid
_getgid = getgid
getgid32
_gettimeofday = gettimeofday
getuid
_getuid = getuid
+getuid32
getutent
_getutent = getutent
getutid
_settimeofday = settimeofday
seteuid
_seteuid = seteuid
+seteuid32
setegid
_setegid = setegid
setegid32
setuid
_setuid = setuid
+setuid32
setutent
_setutent = setutent
chroot
getpwnam_r
getpwuid
_getpwuid = getpwuid
+getpwuid32
getpwuid_r
+getpwuid_r32
getpgrp
_getpgrp = getpgrp
getgrent
ep.strace_file = 0;
ep.process_state = p->process_state;
+
+ ep.uid32 = p->uid;
+ ep.gid32 = p->gid;
break;
}
}
{
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;
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)
#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
HANDLE strace_file;
DWORD process_state;
+
+ __uid32_t uid32;
+ __gid32_t gid32;
};
DWORD cygwin_internal (cygwin_getinfo_types, ...);
/* 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;
if (strcasematch (name, res->pw_name))
return res;
}
- else if (uid == res->pw_uid)
+ else if (uid == (__uid32_t) res->pw_uid)
return res;
}
}
extern "C" struct passwd *
-getpwuid (__uid16_t uid)
+getpwuid32 (__uid32_t uid)
{
if (passwd_state <= initializing)
read_etc_passwd ();
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;
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)
{
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))
PSID owner_sid;
PSID group_sid;
BOOL dummy;
- __uid16_t uid;
+ __uid32_t uid;
__gid32_t gid;
if (!GetSecurityDescriptorOwner (psd, &owner_sid, &dummy))
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)
}
}
if (id == -1)
- id = getuid ();
+ id = getuid32 ();
return id;
}
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,
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;
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;
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;
}
if (uidret)
- *uidret = getuid ();
+ *uidret = getuid32 ();
if (gidret)
*gidret = getgid32 ();
}
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;
/* 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))
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 ())
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;
/* 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);
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 *
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
*/
/* 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)
#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;
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;
* 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))
}
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);
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);
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);
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 */
/* 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 ())
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;
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))))
{
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)
extern "C" int
setegid (__gid16_t gid)
{
- return setegid32 ((__gid32_t) gid);
+ return setegid32 (gid16togid32 (gid));
}
/* setgid: POSIX 4.2.2.1 */
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;
return strcpy (this_username, cygheap->user.name ());
}
+extern "C" __uid32_t
+getuid32 (void)
+{
+ return cygheap->user.real_uid;
+}
+
extern "C" __uid16_t
getuid (void)
{
return cygheap->user.real_gid;
}
+extern "C" __uid32_t
+geteuid32 (void)
+{
+ return myself->uid;
+}
+
extern "C" __uid16_t
geteuid (void)
{
/* 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);