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 - 2001, Marek Michałkiewicz
|
|
|
|
* Copyright (c) 2001 - 2006, Tomasz Kłoczko
|
2009-04-20 17:57:27 +05:30
|
|
|
* Copyright (c) 2007 - 2009, 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
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <errno.h>
|
|
|
|
#include <grp.h>
|
2009-04-23 01:33:26 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <lastlog.h>
|
2009-04-23 01:33:26 +05:30
|
|
|
#endif /* !USE_PAM */
|
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>
|
2009-04-20 18:17:04 +05:30
|
|
|
#include <assert.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))); \
|
2008-06-11 00:26:23 +05:30
|
|
|
(void) pam_end(pamh, retcode); \
|
|
|
|
exit(1); \
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
#define PAM_END { retcode = pam_close_session(pamh,0); \
|
2008-06-11 00:26:23 +05:30
|
|
|
(void) pam_end(pamh,retcode); }
|
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
|
|
|
|
2009-04-23 01:33:26 +05:30
|
|
|
#ifndef 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
|
2009-04-23 01:33:26 +05:30
|
|
|
#endif /* !USE_PAM */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:17:01 +05:30
|
|
|
/*
|
|
|
|
* Global variables
|
|
|
|
*/
|
2008-09-20 21:51:46 +05:30
|
|
|
char *Prog;
|
|
|
|
|
|
|
|
static const char *hostname = "";
|
2009-04-23 02:23:15 +05:30
|
|
|
static /*@null@*/ /*@only@*/char *username = NULL;
|
2008-09-20 21:51:46 +05:30
|
|
|
static int reason = PW_LOGIN;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 01:33:26 +05:30
|
|
|
#ifndef USE_PAM
|
|
|
|
static struct lastlog ll;
|
|
|
|
#endif /* !USE_PAM */
|
2008-06-11 00:26:23 +05:30
|
|
|
static bool pflg = false;
|
|
|
|
static bool fflg = false;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
2008-06-11 00:26:23 +05:30
|
|
|
static bool rflg = false;
|
2008-09-21 01:33:04 +05:30
|
|
|
#else /* RLOGIN */
|
2008-06-11 00:26:23 +05:30
|
|
|
#define rflg false
|
2008-09-21 01:33:04 +05:30
|
|
|
#endif /* !RLOGIN */
|
2008-06-11 00:26:23 +05:30
|
|
|
static bool hflg = false;
|
|
|
|
static bool preauth_flag = false;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
static bool amroot;
|
2009-04-23 01:45:21 +05:30
|
|
|
static unsigned int timeout;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* 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);
|
2009-04-23 02:23:15 +05:30
|
|
|
static void process_flags (int argc, char *const *argv);
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *user);
|
2009-04-23 01:28:39 +05:30
|
|
|
static void update_utmp (const char *username,
|
|
|
|
const char *tty,
|
|
|
|
const char *hostname,
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
/*@null@*/const struct utmp *utent);
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifndef USE_PAM
|
2007-10-07 17:16:07 +05:30
|
|
|
static struct faillog faillog;
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
static void bad_time_notify (void);
|
2009-04-20 18:03:01 +05:30
|
|
|
static void check_nologin (bool login_to_root);
|
2009-04-20 18:17:04 +05:30
|
|
|
#else
|
|
|
|
static void get_pam_user (char **ptr_pam_user);
|
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);
|
2008-06-11 00:26:23 +05:30
|
|
|
if (!amroot) {
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
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);
|
2008-09-21 01:33:04 +05:30
|
|
|
#endif /* RLOGIN */
|
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;
|
2009-04-23 01:42:06 +05:30
|
|
|
int erasechar;
|
|
|
|
int killchar;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 01:42:06 +05:30
|
|
|
if (GTTY (0, &termio) == 0) { /* get terminal characteristics */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 02:18:42 +05:30
|
|
|
/*
|
|
|
|
* Add your favorite terminal modes here ...
|
|
|
|
*/
|
|
|
|
termio.c_lflag |= ISIG | ICANON | ECHO | ECHOE;
|
|
|
|
termio.c_iflag |= ICRNL;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-12 05:47:36 +05:30
|
|
|
#if defined(ECHOKE) && defined(ECHOCTL)
|
2009-04-23 02:18:42 +05:30
|
|
|
termio.c_lflag |= ECHOKE | ECHOCTL;
|
2009-04-12 05:47:36 +05:30
|
|
|
#endif
|
|
|
|
#if defined(ECHOPRT) && defined(NOFLSH) && defined(TOSTOP)
|
2009-04-23 02:18:42 +05:30
|
|
|
termio.c_lflag &= ~(ECHOPRT | NOFLSH | TOSTOP);
|
2009-04-12 05:47:36 +05:30
|
|
|
#endif
|
|
|
|
#ifdef ONLCR
|
2009-04-23 02:18:42 +05:30
|
|
|
termio.c_oflag |= ONLCR;
|
2009-04-12 05:47:36 +05:30
|
|
|
#endif
|
|
|
|
|
2009-04-23 02:18:42 +05:30
|
|
|
/* leave these values unchanged if not specified in login.defs */
|
|
|
|
erasechar = getdef_num ("ERASECHAR", (int) termio.c_cc[VERASE]);
|
|
|
|
killchar = getdef_num ("KILLCHAR", (int) termio.c_cc[VKILL]);
|
|
|
|
termio.c_cc[VERASE] = (cc_t) erasechar;
|
|
|
|
termio.c_cc[VKILL] = (cc_t) killchar;
|
|
|
|
/* Make sure the values were valid.
|
|
|
|
* getdef_num cannot validate this.
|
|
|
|
*/
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
if (erasechar != (int) termio.c_cc[VERASE]) {
|
2009-04-23 02:18:42 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("configuration error - cannot parse %s value: '%d'"),
|
|
|
|
"ERASECHAR", erasechar);
|
|
|
|
exit (1);
|
|
|
|
}
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
if (killchar != (int) termio.c_cc[VKILL]) {
|
2009-04-23 02:18:42 +05:30
|
|
|
fprintf (stderr,
|
|
|
|
_("configuration error - cannot parse %s value: '%d'"),
|
|
|
|
"KILLCHAR", killchar);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ttymon invocation prefers this, but these settings
|
|
|
|
* won't come into effect after the first username login
|
|
|
|
*/
|
|
|
|
(void) STTY (0, &termio);
|
2009-04-23 01:42:06 +05:30
|
|
|
}
|
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-06-11 00:26:23 +05:30
|
|
|
(void) puts (_("Invalid login time"));
|
|
|
|
(void) fflush (stdout);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2009-04-20 18:03:01 +05:30
|
|
|
static void check_nologin (bool login_to_root)
|
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");
|
2008-06-11 00:26:23 +05:30
|
|
|
if ((NULL != fname) && (access (fname, F_OK) == 0)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
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
|
|
|
|
*/
|
2008-06-11 00:26:23 +05:30
|
|
|
nlfp = fopen (fname, "r");
|
|
|
|
if (NULL != nlfp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
while ((c = getc (nlfp)) != EOF) {
|
2008-06-11 00:26:23 +05:30
|
|
|
if (c == '\n') {
|
|
|
|
(void) putchar ('\r');
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
(void) putchar (c);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-11 00:26:23 +05:30
|
|
|
(void) fflush (stdout);
|
|
|
|
(void) fclose (nlfp);
|
|
|
|
} else {
|
|
|
|
(void) puts (_("\nSystem closed for routine maintenance"));
|
|
|
|
}
|
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.
|
|
|
|
*/
|
|
|
|
|
2009-04-20 18:03:01 +05:30
|
|
|
if (!login_to_root) {
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2009-04-23 01:47:11 +05:30
|
|
|
(void) puts (_("\n[Disconnect bypassed -- root login allowed.]"));
|
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
|
|
|
|
2008-09-20 21:51:46 +05:30
|
|
|
static void process_flags (int argc, char *const *argv)
|
2007-10-07 17:16:07 +05:30
|
|
|
{
|
|
|
|
int arg;
|
2008-09-20 21:51:46 +05:30
|
|
|
int flag;
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
/*
|
|
|
|
* 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++) {
|
2008-06-11 00:26:23 +05:30
|
|
|
if (argv[arg][0] == '-' && strlen (argv[arg]) > 2) {
|
2007-10-07 17:16:07 +05:30
|
|
|
usage ();
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2008-05-18 20:24:35 +05:30
|
|
|
if (strcmp(argv[arg], "--") == 0) {
|
|
|
|
break; /* stop checking on a "--" */
|
|
|
|
}
|
2007-10-07 17:16:07 +05:30
|
|
|
}
|
2008-09-20 21:51:46 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Process options.
|
|
|
|
*/
|
2008-09-21 01:50:19 +05:30
|
|
|
while ((flag = getopt (argc, argv, "d:fh:pr:")) != EOF) {
|
2008-09-20 21:51:46 +05:30
|
|
|
switch (flag) {
|
|
|
|
case 'd':
|
|
|
|
/* "-d device" ignored for compatibility */
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
fflg = true;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
hflg = true;
|
|
|
|
hostname = optarg;
|
|
|
|
reason = PW_TELNET;
|
|
|
|
break;
|
|
|
|
#ifdef RLOGIN
|
|
|
|
case 'r':
|
|
|
|
rflg = true;
|
|
|
|
hostname = optarg;
|
|
|
|
reason = PW_RLOGIN;
|
|
|
|
break;
|
2008-09-21 01:33:04 +05:30
|
|
|
#endif /* RLOGIN */
|
2008-09-20 21:51:46 +05:30
|
|
|
case 'p':
|
|
|
|
pflg = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef RLOGIN
|
|
|
|
/*
|
|
|
|
* Neither -h nor -f should be combined with -r.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (rflg && (hflg || fflg)) {
|
|
|
|
usage ();
|
|
|
|
}
|
2008-09-21 01:33:04 +05:30
|
|
|
#endif /* RLOGIN */
|
2008-09-20 21:51:46 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow authentication bypass only if real UID is zero.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((rflg || fflg || hflg) && !amroot) {
|
|
|
|
fprintf (stderr, _("%s: Permission denied.\n"), Prog);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the user name.
|
|
|
|
*/
|
|
|
|
if (optind < argc) {
|
2009-04-23 02:21:13 +05:30
|
|
|
assert (NULL == username);
|
2008-09-21 01:14:12 +05:30
|
|
|
username = xstrdup (argv[optind]);
|
2008-09-20 21:51:46 +05:30
|
|
|
strzero (argv[optind]);
|
|
|
|
++optind;
|
|
|
|
}
|
|
|
|
|
2008-09-21 01:30:51 +05:30
|
|
|
#ifdef RLOGIN
|
|
|
|
if (rflg && (NULL != username)) {
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
#endif /* RLOGIN */
|
|
|
|
if (fflg && (NULL == username)) {
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
tmp = getenv ("LANG");
|
|
|
|
if (NULL != tmp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv ("LANG", tmp);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the timezone environmental variable so that time functions
|
|
|
|
* work correctly.
|
|
|
|
*/
|
2008-06-11 00:26:23 +05:30
|
|
|
tmp = getenv ("TZ");
|
|
|
|
if (NULL != tmp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv ("TZ", tmp);
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifndef USE_PAM
|
2008-06-11 00:26:23 +05:30
|
|
|
else {
|
|
|
|
cp = getdef_str ("ENV_TZ");
|
|
|
|
if (NULL != cp) {
|
|
|
|
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.
|
|
|
|
*/
|
2008-06-11 00:26:23 +05:30
|
|
|
tmp = getenv ("HZ");
|
|
|
|
if (NULL != tmp) {
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv ("HZ", tmp);
|
2007-10-07 17:17:01 +05:30
|
|
|
}
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifndef USE_PAM
|
2008-06-11 00:26:23 +05:30
|
|
|
else {
|
|
|
|
cp = getdef_str ("ENV_HZ");
|
|
|
|
if (NULL != cp) {
|
|
|
|
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
|
|
|
{
|
2009-04-23 01:45:21 +05:30
|
|
|
fprintf (stderr, _("\nLogin timed out after %u seconds.\n"), timeout);
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (0);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2009-04-20 18:17:04 +05:30
|
|
|
#ifdef USE_PAM
|
|
|
|
/*
|
|
|
|
* get_pam_user - Get the username according to PAM
|
|
|
|
*
|
|
|
|
* ptr_pam_user shall point to a malloc'ed string (or NULL).
|
|
|
|
*/
|
|
|
|
static void get_pam_user (char **ptr_pam_user)
|
|
|
|
{
|
|
|
|
int retcode;
|
|
|
|
void *ptr_user;
|
|
|
|
|
|
|
|
assert (NULL != ptr_pam_user);
|
|
|
|
|
|
|
|
retcode = pam_get_item (pamh, PAM_USER, (const void **)&ptr_user);
|
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
|
|
|
|
if (NULL != *ptr_pam_user) {
|
|
|
|
free (*ptr_pam_user);
|
|
|
|
}
|
|
|
|
if (NULL != ptr_user) {
|
|
|
|
*ptr_pam_user = xstrdup ((const char *)ptr_user);
|
|
|
|
} else {
|
|
|
|
*ptr_pam_user = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_failent_user - Return a string that can be used to log failure
|
|
|
|
* from an user.
|
|
|
|
*
|
|
|
|
* This will be either the user argument, or "UNKNOWN".
|
|
|
|
*
|
|
|
|
* It is quite common to mistyped the password for username, and passwords
|
|
|
|
* should not be logged.
|
|
|
|
*/
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *user)
|
2009-04-20 18:17:04 +05:30
|
|
|
{
|
|
|
|
const char *failent_user = "UNKNOWN";
|
|
|
|
bool log_unkfail_enab = getdef_bool("LOG_UNKFAIL_ENAB");
|
|
|
|
|
|
|
|
if ((NULL != user) && ('\0' != user[0])) {
|
|
|
|
if ( log_unkfail_enab
|
|
|
|
|| (getpwnam (user) != NULL)) {
|
|
|
|
failent_user = user;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return failent_user;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 01:28:39 +05:30
|
|
|
/*
|
|
|
|
* update_utmp - Update or create an utmp entry in utmp, wtmp, utmpw, and
|
|
|
|
* wtmpx
|
|
|
|
*
|
|
|
|
* utent should be the utmp entry returned by get_current_utmp (or
|
|
|
|
* NULL).
|
|
|
|
*/
|
|
|
|
static void update_utmp (const char *username,
|
|
|
|
const char *tty,
|
|
|
|
const char *hostname,
|
|
|
|
/*@null@*/const struct utmp *utent)
|
|
|
|
{
|
|
|
|
struct utmp *ut = prepare_utmp (username, tty, hostname, utent);
|
|
|
|
#ifdef HAVE_UTMPX_H
|
|
|
|
struct utmpx *utx = prepare_utmpx (username, tty, hostname, utent);
|
|
|
|
#endif /* HAVE_UTMPX_H */
|
|
|
|
|
|
|
|
(void) setutmp (ut); /* make entry in the utmp & wtmp files */
|
|
|
|
free (ut);
|
|
|
|
|
|
|
|
#ifdef HAVE_UTMPX_H
|
|
|
|
(void) setutmpx (utx); /* make entry in the utmpx & wtmpx files */
|
|
|
|
free (utx);
|
|
|
|
#endif /* HAVE_UTMPX_H */
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-04-18 02:10:26 +05:30
|
|
|
const char *tmptty;
|
2007-10-07 17:14:59 +05:30
|
|
|
char tty[BUFSIZ];
|
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
2007-10-07 17:14:59 +05:30
|
|
|
char term[128] = "";
|
2008-09-21 01:33:04 +05:30
|
|
|
#endif /* RLOGIN */
|
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
|
2009-04-23 01:45:21 +05:30
|
|
|
unsigned int delay;
|
|
|
|
unsigned int retries;
|
2008-06-11 00:26:23 +05:30
|
|
|
bool failed;
|
|
|
|
bool subroot = false;
|
2007-12-09 04:57:35 +05:30
|
|
|
#ifndef USE_PAM
|
2008-06-11 00:26:23 +05:30
|
|
|
bool 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];
|
2009-04-20 18:59:15 +05:30
|
|
|
struct passwd *pwd = NULL;
|
2007-10-07 17:14:59 +05:30
|
|
|
char **envp = environ;
|
2009-04-20 18:17:04 +05:30
|
|
|
const char *failent_user;
|
2009-04-23 02:23:15 +05:30
|
|
|
/*@null@*/struct utmp *utent;
|
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;
|
2009-04-20 18:17:04 +05:30
|
|
|
char *pam_user = NULL;
|
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
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) 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
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
amroot = (getuid () == 0);
|
|
|
|
Prog = Basename (argv[0]);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-22 04:16:01 +05:30
|
|
|
if (geteuid() != 0) {
|
|
|
|
fprintf (stderr, _("%s: Cannot possibly work without effective root\n"), Prog);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2008-09-20 21:51:46 +05:30
|
|
|
process_flags (argc, argv);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
if ((isatty (0) == 0) || (isatty (1) == 0) || (isatty (2) == 0)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1); /* must be a terminal */
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-22 04:09:14 +05:30
|
|
|
utent = get_current_utmp ();
|
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
|
|
|
|
*/
|
2009-04-22 04:09:14 +05:30
|
|
|
if (!amroot && (NULL == utent)) {
|
|
|
|
(void) puts (_("No utmp entry. You must exec \"login\" from the lowest level \"sh\""));
|
|
|
|
exit (1);
|
|
|
|
}
|
2009-04-23 01:37:34 +05:30
|
|
|
/* NOTE: utent might be NULL afterwards */
|
2009-04-18 02:10:26 +05:30
|
|
|
|
|
|
|
tmptty = ttyname (0);
|
|
|
|
if (NULL == tmptty) {
|
|
|
|
tmptty = "UNKNOWN";
|
|
|
|
}
|
|
|
|
STRFCPY (tty, tmptty);
|
|
|
|
|
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) {
|
|
|
|
/*
|
2008-09-20 20:09:09 +05:30
|
|
|
* Add remote hostname to the environment. I think
|
|
|
|
* (not sure) I saw it once on Irix. --marekm
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2008-09-20 20:09:09 +05:30
|
|
|
addenv ("REMOTEHOST", hostname);
|
|
|
|
}
|
|
|
|
if (fflg) {
|
|
|
|
preauth_flag = true;
|
|
|
|
}
|
|
|
|
if (hflg) {
|
|
|
|
reason = PW_RLOGIN;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef RLOGIN
|
2008-09-21 01:14:12 +05:30
|
|
|
if (rflg) {
|
2009-04-23 02:21:13 +05:30
|
|
|
assert (NULL == username);
|
2009-04-23 02:12:48 +05:30
|
|
|
username = xmalloc (USER_NAME_MAX_LENGTH + 1);
|
|
|
|
username[USER_NAME_MAX_LENGTH] = '\0';
|
|
|
|
if (do_rlogin (hostname, username, USER_NAME_MAX_LENGTH, term, sizeof term)) {
|
2008-09-21 01:14:12 +05:30
|
|
|
preauth_flag = true;
|
|
|
|
} else {
|
|
|
|
free (username);
|
|
|
|
username = NULL;
|
|
|
|
}
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2008-09-21 01:33:04 +05:30
|
|
|
#endif /* RLOGIN */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
OPENLOG ("login");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
setup_tty ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#ifndef USE_PAM
|
2009-04-20 17:47:38 +05:30
|
|
|
(void) umask (getdef_num ("UMASK", GETDEF_DEFAULT_UMASK));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +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
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
if (limit != -1) {
|
|
|
|
set_filesize_limit (limit);
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:16:34 +05:30
|
|
|
#endif
|
2008-09-20 20:09:09 +05:30
|
|
|
/*
|
|
|
|
* The entire environment will be preserved if the -p flag
|
|
|
|
* is used.
|
|
|
|
*/
|
|
|
|
if (pflg) {
|
|
|
|
while (NULL != *envp) { /* add inherited environment, */
|
|
|
|
addenv (*envp, NULL); /* some variables change later */
|
|
|
|
envp++;
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
#ifdef RLOGIN
|
2008-09-20 20:09:09 +05:30
|
|
|
if (term[0] != '\0') {
|
|
|
|
addenv ("TERM", term);
|
|
|
|
} else
|
2008-09-21 01:33:04 +05:30
|
|
|
#endif /* RLOGIN */
|
2008-09-20 20:09:09 +05:30
|
|
|
{
|
|
|
|
/* preserve TERM from getty */
|
|
|
|
if (!pflg) {
|
|
|
|
tmp = getenv ("TERM");
|
|
|
|
if (NULL != tmp) {
|
|
|
|
addenv ("TERM", tmp);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
|
|
|
}
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
init_env ();
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
if (optind < argc) { /* now set command line variables */
|
|
|
|
set_env (argc - optind, &argv[optind]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rflg || hflg) {
|
|
|
|
cp = hostname;
|
2009-04-22 04:09:14 +05:30
|
|
|
#ifdef HAVE_STRUCT_UTMP_UT_HOST
|
2009-04-23 01:37:34 +05:30
|
|
|
} else if ((NULL != utent) && ('\0' != utent->ut_host[0])) {
|
|
|
|
cp = utent->ut_host;
|
2009-04-22 04:09:14 +05:30
|
|
|
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
|
2009-04-23 01:37:34 +05:30
|
|
|
} else {
|
|
|
|
cp = "";
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
if ('\0' != *cp) {
|
|
|
|
snprintf (fromhost, sizeof fromhost,
|
|
|
|
" on '%.100s' from '%.200s'", tty, cp);
|
|
|
|
} else {
|
|
|
|
snprintf (fromhost, sizeof fromhost,
|
|
|
|
" on '%.100s'", tty);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
top:
|
|
|
|
/* only allow ALARM sec. for login */
|
|
|
|
(void) signal (SIGALRM, alarm_handler);
|
2009-04-23 01:45:21 +05:30
|
|
|
timeout = getdef_unum ("LOGIN_TIMEOUT", ALARM);
|
2008-09-20 20:09:09 +05:30
|
|
|
if (timeout > 0) {
|
2009-04-23 01:45:21 +05:30
|
|
|
(void) alarm (timeout);
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
environ = newenvp; /* make new environment active */
|
2009-04-23 01:45:21 +05:30
|
|
|
delay = getdef_unum ("FAIL_DELAY", 1);
|
|
|
|
retries = getdef_unum ("LOGIN_RETRIES", RETRIES);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifdef USE_PAM
|
2008-09-20 20:09:09 +05:30
|
|
|
retcode = pam_start ("login", username, &conv, &pamh);
|
|
|
|
if (retcode != PAM_SUCCESS) {
|
|
|
|
fprintf (stderr,
|
|
|
|
_("login: PAM Failure, aborting: %s\n"),
|
|
|
|
pam_strerror (pamh, retcode));
|
|
|
|
SYSLOG ((LOG_ERR, "Couldn't initialize PAM: %s",
|
|
|
|
pam_strerror (pamh, retcode)));
|
|
|
|
exit (99);
|
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2008-09-20 20:09:09 +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.
|
2009-04-19 19:03:24 +05:30
|
|
|
*
|
|
|
|
* PAM_RHOST and PAM_TTY are used for authentication, only use
|
|
|
|
* information coming from login or from the caller (e.g. no utmp)
|
2008-09-20 20:09:09 +05:30
|
|
|
*/
|
|
|
|
retcode = pam_set_item (pamh, PAM_RHOST, hostname);
|
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
retcode = pam_set_item (pamh, PAM_TTY, tty);
|
|
|
|
PAM_FAIL_CHECK;
|
2008-08-31 22:57:16 +05:30
|
|
|
#ifdef HAS_PAM_FAIL_DELAY
|
2008-09-20 20:09:09 +05:30
|
|
|
retcode = pam_fail_delay (pamh, 1000000 * delay);
|
|
|
|
PAM_FAIL_CHECK;
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2008-09-20 20:09:09 +05:30
|
|
|
/* if fflg, then the user has already been authenticated */
|
2009-04-19 21:39:00 +05:30
|
|
|
if (!fflg) {
|
2008-09-20 20:09:09 +05:30
|
|
|
int failcount = 0;
|
|
|
|
char hostn[256];
|
|
|
|
char loginprompt[256]; /* That's one hell of a prompt :) */
|
|
|
|
|
|
|
|
/* Make the login prompt look like we want it */
|
|
|
|
if (gethostname (hostn, sizeof (hostn)) == 0) {
|
|
|
|
snprintf (loginprompt,
|
|
|
|
sizeof (loginprompt),
|
|
|
|
_("%s login: "), hostn);
|
|
|
|
} else {
|
|
|
|
snprintf (loginprompt,
|
|
|
|
sizeof (loginprompt), _("login: "));
|
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
retcode = pam_set_item (pamh, PAM_USER_PROMPT, loginprompt);
|
|
|
|
PAM_FAIL_CHECK;
|
2007-10-07 17:14:59 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
/* if we didn't get a user on the command line,
|
|
|
|
set it to NULL */
|
2009-04-20 18:17:04 +05:30
|
|
|
get_pam_user (&pam_user);
|
2009-04-15 23:20:17 +05:30
|
|
|
if ((NULL != pam_user) && ('\0' == pam_user[0])) {
|
2008-09-21 02:47:26 +05:30
|
|
|
retcode = pam_set_item (pamh, PAM_USER, NULL);
|
|
|
|
PAM_FAIL_CHECK;
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +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?
|
|
|
|
*/
|
|
|
|
failcount = 0;
|
|
|
|
while (true) {
|
|
|
|
failed = false;
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
failcount++;
|
2008-08-31 22:57:16 +05:30
|
|
|
#ifdef HAS_PAM_FAIL_DELAY
|
2008-09-20 20:09:09 +05:30
|
|
|
if (delay > 0) {
|
|
|
|
retcode = pam_fail_delay(pamh, 1000000*delay);
|
2008-09-21 02:47:26 +05:30
|
|
|
PAM_FAIL_CHECK;
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2008-07-22 02:44:06 +05:30
|
|
|
#endif
|
2007-10-07 17:17:22 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
retcode = pam_authenticate (pamh, 0);
|
2007-10-07 17:17:11 +05:30
|
|
|
|
2009-04-20 18:17:04 +05:30
|
|
|
get_pam_user (&pam_user);
|
|
|
|
failent_user = get_failent_user (pam_user);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-12 05:38:26 +05:30
|
|
|
if (retcode == PAM_MAXTRIES) {
|
2008-09-20 20:09:09 +05:30
|
|
|
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 */
|
2009-04-23 01:47:11 +05:30
|
|
|
(void) fputs (_("login: abort requested by PAM\n"), stderr);
|
2008-09-20 20:09:09 +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 = true;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
if (!failed) {
|
|
|
|
break;
|
2007-10-07 17:14:59 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
#ifdef WITH_AUDIT
|
|
|
|
audit_fd = audit_open ();
|
|
|
|
audit_log_acct_message (audit_fd,
|
|
|
|
AUDIT_USER_LOGIN,
|
|
|
|
NULL, /* Prog. name */
|
|
|
|
"login",
|
|
|
|
failent_user,
|
|
|
|
AUDIT_NO_ID,
|
|
|
|
hostname,
|
|
|
|
NULL, /* addr */
|
|
|
|
tty,
|
|
|
|
0); /* result */
|
|
|
|
close (audit_fd);
|
|
|
|
#endif /* WITH_AUDIT */
|
2007-10-07 17:14:14 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
fprintf (stderr, "\nLogin incorrect\n");
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-12 05:38:26 +05:30
|
|
|
if (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);
|
|
|
|
}
|
|
|
|
|
2008-09-21 02:47:26 +05:30
|
|
|
/*
|
|
|
|
* Let's give it another go around.
|
|
|
|
* Even if a username was given on the command
|
|
|
|
* line, prompt again for the username.
|
|
|
|
*/
|
|
|
|
retcode = pam_set_item (pamh, PAM_USER, NULL);
|
|
|
|
PAM_FAIL_CHECK;
|
2007-10-07 17:15:40 +05:30
|
|
|
}
|
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
/* We don't get here unless they were authenticated above */
|
2009-04-23 01:45:21 +05:30
|
|
|
(void) alarm (0);
|
2009-04-19 21:52:17 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-19 21:52:17 +05:30
|
|
|
/* Check the account validity */
|
|
|
|
retcode = pam_acct_mgmt (pamh, 0);
|
|
|
|
if (retcode == PAM_NEW_AUTHTOK_REQD) {
|
|
|
|
retcode = pam_chauthtok (pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2009-04-19 21:52:17 +05:30
|
|
|
PAM_FAIL_CHECK;
|
2008-09-20 20:09:09 +05:30
|
|
|
|
2009-04-20 18:24:17 +05:30
|
|
|
/* Open the PAM session */
|
|
|
|
get_pam_user (&pam_user);
|
|
|
|
retcode = pam_open_session (pamh, hushed (pam_user) ? PAM_SILENT : 0);
|
|
|
|
PAM_FAIL_CHECK;
|
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
/* Grab the user information out of the password file for future usage
|
2009-04-20 18:17:04 +05:30
|
|
|
* First get the username that we are actually using, though.
|
|
|
|
*
|
|
|
|
* From now on, we will discard changes of the user (PAM_USER) by
|
|
|
|
* PAM APIs.
|
2008-09-20 20:09:09 +05:30
|
|
|
*/
|
2009-04-20 18:17:04 +05:30
|
|
|
get_pam_user (&pam_user);
|
2008-09-21 01:24:35 +05:30
|
|
|
if (NULL != username) {
|
|
|
|
free (username);
|
|
|
|
}
|
2009-04-20 18:17:04 +05:30
|
|
|
username = pam_user;
|
|
|
|
failent_user = get_failent_user (username);
|
2008-09-21 01:24:35 +05:30
|
|
|
|
|
|
|
pwd = xgetpwnam (username);
|
2008-09-20 20:09:09 +05:30
|
|
|
if (NULL == pwd) {
|
2009-04-20 18:17:04 +05:30
|
|
|
SYSLOG ((LOG_ERR, "cannot find user %s", failent_user));
|
2008-09-20 20:09:09 +05:30
|
|
|
exit (1);
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-20 17:57:27 +05:30
|
|
|
/* This set up the process credential (group) and initialize the
|
|
|
|
* supplementary group access list.
|
|
|
|
* This has to be done before pam_setcred
|
|
|
|
*/
|
2008-09-20 20:09:09 +05:30
|
|
|
if (setup_groups (pwd) != 0) {
|
|
|
|
exit (1);
|
|
|
|
}
|
2008-09-20 19:47:20 +05:30
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
retcode = pam_setcred (pamh, PAM_ESTABLISH_CRED);
|
|
|
|
PAM_FAIL_CHECK;
|
2009-04-20 18:24:17 +05:30
|
|
|
/* NOTE: If pam_setcred changes PAM_USER, this will not be taken
|
|
|
|
* into account.
|
|
|
|
*/
|
2008-09-20 20:09:09 +05:30
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#else /* ! USE_PAM */
|
2008-09-20 20:09:09 +05:30
|
|
|
while (true) { /* repeatedly get login/password pairs */
|
2009-04-20 18:59:15 +05:30
|
|
|
/* user_passwd is always a pointer to this constant string
|
|
|
|
* or a passwd or shadow password that will be memzero by
|
2009-04-22 04:09:14 +05:30
|
|
|
* pw_free / spw_free.
|
2009-04-20 18:59:15 +05:30
|
|
|
* Do not free() user_passwd. */
|
|
|
|
const char *user_passwd = "!";
|
|
|
|
|
|
|
|
/* Do some cleanup to avoid keeping entries we do not need
|
|
|
|
* anymore. */
|
|
|
|
if (NULL != pwd) {
|
2009-04-22 04:09:14 +05:30
|
|
|
pw_free (pwd);
|
2009-04-20 18:59:15 +05:30
|
|
|
}
|
|
|
|
if (NULL != spwd) {
|
2009-04-22 04:09:14 +05:30
|
|
|
spw_free (spwd);
|
2009-04-20 18:59:15 +05:30
|
|
|
spwd = NULL;
|
|
|
|
}
|
|
|
|
|
2008-09-20 20:09:09 +05:30
|
|
|
failed = false; /* haven't failed authentication yet */
|
2008-09-21 01:14:12 +05:30
|
|
|
if (NULL == username) { /* need to get a login id */
|
2008-09-20 20:09:09 +05:30
|
|
|
if (subroot) {
|
|
|
|
closelog ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-09-20 20:09:09 +05:30
|
|
|
preauth_flag = false;
|
2009-04-23 02:12:48 +05:30
|
|
|
username = xmalloc (USER_NAME_MAX_LENGTH + 1);
|
|
|
|
username[USER_NAME_MAX_LENGTH] = '\0';
|
|
|
|
login_prompt (_("\n%s login: "), username, USER_NAME_MAX_LENGTH);
|
2008-09-21 01:14:12 +05:30
|
|
|
|
2009-04-23 02:16:49 +05:30
|
|
|
if ('\0' == username[0]) {
|
2008-09-21 01:14:12 +05:30
|
|
|
/* Prompt for a new login */
|
|
|
|
free (username);
|
|
|
|
username = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2008-09-20 20:09:09 +05:30
|
|
|
}
|
2009-04-20 18:17:04 +05:30
|
|
|
/* Get the username to be used to log failures */
|
|
|
|
failent_user = get_failent_user (username);
|
2007-10-07 17:14:14 +05:30
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
pwd = xgetpwnam (username);
|
|
|
|
if (NULL == pwd) {
|
|
|
|
preauth_flag = false;
|
|
|
|
failed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
2009-04-20 18:59:15 +05:30
|
|
|
user_passwd = pwd->pw_passwd;
|
|
|
|
/*
|
|
|
|
* If the encrypted password begins with a "!",
|
|
|
|
* the account is locked and the user cannot
|
|
|
|
* login, even if they have been
|
|
|
|
* "pre-authenticated."
|
|
|
|
*/
|
|
|
|
if ( ('!' == user_passwd[0])
|
|
|
|
|| ('*' == user_passwd[0])) {
|
|
|
|
failed = true;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-09-20 19:47:20 +05:30
|
|
|
|
2009-04-20 18:59:15 +05:30
|
|
|
if (strcmp (user_passwd, SHADOW_PASSWD_STRING) == 0) {
|
|
|
|
spwd = xgetspnam (username);
|
2008-06-11 00:26:23 +05:30
|
|
|
if (NULL != spwd) {
|
2009-04-20 18:59:15 +05:30
|
|
|
user_passwd = spwd->sp_pwdp;
|
2008-06-11 00:26:23 +05:30
|
|
|
} else {
|
2009-04-20 18:59:15 +05:30
|
|
|
/* The user exists in passwd, but not in
|
|
|
|
* shadow. SHADOW_PASSWD_STRING indicates
|
|
|
|
* that the password shall be in shadow.
|
|
|
|
*/
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN,
|
2008-09-20 20:09:09 +05:30
|
|
|
"no shadow password for '%s'%s",
|
|
|
|
username, fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The -r and -f flags provide a name which has already
|
|
|
|
* been authenticated by some server.
|
|
|
|
*/
|
2008-06-11 00:26:23 +05:30
|
|
|
if (preauth_flag) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto auth_ok;
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-20 18:59:15 +05:30
|
|
|
if (pw_auth (user_passwd, username, reason, (char *) 0) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto auth_ok;
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
SYSLOG ((LOG_WARN, "invalid password for '%s' %s",
|
2009-04-20 18:17:04 +05:30
|
|
|
failent_user, fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
failed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
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
|
|
|
*/
|
2008-06-11 00:26:23 +05:30
|
|
|
if ( !failed
|
2009-04-20 18:59:15 +05:30
|
|
|
&& (NULL != pwd)
|
|
|
|
&& (0 == pwd->pw_uid)
|
2007-10-07 17:14:59 +05:30
|
|
|
&& !is_console) {
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_CRIT, "ILLEGAL ROOT LOGIN %s", fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
failed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-11 00:26:23 +05:30
|
|
|
if ( !failed
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 15:27:03 +05:30
|
|
|
&& !login_access (username, ('\0' != *hostname) ? hostname : tty)) {
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
SYSLOG ((LOG_WARN, "LOGIN '%s' REFUSED %s",
|
2008-09-20 20:09:09 +05:30
|
|
|
username, fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
failed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-11 00:26:23 +05:30
|
|
|
if ( (NULL != pwd)
|
|
|
|
&& getdef_bool ("FAILLOG_ENAB")
|
2009-04-20 18:59:15 +05:30
|
|
|
&& !failcheck (pwd->pw_uid, &faillog, failed)) {
|
2007-10-07 17:16:07 +05:30
|
|
|
SYSLOG ((LOG_CRIT,
|
2008-09-20 20:09:09 +05:30
|
|
|
"exceeded failure limit for '%s' %s",
|
|
|
|
username, fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
failed = true;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-11 00:26:23 +05:30
|
|
|
if (!failed) {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* don't log non-existent users */
|
2008-06-11 00:26:23 +05:30
|
|
|
if ((NULL != pwd) && getdef_bool ("FAILLOG_ENAB")) {
|
2009-04-20 18:59:15 +05:30
|
|
|
failure (pwd->pw_uid, tty, &faillog);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
if (getdef_str ("FTMP_FILE") != NULL) {
|
2009-04-22 04:09:14 +05:30
|
|
|
#ifdef HAVE_UTMPX_H
|
|
|
|
struct utmpx *failent =
|
|
|
|
prepare_utmpx (failent_user,
|
|
|
|
tty,
|
|
|
|
/* FIXME: or fromhost? */hostname,
|
|
|
|
utent);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2009-04-22 04:09:14 +05:30
|
|
|
struct utmp *failent =
|
|
|
|
prepare_utmp (failent_user,
|
|
|
|
tty,
|
|
|
|
hostname,
|
|
|
|
utent);
|
2007-10-07 17:14:02 +05:30
|
|
|
#endif
|
2009-04-22 04:09:14 +05:30
|
|
|
failtmp (failent_user, failent);
|
|
|
|
free (failent);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
retries--;
|
|
|
|
if (retries <= 0) {
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_CRIT, "REPEATED login failures%s",
|
2008-09-20 20:09:09 +05:30
|
|
|
fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2008-09-21 01:35:22 +05:30
|
|
|
|
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
|
|
|
*/
|
2009-04-20 18:59:15 +05:30
|
|
|
if (user_passwd[0] == '\0') {
|
2007-10-07 17:16:07 +05:30
|
|
|
pw_auth ("!", username, reason, (char *) 0);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2008-09-21 01:35:22 +05:30
|
|
|
/*
|
|
|
|
* Authentication of this user failed.
|
|
|
|
* The username must be confirmed in the next try.
|
|
|
|
*/
|
|
|
|
free (username);
|
|
|
|
username = NULL;
|
|
|
|
|
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.
|
|
|
|
*/
|
2008-06-11 00:26:23 +05:30
|
|
|
if (delay > 0) {
|
2009-04-23 01:45:21 +05:30
|
|
|
(void) sleep (delay);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 01:47:11 +05:30
|
|
|
(void) puts (_("Login incorrect"));
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/* allow only one attempt with -r or -f */
|
2008-06-11 00:26:23 +05:30
|
|
|
if (rflg || fflg || (retries <= 0)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-09-20 19:47:20 +05:30
|
|
|
} /* while (true) */
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* ! USE_PAM */
|
2009-04-23 02:21:13 +05:30
|
|
|
assert (NULL != username);
|
|
|
|
assert (NULL != pwd);
|
2008-09-20 19:47:20 +05:30
|
|
|
|
2009-04-23 01:45:21 +05:30
|
|
|
(void) alarm (0); /* turn off alarm clock */
|
2008-09-20 19:47:20 +05:30
|
|
|
|
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
|
|
|
|
*/
|
2008-06-11 00:26:23 +05:30
|
|
|
if ( getdef_bool ("PORTTIME_CHECKS_ENAB")
|
2009-04-20 18:59:15 +05:30
|
|
|
&& !isttytime (username, tty, time ((time_t *) 0))) {
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
SYSLOG ((LOG_WARN, "invalid login time for '%s'%s",
|
2008-09-20 20:09:09 +05:30
|
|
|
username, fromhost));
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
|
|
|
bad_time_notify ();
|
|
|
|
exit (1);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
2009-04-20 18:59:15 +05:30
|
|
|
check_nologin (pwd->pw_uid == 0);
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 00:26:23 +05:30
|
|
|
if (getenv ("IFS")) { /* don't export user IFS ... */
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv ("IFS= \t\n", NULL); /* ... instead, set a safe IFS */
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-23 01:28:39 +05:30
|
|
|
update_utmp (username, tty, hostname, utent);
|
2009-04-22 04:09:14 +05:30
|
|
|
|
2009-04-20 18:59:15 +05:30
|
|
|
if (pwd->pw_shell[0] == '*') { /* subsystem root */
|
|
|
|
pwd->pw_shell++; /* skip the '*' */
|
|
|
|
subsystem (pwd); /* figure out what to execute */
|
2008-06-11 00:26:23 +05:30
|
|
|
subroot = true; /* say I was here again */
|
2007-10-07 17:14:59 +05:30
|
|
|
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
|
2008-07-12 03:50:43 +05:30
|
|
|
audit_fd = audit_open ();
|
|
|
|
audit_log_acct_message (audit_fd,
|
|
|
|
AUDIT_USER_LOGIN,
|
|
|
|
NULL, /* Prog. name */
|
|
|
|
"login",
|
2009-04-20 18:59:15 +05:30
|
|
|
username,
|
2008-09-20 18:50:31 +05:30
|
|
|
AUDIT_NO_ID,
|
2008-07-12 03:50:43 +05:30
|
|
|
hostname,
|
|
|
|
NULL, /* addr */
|
|
|
|
tty,
|
|
|
|
1); /* result */
|
|
|
|
close (audit_fd);
|
2007-10-07 17:17:11 +05:30
|
|
|
#endif /* WITH_AUDIT */
|
|
|
|
|
2007-10-07 17:14:59 +05:30
|
|
|
#ifndef USE_PAM /* pam_lastlog handles this */
|
2008-06-11 00:26:23 +05:30
|
|
|
if (getdef_bool ("LASTLOG_ENAB")) { /* give last login and log this one */
|
2009-04-23 01:33:26 +05:30
|
|
|
dolastlog (&ll, pwd, tty, hostname);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
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
|
2009-04-20 18:59:15 +05:30
|
|
|
* don't have access to /etc/shadow.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
2009-04-20 18:59:15 +05:30
|
|
|
if (NULL != spwd) { /* check for age of password */
|
|
|
|
if (expire (pwd, spwd)) {
|
|
|
|
/* The user updated her password, get the new
|
|
|
|
* entries.
|
|
|
|
* Use the x variants because we need to keep the
|
|
|
|
* entry for a long time, and there might be other
|
|
|
|
* getxxyy in between.
|
|
|
|
*/
|
2009-04-22 04:09:14 +05:30
|
|
|
pw_free (pwd);
|
2009-04-20 18:59:15 +05:30
|
|
|
pwd = xgetpwnam (username);
|
|
|
|
if (NULL == pwd) {
|
|
|
|
SYSLOG ((LOG_ERR,
|
|
|
|
"cannot find user %s after update of expired password",
|
|
|
|
username));
|
|
|
|
exit (1);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2009-04-22 04:09:14 +05:30
|
|
|
spw_free (spwd);
|
2009-04-20 18:59:15 +05:30
|
|
|
spwd = xgetspnam (username);
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2009-04-20 18:59:15 +05:30
|
|
|
setup_limits (pwd); /* nice, ulimit etc. */
|
2007-10-07 17:14:59 +05:30
|
|
|
#endif /* ! USE_PAM */
|
2009-04-20 18:59:15 +05:30
|
|
|
chown_tty (pwd);
|
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.
|
|
|
|
*/
|
2008-06-14 02:55:15 +05:30
|
|
|
(void) signal (SIGINT, SIG_IGN);
|
2007-10-07 17:16:52 +05:30
|
|
|
child = fork ();
|
|
|
|
if (child < 0) {
|
|
|
|
/* error in fork() */
|
2007-10-07 17:17:01 +05:30
|
|
|
fprintf (stderr, _("%s: failure forking: %s"),
|
2008-09-20 20:09:09 +05:30
|
|
|
Prog, strerror (errno));
|
2007-10-07 17:16:52 +05:30
|
|
|
PAM_END;
|
|
|
|
exit (0);
|
2008-06-11 00:26:23 +05:30
|
|
|
} else if (child != 0) {
|
2007-10-07 17:16:52 +05:30
|
|
|
/*
|
|
|
|
* 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();
|
2008-06-11 00:26:23 +05:30
|
|
|
if (ioctl(0, TIOCSCTTY, 1) != 0) {
|
2009-04-18 02:10:26 +05:30
|
|
|
fprintf (stderr, _("TIOCSCTTY failed on %s"), tty);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-12-27 04:06:54 +05:30
|
|
|
}
|
2007-10-07 17:16:52 +05:30
|
|
|
|
2009-04-20 17:57:27 +05:30
|
|
|
|
2009-04-20 18:59:15 +05:30
|
|
|
/* The pwd and spwd entries for the user have been copied.
|
|
|
|
*
|
2009-04-20 17:57:27 +05:30
|
|
|
* Close all the files so that unauthorized access won't occur.
|
|
|
|
*/
|
|
|
|
endpwent (); /* stop access to password file */
|
|
|
|
endgrent (); /* stop access to group file */
|
|
|
|
endspent (); /* stop access to shadow passwd file */
|
|
|
|
#ifdef SHADOWGRP
|
|
|
|
endsgent (); /* stop access to shadow group file */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Drop root privileges */
|
2007-10-07 17:14:14 +05:30
|
|
|
#ifndef USE_PAM
|
2009-04-20 18:59:15 +05:30
|
|
|
if (setup_uid_gid (pwd, is_console))
|
2007-10-07 17:14:14 +05:30
|
|
|
#else
|
2009-04-20 17:57:27 +05:30
|
|
|
/* The group privileges were already dropped.
|
|
|
|
* See setup_groups() above.
|
|
|
|
*/
|
2009-04-20 18:59:15 +05:30
|
|
|
if (change_uid (pwd))
|
2007-10-07 17:14:14 +05:30
|
|
|
#endif
|
2008-06-11 00:26:23 +05:30
|
|
|
{
|
2007-10-07 17:14:59 +05:30
|
|
|
exit (1);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-20 18:59:15 +05:30
|
|
|
setup_env (pwd); /* 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);
|
2008-06-11 00:26:23 +05:30
|
|
|
while ((NULL != env) && (NULL != *env)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv (*env, NULL);
|
2007-10-07 17:14:02 +05:30
|
|
|
env++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-06-14 02:55:15 +05:30
|
|
|
(void) setlocale (LC_ALL, "");
|
|
|
|
(void) bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
(void) textdomain (PACKAGE);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-20 17:18:59 +05:30
|
|
|
if (!hushed (username)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
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 */
|
2008-06-11 00:26:23 +05:30
|
|
|
if ( getdef_bool ("FAILLOG_ENAB")
|
|
|
|
&& (0 != faillog.fail_cnt)) {
|
2007-10-07 17:14:59 +05:30
|
|
|
failprint (&faillog);
|
2007-10-07 17:14:02 +05:30
|
|
|
/* Reset the lockout times if logged in */
|
2008-06-11 00:26:23 +05:30
|
|
|
if ( (0 != faillog.fail_max)
|
|
|
|
&& (faillog.fail_cnt >= faillog.fail_max)) {
|
2009-04-23 01:47:11 +05:30
|
|
|
(void) puts (_("Warning: login re-enabled after temporary lockout."));
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_WARN,
|
2008-09-20 20:09:09 +05:30
|
|
|
"login '%s' re-enabled after temporary lockout (%d failures)",
|
|
|
|
username, (int) faillog.fail_cnt));
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
2008-06-11 00:26:23 +05:30
|
|
|
if ( getdef_bool ("LASTLOG_ENAB")
|
2009-04-23 01:33:26 +05:30
|
|
|
&& (ll.ll_time != 0)) {
|
|
|
|
time_t ll_time = ll.ll_time;
|
2007-10-07 17:16:07 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#ifdef HAVE_STRFTIME
|
2009-04-23 01:47:11 +05:30
|
|
|
(void) strftime (ptime, sizeof (ptime),
|
|
|
|
"%a %b %e %H:%M:%S %z %Y",
|
|
|
|
localtime (&ll_time));
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Last login: %s on %s"),
|
2009-04-23 01:33:26 +05:30
|
|
|
ptime, ll.ll_line);
|
2007-10-07 17:14:02 +05:30
|
|
|
#else
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_("Last login: %.19s on %s"),
|
2009-04-23 01:33:26 +05:30
|
|
|
ctime (&ll_time), ll.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 */
|
2009-04-23 01:33:26 +05:30
|
|
|
if ('\0' != ll.ll_host[0]) {
|
2007-10-07 17:14:59 +05:30
|
|
|
printf (_(" from %.*s"),
|
2009-04-23 01:33:26 +05:30
|
|
|
(int) sizeof ll.ll_host, ll.ll_host);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
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
|
|
|
}
|
2009-04-12 00:07:08 +05:30
|
|
|
agecheck (spwd);
|
2007-10-07 17:14:59 +05:30
|
|
|
|
|
|
|
mailcheck (); /* report on the status of mail */
|
|
|
|
#endif /* !USE_PAM */
|
2008-06-11 00:26:23 +05:30
|
|
|
} else {
|
2007-10-07 17:14:59 +05:30
|
|
|
addenv ("HUSHLOGIN=TRUE", NULL);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-20 18:42:09 +05:30
|
|
|
ttytype (tty);
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-14 02:55:15 +05:30
|
|
|
(void) signal (SIGQUIT, SIG_DFL); /* default quit signal */
|
|
|
|
(void) signal (SIGTERM, SIG_DFL); /* default terminate signal */
|
|
|
|
(void) signal (SIGALRM, SIG_DFL); /* default alarm signal */
|
|
|
|
(void) signal (SIGHUP, SIG_DFL); /* added this. --marekm */
|
|
|
|
(void) signal (SIGINT, SIG_DFL); /* default interrupt signal */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2009-04-20 18:59:15 +05:30
|
|
|
if (0 == pwd->pw_uid) {
|
2007-10-07 17:14:59 +05:30
|
|
|
SYSLOG ((LOG_NOTICE, "ROOT LOGIN %s", fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
} else if (getdef_bool ("LOG_OK_LOGINS")) {
|
* src/chfn.c, src/chsh.c, src/groupdel.c, src/groupmems.c,
src/groupmod.c, src/grpck.c, src/login.c, src/logoutd.c,
src/newgrp.c, src/newusers.c, src/passwd.c, src/pwck.c,
src/suauth.c, src/useradd.c, src/userdel.c, src/usermod.c,
src/vipw.c: Complete the switch from the `' quotation style to ''.
Do it also in SYSLOG messages. Quote some parameters. All this
permits to merge some messages.
2008-08-06 21:21:52 +05:30
|
|
|
SYSLOG ((LOG_INFO, "'%s' logged in %s", username, fromhost));
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:14:59 +05:30
|
|
|
closelog ();
|
2008-06-11 00:26:23 +05:30
|
|
|
tmp = getdef_str ("FAKE_SHELL");
|
|
|
|
if (NULL != tmp) {
|
2009-04-20 18:59:15 +05:30
|
|
|
err = shell (tmp, pwd->pw_shell, newenvp); /* fake shell */
|
2008-06-11 00:26:23 +05:30
|
|
|
} else {
|
2007-10-07 17:17:22 +05:30
|
|
|
/* exec the shell finally */
|
2009-04-20 18:59:15 +05:30
|
|
|
err = shell (pwd->pw_shell, (char *) 0, newenvp);
|
2008-06-11 00:26:23 +05:30
|
|
|
}
|
2007-10-07 17:17:22 +05:30
|
|
|
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
|
|
|
}
|
2008-06-11 00:26:23 +05:30
|
|
|
|