home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / shadow-2.pt2 / sub.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  1KB  |  48 lines

  1. #include <sys/types.h>
  2. #include <pwd.h>
  3. #include <utmp.h>
  4. #include <string.h>
  5.  
  6. extern    struct    passwd    pwent;
  7. #ifndef    SU
  8. extern    struct    utmp    utent;
  9. #endif
  10.  
  11. void    setutmp ();
  12.  
  13. /*
  14.  * I have heard of two different types of behavior with subsystem roots.
  15.  * One has you execute login no matter what.  The other has you execute
  16.  * the command [ if one exists ] after the '*' in the shell name.  The
  17.  * macro SUBLOGIN says to execute /bin/login [ followed by /etc/login ]
  18.  * regardless.  Otherwise, pwent.pw_shell is fixed up and that command
  19.  * is executed [ by returning to the caller ].  I prefer the latter since
  20.  * it doesn't require having a "login" on the new root filesystem.
  21.  */
  22.  
  23. void    subsystem ()
  24. {
  25.     char    *strdup ();
  26.  
  27.     if (chdir (pwent.pw_dir) || chroot (pwent.pw_dir)) {
  28.         printf ("Can't change to \"%s\"\n", pwent.pw_dir);
  29.         exit (1);
  30.     }
  31. #ifndef    SU
  32.     (void) strcpy (utent.ut_line, "<!sublogin>");
  33.  
  34.     setutmp ();
  35. #endif
  36. #ifdef    SUBLOGIN
  37.     execl ("/bin/login", "login", name, (char *) 0);
  38.     execl ("/etc/login", "login", name, (char *) 0);
  39.     puts ("No /bin/login or /etc/login on root");
  40.     exit (1);
  41. #else
  42.     if (pwent.pw_shell[1] == '\0')
  43.         pwent.pw_shell = "/bin/sh";
  44.     else
  45.         pwent.pw_shell++;
  46. #endif
  47. }
  48.