1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZMakeAuthentication function.
4 * Created by: Robert French
6 * $Id: ZMkAuth.c,v 1.19 1999/01/22 23:19:16 ghudson Exp $
8 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
9 * For copying and distribution information, see the file
16 static const char rcsid_ZMakeAuthentication_c[] = "$Id: ZMkAuth.c,v 1.19 1999/01/22 23:19:16 ghudson Exp $";
21 static long last_authent_time = 0L;
22 static KTEXT_ST last_authent;
25 Code_t ZResetAuthentication () {
27 last_authent_time = 0L;
32 Code_t ZMakeAuthentication(notice, buffer, buffer_len, len)
33 register ZNotice_t *notice;
45 extern unsigned long des_quad_cksum();
48 if (last_authent_time == 0 || (now - last_authent_time > 120)) {
49 result = krb_mk_req(&authent, SERVER_SERVICE,
50 SERVER_INSTANCE, __Zephyr_realm, 0);
51 if (result != MK_AP_OK) {
52 last_authent_time = 0;
53 return (result+krb_err_base);
55 last_authent_time = now;
56 last_authent = authent;
59 authent = last_authent;
62 notice->z_authent_len = authent.length;
63 notice->z_ascii_authent = (char *)malloc((unsigned)authent.length*3);
64 /* zero length authent is an error, so malloc(0) is not a problem */
65 if (!notice->z_ascii_authent)
67 if ((result = ZMakeAscii(notice->z_ascii_authent,
70 authent.length)) != ZERR_NONE) {
71 free(notice->z_ascii_authent);
74 result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart,
76 free(notice->z_ascii_authent);
77 notice->z_authent_len = 0;
81 /* Compute a checksum over the header and message. */
82 if ((result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE,
83 __Zephyr_realm, &cred)) != 0)
85 checksum = des_quad_cksum(buffer, NULL, cstart - buffer, 0, cred.session);
86 checksum ^= des_quad_cksum(cend, NULL, buffer + *len - cend, 0,
88 checksum ^= des_quad_cksum(notice->z_message, NULL, notice->z_message_len,
90 notice->z_checksum = checksum;
91 ZMakeAscii32(cstart, buffer + buffer_len - cstart, checksum);
95 notice->z_checksum = 0;
97 notice->z_authent_len = 0;
98 notice->z_ascii_authent = "";
99 return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL));