]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZCkAuth.c
r4254@bucket (orig r244): kcr | 2008-01-20 14:40:42 -0500
[1ts-debian.git] / zephyr / lib / ZCkAuth.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZCheckAuthentication function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987,1991 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #ifndef lint
14 static char rcsid_ZCheckAuthentication_c[] =
15     "$Zephyr: /mit/zephyr/src/lib/RCS/ZCheckAuthentication.c,v 1.14 89/03/24 14:17:38 jtkohl Exp Locker: raeburn $";
16 #endif
17
18 #include <internal.h>
19
20 #if defined(HAVE_KRB5) && !HAVE_KRB5_FREE_DATA
21 #define krb5_free_data(ctx, dat) free((dat)->data)
22 #endif
23
24 /* Check authentication of the notice.
25    If it looks authentic but fails the Kerberos check, return -1.
26    If it looks authentic and passes the Kerberos check, return 1.
27    If it doesn't look authentic, return 0
28
29    When not using Kerberos, return true if the notice claims to be authentic.
30    Only used by clients; the server uses its own routine.
31  */
32 Code_t
33 ZCheckAuthentication(ZNotice_t *notice,
34                      struct sockaddr_in *from)
35 {
36 #if 0
37 #if defined(HAVE_KRB4) || defined(HAVE_KRB5)
38     int result;
39     ZChecksum_t our_checksum;
40     C_Block *session;
41 #ifdef HAVE_KRB5
42     krb5_creds *creds_out;
43 #else
44     CREDENTIALS cred;
45 #endif
46     /* If the value is already known, return it. */
47     if (notice->z_checked_auth != ZAUTH_UNSET)
48         return (notice->z_checked_auth);
49
50     if (!notice->z_auth)
51         return (ZAUTH_NO);
52
53 #ifdef HAVE_KRB5
54     result = ZGetCreds(&creds_out);
55     if (result)
56       return ZAUTH_NO;
57     /* HOLDING: creds_out */
58
59     if (creds_out->keyblock.enctype != ENCTYPE_DES_CBC_CRC)
60       return (ZAUTH_NO);
61     session = (C_Block *)creds_out->keyblock.contents;
62     
63 #else
64     if ((result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE, 
65                                __Zephyr_realm, &cred)) != 0)
66         return (ZAUTH_NO);
67
68     session = (C_Block *)cred.session;
69 #endif
70
71 #ifdef NOENCRYPTION
72     our_checksum = 0;
73 #else
74     our_checksum = des_quad_cksum(notice->z_packet, NULL, 
75                                   notice->z_default_format+
76                                   strlen(notice->z_default_format)+1-
77                                   notice->z_packet, 0, session);
78 #endif
79     /* if mismatched checksum, then the packet was corrupted */
80     return ((our_checksum == notice->z_checksum) ? ZAUTH_YES : ZAUTH_FAILED);
81
82 #else
83     return (notice->z_auth ? ZAUTH_YES : ZAUTH_NO);
84 #endif
85 #else
86     ZCheckZcodeAuthentication(notice, from);
87 #endif
88