version 1.58, 2009/10/27 23:59:44 |
version 1.59, 2010/12/09 15:45:30 |
|
|
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
int asme = 0, asthem = 0, ch, fastlogin = 0, emlogin = 0, prio; |
int asme = 0, asthem = 0, ch, fastlogin = 0, emlogin = 0, prio; |
|
int altshell = 0; |
char *user, *shell = NULL, *avshell, *username, **np; |
char *user, *shell = NULL, *avshell, *username, **np; |
char *class = NULL, *style = NULL, *p; |
char *class = NULL, *style = NULL, *p; |
enum { UNSET, YES, NO } iscsh = UNSET; |
enum { UNSET, YES, NO } iscsh = UNSET; |
|
|
uid_t ruid; |
uid_t ruid; |
u_int flags; |
u_int flags; |
|
|
while ((ch = getopt(argc, argv, "a:c:fKLlm-")) != -1) |
while ((ch = getopt(argc, argv, "a:c:fKLlms:-")) != -1) |
switch (ch) { |
switch (ch) { |
case 'a': |
case 'a': |
if (style) |
if (style) |
|
|
asme = 1; |
asme = 1; |
asthem = 0; |
asthem = 0; |
break; |
break; |
|
case 's': |
|
altshell = 1; |
|
shell = optarg; |
|
break; |
default: |
default: |
usage(); |
usage(); |
} |
} |
|
|
if (ruid && class) |
if (ruid && class) |
auth_errx(as, 1, "only the superuser may specify a login class"); |
auth_errx(as, 1, "only the superuser may specify a login class"); |
|
|
|
if (ruid && altshell) |
|
auth_errx(as, 1, "only the superuser may specify a login shell"); |
|
|
if (username != NULL) |
if (username != NULL) |
auth_setoption(as, "invokinguser", username); |
auth_setoption(as, "invokinguser", username); |
|
|
|
|
auth_errx(as, 1, "who are you?"); |
auth_errx(as, 1, "who are you?"); |
if ((username = strdup(pwd->pw_name)) == NULL) |
if ((username = strdup(pwd->pw_name)) == NULL) |
auth_errx(as, 1, "can't allocate memory"); |
auth_errx(as, 1, "can't allocate memory"); |
if (asme) { |
if (asme && !altshell) { |
if (pwd->pw_shell && *pwd->pw_shell) { |
if (pwd->pw_shell && *pwd->pw_shell) { |
if ((shell = strdup(pwd->pw_shell)) == NULL) |
if ((shell = strdup(pwd->pw_shell)) == NULL) |
auth_errx(as, 1, "can't allocate memory"); |
auth_errx(as, 1, "can't allocate memory"); |
|
|
fprintf(stderr, "Login incorrect\n"); |
fprintf(stderr, "Login incorrect\n"); |
} |
} |
|
|
if (asme) { |
if (!altshell) { |
/* if asme and non-standard target shell, must be root */ |
if (asme) { |
if (!chshell(pwd->pw_shell) && ruid) |
/* if asme and non-std target shell, must be root */ |
auth_errx(as, 1, "permission denied (shell)."); |
if (ruid && !chshell(shell)) |
} else if (pwd->pw_shell && *pwd->pw_shell) { |
auth_errx(as, 1, "permission denied (shell)."); |
if ((shell = strdup(pwd->pw_shell)) == NULL) |
} else if (pwd->pw_shell && *pwd->pw_shell) { |
auth_errx(as, 1, "can't allocate memory"); |
if ((shell = strdup(pwd->pw_shell)) == NULL) |
iscsh = UNSET; |
auth_errx(as, 1, "can't allocate memory"); |
} else { |
iscsh = UNSET; |
shell = _PATH_BSHELL; |
} else { |
iscsh = NO; |
shell = _PATH_BSHELL; |
|
iscsh = NO; |
|
} |
} |
} |
|
|
if ((p = strrchr(shell, '/'))) |
if ((p = strrchr(shell, '/'))) |
|
|
} |
} |
if (setenv("HOME", pwd->pw_dir, 1) == -1 || |
if (setenv("HOME", pwd->pw_dir, 1) == -1 || |
setenv("SHELL", shell, 1) == -1) |
setenv("SHELL", shell, 1) == -1) |
|
auth_err(as, 1, "unable to set environment"); |
|
} else if (altshell) { |
|
if (setenv("SHELL", shell, 1) == -1) |
auth_err(as, 1, "unable to set environment"); |
auth_err(as, 1, "unable to set environment"); |
} |
} |
|
|