]>
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[] = "???"; |
06c2568b | 31 | C_Block session; |
de56407f | 32 | |
33 | /* | |
34 | * authentication request auth_001: | |
35 | * | |
36 | * >>> (STRING) "auth_001" | |
37 | * <<< (int) 0 | |
38 | * >>> (STRING) ticket | |
39 | * <<< (int) code | |
40 | * | |
41 | */ | |
42 | ||
43 | int | |
44 | auth_001(str) | |
45 | char *str; | |
46 | { | |
47 | STRING data; | |
c47daf21 | 48 | char host[BUFSIZ], realm[REALM_SZ]; |
49 | char aname[ANAME_SZ], ainst[INST_SZ], arealm[REALM_SZ]; | |
de56407f | 50 | AUTH_DAT ad; |
c47daf21 | 51 | char *p, *first, *config_lookup(); |
de56407f | 52 | KTEXT_ST ticket_st; |
53 | ||
54 | if (send_ok()) | |
55 | lose("sending okay for authorization (auth_001)"); | |
56 | code = receive_object(conn, (char *)&data, STRING_T); | |
57 | if (code) { | |
58 | code = connection_errno(conn); | |
59 | lose("awaiting Kerberos authenticators"); | |
60 | } | |
61 | gethostname(host, BUFSIZ); | |
62 | ticket_st.mbz = 0; | |
63 | ticket_st.length = MAX_STRING_SIZE(data); | |
64 | bcopy(STRING_DATA(data), ticket_st.dat, MAX_STRING_SIZE(data)); | |
1e8fd4c0 | 65 | code = krb_rd_req(&ticket_st, service, |
c47daf21 | 66 | krb_get_phost(host), 0, |
67 | &ad, KEYFILE); | |
de56407f | 68 | if (code) { |
b29ec86e | 69 | code += ERROR_TABLE_BASE_krb; |
de56407f | 70 | strcpy(ad.pname, qmark); |
71 | strcpy(ad.pinst, qmark); | |
72 | strcpy(ad.prealm, qmark); | |
73 | goto auth_failed; | |
74 | } | |
c47daf21 | 75 | |
76 | /* If there is an auth record in the config file matching the | |
77 | * authenticator we received, then accept it. If there's no | |
78 | * auth record, assume [master]@[local realm]. | |
79 | */ | |
80 | if (first = p = config_lookup("auth")) { | |
81 | do { | |
82 | kname_parse(aname, ainst, arealm, p); | |
83 | if (strcmp(aname, ad.pname) || | |
84 | strcmp(ainst, ad.pinst) || | |
85 | strcmp(arealm, ad.prealm)) | |
86 | p = config_lookup("auth"); | |
87 | else | |
88 | p = first; | |
89 | } while (p != first); | |
90 | } else { | |
91 | strcpy(aname, master); | |
92 | strcpy(ainst, ""); | |
93 | if (krb_get_lrealm(arealm,1)) | |
94 | strcpy(arealm, KRB_REALM); | |
95 | } | |
de56407f | 96 | code = EPERM; |
c47daf21 | 97 | if (strcmp(aname, ad.pname) || |
98 | strcmp(ainst, ad.pinst) || | |
99 | strcmp(arealm, ad.prealm)) | |
100 | goto auth_failed; | |
de56407f | 101 | if (send_ok()) |
102 | lose("sending approval of authorization"); | |
103 | have_authorization = 1; | |
06c2568b | 104 | /* Stash away session key */ |
105 | bcopy(ad.session, session, sizeof(session)); | |
de56407f | 106 | return(0); |
107 | auth_failed: | |
108 | sprintf(buf, "auth for %s.%s@%s failed: %s", | |
109 | ad.pname, ad.pinst, ad.prealm, error_message(code)); | |
110 | { | |
111 | register int rc; | |
112 | rc = send_object(conn, (char *)&code, INTEGER_T); | |
113 | code = rc; | |
114 | } | |
115 | if (code) | |
116 | lose("sending rejection of authenticator"); | |
117 | return(EPERM); | |
118 | } |