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));
95 lock_ReleaseMutex(&tokenEventLock);
100 * RPC manager entry point vector functions
103 long AFSRPC_SetToken(
105 unsigned char __RPC_FAR sessionKey[8])
107 cm_RegisterNewTokenEvent(uuid, sessionKey);
111 long AFSRPC_GetToken(
113 unsigned char __RPC_FAR sessionKey[8])
117 found = cm_FindTokenEvent(uuid, sessionKey);
124 void __RPC_FAR * __RPC_USER midl_user_allocate (size_t cBytes)
126 return ((void __RPC_FAR *) malloc(cBytes));
129 void __RPC_USER midl_user_free(void __RPC_FAR * p)
138 RPC_BINDING_VECTOR *ptrBindingVector = NULL;
139 BOOLEAN ifaceRegistered = FALSE;
140 BOOLEAN epRegistered = FALSE;
142 #ifdef NOOSIDEBUGSERVER /* Use All Protseqs already done in OSI */
144 status = RpcServerUseAllProtseqs(1, NULL);
145 if (status != RPC_S_OK) {
146 task = "Use All Protocol Sequences";
150 #endif /* NOOSIDEBUGSERVER */
152 status = RpcServerRegisterIf(afsrpc_v1_0_s_ifspec, NULL, NULL);
153 if (status != RPC_S_OK) {
154 task = "Register Interface";
157 ifaceRegistered = TRUE;
159 status = RpcServerInqBindings(&ptrBindingVector);
160 if (status != RPC_S_OK) {
161 task = "Inquire Bindings";
165 status = RpcServerRegisterAuthInfo(NULL, RPC_C_AUTHN_WINNT, NULL, NULL);
166 if (status != RPC_S_OK) {
167 task = "Register Authentication Info";
171 status = RpcEpRegister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
172 NULL, "AFS session key interface");
173 if (status != RPC_S_OK) {
174 task = "Register Endpoints";
179 afsi_log("RPC server listening");
181 status = RpcServerListen(OSI_MAXRPCCALLS, OSI_MAXRPCCALLS, 0);
182 if (status != RPC_S_OK) {
183 task = "Server Listen";
188 (void) RpcEpUnregister(afsrpc_v1_0_s_ifspec, ptrBindingVector,
191 if (ptrBindingVector)
192 (void) RpcBindingVectorFree(&ptrBindingVector);
195 (void) RpcServerUnregisterIf(afsrpc_v1_0_s_ifspec, NULL, FALSE);
197 if (status != RPC_S_OK)
198 afsi_log("RPC problem, code %d for %s", status, task);
205 LONG status = ERROR_SUCCESS;
207 ULONG listenThreadID = 0;
209 lock_InitializeMutex(&tokenEventLock, "token event lock");
211 listenThread = CreateThread(NULL, 0, (PTHREAD_START_ROUTINE)RpcListen,
212 0, 0, &listenThreadID);
214 if (listenThread == NULL) {
215 status = GetLastError();
217 CloseHandle(listenThread);