home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume38 / shadow / part13 / hushed.c < prev    next >
C/C++ Source or Header  |  1993-08-14  |  2KB  |  81 lines

  1. /*
  2.  * Copyright 1991, 1993, John F. Haugh II and Chip Rosenthal
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  *
  11.  * This software is provided on an AS-IS basis and the author makes
  12.  * no warrantee of any kind.
  13.  */
  14.  
  15. #ifndef lint
  16. static    char    sccsid[] = "@(#)hushed.c    3.2    22:02:26    02 Jun 1993";
  17. #endif
  18.  
  19. #include <sys/types.h>
  20. #include <stdio.h>
  21. #ifndef BSD
  22. # include <string.h>
  23. #else
  24. # include <strings.h>
  25. #endif
  26. #include "config.h"
  27. #include "pwd.h"
  28.  
  29. extern char *getdef_str();
  30.  
  31. /*
  32.  * hushed - determine if a user receives login messages
  33.  *
  34.  * Look in the hushed-logins file (or user's home directory) to see
  35.  * if the user is to receive the login-time messages.
  36.  */
  37.  
  38. int
  39. hushed(pw)
  40. struct passwd *pw;
  41. {
  42.     char *hushfile;
  43.     char buf[BUFSIZ];
  44.     int found;
  45.     FILE *fp;
  46.  
  47.     /*
  48.      * Get the name of the file to use.  If this option is not
  49.      * defined, default to a noisy login.
  50.      */
  51.  
  52.     if ( (hushfile=getdef_str("HUSHLOGIN_FILE")) == NULL )
  53.         return 0;
  54.  
  55.     /*
  56.      * If this is not a fully rooted path then see if the
  57.      * file exists in the user's home directory.
  58.      */
  59.  
  60.     if (hushfile[0] != '/') {
  61.         strcat(strcat(strcpy(buf, pw->pw_dir), "/"), hushfile);
  62.         return (access(buf, 0) == 0);
  63.     }
  64.  
  65.     /*
  66.      * If this is a fully rooted path then go through the file
  67.      * and see if this user is in there.
  68.      */
  69.  
  70.     if ((fp = fopen(hushfile, "r")) == NULL)
  71.         return 0;
  72.  
  73.     for (found = 0;! found && fgets (buf, sizeof buf, fp);) {
  74.         buf[strlen (buf) - 1] = '\0';
  75.         found = ! strcmp (buf,
  76.             buf[0] == '/' ? pw->pw_shell:pw->pw_name);
  77.     }
  78.     (void) fclose(fp);
  79.     return found;
  80. }
  81.