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.20 2002/11/11 18:28:06 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.20 2002/11/11 18:28:06 ghudson Exp $";
23 Code_t ZResetAuthentication () {
27 Code_t ZMakeAuthentication(notice, buffer, buffer_len, len)
28 register ZNotice_t *notice;
40 extern unsigned long des_quad_cksum();
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);
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)
57 if ((result = ZMakeAscii(notice->z_ascii_authent,
60 authent.length)) != ZERR_NONE) {
61 free(notice->z_ascii_authent);
64 result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart,
66 free(notice->z_ascii_authent);
67 notice->z_authent_len = 0;
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,
75 checksum ^= des_quad_cksum(notice->z_message, NULL, notice->z_message_len,
77 notice->z_checksum = checksum;
78 ZMakeAscii32(cstart, buffer + buffer_len - cstart, checksum);
82 notice->z_checksum = 0;
84 notice->z_authent_len = 0;
85 notice->z_ascii_authent = "";
86 return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL));