Mercurial > pidgin
annotate src/protocols/zephyr/ZMkAuth.c @ 11933:1b0c83666f98
[gaim-migrate @ 14224]
The mixed whitespace in this file was confusing Evan. I also cleaned up a couple other stylistic things.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 31 Oct 2005 20:33:13 +0000 |
parents | 64895571248f |
children | 7c2e2c4d45a4 |
rev | line source |
---|---|
2086 | 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 * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
7 * For copying and distribution information, see the file | |
8 * "mit-copyright.h". | |
9 */ | |
10 | |
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
8354
diff
changeset
|
11 #include "internal.h" |
2086 | 12 |
10867 | 13 #ifndef ERROR_TABLE_BASE_krb |
14 #define ERROR_TABLE_BASE_krb (39525376L) | |
2086 | 15 #endif |
16 | |
17 #ifdef ZEPHYR_USES_KERBEROS | |
10867 | 18 #ifdef WIN32 |
19 | |
20 #else | |
2086 | 21 #include <krb_err.h> |
10867 | 22 #endif |
2086 | 23 static long last_authent_time = 0L; |
24 static KTEXT_ST last_authent; | |
25 #endif | |
26 | |
27 Code_t ZResetAuthentication () { | |
28 #ifdef ZEPHYR_USES_KERBEROS | |
29 last_authent_time = 0L; | |
30 #endif | |
31 return ZERR_NONE; | |
32 } | |
33 | |
34 Code_t ZMakeAuthentication(notice, buffer, buffer_len, len) | |
35 register ZNotice_t *notice; | |
36 char *buffer; | |
37 int buffer_len; | |
38 int *len; | |
39 { | |
40 #ifdef ZEPHYR_USES_KERBEROS | |
41 int result; | |
42 time_t now; | |
43 KTEXT_ST authent; | |
44 char *cstart, *cend; | |
45 ZChecksum_t checksum; | |
46 CREDENTIALS cred; | |
47 extern unsigned long des_quad_cksum(); | |
48 | |
49 now = time(0); | |
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; | |
8217 | 55 return (result+ERROR_TABLE_BASE_krb); |
2086 | 56 } |
57 last_authent_time = now; | |
58 last_authent = authent; | |
59 } | |
60 else { | |
61 authent = last_authent; | |
62 } | |
63 notice->z_auth = 1; | |
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) | |
68 return (ENOMEM); | |
69 if ((result = ZMakeAscii(notice->z_ascii_authent, | |
70 authent.length*3, | |
71 authent.dat, | |
72 authent.length)) != ZERR_NONE) { | |
73 free(notice->z_ascii_authent); | |
74 return (result); | |
75 } | |
76 result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart, | |
77 &cend); | |
78 free(notice->z_ascii_authent); | |
79 notice->z_authent_len = 0; | |
80 if (result) | |
81 return(result); | |
82 | |
83 /* Compute a checksum over the header and message. */ | |
84 if ((result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE, | |
85 __Zephyr_realm, &cred)) != 0) | |
86 return result; | |
8354 | 87 checksum = des_quad_cksum(buffer, NULL, cstart - buffer, 0, (C_Block *)cred.session); |
2086 | 88 checksum ^= des_quad_cksum(cend, NULL, buffer + *len - cend, 0, |
8354 | 89 (C_Block *)cred.session); |
2086 | 90 checksum ^= des_quad_cksum(notice->z_message, NULL, notice->z_message_len, |
8354 | 91 0, (C_Block *)cred.session); |
2086 | 92 notice->z_checksum = checksum; |
93 ZMakeAscii32(cstart, buffer + buffer_len - cstart, checksum); | |
94 | |
95 return (ZERR_NONE); | |
96 #else | |
97 notice->z_checksum = 0; | |
98 notice->z_auth = 1; | |
99 notice->z_authent_len = 0; | |
100 notice->z_ascii_authent = ""; | |
101 return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL)); | |
102 #endif | |
103 } |