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

  1. /* History:
  2. 5/3/91 DJB modified to have safe behavior under !HAVE_UCRED
  3. 5/1/91 DJB baseline public domain
  4. */
  5.  
  6. /*
  7.  
  8. struct ucred *getfcred(f) struct file *f; returns the user credentials
  9. for open file f (in user memory). Note that on machines without struct
  10. ucred, all open file descriptions are considered to be owned by root.
  11.  
  12. getfcredstrerr is a strerrfun for getfcred().
  13.  
  14. */
  15.  
  16. #include "structfile.h"
  17. #include "structucred.h"
  18. #include "getfcred.h"
  19. #include "kmem.h"
  20. #include "strerr.h"
  21. #include "conffcredptr.h"
  22. #include "confhaveucred.h"
  23.  
  24. static int getfcrederrno = 0;
  25.  
  26. static struct strerrtab e[] = {
  27.   { 0, "getfcred error 0", 0 }
  28. #define GF_KMEM 1
  29. , { GF_KMEM, "cannot get file credentials: ", kmemstrerr }
  30. } ;
  31.  
  32. char *getfcredstrerr(ke)
  33. strerrfun *ke;
  34. {
  35.  return strerrtaberr(ke,getfcrederrno,e,sizeof(e)/sizeof(*e),"unknown getfcred error");
  36. }
  37.  
  38. static struct ucred uc;
  39.  
  40. struct ucred *getfcred(f)
  41. struct file *f;
  42. {
  43. #ifndef HAVE_UCRED
  44.  uc.uid = -1; uc.gid = -1; /*XXX*/
  45.  return &uc;
  46. #else
  47. #ifdef FCRED_ISNOT_POINTER
  48.  return &(f->f_cred);
  49. #else
  50.  if (kmemcpy((char *) &uc,(char *) f->f_cred,sizeof(uc)) == -1)
  51.    RETERN(0,getfcrederrno,GF_KMEM)
  52.  return &uc;
  53. #endif
  54. #endif
  55. }
  56.