home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / elm-2.4-pl20.tar.Z / elm-2.4-pl20.tar / lib / getfullnam.c < prev    next >
C/C++ Source or Header  |  1992-10-03  |  2KB  |  73 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: getfullnam.c,v 5.1 1992/10/03 22:41:36 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
  6.  *
  7.  *            Copyright (c) 1988-1992 USENET Community Trust
  8.  *            Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: getfullnam.c,v $
  17.  * Revision 5.1  1992/10/03  22:41:36  syd
  18.  * Initial checkin as of 2.4 Release at PL0
  19.  *
  20.  *
  21.  ******************************************************************************/
  22.  
  23. /** 
  24.  
  25. **/
  26.  
  27. #include "headers.h"
  28. #ifdef PWDINSYS
  29. #  include <sys/pwd.h>
  30. #else
  31. #  include <pwd.h>
  32. #endif
  33.  
  34. char *gcos_name();
  35.  
  36. char *
  37. get_full_name(logname)
  38. char *logname;
  39. {
  40.     /* return a pointer to the full user name for the passed logname
  41.      * or NULL if cannot be found
  42.      * If PASSNAMES get it from the gcos field, otherwise get it
  43.      * from ~/.fullname.
  44.      */
  45.  
  46. #ifndef PASSNAMES
  47.     FILE *fp;
  48.     char fullnamefile[SLEN];
  49. #endif
  50.     static char fullname[SLEN];
  51.     struct passwd *getpwnam(), *pass;
  52.  
  53.     if((pass = getpwnam(logname)) == NULL)
  54.       return(NULL);
  55. #ifdef PASSNAMES    /* get full_username from gcos field */
  56.     strcpy(fullname, gcos_name(pass->pw_gecos, logname));
  57. #else            /* get full_username from ~/.fullname file */
  58.     sprintf(fullnamefile, "%s/.fullname", pass->pw_dir);
  59.  
  60.     if(can_access(fullnamefile, READ_ACCESS) != 0)
  61.       return(NULL);        /* fullname file not accessible to user */
  62.     if((fp = fopen(fullnamefile, "r")) == NULL)
  63.       return(NULL);        /* fullname file cannot be opened! */
  64.     if(fgets(fullname, SLEN, fp) == NULL) {
  65.       fclose(fp);
  66.       return(NULL);        /* fullname file empty! */
  67.     }
  68.     fclose(fp);
  69.     no_ret(fullname);    /* remove trailing '\n' */
  70. #endif
  71.     return(fullname);
  72. }
  73.