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
7 * $Author: warmenhoven $
9 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
13 /* $Id: ZMkAuth.c 2096 2001-07-31 01:00:39Z warmenhoven $ */
18 static const char rcsid_ZMakeAuthentication_c
[] = "$Id: ZMkAuth.c 2096 2001-07-31 01:00:39Z warmenhoven $";
21 #ifdef ZEPHYR_USES_KERBEROS
23 static long last_authent_time
= 0L;
24 static KTEXT_ST last_authent
;
27 Code_t
ZResetAuthentication () {
28 #ifdef ZEPHYR_USES_KERBEROS
29 last_authent_time
= 0L;
34 Code_t
ZMakeAuthentication(notice
, buffer
, buffer_len
, len
)
35 register ZNotice_t
*notice
;
40 #ifdef ZEPHYR_USES_KERBEROS
47 extern unsigned long des_quad_cksum();
50 if (last_authent_time
== 0 || (now
- last_authent_time
> 120)) {
51 result
= krb_mk_req(&authent
, SERVER_SERVICE
,
52 SERVER_INSTANCE
, __Zephyr_realm
, 0);
53 if (result
!= MK_AP_OK
) {
54 last_authent_time
= 0;
55 return (result
+krb_err_base
);
57 last_authent_time
= now
;
58 last_authent
= authent
;
61 authent
= last_authent
;
64 notice
->z_authent_len
= authent
.length
;
65 notice
->z_ascii_authent
= (char *)malloc((unsigned)authent
.length
*3);
66 /* zero length authent is an error, so malloc(0) is not a problem */
67 if (!notice
->z_ascii_authent
)
69 if ((result
= ZMakeAscii(notice
->z_ascii_authent
,
72 authent
.length
)) != ZERR_NONE
) {
73 free(notice
->z_ascii_authent
);
76 result
= Z_FormatRawHeader(notice
, buffer
, buffer_len
, len
, &cstart
,
78 free(notice
->z_ascii_authent
);
79 notice
->z_authent_len
= 0;
83 /* Compute a checksum over the header and message. */
84 if ((result
= krb_get_cred(SERVER_SERVICE
, SERVER_INSTANCE
,
85 __Zephyr_realm
, &cred
)) != 0)
87 checksum
= des_quad_cksum(buffer
, NULL
, cstart
- buffer
, 0, cred
.session
);
88 checksum
^= des_quad_cksum(cend
, NULL
, buffer
+ *len
- cend
, 0,
90 checksum
^= des_quad_cksum(notice
->z_message
, NULL
, notice
->z_message_len
,
92 notice
->z_checksum
= checksum
;
93 ZMakeAscii32(cstart
, buffer
+ buffer_len
- cstart
, checksum
);
97 notice
->z_checksum
= 0;
99 notice
->z_authent_len
= 0;
100 notice
->z_ascii_authent
= "";
101 return (Z_FormatRawHeader(notice
, buffer
, buffer_len
, len
, NULL
, NULL
));