2 * Copyright (c) 1999-2005, 2007, 2010-2012, 2014-2016
3 * Todd C. Miller <Todd.Miller@sudo.ws>
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.
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.
24 * This is an open source non-commercial project. Dear PVS-Studio, please check it.
25 * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
32 #include <sys/types.h>
37 #endif /* HAVE_STRING_H */
40 #endif /* HAVE_STRINGS_H */
44 /* Needed for SecurID v5.0 Authentication on UNIX */
50 #include "sudo_auth.h"
53 * securid_init - Initialises communications with ACE server
56 * auth - sudo authentication structure
59 * auth - auth->data contains pointer to new SecurID handle
60 * return code - Fatal if initialization unsuccessful, otherwise
64 sudo_securid_init(struct passwd *pw, sudo_auth *auth)
66 static SDI_HANDLE sd_dat; /* SecurID handle */
67 debug_decl(sudo_securid_init, SUDOERS_DEBUG_AUTH)
69 auth->data = (void *) &sd_dat; /* For method-specific data */
71 /* Start communications */
72 if (AceInitialize() != SD_FALSE)
73 debug_return_int(AUTH_SUCCESS);
75 sudo_warnx(U_("failed to initialise the ACE API library"));
76 debug_return_int(AUTH_FATAL);
80 * securid_setup - Initialises a SecurID transaction and locks out other
84 * pw - struct passwd for username
86 * auth - sudo authentication structure for SecurID handle
89 * return code - Success if transaction started correctly, fatal
93 sudo_securid_setup(struct passwd *pw, char **promptp, sudo_auth *auth)
95 SDI_HANDLE *sd = (SDI_HANDLE *) auth->data;
97 debug_decl(sudo_securid_setup, SUDOERS_DEBUG_AUTH)
99 /* Re-initialize SecurID every time. */
100 if (SD_Init(sd) != ACM_OK) {
101 sudo_warnx(U_("unable to contact the SecurID server"));
102 debug_return_int(AUTH_FATAL);
105 /* Lock new PIN code */
106 retval = SD_Lock(*sd, pw->pw_name);
110 sudo_warnx(U_("User ID locked for SecurID Authentication"));
111 debug_return_int(AUTH_SUCCESS);
113 case ACE_UNDEFINED_USERNAME:
114 sudo_warnx(U_("invalid username length for SecurID"));
115 debug_return_int(AUTH_FATAL);
117 case ACE_ERR_INVALID_HANDLE:
118 sudo_warnx(U_("invalid Authentication Handle for SecurID"));
119 debug_return_int(AUTH_FATAL);
121 case ACM_ACCESS_DENIED:
122 sudo_warnx(U_("SecurID communication failed"));
123 debug_return_int(AUTH_FATAL);
126 sudo_warnx(U_("unknown SecurID error"));
127 debug_return_int(AUTH_FATAL);
132 * securid_verify - Authenticates user and handles ACE responses
135 * pw - struct passwd for username
137 * auth - sudo authentication structure for SecurID handle
140 * return code - Success on successful authentication, failure on
141 * incorrect authentication, fatal on errors
144 sudo_securid_verify(struct passwd *pw, char *pass, sudo_auth *auth, struct sudo_conv_callback *callback)
146 SDI_HANDLE *sd = (SDI_HANDLE *) auth->data;
148 debug_decl(sudo_securid_verify, SUDOERS_DEBUG_AUTH)
150 pass = auth_getpass("Enter your PASSCODE: ", SUDO_CONV_PROMPT_ECHO_OFF,
153 /* Have ACE verify password */
154 switch (SD_Check(*sd, pass, pw->pw_name)) {
159 case ACE_UNDEFINED_PASSCODE:
160 sudo_warnx(U_("invalid passcode length for SecurID"));
164 case ACE_UNDEFINED_USERNAME:
165 sudo_warnx(U_("invalid username length for SecurID"));
169 case ACE_ERR_INVALID_HANDLE:
170 sudo_warnx(U_("invalid Authentication Handle for SecurID"));
174 case ACM_ACCESS_DENIED:
178 case ACM_NEXT_CODE_REQUIRED:
179 /* Sometimes (when current token close to expire?)
180 ACE challenges for the next token displayed
181 (entered without the PIN) */
183 memset_s(pass, SUDO_PASS_MAX, 0, strlen(pass));
186 pass = auth_getpass("\
188 Wait for the token code to change, \n\
189 then enter the new token code.\n", \
190 SUDO_CONV_PROMPT_ECHO_OFF, callback);
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 sudo_printf(SUDO_CONV_ERROR_MSG,
208 "Your SecurID access has not yet been set up.\n");
209 sudo_printf(SUDO_CONV_ERROR_MSG,
210 "Please set up a PIN before you try to authenticate.\n");
215 sudo_warnx(U_("unknown SecurID error"));
224 memset_s(pass, SUDO_PASS_MAX, 0, strlen(pass));
228 /* Return stored state to calling process */
229 debug_return_int(ret);
232 #endif /* HAVE_SECURID */