]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Header$ | |
4 | */ | |
546bc43b | 5 | /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */ |
6 | /* For copying and distribution information, please see the file */ | |
7 | /* <mit-copyright.h>. */ | |
de56407f | 8 | |
9 | #ifndef lint | |
10 | static char *rcsid_auth_001_c = "$Header$"; | |
11 | #endif lint | |
12 | ||
546bc43b | 13 | #include <mit-copyright.h> |
de56407f | 14 | #include <stdio.h> |
15 | #include <strings.h> | |
1e8fd4c0 | 16 | #include <gdb.h> |
de56407f | 17 | #include <krb.h> |
b29ec86e | 18 | #include <krb_et.h> |
de56407f | 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(); | |
1c6164bb | 28 | static char service[] = "rcmd"; |
29 | static char master[] = "sms"; | |
de56407f | 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; | |
c47daf21 | 47 | char host[BUFSIZ], realm[REALM_SZ]; |
48 | char aname[ANAME_SZ], ainst[INST_SZ], arealm[REALM_SZ]; | |
de56407f | 49 | AUTH_DAT ad; |
c47daf21 | 50 | char *p, *first, *config_lookup(); |
de56407f | 51 | KTEXT_ST ticket_st; |
52 | ||
53 | if (send_ok()) | |
54 | lose("sending okay for authorization (auth_001)"); | |
55 | code = receive_object(conn, (char *)&data, STRING_T); | |
56 | if (code) { | |
57 | code = connection_errno(conn); | |
58 | lose("awaiting Kerberos authenticators"); | |
59 | } | |
60 | gethostname(host, BUFSIZ); | |
61 | ticket_st.mbz = 0; | |
62 | ticket_st.length = MAX_STRING_SIZE(data); | |
63 | bcopy(STRING_DATA(data), ticket_st.dat, MAX_STRING_SIZE(data)); | |
1e8fd4c0 | 64 | code = krb_rd_req(&ticket_st, service, |
c47daf21 | 65 | krb_get_phost(host), 0, |
66 | &ad, KEYFILE); | |
de56407f | 67 | if (code) { |
b29ec86e | 68 | code += ERROR_TABLE_BASE_krb; |
de56407f | 69 | strcpy(ad.pname, qmark); |
70 | strcpy(ad.pinst, qmark); | |
71 | strcpy(ad.prealm, qmark); | |
72 | goto auth_failed; | |
73 | } | |
c47daf21 | 74 | |
75 | /* If there is an auth record in the config file matching the | |
76 | * authenticator we received, then accept it. If there's no | |
77 | * auth record, assume [master]@[local realm]. | |
78 | */ | |
79 | if (first = p = config_lookup("auth")) { | |
80 | do { | |
81 | kname_parse(aname, ainst, arealm, p); | |
82 | if (strcmp(aname, ad.pname) || | |
83 | strcmp(ainst, ad.pinst) || | |
84 | strcmp(arealm, ad.prealm)) | |
85 | p = config_lookup("auth"); | |
86 | else | |
87 | p = first; | |
88 | } while (p != first); | |
89 | } else { | |
90 | strcpy(aname, master); | |
91 | strcpy(ainst, ""); | |
92 | if (krb_get_lrealm(arealm,1)) | |
93 | strcpy(arealm, KRB_REALM); | |
94 | } | |
de56407f | 95 | code = EPERM; |
c47daf21 | 96 | if (strcmp(aname, ad.pname) || |
97 | strcmp(ainst, ad.pinst) || | |
98 | strcmp(arealm, ad.prealm)) | |
99 | goto auth_failed; | |
de56407f | 100 | if (send_ok()) |
101 | lose("sending approval of authorization"); | |
102 | have_authorization = 1; | |
103 | return(0); | |
104 | auth_failed: | |
105 | sprintf(buf, "auth for %s.%s@%s failed: %s", | |
106 | ad.pname, ad.pinst, ad.prealm, error_message(code)); | |
107 | { | |
108 | register int rc; | |
109 | rc = send_object(conn, (char *)&code, INTEGER_T); | |
110 | code = rc; | |
111 | } | |
112 | if (code) | |
113 | lose("sending rejection of authenticator"); | |
114 | return(EPERM); | |
115 | } |