Mercurial > pidgin
annotate src/protocols/zephyr/ZMkAuth.c @ 10912:dcbc56eb3f37
[gaim-migrate @ 12667]
Fix bug 1200218 - crash when socks5 password is empty
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Sat, 14 May 2005 13:20:37 +0000 |
| parents | 5727afad0fb8 |
| children | 64895571248f |
| 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 * $Source$ | |
| 10867 | 7 * $Author: thekingant $ |
| 2086 | 8 * |
| 9 * Copyright (c) 1987 by the Massachusetts Institute of Technology. | |
| 10 * For copying and distribution information, see the file | |
| 11 * "mit-copyright.h". | |
| 12 */ | |
| 10867 | 13 /* $Id: ZMkAuth.c 12553 2005-04-25 01:53:01Z thekingant $ */ |
| 2086 | 14 |
|
8792
43d6c08d7e96
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
8354
diff
changeset
|
15 #include "internal.h" |
| 2086 | 16 |
| 17 #ifndef lint | |
| 10867 | 18 static const char rcsid_ZMakeAuthentication_c[] = "$Id: ZMkAuth.c 12553 2005-04-25 01:53:01Z thekingant $"; |
| 19 #endif | |
| 20 | |
| 21 #ifndef ERROR_TABLE_BASE_krb | |
| 22 #define ERROR_TABLE_BASE_krb (39525376L) | |
| 2086 | 23 #endif |
| 24 | |
| 25 #ifdef ZEPHYR_USES_KERBEROS | |
| 10867 | 26 #ifdef WIN32 |
| 27 | |
| 28 #else | |
| 2086 | 29 #include <krb_err.h> |
| 10867 | 30 #endif |
| 2086 | 31 static long last_authent_time = 0L; |
| 32 static KTEXT_ST last_authent; | |
| 33 #endif | |
| 34 | |
| 35 Code_t ZResetAuthentication () { | |
| 36 #ifdef ZEPHYR_USES_KERBEROS | |
| 37 last_authent_time = 0L; | |
| 38 #endif | |
| 39 return ZERR_NONE; | |
| 40 } | |
| 41 | |
| 42 Code_t ZMakeAuthentication(notice, buffer, buffer_len, len) | |
| 43 register ZNotice_t *notice; | |
| 44 char *buffer; | |
| 45 int buffer_len; | |
| 46 int *len; | |
| 47 { | |
| 48 #ifdef ZEPHYR_USES_KERBEROS | |
| 49 int result; | |
| 50 time_t now; | |
| 51 KTEXT_ST authent; | |
| 52 char *cstart, *cend; | |
| 53 ZChecksum_t checksum; | |
| 54 CREDENTIALS cred; | |
| 55 extern unsigned long des_quad_cksum(); | |
| 56 | |
| 57 now = time(0); | |
| 58 if (last_authent_time == 0 || (now - last_authent_time > 120)) { | |
| 59 result = krb_mk_req(&authent, SERVER_SERVICE, | |
| 60 SERVER_INSTANCE, __Zephyr_realm, 0); | |
| 61 if (result != MK_AP_OK) { | |
| 62 last_authent_time = 0; | |
| 8217 | 63 return (result+ERROR_TABLE_BASE_krb); |
| 2086 | 64 } |
| 65 last_authent_time = now; | |
| 66 last_authent = authent; | |
| 67 } | |
| 68 else { | |
| 69 authent = last_authent; | |
| 70 } | |
| 71 notice->z_auth = 1; | |
| 72 notice->z_authent_len = authent.length; | |
| 73 notice->z_ascii_authent = (char *)malloc((unsigned)authent.length*3); | |
| 74 /* zero length authent is an error, so malloc(0) is not a problem */ | |
| 75 if (!notice->z_ascii_authent) | |
| 76 return (ENOMEM); | |
| 77 if ((result = ZMakeAscii(notice->z_ascii_authent, | |
| 78 authent.length*3, | |
| 79 authent.dat, | |
| 80 authent.length)) != ZERR_NONE) { | |
| 81 free(notice->z_ascii_authent); | |
| 82 return (result); | |
| 83 } | |
| 84 result = Z_FormatRawHeader(notice, buffer, buffer_len, len, &cstart, | |
| 85 &cend); | |
| 86 free(notice->z_ascii_authent); | |
| 87 notice->z_authent_len = 0; | |
| 88 if (result) | |
| 89 return(result); | |
| 90 | |
| 91 /* Compute a checksum over the header and message. */ | |
| 92 if ((result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE, | |
| 93 __Zephyr_realm, &cred)) != 0) | |
| 94 return result; | |
| 8354 | 95 checksum = des_quad_cksum(buffer, NULL, cstart - buffer, 0, (C_Block *)cred.session); |
| 2086 | 96 checksum ^= des_quad_cksum(cend, NULL, buffer + *len - cend, 0, |
| 8354 | 97 (C_Block *)cred.session); |
| 2086 | 98 checksum ^= des_quad_cksum(notice->z_message, NULL, notice->z_message_len, |
| 8354 | 99 0, (C_Block *)cred.session); |
| 2086 | 100 notice->z_checksum = checksum; |
| 101 ZMakeAscii32(cstart, buffer + buffer_len - cstart, checksum); | |
| 102 | |
| 103 return (ZERR_NONE); | |
| 104 #else | |
| 105 notice->z_checksum = 0; | |
| 106 notice->z_auth = 1; | |
| 107 notice->z_authent_len = 0; | |
| 108 notice->z_ascii_authent = ""; | |
| 109 return (Z_FormatRawHeader(notice, buffer, buffer_len, len, NULL, NULL)); | |
| 110 #endif | |
| 111 } |
