2 * Copyright 2000, International Business Machines Corporation and others.
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
10 /* These routines provide an interface to the token cache maintained by the
11 kernel. Principally it handles cache misses by requesting the desired token
12 from the AuthServer. */
14 #include <afsconfig.h>
16 #include "afs/param.h"
18 #include <afs/param.h>
25 #include "afs/sysincludes.h"
26 #include "afsincludes.h"
29 #include "afs/pthread_glock.h"
32 #include "afs/kauth.h"
33 #include "afs/kautils.h"
35 #include "afs/pthread_glock.h"
36 #else /* defined(UKERNEL) */
38 #include <sys/types.h>
40 #include <afs/pthread_glock.h>
44 #include <sys/socket.h>
45 #include <netinet/in.h>
54 /* netinet/in.h and cellconfig.h are needed together */
55 #include <afs/cellconfig.h>
56 /* these are needed together */
63 #endif /* defined(UKERNEL) */
67 ka_GetAuthToken(char *name, char *instance, char *cell,
68 struct ktc_encryptionKey * key, afs_int32 lifetime,
69 afs_int32 * pwexpires)
72 struct ubik_client *conn;
73 afs_int32 now = time(0);
74 struct ktc_token token;
75 char cellname[MAXKTCREALMLEN];
76 char realm[MAXKTCREALMLEN];
77 struct ktc_principal client, server;
80 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
87 /* get an unauthenticated connection to desired cell */
88 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
94 ka_Authenticate(name, instance, cell, conn,
95 KA_TICKET_GRANTING_SERVICE, key, now, now + lifetime,
101 code = ubik_ClientDestroy(conn);
107 code = ka_CellToRealm(cell, realm, 0 /*local */ );
112 strcpy(client.name, name);
113 strcpy(client.instance, instance);
114 strncpy(client.cell, cell, sizeof(client.cell));
115 strcpy(server.name, KA_TGS_NAME);
116 strcpy(server.instance, realm);
117 strcpy(server.cell, cell);
118 code = ktc_SetToken(&server, &token, &client, 0);
124 ka_GetServerToken(char *name, char *instance, char *cell, Date lifetime,
125 struct ktc_token * token, int new, int dosetpag)
128 struct ubik_client *conn;
129 afs_int32 now = time(0);
130 struct ktc_token auth_token;
131 struct ktc_token cell_token;
132 struct ktc_principal server, auth_server, client;
133 char *localCell = ka_LocalCell();
134 char cellname[MAXKTCREALMLEN];
135 char realm[MAXKTCREALMLEN];
136 char authDomain[MAXKTCREALMLEN];
140 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
147 strcpy(server.name, name);
148 strcpy(server.instance, instance);
149 lcstring(server.cell, cell, sizeof(server.cell));
152 ktc_GetToken(&server, token, sizeof(struct ktc_token), &client);
159 code = ka_CellToRealm(cell, realm, &local);
165 /* get TGS ticket for proper realm */
166 strcpy(auth_server.name, KA_TGS_NAME);
167 strcpy(auth_server.instance, realm);
168 lcstring(auth_server.cell, realm, sizeof(auth_server.cell));
169 strcpy(authDomain, realm);
171 ktc_GetToken(&auth_server, &auth_token, sizeof(auth_token), &client);
172 if (code && !local) { /* try for remotely authenticated ticket */
173 strcpy(auth_server.cell, localCell);
174 strcpy(authDomain, "");
176 ktc_GetToken(&auth_server, &auth_token, sizeof(auth_token),
184 /* here we invoke the inter-cell mechanism */
186 /* get local auth ticket */
187 ucstring(auth_server.instance, localCell,
188 sizeof(auth_server.instance));
189 strcpy(auth_server.cell, localCell);
191 ktc_GetToken(&auth_server, &cell_token, sizeof(cell_token),
197 /* get a connection to the local cell */
199 ka_AuthServerConn(localCell, KA_TICKET_GRANTING_SERVICE, 0,
204 /* get foreign auth ticket */
206 ka_GetToken(KA_TGS_NAME, realm, localCell, client.name,
207 client.instance, conn, now, now + lifetime,
208 &cell_token, "" /* local auth domain */ ,
213 code = ubik_ClientDestroy(conn);
220 /* save foreign auth ticket */
221 strcpy(auth_server.instance, realm);
222 lcstring(auth_server.cell, localCell, sizeof(auth_server.cell));
223 ucstring(authDomain, localCell, sizeof(authDomain));
224 if ((code = ktc_SetToken(&auth_server, &auth_token, &client, 0))) {
231 ka_AuthServerConn(cell, KA_TICKET_GRANTING_SERVICE, 0, &conn))) {
236 ka_GetToken(name, instance, cell, client.name, client.instance, conn,
237 now, now + lifetime, &auth_token, authDomain, token))) {
241 code = ubik_ClientDestroy(conn);
248 ktc_SetToken(&server, token, &client,
249 dosetpag ? AFS_SETTOK_SETPAG : 0))) {
258 ka_GetAdminToken(char *name, char *instance, char *cell,
259 struct ktc_encryptionKey * key, afs_int32 lifetime,
260 struct ktc_token * token, int new)
263 struct ubik_client *conn;
264 afs_int32 now = time(0);
265 struct ktc_principal server, client;
266 struct ktc_token localToken;
267 char cellname[MAXKTCREALMLEN];
270 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
278 token = &localToken; /* in case caller doesn't want token */
280 strcpy(server.name, KA_ADMIN_NAME);
281 strcpy(server.instance, KA_ADMIN_INST);
282 strncpy(server.cell, cell, sizeof(server.cell));
285 ktc_GetToken(&server, token, sizeof(struct ktc_token), &client);
292 if ((name == 0) || (key == 0)) {
293 /* just lookup in cache don't get new one */
298 /* get an unauthenticated connection to desired cell */
299 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
305 ka_Authenticate(name, instance, cell, conn, KA_MAINTENANCE_SERVICE,
306 key, now, now + lifetime, token, 0);
307 (void)ubik_ClientDestroy(conn);
313 strcpy(client.name, name);
314 strcpy(client.instance, instance);
315 strncpy(client.cell, cell, sizeof(client.cell));
316 code = ktc_SetToken(&server, token, &client, 0);
323 ka_VerifyUserToken(char *name, char *instance, char *cell,
324 struct ktc_encryptionKey * key)
327 struct ubik_client *conn;
328 afs_int32 now = time(0);
329 struct ktc_token token;
330 char cellname[MAXKTCREALMLEN];
334 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
342 /* get an unauthenticated connection to desired cell */
343 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
350 ka_Authenticate(name, instance, cell, conn,
351 KA_TICKET_GRANTING_SERVICE, key, now,
352 now + MAXKTCTICKETLIFETIME, &token, &pwexpires);
357 code = ubik_ClientDestroy(conn);