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>
24 osi_rwlock_t cm_userLock;
26 cm_user_t *cm_rootUserp;
28 void cm_InitUser(void)
30 static osi_once_t once;
32 if (osi_Once(&once)) {
33 lock_InitializeRWLock(&cm_userLock, "cm_userLock");
37 cm_rootUserp = cm_NewUser();
40 cm_user_t *cm_NewUser(void)
44 up = malloc(sizeof(*up));
45 memset(up, 0, sizeof(*up));
47 up->vcRefs = 1; /* from caller */
48 lock_InitializeMutex(&up->mx, "cm_user_t");
52 /* must be called with locked userp */
53 cm_ucell_t *cm_GetUCell(cm_user_t *userp, cm_cell_t *cellp)
57 lock_AssertMutex(&userp->mx);
58 for(ucp = userp->cellInfop; ucp; ucp=ucp->nextp) {
59 if (ucp->cellp == cellp) break;
63 ucp = malloc(sizeof(*ucp));
64 memset(ucp, 0, sizeof(*ucp));
65 ucp->nextp = userp->cellInfop;
67 ucp->iterator = userp->cellInfop->iterator + 1;
70 userp->cellInfop = ucp;
77 cm_ucell_t *cm_FindUCell(cm_user_t *userp, int iterator)
83 lock_AssertMutex(&userp->mx);
84 for (ucp = userp->cellInfop; ucp; ucp = ucp->nextp) {
85 if (ucp->iterator >= iterator)
93 void cm_HoldUser(cm_user_t *up)
95 lock_ObtainWrite(&cm_userLock);
97 lock_ReleaseWrite(&cm_userLock);
100 void cm_ReleaseUser(cm_user_t *up)
105 if (up == NULL) return;
107 lock_ObtainWrite(&cm_userLock);
108 osi_assert(up->refCount-- > 0);
109 if (up->refCount == 0) {
110 lock_FinalizeMutex(&up->mx);
111 for(ucp = up->cellInfop; ucp; ucp = ncp) {
113 if (ucp->ticketp) free(ucp->ticketp);
118 lock_ReleaseWrite(&cm_userLock);
121 /* release the count of the # of connections that use this user structure.
122 * When this hits zero, we know we won't be getting an new requests from
123 * this user, and thus we can start GC'ing connections. Ref count on user
124 * won't hit zero until all cm_conn_t's have been GC'd, since they hold
125 * refCount references to userp.
127 void cm_ReleaseUserVCRef(cm_user_t *userp)
129 lock_ObtainMutex(&userp->mx);
130 osi_assert(userp->vcRefs-- > 0);
131 lock_ReleaseMutex(&userp->mx);
136 * Check if any users' tokens have expired and if they have then do the
137 * equivalent of unlogging the user for that particular cell for which
138 * the tokens have expired.
139 * ref. cm_IoctlDelToken() in cm_ioctl.c
140 * This routine is called by the cm_Daemon() ie. the periodic daemon.
141 * every cm_daemonTokenCheckInterval seconds
143 void cm_CheckTokenCache(long now)
145 extern smb_vc_t *smb_allVCsp; /* global vcp list */
148 cm_user_t *userp = NULL;
153 * For every vcp, get the user and check his tokens
155 lock_ObtainWrite(&smb_rctLock);
156 for(vcp=smb_allVCsp; vcp; vcp=vcp->nextp) {
157 for(usersp=vcp->usersp; usersp; usersp=usersp->nextp) {
\r
159 if ((userp=usersp->unp->userp)==0)
\r
163 lock_ObtainMutex(&userp->mx);
164 for(ucellp=userp->cellInfop; ucellp; ucellp=ucellp->nextp) {
165 if(ucellp->flags & CM_UCELLFLAG_RXKAD) {
166 if(ucellp->expirationTime < now) {
167 /* this guy's tokens have expired */
168 osi_Log3(afsd_logp, "cm_CheckTokens: Tokens for user:%s have expired expiration time:0x%x ucellp:%x", ucellp->userName, ucellp->expirationTime, ucellp);
169 if (ucellp->ticketp) {
170 free(ucellp->ticketp);
171 ucellp->ticketp = NULL;
173 ucellp->flags &= ~CM_UCELLFLAG_RXKAD;
179 lock_ReleaseMutex(&userp->mx);
182 cm_ResetACLCache(userp);
186 lock_ReleaseWrite(&smb_rctLock);