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>
48 /* netinet/in.h and cellconfig.h are needed together */
49 #include <afs/cellconfig.h>
50 /* these are needed together */
57 #endif /* defined(UKERNEL) */
61 ka_GetAuthToken(char *name, char *instance, char *cell,
62 struct ktc_encryptionKey * key, afs_int32 lifetime,
63 afs_int32 * pwexpires)
66 struct ubik_client *conn;
67 afs_int32 now = time(0);
68 struct ktc_token token;
69 char cellname[MAXKTCREALMLEN];
70 char realm[MAXKTCREALMLEN];
71 struct ktc_principal client, server;
74 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
81 /* get an unauthenticated connection to desired cell */
82 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
88 ka_Authenticate(name, instance, cell, conn,
89 KA_TICKET_GRANTING_SERVICE, key, now, now + lifetime,
95 code = ubik_ClientDestroy(conn);
101 code = ka_CellToRealm(cell, realm, 0 /*local */ );
106 strcpy(client.name, name);
107 strcpy(client.instance, instance);
108 strncpy(client.cell, cell, sizeof(client.cell));
109 strcpy(server.name, KA_TGS_NAME);
110 strcpy(server.instance, realm);
111 strcpy(server.cell, cell);
112 code = ktc_SetToken(&server, &token, &client, 0);
118 ka_GetServerToken(char *name, char *instance, char *cell, Date lifetime,
119 struct ktc_token * token, int new, int dosetpag)
122 struct ubik_client *conn;
123 afs_int32 now = time(0);
124 struct ktc_token auth_token;
125 struct ktc_token cell_token;
126 struct ktc_principal server, auth_server, client;
127 char *localCell = ka_LocalCell();
128 char cellname[MAXKTCREALMLEN];
129 char realm[MAXKTCREALMLEN];
130 char authDomain[MAXKTCREALMLEN];
134 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
141 strcpy(server.name, name);
142 strcpy(server.instance, instance);
143 lcstring(server.cell, cell, sizeof(server.cell));
146 ktc_GetToken(&server, token, sizeof(struct ktc_token), &client);
153 code = ka_CellToRealm(cell, realm, &local);
159 /* get TGS ticket for proper realm */
160 strcpy(auth_server.name, KA_TGS_NAME);
161 strcpy(auth_server.instance, realm);
162 lcstring(auth_server.cell, realm, sizeof(auth_server.cell));
163 strcpy(authDomain, realm);
165 ktc_GetToken(&auth_server, &auth_token, sizeof(auth_token), &client);
166 if (code && !local) { /* try for remotely authenticated ticket */
167 strcpy(auth_server.cell, localCell);
168 strcpy(authDomain, "");
170 ktc_GetToken(&auth_server, &auth_token, sizeof(auth_token),
178 /* here we invoke the inter-cell mechanism */
180 /* get local auth ticket */
181 ucstring(auth_server.instance, localCell,
182 sizeof(auth_server.instance));
183 strcpy(auth_server.cell, localCell);
185 ktc_GetToken(&auth_server, &cell_token, sizeof(cell_token),
191 /* get a connection to the local cell */
193 ka_AuthServerConn(localCell, KA_TICKET_GRANTING_SERVICE, 0,
198 /* get foreign auth ticket */
200 ka_GetToken(KA_TGS_NAME, realm, localCell, client.name,
201 client.instance, conn, now, now + lifetime,
202 &cell_token, "" /* local auth domain */ ,
207 code = ubik_ClientDestroy(conn);
214 /* save foreign auth ticket */
215 strcpy(auth_server.instance, realm);
216 lcstring(auth_server.cell, localCell, sizeof(auth_server.cell));
217 ucstring(authDomain, localCell, sizeof(authDomain));
218 if ((code = ktc_SetToken(&auth_server, &auth_token, &client, 0))) {
225 ka_AuthServerConn(cell, KA_TICKET_GRANTING_SERVICE, 0, &conn))) {
230 ka_GetToken(name, instance, cell, client.name, client.instance, conn,
231 now, now + lifetime, &auth_token, authDomain, token))) {
235 code = ubik_ClientDestroy(conn);
242 ktc_SetToken(&server, token, &client,
243 dosetpag ? AFS_SETTOK_SETPAG : 0))) {
252 ka_GetAdminToken(char *name, char *instance, char *cell,
253 struct ktc_encryptionKey * key, afs_int32 lifetime,
254 struct ktc_token * token, int new)
257 struct ubik_client *conn;
258 afs_int32 now = time(0);
259 struct ktc_principal server, client;
260 struct ktc_token localToken;
261 char cellname[MAXKTCREALMLEN];
264 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
272 token = &localToken; /* in case caller doesn't want token */
274 strcpy(server.name, KA_ADMIN_NAME);
275 strcpy(server.instance, KA_ADMIN_INST);
276 strncpy(server.cell, cell, sizeof(server.cell));
279 ktc_GetToken(&server, token, sizeof(struct ktc_token), &client);
286 if ((name == 0) || (key == 0)) {
287 /* just lookup in cache don't get new one */
292 /* get an unauthenticated connection to desired cell */
293 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
299 ka_Authenticate(name, instance, cell, conn, KA_MAINTENANCE_SERVICE,
300 key, now, now + lifetime, token, 0);
301 (void)ubik_ClientDestroy(conn);
307 strcpy(client.name, name);
308 strcpy(client.instance, instance);
309 strncpy(client.cell, cell, sizeof(client.cell));
310 code = ktc_SetToken(&server, token, &client, 0);
317 ka_VerifyUserToken(char *name, char *instance, char *cell,
318 struct ktc_encryptionKey * key)
321 struct ubik_client *conn;
322 afs_int32 now = time(0);
323 struct ktc_token token;
324 char cellname[MAXKTCREALMLEN];
328 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
336 /* get an unauthenticated connection to desired cell */
337 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
344 ka_Authenticate(name, instance, cell, conn,
345 KA_TICKET_GRANTING_SERVICE, key, now,
346 now + MAXKTCTICKETLIFETIME, &token, &pwexpires);
351 code = ubik_ClientDestroy(conn);