home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1989, 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <sys/types.h>
- #include <pwd.h>
- #include <utmp.h>
- #ifndef BSD
- #include <string.h>
- #include <memory.h>
- #else
- #include <strings.h>
- #define strchr index
- #define strrchr rindex
- #endif
-
- #ifndef lint
- static char _sccsid[] = "@(#)sub.c 2.2 19:24:19 7/29/90";
- #endif
-
- extern struct passwd pwent;
- #ifndef SU
- extern struct utmp utent;
- #endif
-
- void setutmp ();
-
- /*
- * I have heard of two different types of behavior with subsystem roots.
- * One has you execute login no matter what. The other has you execute
- * the command [ if one exists ] after the '*' in the shell name. The
- * macro SUBLOGIN says to execute /bin/login [ followed by /etc/login ]
- * regardless. Otherwise, pwent.pw_shell is fixed up and that command
- * is executed [ by returning to the caller ]. I prefer the latter since
- * it doesn't require having a "login" on the new root filesystem.
- */
-
- void subsystem ()
- {
- char *strdup ();
-
- if (pwent.pw_dir[0] != '/')
- exit (1);
-
- if (chdir (pwent.pw_dir) || chroot (pwent.pw_dir)) {
- printf ("Can't change to \"%s\"\n", pwent.pw_dir);
- exit (1);
- }
- #ifndef SU
- (void) strcpy (utent.ut_line, "<!sublogin>");
-
- setutmp ();
- #endif
- #ifdef SUBLOGIN
- execl ("/bin/login", "login", name, (char *) 0);
- execl ("/etc/login", "login", name, (char *) 0);
- puts ("No /bin/login or /etc/login on root");
- exit (1);
- #else
- if (! pwent.pw_shell || strlen (pwent.pw_shell) == 1)
- pwent.pw_shell = "/bin/sh"; /* default shell */
- else
- pwent.pw_shell++; /* skip over '*' */
- #endif
- }
-