Imported Upstream version 1.6.6
[debian/sudo] / auth / securid.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 Giles Todd
6  * <giles@gt.demon.co.uk>.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * 3. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * 4. Products derived from this software may not be called "Sudo" nor
23  *    may "Sudo" appear in their names without specific prior written
24  *    permission from the author.
25  *
26  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
27  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
29  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37
38 #include "config.h"
39
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <stdio.h>
43 #ifdef STDC_HEADERS
44 # include <stdlib.h>
45 # include <stddef.h>
46 #else
47 # ifdef HAVE_STDLIB_H
48 #  include <stdlib.h>
49 # endif
50 #endif /* STDC_HEADERS */
51 #ifdef HAVE_STRING_H
52 # include <string.h>
53 #else
54 # ifdef HAVE_STRINGS_H
55 #  include <strings.h>
56 # endif
57 #endif /* HAVE_STRING_H */
58 #ifdef HAVE_UNISTD_H
59 # include <unistd.h>
60 #endif /* HAVE_UNISTD_H */
61 #include <pwd.h>
62
63 #include <sdi_athd.h>
64 #include <sdconf.h>
65 #include <sdacmvls.h>
66
67 #include "sudo.h"
68 #include "sudo_auth.h"
69
70 #ifndef lint
71 static const char rcsid[] = "$Sudo: securid.c,v 1.8 2001/12/14 19:52:53 millert Exp $";
72 #endif /* lint */
73
74 union config_record configure;
75
76 int
77 securid_init(pw, promptp, auth)
78     struct passwd *pw;
79     char **promptp;
80     sudo_auth *auth;
81 {
82     static struct SD_CLIENT sd_dat;             /* SecurID data block */
83
84     auth->data = (VOID *) &sd_dat;              /* For method-specific data */
85
86     if (creadcfg() == 0)
87         return(AUTH_SUCCESS);
88     else
89         return(AUTH_FATAL);
90 }
91
92 int
93 securid_setup(pw, promptp, auth)
94     struct passwd *pw;
95     char **promptp;
96     sudo_auth *auth;
97 {
98     struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
99
100     /* Re-initialize SecurID every time. */
101     if (sd_init(sd) == 0) {
102         strcpy(sd->username, pw->pw_name);
103         return(AUTH_SUCCESS);
104     } else {
105         (void) fprintf(stderr, "%s: Cannot contact SecurID server\n", Argv[0]);
106         return(AUTH_FATAL);
107     }
108 }
109
110 int
111 securid_verify(pw, pass, auth)
112     struct passwd *pw;
113     char *pass;
114     sudo_auth *auth;
115 {
116     struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
117     int rval;
118
119     rval = sd_auth(sd);
120     sd_close();
121     if (rval == ACM_OK)
122         return(AUTH_SUCCESS);
123     else
124         return(AUTH_FAILURE);
125 }