]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZCkAuth.c
17fdc2b6e270678184525825970669c33df60c8e
[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 /* Check authentication of the notice.
21    If it looks authentic but fails the Kerberos check, return -1.
22    If it looks authentic and passes the Kerberos check, return 1.
23    If it doesn't look authentic, return 0
24
25    When not using Kerberos, return true if the notice claims to be authentic.
26    Only used by clients; the server uses its own routine.
27  */
28 Code_t ZCheckAuthentication(notice, from)
29     ZNotice_t *notice;
30     struct sockaddr_in *from;
31 {       
32 #ifdef HAVE_KRB4
33     int result;
34     ZChecksum_t our_checksum;
35     CREDENTIALS cred;
36
37     /* If the value is already known, return it. */
38     if (notice->z_checked_auth != ZAUTH_UNSET)
39         return (notice->z_checked_auth);
40
41     if (!notice->z_auth)
42         return (ZAUTH_NO);
43         
44     if ((result = krb_get_cred(SERVER_SERVICE, SERVER_INSTANCE, 
45                                __Zephyr_realm, &cred)) != 0)
46         return (ZAUTH_NO);
47
48 #ifdef NOENCRYPTION
49     our_checksum = 0;
50 #else
51     our_checksum = des_quad_cksum(notice->z_packet, NULL, 
52                                   notice->z_default_format+
53                                   strlen(notice->z_default_format)+1-
54                                   notice->z_packet, 0, cred.session);
55 #endif
56     /* if mismatched checksum, then the packet was corrupted */
57     return ((our_checksum == notice->z_checksum) ? ZAUTH_YES : ZAUTH_FAILED);
58
59 #else
60     return (notice->z_auth ? ZAUTH_YES : ZAUTH_NO);
61 #endif
62