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
|
/*
* lib/krb425/rd_safe.c
*
* Copyright 1990,1991 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
*
* krb_rd_safe for krb425
*/
#include "krb425.h"
#ifndef hpux
#include <arpa/inet.h>
#endif
long
krb_rd_safe(in, in_length, key, sender, receiver, msg)
u_char *in;
u_long in_length;
des_cblock key;
struct sockaddr_in *sender;
struct sockaddr_in *receiver;
MSG_DAT *msg;
{
krb5_data inbuf;
krb5_data out;
krb5_keyblock keyb;
krb5_address saddr, *saddr2;
krb5_address raddr;
krb5_error_code r;
char sa[4], ra[4];
krb5_rcache rcache;
char *cachename;
keyb.keytype = KEYTYPE_DES;
keyb.length = sizeof(des_cblock);
keyb.contents = (krb5_octet *)key;
saddr.addrtype = ADDRTYPE_INET;
saddr.length = 4;
saddr.contents = (krb5_octet *)sa;
raddr.addrtype = ADDRTYPE_INET;
raddr.length = 4;
raddr.contents = (krb5_octet *)ra;
memcpy(sa, (char *)&sender->sin_addr, 4);
memcpy(ra, (char *)&receiver->sin_addr, 4);
inbuf.data = (char *)in;
inbuf.length = in_length;
if (r = krb5_gen_portaddr(&saddr, (krb5_pointer)&sender->sin_port,
&saddr2)) {
#ifdef EBUG
ERROR(r);
#endif
return(krb425error(r));
}
if (cachename = calloc(1, strlen(inet_ntoa(sender->sin_addr)+1+1+5)))
/* 1 for NUL, 1 for rc_., 5 for digits of port
(unsigned 16bit, no greater than 65535) */
sprintf(cachename, "%s.%u", inet_ntoa(sender->sin_addr),
ntohs(receiver->sin_port));
else {
#ifdef EBUG
ERROR(ENOMEM);
#endif
return(krb425error(ENOMEM));
}
out.data = cachename;
out.length = strlen(cachename);
if (r = krb5_get_server_rcache(&out,
&rcache)) {
krb5_free_address(saddr2);
#ifdef EBUG
ERROR(r);
#endif
return(-1);
}
free(cachename);
r = krb5_rd_safe(&inbuf, &keyb, saddr2, &raddr,
0, 0, rcache, &out);
krb5_rc_close(rcache);
krb5_free_address(saddr2);
if (r) {
#ifdef EBUG
ERROR(r);
#endif
return(krb425error(r));
}
msg->app_data = (u_char *)out.data;
msg->app_length = out.length;
msg->hash = 0L;
msg->swap = 0;
msg->time_sec = 0;
msg->time_5ms = 0;
return(KSUCCESS);
}
|