]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZMkAuth.c
5a6749c2defdb8e12b8a95c2760f8c2a826c54f2
[1ts-debian.git] / zephyr / lib / ZMkAuth.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZMakeAuthentication function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #include <internal.h>
14
15 #ifndef lint
16 static const char rcsid_ZMakeAuthentication_c[] = "$Id$";
17 #endif
18
19 #ifdef HAVE_KRB4
20 #include <krb_err.h>
21 #endif
22
23 Code_t ZResetAuthentication () {
24     return ZERR_NONE;
25 }
26
27 Code_t ZMakeAuthentication(notice, buffer, buffer_len, len)
28     register ZNotice_t *notice;
29     char *buffer;
30     int buffer_len;
31     int *len;
32 {
33 #ifdef HAVE_KRB4
34     int result;
35     time_t now;
36     KTEXT_ST authent;
37     char *cstart, *cend;
38     ZChecksum_t checksum;
39     CREDENTIALS cred;
40     extern unsigned long des_quad_cksum();
41
42     result = krb_mk_req(&authent, SERVER_SERVICE, 
43                         SERVER_INSTANCE, __Zephyr_realm, 0);
44     if (result != MK_AP_OK)
45         return (result+krb_err_base);
46     result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE,
47                           __Zephyr_realm, &cred);
48     if (result != KSUCCESS)
49         return (result+krb_err_base);
50
51     notice->z_auth = 1;
52     notice->z_authent_len = authent.length;
53     notice->z_ascii_authent = (char *)malloc((unsigned)authent.length*3);
54     /* zero length authent is an error, so malloc(0) is not a problem */
55     if (!notice->z_ascii_authent)
56         return (ENOMEM);
57     if ((result = ZMakeAscii(notice->z_ascii_authent, 
58                              authent.length*3, 
59                              authent.dat, 
60                              authent.length)) != ZERR_NONE) {
61         free(notice->z_ascii_authent);
62         return (result);
63     }
64     result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart,
65                                &cend);
66     free(notice->z_ascii_authent);
67     notice->z_authent_len = 0;
68     if (result)
69         return(result);
70
71     /* Compute a checksum over the header and message. */
72     checksum = des_quad_cksum(buffer, NULL, cstart - buffer, 0, cred.session);
73     checksum ^= des_quad_cksum(cend, NULL, buffer + *len - cend, 0,
74                                cred.session);
75     checksum ^= des_quad_cksum(notice->z_message, NULL, notice->z_message_len,
76                                0, cred.session);
77     notice->z_checksum = checksum;
78     ZMakeAscii32(cstart, buffer + buffer_len - cstart, checksum);
79
80     return (ZERR_NONE);
81 #else
82     notice->z_checksum = 0;
83     notice->z_auth = 1;
84     notice->z_authent_len = 0;
85     notice->z_ascii_authent = "";
86     return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL));
87 #endif
88 }