home *** CD-ROM | disk | FTP | other *** search
- /* History:
- 5/3/91 DJB added reasonable behavior on !HAVE_UCRED
- 5/1/91 DJB baseline public domain
- */
-
- /*
-
- struct ucred *getpcred(p) struct proc *p; returns the user credentials
- for process p (in user memory). Note that on machines without struct
- proc, all processes are considered to have XXX root credentials.
-
- getpcredstrerr is a strerrfun for getpcred().
-
- */
-
- #include "structfile.h"
- #include "structucred.h"
- #include "structproc.h"
- #include "getpcred.h"
- #include "kmem.h"
- #include "strerr.h"
- #include "confpcredinproc.h"
- #include "confpcredunderproc.h"
- #include "confhaveucred.h"
-
- static int getpcrederrno = 0;
-
- static struct strerrtab e[] = {
- { 0, "getpcred error 0", 0 }
- #define GP_KMEM 1
- , { GP_KMEM, "cannot get process credentials: ", kmemstrerr }
- } ;
-
- char *getpcredstrerr(ke)
- strerrfun *ke;
- {
- return strerrtaberr(ke,getpcrederrno,e,sizeof(e)/sizeof(*e),"unknown getpcred error");
- }
-
- static struct ucred uc;
-
- struct ucred *getpcred(p,u)
- struct proc *p;
- struct user *u;
- {
- #ifndef HAVE_UCRED
- uc.uid = p->p_uid;
- return &uc;
- #else
- #ifdef PCRED_IN_PROC
- return &(p->p_cred);
- #else
- #ifdef PCRED_UNDER_PROC
- if (kmemcpy((char *) &uc,(char *) p->p_cred,sizeof(uc)) == -1)
- RETERN(0,getpcrederrno,GP_KMEM)
- return &uc;
- #else
- if (kmemcpy((char *) &uc,(char *) u->u_cred,sizeof(uc)) == -1)
- RETERN(0,getpcrederrno,GP_KMEM)
- return &uc;
- #endif
- #endif
- #endif
- }
-