home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / shadow-3.1.4 / login.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-05  |  2.0 KB  |  103 lines

  1. /*
  2.  * Copyright 1989, 1990, 1991, 1992, John F. Haugh II
  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.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14. #ifndef    BSD
  15. #include <string.h>
  16. #include <memory.h>
  17. #else
  18. #include <strings.h>
  19. #define    strchr    index
  20. #define    strrchr    rindex
  21. #endif
  22.  
  23. #ifndef    lint
  24. static    char    sccsid[] = "@(#)login.c    3.2    20:37:17    3/7/92";
  25. #endif
  26.  
  27. void    setenv ();
  28.  
  29. /*
  30.  * login - prompt the user for their login name
  31.  *
  32.  * login() displays the standard login prompt.  If the option
  33.  * ISSUE_FILE_ENAB is set, the file /etc/issue is displayed
  34.  * before the prompt.
  35.  */
  36.  
  37. void
  38. login (name, prompt)
  39. char    *name;
  40. char    *prompt;
  41. {
  42.     char    buf[BUFSIZ];
  43.     char    *envp[32];
  44.     int    envc;
  45.     char    *cp;
  46.     int    i;
  47.     FILE    *fp;
  48.  
  49.     /*
  50.      * See if the user has configured the /etc/issue file to
  51.      * be displayed and display it before the prompt.
  52.      */
  53.  
  54.     if (prompt) {
  55.         if (getdef_bool ("ISSUE_FILE_ENAB")) {
  56.             if (fp = fopen ("/etc/issue", "r")) {
  57.                 while ((i = getc (fp)) != EOF)
  58.                     putc (i, stdout);
  59.  
  60.                 fflush (stdout);
  61.                 fclose (fp);
  62.             }
  63.         }
  64.         fputs (prompt, stdout);
  65.     }
  66.  
  67.     /* 
  68.      * Read the user's response.  The trailing newline will be
  69.      * removed.
  70.      */
  71.  
  72. #ifndef    BSD
  73.     (void) memset (buf, '\0', sizeof buf);
  74. #else
  75.     bzero (buf, sizeof buf);
  76. #endif
  77.     if (fgets (buf, BUFSIZ, stdin) != buf)
  78.         exit (1);
  79.  
  80.     buf[strlen (buf) - 1] = '\0';    /* remove \n [ must be there ] */
  81.  
  82.     for (cp = buf;*cp == ' ' || *cp == '\t';cp++)
  83.         ;
  84.  
  85.     for (i = 0;i < BUFSIZ - 1 && isgraph (*cp);name[i++] = *cp++)
  86.         ;
  87.  
  88.     if (*cp)
  89.         cp++;
  90.  
  91.     name[i] = '\0';
  92.  
  93.     if (*cp != '\0') {        /* process new variables */
  94.         for (envc = 0;envc < 32;envc++) {
  95.             envp[envc] = strtok (envc == 0 ? cp:(char *) 0, " \t,");
  96.  
  97.             if (envp[envc] == (char *) 0)
  98.                 break;
  99.         }
  100.         setenv (envc, envp);
  101.     }
  102. }
  103.