#include <sys/wait.h>
#include <signal.h>
#include <errno.h>
+#include <err.h>
#include <grp.h>
#include <pwd.h>
#include <utmp.h>
# define PAM_FAIL_CHECK if (retcode != PAM_SUCCESS) { \
fprintf(stderr,"\n%s\n",pam_strerror(pamh, retcode)); \
syslog(LOG_ERR,"%s",pam_strerror(pamh, retcode)); \
- pam_end(pamh, retcode); exit(1); \
+ pam_end(pamh, retcode); exit(EXIT_FAILURE); \
}
# define PAM_END { \
pam_setcred(pamh, PAM_DELETE_CRED); \
if (fd == -1) {
syslog(LOG_ERR, _("FATAL: can't reopen tty: %s"),
strerror(errno));
- sleep(1);
- exit(1);
+ sleepexit(EXIT_FAILURE);
}
if (!isatty(fd)) {
close(fd);
syslog(LOG_ERR, _("FATAL: %s is not a terminal"), tty);
- sleep(1);
- exit(1);
+ sleepexit(EXIT_FAILURE);
}
flags = fcntl(fd, F_GETFL);
|| !S_ISCHR(statbuf.st_mode)
|| (statbuf.st_nlink > 1 && strncmp(ttyn, "/dev/", 5))
|| (access(ttyn, R_OK | W_OK) != 0)) {
+
syslog(LOG_ERR, _("FATAL: bad tty"));
- sleep(1);
- exit(1);
+ sleepexit(EXIT_FAILURE);
}
}
if (getuid()) {
fprintf(stderr,
_("login: -h for super-user only.\n"));
- exit(1);
+ exit(EXIT_FAILURE);
}
hflag = 1;
if (domain && (p = strchr(optarg, '.')) &&
default:
fprintf(stderr,
_("usage: login [-fp] [username]\n"));
- exit(1);
+ exit(EXIT_FAILURE);
}
argc -= optind;
argv += optind;
retcode = pam_start(hflag?"remote":"login",username, &conv, &pamh);
if(retcode != PAM_SUCCESS) {
- fprintf(stderr, _("%s: PAM failure, aborting: %s\n"),
- "login", pam_strerror(pamh, retcode));
+ warnx(_("PAM failure, aborting: %s"), pam_strerror(pamh, retcode));
syslog(LOG_ERR, _("Couldn't initialize PAM: %s"),
pam_strerror(pamh, retcode));
- exit(99);
+ exit(EXIT_FAILURE);
}
/* hostname & tty are either set to NULL or their correct values,
depending on how much we know */
fprintf(stderr,_("\nLogin incorrect\n"));
pam_end(pamh, retcode);
- exit(0);
+ exit(EXIT_SUCCESS);
}
}
PAM_FAIL_CHECK;
if (!username || !*username) {
- fprintf(stderr, _("\nSession setup problem, abort.\n"));
+ warnx(_("\nSession setup problem, abort."));
syslog(LOG_ERR, _("NULL user name in %s:%d. Abort."),
__FUNCTION__, __LINE__);
pam_end(pamh, PAM_SYSTEM_ERR);
- exit(1);
+ exit(EXIT_FAILURE);
}
if (!(pwd = getpwnam(username))) {
- fprintf(stderr, _("\nSession setup problem, abort.\n"));
+ warnx(_("\nSession setup problem, abort."));
syslog(LOG_ERR, _("Invalid user name \"%s\" in %s:%d. Abort."),
username, __FUNCTION__, __LINE__);
pam_end(pamh, PAM_SYSTEM_ERR);
- exit(1);
+ exit(EXIT_FAILURE);
}
/*
pwd->pw_shell = strdup(pwd->pw_shell);
if (!pwd->pw_name || !pwd->pw_passwd || !pwd->pw_gecos ||
!pwd->pw_dir || !pwd->pw_shell) {
- fprintf(stderr, _("login: Out of memory\n"));
+ warnx(_("out of memory"));
syslog(LOG_ERR, "Out of memory");
pam_end(pamh, PAM_SYSTEM_ERR);
- exit(1);
+ exit(EXIT_FAILURE);
}
username = pwd->pw_name;
*/
if (initgroups(username, pwd->pw_gid) < 0) {
syslog(LOG_ERR, "initgroups: %m");
- fprintf(stderr, _("\nSession setup problem, abort.\n"));
+ warnx(_("\nSession setup problem, abort."));
pam_end(pamh, PAM_SYSTEM_ERR);
- exit(1);
+ exit(EXIT_FAILURE);
}
retcode = pam_open_session(pamh, 0);
if (username[0] == '+') {
puts(_("Illegal username"));
badlogin(username);
- sleepexit(1);
+ sleepexit(EXIT_FAILURE);
}
/* (void)strcpy(tbuf, username); why was this here? */
* refuse the login attempt.
*/
if (pwd && pwd->pw_uid == 0 && !rootterm(tty_name)) {
- fprintf(stderr,
- _("%s login refused on this terminal.\n"),
+ warnx(_("%s login refused on this terminal."),
pwd->pw_name);
if (hostname)
/* we allow 10 tries, but after 3 we start backing off */
if (++cnt > 3) {
if (cnt >= 10) {
- sleepexit(1);
+ sleepexit(EXIT_FAILURE);
}
sleep((unsigned int)((cnt - 3) * 5));
}
child_pid = fork();
if (child_pid < 0) {
- int errsv = errno;
/* error in fork() */
- fprintf(stderr, _("login: failure forking: %s"), strerror(errsv));
+ warn(_("failure forking"));
PAM_END;
- exit(0);
+ exit(EXIT_FAILURE);
}
if (child_pid) {
;
openlog("login", LOG_ODELAY, LOG_AUTHPRIV);
PAM_END;
- exit(0);
+ exit(EXIT_SUCCESS);
}
/* child */
sigaction(SIGHUP, &oldsa_hup, NULL);
sigaction(SIGTERM, &oldsa_term, NULL);
if(got_sig)
- exit(1);
+ exit(EXIT_FAILURE);
/*
* Problem: if the user's shell is a shell like ash that doesnt do
/* discard permissions last so can't get killed and drop core */
if(setuid(pwd->pw_uid) < 0 && pwd->pw_uid) {
syslog(LOG_ALERT, _("setuid() failed"));
- exit(1);
+ exit(EXIT_FAILURE);
}
/* wait until here to change directory! */
if (chdir(pwd->pw_dir) < 0) {
- printf(_("No directory %s!\n"), pwd->pw_dir);
+ warn(_("%s: change directory failed"), pwd->pw_dir);
if (chdir("/"))
- exit(0);
+ exit(EXIT_FAILURE);
pwd->pw_dir = "/";
printf(_("Logging in with home = \"/\".\n"));
}
errsv = errno;
if (!strcmp(childArgv[0], "/bin/sh"))
- fprintf(stderr, _("login: couldn't exec shell script: %s.\n"),
- strerror(errsv));
+ warn(_("couldn't exec shell script"));
else
- fprintf(stderr, _("login: no shell: %s.\n"), strerror(errsv));
+ warn(_("no shell"));
- exit(0);
+ exit(EXIT_SUCCESS);
}
#ifndef HAVE_SECURITY_PAM_MISC_H
for (p = nbuf; (ch = getchar()) != '\n'; ) {
if (ch == EOF) {
badlogin("EOF");
- exit(0);
+ exit(EXIT_FAILURE);
}
if (p < nbuf + UT_NAMESIZE)
*p++ = ch;
cnt++;
if (cnt > UT_NAMESIZE + 20) {
- fprintf(stderr, _("login name much too long.\n"));
badlogin(_("NAME too long"));
- exit(0);
+ errx(EXIT_FAILURE, _("login name much too long."));
}
}
if (p > nbuf) {
if (nbuf[0] == '-')
- fprintf(stderr,
- _("login names may not start with '-'.\n"));
+ warnx(_("login names may not start with '-'."));
else {
*p = '\0';
username = nbuf;
cnt2++;
if (cnt2 > 50) {
- fprintf(stderr, _("too many bare linefeeds.\n"));
badlogin(_("EXCESSIVE linefeeds"));
- exit(0);
+ errx(EXIT_FAILURE, _("too many bare linefeeds."));
}
}
}
tcgetattr(0, &ti);
ti.c_lflag |= ECHO;
tcsetattr(0, TCSANOW, &ti);
- exit(0); /* %% */
+ exit(EXIT_SUCCESS); /* %% */
}
static void
timedout(int sig) {
signal(SIGALRM, timedout2);
alarm(10);
- fprintf(stderr, _("Login timed out after %d seconds\n"), timeout);
+ warnx(_("timed out after %d seconds"), timeout);
signal(SIGALRM, SIG_IGN);
alarm(0);
timedout2(0);
return 1;
} else
continue;
- } else {
+ } else {
close(fd);
return 0;
- }
+ }
}
}
#endif /* !HAVE_SECURITY_PAM_MISC_H */
while ((nchars = read(fd, tbuf, sizeof(tbuf))) > 0)
write(fileno(stdout), tbuf, nchars);
close(fd);
- sleepexit(0);
+ sleepexit(EXIT_SUCCESS);
}
}
#endif