From 8a266a478e47089e7752c10e5baae7b90b0e0b6d Mon Sep 17 00:00:00 2001 From: Thomas Veerman Date: Mon, 5 Sep 2011 13:56:14 +0000 Subject: [PATCH] Increase gid_t and uid_t to 32 bits Increase gid_t and uid_t to 32 bits and provide backwards compatibility where needed. --- bin/mkdir/minix-port.patch | 0 common/include/minix/callnr.h | 9 ++- include/limits.h | 3 + include/minix/types.h | 4 +- include/net/ioctl.h | 1 + include/sys/stat.h | 2 +- include/sys/ucred.h | 13 +++- lib/libc/other/fslib.c | 8 +-- lib/libc/posix/_getgroups.c | 2 +- lib/nbsd_libc/gen/getgrent.c | 44 ------------ lib/nbsd_libc/gen/getgroupmembership.c | 24 ------- lib/nbsd_libc/gen/getpwent.c | 48 ------------- lib/nbsd_libminlib/fslib.c | 8 +-- nbsd_include/sys/ansi.h | 4 +- nbsd_include/sys/stat.h | 2 +- nbsd_include/sys/syslimits.h | 4 +- nbsd_include/sys/ucred.h | 13 ++-- servers/apfs/dev_uds.c | 7 ++ servers/apfs/proto.h | 2 + servers/apfs/uds.c | 48 +++++++++++++ servers/avfs/protect.c | 8 ++- servers/mfs/cache.c | 4 +- servers/mfs/inode.h | 18 ++--- servers/mfs/main.c | 2 + servers/mfs/stadir.c | 8 +-- servers/pfs/dev_uds.c | 7 ++ servers/pfs/proto.h | 2 + servers/pfs/uds.c | 48 +++++++++++++ servers/pm/getset.c | 99 +++++++++++++++++++++----- servers/pm/misc.c | 39 ++++++++-- servers/pm/proto.h | 1 + servers/pm/table.c | 22 +++--- servers/vfs/main.c | 2 +- servers/vfs/protect.c | 13 ++-- servers/vfs/table.c | 18 ++--- test/test46.c | 36 ++++------ 36 files changed, 339 insertions(+), 234 deletions(-) delete mode 100644 bin/mkdir/minix-port.patch diff --git a/bin/mkdir/minix-port.patch b/bin/mkdir/minix-port.patch deleted file mode 100644 index e69de29bb..000000000 diff --git a/common/include/minix/callnr.h b/common/include/minix/callnr.h index 0236fcf04..5af4baaa8 100644 --- a/common/include/minix/callnr.h +++ b/common/include/minix/callnr.h @@ -30,7 +30,10 @@ #define PREV_FSTAT 28 #define PAUSE 29 #define UTIME 30 +#define GETEPINFO 31 +#define SETGROUPS 32 #define ACCESS 33 +#define GETGROUPS 34 #define SYNC 36 #define KILL 37 #define RENAME 38 @@ -54,8 +57,8 @@ #define SETSID 62 #define GETPGRP 63 #define ITIMER 64 -#define GETGROUPS 65 -#define SETGROUPS 66 +#define GETGROUPS_O 65 +#define SETGROUPS_O 66 #define GETMCONTEXT 67 #define SETMCONTEXT 68 @@ -100,7 +103,7 @@ #define PROCSTAT 103 /* to PM */ #define GETPROCNR 104 /* to PM */ -#define GETEPINFO 107 /* to PM: get pid/uid/gid of an endpoint */ +#define GETEPINFO_O 107 /* to PM: get pid/uid/gid of an endpoint */ #define ADDDMA 108 /* to PM: inform PM about a region of memory * that is used for bus-master DMA */ diff --git a/include/limits.h b/include/limits.h index 3a69ea2e1..792d3c1d8 100644 --- a/include/limits.h +++ b/include/limits.h @@ -113,4 +113,7 @@ #define IOV_MAX INT_MAX /* maximum number of buffers for readv/writev */ #endif /* _POSIX_SOURCE */ +#define GID_MAX USHRT_MAX +#define UID_MAX USHRT_MAX + #endif /* _LIMITS_H */ diff --git a/include/minix/types.h b/include/minix/types.h index 4c46763dd..1c7ba40be 100644 --- a/include/minix/types.h +++ b/include/minix/types.h @@ -104,7 +104,7 @@ typedef u32_t big_dev_t; /* Types used in disk, inode, etc. data structures. * Some u64_t should be i64_t, but anyway with old libc we use .lo only. */ -typedef char gid_t; /* group id */ +typedef u32_t gid_t; /* group id */ typedef u32_t big_gid_t; /* group id */ typedef unsigned long ino_t; /* i-node number (V3 filesystem) */ typedef u64_t big_ino_t; /* i-node number (V3 filesystem) */ @@ -115,7 +115,7 @@ typedef u32_t big_nlink_t;/* number of links to a file */ typedef long off_t; /* offset within a file */ typedef u64_t big_off_t; /* offset within a file */ typedef int pid_t; /* process id (must be signed) */ -typedef short uid_t; /* user id */ +typedef u32_t uid_t; /* user id */ typedef u32_t big_uid_t; /* user id */ typedef unsigned long fsblkcnt_t; /* File system block count */ typedef unsigned long fsfilcnt_t; /* File system file count */ diff --git a/include/net/ioctl.h b/include/net/ioctl.h index 71ca4752b..9efb13a66 100644 --- a/include/net/ioctl.h +++ b/include/net/ioctl.h @@ -84,6 +84,7 @@ struct msg_control /* setsockopt/setsockopt for unix domain sockets */ #define NWIOGUDSSOTYPE _IOR('n', 90, int) /* SO_TYPE */ +#define NWIOGUDSPEERCREDOLD _IOR('n', 91, struct ucred_old) /* SO_PEERCRED */ #define NWIOGUDSPEERCRED _IOR('n', 91, struct ucred) /* SO_PEERCRED */ #define NWIOGUDSSNDBUF _IOR('n', 92, size_t) /* SO_SNDBUF */ #define NWIOSUDSSNDBUF _IOW('n', 93, size_t) /* SO_SNDBUF */ diff --git a/include/sys/stat.h b/include/sys/stat.h index ee7b7fc8a..71e4a43ac 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -51,7 +51,7 @@ struct minix_prev_stat { ino_t st_ino; /* i-node number */ mode_t st_mode; /* file mode, protection bits, etc. */ nlink_t st_nlink; /* # links; */ - uid_t st_uid; /* uid of the file's owner */ + short st_uid; /* uid of the file's owner */ short int st_gid; /* gid; TEMPORARY HACK: should be gid_t */ short st_rdev; off_t st_size; /* file size */ diff --git a/include/sys/ucred.h b/include/sys/ucred.h index c88422d02..5babf6fb5 100644 --- a/include/sys/ucred.h +++ b/include/sys/ucred.h @@ -1,11 +1,18 @@ #ifndef __SYS_UCRED_H #define __SYS_UCRED_H -struct ucred +struct ucred_old { pid_t pid; - uid_t uid; - gid_t gid; + short uid; + char gid; +}; + +struct ucred +{ + pid_t pid; + uid_t uid; + gid_t gid; }; #endif diff --git a/lib/libc/other/fslib.c b/lib/libc/other/fslib.c index bcbcd24c5..0ef6ad30b 100644 --- a/lib/libc/other/fslib.c +++ b/lib/libc/other/fslib.c @@ -164,9 +164,9 @@ int norm; /* TRUE = do not swap bytes; FALSE = swap */ if (direction == READING) { /* Copy V2.x inode to the in-core table, swapping bytes if need be. */ rip->i_mode = conv2(norm,dip->d2_mode); - rip->i_uid = conv2(norm,dip->d2_uid ); + rip->i_uid = conv4(norm,dip->d2_uid ); rip->i_nlinks = conv2(norm,(int) dip->d2_nlinks); - rip->i_gid = conv2(norm,(int) dip->d2_gid ); + rip->i_gid = conv4(norm,(int) dip->d2_gid ); rip->i_size = conv4(norm,dip->d2_size); rip->i_atime = conv4(norm,dip->d2_atime); rip->i_ctime = conv4(norm,dip->d2_ctime); @@ -178,9 +178,9 @@ int norm; /* TRUE = do not swap bytes; FALSE = swap */ } else { /* Copying V2.x inode to disk from the in-core table. */ dip->d2_mode = conv2(norm,rip->i_mode); - dip->d2_uid = conv2(norm,rip->i_uid ); + dip->d2_uid = conv4(norm,rip->i_uid ); dip->d2_nlinks = conv2(norm,rip->i_nlinks); - dip->d2_gid = conv2(norm,rip->i_gid ); + dip->d2_gid = conv4(norm,rip->i_gid ); dip->d2_size = conv4(norm,rip->i_size); dip->d2_atime = conv4(norm,rip->i_atime); dip->d2_ctime = conv4(norm,rip->i_ctime); diff --git a/lib/libc/posix/_getgroups.c b/lib/libc/posix/_getgroups.c index 27d2d6a53..39a7c6362 100644 --- a/lib/libc/posix/_getgroups.c +++ b/lib/libc/posix/_getgroups.c @@ -10,7 +10,7 @@ PUBLIC int getgroups(int ngroups, gid_t *arr) { message m; m.m1_i1 = ngroups; - m.m1_p1 = arr; + m.m1_p1 = (char *) arr; return(_syscall(PM_PROC_NR, GETGROUPS, &m)); } diff --git a/lib/nbsd_libc/gen/getgrent.c b/lib/nbsd_libc/gen/getgrent.c index de0c9ea51..9e2b6957f 100644 --- a/lib/nbsd_libc/gen/getgrent.c +++ b/lib/nbsd_libc/gen/getgrent.c @@ -481,11 +481,7 @@ static int _files_getgrgid(void *nsrv, void *nscb, va_list ap) { struct group **retval = va_arg(ap, struct group **); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif int rv, rerror; @@ -510,11 +506,7 @@ static int _files_getgrgid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif struct group *grp = va_arg(ap, struct group *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -809,11 +801,7 @@ static int _dns_getgrgid(void *nsrv, void *nscb, va_list ap) { struct group **retval = va_arg(ap, struct group **); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif int rv, rerror; @@ -837,11 +825,7 @@ static int _dns_getgrgid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif struct group *grp = va_arg(ap, struct group *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -1164,11 +1148,7 @@ static int _nis_getgrgid(void *nsrv, void *nscb, va_list ap) { struct group **retval = va_arg(ap, struct group **); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif int rv, rerror; @@ -1192,11 +1172,7 @@ static int _nis_getgrgid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif struct group *grp = va_arg(ap, struct group *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -1432,11 +1408,7 @@ __grscan_compat(int *retval, struct group *grp, char *buffer, size_t buflen, crv = nsdispatch(NULL, compatgiddtab, NSDB_GROUP_COMPAT, "getgrgid_r", __nsdefaultnis, -#ifdef __minix - &cretval, (int)gid, -#else &cretval, gid, -#endif &cgrp, filebuf, sizeof(filebuf), &cgrpres); } if (crv != NS_SUCCESS) { /* not found */ @@ -1638,11 +1610,7 @@ static int _compat_getgrgid(void *nsrv, void *nscb, va_list ap) { struct group **retval = va_arg(ap, struct group **); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif int rv, rerror; @@ -1667,11 +1635,7 @@ static int _compat_getgrgid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - gid_t gid = (gid_t)va_arg(ap, int); -#else gid_t gid = va_arg(ap, gid_t); -#endif struct group *grp = va_arg(ap, struct group *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -1821,11 +1785,7 @@ getgrgid(gid_t gid) mutex_lock(&__grmutex); rv = nsdispatch(NULL, dtab, NSDB_GROUP, "getgrgid", __nsdefaultcompat, -#ifdef __minix - &retval, (int)gid); -#else &retval, gid); -#endif mutex_unlock(&__grmutex); return (rv == NS_SUCCESS) ? retval : NULL; } @@ -1852,11 +1812,7 @@ getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t buflen, retval = 0; mutex_lock(&__grmutex); rv = nsdispatch(NULL, dtab, NSDB_GROUP, "getgrgid_r", __nsdefaultcompat, -#ifdef __minix - &retval, (int)gid, grp, buffer, buflen, result); -#else &retval, gid, grp, buffer, buflen, result); -#endif mutex_unlock(&__grmutex); switch (rv) { case NS_SUCCESS: diff --git a/lib/nbsd_libc/gen/getgroupmembership.c b/lib/nbsd_libc/gen/getgroupmembership.c index 2c8a40540..78687c0a5 100644 --- a/lib/nbsd_libc/gen/getgroupmembership.c +++ b/lib/nbsd_libc/gen/getgroupmembership.c @@ -101,11 +101,7 @@ _files_getgroupmembership(void *retval, void *cb_data, va_list ap) { int *result = va_arg(ap, int *); const char *uname = va_arg(ap, const char *); -#ifdef __minix - gid_t agroup = (gid_t)va_arg(ap, int); -#else gid_t agroup = va_arg(ap, gid_t); -#endif gid_t *groups = va_arg(ap, gid_t *); int maxgrp = va_arg(ap, int); int *groupc = va_arg(ap, int *); @@ -148,11 +144,7 @@ _dns_getgroupmembership(void *retval, void *cb_data, va_list ap) { int *result = va_arg(ap, int *); const char *uname = va_arg(ap, const char *); -#ifdef __minix - gid_t agroup = (gid_t)va_arg(ap, int); -#else gid_t agroup = va_arg(ap, gid_t); -#endif gid_t *groups = va_arg(ap, gid_t *); int maxgrp = va_arg(ap, int); int *groupc = va_arg(ap, int *); @@ -245,11 +237,7 @@ _nis_getgroupmembership(void *retval, void *cb_data, va_list ap) { int *result = va_arg(ap, int *); const char *uname = va_arg(ap, const char *); -#ifdef __minix - gid_t agroup = (gid_t)va_arg(ap, int); -#else gid_t agroup = va_arg(ap, gid_t); -#endif gid_t *groups = va_arg(ap, gid_t *); int maxgrp = va_arg(ap, int); int *groupc = va_arg(ap, int *); @@ -317,11 +305,7 @@ _compat_ggm_search(void *cookie, struct group **groupres) crv = nsdispatch(NULL, dtab, NSDB_GROUP_COMPAT, "getgroupmembership", __nsdefaultnis, -#ifdef __minix - &rerror, cp->uname, (int)cp->agroup, cp->groups, cp->maxgrp, cp->groupc); -#else &rerror, cp->uname, cp->agroup, cp->groups, cp->maxgrp, cp->groupc); -#endif if (crv == NS_SUCCESS) crv = NS_NOTFOUND; /* indicate "no more +: entries" */ @@ -335,11 +319,7 @@ _compat_getgroupmembership(void *retval, void *cb_data, va_list ap) { int *result = va_arg(ap, int *); const char *uname = va_arg(ap, const char *); -#ifdef __minix - gid_t agroup = (gid_t)va_arg(ap, int); -#else gid_t agroup = va_arg(ap, gid_t); -#endif gid_t *groups = va_arg(ap, gid_t *); int maxgrp = va_arg(ap, int); int *groupc = va_arg(ap, int *); @@ -415,11 +395,7 @@ getgroupmembership(const char *uname, gid_t agroup, */ (void) nsdispatch(NULL, dtab, NSDB_GROUP, "getgroupmembership", __nsdefaultcompat, -#ifdef __minix - &rerror, uname, (int)agroup, groups, maxgrp, groupc); -#else &rerror, uname, agroup, groups, maxgrp, groupc); -#endif mutex_unlock(&__grmutex); if (*groupc > maxgrp) /* too many groups found */ diff --git a/lib/nbsd_libc/gen/getpwent.c b/lib/nbsd_libc/gen/getpwent.c index 1250fc73a..44abb45fd 100644 --- a/lib/nbsd_libc/gen/getpwent.c +++ b/lib/nbsd_libc/gen/getpwent.c @@ -671,11 +671,7 @@ static int _files_getpwuid(void *nsrv, void *nscb, va_list ap) { struct passwd **retval = va_arg(ap, struct passwd **); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif int rv, rerror; @@ -700,11 +696,7 @@ static int _files_getpwuid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif struct passwd *pw = va_arg(ap, struct passwd *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -1000,11 +992,7 @@ static int _dns_getpwuid(void *nsrv, void *nscb, va_list ap) { struct passwd **retval = va_arg(ap, struct passwd **); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif int rv, rerror; @@ -1031,11 +1019,7 @@ static int _dns_getpwuid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif struct passwd *pw = va_arg(ap, struct passwd *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -1524,11 +1508,7 @@ static int _nis_getpwuid(void *nsrv, void *nscb, va_list ap) { struct passwd **retval = va_arg(ap, struct passwd **); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif int rv, rerror; @@ -1554,11 +1534,7 @@ static int _nis_getpwuid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif struct passwd *pw = va_arg(ap, struct passwd *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -1920,15 +1896,9 @@ _passwdcompat_pwscan(struct passwd *pw, char *buffer, size_t buflen, &crv, name, pw, buffer, buflen, &cpw); break; case _PW_KEYBYUID: -#ifdef __minix - rv = nsdispatch(NULL, compatuiddtab, - NSDB_PASSWD_COMPAT, "getpwuid_r", __nsdefaultnis, - &crv, (int)uid, pw, buffer, buflen, &cpw); -#else rv = nsdispatch(NULL, compatuiddtab, NSDB_PASSWD_COMPAT, "getpwuid_r", __nsdefaultnis, &crv, uid, pw, buffer, buflen, &cpw); -#endif break; default: abort(); @@ -2331,11 +2301,7 @@ static int _compat_getpwuid(void *nsrv, void *nscb, va_list ap) { struct passwd **retval = va_arg(ap, struct passwd **); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif int rv, rerror; @@ -2360,11 +2326,7 @@ static int _compat_getpwuid_r(void *nsrv, void *nscb, va_list ap) { int *retval = va_arg(ap, int *); -#ifdef __minix - uid_t uid = (uid_t)va_arg(ap, int); -#else uid_t uid = va_arg(ap, uid_t); -#endif struct passwd *pw = va_arg(ap, struct passwd *); char *buffer = va_arg(ap, char *); size_t buflen = va_arg(ap, size_t); @@ -2520,13 +2482,8 @@ getpwuid(uid_t uid) }; mutex_lock(&_pwmutex); -#ifdef __minix - rv = nsdispatch(NULL, dtab, NSDB_PASSWD, "getpwuid", __nsdefaultcompat, - &retval, (int)uid); -#else rv = nsdispatch(NULL, dtab, NSDB_PASSWD, "getpwuid", __nsdefaultcompat, &retval, uid); -#endif mutex_unlock(&_pwmutex); return (rv == NS_SUCCESS) ? retval : NULL; } @@ -2552,13 +2509,8 @@ getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t buflen, *result = NULL; retval = 0; mutex_lock(&_pwmutex); -#ifdef __minix - r = nsdispatch(NULL, dtab, NSDB_PASSWD, "getpwuid_r", __nsdefaultcompat, - &retval, (int)uid, pwd, buffer, buflen, result); -#else r = nsdispatch(NULL, dtab, NSDB_PASSWD, "getpwuid_r", __nsdefaultcompat, &retval, uid, pwd, buffer, buflen, result); -#endif mutex_unlock(&_pwmutex); switch (r) { diff --git a/lib/nbsd_libminlib/fslib.c b/lib/nbsd_libminlib/fslib.c index bcbcd24c5..0ef6ad30b 100644 --- a/lib/nbsd_libminlib/fslib.c +++ b/lib/nbsd_libminlib/fslib.c @@ -164,9 +164,9 @@ int norm; /* TRUE = do not swap bytes; FALSE = swap */ if (direction == READING) { /* Copy V2.x inode to the in-core table, swapping bytes if need be. */ rip->i_mode = conv2(norm,dip->d2_mode); - rip->i_uid = conv2(norm,dip->d2_uid ); + rip->i_uid = conv4(norm,dip->d2_uid ); rip->i_nlinks = conv2(norm,(int) dip->d2_nlinks); - rip->i_gid = conv2(norm,(int) dip->d2_gid ); + rip->i_gid = conv4(norm,(int) dip->d2_gid ); rip->i_size = conv4(norm,dip->d2_size); rip->i_atime = conv4(norm,dip->d2_atime); rip->i_ctime = conv4(norm,dip->d2_ctime); @@ -178,9 +178,9 @@ int norm; /* TRUE = do not swap bytes; FALSE = swap */ } else { /* Copying V2.x inode to disk from the in-core table. */ dip->d2_mode = conv2(norm,rip->i_mode); - dip->d2_uid = conv2(norm,rip->i_uid ); + dip->d2_uid = conv4(norm,rip->i_uid ); dip->d2_nlinks = conv2(norm,rip->i_nlinks); - dip->d2_gid = conv2(norm,rip->i_gid ); + dip->d2_gid = conv4(norm,rip->i_gid ); dip->d2_size = conv4(norm,rip->i_size); dip->d2_atime = conv4(norm,rip->i_atime); dip->d2_ctime = conv4(norm,rip->i_ctime); diff --git a/nbsd_include/sys/ansi.h b/nbsd_include/sys/ansi.h index 2f9365892..c17ca9e2a 100644 --- a/nbsd_include/sys/ansi.h +++ b/nbsd_include/sys/ansi.h @@ -35,7 +35,7 @@ #include typedef char * __caddr_t; /* core address */ -typedef char __gid_t; /* group id */ +typedef __uint32_t __gid_t; /* group id */ typedef __uint32_t __in_addr_t; /* IP(v4) address */ typedef __uint16_t __in_port_t; /* "Internet" port number */ typedef unsigned short __mode_t; /* file permissions */ @@ -43,7 +43,7 @@ typedef long __off_t; /* file offset */ typedef int __pid_t; /* process id */ typedef __uint8_t __sa_family_t; /* socket address family */ typedef __int32_t __socklen_t; /* socket-related datum length */ -typedef short __uid_t; /* user id */ +typedef __uint32_t __uid_t; /* user id */ typedef unsigned long __fsblkcnt_t; /* fs block count (statvfs) */ typedef unsigned long __fsfilcnt_t; /* fs file count */ diff --git a/nbsd_include/sys/stat.h b/nbsd_include/sys/stat.h index fd89f9def..79bb8e58b 100644 --- a/nbsd_include/sys/stat.h +++ b/nbsd_include/sys/stat.h @@ -46,7 +46,7 @@ struct minix_prev_stat { ino_t st_ino; /* i-node number */ mode_t st_mode; /* file mode, protection bits, etc. */ nlink_t st_nlink; /* # links; */ - uid_t st_uid; /* uid of the file's owner */ + short st_uid; /* uid of the file's owner */ short int st_gid; /* gid; TEMPORARY HACK: should be gid_t */ short st_rdev; off_t st_size; /* file size */ diff --git a/nbsd_include/sys/syslimits.h b/nbsd_include/sys/syslimits.h index 117eadbcf..4fb0039dc 100644 --- a/nbsd_include/sys/syslimits.h +++ b/nbsd_include/sys/syslimits.h @@ -22,13 +22,13 @@ #define CHILD_MAX _NO_LIMIT /* max simultaneous processes */ #endif -#define GID_MAX CHAR_MAX /* max value for a gid_t */ +#define GID_MAX USHRT_MAX /* max value for a gid_t */ #define LINK_MAX SHRT_MAX /* # links a file may have */ #define MAX_CANON 255 /* size of the canonical input queue */ #define MAX_INPUT 255 /* size of the type-ahead buffer */ #define NAME_MAX 255 /* system-wide max # chars in a file name */ #define NGROUPS_MAX 8 /* max. number of supplemental groups */ -#define UID_MAX SHRT_MAX /* max value for a uid_t */ +#define UID_MAX USHRT_MAX /* max value for a uid_t */ #ifndef OPEN_MAX #define OPEN_MAX __MINIX_OPEN_MAX /* max open files per process */ #endif diff --git a/nbsd_include/sys/ucred.h b/nbsd_include/sys/ucred.h index 15cda1ff9..5babf6fb5 100644 --- a/nbsd_include/sys/ucred.h +++ b/nbsd_include/sys/ucred.h @@ -1,13 +1,18 @@ #ifndef __SYS_UCRED_H #define __SYS_UCRED_H -#include +struct ucred_old +{ + pid_t pid; + short uid; + char gid; +}; struct ucred { - pid_t pid; - uid_t uid; - gid_t gid; + pid_t pid; + uid_t uid; + gid_t gid; }; #endif diff --git a/servers/apfs/dev_uds.c b/servers/apfs/dev_uds.c index e16ad099c..05b3adf25 100644 --- a/servers/apfs/dev_uds.c +++ b/servers/apfs/dev_uds.c @@ -876,6 +876,13 @@ PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out) break; + case NWIOGUDSPEERCREDOLD: + + /* get peer endpoint -- getsockopt(SO_PEERCRED) */ + rc = do_getsockopt_peercred_old(dev_m_in, dev_m_out); + + break; + case NWIOSUDSTADDR: /* set target address -- sendto() */ diff --git a/servers/apfs/proto.h b/servers/apfs/proto.h index e0da81367..210e9d1d4 100644 --- a/servers/apfs/proto.h +++ b/servers/apfs/proto.h @@ -85,6 +85,8 @@ _PROTOTYPE( int do_getsockopt_sotype, (message *dev_m_in, message *dev_m_out) ); _PROTOTYPE( int do_getsockopt_peercred, (message *dev_m_in, message *dev_m_out) ); +_PROTOTYPE( int do_getsockopt_peercred_old, + (message *dev_m_in, message *dev_m_out) ); _PROTOTYPE( int do_getsockopt_sndbuf, (message *dev_m_in, message *dev_m_out) ); _PROTOTYPE( int do_setsockopt_sndbuf, diff --git a/servers/apfs/uds.c b/servers/apfs/uds.c index 67e5ae255..18c70e103 100644 --- a/servers/apfs/uds.c +++ b/servers/apfs/uds.c @@ -1045,6 +1045,54 @@ PUBLIC int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out) return rc ? EIO : OK; } +PUBLIC int do_getsockopt_peercred_old(message *dev_m_in, message *dev_m_out) +{ + int minor; + int peer_minor; + int rc; + struct ucred cred; + struct ucred_old cred_old; + +#if DEBUG == 1 + static int call_count = 0; + printf("(uds) [%d] do_getsockopt_peercred() call_count=%d\n", + uds_minor(dev_m_in), ++call_count); +#endif + + minor = uds_minor(dev_m_in); + + if (uds_fd_table[minor].peer == -1) { + + if (uds_fd_table[minor].err == ECONNRESET) { + uds_fd_table[minor].err = 0; + + return ECONNRESET; + } else { + return ENOTCONN; + } + } + + peer_minor = uds_fd_table[minor].peer; + + /* obtain the peer's credentials */ + rc = getnucred(uds_fd_table[peer_minor].owner, &cred); + if (rc == -1) { + /* likely error: invalid endpoint / proc doesn't exist */ + return errno; + } + + /* copy to old structure */ + cred_old.pid = cred.pid; + cred_old.uid = (short) cred.uid; + cred_old.gid = (char) cred.gid; + + rc = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT, + (vir_bytes) 0, (vir_bytes) &cred_old, sizeof(struct ucred_old), + D); + + return rc ? EIO : OK; +} + int do_getsockopt_sndbuf(message *dev_m_in, message *dev_m_out) { int minor; diff --git a/servers/avfs/protect.c b/servers/avfs/protect.c index 300a47d31..3f8c3838e 100644 --- a/servers/avfs/protect.c +++ b/servers/avfs/protect.c @@ -137,8 +137,11 @@ PUBLIC int do_chown() /* Do not change uid/gid if new uid/gid is -1. */ uid = (m_in.owner == (uid_t)-1 ? vp->v_uid : m_in.owner); gid = (m_in.group == (gid_t)-1 ? vp->v_gid : m_in.group); - if ((r = req_chown(vp->v_fs_e, vp->v_inode_nr, uid, gid, - &new_mode)) == OK) { + + if (uid > UID_MAX || gid > GID_MAX) + r = EINVAL; + else if ((r = req_chown(vp->v_fs_e, vp->v_inode_nr, uid, gid, + &new_mode)) == OK) { vp->v_uid = uid; vp->v_gid = gid; vp->v_mode = new_mode; @@ -156,7 +159,6 @@ PUBLIC int do_chown() return(r); } - /*===========================================================================* * do_umask * *===========================================================================*/ diff --git a/servers/mfs/cache.c b/servers/mfs/cache.c index 5e9f00387..3a6898db7 100644 --- a/servers/mfs/cache.c +++ b/servers/mfs/cache.c @@ -352,7 +352,7 @@ int rw_flag; /* READING or WRITING */ op = (rw_flag == READING ? MFS_DEV_READ : MFS_DEV_WRITE); r = block_dev_io(op, dev, SELF_E, bp->b_data, pos, fs_block_size); if (r < 0) { - printf("MFS(%d) I/O error on device %d/%d, block %lu\n", + printf("MFS(%d) I/O error on device %d/%d, block %u\n", SELF_E, major(dev), minor(dev), bp->b_blocknr); op_failed = 1; } else if( (unsigned) r != fs_block_size) { @@ -480,7 +480,7 @@ PUBLIC void rw_scattered( /* Transfer failed. An error? Do we care? */ if (r != OK && i == 0) { printf( - "MFS: I/O error on device %d/%d, block %lu\n", + "MFS: I/O error on device %d/%d, block %u\n", major(dev), minor(dev), bp->b_blocknr); bp->b_dev = NO_DEV; /* invalidate block */ vm_forgetblocks(); diff --git a/servers/mfs/inode.h b/servers/mfs/inode.h index f66532c3a..d6a527f6d 100644 --- a/servers/mfs/inode.h +++ b/servers/mfs/inode.h @@ -17,15 +17,15 @@ #include EXTERN struct inode { - mode_t i_mode; /* file type, protection, etc. */ - nlink_t i_nlinks; /* how many links to this file */ - uid_t i_uid; /* user id of the file's owner */ - gid_t i_gid; /* group number */ - off_t i_size; /* current file size in bytes */ - time_t i_atime; /* time of last access (V2 only) */ - time_t i_mtime; /* when was file data last changed */ - time_t i_ctime; /* when was inode itself changed (V2 only)*/ - zone_t i_zone[V2_NR_TZONES]; /* zone numbers for direct, ind, and dbl ind */ + u16_t i_mode; /* file type, protection, etc. */ + u16_t i_nlinks; /* how many links to this file */ + u16_t i_uid; /* user id of the file's owner */ + u16_t i_gid; /* group number */ + i32_t i_size; /* current file size in bytes */ + u32_t i_atime; /* time of last access (V2 only) */ + u32_t i_mtime; /* when was file data last changed */ + u32_t i_ctime; /* when was inode itself changed (V2 only)*/ + u32_t i_zone[V2_NR_TZONES]; /* zone numbers for direct, ind, and dbl ind */ /* The following items are not present on the disk. */ dev_t i_dev; /* which device is the inode on */ diff --git a/servers/mfs/main.c b/servers/mfs/main.c index 76d7198ea..d0b3408f7 100644 --- a/servers/mfs/main.c +++ b/servers/mfs/main.c @@ -82,6 +82,8 @@ PUBLIC int main(int argc, char *argv[]) read_ahead(); /* do block read ahead */ } + + return(OK); } /*===========================================================================* diff --git a/servers/mfs/stadir.c b/servers/mfs/stadir.c index b7ec1c68d..93b05cceb 100644 --- a/servers/mfs/stadir.c +++ b/servers/mfs/stadir.c @@ -18,8 +18,8 @@ PRIVATE int copy_new_to_old_stat(endpoint_t who_e, prevst.st_dev = st->st_dev; prevst.st_ino = st->st_ino; prevst.st_mode = st->st_mode; - prevst.st_uid = st->st_uid; - prevst.st_gid = st->st_gid; + prevst.st_uid = (short) st->st_uid; + prevst.st_gid = (short) st->st_gid; prevst.st_size = st->st_size; prevst.st_rdev = st->st_rdev; @@ -63,7 +63,7 @@ PRIVATE int stat_inode( statbuf.st_mode = rip->i_mode; statbuf.st_nlink = rip->i_nlinks; statbuf.st_uid = rip->i_uid; - statbuf.st_gid = (short) rip->i_gid; /* FIXME: should become gid_t */ + statbuf.st_gid = rip->i_gid; statbuf.st_rdev = (s ? (dev_t) rip->i_zone[0] : NO_DEV); statbuf.st_size = rip->i_size; statbuf.st_atime = rip->i_atime; @@ -122,7 +122,7 @@ PUBLIC int fs_statvfs() scale = sp->s_log_zone_size; - blockstats(&st.f_blocks, &st.f_bfree, &used); + blockstats((u32_t *) &st.f_blocks, (u32_t *) &st.f_bfree, &used); st.f_bavail = st.f_bfree; st.f_bsize = sp->s_block_size << scale; diff --git a/servers/pfs/dev_uds.c b/servers/pfs/dev_uds.c index c6033323e..015e5cfd5 100644 --- a/servers/pfs/dev_uds.c +++ b/servers/pfs/dev_uds.c @@ -886,6 +886,13 @@ PUBLIC int uds_ioctl(message *dev_m_in, message *dev_m_out) break; + case NWIOGUDSPEERCREDOLD: + + /* get peer endpoint -- getsockopt(SO_PEERCRED) */ + rc = do_getsockopt_peercred_old(dev_m_in, dev_m_out); + + break; + case NWIOSUDSTADDR: /* set target address -- sendto() */ diff --git a/servers/pfs/proto.h b/servers/pfs/proto.h index 9ba371c97..d6465e0ac 100644 --- a/servers/pfs/proto.h +++ b/servers/pfs/proto.h @@ -82,6 +82,8 @@ _PROTOTYPE( int do_getsockopt_sotype, (message *dev_m_in, message *dev_m_out) ); _PROTOTYPE( int do_getsockopt_peercred, (message *dev_m_in, message *dev_m_out) ); +_PROTOTYPE( int do_getsockopt_peercred_old, + (message *dev_m_in, message *dev_m_out) ); _PROTOTYPE( int do_getsockopt_sndbuf, (message *dev_m_in, message *dev_m_out) ); _PROTOTYPE( int do_setsockopt_sndbuf, diff --git a/servers/pfs/uds.c b/servers/pfs/uds.c index 81efd2ef3..7a1309cf4 100644 --- a/servers/pfs/uds.c +++ b/servers/pfs/uds.c @@ -1047,6 +1047,54 @@ PUBLIC int do_getsockopt_peercred(message *dev_m_in, message *dev_m_out) return rc ? EIO : OK; } +PUBLIC int do_getsockopt_peercred_old(message *dev_m_in, message *dev_m_out) +{ + int minor; + int peer_minor; + int rc; + struct ucred cred; + struct ucred_old cred_old; + +#if DEBUG == 1 + static int call_count = 0; + printf("(uds) [%d] do_getsockopt_peercred() call_count=%d\n", + uds_minor(dev_m_in), ++call_count); +#endif + + minor = uds_minor(dev_m_in); + + if (uds_fd_table[minor].peer == -1) { + + if (uds_fd_table[minor].err == ECONNRESET) { + uds_fd_table[minor].err = 0; + + return ECONNRESET; + } else { + return ENOTCONN; + } + } + + peer_minor = uds_fd_table[minor].peer; + + /* obtain the peer's credentials */ + rc = getnucred(uds_fd_table[peer_minor].owner, &cred); + if (rc == -1) { + /* likely error: invalid endpoint / proc doesn't exist */ + return errno; + } + + /* copy to old structure */ + cred_old.pid = cred.pid; + cred_old.uid = (short) cred.uid; + cred_old.gid = (char) cred.gid; + + rc = sys_safecopyto(VFS_PROC_NR, (cp_grant_id_t) dev_m_in->IO_GRANT, + (vir_bytes) 0, (vir_bytes) &cred_old, sizeof(struct ucred_old), + D); + + return rc ? EIO : OK; +} + int do_getsockopt_sndbuf(message *dev_m_in, message *dev_m_out) { int minor; diff --git a/servers/pm/getset.c b/servers/pm/getset.c index daf5b797f..a2e3e7f3a 100644 --- a/servers/pm/getset.c +++ b/servers/pm/getset.c @@ -18,37 +18,62 @@ *===========================================================================*/ PUBLIC int do_get() { -/* Handle GETUID, GETGID, GETPID, GETPGRP, GETSID. +/* Handle GETUID, GETGID, GETGROUPS, GETGROUPS_O, GETPID, GETPGRP, GETSID. */ register struct mproc *rmp = mp; - int r; + int r, i; int ngroups; + char sgroups[NGROUPS_MAX]; /* XXX: Temp storage for GETGROUPS_O */ switch(call_nr) { - case GETGROUPS: - ngroups = m_in.grp_no; - if (ngroups > NGROUPS_MAX || ngroups < 0) - return(EINVAL); + case GETGROUPS_O: + ngroups = m_in.grp_no; + if (ngroups > NGROUPS_MAX || ngroups < 0) + return(EINVAL); - if (ngroups == 0) { - r = rmp->mp_ngroups; - break; - } + if (ngroups == 0) { + r = rmp->mp_ngroups; + break; + } - if (ngroups < rmp->mp_ngroups) + if (ngroups < rmp->mp_ngroups) /* Asking for less groups than available */ return(EINVAL); + for (i = 0; i < ngroups; i++) + sgroups[i] = (char) rmp->mp_sgroups[i]; + + r = sys_datacopy(SELF, (vir_bytes) &sgroups, who_e, + (vir_bytes) m_in.groupsp, ngroups * sizeof(char)); + + if (r != OK) + return(r); + + r = rmp->mp_ngroups; + break; + case GETGROUPS: + ngroups = m_in.grp_no; + if (ngroups > NGROUPS_MAX || ngroups < 0) + return(EINVAL); - r = sys_datacopy(SELF, (vir_bytes) rmp->mp_sgroups, who_e, - (vir_bytes) m_in.groupsp, ngroups * sizeof(gid_t)); + if (ngroups == 0) { + r = rmp->mp_ngroups; + break; + } - if (r != OK) - return(r); - - r = rmp->mp_ngroups; - break; + if (ngroups < rmp->mp_ngroups) + /* Asking for less groups than available */ + return(EINVAL); + + r = sys_datacopy(SELF, (vir_bytes) rmp->mp_sgroups, who_e, + (vir_bytes) m_in.groupsp, ngroups * sizeof(gid_t)); + + if (r != OK) + return(r); + + r = rmp->mp_ngroups; + break; case GETUID: r = rmp->mp_realuid; rmp->mp_reply.reply_res2 = rmp->mp_effuid; @@ -97,6 +122,8 @@ PUBLIC int do_set() message m; int r, i; int ngroups; + char sgroups[NGROUPS_MAX]; /* XXX: Temp storage for SETGROUPS_O */ + switch(call_nr) { case SETUID: @@ -146,6 +173,40 @@ PUBLIC int do_set() if (r != OK) return(r); + for (i = 0; i < ngroups; i++) { + if (rmp->mp_sgroups[i] > GID_MAX) + return(EINVAL); + } + for (i = ngroups; i < NGROUPS_MAX; i++) { + rmp->mp_sgroups[i] = 0; + } + rmp->mp_ngroups = ngroups; + + m.m_type = PM_SETGROUPS; + m.PM_PROC = rmp->mp_endpoint; + m.PM_GROUP_NO = rmp->mp_ngroups; + m.PM_GROUP_ADDR = (char *) rmp->mp_sgroups; + + break; + case SETGROUPS_O: + if (rmp->mp_effuid != SUPER_USER) + return(EPERM); + + ngroups = m_in.grp_no; + + if (ngroups > NGROUPS_MAX || ngroups < 0) + return(EINVAL); + + if (m_in.groupsp == NULL) + return(EFAULT); + + r = sys_datacopy(who_e, (vir_bytes) m_in.groupsp, SELF, + (vir_bytes) &sgroups, ngroups * sizeof(char)); + if (r != OK) + return(r); + + for (i = 0; i < ngroups; i++) + rmp->mp_sgroups[i] = (gid_t) sgroups[i]; for (i = ngroups; i < NGROUPS_MAX; i++) rmp->mp_sgroups[i] = 0; rmp->mp_ngroups = ngroups; @@ -153,7 +214,7 @@ PUBLIC int do_set() m.m_type = PM_SETGROUPS; m.PM_PROC = rmp->mp_endpoint; m.PM_GROUP_NO = rmp->mp_ngroups; - m.PM_GROUP_ADDR = rmp->mp_sgroups; + m.PM_GROUP_ADDR = (char *) rmp->mp_sgroups; break; case SETSID: diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 3549eb3af..b6adec1c7 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -316,15 +316,14 @@ PUBLIC int do_getepinfo() endpoint_t ep; /* This call should be moved to DS. */ - if (mp->mp_effuid != 0) - { - printf("PM: unauthorized call of do_getepinfo by proc %d\n", + if (mp->mp_effuid != 0) { + printf("PM: unauthorized call of do_getepinfo_o by proc %d\n", mp->mp_endpoint); sys_sysctl_stacktrace(mp->mp_endpoint); return EPERM; } - ep= m_in.PM_ENDPT; + ep = m_in.PM_ENDPT; for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) { if ((rmp->mp_flags & IN_USE) && (rmp->mp_endpoint == ep)) { @@ -332,7 +331,37 @@ PUBLIC int do_getepinfo() mp->mp_reply.reply_res3 = rmp->mp_effgid; return(rmp->mp_pid); } - } + } + + /* Process not found */ + return(ESRCH); +} + +/*===========================================================================* + * do_getepinfo_o * + *===========================================================================*/ +PUBLIC int do_getepinfo_o() +{ + register struct mproc *rmp; + endpoint_t ep; + + /* This call should be moved to DS. */ + if (mp->mp_effuid != 0) { + printf("PM: unauthorized call of do_getepinfo_o by proc %d\n", + mp->mp_endpoint); + sys_sysctl_stacktrace(mp->mp_endpoint); + return EPERM; + } + + ep = m_in.PM_ENDPT; + + for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) { + if ((rmp->mp_flags & IN_USE) && (rmp->mp_endpoint == ep)) { + mp->mp_reply.reply_res2 = (short) rmp->mp_effuid; + mp->mp_reply.reply_res3 = (char) rmp->mp_effgid; + return(rmp->mp_pid); + } + } /* Process not found */ return(ESRCH); diff --git a/servers/pm/proto.h b/servers/pm/proto.h index 9eb2bd429..e2ab0528c 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -62,6 +62,7 @@ _PROTOTYPE( int do_getsysinfo, (void) ); _PROTOTYPE( int do_getsysinfo_up, (void) ); _PROTOTYPE( int do_getprocnr, (void) ); _PROTOTYPE( int do_getepinfo, (void) ); +_PROTOTYPE( int do_getepinfo_o, (void) ); _PROTOTYPE( int do_svrctl, (void) ); _PROTOTYPE( int do_getsetpriority, (void) ); diff --git a/servers/pm/table.c b/servers/pm/table.c index 6a69002ec..e81a3ca6a 100644 --- a/servers/pm/table.c +++ b/servers/pm/table.c @@ -15,7 +15,7 @@ _PROTOTYPE (int (*call_vec[]), (void) ) = { do_exit, /* 1 = exit */ do_fork, /* 2 = fork */ no_sys, /* 3 = read */ - no_sys, /* 4 = write */ + no_sys, /* 4 = write */ no_sys, /* 5 = open */ no_sys, /* 6 = close */ do_waitpid, /* 7 = wait */ @@ -42,11 +42,11 @@ _PROTOTYPE (int (*call_vec[]), (void) ) = { no_sys, /* 28 = fstat */ do_pause, /* 29 = pause */ no_sys, /* 30 = utime */ - no_sys, /* 31 = (stty) */ - no_sys, /* 32 = (gtty) */ + do_getepinfo, /* 31 = getepinfo */ + do_set, /* 32 = setgroups */ no_sys, /* 33 = access */ - no_sys, /* 34 = (nice) */ - no_sys, /* 35 = (ftime) */ + do_get, /* 34 = getgroups */ + no_sys, /* 35 = unused */ no_sys, /* 36 = sync */ do_kill, /* 37 = kill */ no_sys, /* 38 = rename */ @@ -55,19 +55,19 @@ _PROTOTYPE (int (*call_vec[]), (void) ) = { no_sys, /* 41 = dup */ no_sys, /* 42 = pipe */ do_times, /* 43 = times */ - no_sys, /* 44 = (prof) */ + no_sys, /* 44 = unused */ no_sys, /* 45 = unused */ do_set, /* 46 = setgid */ do_get, /* 47 = getgid */ no_sys, /* 48 = (signal)*/ no_sys, /* 49 = unused */ no_sys, /* 50 = lstat */ - no_sys, /* 51 = (acct) */ - no_sys, /* 52 = (phys) */ - no_sys, /* 53 = (lock) */ + no_sys, /* 51 = unused */ + no_sys, /* 52 = unused */ + no_sys, /* 53 = unused */ no_sys, /* 54 = ioctl */ no_sys, /* 55 = fcntl */ - no_sys, /* 56 = (mpx) */ + no_sys, /* 56 = unused */ no_sys, /* 57 = unused */ no_sys, /* 58 = unused */ do_exec, /* 59 = execve */ @@ -119,7 +119,7 @@ _PROTOTYPE (int (*call_vec[]), (void) ) = { do_getprocnr, /* 104 = getprocnr */ no_sys, /* 105 = unused */ no_sys, /* 106 = unused */ - do_getepinfo, /* 107 = getepinfo */ + do_getepinfo_o, /* 107 = getepinfo XXX: old implementation*/ do_adddma, /* 108 = adddma */ do_deldma, /* 109 = deldma */ do_getdma, /* 110 = getdma */ diff --git a/servers/vfs/main.c b/servers/vfs/main.c index 79a3d5773..55447a954 100644 --- a/servers/vfs/main.c +++ b/servers/vfs/main.c @@ -572,7 +572,7 @@ PRIVATE void service_pm() break; case PM_SETGROUPS: - pm_setgroups(m_in.PM_PROC, m_in.PM_GROUP_NO, m_in.PM_GROUP_ADDR); + pm_setgroups(m_in.PM_PROC, m_in.PM_GROUP_NO, (gid_t *) m_in.PM_GROUP_ADDR); m_out.m_type = PM_SETGROUPS_REPLY; m_out.PM_PROC = m_in.PM_PROC; diff --git a/servers/vfs/protect.c b/servers/vfs/protect.c index 558cf4f90..01a0555d4 100644 --- a/servers/vfs/protect.c +++ b/servers/vfs/protect.c @@ -105,11 +105,14 @@ PUBLIC int do_chown() } if (r == OK) { - /* Do not change uid/gid if new uid/gid is -1. */ - uid = (m_in.owner == (uid_t)-1 ? vp->v_uid : m_in.owner); - gid = (m_in.group == (gid_t)-1 ? vp->v_gid : m_in.group); - if ((r = req_chown(vp->v_fs_e, vp->v_inode_nr, uid, gid, - &new_mode)) == OK) { + /* Do not change uid/gid if new uid/gid is -1. */ + uid = (m_in.owner == (uid_t)-1 ? vp->v_uid : m_in.owner); + gid = (m_in.group == (gid_t)-1 ? vp->v_gid : m_in.group); + + if (uid > UID_MAX || gid > GID_MAX) + r = EINVAL; + else if ((r = req_chown(vp->v_fs_e, vp->v_inode_nr, uid, gid, + &new_mode)) == OK) { vp->v_uid = uid; vp->v_gid = gid; vp->v_mode = new_mode; diff --git a/servers/vfs/table.c b/servers/vfs/table.c index 0f05fd528..029e7a45c 100644 --- a/servers/vfs/table.c +++ b/servers/vfs/table.c @@ -46,11 +46,11 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = { do_fstat, /* 28 = fstat (prev)*/ no_sys, /* 29 = pause */ do_utime, /* 30 = utime */ - no_sys, /* 31 = (stty) */ - no_sys, /* 32 = (gtty) */ + no_sys, /* 31 = unused */ + no_sys, /* 32 = unused */ do_access, /* 33 = access */ - no_sys, /* 34 = (nice) */ - no_sys, /* 35 = (ftime) */ + no_sys, /* 34 = unused */ + no_sys, /* 35 = unused */ do_sync, /* 36 = sync */ no_sys, /* 37 = kill */ do_rename, /* 38 = rename */ @@ -59,19 +59,19 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = { do_dup, /* 41 = dup */ do_pipe, /* 42 = pipe */ no_sys, /* 43 = times */ - no_sys, /* 44 = (prof) */ + no_sys, /* 44 = unused */ do_slink, /* 45 = symlink */ no_sys, /* 46 = (setgid)*/ no_sys, /* 47 = getgid */ no_sys, /* 48 = (signal)*/ do_rdlink, /* 49 = readlink*/ do_lstat, /* 50 = lstat (prev)*/ - no_sys, /* 51 = (acct) */ - no_sys, /* 52 = (phys) */ - no_sys, /* 53 = (lock) */ + no_sys, /* 51 = unused */ + no_sys, /* 52 = unused */ + no_sys, /* 53 = unused */ do_ioctl, /* 54 = ioctl */ do_fcntl, /* 55 = fcntl */ - no_sys, /* 56 = (mpx) */ + no_sys, /* 56 = unused */ do_fslogin, /* 57 = FS proc login */ no_sys, /* 58 = unused */ no_sys, /* 59 = (execve)*/ diff --git a/test/test46.c b/test/test46.c index 7d0d0ac16..35b962c22 100644 --- a/test/test46.c +++ b/test/test46.c @@ -28,8 +28,7 @@ _PROTOTYPE( void group_test_4, (void) ); _PROTOTYPE( void group_test_5, (void) ); _PROTOTYPE( int dotest, (void (*testfunc)(void)) ); -int subtest = -1, errorct = 0; -#define ERROR_MAX 5 +#define MAX_ERROR 5 #define IMAGINARY_GID 100 #define IMAGINARY_GID_STR "100" #define IMAGINARY_UID 101 @@ -38,12 +37,14 @@ int subtest = -1, errorct = 0; setgid((IMAGINARY_GID) + 1 ); \ setuid(IMAGINARY_UID); \ } while(0) +#include "common.c" + +int subtest = -1, errorct = 0; int main(int argc, char *argv[]) { int superuser; - printf("Test 46 "); - fflush(stdout); + start(46); superuser = (geteuid() == 0); @@ -58,13 +59,7 @@ int main(int argc, char *argv[]) api_test(); /* Perform some very basic API tests */ group_test(); /* Perform some tests that mimic actual use */ - if(errorct > 0) { - printf("%d error(s)\n", errorct); - return(errorct); - } - - printf("ok\n"); - return(0); + quit(); } void limit_test() { @@ -115,8 +110,8 @@ void api_test() { /* Let's invent some imaginary groups */ #define START_GID 20001 - for (i = START_GID; i < START_GID + ngroups_max; i++) - grouplist[i - START_GID] = i; + for (i = 0; i < ngroups_max; i++) + grouplist[i] = i + START_GID; /* Normal usage */ if (setgroups(ngroups_max, grouplist) != 0) e(1); @@ -184,6 +179,11 @@ void api_test() { } } + /* Try to set too high a group ID */ + grouplist2[0] = GID_MAX + 1; /* Out of range */ + if (setgroups(1, grouplist2) == 0) e(23); + if (errno != EINVAL) e(24); + free(grouplist); free(grouplist2); } @@ -343,13 +343,3 @@ void group_test_5() { dirp = opendir("DIR_046/sub"); exit(dirp != NULL); /* If not NULL, we were able to access it */ } - -void e(int error_no) { - printf("Subtest %d, error %d\n", subtest, error_no); - - if (errorct++ > ERROR_MAX) { - printf("Too many errors, test aborted\n"); - exit(1); - } -} - -- 2.44.0