Imported Upstream version 1.7.4p6
[debian/sudo] / auth / securid.c
1 /*
2  * Copyright (c) 1999-2005, 2007, 2010
3  *      Todd C. Miller <Todd.Miller@courtesan.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
17  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
18  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19  *
20  * Sponsored in part by the Defense Advanced Research Projects
21  * Agency (DARPA) and Air Force Research Laboratory, Air Force
22  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
23  */
24
25 #include <config.h>
26
27 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <stdio.h>
30 #ifdef STDC_HEADERS
31 # include <stdlib.h>
32 # include <stddef.h>
33 #else
34 # ifdef HAVE_STDLIB_H
35 #  include <stdlib.h>
36 # endif
37 #endif /* STDC_HEADERS */
38 #ifdef HAVE_STRING_H
39 # include <string.h>
40 #endif /* HAVE_STRING_H */
41 #ifdef HAVE_STRINGS_H
42 # include <strings.h>
43 #endif /* HAVE_STRINGS_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 union config_record configure;
57
58 int
59 securid_init(pw, promptp, auth)
60     struct passwd *pw;
61     char **promptp;
62     sudo_auth *auth;
63 {
64     static struct SD_CLIENT sd_dat;             /* SecurID data block */
65
66     auth->data = (void *) &sd_dat;              /* For method-specific data */
67
68     if (creadcfg() == 0)
69         return(AUTH_SUCCESS);
70     else
71         return(AUTH_FATAL);
72 }
73
74 int
75 securid_setup(pw, promptp, auth)
76     struct passwd *pw;
77     char **promptp;
78     sudo_auth *auth;
79 {
80     struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
81
82     /* Re-initialize SecurID every time. */
83     if (sd_init(sd) == 0) {
84         /* The programmer's guide says username is 32 bytes */
85         strlcpy(sd->username, pw->pw_name, 32);
86         return(AUTH_SUCCESS);
87     } else {
88         warningx("unable to contact the SecurID server");
89         return(AUTH_FATAL);
90     }
91 }
92
93 int
94 securid_verify(pw, pass, auth)
95     struct passwd *pw;
96     char *pass;
97     sudo_auth *auth;
98 {
99     struct SD_CLIENT *sd = (struct SD_CLIENT *) auth->data;
100     int rval;
101
102     rval = sd_auth(sd);
103     sd_close();
104     if (rval == ACM_OK)
105         return(AUTH_SUCCESS);
106     else
107         return(AUTH_FAILURE);
108 }