2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Copyright 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* 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.
|
|
|
|
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH 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
|
2007-10-07 17:14:59 +05:30
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
|
2007-10-07 17:14:02 +05:30
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <errno.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <lastlog.h>
|
|
|
|
#ifdef UT_ADDR
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
2007-10-07 17:17:01 +05:30
|
|
|
#include <pwd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/stat.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 "faillog.h"
|
|
|
|
#include "failure.h"
|
|
|
|
#include "getdef.h"
|
|
|
|
#include "prototypes.h"
|
|
|
|
#include "pwauth.h"
|
2007-10-07 17:17:22 +05:30
|
|
|
#include "exitcodes.h"
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifdef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "pam_defs.h"
|
|
|
|
|
|
|
|
static pam_handle_t *pamh = NULL;
|
|
|
|
|
|
|
|
#define PAM_FAIL_CHECK if (retcode != PAM_SUCCESS) { \
|
2007-10-07 17:14:51 +05:30
|
|
|
fprintf(stderr,"\n%s\n",pam_strerror(pamh, retcode)); \
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG((LOG_ERR,"%s",pam_strerror(pamh, retcode))); \
|
2007-10-07 17:14:02 +05:30
|
|
|
pam_end(pamh, retcode); exit(1); \
|
|
|
|
}
|
|
|
|
#define PAM_END { retcode = pam_close_session(pamh,0); \
|
|
|
|
pam_end(pamh,retcode); }
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Needed for MkLinux DR1/2/2.1 - J.
|
|
|
|
*/
|
|
|
|
#ifndef LASTLOG_FILE
|
|
|
|
#define LASTLOG_FILE "/var/log/lastlog"
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2007-10-07 17:14:02 +05:30
|
|
|
const char *hostname = "";
|
|
|
|
|
2007-10-07 17:15:14 +05:30
|
|
|
static struct passwd pwent;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#if HAVE_UTMPX_H
|
2007-10-07 17:16:07 +05:30
|
|
|
extern struct utmpx utxent;
|
2007-10-07 17:15:14 +05:30
|
|
|
struct utmpx failent;
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:15:14 +05:30
|
|
|
struct utmp failent;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:16:07 +05:30
|
|
|
extern struct utmp utent;
|
2007-10-07 17:15:14 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
struct lastlog lastlog;
|
2007-10-07 17:14:02 +05:30
|
|
|
static int pflg = 0;
|
|
|
|
static int fflg = 0;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
|
|
|
static int rflg = 0;
|
|
|
|
#else
|
|
|
|
#define rflg 0
|
|
|
|
#endif
|
|
|
|
static int hflg = 0;
|
|
|
|
static int preauth_flag = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Global variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *Prog;
|
|
|
|
static int amroot;
|
|
|
|
static int timeout;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* External identifiers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
#ifndef RETRIES
|
|
|
|
#define RETRIES 3
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* local function prototypes */
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void);
|
|
|
|
static void setup_tty (void);
|
|
|
|
static void check_flags (int, char *const *);
|
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:16:07 +05:30
|
|
|
extern int login_access (const char *, const char *);
|
|
|
|
|
|
|
|
static struct faillog faillog;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void bad_time_notify (void);
|
|
|
|
static void check_nologin (void);
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void init_env (void);
|
|
|
|
static RETSIGTYPE alarm_handler (int);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* usage - print login command usage and exit
|
|
|
|
*
|
|
|
|
* login [ name ]
|
|
|
|
* login -r hostname (for rlogind)
|
|
|
|
* login -h hostname (for telnetd, etc.)
|
|
|
|
* login -f name (for pre-authenticated login: datakit, xterm, etc.)
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void usage (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:15:23 +05:30
|
|
|
fprintf (stderr, _("Usage: %s [-p] [name]\n"), Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (!amroot)
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
|
|
|
fprintf (stderr, _(" %s [-p] [-h host] [-f name]\n"), Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
2007-10-07 17:14:59 +05:30
|
|
|
fprintf (stderr, _(" %s [-p] -r host\n"), Prog);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
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
|
|
|
static void setup_tty (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
TERMIO termio;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
GTTY (0, &termio); /* get terminal characteristics */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Add your favorite terminal modes here ...
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
termio.c_lflag |= ISIG | ICANON | ECHO | ECHOE;
|
2007-10-07 17:14:02 +05:30
|
|
|
termio.c_iflag |= ICRNL;
|
|
|
|
|
|
|
|
/* leave these values unchanged if not specified in login.defs */
|
2007-10-07 17:16:07 +05:30
|
|
|
termio.c_cc[VERASE] = getdef_num ("ERASECHAR", termio.c_cc[VERASE]);
|
2007-10-07 17:14:59 +05:30
|
|
|
termio.c_cc[VKILL] = getdef_num ("KILLCHAR", termio.c_cc[VKILL]);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* ttymon invocation prefers this, but these settings won't come into
|
|
|
|
* effect after the first username login
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
STTY (0, &termio);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Tell the user that this is not the right time to login at this tty
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
static void bad_time_notify (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-01-25 02:12:12 +05:30
|
|
|
puts (_("Invalid login time\n"));
|
2007-10-07 17:14:59 +05:30
|
|
|
fflush (stdout);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void check_nologin (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
char *fname;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if system is turned off for non-root users.
|
|
|
|
* This would be useful to prevent users from logging in
|
2007-10-07 17:14:59 +05:30
|
|
|
* during system maintenance. We make sure the message comes
|
2007-10-07 17:14:02 +05:30
|
|
|
* out for root so she knows to remove the file if she's
|
|
|
|
* forgotten about it ...
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
fname = getdef_str ("NOLOGINS_FILE");
|
|
|
|
if (fname != NULL && access (fname, F_OK) == 0) {
|
|
|
|
FILE *nlfp;
|
|
|
|
int c;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Cat the file if it can be opened, otherwise just
|
|
|
|
* print a default message
|
|
|
|
*/
|
|
|
|
if ((nlfp = fopen (fname, "r"))) {
|
|
|
|
while ((c = getc (nlfp)) != EOF) {
|
|
|
|
if (c == '\n')
|
|
|
|
putchar ('\r');
|
|
|
|
|
|
|
|
putchar (c);
|
|
|
|
}
|
|
|
|
fflush (stdout);
|
|
|
|
fclose (nlfp);
|
|
|
|
} else
|
2008-01-25 02:12:12 +05:30
|
|
|
puts (_("\nSystem closed for routine maintenance\n"));
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Non-root users must exit. Root gets the message, but
|
2007-10-07 17:14:02 +05:30
|
|
|
* gets to login.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (pwent.pw_uid != 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-01-25 02:12:12 +05:30
|
|
|
puts (_("\n[Disconnect bypassed -- root login allowed.]\n"));
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void check_flags (int argc, char *const *argv)
|
|
|
|
{
|
|
|
|
int arg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the flags for proper form. Every argument starting with
|
|
|
|
* "-" must be exactly two characters long. This closes all the
|
|
|
|
* clever rlogin, telnet, and getty holes.
|
|
|
|
*/
|
|
|
|
for (arg = 1; arg < argc; arg++) {
|
|
|
|
if (argv[arg][0] == '-' && strlen (argv[arg]) > 2)
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void init_env (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:17:22 +05:30
|
|
|
#ifndef USE_PAM
|
|
|
|
char *cp;
|
|
|
|
#endif
|
|
|
|
char *tmp;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if ((tmp = getenv ("LANG"))) {
|
|
|
|
addenv ("LANG", tmp);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the timezone environmental variable so that time functions
|
|
|
|
* work correctly.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if ((tmp = getenv ("TZ"))) {
|
|
|
|
addenv ("TZ", tmp);
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:17:01 +05:30
|
|
|
else if ((cp = getdef_str ("ENV_TZ")))
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv (*cp == '/' ? tz (cp) : cp, NULL);
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Add the clock frequency so that profiling commands work
|
|
|
|
* correctly.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if ((tmp = getenv ("HZ"))) {
|
|
|
|
addenv ("HZ", tmp);
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:17:01 +05:30
|
|
|
else if ((cp = getdef_str ("ENV_HZ")))
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv (cp, NULL);
|
2007-10-07 17:17:01 +05:30
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-06 18:50:25 +05:30
|
|
|
static RETSIGTYPE alarm_handler (unused int sig)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
fprintf (stderr, _("\nLogin timed out after %d seconds.\n"), timeout);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* login - create a new login session for a user
|
|
|
|
*
|
|
|
|
* login is typically called by getty as the second step of a
|
2007-10-07 17:14:59 +05:30
|
|
|
* new user session. getty is responsible for setting the line
|
2007-10-07 17:14:02 +05:30
|
|
|
* characteristics to a reasonable set of values and getting
|
2007-10-07 17:14:59 +05:30
|
|
|
* the name of the user to be logged in. login may also be
|
2007-10-07 17:14:02 +05:30
|
|
|
* called to create a new user session on a pty for a variety
|
|
|
|
* of reasons, such as X servers or network logins.
|
|
|
|
*
|
|
|
|
* the flags which login supports are
|
|
|
|
*
|
|
|
|
* -p - preserve the environment
|
|
|
|
* -r - perform autologin protocol for rlogin
|
|
|
|
* -f - do not perform authentication, user is preauthenticated
|
|
|
|
* -h - the name of the remote host
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
int main (int argc, char **argv)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
char username[32];
|
|
|
|
char tty[BUFSIZ];
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
2007-10-07 17:14:59 +05:30
|
|
|
char term[128] = "";
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
#if defined(HAVE_STRFTIME) && !defined(USE_PAM)
|
2007-10-07 17:14:02 +05:30
|
|
|
char ptime[80];
|
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
int reason = PW_LOGIN;
|
|
|
|
int delay;
|
|
|
|
int retries;
|
|
|
|
int failed;
|
|
|
|
int flag;
|
|
|
|
int subroot = 0;
|
2007-12-09 04:57:35 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
int is_console;
|
2007-12-09 04:57:35 +05:30
|
|
|
#endif
|
2007-10-07 17:17:22 +05:30
|
|
|
int err;
|
2007-10-07 17:14:02 +05:30
|
|
|
const char *cp;
|
2007-10-07 17:14:59 +05:30
|
|
|
char *tmp;
|
|
|
|
char fromhost[512];
|
|
|
|
struct passwd *pwd;
|
|
|
|
char **envp = environ;
|
2007-10-07 17:14:02 +05:30
|
|
|
static char temp_pw[2];
|
|
|
|
static char temp_shell[] = "/bin/sh";
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifdef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
int retcode;
|
|
|
|
pid_t child;
|
2007-10-07 17:14:14 +05:30
|
|
|
char *pam_user;
|
2007-11-20 01:55:36 +05:30
|
|
|
char **ptr_pam_user = &pam_user;
|
2007-10-07 17:16:34 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
struct spwd *spwd = NULL;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Some quick initialization.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
sanitize_env ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
initenv ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
username[0] = '\0';
|
2007-10-07 17:14:59 +05:30
|
|
|
amroot = (getuid () == 0);
|
|
|
|
Prog = Basename (argv[0]);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
check_flags (argc, argv);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:25 +05:30
|
|
|
while ((flag = getopt (argc, argv, "d:f::h:pr:")) != EOF) {
|
2007-10-07 17:14:02 +05:30
|
|
|
switch (flag) {
|
2007-10-07 17:16:34 +05:30
|
|
|
case 'd':
|
|
|
|
/* "-d device" ignored for compatibility */
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
/*
|
|
|
|
* username must be a separate token
|
|
|
|
* (-f root, *not* -froot). --marekm
|
2007-10-07 17:16:25 +05:30
|
|
|
*
|
|
|
|
* if -f has an arg, use that, else use the
|
|
|
|
* normal user name passed after all options
|
|
|
|
* --benc
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:16:25 +05:30
|
|
|
if (optarg != NULL && optarg != argv[optind - 1])
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
fflg++;
|
2007-10-07 17:16:25 +05:30
|
|
|
if (optarg)
|
|
|
|
STRFCPY (username, optarg);
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2007-10-07 17:16:34 +05:30
|
|
|
case 'h':
|
|
|
|
hflg++;
|
|
|
|
hostname = optarg;
|
|
|
|
reason = PW_TELNET;
|
|
|
|
break;
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
|
|
|
case 'r':
|
|
|
|
rflg++;
|
|
|
|
hostname = optarg;
|
|
|
|
reason = PW_RLOGIN;
|
|
|
|
break;
|
|
|
|
#endif
|
2007-10-07 17:16:34 +05:30
|
|
|
case 'p':
|
|
|
|
pflg++;
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
|
|
|
default:
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RLOGIN
|
|
|
|
/*
|
|
|
|
* Neither -h nor -f should be combined with -r.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (rflg && (hflg || fflg))
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow authentication bypass only if real UID is zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((rflg || fflg || hflg) && !amroot) {
|
2007-10-07 17:16:25 +05:30
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
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
|
|
|
if (!isatty (0) || !isatty (1) || !isatty (2))
|
|
|
|
exit (1); /* must be a terminal */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Be picky if run by normal users (possible if installed setuid
|
2007-10-07 17:14:59 +05:30
|
|
|
* root), but not if run by root. This way it still allows logins
|
2007-10-07 17:14:02 +05:30
|
|
|
* even if your getty is broken, or if something corrupts utmp,
|
|
|
|
* but users must "exec login" which will use the existing utmp
|
|
|
|
* entry (will not overwrite remote hostname). --marekm
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
checkutmp (!amroot);
|
|
|
|
STRFCPY (tty, utent.ut_line);
|
2007-12-09 04:57:35 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
is_console = console (tty);
|
2007-12-09 04:57:35 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (rflg || hflg) {
|
|
|
|
#ifdef UT_ADDR
|
|
|
|
struct hostent *he;
|
|
|
|
|
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Fill in the ut_addr field (remote login IP address). XXX
|
|
|
|
* - login from util-linux does it, but this is not the
|
|
|
|
* right place to do it. The program that starts login
|
|
|
|
* (telnetd, rlogind) knows the IP address, so it should
|
|
|
|
* create the utmp entry and fill in ut_addr.
|
|
|
|
* gethostbyname() is not 100% reliable (the remote host may
|
|
|
|
* be unknown, etc.). --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if ((he = gethostbyname (hostname))) {
|
2007-10-07 17:16:07 +05:30
|
|
|
utent.ut_addr = *((int32_t *) (he->h_addr_list[0]));
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
#ifdef UT_HOST
|
2007-10-07 17:14:59 +05:30
|
|
|
strncpy (utent.ut_host, hostname,
|
|
|
|
sizeof (utent.ut_host));
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
#if HAVE_UTMPX_H
|
2007-10-07 17:14:59 +05:30
|
|
|
strncpy (utxent.ut_host, hostname,
|
|
|
|
sizeof (utxent.ut_host));
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* Add remote hostname to the environment. I think
|
|
|
|
* (not sure) I saw it once on Irix. --marekm
|
|
|
|
*/
|
|
|
|
addenv ("REMOTEHOST", hostname);
|
|
|
|
}
|
|
|
|
#ifdef __linux__
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* workaround for init/getty leaving junk in ut_host at least in
|
|
|
|
* some version of RedHat. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
else if (amroot)
|
|
|
|
memzero (utent.ut_host, sizeof utent.ut_host);
|
|
|
|
#endif
|
2007-10-07 17:15:40 +05:30
|
|
|
if (fflg)
|
2007-10-07 17:14:59 +05:30
|
|
|
preauth_flag++;
|
2007-10-07 17:15:40 +05:30
|
|
|
if (hflg)
|
|
|
|
reason = PW_RLOGIN;
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
2007-10-07 17:14:59 +05:30
|
|
|
if (rflg
|
|
|
|
&& do_rlogin (hostname, username, sizeof username,
|
|
|
|
term, sizeof term))
|
|
|
|
preauth_flag++;
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
OPENLOG ("login");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
setup_tty ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:17:22 +05:30
|
|
|
umask (getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Use the ULIMIT in the login.defs file, and if
|
|
|
|
* there isn't one, use the default value. The
|
|
|
|
* user may have one for themselves, but otherwise,
|
|
|
|
* just take what you get.
|
|
|
|
*/
|
|
|
|
long limit = getdef_long ("ULIMIT", -1L);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (limit != -1)
|
|
|
|
set_filesize_limit (limit);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* The entire environment will be preserved if the -p flag
|
|
|
|
* is used.
|
|
|
|
*/
|
|
|
|
if (pflg)
|
|
|
|
while (*envp) /* add inherited environment, */
|
|
|
|
addenv (*envp++, NULL); /* some variables change later */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef RLOGIN
|
2007-10-07 17:14:59 +05:30
|
|
|
if (term[0] != '\0')
|
|
|
|
addenv ("TERM", term);
|
|
|
|
else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
/* preserve TERM from getty */
|
|
|
|
if (!pflg && (tmp = getenv ("TERM")))
|
|
|
|
addenv ("TERM", tmp);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
init_env ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (optind < argc) { /* get the user name */
|
2007-10-07 17:16:25 +05:30
|
|
|
if (rflg || (fflg && username[0]))
|
2007-10-07 17:14:59 +05:30
|
|
|
usage ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
STRFCPY (username, argv[optind]);
|
|
|
|
strzero (argv[optind]);
|
|
|
|
++optind;
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
|
|
|
if (optind < argc) /* now set command line variables */
|
|
|
|
set_env (argc - optind, &argv[optind]);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (rflg || hflg)
|
|
|
|
cp = hostname;
|
|
|
|
else
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef UT_HOST
|
2007-10-07 17:14:59 +05:30
|
|
|
if (utent.ut_host[0])
|
|
|
|
cp = utent.ut_host;
|
|
|
|
else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
#if HAVE_UTMPX_H
|
2007-10-07 17:14:59 +05:30
|
|
|
if (utxent.ut_host[0])
|
|
|
|
cp = utxent.ut_host;
|
|
|
|
else
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
cp = "";
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (*cp)
|
|
|
|
snprintf (fromhost, sizeof fromhost,
|
2007-10-07 17:17:33 +05:30
|
|
|
_(" on '%.100s' from '%.200s'"), tty, cp);
|
2007-10-07 17:14:59 +05:30
|
|
|
else
|
|
|
|
snprintf (fromhost, sizeof fromhost,
|
2007-10-07 17:17:33 +05:30
|
|
|
_(" on '%.100s'"), tty);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
top:
|
|
|
|
/* only allow ALARM sec. for login */
|
|
|
|
signal (SIGALRM, alarm_handler);
|
|
|
|
timeout = getdef_num ("LOGIN_TIMEOUT", ALARM);
|
|
|
|
if (timeout > 0)
|
|
|
|
alarm (timeout);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
environ = newenvp; /* make new environment active */
|
|
|
|
delay = getdef_num ("FAIL_DELAY", 1);
|
|
|
|
retries = getdef_num ("LOGIN_RETRIES", RETRIES);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifdef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
retcode = pam_start ("login", username, &conv, &pamh);
|
|
|
|
if (retcode != PAM_SUCCESS) {
|
|
|
|
fprintf (stderr,
|
2007-10-07 17:17:01 +05:30
|
|
|
_("login: PAM Failure, aborting: %s\n"),
|
2007-10-07 17:14:59 +05:30
|
|
|
pam_strerror (pamh, retcode));
|
2007-10-07 17:16:34 +05:30
|
|
|
SYSLOG ((LOG_ERR, "Couldn't initialize PAM: %s",
|
2007-10-07 17:17:01 +05:30
|
|
|
pam_strerror (pamh, retcode)));
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (99);
|
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* hostname & tty are either set to NULL or their correct values,
|
|
|
|
* depending on how much we know. We also set PAM's fail delay to
|
|
|
|
* ours.
|
|
|
|
*/
|
|
|
|
retcode = pam_set_item (pamh, PAM_RHOST, hostname);
|
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
retcode = pam_set_item (pamh, PAM_TTY, tty);
|
2007-10-07 17:14:14 +05:30
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
#ifdef HAVE_PAM_FAIL_DELAY
|
2007-10-07 17:14:59 +05:30
|
|
|
retcode = pam_fail_delay (pamh, 1000000 * delay);
|
|
|
|
PAM_FAIL_CHECK;
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
/* if fflg == 1, then the user has already been authenticated */
|
|
|
|
if (!fflg || (getuid () != 0)) {
|
|
|
|
int failcount = 0;
|
|
|
|
char hostn[256];
|
2008-01-05 19:23:14 +05:30
|
|
|
char loginprompt[256]; /* That's one hell of a prompt :) */
|
2007-10-07 17:14:59 +05:30
|
|
|
|
|
|
|
/* Make the login prompt look like we want it */
|
|
|
|
if (!gethostname (hostn, sizeof (hostn)))
|
2008-01-05 19:23:14 +05:30
|
|
|
snprintf (loginprompt,
|
|
|
|
sizeof (loginprompt),
|
2007-10-07 17:17:22 +05:30
|
|
|
_("%s login: "), hostn);
|
2007-10-07 17:14:59 +05:30
|
|
|
else
|
2008-01-05 19:23:14 +05:30
|
|
|
snprintf (loginprompt,
|
|
|
|
sizeof (loginprompt), _("login: "));
|
2007-10-07 17:14:59 +05:30
|
|
|
|
|
|
|
retcode =
|
2008-01-05 19:23:14 +05:30
|
|
|
pam_set_item (pamh, PAM_USER_PROMPT, loginprompt);
|
2007-10-07 17:14:59 +05:30
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
|
|
|
|
/* if we didn't get a user on the command line,
|
|
|
|
set it to NULL */
|
|
|
|
pam_get_item (pamh, PAM_USER,
|
2007-11-20 01:55:36 +05:30
|
|
|
(const void **)ptr_pam_user);
|
2007-10-07 17:14:59 +05:30
|
|
|
if (pam_user[0] == '\0')
|
|
|
|
pam_set_item (pamh, PAM_USER, NULL);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/*
|
|
|
|
* There may be better ways to deal with some of
|
|
|
|
* these conditions, but at least this way I don't
|
|
|
|
* think we'll be giving away information. Perhaps
|
|
|
|
* someday we can trust that all PAM modules will
|
|
|
|
* pay attention to failure count and get rid of
|
|
|
|
* MAX_LOGIN_TRIES?
|
|
|
|
*/
|
2007-10-07 17:17:22 +05:30
|
|
|
failcount = 0;
|
|
|
|
while (1) {
|
|
|
|
const char *failent_user;
|
|
|
|
failed = 0;
|
|
|
|
|
|
|
|
failcount++;
|
|
|
|
if (delay > 0)
|
|
|
|
retcode = pam_fail_delay(pamh, 1000000*delay);
|
|
|
|
|
|
|
|
retcode = pam_authenticate (pamh, 0);
|
|
|
|
|
|
|
|
pam_get_item (pamh, PAM_USER,
|
2007-11-20 01:55:36 +05:30
|
|
|
(const void **) ptr_pam_user);
|
2007-10-07 17:17:22 +05:30
|
|
|
|
|
|
|
if (pam_user && pam_user[0]) {
|
2007-11-19 04:50:02 +05:30
|
|
|
pwd = xgetpwnam(pam_user);
|
2007-10-07 17:17:22 +05:30
|
|
|
if (pwd) {
|
|
|
|
pwent = *pwd;
|
|
|
|
failent_user = pwent.pw_name;
|
|
|
|
} else {
|
|
|
|
if (getdef_bool("LOG_UNKFAIL_ENAB") && pam_user)
|
|
|
|
failent_user = pam_user;
|
|
|
|
else
|
|
|
|
failent_user = "UNKNOWN";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pwd = NULL;
|
|
|
|
failent_user = "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (retcode == PAM_MAXTRIES || failcount >= retries) {
|
|
|
|
SYSLOG ((LOG_NOTICE,
|
|
|
|
"TOO MANY LOGIN TRIES (%d)%s FOR `%s'",
|
|
|
|
failcount, fromhost, failent_user));
|
|
|
|
fprintf(stderr,
|
|
|
|
_("Maximum number of tries exceeded (%d)\n"),
|
|
|
|
failcount);
|
|
|
|
PAM_END;
|
|
|
|
exit(0);
|
|
|
|
} else if (retcode == PAM_ABORT) {
|
|
|
|
/* Serious problems, quit now */
|
2008-01-25 02:12:12 +05:30
|
|
|
fputs (_("login: abort requested by PAM\n"),stderr);
|
2007-10-07 17:17:22 +05:30
|
|
|
SYSLOG ((LOG_ERR,"PAM_ABORT returned from pam_authenticate()"));
|
|
|
|
PAM_END;
|
|
|
|
exit(99);
|
|
|
|
} else if (retcode != PAM_SUCCESS) {
|
|
|
|
SYSLOG ((LOG_NOTICE,"FAILED LOGIN (%d)%s FOR `%s', %s",
|
|
|
|
failcount, fromhost, failent_user,
|
|
|
|
pam_strerror (pamh, retcode)));
|
|
|
|
failed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!failed)
|
|
|
|
break;
|
2007-10-07 17:17:11 +05:30
|
|
|
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
{
|
|
|
|
struct passwd *pw;
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
audit_fd = audit_open ();
|
2007-11-19 04:50:02 +05:30
|
|
|
/* local, no need for xgetpwnam */
|
2007-10-07 17:17:11 +05:30
|
|
|
pw = getpwnam (username);
|
|
|
|
if (pw) {
|
|
|
|
snprintf (buf, sizeof (buf),
|
|
|
|
"uid=%d", pw->pw_uid);
|
|
|
|
audit_log_user_message
|
|
|
|
(audit_fd, AUDIT_USER_LOGIN,
|
|
|
|
buf, hostname, NULL,
|
|
|
|
tty, 0);
|
|
|
|
} else {
|
|
|
|
snprintf (buf, sizeof (buf),
|
|
|
|
"acct=%s", username);
|
|
|
|
audit_log_user_message
|
|
|
|
(audit_fd, AUDIT_USER_LOGIN,
|
|
|
|
buf, hostname, NULL,
|
|
|
|
tty, 0);
|
|
|
|
}
|
|
|
|
close (audit_fd);
|
|
|
|
}
|
|
|
|
#endif /* WITH_AUDIT */
|
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
fprintf(stderr,"\nLogin incorrect\n");
|
|
|
|
|
|
|
|
/* Let's give it another go around */
|
|
|
|
pam_set_item(pamh,PAM_USER,NULL);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:22 +05:30
|
|
|
/* We don't get here unless they were authenticated above */
|
2007-10-07 17:17:33 +05:30
|
|
|
alarm (0);
|
2007-10-07 17:14:59 +05:30
|
|
|
retcode = pam_acct_mgmt (pamh, 0);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (retcode == PAM_NEW_AUTHTOK_REQD) {
|
|
|
|
retcode =
|
|
|
|
pam_chauthtok (pamh,
|
|
|
|
PAM_CHANGE_EXPIRED_AUTHTOK);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
}
|
2007-10-07 17:14:14 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
/* Grab the user information out of the password file for future usage
|
|
|
|
First get the username that we are actually using, though.
|
|
|
|
*/
|
|
|
|
retcode =
|
2007-11-20 01:55:36 +05:30
|
|
|
pam_get_item (pamh, PAM_USER, (const void **)ptr_pam_user);
|
2007-10-07 17:14:59 +05:30
|
|
|
setpwent ();
|
2007-11-19 04:50:02 +05:30
|
|
|
pwd = xgetpwnam (pam_user);
|
2007-11-17 21:35:54 +05:30
|
|
|
if (!pwd) {
|
2007-11-19 04:50:02 +05:30
|
|
|
SYSLOG ((LOG_ERR, "xgetpwnam(%s) failed",
|
2007-11-17 21:35:54 +05:30
|
|
|
getdef_bool ("LOG_UNKFAIL_ENAB") ?
|
|
|
|
pam_user : "UNKNOWN"));
|
|
|
|
exit (1);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:15:40 +05:30
|
|
|
if (fflg) {
|
2007-10-07 17:16:07 +05:30
|
|
|
retcode = pam_acct_mgmt (pamh, 0);
|
2007-10-07 17:15:40 +05:30
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
}
|
|
|
|
|
2007-11-19 04:22:56 +05:30
|
|
|
if (setup_groups (pwd))
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2007-11-17 21:35:54 +05:30
|
|
|
|
|
|
|
pwent = *pwd;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
retcode = pam_setcred (pamh, PAM_ESTABLISH_CRED);
|
|
|
|
PAM_FAIL_CHECK;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:25 +05:30
|
|
|
retcode = pam_open_session (pamh,
|
|
|
|
hushed (&pwent) ? PAM_SILENT : 0);
|
2007-10-07 17:14:59 +05:30
|
|
|
PAM_FAIL_CHECK;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#else /* ! USE_PAM */
|
|
|
|
while (1) { /* repeatedly get login/password pairs */
|
|
|
|
failed = 0; /* haven't failed authentication yet */
|
2007-10-07 17:16:07 +05:30
|
|
|
if (!username[0]) { /* need to get a login id */
|
|
|
|
if (subroot) {
|
|
|
|
closelog ();
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
preauth_flag = 0;
|
|
|
|
login_prompt (_("\n%s login: "), username,
|
|
|
|
sizeof username);
|
|
|
|
continue;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* ! USE_PAM */
|
2007-10-07 17:14:14 +05:30
|
|
|
|
|
|
|
#ifdef USE_PAM
|
2007-11-19 04:50:02 +05:30
|
|
|
if (!(pwd = xgetpwnam (pam_user))) {
|
2007-10-07 17:14:14 +05:30
|
|
|
pwent.pw_name = pam_user;
|
|
|
|
#else
|
2007-11-19 04:50:02 +05:30
|
|
|
if (!(pwd = xgetpwnam (username))) {
|
2007-10-07 17:14:02 +05:30
|
|
|
pwent.pw_name = username;
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
strcpy (temp_pw, "!");
|
2007-10-07 17:14:02 +05:30
|
|
|
pwent.pw_passwd = temp_pw;
|
|
|
|
pwent.pw_shell = temp_shell;
|
|
|
|
|
|
|
|
preauth_flag = 0;
|
|
|
|
failed = 1;
|
|
|
|
} else {
|
|
|
|
pwent = *pwd;
|
|
|
|
}
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
spwd = NULL;
|
2007-10-07 17:16:07 +05:30
|
|
|
if (pwd && strcmp (pwd->pw_passwd, SHADOW_PASSWD_STRING) == 0) {
|
2007-11-19 04:50:02 +05:30
|
|
|
/* !USE_PAM, no need for xgetspnam */
|
2007-10-07 17:14:59 +05:30
|
|
|
spwd = getspnam (username);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (spwd)
|
|
|
|
pwent.pw_passwd = spwd->sp_pwdp;
|
|
|
|
else
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN,
|
|
|
|
"no shadow password for `%s'%s",
|
|
|
|
username, fromhost));
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the encrypted password begins with a "!", the account
|
|
|
|
* is locked and the user cannot login, even if they have
|
|
|
|
* been "pre-authenticated."
|
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
if (pwent.pw_passwd[0] == '!' || pwent.pw_passwd[0] == '*')
|
2007-10-07 17:14:02 +05:30
|
|
|
failed = 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The -r and -f flags provide a name which has already
|
|
|
|
* been authenticated by some server.
|
|
|
|
*/
|
|
|
|
if (preauth_flag)
|
|
|
|
goto auth_ok;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (pw_auth
|
2007-10-07 17:16:07 +05:30
|
|
|
(pwent.pw_passwd, username, reason, (char *) 0) == 0)
|
2007-10-07 17:14:02 +05:30
|
|
|
goto auth_ok;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Don't log unknown usernames - I mistyped the password for
|
2007-10-07 17:14:59 +05:30
|
|
|
* username at least once. Should probably use LOG_AUTHPRIV
|
2007-10-07 17:14:02 +05:30
|
|
|
* for those who really want to log them. --marekm
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN, "invalid password for `%s' %s",
|
|
|
|
(pwd
|
|
|
|
|| getdef_bool ("LOG_UNKFAIL_ENAB")) ?
|
|
|
|
username : "UNKNOWN", fromhost));
|
2007-10-07 17:14:02 +05:30
|
|
|
failed = 1;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
auth_ok:
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* This is the point where all authenticated users wind up.
|
|
|
|
* If you reach this far, your password has been
|
|
|
|
* authenticated and so on.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!failed && pwent.pw_name && pwent.pw_uid == 0
|
|
|
|
&& !is_console) {
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_CRIT, "ILLEGAL ROOT LOGIN %s", fromhost));
|
2007-10-07 17:14:02 +05:30
|
|
|
failed = 1;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!failed
|
2007-10-07 17:16:07 +05:30
|
|
|
&& !login_access (username, *hostname ? hostname : tty)) {
|
|
|
|
SYSLOG ((LOG_WARN, "LOGIN `%s' REFUSED %s",
|
|
|
|
username, fromhost));
|
2007-10-07 17:14:02 +05:30
|
|
|
failed = 1;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (pwd && getdef_bool ("FAILLOG_ENAB") &&
|
|
|
|
!failcheck (pwent.pw_uid, &faillog, failed)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_CRIT,
|
2007-10-07 17:14:59 +05:30
|
|
|
"exceeded failure limit for `%s' %s",
|
|
|
|
username, fromhost));
|
2007-10-07 17:14:02 +05:30
|
|
|
failed = 1;
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!failed)
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
|
|
|
|
|
|
|
/* don't log non-existent users */
|
2007-10-07 17:14:59 +05:30
|
|
|
if (pwd && getdef_bool ("FAILLOG_ENAB"))
|
2007-10-07 17:14:02 +05:30
|
|
|
failure (pwent.pw_uid, tty, &faillog);
|
2007-10-07 17:14:59 +05:30
|
|
|
if (getdef_str ("FTMP_FILE") != NULL) {
|
2007-10-07 17:14:02 +05:30
|
|
|
const char *failent_user;
|
|
|
|
|
|
|
|
#if HAVE_UTMPX_H
|
|
|
|
failent = utxent;
|
2007-10-07 17:15:23 +05:30
|
|
|
if (sizeof (failent.ut_tv) == sizeof (struct timeval))
|
2007-10-07 17:16:07 +05:30
|
|
|
gettimeofday ((struct timeval *)
|
|
|
|
&failent.ut_tv, NULL);
|
|
|
|
else {
|
2007-10-07 17:15:23 +05:30
|
|
|
struct timeval tv;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:15:23 +05:30
|
|
|
gettimeofday (&tv, NULL);
|
|
|
|
failent.ut_tv.tv_sec = tv.tv_sec;
|
|
|
|
failent.ut_tv.tv_usec = tv.tv_usec;
|
2007-10-07 17:16:07 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
|
|
|
failent = utent;
|
2007-10-07 17:15:23 +05:30
|
|
|
failent.ut_time = time (NULL);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
if (pwd) {
|
|
|
|
failent_user = pwent.pw_name;
|
|
|
|
} else {
|
2007-10-07 17:16:07 +05:30
|
|
|
if (getdef_bool ("LOG_UNKFAIL_ENAB"))
|
2007-10-07 17:14:02 +05:30
|
|
|
failent_user = username;
|
|
|
|
else
|
|
|
|
failent_user = "UNKNOWN";
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
strncpy (failent.ut_user, failent_user,
|
|
|
|
sizeof (failent.ut_user));
|
2007-10-07 17:14:02 +05:30
|
|
|
failent.ut_type = USER_PROCESS;
|
2007-10-07 17:14:59 +05:30
|
|
|
failtmp (&failent);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
memzero (username, sizeof username);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (--retries <= 0)
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_CRIT, "REPEATED login failures%s",
|
|
|
|
fromhost));
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* If this was a passwordless account and we get here, login
|
|
|
|
* was denied (securetty, faillog, etc.). There was no
|
|
|
|
* password prompt, so do it now (will always fail - the bad
|
|
|
|
* guys won't see that the passwordless account exists at
|
|
|
|
* all). --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
if (pwent.pw_passwd[0] == '\0')
|
2007-10-07 17:16:07 +05:30
|
|
|
pw_auth ("!", username, reason, (char *) 0);
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* Wait a while (a la SVR4 /usr/bin/login) before attempting
|
2007-10-07 17:14:59 +05:30
|
|
|
* to login the user again. If the earlier alarm occurs
|
2007-10-07 17:14:02 +05:30
|
|
|
* before the sleep() below completes, login will exit.
|
|
|
|
*/
|
|
|
|
if (delay > 0)
|
2007-10-07 17:14:59 +05:30
|
|
|
sleep (delay);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
puts (_("Login incorrect"));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* allow only one attempt with -r or -f */
|
|
|
|
if (rflg || fflg || retries <= 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
} /* while (1) */
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* ! USE_PAM */
|
2007-10-07 17:16:07 +05:30
|
|
|
alarm (0); /* turn off alarm clock */
|
2007-10-07 17:14:59 +05:30
|
|
|
#ifndef USE_PAM /* PAM does this */
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
|
|
|
* porttime checks moved here, after the user has been
|
2007-10-07 17:14:59 +05:30
|
|
|
* authenticated. now prints a message, as suggested
|
2007-10-07 17:14:02 +05:30
|
|
|
* by Ivan Nejgebauer <ian@unsux.ns.ac.yu>. --marekm
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
if (getdef_bool ("PORTTIME_CHECKS_ENAB") &&
|
|
|
|
!isttytime (pwent.pw_name, tty, time ((time_t *) 0))) {
|
|
|
|
SYSLOG ((LOG_WARN, "invalid login time for `%s'%s",
|
|
|
|
username, fromhost));
|
|
|
|
closelog ();
|
|
|
|
bad_time_notify ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
check_nologin ();
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (getenv ("IFS")) /* don't export user IFS ... */
|
|
|
|
addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifdef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
setutmp (pam_user, tty, hostname); /* make entry in utmp & wtmp files */
|
2007-10-07 17:14:14 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
setutmp (username, tty, hostname); /* make entry in utmp & wtmp files */
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
if (pwent.pw_shell[0] == '*') { /* subsystem root */
|
2007-10-07 17:14:51 +05:30
|
|
|
pwent.pw_shell++; /* skip the '*' */
|
2007-10-07 17:14:02 +05:30
|
|
|
subsystem (&pwent); /* figure out what to execute */
|
2007-10-07 17:14:59 +05:30
|
|
|
subroot++; /* say i was here again */
|
|
|
|
endpwent (); /* close all of the file which were */
|
|
|
|
endgrent (); /* open in the original rooted file */
|
|
|
|
endspent (); /* system. they will be re-opened */
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:14:59 +05:30
|
|
|
endsgent (); /* in the new rooted file system */
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
goto top; /* go do all this all over again */
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:17:11 +05:30
|
|
|
|
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
audit_fd = audit_open ();
|
|
|
|
snprintf (buf, sizeof (buf), "uid=%d", pwd->pw_uid);
|
|
|
|
audit_log_user_message (audit_fd, AUDIT_USER_LOGIN,
|
|
|
|
buf, hostname, NULL, tty, 1);
|
|
|
|
close (audit_fd);
|
|
|
|
}
|
|
|
|
#endif /* WITH_AUDIT */
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#ifndef USE_PAM /* pam_lastlog handles this */
|
|
|
|
if (getdef_bool ("LASTLOG_ENAB")) /* give last login and log this one */
|
2007-10-07 17:16:07 +05:30
|
|
|
dolastlog (&lastlog, &pwent, utent.ut_line, hostname);
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#ifndef USE_PAM /* PAM handles this as well */
|
2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2007-10-07 17:14:59 +05:30
|
|
|
* Have to do this while we still have root privileges, otherwise we
|
|
|
|
* don't have access to /etc/shadow. expire() closes password files,
|
|
|
|
* and changes to the user in the child before executing the passwd
|
|
|
|
* program. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2007-10-07 17:16:07 +05:30
|
|
|
if (spwd) { /* check for age of password */
|
2007-10-07 17:14:02 +05:30
|
|
|
if (expire (&pwent, spwd)) {
|
2007-11-19 04:50:02 +05:30
|
|
|
/* !USE_PAM, no need for xgetpwnam */
|
2007-10-07 17:14:59 +05:30
|
|
|
pwd = getpwnam (username);
|
2007-11-19 04:50:02 +05:30
|
|
|
/* !USE_PAM, no need for xgetspnam */
|
2007-10-07 17:14:59 +05:30
|
|
|
spwd = getspnam (username);
|
2007-10-07 17:14:02 +05:30
|
|
|
if (pwd)
|
|
|
|
pwent = *pwd;
|
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
setup_limits (&pwent); /* nice, ulimit etc. */
|
|
|
|
#endif /* ! USE_PAM */
|
|
|
|
chown_tty (tty, &pwent);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:25 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
/*
|
|
|
|
* We must fork before setuid() because we need to call
|
|
|
|
* pam_close_session() as root.
|
|
|
|
*/
|
2007-10-07 17:16:52 +05:30
|
|
|
signal (SIGINT, SIG_IGN);
|
|
|
|
child = fork ();
|
|
|
|
if (child < 0) {
|
|
|
|
/* error in fork() */
|
2007-10-07 17:17:01 +05:30
|
|
|
fprintf (stderr, _("%s: failure forking: %s"),
|
|
|
|
Prog, strerror (errno));
|
2007-10-07 17:16:52 +05:30
|
|
|
PAM_END;
|
|
|
|
exit (0);
|
|
|
|
} else if (child) {
|
|
|
|
/*
|
|
|
|
* parent - wait for child to finish, then cleanup
|
|
|
|
* session
|
|
|
|
*/
|
|
|
|
wait (NULL);
|
|
|
|
PAM_END;
|
|
|
|
exit (0);
|
2007-10-07 17:16:25 +05:30
|
|
|
}
|
2007-10-07 17:16:52 +05:30
|
|
|
/* child */
|
2007-10-07 17:16:25 +05:30
|
|
|
#endif
|
2007-12-27 04:06:54 +05:30
|
|
|
/* If we were init, we need to start a new session */
|
|
|
|
if (getppid() == 1) {
|
|
|
|
setsid();
|
|
|
|
if (ioctl(0, TIOCSCTTY, 1))
|
|
|
|
fprintf(stderr,_("TIOCSCTTY failed on %s"),tty);
|
|
|
|
}
|
2007-10-07 17:16:52 +05:30
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
/* We call set_groups() above because this clobbers pam_groups.so */
|
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
if (setup_uid_gid (&pwent, is_console))
|
2007-10-07 17:14:14 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
if (change_uid (&pwent))
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
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
|
|
|
setup_env (&pwent); /* set env vars, cd to the home dir */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifdef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
const char *const *env;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
env = (const char *const *) pam_getenvlist (pamh);
|
2007-10-07 17:14:02 +05:30
|
|
|
while (env && *env) {
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv (*env, NULL);
|
2007-10-07 17:14:02 +05:30
|
|
|
env++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
if (!hushed (&pwent)) {
|
|
|
|
addenv ("HUSHLOGIN=FALSE", NULL);
|
|
|
|
/*
|
|
|
|
* pam_unix, pam_mail and pam_lastlog should take care of
|
|
|
|
* this
|
|
|
|
*/
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:59 +05:30
|
|
|
motd (); /* print the message of the day */
|
|
|
|
if (getdef_bool ("FAILLOG_ENAB")
|
|
|
|
&& faillog.fail_cnt != 0) {
|
|
|
|
failprint (&faillog);
|
2007-10-07 17:14:02 +05:30
|
|
|
/* Reset the lockout times if logged in */
|
|
|
|
if (faillog.fail_max &&
|
|
|
|
faillog.fail_cnt >= faillog.fail_max) {
|
2007-10-07 17:14:59 +05:30
|
|
|
puts (_
|
|
|
|
("Warning: login re-enabled after temporary lockout.\n"));
|
|
|
|
SYSLOG ((LOG_WARN,
|
|
|
|
"login `%s' re-enabled after temporary lockout (%d failures)",
|
2007-10-07 17:16:07 +05:30
|
|
|
username, (int) faillog.fail_cnt));
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (getdef_bool ("LASTLOG_ENAB")
|
|
|
|
&& lastlog.ll_time != 0) {
|
2007-10-07 17:15:23 +05:30
|
|
|
time_t ll_time = lastlog.ll_time;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_STRFTIME
|
2007-10-07 17:14:59 +05:30
|
|
|
strftime (ptime, sizeof (ptime),
|
|
|
|
"%a %b %e %H:%M:%S %z %Y",
|
2007-10-07 17:15:23 +05:30
|
|
|
localtime (&ll_time));
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Last login: %s on %s"),
|
2007-10-07 17:14:02 +05:30
|
|
|
ptime, lastlog.ll_line);
|
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Last login: %.19s on %s"),
|
2007-10-07 17:16:07 +05:30
|
|
|
ctime (&ll_time), lastlog.ll_line);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:15:23 +05:30
|
|
|
#ifdef HAVE_LL_HOST /* __linux__ || SUN4 */
|
2007-10-07 17:14:02 +05:30
|
|
|
if (lastlog.ll_host[0])
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_(" from %.*s"),
|
|
|
|
(int) sizeof lastlog.
|
|
|
|
ll_host, lastlog.ll_host);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (".\n");
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
agecheck (&pwent, spwd);
|
|
|
|
|
|
|
|
mailcheck (); /* report on the status of mail */
|
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
} else
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv ("HUSHLOGIN=TRUE", NULL);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
if (getdef_str ("TTYTYPE_FILE") != NULL && getenv ("TERM") == NULL)
|
2007-10-07 17:14:59 +05:30
|
|
|
ttytype (tty);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
signal (SIGQUIT, SIG_DFL); /* default quit signal */
|
|
|
|
signal (SIGTERM, SIG_DFL); /* default terminate signal */
|
|
|
|
signal (SIGALRM, SIG_DFL); /* default alarm signal */
|
|
|
|
signal (SIGHUP, SIG_DFL); /* added this. --marekm */
|
|
|
|
signal (SIGINT, SIG_DFL); /* default interrupt signal */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
endpwent (); /* stop access to password file */
|
|
|
|
endgrent (); /* stop access to group file */
|
|
|
|
endspent (); /* stop access to shadow passwd file */
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef SHADOWGRP
|
2007-10-07 17:16:07 +05:30
|
|
|
endsgent (); /* stop access to shadow group file */
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
|
|
|
if (pwent.pw_uid == 0)
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_NOTICE, "ROOT LOGIN %s", fromhost));
|
|
|
|
else if (getdef_bool ("LOG_OK_LOGINS"))
|
2007-10-07 17:16:25 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
SYSLOG ((LOG_INFO, "`%s' logged in %s", pam_user, fromhost));
|
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_INFO, "`%s' logged in %s", username, fromhost));
|
2007-10-07 17:16:25 +05:30
|
|
|
#endif
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
2007-10-07 17:17:22 +05:30
|
|
|
if ((tmp = getdef_str ("FAKE_SHELL")) != NULL)
|
|
|
|
err = shell (tmp, pwent.pw_shell, newenvp); /* fake shell */
|
|
|
|
else
|
|
|
|
/* exec the shell finally */
|
|
|
|
err = shell (pwent.pw_shell, (char *) 0, newenvp);
|
|
|
|
exit (err == ENOENT ? E_CMD_NOTFOUND : E_CMD_NOEXEC);
|
2007-10-07 17:15:23 +05:30
|
|
|
/* NOT REACHED */
|
|
|
|
return 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|