home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / mmdf-IIb.43 / uip / ucbmail / getname.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-06-03  |  1.1 KB  |  58 lines

  1. /*
  2.  * Copyright (c) 1980 Regents of the University of California.
  3.  * All rights reserved.  The Berkeley software License Agreement
  4.  * specifies the terms and conditions for redistribution.
  5.  */
  6.  
  7. #ifndef lint
  8. static char *sccsid = "@(#)getname.c    5.2 (Berkeley) 6/21/85";
  9. #endif not lint
  10.  
  11. #include <pwd.h>
  12.  
  13. /*
  14.  * Getname / getuserid for those with
  15.  * hashed passwd data base).
  16.  *
  17.  */
  18.  
  19. #include "./rcv.h"
  20.  
  21. /*
  22.  * Search the passwd file for a uid.  Return name through ref parameter
  23.  * if found, indicating success with 0 return.  Return -1 on error.
  24.  * If -1 is passed as the user id, close the passwd file.
  25.  */
  26.  
  27. getname(l_uid, namebuf)
  28.     char namebuf[];
  29. {
  30.     struct passwd *pw;
  31.  
  32.     if (l_uid == -1) {
  33.         return(0);
  34.     }
  35.     if ((pw = getpwuid(l_uid)) == NULL)
  36.         return(-1);
  37.     strcpy(namebuf, pw->pw_name);
  38.     return 0;
  39. }
  40.  
  41. /*
  42.  * Convert the passed name to a user id and return it.  Return -1
  43.  * on error.  Iff the name passed is -1 (yech) close the pwfile.
  44.  */
  45.  
  46. getuserid(name)
  47.     char name[];
  48. {
  49.     struct passwd *pw;
  50.  
  51.     if (name == (char *) -1) {
  52.         return(0);
  53.     }
  54.     if ((pw = getpwnam(name)) == NULL)
  55.         return 0;
  56.     return pw->pw_uid;
  57. }
  58.