]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - lib/ZMkAuth.c
fix zwgc man page on linux and note
[1ts-debian.git] / 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: ZMkAuth.c,v 1.19 1999/01/22 23:19:16 ghudson Exp $
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: ZMkAuth.c,v 1.19 1999/01/22 23:19:16 ghudson Exp $";
17 #endif
18
19 #ifdef HAVE_KRB4
20 #include <krb_err.h>
21 static long last_authent_time = 0L;
22 static KTEXT_ST last_authent;
23 #endif
24
25 Code_t ZResetAuthentication () {
26 #ifdef HAVE_KRB4
27     last_authent_time = 0L;
28 #endif
29     return ZERR_NONE;
30 }
31
32 Code_t ZMakeAuthentication(notice, buffer, buffer_len, len)
33     register ZNotice_t *notice;
34     char *buffer;
35     int buffer_len;
36     int *len;
37 {
38 #ifdef HAVE_KRB4
39     int result;
40     time_t now;
41     KTEXT_ST authent;
42     char *cstart, *cend;
43     ZChecksum_t checksum;
44     CREDENTIALS cred;
45     extern unsigned long des_quad_cksum();
46
47     now = time(0);
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);
54         }
55         last_authent_time = now;
56         last_authent = authent;
57     }
58     else {
59         authent = last_authent;
60     }
61     notice->z_auth = 1;
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)
66         return (ENOMEM);
67     if ((result = ZMakeAscii(notice->z_ascii_authent, 
68                              authent.length*3, 
69                              authent.dat, 
70                              authent.length)) != ZERR_NONE) {
71         free(notice->z_ascii_authent);
72         return (result);
73     }
74     result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart,
75                                &cend);
76     free(notice->z_ascii_authent);
77     notice->z_authent_len = 0;
78     if (result)
79         return(result);
80
81     /* Compute a checksum over the header and message. */
82     if ((result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE, 
83                               __Zephyr_realm, &cred)) != 0)
84         return result;
85     checksum = des_quad_cksum(buffer, NULL, cstart - buffer, 0, cred.session);
86     checksum ^= des_quad_cksum(cend, NULL, buffer + *len - cend, 0,
87                                cred.session);
88     checksum ^= des_quad_cksum(notice->z_message, NULL, notice->z_message_len,
89                                0, cred.session);
90     notice->z_checksum = checksum;
91     ZMakeAscii32(cstart, buffer + buffer_len - cstart, checksum);
92
93     return (ZERR_NONE);
94 #else
95     notice->z_checksum = 0;
96     notice->z_auth = 1;
97     notice->z_authent_len = 0;
98     notice->z_ascii_authent = "";
99     return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL));
100 #endif
101 }