Imported Upstream version 1.7.0
[debian/sudo] / auth / securid.c
1 /*
2  * Copyright (c) 1999-2005, 2007 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 #include <pwd.h>
48
49 #include <sdi_athd.h>
50 #include <sdconf.h>
51 #include <sdacmvls.h>
52
53 #include "sudo.h"
54 #include "sudo_auth.h"
55
56 #ifndef lint
57 __unused static const char rcsid[] = "$Sudo: securid.c,v 1.18 2008/11/09 14:13:13 millert Exp $";
58 #endif /* lint */
59
60 union config_record configure;
61
62 int
63 securid_init(pw, promptp, auth)
64     struct passwd *pw;
65     char **promptp;
66     sudo_auth *auth;
67 {
68     static struct SD_CLIENT sd_dat;             /* SecurID data block */
69
70     auth->data = (void *) &sd_dat;              /* For method-specific data */
71
72     if (creadcfg() == 0)
73         return(AUTH_SUCCESS);
74     else
75         return(AUTH_FATAL);
76 }
77
78 int
79 securid_setup(pw, promptp, auth)
80     struct passwd *pw;
81     char **promptp;
82     sudo_auth *auth;
83 {
84     struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
85
86     /* Re-initialize SecurID every time. */
87     if (sd_init(sd) == 0) {
88         /* The programmer's guide says username is 32 bytes */
89         strlcpy(sd->username, pw->pw_name, 32);
90         return(AUTH_SUCCESS);
91     } else {
92         warningx("unable to contact the SecurID server");
93         return(AUTH_FATAL);
94     }
95 }
96
97 int
98 securid_verify(pw, pass, auth)
99     struct passwd *pw;
100     char *pass;
101     sudo_auth *auth;
102 {
103     struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
104     int rval;
105
106     rval = sd_auth(sd);
107     sd_close();
108     if (rval == ACM_OK)
109         return(AUTH_SUCCESS);
110     else
111         return(AUTH_FAILURE);
112 }