From 4c263d60026f1656197485b085114f9ec6838721 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Sat, 31 Oct 2009 14:09:28 +0000 Subject: [PATCH] PM: clean up endpoint info API/ABI --- include/minix/callnr.h | 2 +- include/unistd.h | 8 ++++---- lib/other/Makefile.in | 1 - lib/other/_getngid.c | 6 +++--- lib/other/_getnpid.c | 7 +++---- lib/other/_getnuid.c | 8 ++++---- lib/other/getpeuid.c | 12 ------------ servers/pm/getset.c | 6 ------ servers/pm/main.c | 4 ++-- servers/pm/misc.c | 13 +++++++------ servers/pm/proto.h | 2 +- servers/rs/main.c | 2 +- 12 files changed, 26 insertions(+), 45 deletions(-) delete mode 100755 lib/other/getpeuid.c diff --git a/include/minix/callnr.h b/include/minix/callnr.h index c37761681..75b4b78bb 100755 --- a/include/minix/callnr.h +++ b/include/minix/callnr.h @@ -97,7 +97,7 @@ #if 0 #define FREEMEM 106 /* to PM, not used, not implemented */ #endif -#define GETPUID 107 /* to PM: get the uid of a process (endpoint) */ +#define GETEPINFO 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/unistd.h b/include/unistd.h index ad46bc0b2..3c9e15eaf 100755 --- a/include/unistd.h +++ b/include/unistd.h @@ -121,9 +121,6 @@ _PROTOTYPE( int getgroups, (int _gidsetsize, gid_t _grouplist[]) ); _PROTOTYPE( char *getlogin, (void) ); _PROTOTYPE( pid_t getpgrp, (void) ); _PROTOTYPE( pid_t getpid, (void) ); -_PROTOTYPE( pid_t getnpid, (int proc_nr) ); -_PROTOTYPE( uid_t getnuid, (int proc_nr) ); -_PROTOTYPE( gid_t getngid, (int proc_nr) ); _PROTOTYPE( pid_t getppid, (void) ); _PROTOTYPE( uid_t getuid, (void) ); _PROTOTYPE( int isatty, (int _fd) ); @@ -201,7 +198,6 @@ _PROTOTYPE( int devctl, (int ctl_req, int driver, int device, int style, int force) ); _PROTOTYPE( int mapdriver5, (char *label, size_t len, int major, int style, int force) ); -_PROTOTYPE( uid_t getpeuid, (endpoint_t ep) ); _PROTOTYPE(int adddma, (endpoint_t proc_e, phys_bytes start, phys_bytes size) ); _PROTOTYPE(int deldma, (endpoint_t proc_e, @@ -209,6 +205,10 @@ _PROTOTYPE(int deldma, (endpoint_t proc_e, _PROTOTYPE(int getdma, (endpoint_t *procp, phys_bytes *basep, phys_bytes *sizep) ); +_PROTOTYPE( pid_t getnpid, (endpoint_t proc_ep) ); +_PROTOTYPE( uid_t getnuid, (endpoint_t proc_ep) ); +_PROTOTYPE( gid_t getngid, (endpoint_t proc_ep) ); + /* For compatibility with other Unix systems */ _PROTOTYPE( int getpagesize, (void) ); _PROTOTYPE( int setgroups, (int ngroups, const gid_t *gidset) ); diff --git a/lib/other/Makefile.in b/lib/other/Makefile.in index b7e6e10a9..344a34a81 100644 --- a/lib/other/Makefile.in +++ b/lib/other/Makefile.in @@ -54,7 +54,6 @@ libc_FILES=" \ getlogin.c \ getpagesize.c \ getpass.c \ - getpeuid.c \ getpwent.c \ getttyent.c \ getw.c \ diff --git a/lib/other/_getngid.c b/lib/other/_getngid.c index cabb7e3d0..22c114491 100644 --- a/lib/other/_getngid.c +++ b/lib/other/_getngid.c @@ -2,10 +2,10 @@ #define getngid _getngid #include -PUBLIC gid_t getngid(int proc_nr) +PUBLIC gid_t getngid(endpoint_t proc_ep) { message m; - m.m1_i1 = proc_nr; /* search gid for this process */ - if (_syscall(MM, GETGID, &m) < 0) return ( (gid_t) -1); + m.m1_i1 = proc_ep; /* search gid for this process */ + if (_syscall(MM, GETEPINFO, &m) < 0) return ( (gid_t) -1); return( (gid_t) m.m2_i2); /* return search result */ } diff --git a/lib/other/_getnpid.c b/lib/other/_getnpid.c index 2f51b5a55..a04ee3c4b 100644 --- a/lib/other/_getnpid.c +++ b/lib/other/_getnpid.c @@ -2,10 +2,9 @@ #define getnpid _getnpid #include -PUBLIC pid_t getnpid(int proc_nr) +PUBLIC pid_t getnpid(endpoint_t proc_ep) { message m; - m.m1_i1 = proc_nr; /* search pid for this process */ - if (_syscall(MM, MINIX_GETPID, &m) < 0) return ( (pid_t) -1); - return( (pid_t) m.m2_i2); /* return search result */ + m.m1_i1 = proc_ep; /* search pid for this process */ + return _syscall(MM, GETEPINFO, &m); } diff --git a/lib/other/_getnuid.c b/lib/other/_getnuid.c index 67244cff7..29202a86b 100644 --- a/lib/other/_getnuid.c +++ b/lib/other/_getnuid.c @@ -2,10 +2,10 @@ #define getnuid _getnuid #include -PUBLIC uid_t getnuid(int proc_nr) +PUBLIC uid_t getnuid(endpoint_t proc_ep) { message m; - m.m1_i1 = proc_nr; /* search uid for this process */ - if (_syscall(MM, GETUID, &m) < 0) return ( (uid_t) -1); - return( (uid_t) m.m2_i2); /* return search result */ + m.m1_i1 = proc_ep; /* search uid for this process */ + if (_syscall(MM, GETEPINFO, &m) < 0) return ( (uid_t) -1); + return( (uid_t) m.m2_i1); /* return search result */ } diff --git a/lib/other/getpeuid.c b/lib/other/getpeuid.c deleted file mode 100755 index 4c7e2cd96..000000000 --- a/lib/other/getpeuid.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -PUBLIC uid_t getpeuid(ep) -endpoint_t ep; -{ - message m; - - m.m1_i1= ep; - if (_syscall(MM, GETPUID, &m) < 0) return ( (uid_t) -1); - return( (uid_t) m.m2_i1); -} diff --git a/servers/pm/getset.c b/servers/pm/getset.c index dce214dea..5fb6e8c73 100644 --- a/servers/pm/getset.c +++ b/servers/pm/getset.c @@ -27,22 +27,16 @@ PUBLIC int do_get() case GETUID: r = rmp->mp_realuid; rmp->mp_reply.reply_res2 = rmp->mp_effuid; - if (pm_isokendpt(m_in.PM_ENDPT, &proc) == OK && proc >= 0) - rmp->mp_reply.reply_res3 = mproc[proc].mp_effuid; break; case GETGID: r = rmp->mp_realgid; rmp->mp_reply.reply_res2 = rmp->mp_effgid; - if (pm_isokendpt(m_in.PM_ENDPT, &proc) == OK && proc >= 0) - rmp->mp_reply.reply_res3 = mproc[proc].mp_effgid; break; case MINIX_GETPID: r = mproc[who_p].mp_pid; rmp->mp_reply.reply_res2 = mproc[rmp->mp_parent].mp_pid; - if(pm_isokendpt(m_in.PM_ENDPT, &proc) == OK && proc >= 0) - rmp->mp_reply.reply_res3 = mproc[proc].mp_pid; break; case GETPGRP: diff --git a/servers/pm/main.c b/servers/pm/main.c index ce6fd9058..6c317082d 100644 --- a/servers/pm/main.c +++ b/servers/pm/main.c @@ -128,8 +128,8 @@ PUBLIC int main() case GETPROCNR: result= do_getprocnr(); break; - case GETPUID: - result= do_getpuid(); + case GETEPINFO: + result= do_getepinfo(); break; default: /* Else, if the system call number is valid, perform the diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 699c0d7dd..2d2c3cdf7 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -5,7 +5,7 @@ * do_procstat: request process status (Jorrit N. Herder) * do_getsysinfo: request copy of PM data structure (Jorrit N. Herder) * do_getprocnr: lookup process slot number (Jorrit N. Herder) - * do_getpuid: get the uid/euid of a process given its endpoint + * do_getepinfo: get the pid/uid/gid of a process given its endpoint * do_allocmem: allocate a chunk of memory (Jorrit N. Herder) * do_freemem: deallocate a chunk of memory (Jorrit N. Herder) * do_getsetpriority: get/set process priority @@ -360,9 +360,9 @@ PUBLIC int do_getprocnr() } /*===========================================================================* - * do_getpuid * + * do_getepinfo * *===========================================================================*/ -PUBLIC int do_getpuid() +PUBLIC int do_getepinfo() { register struct mproc *rmp; endpoint_t ep; @@ -370,7 +370,7 @@ PUBLIC int do_getpuid() /* This call should be moved to DS. */ if (mp->mp_effuid != 0) { - printf("PM: unauthorized call of do_getpuid by proc %d\n", + printf("PM: unauthorized call of do_getepinfo by proc %d\n", mp->mp_endpoint); sys_sysctl_stacktrace(mp->mp_endpoint); return EPERM; @@ -381,12 +381,13 @@ PUBLIC int do_getpuid() for (rmp = &mproc[0]; rmp < &mproc[NR_PROCS]; rmp++) { if ((rmp->mp_flags & IN_USE) && (rmp->mp_endpoint == ep)) { mp->mp_reply.reply_res2 = rmp->mp_effuid; - return(rmp->mp_realuid); + mp->mp_reply.reply_res3 = rmp->mp_effgid; + return(rmp->mp_pid); } } /* Process not found */ - return(ESRCH); + return(ESRCH); } /*===========================================================================* diff --git a/servers/pm/proto.h b/servers/pm/proto.h index 836bdbde5..f8795d3d1 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -52,7 +52,7 @@ _PROTOTYPE( int do_sysuname, (void) ); _PROTOTYPE( int do_getsysinfo, (void) ); _PROTOTYPE( int do_getsysinfo_up, (void) ); _PROTOTYPE( int do_getprocnr, (void) ); -_PROTOTYPE( int do_getpuid, (void) ); +_PROTOTYPE( int do_getepinfo, (void) ); _PROTOTYPE( int do_svrctl, (void) ); _PROTOTYPE( int do_allocmem, (void) ); _PROTOTYPE( int do_freemem, (void) ); diff --git a/servers/rs/main.c b/servers/rs/main.c index 55d909d85..d6e75219f 100644 --- a/servers/rs/main.c +++ b/servers/rs/main.c @@ -92,7 +92,7 @@ PUBLIC int main(void) } /* Only root can make calls to rs. unless it's RS_LOOKUP. */ - euid= getpeuid(m.m_source); + euid= getnuid(m.m_source); if (euid != 0 && call_nr != RS_LOOKUP) { printf("RS: got unauthorized request %d from endpoint %d\n", -- 2.44.0