Increase gid_t and uid_t to 32 bits

Increase gid_t and uid_t to 32 bits and provide backwards compatibility
where needed.
This commit is contained in:
Thomas Veerman 2011-09-05 13:56:14 +00:00
parent fde9a258d0
commit 8a266a478e
36 changed files with 339 additions and 234 deletions

View file

@ -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
*/

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -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 */

View file

@ -1,6 +1,13 @@
#ifndef __SYS_UCRED_H
#define __SYS_UCRED_H
struct ucred_old
{
pid_t pid;
short uid;
char gid;
};
struct ucred
{
pid_t pid;

View file

@ -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);

View file

@ -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));
}

View file

@ -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:

View file

@ -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 */

View file

@ -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) {

View file

@ -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);

View file

@ -35,7 +35,7 @@
#include <machine/ansi.h>
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 */

View file

@ -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 */

View file

@ -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

View file

@ -1,7 +1,12 @@
#ifndef __SYS_UCRED_H
#define __SYS_UCRED_H
#include <sys/types.h>
struct ucred_old
{
pid_t pid;
short uid;
char gid;
};
struct ucred
{

View file

@ -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() */

View file

@ -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,

View file

@ -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;

View file

@ -137,7 +137,10 @@ 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,
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;
@ -156,7 +159,6 @@ PUBLIC int do_chown()
return(r);
}
/*===========================================================================*
* do_umask *
*===========================================================================*/

View file

@ -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();

View file

@ -17,15 +17,15 @@
#include <sys/queue.h>
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 */

View file

@ -82,6 +82,8 @@ PUBLIC int main(int argc, char *argv[])
read_ahead(); /* do block read ahead */
}
return(OK);
}
/*===========================================================================*

View file

@ -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;

View file

@ -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() */

View file

@ -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,

View file

@ -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;

View file

@ -18,15 +18,16 @@
*===========================================================================*/
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:
case GETGROUPS_O:
ngroups = m_in.grp_no;
if (ngroups > NGROUPS_MAX || ngroups < 0)
return(EINVAL);
@ -40,6 +41,30 @@ PUBLIC int do_get()
/* 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);
if (ngroups == 0) {
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));
@ -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:

View file

@ -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)) {
@ -338,6 +337,36 @@ PUBLIC int do_getepinfo()
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);
}
/*===========================================================================*
* do_reboot *
*===========================================================================*/

View file

@ -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) );

View file

@ -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 */

View file

@ -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;

View file

@ -108,7 +108,10 @@ 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,
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;

View file

@ -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)*/

View file

@ -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);
}
}