2 * Copyright (c) 1999-2005 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
16 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 * Sponsored in part by the Defense Advanced Research Projects
19 * Agency (DARPA) and Air Force Research Laboratory, Air Force
20 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
25 #include <sys/types.h>
26 #include <sys/param.h>
35 #endif /* STDC_HEADERS */
39 # ifdef HAVE_STRINGS_H
42 #endif /* HAVE_STRING_H */
45 #endif /* HAVE_UNISTD_H */
50 #include "sudo_auth.h"
53 __unused static const char rcsid[] = "$Sudo: sia.c,v 1.14.2.2 2007/06/12 01:28:42 millert Exp $";
56 static int sudo_collect __P((int, int, uchar_t *, int, prompt_t *));
58 static char *def_prompt;
61 * Collection routine (callback) for limiting the timeouts in SIA
62 * prompts and (possibly) setting a custom prompt.
65 sudo_collect(timeout, rendition, title, nprompts, prompts)
75 if (timeout <= 0 || timeout > def_passwd_timeout * 60)
76 timeout = def_passwd_timeout * 60;
78 * Substitute custom prompt if a) the sudo prompt is not "Password:"
79 * and b) the SIA prompt is "Password:" (so we know it is safe).
80 * This keeps us from overwriting things like S/Key challenges.
82 if (strcmp((char *)prompts[0].prompt, "Password:") == 0 &&
83 strcmp(def_prompt, "Password:") != 0)
84 prompts[0].prompt = (unsigned char *)def_prompt;
90 return sia_collect_trm(timeout, rendition, title, nprompts, prompts);
94 sia_setup(pw, promptp, auth)
99 SIAENTITY *siah = NULL;
103 if (sia_ses_init(&siah, Argc, Argv, NULL, pw->pw_name, ttyname(0), 1, NULL)
106 log_error(USE_ERRNO|NO_EXIT|NO_MAIL,
107 "unable to initialize SIA session");
111 auth->data = (VOID *) siah;
112 return(AUTH_SUCCESS);
116 sia_verify(pw, prompt, auth)
121 SIAENTITY *siah = (SIAENTITY *) auth->data;
123 def_prompt = prompt; /* for sudo_collect */
125 /* XXX - need a way to detect user hitting return or EOF at prompt */
126 if (sia_ses_reauthent(sudo_collect, siah) == SIASUCCESS)
127 return(AUTH_SUCCESS);
129 return(AUTH_FAILURE);
133 sia_cleanup(pw, auth)
137 SIAENTITY *siah = (SIAENTITY *) auth->data;
139 (void) sia_ses_release(&siah);
140 return(AUTH_SUCCESS);