home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3297 / getpcred.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-07  |  1.3 KB  |  65 lines

  1. /* History:
  2. 5/3/91 DJB added reasonable behavior on !HAVE_UCRED
  3. 5/1/91 DJB baseline public domain
  4. */
  5.  
  6. /*
  7.  
  8. struct ucred *getpcred(p) struct proc *p; returns the user credentials
  9. for process p (in user memory). Note that on machines without struct
  10. proc, all processes are considered to have XXX root credentials.
  11.  
  12. getpcredstrerr is a strerrfun for getpcred().
  13.  
  14. */
  15.  
  16. #include "structfile.h"
  17. #include "structucred.h"
  18. #include "structproc.h"
  19. #include "getpcred.h"
  20. #include "kmem.h"
  21. #include "strerr.h"
  22. #include "confpcredinproc.h"
  23. #include "confpcredunderproc.h"
  24. #include "confhaveucred.h"
  25.  
  26. static int getpcrederrno = 0;
  27.  
  28. static struct strerrtab e[] = {
  29.   { 0, "getpcred error 0", 0 }
  30. #define GP_KMEM 1
  31. , { GP_KMEM, "cannot get process credentials: ", kmemstrerr }
  32. } ;
  33.  
  34. char *getpcredstrerr(ke)
  35. strerrfun *ke;
  36. {
  37.  return strerrtaberr(ke,getpcrederrno,e,sizeof(e)/sizeof(*e),"unknown getpcred error");
  38. }
  39.  
  40. static struct ucred uc;
  41.  
  42. struct ucred *getpcred(p,u)
  43. struct proc *p;
  44. struct user *u;
  45. {
  46. #ifndef HAVE_UCRED
  47.  uc.uid = p->p_uid;
  48.  return &uc;
  49. #else
  50. #ifdef PCRED_IN_PROC
  51.  return &(p->p_cred);
  52. #else
  53. #ifdef PCRED_UNDER_PROC
  54.  if (kmemcpy((char *) &uc,(char *) p->p_cred,sizeof(uc)) == -1)
  55.    RETERN(0,getpcrederrno,GP_KMEM)
  56.  return &uc;
  57. #else
  58.  if (kmemcpy((char *) &uc,(char *) u->u_cred,sizeof(uc)) == -1)
  59.    RETERN(0,getpcrederrno,GP_KMEM)
  60.  return &uc;
  61. #endif
  62. #endif
  63. #endif
  64. }
  65.