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
|
/* This file is part of the Project Athena Zephyr Notification System.
* It contains source for the ZFormatAuthenticNotice function.
*
* Created by: Robert French
*
* $Id$
*
* Copyright (c) 1987,1988 by the Massachusetts Institute of Technology.
* For copying and distribution information, see the file
* "mit-copyright.h".
*/
#ifndef lint
static const char rcsid_ZFormatAuthenticNotice_c[] = "$Id$";
#endif
#include <internal.h>
#ifdef HAVE_KRB4
Code_t
ZFormatAuthenticNotice(ZNotice_t *notice,
char *buffer,
int buffer_len,
int *len,
C_Block session)
{
ZNotice_t newnotice;
char *ptr;
int retval, hdrlen;
newnotice = *notice;
newnotice.z_auth = 1;
newnotice.z_authent_len = 0;
newnotice.z_ascii_authent = "";
if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len,
&hdrlen, &ptr, NULL)) != ZERR_NONE)
return (retval);
newnotice.z_checksum =
(ZChecksum_t)des_quad_cksum((unsigned char *)buffer, NULL, ptr - buffer, 0, (C_Block *)session);
if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len,
&hdrlen, NULL, NULL)) != ZERR_NONE)
return (retval);
ptr = buffer+hdrlen;
if (newnotice.z_message_len+hdrlen > buffer_len)
return (ZERR_PKTLEN);
(void) memcpy(ptr, newnotice.z_message, newnotice.z_message_len);
*len = hdrlen+newnotice.z_message_len;
if (*len > Z_MAXPKTLEN)
return (ZERR_PKTLEN);
return (ZERR_NONE);
}
#endif
#ifdef HAVE_KRB5
Code_t
ZFormatAuthenticNoticeV5(ZNotice_t *notice,
register char *buffer,
register int buffer_len,
int *len,
krb5_keyblock *keyblock)
{
ZNotice_t newnotice;
char *ptr;
int retval, hdrlen, hdr_adj;
krb5_enctype enctype;
krb5_cksumtype cksumtype;
int key_len;
char *cksum_start, *cstart, *cend;
int cksum_len;
key_len = Z_keylen(keyblock);
retval = Z_ExtractEncCksum(keyblock, &enctype, &cksumtype);
if (retval)
return (ZAUTH_FAILED);
#ifdef HAVE_KRB4
if (key_len == 8 && (enctype == ENCTYPE_DES_CBC_CRC ||
enctype == ENCTYPE_DES_CBC_MD4 ||
enctype == ENCTYPE_DES_CBC_MD5)) {
C_Block tmp;
memcpy(&tmp, Z_keydata(keyblock), key_len);
return ZFormatAuthenticNotice(notice, buffer, buffer_len, len,
tmp);
}
#endif
newnotice = *notice;
newnotice.z_auth = 1;
newnotice.z_authent_len = 0;
newnotice.z_ascii_authent = "";
if ((retval = Z_NewFormatRawHeader(&newnotice, buffer, buffer_len,
&hdrlen,
&cksum_start, &cksum_len, &cstart,
&cend)) != ZERR_NONE)
return (retval);
retval = Z_InsertZcodeChecksum(keyblock, &newnotice, buffer,
cksum_start, cksum_len, cstart, cend,
buffer_len, &hdr_adj);
if (retval)
return retval;
hdrlen += hdr_adj;
ptr = buffer+hdrlen;
if (newnotice.z_message_len+hdrlen > buffer_len)
return (ZERR_PKTLEN);
(void) memcpy(ptr, newnotice.z_message, newnotice.z_message_len);
*len = hdrlen+newnotice.z_message_len;
if (*len > Z_MAXPKTLEN)
return (ZERR_PKTLEN);
return (ZERR_NONE);
}
#endif
|