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