]> andersk Git - moira.git/blob - update/auth_001.c
Initial revision
[moira.git] / update / auth_001.c
1 /*
2  *      $Source$
3  *      $Header$
4  */
5
6 #ifndef lint
7 static char *rcsid_auth_001_c = "$Header$";
8 #endif  lint
9
10 #include <stdio.h>
11 #include <strings.h>
12 #include "gdb.h"
13 #include "smsu_int.h"
14 #include "kludge.h"
15 #include <krb.h>
16 #include <netinet/in.h>
17 #include <errno.h>
18
19 extern char buf[BUFSIZ];
20 extern int have_authorization;
21 extern struct sockaddr_in *client_address();
22 extern CONNECTION conn;
23 int code;
24 extern char *PrincipalHostname();
25 static char sms[] = "sms";
26 static char qmark[] = "???";
27
28 /*
29  * authentication request auth_001:
30  *
31  * >>> (STRING) "auth_001"
32  * <<< (int) 0
33  * >>> (STRING) ticket
34  * <<< (int) code
35  *
36  */
37
38 int
39 auth_001(str)
40      char *str;
41 {
42     STRING data;
43     char host[BUFSIZ];
44     AUTH_DAT ad;
45     char realm[REALM_SZ];
46     KTEXT_ST ticket_st;
47
48     if (send_ok())
49         lose("sending okay for authorization (auth_001)");
50     code = receive_object(conn, (char *)&data, STRING_T);
51     if (code) {
52         code = connection_errno(conn);
53         lose("awaiting Kerberos authenticators");
54     }
55     gethostname(host, BUFSIZ);
56     ticket_st.mbz = 0;
57     ticket_st.length = MAX_STRING_SIZE(data);
58     bcopy(STRING_DATA(data), ticket_st.dat, MAX_STRING_SIZE(data));
59     code = rd_ap_req(&ticket_st, sms,
60                      PrincipalHostname(host), 0,
61                      &ad, "/etc/srvtab");
62     if (code) {
63         code = krb_err_frob(code);
64         strcpy(ad.pname, qmark);
65         strcpy(ad.pinst, qmark);
66         strcpy(ad.prealm, qmark);
67         goto auth_failed;
68     }
69     if (get_krbrlm(realm,0))
70         realm[0] = '\0';
71     code = EPERM;
72     if (strcmp(sms, ad.pname))
73         goto auth_failed;
74     if (ad.pinst[0] != '\0')
75         goto auth_failed;
76     if (strcmp(realm, ad.prealm))
77         goto auth_failed;
78     if (send_ok())
79         lose("sending approval of authorization");
80     have_authorization = 1;
81     return(0);
82 auth_failed:
83     sprintf(buf, "auth for %s.%s@%s failed: %s",
84             ad.pname, ad.pinst, ad.prealm, error_message(code));
85     {
86         register int rc;
87         rc = send_object(conn, (char *)&code, INTEGER_T);
88         code = rc;
89     }
90     if (code)
91         lose("sending rejection of authenticator");
92     return(EPERM);
93 }
This page took 0.046029 seconds and 5 git commands to generate.