home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2290 / sub.c < prev   
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.6 KB  |  70 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <sys/types.h>
  10. #include <pwd.h>
  11. #include <utmp.h>
  12. #ifndef    BSD
  13. #include <string.h>
  14. #include <memory.h>
  15. #else
  16. #include <strings.h>
  17. #define    strchr    index
  18. #define    strrchr    rindex
  19. #endif
  20.  
  21. #ifndef    lint
  22. static    char    _sccsid[] = "@(#)sub.c    2.2    19:24:19    7/29/90";
  23. #endif
  24.  
  25. extern    struct    passwd    pwent;
  26. #ifndef    SU
  27. extern    struct    utmp    utent;
  28. #endif
  29.  
  30. void    setutmp ();
  31.  
  32. /*
  33.  * I have heard of two different types of behavior with subsystem roots.
  34.  * One has you execute login no matter what.  The other has you execute
  35.  * the command [ if one exists ] after the '*' in the shell name.  The
  36.  * macro SUBLOGIN says to execute /bin/login [ followed by /etc/login ]
  37.  * regardless.  Otherwise, pwent.pw_shell is fixed up and that command
  38.  * is executed [ by returning to the caller ].  I prefer the latter since
  39.  * it doesn't require having a "login" on the new root filesystem.
  40.  */
  41.  
  42. void    subsystem ()
  43. {
  44.     char    *strdup ();
  45.  
  46.     if (pwent.pw_dir[0] != '/')
  47.         exit (1);
  48.  
  49.     if (chdir (pwent.pw_dir) || chroot (pwent.pw_dir)) {
  50.         printf ("Can't change to \"%s\"\n", pwent.pw_dir);
  51.         exit (1);
  52.     }
  53. #ifndef    SU
  54.     (void) strcpy (utent.ut_line, "<!sublogin>");
  55.  
  56.     setutmp ();
  57. #endif
  58. #ifdef    SUBLOGIN
  59.     execl ("/bin/login", "login", name, (char *) 0);
  60.     execl ("/etc/login", "login", name, (char *) 0);
  61.     puts ("No /bin/login or /etc/login on root");
  62.     exit (1);
  63. #else
  64.     if (! pwent.pw_shell || strlen (pwent.pw_shell) == 1)
  65.         pwent.pw_shell = "/bin/sh";    /* default shell */
  66.     else
  67.         pwent.pw_shell++;        /* skip over '*' */
  68. #endif
  69. }
  70.