kauth warning reduction
[openafs.git] / src / auth / authcon.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #if defined(UKERNEL)
12 #include "afs/param.h"
13 #else
14 #include <afs/param.h>
15 #endif
16
17
18 #if defined(UKERNEL)
19 #include "afs/sysincludes.h"
20 #include "afsincludes.h"
21 #include "afs/stds.h"
22 #include "afs/pthread_glock.h"
23 #include "rx/rxkad.h"
24 #include "rx/rx.h"
25 #include "afs/cellconfig.h"
26 #include "afs/keys.h"
27 #include "afs/auth.h"
28 #include "afs/pthread_glock.h"
29 #else /* defined(UKERNEL) */
30 #include <afs/stds.h>
31 #include <afs/pthread_glock.h>
32 #include <sys/types.h>
33 #ifdef AFS_NT40_ENV
34 #include <winsock2.h>
35 #else
36 #include <sys/file.h>
37 #include <sys/time.h>
38 #include <netinet/in.h>
39 #include <netdb.h>
40 #endif
41 #include <string.h>
42 #include <stdio.h>
43 #include <des.h>
44 #include <des_prototypes.h>
45 #include <rx/rxkad.h>
46 #include <rx/rx.h>
47 #include "cellconfig.h"
48 #include "keys.h"
49 #include "auth.h"
50 #endif /* defined(UKERNEL) */
51
52 /* return a null security object if nothing else can be done */
53 static afs_int32
54 QuickAuth(struct rx_securityClass **astr, afs_int32 *aindex)
55 {
56     register struct rx_securityClass *tc;
57     tc = rxnull_NewClientSecurityObject();
58     *astr = tc;
59     *aindex = 0;
60     return 0;
61 }
62
63 #if !defined(UKERNEL)
64 /* Return an appropriate security class and index */
65 afs_int32
66 afsconf_ServerAuth(void *arock,
67                    struct rx_securityClass **astr, 
68                    afs_int32 *aindex)
69 {
70     struct afsconf_dir *adir = (struct afsconf_dir *) arock;
71     register struct rx_securityClass *tclass;
72
73     LOCK_GLOBAL_MUTEX;
74     tclass = (struct rx_securityClass *)
75         rxkad_NewServerSecurityObject(0, adir, afsconf_GetKey, NULL);
76     if (tclass) {
77         *astr = tclass;
78         *aindex = 2;            /* kerberos security index */
79         UNLOCK_GLOBAL_MUTEX;
80         return 0;
81     } else {
82         UNLOCK_GLOBAL_MUTEX;
83         return 2;
84     }
85 }
86 #endif /* !defined(UKERNEL) */
87
88 static afs_int32
89 GenericAuth(struct afsconf_dir *adir, 
90             struct rx_securityClass **astr, 
91             afs_int32 *aindex, 
92             rxkad_level enclevel)
93 {
94     char tbuffer[256];
95     struct ktc_encryptionKey key, session;
96     struct rx_securityClass *tclass;
97     afs_int32 kvno;
98     afs_int32 ticketLen;
99     register afs_int32 code;
100
101     /* first, find the right key and kvno to use */
102     code = afsconf_GetLatestKey(adir, &kvno, &key);
103     if (code) {
104         return QuickAuth(astr, aindex);
105     }
106
107     /* next create random session key, using key for seed to good random */
108     des_init_random_number_generator(ktc_to_cblock(&key));
109     code = des_random_key(ktc_to_cblock(&session));
110     if (code) {
111         return QuickAuth(astr, aindex);
112     }
113
114     /* now create the actual ticket */
115     ticketLen = sizeof(tbuffer);
116     memset(tbuffer, '\0', sizeof(tbuffer));
117     code =
118         tkt_MakeTicket(tbuffer, &ticketLen, &key, AUTH_SUPERUSER, "", "", 0,
119                        0xffffffff, &session, 0, "afs", "");
120     /* parms were buffer, ticketlen, key to seal ticket with, principal
121      * name, instance and cell, start time, end time, session key to seal
122      * in ticket, inet host, server name and server instance */
123     if (code) {
124         return QuickAuth(astr, aindex);
125     }
126
127     /* Next, we have ticket, kvno and session key, authenticate the connection.
128      * We use a magic # instead of a constant because of basic compilation
129      * order when compiling the system from scratch (rx/rxkad.h isn't installed
130      * yet). */
131     tclass = (struct rx_securityClass *)
132         rxkad_NewClientSecurityObject(enclevel, &session, kvno, ticketLen,
133                                       tbuffer);
134     *astr = tclass;
135     *aindex = 2;                /* kerberos security index */
136     return 0;
137 }
138
139 /* build a fake ticket for 'afs' using keys from adir, returning an
140  * appropriate security class and index
141  */
142 afs_int32
143 afsconf_ClientAuth(void *arock, struct rx_securityClass ** astr,
144                    afs_int32 * aindex)
145 {
146     struct afsconf_dir * adir = (struct afsconf_dir *) arock;
147     afs_int32 rc;
148
149     LOCK_GLOBAL_MUTEX;
150     rc = GenericAuth(adir, astr, aindex, rxkad_clear);
151     UNLOCK_GLOBAL_MUTEX;
152     return rc;
153 }
154
155 /* build a fake ticket for 'afs' using keys from adir, returning an
156  * appropriate security class and index.  This one, unlike the above,
157  * tells rxkad to encrypt the data, too.
158  */
159 afs_int32
160 afsconf_ClientAuthSecure(void *arock, 
161                          struct rx_securityClass **astr, 
162                          afs_int32 *aindex)
163 {
164     struct afsconf_dir *adir = (struct afsconf_dir *) arock;
165     afs_int32 rc;
166
167     LOCK_GLOBAL_MUTEX;
168     rc = GenericAuth(adir, astr, aindex, rxkad_crypt);
169     UNLOCK_GLOBAL_MUTEX;
170     return rc;
171 }