home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
shadow-2.pt3
/
lmain.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-03
|
4KB
|
165 lines
#include <sys/types.h>
#include <stdio.h>
#include <pwd.h>
#include <utmp.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include "config.h"
#include "lastlog.h"
char name[BUFSIZ];
char pass[BUFSIZ];
char home[BUFSIZ];
char prog[BUFSIZ];
char mail[BUFSIZ];
struct passwd pwent;
struct utmp utent;
struct lastlog lastlog;
#ifndef MAXENV
#define MAXENV 64
#endif
char *newenvp[MAXENV];
int newenvc = 0;
int maxenv = MAXENV;
extern char **environ;
char *getenv ();
char *memset ();
void checkutmp ();
void addenv ();
void setenv ();
unsigned alarm ();
void login ();
void entry ();
void setutmp ();
void subsystem ();
void log ();
void setup ();
void expire ();
void motd ();
void mailcheck ();
void shell ();
#ifndef ALARM
#define ALARM 60
#endif
#ifndef RETRIES
#define RETRIES 3
#endif
int main (argc, argv, envp)
int argc;
char **argv;
char **envp;
{
int retries = RETRIES;
checkutmp (); /* must be lowest level shell */
if (! isatty (0)) /* must be a terminal */
exit (1);
while (*envp) /* add inherited environment, */
addenv (*envp++); /* some variables change later */
#ifdef TZ
addenv (TZ); /* set the default $TZ, if one */
#endif
#ifdef HZ
addenv (HZ); /* set the default $HZ, if one */
#endif
if (argc >= 2) { /* now set command line variables */
setenv (argc - 2, &argv[2]);
(void) strncpy (name, argv[1], sizeof name);
}
(void) alarm (ALARM); /* only allow ALARM sec. for login */
while (1) { /* repeatedly get login/password pairs */
if (! name[0]) { /* need to get a login id */
login (name);
continue;
}
entry (name, &pwent); /* get entry from password file */
/*
* Here we have a sticky situation. Some accounts may have no
* password entry in the password file. So, we don't ask for a
* password. Others, have a blank password entered - you be the
* judge. The conditional compilation NOBLANK requires even
* blank passwords to be prompted for. This may well break
* quite a few systems. Use with discretion.
*/
#ifdef NOBLANK
/* get a password from user */
if (! password ("Password:", pass))
continue;
#else
if ((! pwent.pw_name || pwent.pw_passwd)
&& ! password ("Password:", pass))
continue;
#endif
if (valid (pass, &pwent)) /* check encrypted passwords ... */
break; /* ... encrypted passwords matched */
if (--retries <= 0) /* only allow so many failures */
exit (1);
puts ("Login incorrect");
(void) memset (name, '\0', sizeof name);
}
#ifdef DIALUP
if (! dialcheck (utent.ut_line,
pwent.pw_shell ? pwent.pw_shell:"/bin/sh")) {
puts ("Dialup password incorrect");
exit (1);
}
#endif
(void) alarm (0); /* turn off alarm clock */
environ = newenvp; /* make new environment active */
if (getenv ("IFS")) /* don't export user IFS ... */
addenv ("IFS= \t\n"); /* ... instead, set a safe IFS */
setutmp (); /* make entry in utmp & wtmp files */
#ifdef CONSOLE
if (pwent.pw_uid == 0 && /* root no logging in on console ? */
strncmp (CONSOLE, utent.ut_line, sizeof utent.ut_line))
exit (1); /* then exit! */
#endif
if (pwent.pw_shell[0] == '*') /* subsystem root required */
subsystem (); /* figure out what to execute */
#ifdef LASTLOG
log (); /* give last login and log this one */
#endif
setup (&pwent); /* set UID, GID, HOME, etc ... */
#ifdef AGING
if (pwent.pw_age) /* check for age of password ... */
expire (pwent.pw_age); /* ... ask for new one if expired */
#endif
#ifdef MOTD
motd (); /* print the message of the day */
#endif
#ifdef LASTLOG
if (lastlog.ll_time != 0)
printf ("Last login: %.19s on %s\n",
ctime (&lastlog.ll_time), lastlog.ll_line);
#endif
#ifdef MAILCHECK
mailcheck (); /* report on the status of mail */
#endif
signal (SIGINT, SIG_DFL); /* default interrupt signal */
signal (SIGQUIT, SIG_DFL); /* default quit signal */
signal (SIGTERM, SIG_DFL); /* default terminate signal */
signal (SIGALRM, SIG_DFL); /* default alarm signal */
shell (pwent.pw_shell); /* exec the shell finally. */
/*NOTREACHED*/
}