From: Philip Homburg Date: Fri, 27 Apr 2007 12:21:06 +0000 (+0000) Subject: getpeuid implementation. Get the uid of a process (by endpoint) X-Git-Tag: v3.1.4~392 X-Git-Url: http://zhaoyanbai.com/repos/icons/debian/static/man.7.ps?a=commitdiff_plain;h=69ca935251a4d0acaf0a09439c461c94dcf60cdc;p=minix.git getpeuid implementation. Get the uid of a process (by endpoint) --- diff --git a/include/minix/callnr.h b/include/minix/callnr.h index 20930bc02..1a64ae6c8 100755 --- a/include/minix/callnr.h +++ b/include/minix/callnr.h @@ -95,6 +95,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 DEVCTL 120 /* to FS, map or unmap a device */ #define TASK_REPLY 121 /* to FS: reply code from drivers, not diff --git a/include/unistd.h b/include/unistd.h index c8790f270..3e43c2f1a 100755 --- a/include/unistd.h +++ b/include/unistd.h @@ -198,6 +198,7 @@ _PROTOTYPE( int freemem, (phys_bytes size, phys_bytes base) ); #define unmapdriver(device) devctl(DEV_UNMAP, 0, device, 0) _PROTOTYPE( int devctl, (int ctl_req, int driver, int device, int style, int force) ); +_PROTOTYPE( uid_t getpeuid, (endpoint_t ep) ); /* For compatibility with other Unix systems */ _PROTOTYPE( int getpagesize, (void) ); diff --git a/lib/other/Makefile.in b/lib/other/Makefile.in index 56a9b9668..0528a068b 100644 --- a/lib/other/Makefile.in +++ b/lib/other/Makefile.in @@ -44,6 +44,7 @@ libc_FILES=" \ getlogin.c \ getpagesize.c \ getpass.c \ + getpeuid.c \ getpwent.c \ getttyent.c \ getw.c \ diff --git a/lib/other/getpeuid.c b/lib/other/getpeuid.c new file mode 100755 index 000000000..4c7e2cd96 --- /dev/null +++ b/lib/other/getpeuid.c @@ -0,0 +1,12 @@ +#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/main.c b/servers/pm/main.c index 0c2df15ab..f59af00e7 100644 --- a/servers/pm/main.c +++ b/servers/pm/main.c @@ -119,6 +119,9 @@ PUBLIC int main() case GETPROCNR: result= do_getprocnr(); break; + case GETPUID: + result= do_getpuid(); + break; default: /* Else, if the system call number is valid, perform the * call. diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 9aa6bdb2e..70147268d 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -5,6 +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 it's 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 @@ -358,6 +359,35 @@ PUBLIC int do_getprocnr() return(OK); } +/*===========================================================================* + * do_getpuid * + *===========================================================================*/ +PUBLIC int do_getpuid() +{ + 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_getpuid by proc %d\n", + mp->mp_endpoint); + return EPERM; + } + + ep= m_in.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 = rmp->mp_effuid; + return(rmp->mp_realuid); + } + } + + /* Process not found */ + return(ESRCH); +} + /*===========================================================================* * do_reboot * *===========================================================================*/ diff --git a/servers/pm/proto.h b/servers/pm/proto.h index 9b9436a91..1cad787a8 100644 --- a/servers/pm/proto.h +++ b/servers/pm/proto.h @@ -68,6 +68,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_svrctl, (void) ); _PROTOTYPE( int do_allocmem, (void) ); _PROTOTYPE( int do_freemem, (void) );