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 #include <afs/param.h>
25 #include "afsd_init.h"
32 * The motivation for this whole module is that in transmitting tokens
33 * between applications and the AFS service, we must not send session keys
34 * in the clear. So the SetToken and GetToken pioctl's also do an RPC using
35 * packet privacy to transmit the session key. The pioctl() generates a UUID
36 * and sends it down, and the RPC sends down the same UUID, so that the service
37 * can match them up. A list of session keys, searched by UUID, is maintained.
40 extern void afsi_log();
42 typedef struct tokenEvent {
45 struct tokenEvent *next;
48 tokenEvent_t *tokenEvents = NULL;
50 osi_mutex_t tokenEventLock;
53 * Add a new uuid and session key to the list.
55 void cm_RegisterNewTokenEvent(
59 tokenEvent_t *te = malloc(sizeof(tokenEvent_t));
61 memcpy(te->sessionKey, sessionKey, sizeof(te->sessionKey));
62 lock_ObtainMutex(&tokenEventLock);
63 te->next = tokenEvents;
65 lock_ReleaseMutex(&tokenEventLock);
69 * Find a uuid on the list. If it is there, copy the session key and
70 * destroy the entry, since it is only used once.
72 * Return TRUE if found, FALSE if not found
74 BOOL cm_FindTokenEvent(afs_uuid_t uuid, char sessionKey[8])
80 lock_ObtainMutex(&tokenEventLock);
84 if (UuidEqual((UUID *)&uuid, (UUID *)&te->uuid, &status))
86 lock_ReleaseMutex(&tokenEventLock);
87 memcpy(sessionKey, te->sessionKey,
88 sizeof(te->sessionKey));
94 lock_ReleaseMutex(&tokenEventLock);
99 * RPC manager entry point vector functions
102 long AFSRPC_SetToken(
104 unsigned char __RPC_FAR sessionKey[8])
106 cm_RegisterNewTokenEvent(uuid, sessionKey);
110 long AFSRPC_GetToken(
112 unsigned char __RPC_FAR sessionKey[8])
116 found = cm_FindTokenEvent(uuid, sessionKey);
123 void __RPC_FAR * __RPC_USER midl_user_allocate (size_t cBytes)
125 return ((void __RPC_FAR *) malloc(cBytes));
128 void __RPC_USER midl_user_free(void __RPC_FAR * p)
137 RPC_BINDING_VECTOR *ptrBindingVector = NULL;
138 BOOLEAN ifaceRegistered = FALSE;
139 BOOLEAN epRegistered = FALSE;
141 #ifdef NOOSIDEBUGSERVER /* Use All Protseqs already done in OSI */
143 status = RpcServerUseAllProtseqs(1, NULL);
144 if (status != RPC_S_OK) {
145 task = "Use All Protocol Sequences";
149 #endif /* NOOSIDEBUGSERVER */
151 status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL);
152 if (status != RPC_S_OK) {
153 task = "Register Interface";
156 ifaceRegistered = TRUE;
158 status = RpcServerInqBindings(&ptrBindingVector);
159 if (status != RPC_S_OK) {
160 task = "Inquire Bindings";
164 status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL);
165 if (status != RPC_S_OK) {
166 task = "Register Authentication Info";
170 status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
171 NULL, "AFS session key interface");
172 if (status != RPC_S_OK) {
173 task = "Register Endpoints";
178 afsi_log("RPC server listening");
180 status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0);
181 if (status != RPC_S_OK) {
182 task = "Server Listen";
187 (void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
190 if (ptrBindingVector)
191 (void) RpcBindingVectorFree(&ptrBindingVector);
194 (void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE);
196 if (status != RPC_S_OK)
197 afsi_log("RPC problem, code %d for %s", status, task);
204 LONG status = ERROR_SUCCESS;
206 ULONG listenThreadID = 0;
208 lock_InitializeMutex(&tokenEventLock, "token event lock");
210 listenThread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)RpcListen,
211 0, 0, &listenThreadID);
213 if (listenThread == NULL) {
214 status = GetLastError();
216 CloseHandle(listenThread);