home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <stdio.h>
- #include <pwd.h>
- #include <utmp.h>
- #include "config.h"
- #include "lastlog.h"
-
- char name[BUFSIZ];
- char pass[BUFSIZ];
- char home[BUFSIZ];
- char prog[BUFSIZ];
- char mail[BUFSIZ];
-
- struct passwd pwent;
- struct utmp utent;
- struct lastlog lastlog;
-
- #ifndef MAXENV
- #define MAXENV 64
- #endif
-
- char *newenvp[MAXENV];
- int newenvc = 0;
- int maxenv = MAXENV;
- extern char **environ;
-
- #ifndef ALARM
- #define ALARM 60
- #endif
-
- #ifndef RETRIES
- #define RETRIES 3
- #endif
-
- int main (argc, argv, envp)
- int argc;
- char **argv;
- char **envp;
- {
- char *getenv ();
- char *ttyname ();
- char *cp;
-
- if (access (PWDFILE, 0) == -1) { /* must be a password file! */
- printf ("No password file\n");
- exit (1);
- }
- #ifndef DEBUG
- if (getppid () != 1) /* parent must be INIT */
- exit (1);
- #endif
- if (! isatty (0)) /* must be a terminal */
- exit (1);
-
- while (*envp) /* add inherited environment, */
- addenv (*envp++); /* some variables change later */
-
- #ifdef TZ
- addenv (TZ); /* set the default $TZ, if one */
- #endif
- #ifdef HZ
- addenv (HZ); /* set the default $HZ, if one */
- #endif
- (void) strcpy (name, "root"); /* KLUDGE!!! */
-
- while (1) { /* repeatedly get login/password pairs */
- entry (name, &pwent); /* get entry from password file */
- if (pwent.pw_name == (char *) 0) {
- printf ("No password entry for 'root'\n");
- exit (1);
- }
-
- /*
- * Here we prompt for the root password, or if no password is
- * given we just exit and let INIT go to runlevel 2.
- */
-
- /* get a password for root */
- if (! password ("Type control-d for normal startup,\n(or give root password for system maintenance):", pass))
- exit (0);
-
- if (valid (pass, &pwent)) /* check encrypted passwords ... */
- break; /* ... encrypted passwords matched */
-
- puts ("Login incorrect");
- }
- environ = newenvp; /* make new environment active */
-
- puts ("Entering System Maintenance Mode");
-
- /*
- * Normally there would be a utmp entry for login to mung on
- * to get the tty name, date, etc. from. We don't need all that
- * stuff because we won't update the utmp or wtmp files. BUT!,
- * we do need the tty name so we can set the permissions and
- * ownership.
- */
-
- if (cp = ttyname (0)) /* found entry in /dev/ */
- strcpy (utent.ut_line, cp); /* needed for tty perms (setup) */
-
- if (getenv ("IFS")) /* don't export user IFS ... */
- addenv ("IFS= \t\n"); /* ... instead, set a safe IFS */
-
- setup (&pwent); /* set UID, GID, HOME, etc ... */
-
- shell (pwent.pw_shell); /* exec the shell finally. */
- /*NOTREACHED*/
- }
-