1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
/*
* $Source$
* $Author$
*
* Copyright 1990 by the Massachusetts Institute of Technology.
*
* For copying and distribution information, please see the file
* <krb5/copyright.h>.
*
* krb_rd_req for krb425
*/
#if !defined(lint) && !defined(SABER)
static char rcsid_rd_req_c[] =
"$Id$";
#endif /* !lint & !SABER */
#include <krb5/copyright.h>
#include "krb425.h"
static krb5_error_code
setkey_key_proc(DECLARG(krb5_pointer,arg),
DECLARG(krb5_principal,princ),
DECLARG(krb5_kvno,kvno),
DECLARG(krb5_keyblock **,retkey))
OLDDECLARG(krb5_pointer,arg)
OLDDECLARG(krb5_principal,princ)
OLDDECLARG(krb5_kvno,kvno)
OLDDECLARG(krb5_keyblock **,retkey)
{
return krb5_copy_keyblock(&_krb425_servkey, retkey);
}
int
krb_rd_req(authent, service, instance, from_addr, ad, fn)
KTEXT authent;
char *service;
char *instance;
u_long from_addr;
AUTH_DAT *ad;
char *fn;
{
krb5_address peer;
krb5_tkt_authent *authdat;
char addr[4];
krb5_data *server[4];
krb5_data srvdata[3];
krb5_error_code r;
krb5_data authe;
extern int gethostname();
int use_set_key = 0;
if (from_addr) {
peer.addrtype = ADDRTYPE_INET;
peer.length = 4;
peer.contents = (krb5_octet *)addr;
memcpy(addr, (char *)&from_addr + (sizeof(from_addr) - 4), 4);
}
if (!_krb425_local_realm)
if (r = krb5_get_default_realm(&_krb425_local_realm))
return(krb425error(r));
if (!strcmp(instance, "*")) {
static char hostname[64] = { 0 };
if (!hostname[0]) {
struct hostent *h;
gethostname(hostname, sizeof(hostname));
if (h = gethostbyname(hostname)) {
char *p;
strncpy(hostname, h->h_name, sizeof(hostname));
hostname[sizeof(hostname)-1] = 0;
p = hostname;
do {
if (isupper(*p)) *p=tolower(*p);
} while (*p++);
}
}
instance = hostname;
}
set_data5(srvdata[0], _krb425_local_realm);
set_data5(srvdata[1], service);
set_data5(srvdata[2], instance);
server[0] = &srvdata[0];
server[1] = &srvdata[1];
server[2] = &srvdata[2];
server[3] = 0;
authe.length = authent->length;
authe.data = (char *)authent->dat;
if (!fn) {
use_set_key = 1;
fn = (char *)0;
} else if (!*fn)
fn = (char *)0;
#ifdef EBUG
EPRINT "Calling krb5_rd_req with:\n");
EPRINT " Realm : "); show5(srvdata[0]); ENEWLINE
EPRINT " Service : "); show5(srvdata[1]); ENEWLINE
EPRINT " Instance: "); show5(srvdata[2]); ENEWLINE
EPRINT "Authenenticator : %d bytes\n", authe.length);
EPRINT "Filename : %s\n", fn ? fn : "none given");
if (from_addr) {
EPRINT "Address type : %s\n",
peer.addrtype == ADDRTYPE_INET ? "inet" :
peer.addrtype == ADDRTYPE_CHAOS ? "chaos" :
peer.addrtype == ADDRTYPE_XNS ? "xns" :
peer.addrtype == ADDRTYPE_ISO ? "iso" :
peer.addrtype == ADDRTYPE_DDP ? "ddp" : "unknown type");
EPRINT "Address length : %d\n", peer.length);
EPRINT "Address :");
{
int x;
for (x = 0; x < peer.length && x < 8; ++x)
fprintf(stderr, " %d", peer.contents[x]);
if (x < peer.length)
fprintf(stderr, " (%d)", peer.length);
fprintf(stderr, "\n");
}
}
#endif
if (r = krb5_rd_req(&authe,
(krb5_principal)server,
from_addr ? &peer : 0,
fn, use_set_key ? setkey_key_proc : 0,
0, 0, &authdat)) {
#ifdef EBUG
ERROR(r)
#endif
return(krb425error(r));
}
ad->k_flags = 0;
#ifdef EBUG
r = 0;
while (authdat->authenticator->client[r]) {
EPRINT "Client[%d]: ", r); show5((*authdat->authenticator->client[r])); ENEWLINE
++r;
}
r = 0;
while (authdat->ticket->server[r]) {
EPRINT "Server[%d]: ", r); show5((*authdat->ticket->server[r])); ENEWLINE
++r;
}
r = 0;
#endif
set_string(ad->pname, ANAME_SZ, authdat->authenticator->client[1]);
set_string(ad->pinst, INST_SZ, authdat->authenticator->client[2]);
set_string(ad->prealm, REALM_SZ, authdat->authenticator->client[0]);
ad->checksum = *(long *)authdat->authenticator->checksum->contents;
if (authdat->ticket->enc_part2->session->keytype != KEYTYPE_DES) {
r = KFAILURE;
goto out;
} else
memcpy((char*)ad->session,
(char*)authdat->ticket->enc_part2->session->contents,
sizeof(C_Block));
ad->life = authdat->ticket->enc_part2->times.endtime;
ad->time_sec = authdat->authenticator->ctime;
ad->address = 0;
if (authdat->ticket->enc_part2->caddrs[0]->addrtype != ADDRTYPE_INET) {
r = KFAILURE;
goto out;
} else
memcpy((char*)&ad->address + sizeof(ad->address) - 4,
(char*)authdat->ticket->enc_part2->caddrs[0]->contents, 4);
if (authdat->ticket->enc_part2->authorization_data &&
authdat->ticket->enc_part2->authorization_data[0]) {
ad->reply.length = authdat->ticket->enc_part2->authorization_data[0]->length;
memcpy((char*)ad->reply.dat,
(char*)authdat->ticket->enc_part2->authorization_data[0]->contents,
min(ad->reply.length, MAX_KTXT_LEN));
ad->reply.mbz = 0;
}
out:
krb5_free_tkt_authent(authdat);
return(r);
}
|