2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2008-04-27 06:10:09 +05:30
|
|
|
* Copyright (c) 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* Copyright (c) 1996 - 2000, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2002 - 2006, Tomasz Kłoczko
|
|
|
|
* Copyright (c) 2007 - 2008, Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2008-04-27 06:10:09 +05:30
|
|
|
* 3. The name of the copyright holders or contributors may not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* specific prior written permission.
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2008-04-27 06:10:09 +05:30
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <pwd.h>
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
2007-12-27 04:06:54 +05:30
|
|
|
#include <sys/ioctl.h>
|
2007-10-07 17:17:01 +05:30
|
|
|
#include "defines.h"
|
|
|
|
#include "getdef.h"
|
|
|
|
#include "prototypes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "pwauth.h"
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "exitcodes.h"
|
2007-10-07 17:17:01 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2007-10-07 17:14:02 +05:30
|
|
|
static char name[BUFSIZ];
|
|
|
|
static char pass[BUFSIZ];
|
|
|
|
|
|
|
|
static struct passwd pwent;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
extern char **newenvp;
|
|
|
|
extern size_t newenvc;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
extern char **environ;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifndef ALARM
|
|
|
|
#define ALARM 60
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:17:22 +05:30
|
|
|
static RETSIGTYPE catch_signals (int);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-01-06 18:50:25 +05:30
|
|
|
static RETSIGTYPE catch_signals (unused int sig)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* syslogd is usually not running at the time when sulogin is typically
|
|
|
|
* called, cluttering the screen with unnecessary messages. Suggested by
|
|
|
|
* Ivan Nejgebauer <ian@unsux.ns.ac.yu>. --marekm
|
|
|
|
*/
|
2007-10-07 17:14:02 +05:30
|
|
|
#undef USE_SYSLOG
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/*ARGSUSED*/ int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
char *cp;
|
|
|
|
char **envp = environ;
|
|
|
|
TERMIO termio;
|
2007-10-07 17:17:22 +05:30
|
|
|
int err = 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef USE_TERMIO
|
|
|
|
ioctl (0, TCGETA, &termio);
|
2007-10-07 17:14:59 +05:30
|
|
|
termio.c_iflag |= (ICRNL | IXON);
|
|
|
|
termio.c_oflag |= (OPOST | ONLCR);
|
2007-10-07 17:14:02 +05:30
|
|
|
termio.c_cflag |= (CREAD);
|
2007-10-07 17:14:59 +05:30
|
|
|
termio.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK);
|
2007-10-07 17:14:02 +05:30
|
|
|
ioctl (0, TCSETAF, &termio);
|
|
|
|
#endif
|
|
|
|
#ifdef USE_TERMIOS
|
|
|
|
tcgetattr (0, &termio);
|
2007-10-07 17:14:59 +05:30
|
|
|
termio.c_iflag |= (ICRNL | IXON);
|
2007-10-07 17:14:02 +05:30
|
|
|
termio.c_oflag |= (CREAD);
|
2007-10-07 17:14:59 +05:30
|
|
|
termio.c_lflag |= (ECHO | ECHOE | ECHOK | ICANON | ISIG);
|
2007-10-07 17:14:02 +05:30
|
|
|
tcsetattr (0, TCSANOW, &termio);
|
|
|
|
#endif
|
|
|
|
|
2008-06-11 01:06:05 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:14:59 +05:30
|
|
|
OPENLOG ("sulogin");
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
initenv ();
|
2007-10-07 17:14:02 +05:30
|
|
|
if (argc > 1) {
|
|
|
|
close (0);
|
|
|
|
close (1);
|
|
|
|
close (2);
|
|
|
|
|
|
|
|
if (open (argv[1], O_RDWR) >= 0) {
|
|
|
|
dup (0);
|
|
|
|
dup (0);
|
|
|
|
} else {
|
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG (LOG_WARN, "cannot open %s\n", argv[1]);
|
2007-10-07 17:14:02 +05:30
|
|
|
closelog ();
|
|
|
|
#endif
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (access (PASSWD_FILE, F_OK) == -1) { /* must be a password file! */
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("No password file"));
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG (LOG_WARN, "No password file\n");
|
2007-10-07 17:14:02 +05:30
|
|
|
closelog ();
|
|
|
|
#endif
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#if !defined(DEBUG) && defined(SULOGIN_ONLY_INIT)
|
2007-10-07 17:14:59 +05:30
|
|
|
if (getppid () != 1) { /* parent must be INIT */
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG (LOG_WARN, "Pid == %d, not 1\n", getppid ());
|
2007-10-07 17:14:02 +05:30
|
|
|
closelog ();
|
|
|
|
#endif
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
#endif
|
2008-06-11 01:06:05 +05:30
|
|
|
if ((isatty (0) == 0) || (isatty (1) == 0) || (isatty (2) == 0)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_SYSLOG
|
|
|
|
closelog ();
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1); /* must be a terminal */
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-12-27 04:06:54 +05:30
|
|
|
/* If we were init, we need to start a new session */
|
|
|
|
if (getppid() == 1) {
|
|
|
|
setsid();
|
2008-06-11 01:06:05 +05:30
|
|
|
if (ioctl(0, TIOCSCTTY, 1) != 0) {
|
2008-01-25 01:08:06 +05:30
|
|
|
fputs (_("TIOCSCTTY failed"), stderr);
|
2008-06-11 01:06:05 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
while (NULL != *envp) { /* add inherited environment, */
|
|
|
|
addenv (*envp, NULL); /* some variables change later */
|
|
|
|
envp++;
|
2007-12-27 04:06:54 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifndef USE_PAM
|
|
|
|
|
2008-06-11 01:06:05 +05:30
|
|
|
cp = getdef_str ("ENV_TZ");
|
|
|
|
if (NULL != cp) {
|
|
|
|
addenv (('/' == *cp) ? tz (cp) : cp, NULL);
|
|
|
|
}
|
|
|
|
cp = getdef_str ("ENV_HZ");
|
|
|
|
if (NULL != cp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv (cp, NULL); /* set the default $HZ, if one */
|
2008-06-11 01:06:05 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#endif /* !USE_PAM */
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
(void) strcpy (name, "root"); /* KLUDGE!!! */
|
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
signal (SIGALRM, catch_signals); /* exit if the timer expires */
|
2007-10-07 17:14:59 +05:30
|
|
|
alarm (ALARM); /* only wait so long ... */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:06:05 +05:30
|
|
|
while (true) { /* repeatedly get login/password pairs */
|
2007-10-07 17:14:59 +05:30
|
|
|
pw_entry (name, &pwent); /* get entry from password file */
|
2007-10-07 17:14:02 +05:30
|
|
|
if (pwent.pw_name == (char *) 0) {
|
|
|
|
/*
|
|
|
|
* Fail secure
|
|
|
|
*/
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("No password entry for 'root'"));
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG (LOG_WARN, "No password entry for 'root'\n");
|
2007-10-07 17:14:02 +05:30
|
|
|
closelog ();
|
|
|
|
#endif
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* Here we prompt for the root password, or if no password
|
|
|
|
* is given we just exit.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* get a password for root */
|
|
|
|
cp = getpass (_
|
2007-10-07 17:17:33 +05:30
|
|
|
("\n"
|
|
|
|
"Type control-d to proceed with normal startup,\n"
|
|
|
|
"(or give root password for system maintenance):"));
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* XXX - can't enter single user mode if root password is
|
|
|
|
* empty. I think this doesn't happen very often :-). But
|
|
|
|
* it will work with standard getpass() (no NULL on EOF).
|
|
|
|
* --marekm
|
|
|
|
*/
|
2008-06-11 01:06:05 +05:30
|
|
|
if ((NULL == cp) || ('\0' == *cp)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG (LOG_INFO, "Normal startup\n");
|
2007-10-07 17:14:02 +05:30
|
|
|
closelog ();
|
|
|
|
#endif
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts ("");
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef TELINIT
|
2007-10-07 17:16:07 +05:30
|
|
|
execl (PATH_TELINIT, "telinit", RUNLEVEL, (char *) 0);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
exit (0);
|
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
STRFCPY (pass, cp);
|
|
|
|
strzero (cp);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (valid (pass, &pwent)) /* check encrypted passwords ... */
|
|
|
|
break; /* ... encrypted passwords matched */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG (LOG_WARN, "Incorrect root password\n");
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
sleep (2);
|
2007-10-07 17:14:02 +05:30
|
|
|
puts (_("Login incorrect"));
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
strzero (pass);
|
2008-06-11 01:06:05 +05:30
|
|
|
(void) alarm (0);
|
2007-10-07 17:14:02 +05:30
|
|
|
signal (SIGALRM, SIG_DFL);
|
2007-10-07 17:14:59 +05:30
|
|
|
environ = newenvp; /* make new environment active */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
* libmisc/age.c, libmisc/yesno.c, src/lastlog.c, src/grpck.c,
src/chfn.c, src/passwd.c, src/chage.c, src/login.c, src/sulogin.c,
src/chsh.c: Fix call to puts (remove end of line, or use fputs).
* po/*.po: Unfuzzy PO files according to above change.
2008-02-03 21:58:03 +05:30
|
|
|
puts (_("Entering System Maintenance Mode"));
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef USE_SYSLOG
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG (LOG_INFO, "System Maintenance Mode\n");
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SYSLOG
|
|
|
|
closelog ();
|
|
|
|
#endif
|
2007-10-07 17:17:22 +05:30
|
|
|
/* exec the shell finally. */
|
|
|
|
err = shell (pwent.pw_shell, (char *) 0, environ);
|
2008-06-11 01:06:05 +05:30
|
|
|
exit ((err == ENOENT) ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
|
2007-10-07 17:14:59 +05:30
|
|
|
/*NOTREACHED*/ return (0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-11 01:06:05 +05:30
|
|
|
|