summaryrefslogtreecommitdiff
path: root/usr.bin/sudo/auth
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-01-03 03:49:17 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-01-03 03:49:17 +0000
commita8c409b2b43635d095e5e8b5fd8fcd42fc4a539c (patch)
tree69468cedd38b3d8eb953e6fdfbdc23e8500f93cc /usr.bin/sudo/auth
parent2e8dc04dc3a4b4d1e0664c16b572efd2c74466e5 (diff)
Update to sudo 1.6.4
Diffstat (limited to 'usr.bin/sudo/auth')
-rw-r--r--usr.bin/sudo/auth/afs.c30
-rw-r--r--usr.bin/sudo/auth/aix_auth.c34
-rw-r--r--usr.bin/sudo/auth/bsdauth.c44
-rw-r--r--usr.bin/sudo/auth/dce.c32
-rw-r--r--usr.bin/sudo/auth/fwtk.c47
-rw-r--r--usr.bin/sudo/auth/kerb4.c30
-rw-r--r--usr.bin/sudo/auth/kerb5.c30
-rw-r--r--usr.bin/sudo/auth/pam.c116
-rw-r--r--usr.bin/sudo/auth/passwd.c43
-rw-r--r--usr.bin/sudo/auth/rfc1938.c32
-rw-r--r--usr.bin/sudo/auth/secureware.c30
-rw-r--r--usr.bin/sudo/auth/securid.c47
-rw-r--r--usr.bin/sudo/auth/sia.c34
-rw-r--r--usr.bin/sudo/auth/sudo_auth.c73
-rw-r--r--usr.bin/sudo/auth/sudo_auth.h5
15 files changed, 409 insertions, 218 deletions
diff --git a/usr.bin/sudo/auth/afs.c b/usr.bin/sudo/auth/afs.c
index e9f6070ca4b..f17a6e875bd 100644
--- a/usr.bin/sudo/auth/afs.c
+++ b/usr.bin/sudo/auth/afs.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999, 2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,21 +34,27 @@
#include "config.h"
+#include <sys/param.h>
+#include <sys/types.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <afs/stds.h>
@@ -58,7 +64,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: afs.c,v 1.5 1999/08/14 15:36:45 millert Exp $";
+static const char rcsid[] = "$Sudo: afs.c,v 1.6 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
int
diff --git a/usr.bin/sudo/auth/aix_auth.c b/usr.bin/sudo/auth/aix_auth.c
index 3748d4dd869..126664c2c61 100644
--- a/usr.bin/sudo/auth/aix_auth.c
+++ b/usr.bin/sudo/auth/aix_auth.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,28 +34,34 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include "sudo.h"
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: aix_auth.c,v 1.8 2000/02/27 03:49:05 millert Exp $";
+static const char rcsid[] = "$Sudo: aix_auth.c,v 1.11 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
int
@@ -67,8 +73,8 @@ aixauth_verify(pw, prompt, auth)
char *message, *pass;
int reenter = 1;
- pass = tgetpass(prompt, def_ival(I_PW_TIMEOUT) * 60, tgetpass_flags);
- if (authenticate(pw->pw_name, pass, &reenter, &message) == 0)
+ pass = tgetpass(prompt, def_ival(I_PASSWD_TIMEOUT) * 60, tgetpass_flags);
+ if (pass && authenticate(pw->pw_name, pass, &reenter, &message) == 0)
return(AUTH_SUCCESS);
else
return(AUTH_FAILURE);
diff --git a/usr.bin/sudo/auth/bsdauth.c b/usr.bin/sudo/auth/bsdauth.c
index 08b566d7922..faf117754f2 100644
--- a/usr.bin/sudo/auth/bsdauth.c
+++ b/usr.bin/sudo/auth/bsdauth.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 2000-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,22 +34,28 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <ctype.h>
-#include <sys/param.h>
-#include <sys/types.h>
#include <pwd.h>
#include <login_cap.h>
@@ -59,7 +65,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: bsdauth.c,v 1.3 2000/10/30 03:45:11 millert Exp $";
+static const char rcsid[] = "$Sudo: bsdauth.c,v 1.6 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
extern char *login_style; /* from sudo.c */
@@ -122,10 +128,10 @@ bsdauth_verify(pw, prompt, auth)
* S/Key.
*/
if ((s = auth_challenge(as)) == NULL) {
- pass = tgetpass(prompt, def_ival(I_PW_TIMEOUT) * 60, tgetpass_flags);
+ pass = tgetpass(prompt, def_ival(I_PASSWD_TIMEOUT) * 60, tgetpass_flags);
} else {
- pass = tgetpass(s, def_ival(I_PW_TIMEOUT) * 60, tgetpass_flags);
- if (!pass || *pass == '\0') {
+ pass = tgetpass(s, def_ival(I_PASSWD_TIMEOUT) * 60, tgetpass_flags);
+ if (pass && *pass == '\0') {
if ((prompt = strrchr(s, '\n')))
prompt++;
else
@@ -139,16 +145,16 @@ bsdauth_verify(pw, prompt, auth)
while (isspace(prompt[len]) || prompt[len] == ':')
prompt[len--] = '\0';
easprintf(&s, "%s [echo on]: ", prompt);
- pass = tgetpass(s, def_ival(I_PW_TIMEOUT) * 60,
+ pass = tgetpass(s, def_ival(I_PASSWD_TIMEOUT) * 60,
tgetpass_flags | TGP_ECHO);
free(s);
}
}
- if (!pass || *pass == '\0')
- nil_pw = 1; /* empty password */
+ if (!pass || *pass == '\0') /* ^C or empty password */
+ nil_pw = 1;
- authok = auth_userresponse(as, pass, 1);
+ authok = pass ? auth_userresponse(as, pass, 1) : 0;
/* restore old signal handler */
(void)signal(SIGCHLD, childkiller);
diff --git a/usr.bin/sudo/auth/dce.c b/usr.bin/sudo/auth/dce.c
index 012467b4836..8d4115b38d3 100644
--- a/usr.bin/sudo/auth/dce.c
+++ b/usr.bin/sudo/auth/dce.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
+ * Copyright (c) 1996, 1998, 1999, 2001
+ * Todd C. Miller <Todd.Miller@courtesan.com>. All rights reserved.
*
* This code is derived from software contributed by Jeff Earickson
* of Colby College, Waterville, ME <jaearick@colby.edu>
@@ -48,21 +48,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <dce/rpc.h>
@@ -73,7 +79,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: dce.c,v 1.7 1999/08/31 09:39:17 millert Exp $";
+static const char rcsid[] = "$Sudo: dce.c,v 1.8 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
static int check_dce_status __P((error_status_t, char *));
diff --git a/usr.bin/sudo/auth/fwtk.c b/usr.bin/sudo/auth/fwtk.c
index dbbb9275b4c..ab3bae0922a 100644
--- a/usr.bin/sudo/auth/fwtk.c
+++ b/usr.bin/sudo/auth/fwtk.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,21 +34,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <auth.h>
@@ -58,7 +64,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: fwtk.c,v 1.10 2000/02/27 03:49:06 millert Exp $";
+static const char rcsid[] = "$Sudo: fwtk.c,v 1.14 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
int
@@ -118,16 +124,23 @@ fwtk_verify(pw, prompt, auth)
/* Get the password/response from the user. */
if (strncmp(resp, "challenge ", 10) == 0) {
(void) snprintf(buf, sizeof(buf), "%s\nResponse: ", &resp[10]);
- pass = tgetpass(buf, def_ival(I_PW_TIMEOUT) * 60,
- tgetpass_flags | TGP_ECHO);
+ pass = tgetpass(buf, def_ival(I_PASSWD_TIMEOUT) * 60, tgetpass_flags);
+ if (pass && *pass == '\0') {
+ pass = tgetpass("Response [echo on]: ",
+ def_ival(I_PASSWD_TIMEOUT) * 60, tgetpass_flags | TGP_ECHO);
+ }
} else if (strncmp(resp, "password", 8) == 0) {
- pass = tgetpass(prompt, def_ival(I_PW_TIMEOUT) * 60, tgetpass_flags);
+ pass = tgetpass(prompt, def_ival(I_PASSWD_TIMEOUT) * 60,
+ tgetpass_flags);
} else {
(void) fprintf(stderr, "%s: %s\n", Argv[0], resp);
return(AUTH_FATAL);
}
- if (!pass || *pass == '\0')
- nil_pw = 1; /* empty password */
+ if (!pass) { /* ^C or error */
+ nil_pw = 1;
+ return(AUTH_FAILURE);
+ } else if (*pass == '\0') /* empty password */
+ nil_pw = 1;
/* Send the user's response to the server */
(void) snprintf(buf, sizeof(buf), "response '%s'", pass);
diff --git a/usr.bin/sudo/auth/kerb4.c b/usr.bin/sudo/auth/kerb4.c
index 2791ec9aef5..fd64aabba5e 100644
--- a/usr.bin/sudo/auth/kerb4.c
+++ b/usr.bin/sudo/auth/kerb4.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999, 2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,21 +34,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <krb.h>
@@ -56,7 +62,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: kerb4.c,v 1.5 1999/08/14 15:36:46 millert Exp $";
+static const char rcsid[] = "$Sudo: kerb4.c,v 1.6 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
int
diff --git a/usr.bin/sudo/auth/kerb5.c b/usr.bin/sudo/auth/kerb5.c
index f9adb3dcaea..1992c1dd6c7 100644
--- a/usr.bin/sudo/auth/kerb5.c
+++ b/usr.bin/sudo/auth/kerb5.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999, 2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* This code is derived from software contributed by Frank Cusack
@@ -37,21 +37,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <krb5.h>
@@ -59,7 +65,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: kerb5.c,v 1.10 1999/10/13 02:34:55 millert Exp $";
+static const char rcsid[] = "$Sudo: kerb5.c,v 1.11 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
static int verify_krb_v5_tgt __P((krb5_context, krb5_ccache, char *));
diff --git a/usr.bin/sudo/auth/pam.c b/usr.bin/sudo/auth/pam.c
index 169602dda74..24bc59f7c6f 100644
--- a/usr.bin/sudo/auth/pam.c
+++ b/usr.bin/sudo/auth/pam.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,21 +34,30 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
+# include <memory.h>
+# endif
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <security/pam_appl.h>
@@ -57,13 +66,17 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: pam.c,v 1.15 2000/02/27 03:49:06 millert Exp $";
+static const char rcsid[] = "$Sudo: pam.c,v 1.23 2001/12/31 17:18:12 millert Exp $";
#endif /* lint */
static int sudo_conv __P((int, PAM_CONST struct pam_message **,
struct pam_response **, VOID *));
static char *def_prompt;
+#ifndef PAM_DATA_SILENT
+#define PAM_DATA_SILENT 0
+#endif
+
int
pam_init(pw, promptp, auth)
struct passwd *pw;
@@ -80,6 +93,9 @@ pam_init(pw, promptp, auth)
"unable to initialize PAM");
return(AUTH_FATAL);
}
+ if (strcmp(user_tty, "unknown"))
+ (void) pam_set_item(pamh, PAM_TTY, user_tty);
+
auth->data = (VOID *) pamh;
return(AUTH_SUCCESS);
}
@@ -96,17 +112,19 @@ pam_verify(pw, prompt, auth)
def_prompt = prompt; /* for sudo_conv */
- /* PAM_SILENT prevents error messages from going to syslog(3) */
- if ((error = pam_authenticate(pamh, PAM_SILENT)) == PAM_SUCCESS)
- return(AUTH_SUCCESS);
-
- /* Any error other than PAM_AUTH_ERR or PAM_MAXTRIES is probably fatal. */
- if (error != PAM_AUTH_ERR && error != PAM_MAXTRIES) {
- if ((s = pam_strerror(pamh, error)))
- log_error(NO_EXIT|NO_MAIL, "pam_authenticate: %s\n", s);
- return(AUTH_FATAL);
+ /* PAM_SILENT prevents the authentication service from generating output. */
+ error = pam_authenticate(pamh, PAM_SILENT);
+ switch (error) {
+ case PAM_SUCCESS:
+ return(AUTH_SUCCESS);
+ case PAM_AUTH_ERR:
+ case PAM_MAXTRIES:
+ return(AUTH_FAILURE);
+ default:
+ if ((s = pam_strerror(pamh, error)))
+ log_error(NO_EXIT|NO_MAIL, "pam_authenticate: %s", s);
+ return(AUTH_FATAL);
}
- return(AUTH_FAILURE);
}
int
@@ -115,13 +133,61 @@ pam_cleanup(pw, auth)
sudo_auth *auth;
{
pam_handle_t *pamh = (pam_handle_t *) auth->data;
+ int status = PAM_DATA_SILENT;
+
+ /* Convert AUTH_FOO -> PAM_FOO as best we can. */
+ /* XXX - store real value somewhere in auth->data and use it */
+ switch (auth->status) {
+ case AUTH_SUCCESS:
+ status |= PAM_SUCCESS;
+ break;
+ case AUTH_FAILURE:
+ status |= PAM_AUTH_ERR;
+ break;
+ case AUTH_FATAL:
+ default:
+ status |= PAM_ABORT;
+ break;
+ }
- if (pam_end(pamh, (auth->status == AUTH_SUCCESS)) == PAM_SUCCESS)
+ if (pam_end(pamh, status) == PAM_SUCCESS)
return(AUTH_SUCCESS);
else
return(AUTH_FAILURE);
}
+int
+pam_prep_user(pw)
+ struct passwd *pw;
+{
+ struct pam_conv pam_conv;
+ pam_handle_t *pamh;
+ const char *s;
+ int error;
+
+ /* We need to setup a new PAM session for the user we are changing *to*. */
+ pam_conv.conv = sudo_conv;
+ if (pam_start("sudo", pw->pw_name, &pam_conv, &pamh) != PAM_SUCCESS) {
+ log_error(USE_ERRNO|NO_EXIT|NO_MAIL,
+ "unable to initialize PAM");
+ return(AUTH_FATAL);
+ }
+ (void) pam_set_item(pamh, PAM_RUSER, user_name);
+ if (strcmp(user_tty, "unknown"))
+ (void) pam_set_item(pamh, PAM_TTY, user_tty);
+
+ /* Set credentials (may include resource limits, device ownership, etc). */
+ if ((error = pam_setcred(pamh, PAM_ESTABLISH_CRED)) != PAM_SUCCESS) {
+ if ((s = pam_strerror(pamh, error)))
+ log_error(NO_EXIT|NO_MAIL, "pam_setcred: %s", s);
+ }
+
+ if (pam_end(pamh, error) != PAM_SUCCESS)
+ return(AUTH_FAILURE);
+
+ return(error == PAM_SUCCESS ? AUTH_SUCCESS : AUTH_FAILURE);
+}
+
/*
* ``Conversation function'' for PAM.
*/
@@ -152,8 +218,8 @@ sudo_conv(num_msg, msg, response, appdata_ptr)
p = pm->msg;
/* Read the password. */
pr->resp = estrdup((char *) tgetpass(p,
- def_ival(I_PW_TIMEOUT) * 60, tgetpass_flags));
- if (*pr->resp == '\0')
+ def_ival(I_PASSWD_TIMEOUT) * 60, tgetpass_flags));
+ if (pr->resp == NULL || *pr->resp == '\0')
nil_pw = 1; /* empty password */
break;
case PAM_TEXT_INFO:
diff --git a/usr.bin/sudo/auth/passwd.c b/usr.bin/sudo/auth/passwd.c
index 9ec631dc4fd..92b6a3efa79 100644
--- a/usr.bin/sudo/auth/passwd.c
+++ b/usr.bin/sudo/auth/passwd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,34 +34,53 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include "sudo.h"
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: passwd.c,v 1.7 2000/03/23 00:27:41 millert Exp $";
+static const char rcsid[] = "$Sudo: passwd.c,v 1.9 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
#define DESLEN 13
#define HAS_AGEINFO(p, l) (l == 18 && p[DESLEN] == ',')
int
+passwd_init(pw, promptp, auth)
+ struct passwd *pw;
+ char **promptp;
+ sudo_auth *auth;
+{
+#ifdef HAVE_SKEYACCESS
+ if (skeyaccess(pw->pw_name, user_tty, NULL, NULL) == 0)
+ return(AUTH_FATAL);
+#endif
+ return(AUTH_SUCCESS);
+}
+
+int
passwd_verify(pw, pass, auth)
struct passwd *pw;
char *pass;
diff --git a/usr.bin/sudo/auth/rfc1938.c b/usr.bin/sudo/auth/rfc1938.c
index bad20d24dca..0ad125d48d3 100644
--- a/usr.bin/sudo/auth/rfc1938.c
+++ b/usr.bin/sudo/auth/rfc1938.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 1994-1996,1998-1999 Todd C. Miller <Todd.Miller@courtesan.com>
- * All rights reserved.
+ * Copyright (c) 1994-1996, 1998-1999, 2001
+ * Todd C. Miller <Todd.Miller@courtesan.com>. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -34,21 +34,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#if defined(HAVE_SKEY)
@@ -67,7 +73,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: rfc1938.c,v 1.8 1999/10/07 21:21:07 millert Exp $";
+static const char rcsid[] = "$Sudo: rfc1938.c,v 1.9 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
int
diff --git a/usr.bin/sudo/auth/secureware.c b/usr.bin/sudo/auth/secureware.c
index ddba29fbc9b..4ed7297d6aa 100644
--- a/usr.bin/sudo/auth/secureware.c
+++ b/usr.bin/sudo/auth/secureware.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1998, 1999, 2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,21 +34,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#ifdef __hpux
# undef MAXINT
@@ -62,7 +68,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: secureware.c,v 1.7 1999/08/22 09:59:28 millert Exp $";
+static const char rcsid[] = "$Sudo: secureware.c,v 1.8 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
int
diff --git a/usr.bin/sudo/auth/securid.c b/usr.bin/sudo/auth/securid.c
index 987862289cd..9da4d5e4e48 100644
--- a/usr.bin/sudo/auth/securid.c
+++ b/usr.bin/sudo/auth/securid.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* This code is derived from software contributed by Giles Todd
@@ -37,21 +37,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <sdi_athd.h>
@@ -62,7 +68,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: securid.c,v 1.6 1999/12/02 20:21:31 millert Exp $";
+static const char rcsid[] = "$Sudo: securid.c,v 1.8 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
union config_record configure;
@@ -76,8 +82,11 @@ securid_init(pw, promptp, auth)
static struct SD_CLIENT sd_dat; /* SecurID data block */
auth->data = (VOID *) &sd_dat; /* For method-specific data */
- creadcfg(); /* Only read config file once */
- return(AUTH_SUCCESS);
+
+ if (creadcfg() == 0)
+ return(AUTH_SUCCESS);
+ else
+ return(AUTH_FATAL);
}
int
@@ -89,9 +98,10 @@ securid_setup(pw, promptp, auth)
struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
/* Re-initialize SecurID every time. */
- if (sd_init(sd) == 0)
+ if (sd_init(sd) == 0) {
+ strcpy(sd->username, pw->pw_name);
return(AUTH_SUCCESS);
- else {
+ } else {
(void) fprintf(stderr, "%s: Cannot contact SecurID server\n", Argv[0]);
return(AUTH_FATAL);
}
@@ -104,8 +114,11 @@ securid_verify(pw, pass, auth)
sudo_auth *auth;
{
struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
+ int rval;
- if (sd_auth(sd) == ACM_OK)
+ rval = sd_auth(sd);
+ sd_close();
+ if (rval == ACM_OK)
return(AUTH_SUCCESS);
else
return(AUTH_FAILURE);
diff --git a/usr.bin/sudo/auth/sia.c b/usr.bin/sudo/auth/sia.c
index d41263c9603..09b67e21e7e 100644
--- a/usr.bin/sudo/auth/sia.c
+++ b/usr.bin/sudo/auth/sia.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* This code is derived from software contributed by Spider Boardman
@@ -36,21 +36,27 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <siad.h>
@@ -58,7 +64,7 @@
#include "sudo_auth.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: sia.c,v 1.8 1999/10/07 21:21:07 millert Exp $";
+static const char rcsid[] = "$Sudo: sia.c,v 1.10 2001/12/14 19:52:53 millert Exp $";
#endif /* lint */
static int sudo_collect __P((int, int, uchar_t *, int, prompt_t *));
@@ -80,8 +86,8 @@ sudo_collect(timeout, rendition, title, nprompts, prompts)
switch (rendition) {
case SIAFORM:
case SIAONELINER:
- if (timeout <= 0 || timeout > def_ival(I_PW_TIMEOUT) * 60)
- timeout = def_ival(I_PW_TIMEOUT) * 60;
+ if (timeout <= 0 || timeout > def_ival(I_PASSWD_TIMEOUT) * 60)
+ timeout = def_ival(I_PASSWD_TIMEOUT) * 60;
/*
* Substitute custom prompt if a) the sudo prompt is not "Password:"
* and b) the SIA prompt is "Password:" (so we know it is safe).
diff --git a/usr.bin/sudo/auth/sudo_auth.c b/usr.bin/sudo/auth/sudo_auth.c
index 8e62c01bd6d..eb4c3c4f9a9 100644
--- a/usr.bin/sudo/auth/sudo_auth.c
+++ b/usr.bin/sudo/auth/sudo_auth.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -34,30 +34,40 @@
#include "config.h"
+#include <sys/types.h>
+#include <sys/param.h>
#include <stdio.h>
#ifdef STDC_HEADERS
-#include <stdlib.h>
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+# endif
#endif /* STDC_HEADERS */
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#ifdef HAVE_STRING_H
-#include <string.h>
+# if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
+# include <memory.h>
+# endif
+# include <string.h>
+#else
+# ifdef HAVE_STRINGS_H
+# include <strings.h>
+# endif
#endif /* HAVE_STRING_H */
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif /* HAVE_STRINGS_H */
-#include <sys/param.h>
-#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif /* HAVE_UNISTD_H */
#include <pwd.h>
#include <time.h>
+#include <signal.h>
#include "sudo.h"
#include "sudo_auth.h"
#include "insults.h"
#ifndef lint
-static const char rcsid[] = "$Sudo: sudo_auth.c,v 1.19 2000/03/06 19:42:21 millert Exp $";
+static const char rcsid[] = "$Sudo: sudo_auth.c,v 1.25 2001/12/14 19:52:54 millert Exp $";
#endif /* lint */
sudo_auth auth_switch[] = {
@@ -65,7 +75,7 @@ sudo_auth auth_switch[] = {
AUTH_STANDALONE
#else
# ifndef WITHOUT_PASSWD
- AUTH_ENTRY(0, "passwd", NULL, NULL, passwd_verify, NULL)
+ AUTH_ENTRY(0, "passwd", passwd_init, NULL, passwd_verify, NULL)
# endif
# if defined(HAVE_GETPRPWNAM) && !defined(WITHOUT_PASSWD)
AUTH_ENTRY(0, "secureware", secureware_init, NULL, secureware_verify, NULL)
@@ -99,11 +109,19 @@ verify_user(pw, prompt)
struct passwd *pw;
char *prompt;
{
- short counter = def_ival(I_PW_TRIES) + 1;
- short success = AUTH_FAILURE;
- short status;
+ int counter = def_ival(I_PASSWD_TRIES) + 1;
+ int success = AUTH_FAILURE;
+ int status;
+ int flags;
char *p;
sudo_auth *auth;
+ sigaction_t sa, osa;
+
+ /* Enable suspend during password entry. */
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESTART;
+ sa.sa_handler = SIG_DFL;
+ (void) sigaction(SIGTSTP, &sa, &osa);
/* Make sure we have at least one auth method. */
if (auth_switch[0].name == NULL)
@@ -156,14 +174,14 @@ verify_user(pw, prompt)
#ifdef AUTH_STANDALONE
p = prompt;
#else
- p = (char *) tgetpass(prompt, def_ival(I_PW_TIMEOUT) * 60,
+ p = (char *) tgetpass(prompt, def_ival(I_PASSWD_TIMEOUT) * 60,
tgetpass_flags);
if (!p || *p == '\0')
nil_pw = 1;
#endif /* AUTH_STANDALONE */
/* Call authentication functions. */
- for (auth = auth_switch; auth->name; auth++) {
+ for (auth = auth_switch; p && auth->name; auth++) {
if (!IS_CONFIGURED(auth))
continue;
@@ -179,12 +197,13 @@ verify_user(pw, prompt)
goto cleanup;
}
#ifndef AUTH_STANDALONE
- (void) memset(p, 0, strlen(p));
+ if (p)
+ (void) memset(p, 0, strlen(p));
#endif
/* Exit loop on nil password, but give it a chance to match first. */
if (nil_pw) {
- if (counter == def_ival(I_PW_TRIES))
+ if (counter == def_ival(I_PASSWD_TRIES))
exit(1);
else
break;
@@ -211,14 +230,20 @@ cleanup:
switch (success) {
case AUTH_SUCCESS:
+ (void) sigaction(SIGTSTP, &osa, NULL);
return;
case AUTH_FAILURE:
- log_error(NO_MAIL, "%d incorrect password attempt%s",
- def_ival(I_PW_TRIES) - counter,
- (def_ival(I_PW_TRIES) - counter == 1) ? "" : "s");
+ if (def_flag(I_MAIL_BADPASS) || def_flag(I_MAIL_ALWAYS))
+ flags = 0;
+ else
+ flags = NO_MAIL;
+ log_error(flags, "%d incorrect password attempt%s",
+ def_ival(I_PASSWD_TRIES) - counter,
+ (def_ival(I_PASSWD_TRIES) - counter == 1) ? "" : "s");
case AUTH_FATAL:
exit(1);
}
+ /* NOTREACHED */
}
void
@@ -231,7 +256,7 @@ pass_warn(fp)
(void) fprintf(fp, "%s\n", INSULT);
else
#endif
- (void) fprintf(fp, "%s\n", def_str(I_BADPASS_MSG));
+ (void) fprintf(fp, "%s\n", def_str(I_BADPASS_MESSAGE));
}
void
diff --git a/usr.bin/sudo/auth/sudo_auth.h b/usr.bin/sudo/auth/sudo_auth.h
index 5e08ecc1489..f2db87de4d7 100644
--- a/usr.bin/sudo/auth/sudo_auth.h
+++ b/usr.bin/sudo/auth/sudo_auth.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Todd C. Miller <Todd.Miller@courtesan.com>
+ * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,7 +31,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Sudo: sudo_auth.h,v 1.17 2000/10/29 22:30:22 millert Exp $
+ * $Sudo: sudo_auth.h,v 1.19 2001/12/14 19:55:01 millert Exp $
*/
#ifndef SUDO_AUTH_H
@@ -80,6 +80,7 @@ int bsdauth_verify __P((struct passwd *pw, char *prompt, sudo_auth *auth));
int bsdauth_cleanup __P((struct passwd *pw, sudo_auth *auth));
/* Prototypes for normal methods */
+int passwd_init __P((struct passwd *pw, char **prompt, sudo_auth *auth));
int passwd_verify __P((struct passwd *pw, char *pass, sudo_auth *auth));
int secureware_init __P((struct passwd *pw, char **prompt, sudo_auth *auth));
int secureware_verify __P((struct passwd *pw, char *pass, sudo_auth *auth));