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 * Copyright (c) 1987 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, see the file
13 #ifndef ERROR_TABLE_BASE_krb
14 #define ERROR_TABLE_BASE_krb (39525376L)
17 #ifdef ZEPHYR_USES_KERBEROS
23 static long last_authent_time
= 0L;
24 static KTEXT_ST last_authent
;
27 Code_t
ZMakeAuthentication(notice
, buffer
, buffer_len
, len
)
28 register ZNotice_t
*notice
;
33 #ifdef ZEPHYR_USES_KERBEROS
40 extern unsigned long des_quad_cksum();
43 if (last_authent_time
== 0 || (now
- last_authent_time
> 120)) {
44 result
= krb_mk_req(&authent
, SERVER_SERVICE
,
45 SERVER_INSTANCE
, __Zephyr_realm
, 0);
46 if (result
!= MK_AP_OK
) {
47 last_authent_time
= 0;
48 return (result
+ERROR_TABLE_BASE_krb
);
50 last_authent_time
= now
;
51 last_authent
= authent
;
54 authent
= last_authent
;
57 notice
->z_authent_len
= authent
.length
;
58 notice
->z_ascii_authent
= (char *)malloc((unsigned)authent
.length
*3);
59 /* zero length authent is an error, so malloc(0) is not a problem */
60 if (!notice
->z_ascii_authent
)
62 if ((result
= ZMakeAscii(notice
->z_ascii_authent
,
65 authent
.length
)) != ZERR_NONE
) {
66 free(notice
->z_ascii_authent
);
69 result
= Z_FormatRawHeader(notice
, buffer
, buffer_len
, len
, &cstart
,
71 free(notice
->z_ascii_authent
);
72 notice
->z_authent_len
= 0;
76 /* Compute a checksum over the header and message. */
77 if ((result
= krb_get_cred(SERVER_SERVICE
, SERVER_INSTANCE
,
78 __Zephyr_realm
, &cred
)) != 0)
80 checksum
= des_quad_cksum(buffer
, NULL
, cstart
- buffer
, 0, (C_Block
*)cred
.session
);
81 checksum
^= des_quad_cksum(cend
, NULL
, buffer
+ *len
- cend
, 0,
82 (C_Block
*)cred
.session
);
83 checksum
^= des_quad_cksum(notice
->z_message
, NULL
, notice
->z_message_len
,
84 0, (C_Block
*)cred
.session
);
85 notice
->z_checksum
= checksum
;
86 ZMakeAscii32(cstart
, buffer
+ buffer_len
- cstart
, checksum
);
90 notice
->z_checksum
= 0;
92 notice
->z_authent_len
= 0;
93 notice
->z_ascii_authent
= "";
94 return (Z_FormatRawHeader(notice
, buffer
, buffer_len
, len
, NULL
, NULL
));