home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume9 / elm2 / part01 / src / validname.c < prev   
Encoding:
C/C++ Source or Header  |  1987-03-08  |  848 b   |  52 lines

  1. /**            validname.c            **/
  2.  
  3. /** This routine takes a single address, no machine hops or
  4.     anything, and returns 1 if it's valid and 0 if not.  The
  5.     algorithm it uses is the same one that uux uses, namely:
  6.  
  7.     1. Is there a file '/usr/mail/%s'?  
  8.     2. Is there a password entry for %s?
  9.     
  10.    (C) Copyright 1986 Dave Taylor 
  11. **/
  12.  
  13. #include "defs.h"
  14.  
  15. #include <stdio.h>
  16.  
  17. #ifndef NOCHECK_VALIDNAME
  18. #  ifdef BSD4.1
  19. #    include <sys/pwd.h>
  20. #  else
  21. #    include <pwd.h>
  22. #  endif
  23. #endif
  24.  
  25. int
  26. valid_name(name)
  27. char *name;
  28. {
  29.     /** does what it says above, boss! **/
  30.  
  31. #ifdef NOCHECK_VALIDNAME
  32.  
  33.     return(1);        /* always say it's okay! */
  34.  
  35. #else
  36.     struct passwd *getpwname();
  37.     char filebuf[SLEN];
  38.  
  39.     sprintf(filebuf,"%s/%s", mailhome, name);
  40.     
  41.     if (access(filebuf, ACCESS_EXISTS) == 0)
  42.       return(1);
  43.  
  44.     if (getpwnam(name) != NULL)
  45.       return(1);
  46.  
  47.     return(0);
  48.  
  49. #endif
  50.  
  51. }
  52.