getpeuid implementation. Get the uid of a process (by endpoint)

This commit is contained in:
Philip Homburg 2007-04-27 12:21:06 +00:00
parent 8eb09f6ddc
commit 69ca935251
7 changed files with 49 additions and 0 deletions

View file

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

View file

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

View file

@ -44,6 +44,7 @@ libc_FILES=" \
getlogin.c \
getpagesize.c \
getpass.c \
getpeuid.c \
getpwent.c \
getttyent.c \
getw.c \

12
lib/other/getpeuid.c Executable file
View file

@ -0,0 +1,12 @@
#include <lib.h>
#include <unistd.h>
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);
}

View file

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

View file

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

View file

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