]> git.gag.com Git - debian/sudo/blob - auth/sia.c
Imported Upstream version 1.6.6
[debian/sudo] / auth / sia.c
1 /*
2  * Copyright (c) 1999-2001 Todd C. Miller <Todd.Miller@courtesan.com>
3  * All rights reserved.
4  *
5  * This code is derived from software contributed by Spider Boardman
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * 4. Products derived from this software may not be called "Sudo" nor
22  *    may "Sudo" appear in their names without specific prior written
23  *    permission from the author.
24  *
25  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
26  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
27  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
28  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
31  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
33  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  */
36
37 #include "config.h"
38
39 #include <sys/types.h>
40 #include <sys/param.h>
41 #include <stdio.h>
42 #ifdef STDC_HEADERS
43 # include <stdlib.h>
44 # include <stddef.h>
45 #else
46 # ifdef HAVE_STDLIB_H
47 #  include <stdlib.h>
48 # endif
49 #endif /* STDC_HEADERS */
50 #ifdef HAVE_STRING_H
51 # include <string.h>
52 #else
53 # ifdef HAVE_STRINGS_H
54 #  include <strings.h>
55 # endif
56 #endif /* HAVE_STRING_H */
57 #ifdef HAVE_UNISTD_H
58 # include <unistd.h>
59 #endif /* HAVE_UNISTD_H */
60 #include <pwd.h>
61 #include <siad.h>
62
63 #include "sudo.h"
64 #include "sudo_auth.h"
65
66 #ifndef lint
67 static const char rcsid[] = "$Sudo: sia.c,v 1.10 2001/12/14 19:52:53 millert Exp $";
68 #endif /* lint */
69
70 static int sudo_collect __P((int, int, uchar_t *, int, prompt_t *));
71
72 static char *def_prompt;
73
74 /*
75  * Collection routine (callback) for limiting the timeouts in SIA
76  * prompts and (possibly) setting a custom prompt.
77  */
78 static int
79 sudo_collect(timeout, rendition, title, nprompts, prompts)
80     int timeout;
81     int rendition;
82     uchar_t *title;
83     int nprompts;
84     prompt_t *prompts;
85 {
86     switch (rendition) {
87         case SIAFORM:
88         case SIAONELINER:
89             if (timeout <= 0 || timeout > def_ival(I_PASSWD_TIMEOUT) * 60)
90                 timeout = def_ival(I_PASSWD_TIMEOUT) * 60;
91             /*
92              * Substitute custom prompt if a) the sudo prompt is not "Password:"
93              * and b) the SIA prompt is "Password:" (so we know it is safe).
94              * This keeps us from overwriting things like S/Key challenges.
95              */
96             if (strcmp((char *)prompts[0].prompt, "Password:") == 0 &&
97                 strcmp(def_prompt, "Password:") != 0)
98                 prompts[0].prompt = (unsigned char *)def_prompt;
99             break;
100         default:
101             break;
102     }
103
104     return sia_collect_trm(timeout, rendition, title, nprompts, prompts);
105 }
106
107 int
108 sia_setup(pw, promptp, auth)
109     struct passwd *pw;
110     char **promptp;
111     sudo_auth *auth;
112 {
113     SIAENTITY *siah = NULL;
114
115     if (sia_ses_init(&siah, Argc, Argv, NULL, pw->pw_name, ttyname(0), 1, NULL)
116         != SIASUCCESS) {
117
118         log_error(USE_ERRNO|NO_EXIT|NO_MAIL,
119             "unable to initialize SIA session");
120         return(AUTH_FATAL);
121     }
122
123     auth->data = (VOID *) siah;
124     return(AUTH_SUCCESS);
125 }
126
127 int
128 sia_verify(pw, prompt, auth)
129     struct passwd *pw;
130     char *prompt;
131     sudo_auth *auth;
132 {
133     SIAENTITY *siah = (SIAENTITY *) auth->data;
134
135     def_prompt = prompt;                /* for sudo_collect */
136
137     /* XXX - need a way to detect user hitting return or EOF at prompt */
138     if (sia_ses_reauthent(sudo_collect, siah) == SIASUCCESS)
139         return(AUTH_SUCCESS);
140     else
141         return(AUTH_FAILURE);
142 }
143
144 int
145 sia_cleanup(pw, auth)
146     struct passwd *pw;
147     sudo_auth *auth;
148 {
149     SIAENTITY *siah = (SIAENTITY *) auth->data;
150
151     (void) sia_ses_release(&siah);
152     return(AUTH_SUCCESS);
153 }