]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZFmtAuth.c
import zephyr 3.0~rc2544
[1ts-debian.git] / zephyr / lib / ZFmtAuth.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZFormatAuthenticNotice function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id: ZFmtAuth.c 2502 2009-07-26 21:25:27Z kcr@ATHENA.MIT.EDU $
7  *
8  *      Copyright (c) 1987,1988 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h".
11  */
12
13 #ifndef lint
14 static const char rcsid_ZFormatAuthenticNotice_c[] = "$Id: ZFmtAuth.c 2502 2009-07-26 21:25:27Z kcr@ATHENA.MIT.EDU $";
15 #endif
16
17 #include <internal.h>
18
19 #ifdef HAVE_KRB4
20 Code_t
21 ZFormatAuthenticNotice(ZNotice_t *notice,
22                        char *buffer,
23                        int buffer_len,
24                        int *len,
25                        C_Block session)
26 {
27     ZNotice_t newnotice;
28     char *ptr;
29     int retval, hdrlen;
30
31     newnotice = *notice;
32     newnotice.z_auth = 1;
33     newnotice.z_authent_len = 0;
34     newnotice.z_ascii_authent = "";
35
36     if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len,
37                                     &hdrlen, &ptr, NULL)) != ZERR_NONE)
38         return (retval);
39
40     newnotice.z_checksum =
41         (ZChecksum_t)des_quad_cksum((unsigned char *)buffer, NULL, ptr - buffer, 0, (C_Block *)session);
42
43     if ((retval = Z_FormatRawHeader(&newnotice, buffer, buffer_len,
44                                     &hdrlen, NULL, NULL)) != ZERR_NONE)
45         return (retval);
46
47     ptr = buffer+hdrlen;
48
49     if (newnotice.z_message_len+hdrlen > buffer_len)
50         return (ZERR_PKTLEN);
51
52     (void) memcpy(ptr, newnotice.z_message, newnotice.z_message_len);
53
54     *len = hdrlen+newnotice.z_message_len;
55
56     if (*len > Z_MAXPKTLEN)
57         return (ZERR_PKTLEN);
58
59     return (ZERR_NONE);
60 }
61 #endif
62
63 #ifdef HAVE_KRB5
64 Code_t
65 ZFormatAuthenticNoticeV5(ZNotice_t *notice,
66                          register char *buffer,
67                          register int buffer_len,
68                          int *len,
69                          krb5_keyblock *keyblock)
70 {
71     ZNotice_t newnotice;
72     char *ptr;
73     int retval, hdrlen, hdr_adj;
74     krb5_enctype enctype;
75     krb5_cksumtype cksumtype;
76     int key_len;
77     char *cksum_start, *cstart, *cend;
78     int cksum_len;
79
80     key_len = Z_keylen(keyblock);
81     retval = Z_ExtractEncCksum(keyblock, &enctype, &cksumtype);
82     if (retval)
83         return (ZAUTH_FAILED);
84
85 #ifdef HAVE_KRB4
86     if (key_len == 8 && (enctype == ENCTYPE_DES_CBC_CRC ||
87                          enctype == ENCTYPE_DES_CBC_MD4 ||
88                          enctype == ENCTYPE_DES_CBC_MD5)) {
89          C_Block tmp;
90          memcpy(&tmp, Z_keydata(keyblock), key_len);
91          return ZFormatAuthenticNotice(notice, buffer, buffer_len, len,
92                                        tmp);
93     }
94 #endif
95
96     newnotice = *notice;
97     newnotice.z_auth = 1;
98     newnotice.z_authent_len = 0;
99     newnotice.z_ascii_authent = "";
100
101     if ((retval = Z_NewFormatRawHeader(&newnotice, buffer, buffer_len,
102                                        &hdrlen,
103                                        &cksum_start, &cksum_len, &cstart,
104                                        &cend)) != ZERR_NONE)
105         return (retval);
106
107     /* we know this is only called by the server */
108     retval = Z_InsertZcodeChecksum(keyblock, &newnotice, buffer,
109                                    cksum_start, cksum_len, cstart, cend,
110                                    buffer_len, &hdr_adj, 1);
111     if (retval)
112         return retval;
113
114     hdrlen += hdr_adj;
115
116     ptr = buffer+hdrlen;
117
118     if (newnotice.z_message_len+hdrlen > buffer_len)
119          return (ZERR_PKTLEN);
120
121     (void) memcpy(ptr, newnotice.z_message, newnotice.z_message_len);
122
123     *len = hdrlen+newnotice.z_message_len;
124
125     if (*len > Z_MAXPKTLEN)
126         return (ZERR_PKTLEN);
127
128     return (ZERR_NONE);
129 }
130 #endif