2 * Copyright (c) 1999-2005, 2007, 2010-2011
3 * Todd C. Miller <Todd.Miller@courtesan.com>
4 * Copyright (c) 2002 Michael Stroucken <michael@stroucken.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
19 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 * Sponsored in part by the Defense Advanced Research Projects
22 * Agency (DARPA) and Air Force Research Laboratory, Air Force
23 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
28 #include <sys/types.h>
29 #include <sys/param.h>
38 #endif /* STDC_HEADERS */
41 #endif /* HAVE_STRING_H */
44 #endif /* HAVE_STRINGS_H */
47 #endif /* HAVE_UNISTD_H */
50 /* Needed for SecurID v5.0 Authentication on UNIX */
56 #include "sudo_auth.h"
59 * securid_init - Initialises communications with ACE server
63 * auth - sudo authentication structure
66 * auth - auth->data contains pointer to new SecurID handle
67 * return code - Fatal if initialization unsuccessful, otherwise
71 securid_init(struct passwd *pw, char **promptp, sudo_auth *auth)
73 static SDI_HANDLE sd_dat; /* SecurID handle */
75 auth->data = (void *) &sd_dat; /* For method-specific data */
77 /* Start communications */
78 if (AceInitialize() != SD_FALSE)
81 warningx(_("failed to initialise the ACE API library"));
86 * securid_setup - Initialises a SecurID transaction and locks out other
90 * pw - struct passwd for username
92 * auth - sudo authentication structure for SecurID handle
95 * return code - Success if transaction started correctly, fatal
99 securid_setup(struct passwd *pw, char **promptp, sudo_auth *auth)
101 SDI_HANDLE *sd = (SDI_HANDLE *) auth->data;
104 /* Re-initialize SecurID every time. */
105 if (SD_Init(sd) != ACM_OK) {
106 warningx(_("unable to contact the SecurID server"));
110 /* Lock new PIN code */
111 retval = SD_Lock(*sd, pw->pw_name);
115 warningx(_("User ID locked for SecurID Authentication"));
118 case ACE_UNDEFINED_USERNAME:
119 warningx(_("invalid username length for SecurID"));
122 case ACE_ERR_INVALID_HANDLE:
123 warningx(_("invalid Authentication Handle for SecurID"));
126 case ACM_ACCESS_DENIED:
127 warningx(_("SecurID communication failed"));
131 warningx(_("unknown SecurID error"));
137 * securid_verify - Authenticates user and handles ACE responses
140 * pw - struct passwd for username
142 * auth - sudo authentication structure for SecurID handle
145 * return code - Success on successful authentication, failure on
146 * incorrect authentication, fatal on errors
149 securid_verify(struct passwd *pw, char *pass, sudo_auth *auth)
151 SDI_HANDLE *sd = (SDI_HANDLE *) auth->data;
154 pass = auth_getpass("Enter your PASSCODE: ",
155 def_passwd_timeout * 60, SUDO_CONV_PROMPT_ECHO_OFF);
157 /* Have ACE verify password */
158 switch (SD_Check(*sd, pass, pw->pw_name)) {
163 case ACE_UNDEFINED_PASSCODE:
164 warningx(_("invalid passcode length for SecurID"));
168 case ACE_UNDEFINED_USERNAME:
169 warningx(_("invalid username length for SecurID"));
173 case ACE_ERR_INVALID_HANDLE:
174 warningx(_("invalid Authentication Handle for SecurID"));
178 case ACM_ACCESS_DENIED:
182 case ACM_NEXT_CODE_REQUIRED:
183 /* Sometimes (when current token close to expire?)
184 ACE challenges for the next token displayed
185 (entered without the PIN) */
186 pass = auth_getpass("\
188 Wait for the token code to change, \n\
189 then enter the new token code.\n", \
190 def_passwd_timeout * 60, SUDO_CONV_PROMPT_ECHO_OFF);
192 if (SD_Next(*sd, pass) == ACM_OK) {
200 case ACM_NEW_PIN_REQUIRED:
202 * This user's SecurID has not been activated yet,
203 * or the pin has been reset
205 /* XXX - Is setting up a new PIN within sudo's scope? */
207 fprintf(stderr, "Your SecurID access has not yet been set up.\n");
208 fprintf(stderr, "Please set up a PIN before you try to authenticate.\n");
213 warningx(_("unknown SecurID error"));
221 /* Return stored state to calling process */