1 /*
2 * Copyright (c) 1999-2001, 2003 Todd C. Miller <Todd.Miller@courtesan.com>
3 *
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.
7 *
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 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
16 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
17 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
18 *
19 * Sponsored in part by the Defense Advanced Research Projects
20 * Agency (DARPA) and Air Force Research Laboratory, Air Force
21 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
22 */
23
24 #include "config.h"
25
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <stdio.h>
29 #ifdef STDC_HEADERS
30 # include <stdlib.h>
31 # include <stddef.h>
32 #else
33 # ifdef HAVE_STDLIB_H
34 # include <stdlib.h>
35 # endif
36 #endif /* STDC_HEADERS */
37 #ifdef HAVE_STRING_H
38 # include <string.h>
39 #else
40 # ifdef HAVE_STRINGS_H
41 # include <strings.h>
42 # endif
43 #endif /* HAVE_STRING_H */
44 #ifdef HAVE_UNISTD_H
45 # include <unistd.h>
46 #endif /* HAVE_UNISTD_H */
47 #ifdef HAVE_ERR_H
48 # include <err.h>
49 #else
50 # include "emul/err.h"
51 #endif /* HAVE_ERR_H */
52 #include <pwd.h>
53
54 #include <sdi_athd.h>
55 #include <sdconf.h>
56 #include <sdacmvls.h>
57
58 #include "sudo.h"
59 #include "sudo_auth.h"
60
61 #ifndef lint
62 static const char rcsid[] = "$Sudo: securid.c,v 1.12 2004/02/13 21:36:47 millert Exp $";
63 #endif /* lint */
64
65 union config_record configure;
66
67 int
securid_init(pw,promptp,auth)68 securid_init(pw, promptp, auth)
69 struct passwd *pw;
70 char **promptp;
71 sudo_auth *auth;
72 {
73 static struct SD_CLIENT sd_dat; /* SecurID data block */
74
75 auth->data = (VOID *) &sd_dat; /* For method-specific data */
76
77 if (creadcfg() == 0)
78 return(AUTH_SUCCESS);
79 else
80 return(AUTH_FATAL);
81 }
82
83 int
securid_setup(pw,promptp,auth)84 securid_setup(pw, promptp, auth)
85 struct passwd *pw;
86 char **promptp;
87 sudo_auth *auth;
88 {
89 struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
90
91 /* Re-initialize SecurID every time. */
92 if (sd_init(sd) == 0) {
93 /* The programmer's guide says username is 32 bytes */
94 strlcpy(sd->username, pw->pw_name, 32);
95 return(AUTH_SUCCESS);
96 } else {
97 warnx("unable to contact the SecurID server");
98 return(AUTH_FATAL);
99 }
100 }
101
102 int
securid_verify(pw,pass,auth)103 securid_verify(pw, pass, auth)
104 struct passwd *pw;
105 char *pass;
106 sudo_auth *auth;
107 {
108 struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
109 int rval;
110
111 rval = sd_auth(sd);
112 sd_close();
113 if (rval == ACM_OK)
114 return(AUTH_SUCCESS);
115 else
116 return(AUTH_FAILURE);
117 }
118