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>
15 #include <afs/param.h>
21 # include "afsincludes.h"
25 #include <afs/pthread_glock.h>
26 #include <afs/cellconfig.h>
36 ka_GetAuthToken(char *name, char *instance, char *cell,
37 struct ktc_encryptionKey * key, afs_int32 lifetime,
38 afs_int32 * pwexpires)
41 struct ubik_client *conn;
42 afs_int32 now = time(0);
43 struct ktc_token token;
44 char cellname[MAXKTCREALMLEN];
45 char realm[MAXKTCREALMLEN];
46 struct ktc_principal client, server;
49 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
56 /* get an unauthenticated connection to desired cell */
57 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
63 ka_Authenticate(name, instance, cell, conn,
64 KA_TICKET_GRANTING_SERVICE, key, now, now + lifetime,
70 code = ubik_ClientDestroy(conn);
76 code = ka_CellToRealm(cell, realm, 0 /*local */ );
81 strcpy(client.name, name);
82 strcpy(client.instance, instance);
83 strncpy(client.cell, cell, sizeof(client.cell));
84 strcpy(server.name, KA_TGS_NAME);
85 strcpy(server.instance, realm);
86 strcpy(server.cell, cell);
87 code = ktc_SetToken(&server, &token, &client, 0);
93 ka_GetServerToken(char *name, char *instance, char *cell, Date lifetime,
94 struct ktc_token * token, int new, int dosetpag)
97 struct ubik_client *conn;
98 afs_int32 now = time(0);
99 struct ktc_token auth_token;
100 struct ktc_token cell_token;
101 struct ktc_principal server, auth_server, client;
102 char *localCell = ka_LocalCell();
103 char cellname[MAXKTCREALMLEN];
104 char realm[MAXKTCREALMLEN];
105 char authDomain[MAXKTCREALMLEN];
109 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
116 strcpy(server.name, name);
117 strcpy(server.instance, instance);
118 lcstring(server.cell, cell, sizeof(server.cell));
121 ktc_GetToken(&server, token, sizeof(struct ktc_token), &client);
128 code = ka_CellToRealm(cell, realm, &local);
134 /* get TGS ticket for proper realm */
135 strcpy(auth_server.name, KA_TGS_NAME);
136 strcpy(auth_server.instance, realm);
137 lcstring(auth_server.cell, realm, sizeof(auth_server.cell));
138 strcpy(authDomain, realm);
140 ktc_GetToken(&auth_server, &auth_token, sizeof(auth_token), &client);
141 if (code && !local) { /* try for remotely authenticated ticket */
142 strcpy(auth_server.cell, localCell);
143 strcpy(authDomain, "");
145 ktc_GetToken(&auth_server, &auth_token, sizeof(auth_token),
153 /* here we invoke the inter-cell mechanism */
155 /* get local auth ticket */
156 ucstring(auth_server.instance, localCell,
157 sizeof(auth_server.instance));
158 strcpy(auth_server.cell, localCell);
160 ktc_GetToken(&auth_server, &cell_token, sizeof(cell_token),
166 /* get a connection to the local cell */
168 ka_AuthServerConn(localCell, KA_TICKET_GRANTING_SERVICE, 0,
173 /* get foreign auth ticket */
175 ka_GetToken(KA_TGS_NAME, realm, localCell, client.name,
176 client.instance, conn, now, now + lifetime,
177 &cell_token, "" /* local auth domain */ ,
182 code = ubik_ClientDestroy(conn);
189 /* save foreign auth ticket */
190 strcpy(auth_server.instance, realm);
191 lcstring(auth_server.cell, localCell, sizeof(auth_server.cell));
192 ucstring(authDomain, localCell, sizeof(authDomain));
193 if ((code = ktc_SetToken(&auth_server, &auth_token, &client, 0))) {
200 ka_AuthServerConn(cell, KA_TICKET_GRANTING_SERVICE, 0, &conn))) {
205 ka_GetToken(name, instance, cell, client.name, client.instance, conn,
206 now, now + lifetime, &auth_token, authDomain, token))) {
210 code = ubik_ClientDestroy(conn);
217 ktc_SetToken(&server, token, &client,
218 dosetpag ? AFS_SETTOK_SETPAG : 0))) {
227 ka_GetAdminToken(char *name, char *instance, char *cell,
228 struct ktc_encryptionKey * key, afs_int32 lifetime,
229 struct ktc_token * token, int new)
232 struct ubik_client *conn;
233 afs_int32 now = time(0);
234 struct ktc_principal server, client;
235 struct ktc_token localToken;
236 char cellname[MAXKTCREALMLEN];
239 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
247 token = &localToken; /* in case caller doesn't want token */
249 strcpy(server.name, KA_ADMIN_NAME);
250 strcpy(server.instance, KA_ADMIN_INST);
251 strncpy(server.cell, cell, sizeof(server.cell));
254 ktc_GetToken(&server, token, sizeof(struct ktc_token), &client);
261 if ((name == 0) || (key == 0)) {
262 /* just lookup in cache don't get new one */
267 /* get an unauthenticated connection to desired cell */
268 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
274 ka_Authenticate(name, instance, cell, conn, KA_MAINTENANCE_SERVICE,
275 key, now, now + lifetime, token, 0);
276 (void)ubik_ClientDestroy(conn);
282 strcpy(client.name, name);
283 strcpy(client.instance, instance);
284 strncpy(client.cell, cell, sizeof(client.cell));
285 code = ktc_SetToken(&server, token, &client, 0);
292 ka_VerifyUserToken(char *name, char *instance, char *cell,
293 struct ktc_encryptionKey * key)
296 struct ubik_client *conn;
297 afs_int32 now = time(0);
298 struct ktc_token token;
299 char cellname[MAXKTCREALMLEN];
303 code = ka_ExpandCell(cell, cellname, 0 /*local */ );
311 /* get an unauthenticated connection to desired cell */
312 code = ka_AuthServerConn(cell, KA_AUTHENTICATION_SERVICE, 0, &conn);
319 ka_Authenticate(name, instance, cell, conn,
320 KA_TICKET_GRANTING_SERVICE, key, now,
321 now + MAXKTCTICKETLIFETIME, &token, &pwexpires);
326 code = ubik_ClientDestroy(conn);