Replace functions which called once with their bodies
[pidgin-git.git] / libpurple / protocols / zephyr / ZMkAuth.c
blobdc9d1d5bfab8e0282c07f72e2b87c0b3c6854c08
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
8 * "mit-copyright.h".
9 */
11 #include "internal.h"
13 #ifndef ERROR_TABLE_BASE_krb
14 #define ERROR_TABLE_BASE_krb (39525376L)
15 #endif
17 #ifdef ZEPHYR_USES_KERBEROS
18 #ifdef WIN32
20 #else
21 #include <krb_err.h>
22 #endif
23 static long last_authent_time = 0L;
24 static KTEXT_ST last_authent;
25 #endif
27 Code_t ZMakeAuthentication(notice, buffer, buffer_len, len)
28 register ZNotice_t *notice;
29 char *buffer;
30 int buffer_len;
31 int *len;
33 #ifdef ZEPHYR_USES_KERBEROS
34 int result;
35 time_t now;
36 KTEXT_ST authent;
37 char *cstart, *cend;
38 ZChecksum_t checksum;
39 CREDENTIALS cred;
40 extern unsigned long des_quad_cksum();
42 now = time(0);
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;
53 else {
54 authent = last_authent;
56 notice->z_auth = 1;
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)
61 return (ENOMEM);
62 if ((result = ZMakeAscii(notice->z_ascii_authent,
63 authent.length*3,
64 authent.dat,
65 authent.length)) != ZERR_NONE) {
66 free(notice->z_ascii_authent);
67 return (result);
69 result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart,
70 &cend);
71 free(notice->z_ascii_authent);
72 notice->z_authent_len = 0;
73 if (result)
74 return(result);
76 /* Compute a checksum over the header and message. */
77 if ((result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE,
78 __Zephyr_realm, &cred)) != 0)
79 return result;
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);
88 return (ZERR_NONE);
89 #else
90 notice->z_checksum = 0;
91 notice->z_auth = 1;
92 notice->z_authent_len = 0;
93 notice->z_ascii_authent = "";
94 return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL));
95 #endif