home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
shadow-2.pt2
/
sub.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-03
|
1KB
|
48 lines
#include <sys/types.h>
#include <pwd.h>
#include <utmp.h>
#include <string.h>
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 (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[1] == '\0')
pwent.pw_shell = "/bin/sh";
else
pwent.pw_shell++;
#endif
}