4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Windows to Solaris Identity Mapping
29 * This module provides the libidmap idmap_cache.
33 #include <sys/types.h>
38 #include <sys/idmap.h>
41 #include <rpcsvc/idmap_prot.h>
42 #include "idmap_cache.h"
46 * Internal definitions and functions
49 #define CACHE_UID_TRIGGER_SIZE 4096
50 #define CACHE_GID_TRIGGER_SIZE 2048
51 #define CACHE_UID_GID_TRIGGER_SIZE \
52 (CACHE_UID_TRIGGER_SIZE + CACHE_GID_TRIGGER_SIZE)
55 #define UNDEF_UID ((uid_t)-1)
56 #define UNDEF_GID ((gid_t)-1)
57 #define UNDEF_ISUSER (-1)
59 #define CACHE_PURGE_INTERVAL (60 * 3)
60 #define CACHE_TTL (60 * 10)
65 #define list_insert(head, ele)\
67 (ele)->flink = (head)->flink;\
68 (head)->flink = (ele);\
69 (ele)->blink = (ele)->flink->blink;\
70 (ele)->flink->blink = (ele);\
75 #define list_remove(ele)\
77 (ele)->flink->blink = (ele)->blink;\
78 (ele)->blink->flink = (ele)->flink;\
82 #define list_move(head, ele) \
84 if ((head)->flink != (ele)) {\
86 list_insert(head, ele);\
90 typedef struct sid2uid_gid
{
92 struct sid2uid_gid
*flink
;
93 struct sid2uid_gid
*blink
;
94 const char *sid_prefix
;
104 typedef struct pid2sid_winname
{
106 struct pid2sid_winname
*flink
;
107 struct pid2sid_winname
*blink
;
109 const char *sid_prefix
;
113 const char *windomain
;
118 typedef struct winname2uid_gid
{
120 struct winname2uid_gid
*flink
;
121 struct winname2uid_gid
*blink
;
123 const char *windomain
;
131 typedef struct sid2uid_gid_cache
{
133 pthread_mutex_t mutex
;
140 } sid2uid_gid_cache_t
;
143 typedef struct pid2sid_winname_cache
{
145 pthread_mutex_t mutex
;
146 pid2sid_winname_t head
;
147 pid2sid_winname_t
*prev
;
151 } pid2sid_winname_cache_t
;
155 typedef struct winname2uid_gid_cache
{
157 pthread_mutex_t mutex
;
158 winname2uid_gid_t head
;
159 winname2uid_gid_t
*prev
;
163 } winname2uid_gid_cache_t
;
166 typedef struct idmap_cache
{
167 sid2uid_gid_cache_t sid2uid_gid
;
168 pid2sid_winname_cache_t uid2sid_winname
;
169 pid2sid_winname_cache_t gid2sid_winname
;
170 winname2uid_gid_cache_t winname2uid_gid
;
175 typedef int (*avl_comp_fn
)(const void*, const void*);
178 idmap_purge_sid2uid_gid_cache(sid2uid_gid_cache_t
*cache
, size_t limit
);
181 idmap_purge_pid2sid_winname_cache(pid2sid_winname_cache_t
*cache
, size_t limit
);
184 idmap_purge_winname2uid_gid_cache(winname2uid_gid_cache_t
*avl
, size_t limit
);
190 static idmap_cache_t idmap_cache
;
196 idmap_compare_sid(const sid2uid_gid_t
*entry1
, const sid2uid_gid_t
*entry2
)
198 int64_t comp
= ((int64_t)entry2
->rid
) - ((int64_t)entry1
->rid
);
201 comp
= strcmp(entry2
->sid_prefix
, entry1
->sid_prefix
);
213 idmap_compare_pid(const pid2sid_winname_t
*entry1
,
214 const pid2sid_winname_t
*entry2
)
216 if (entry2
->pid
> entry1
->pid
)
218 if (entry2
->pid
< entry1
->pid
)
225 idmap_compare_winname(const winname2uid_gid_t
*entry1
,
226 const winname2uid_gid_t
*entry2
)
230 comp
= strcasecmp(entry2
->winname
, entry1
->winname
);
232 if (entry2
->windomain
== NULL
&& entry1
->windomain
== NULL
)
234 if (entry1
->windomain
== NULL
)
236 if (entry2
->windomain
== NULL
)
239 comp
= strcasecmp(entry2
->windomain
, entry1
->windomain
);
251 * Routine to update item
257 update_str(const char **item
, const char *str
)
261 if (*item
!= NULL
&& str
!= NULL
) {
262 if (strcmp(*item
, str
) != 0) {
263 if ((tmp
= strdup(str
)) == NULL
)
268 } else if (str
!= NULL
) {
270 if ((*item
= strdup(str
)) == NULL
)
272 } else if (*item
!= NULL
) {
282 * The Cache is initialized on loading libidmap.so
284 #pragma init(idmap_cache_create)
287 idmap_cache_create(void)
289 avl_create(&idmap_cache
.sid2uid_gid
.tree
,
290 (avl_comp_fn
)idmap_compare_sid
, sizeof (sid2uid_gid_t
),
291 offsetof(sid2uid_gid_t
, avl_link
));
292 (void) pthread_mutex_init(&idmap_cache
.sid2uid_gid
.mutex
, NULL
);
293 idmap_cache
.sid2uid_gid
.head
.flink
= &idmap_cache
.sid2uid_gid
.head
;
294 idmap_cache
.sid2uid_gid
.head
.blink
= &idmap_cache
.sid2uid_gid
.head
;
295 idmap_cache
.sid2uid_gid
.prev
= NULL
;
296 idmap_cache
.sid2uid_gid
.purge_time
= 0;
297 idmap_cache
.sid2uid_gid
.uid_num
= 0;
298 idmap_cache
.sid2uid_gid
.gid_num
= 0;
299 idmap_cache
.sid2uid_gid
.pid_num
= 0;
301 avl_create(&idmap_cache
.uid2sid_winname
.tree
,
302 (avl_comp_fn
)idmap_compare_pid
, sizeof (pid2sid_winname_t
),
303 offsetof(pid2sid_winname_t
, avl_link
));
304 (void) pthread_mutex_init(&idmap_cache
.uid2sid_winname
.mutex
, NULL
);
305 idmap_cache
.uid2sid_winname
.head
.flink
=
306 &idmap_cache
.uid2sid_winname
.head
;
307 idmap_cache
.uid2sid_winname
.head
.blink
=
308 &idmap_cache
.uid2sid_winname
.head
;
309 idmap_cache
.uid2sid_winname
.prev
= NULL
;
310 idmap_cache
.uid2sid_winname
.purge_time
= 0;
311 idmap_cache
.uid2sid_winname
.sid_num
= 0;
312 idmap_cache
.uid2sid_winname
.winname_num
= 0;
314 avl_create(&idmap_cache
.gid2sid_winname
.tree
,
315 (avl_comp_fn
)idmap_compare_pid
, sizeof (pid2sid_winname_t
),
316 offsetof(pid2sid_winname_t
, avl_link
));
317 (void) pthread_mutex_init(&idmap_cache
.gid2sid_winname
.mutex
, NULL
);
318 idmap_cache
.gid2sid_winname
.head
.flink
=
319 &idmap_cache
.gid2sid_winname
.head
;
320 idmap_cache
.gid2sid_winname
.head
.blink
=
321 &idmap_cache
.gid2sid_winname
.head
;
322 idmap_cache
.gid2sid_winname
.prev
= NULL
;
323 idmap_cache
.gid2sid_winname
.purge_time
= 0;
324 idmap_cache
.gid2sid_winname
.sid_num
= 0;
325 idmap_cache
.gid2sid_winname
.winname_num
= 0;
327 avl_create(&idmap_cache
.winname2uid_gid
.tree
,
328 (avl_comp_fn
)idmap_compare_winname
, sizeof (winname2uid_gid_t
),
329 offsetof(winname2uid_gid_t
, avl_link
));
330 (void) pthread_mutex_init(&idmap_cache
.winname2uid_gid
.mutex
, NULL
);
331 idmap_cache
.winname2uid_gid
.head
.flink
=
332 &idmap_cache
.winname2uid_gid
.head
;
333 idmap_cache
.winname2uid_gid
.head
.blink
=
334 &idmap_cache
.winname2uid_gid
.head
;
335 idmap_cache
.winname2uid_gid
.prev
= NULL
;
336 idmap_cache
.winname2uid_gid
.purge_time
= 0;
337 idmap_cache
.winname2uid_gid
.uid_num
= 0;
338 idmap_cache
.winname2uid_gid
.gid_num
= 0;
343 idmap_cache_purge(void)
345 sid2uid_gid_t
*sid2uid_gid
;
346 pid2sid_winname_t
*uid2sid_winname
;
347 pid2sid_winname_t
*gid2sid_winname
;
348 winname2uid_gid_t
*winname2uid_gid
;
351 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
353 while ((sid2uid_gid
= avl_destroy_nodes(
354 &idmap_cache
.sid2uid_gid
.tree
, &cookie
)) != NULL
) {
355 free((char *)sid2uid_gid
->sid_prefix
);
358 avl_destroy(&idmap_cache
.sid2uid_gid
.tree
);
359 avl_create(&idmap_cache
.sid2uid_gid
.tree
,
360 (avl_comp_fn
)idmap_compare_sid
, sizeof (sid2uid_gid_t
),
361 offsetof(sid2uid_gid_t
, avl_link
));
362 idmap_cache
.sid2uid_gid
.head
.flink
= &idmap_cache
.sid2uid_gid
.head
;
363 idmap_cache
.sid2uid_gid
.head
.blink
= &idmap_cache
.sid2uid_gid
.head
;
364 idmap_cache
.sid2uid_gid
.prev
= NULL
;
365 idmap_cache
.sid2uid_gid
.purge_time
= 0;
366 idmap_cache
.sid2uid_gid
.uid_num
= 0;
367 idmap_cache
.sid2uid_gid
.gid_num
= 0;
368 idmap_cache
.sid2uid_gid
.pid_num
= 0;
369 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
372 (void) pthread_mutex_lock(&idmap_cache
.uid2sid_winname
.mutex
);
374 while ((uid2sid_winname
= avl_destroy_nodes(
375 &idmap_cache
.uid2sid_winname
.tree
, &cookie
)) != NULL
) {
376 free((char *)uid2sid_winname
->sid_prefix
);
377 free((char *)uid2sid_winname
->winname
);
378 if (uid2sid_winname
->windomain
!= NULL
)
379 free((char *)uid2sid_winname
->windomain
);
380 free(uid2sid_winname
);
382 avl_destroy(&idmap_cache
.uid2sid_winname
.tree
);
383 avl_create(&idmap_cache
.uid2sid_winname
.tree
,
384 (avl_comp_fn
)idmap_compare_pid
, sizeof (pid2sid_winname_t
),
385 offsetof(pid2sid_winname_t
, avl_link
));
386 idmap_cache
.uid2sid_winname
.head
.flink
=
387 &idmap_cache
.uid2sid_winname
.head
;
388 idmap_cache
.uid2sid_winname
.head
.blink
=
389 &idmap_cache
.uid2sid_winname
.head
;
390 idmap_cache
.uid2sid_winname
.prev
= NULL
;
391 idmap_cache
.uid2sid_winname
.purge_time
= 0;
392 idmap_cache
.uid2sid_winname
.sid_num
= 0;
393 idmap_cache
.uid2sid_winname
.winname_num
= 0;
394 (void) pthread_mutex_unlock(&idmap_cache
.uid2sid_winname
.mutex
);
397 (void) pthread_mutex_lock(&idmap_cache
.gid2sid_winname
.mutex
);
399 while ((gid2sid_winname
= avl_destroy_nodes(
400 &idmap_cache
.gid2sid_winname
.tree
, &cookie
)) != NULL
) {
401 free((char *)gid2sid_winname
->sid_prefix
);
402 free((char *)gid2sid_winname
->winname
);
403 if (gid2sid_winname
->windomain
!= NULL
)
404 free((char *)gid2sid_winname
->windomain
);
405 free(gid2sid_winname
);
407 avl_destroy(&idmap_cache
.gid2sid_winname
.tree
);
408 avl_create(&idmap_cache
.gid2sid_winname
.tree
,
409 (avl_comp_fn
)idmap_compare_pid
, sizeof (pid2sid_winname_t
),
410 offsetof(pid2sid_winname_t
, avl_link
));
411 idmap_cache
.gid2sid_winname
.head
.flink
=
412 &idmap_cache
.gid2sid_winname
.head
;
413 idmap_cache
.gid2sid_winname
.head
.blink
=
414 &idmap_cache
.gid2sid_winname
.head
;
415 idmap_cache
.gid2sid_winname
.prev
= NULL
;
416 idmap_cache
.gid2sid_winname
.purge_time
= 0;
417 idmap_cache
.gid2sid_winname
.sid_num
= 0;
418 idmap_cache
.gid2sid_winname
.winname_num
= 0;
419 (void) pthread_mutex_unlock(&idmap_cache
.gid2sid_winname
.mutex
);
421 (void) pthread_mutex_lock(&idmap_cache
.winname2uid_gid
.mutex
);
423 while ((winname2uid_gid
= avl_destroy_nodes(
424 &idmap_cache
.winname2uid_gid
.tree
, &cookie
)) != NULL
) {
425 free((char *)winname2uid_gid
->winname
);
426 if (winname2uid_gid
->windomain
)
427 free((char *)winname2uid_gid
->windomain
);
428 free(winname2uid_gid
);
430 avl_destroy(&idmap_cache
.winname2uid_gid
.tree
);
431 avl_create(&idmap_cache
.winname2uid_gid
.tree
,
432 (avl_comp_fn
)idmap_compare_winname
, sizeof (winname2uid_gid_t
),
433 offsetof(winname2uid_gid_t
, avl_link
));
434 idmap_cache
.winname2uid_gid
.head
.flink
=
435 &idmap_cache
.winname2uid_gid
.head
;
436 idmap_cache
.winname2uid_gid
.head
.blink
=
437 &idmap_cache
.winname2uid_gid
.head
;
438 idmap_cache
.winname2uid_gid
.prev
= NULL
;
439 idmap_cache
.winname2uid_gid
.purge_time
= 0;
440 idmap_cache
.winname2uid_gid
.uid_num
= 0;
441 idmap_cache
.winname2uid_gid
.gid_num
= 0;
442 (void) pthread_mutex_unlock(&idmap_cache
.winname2uid_gid
.mutex
);
448 idmap_cache_get_data(size_t *uidbysid
, size_t *gidbysid
,
449 size_t *pidbysid
, size_t *sidbyuid
, size_t *sidbygid
,
450 size_t *winnamebyuid
, size_t *winnamebygid
,
451 size_t *uidbywinname
, size_t *gidbywinname
)
453 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
454 *uidbysid
= idmap_cache
.sid2uid_gid
.uid_num
;
455 *gidbysid
= idmap_cache
.sid2uid_gid
.gid_num
;
456 *pidbysid
= idmap_cache
.sid2uid_gid
.pid_num
;
457 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
459 (void) pthread_mutex_lock(&idmap_cache
.uid2sid_winname
.mutex
);
460 *sidbyuid
= idmap_cache
.uid2sid_winname
.sid_num
;
461 *winnamebyuid
= idmap_cache
.uid2sid_winname
.winname_num
;
462 (void) pthread_mutex_unlock(&idmap_cache
.uid2sid_winname
.mutex
);
464 (void) pthread_mutex_lock(&idmap_cache
.gid2sid_winname
.mutex
);
465 *sidbygid
= idmap_cache
.gid2sid_winname
.sid_num
;
466 *winnamebygid
= idmap_cache
.gid2sid_winname
.winname_num
;
467 (void) pthread_mutex_unlock(&idmap_cache
.gid2sid_winname
.mutex
);
469 (void) pthread_mutex_lock(&idmap_cache
.winname2uid_gid
.mutex
);
470 *uidbywinname
= idmap_cache
.winname2uid_gid
.uid_num
;
471 *gidbywinname
= idmap_cache
.winname2uid_gid
.gid_num
;
472 (void) pthread_mutex_unlock(&idmap_cache
.winname2uid_gid
.mutex
);
477 idmap_cache_lookup_uidbysid(const char *sid_prefix
,
478 idmap_rid_t rid
, uid_t
*uid
)
481 sid2uid_gid_t
*result
;
483 int status
= IDMAP_ERR_NOMAPPING
;
484 time_t now
= time(NULL
);
486 entry
.sid_prefix
= sid_prefix
;
489 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
491 result
= avl_find(&idmap_cache
.sid2uid_gid
.tree
, &entry
, &where
);
492 if (result
!= NULL
) {
493 list_move(&idmap_cache
.sid2uid_gid
.head
, result
);
494 if (result
->uid
!= UNDEF_UID
&& result
->uid_ttl
> now
) {
496 status
= IDMAP_SUCCESS
;
500 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
508 idmap_cache_lookup_gidbysid(const char *sid_prefix
,
509 idmap_rid_t rid
, gid_t
*gid
)
512 sid2uid_gid_t
*result
;
514 int status
= IDMAP_ERR_NOMAPPING
;
515 time_t now
= time(NULL
);
517 entry
.sid_prefix
= sid_prefix
;
520 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
522 result
= avl_find(&idmap_cache
.sid2uid_gid
.tree
, &entry
, &where
);
523 if (result
!= NULL
) {
524 list_move(&idmap_cache
.sid2uid_gid
.head
, result
);
525 if (result
->gid
!= UNDEF_GID
&& result
->gid_ttl
> now
) {
527 status
= IDMAP_SUCCESS
;
531 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
540 idmap_cache_lookup_pidbysid(const char *sid_prefix
,
541 idmap_rid_t rid
, uid_t
*pid
, int *is_user
)
544 sid2uid_gid_t
*result
;
546 int status
= IDMAP_ERR_NOMAPPING
;
547 time_t now
= time(NULL
);
549 entry
.sid_prefix
= sid_prefix
;
552 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
554 result
= avl_find(&idmap_cache
.sid2uid_gid
.tree
, &entry
, &where
);
555 if (result
!= NULL
) {
556 list_move(&idmap_cache
.sid2uid_gid
.head
, result
);
557 if (result
->is_user
!= UNDEF_ISUSER
) {
558 *is_user
= result
->is_user
;
559 if (result
->is_user
&& result
->uid_ttl
> now
) {
561 status
= IDMAP_SUCCESS
;
562 } else if (!result
->is_user
&& result
->gid_ttl
> now
) {
564 status
= IDMAP_SUCCESS
;
569 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
577 idmap_cache_lookup_sidbyuid(char **sid_prefix
,
578 idmap_rid_t
*rid
, uid_t uid
)
580 pid2sid_winname_t entry
;
581 pid2sid_winname_t
*result
;
583 int status
= IDMAP_ERR_NOMAPPING
;
584 time_t now
= time(NULL
);
588 (void) pthread_mutex_lock(&idmap_cache
.uid2sid_winname
.mutex
);
590 result
= avl_find(&idmap_cache
.uid2sid_winname
.tree
, &entry
, &where
);
591 if (result
!= NULL
) {
592 list_move(&idmap_cache
.uid2sid_winname
.head
, result
);
593 if (result
->sid_ttl
> now
) {
595 *sid_prefix
= strdup(result
->sid_prefix
);
596 if (*sid_prefix
!= NULL
)
597 status
= IDMAP_SUCCESS
;
599 status
= IDMAP_ERR_MEMORY
;
603 (void) pthread_mutex_unlock(&idmap_cache
.uid2sid_winname
.mutex
);
609 idmap_cache_lookup_sidbygid(char **sid_prefix
,
610 idmap_rid_t
*rid
, gid_t gid
)
612 pid2sid_winname_t entry
;
613 pid2sid_winname_t
*result
;
615 int status
= IDMAP_ERR_NOMAPPING
;
616 time_t now
= time(NULL
);
620 (void) pthread_mutex_lock(&idmap_cache
.gid2sid_winname
.mutex
);
622 result
= avl_find(&idmap_cache
.gid2sid_winname
.tree
, &entry
, &where
);
623 if (result
!= NULL
) {
624 list_move(&idmap_cache
.gid2sid_winname
.head
, result
);
625 if (result
->sid_ttl
> now
) {
627 *sid_prefix
= strdup(result
->sid_prefix
);
628 if (*sid_prefix
!= NULL
)
629 status
= IDMAP_SUCCESS
;
631 status
= IDMAP_ERR_MEMORY
;
635 (void) pthread_mutex_unlock(&idmap_cache
.gid2sid_winname
.mutex
);
642 idmap_cache_lookup_winnamebyuid(char **name
, char **domain
, uid_t uid
)
644 pid2sid_winname_t entry
;
645 pid2sid_winname_t
*result
;
647 int status
= IDMAP_ERR_NOMAPPING
;
648 time_t now
= time(NULL
);
652 (void) pthread_mutex_lock(&idmap_cache
.uid2sid_winname
.mutex
);
654 result
= avl_find(&idmap_cache
.uid2sid_winname
.tree
, &entry
, &where
);
655 if (result
!= NULL
) {
656 list_move(&idmap_cache
.uid2sid_winname
.head
, result
);
657 if (result
->winname_ttl
> now
) {
658 *name
= strdup(result
->winname
);
660 if (domain
!= NULL
) {
661 if (result
->windomain
!= NULL
) {
663 strdup(result
->windomain
);
665 status
= IDMAP_SUCCESS
;
671 status
= IDMAP_SUCCESS
;
674 status
= IDMAP_SUCCESS
;
676 status
= IDMAP_ERR_MEMORY
;
680 (void) pthread_mutex_unlock(&idmap_cache
.uid2sid_winname
.mutex
);
687 idmap_cache_lookup_winnamebygid(char **name
, char **domain
, gid_t gid
)
689 pid2sid_winname_t entry
;
690 pid2sid_winname_t
*result
;
692 int status
= IDMAP_ERR_NOMAPPING
;
693 time_t now
= time(NULL
);
697 (void) pthread_mutex_lock(&idmap_cache
.gid2sid_winname
.mutex
);
699 result
= avl_find(&idmap_cache
.gid2sid_winname
.tree
, &entry
, &where
);
700 if (result
!= NULL
) {
701 list_move(&idmap_cache
.gid2sid_winname
.head
, result
);
702 if (result
->winname_ttl
> now
) {
703 *name
= strdup(result
->winname
);
705 if (domain
!= NULL
) {
706 if (result
->windomain
!= NULL
) {
708 strdup(result
->windomain
);
710 status
= IDMAP_SUCCESS
;
716 status
= IDMAP_SUCCESS
;
719 status
= IDMAP_SUCCESS
;
721 status
= IDMAP_ERR_MEMORY
;
725 (void) pthread_mutex_unlock(&idmap_cache
.gid2sid_winname
.mutex
);
732 idmap_cache_lookup_uidbywinname(const char *name
, const char *domain
,
735 winname2uid_gid_t entry
;
736 winname2uid_gid_t
*result
;
738 int status
= IDMAP_ERR_NOMAPPING
;
739 time_t now
= time(NULL
);
741 entry
.winname
= name
;
742 entry
.windomain
= domain
;
744 (void) pthread_mutex_lock(&idmap_cache
.winname2uid_gid
.mutex
);
746 result
= avl_find(&idmap_cache
.winname2uid_gid
.tree
, &entry
, &where
);
747 if (result
!= NULL
) {
748 list_move(&idmap_cache
.winname2uid_gid
.head
, result
);
749 if (result
->uid
!= UNDEF_UID
&& result
->uid_ttl
> now
) {
751 status
= IDMAP_SUCCESS
;
755 (void) pthread_mutex_unlock(&idmap_cache
.winname2uid_gid
.mutex
);
762 idmap_cache_lookup_gidbywinname(const char *name
, const char *domain
,
765 winname2uid_gid_t entry
;
766 winname2uid_gid_t
*result
;
768 int status
= IDMAP_ERR_NOMAPPING
;
769 time_t now
= time(NULL
);
771 entry
.winname
= name
;
772 entry
.windomain
= domain
;
774 (void) pthread_mutex_lock(&idmap_cache
.winname2uid_gid
.mutex
);
776 result
= avl_find(&idmap_cache
.winname2uid_gid
.tree
, &entry
, &where
);
777 if (result
!= NULL
) {
778 list_move(&idmap_cache
.winname2uid_gid
.head
, result
);
779 if (result
->gid
!= UNDEF_GID
&& result
->gid_ttl
> now
) {
781 status
= IDMAP_SUCCESS
;
785 (void) pthread_mutex_unlock(&idmap_cache
.winname2uid_gid
.mutex
);
792 idmap_cache_add_sid2uid(const char *sid_prefix
,
793 idmap_rid_t rid
, uid_t uid
, int direction
)
797 time_t ttl
= CACHE_TTL
+ time(NULL
);
800 if (direction
== IDMAP_DIRECTION_BI
||
801 direction
== IDMAP_DIRECTION_W2U
) {
803 sid2uid_gid_t
*result
;
806 find
.sid_prefix
= sid_prefix
;
809 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
810 result
= avl_find(&idmap_cache
.sid2uid_gid
.tree
, &find
, &where
);
813 if (result
->uid_ttl
== 0)
814 idmap_cache
.sid2uid_gid
.uid_num
++;
816 result
->uid_ttl
= ttl
;
818 new = malloc(sizeof (sid2uid_gid_t
));
820 goto exit_sid2uid_gid
;
821 new->sid_prefix
= strdup(sid_prefix
);
822 if (new->sid_prefix
== NULL
) {
824 goto exit_sid2uid_gid
;
829 new->gid
= UNDEF_GID
;
831 new->is_user
= UNDEF_ISUSER
; /* Unknown */
832 idmap_cache
.sid2uid_gid
.uid_num
++;
834 list_insert(&idmap_cache
.sid2uid_gid
.head
, new);
835 avl_insert(&idmap_cache
.sid2uid_gid
.tree
, new, where
);
837 if ((avl_numnodes(&idmap_cache
.sid2uid_gid
.tree
) >
838 CACHE_UID_GID_TRIGGER_SIZE
) &&
839 (idmap_cache
.sid2uid_gid
.purge_time
+ CACHE_PURGE_INTERVAL
<
841 idmap_purge_sid2uid_gid_cache(&idmap_cache
.sid2uid_gid
,
842 CACHE_UID_GID_TRIGGER_SIZE
);
845 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
848 if (direction
== IDMAP_DIRECTION_BI
||
849 direction
== IDMAP_DIRECTION_U2W
) {
850 pid2sid_winname_t find
;
851 pid2sid_winname_t
*result
;
852 pid2sid_winname_t
*new;
856 (void) pthread_mutex_lock(&idmap_cache
.uid2sid_winname
.mutex
);
857 result
= avl_find(&idmap_cache
.uid2sid_winname
.tree
, &find
,
861 if (update_str(&result
->sid_prefix
, sid_prefix
) != 0)
862 goto exit_pid2sid_winname
;
863 if (result
->sid_ttl
== 0)
864 idmap_cache
.uid2sid_winname
.sid_num
++;
866 result
->sid_ttl
= ttl
;
868 new = malloc(sizeof (pid2sid_winname_t
));
870 goto exit_pid2sid_winname
;
872 new->sid_prefix
= strdup(sid_prefix
);
873 if (new->sid_prefix
== NULL
) {
875 goto exit_pid2sid_winname
;
880 new->windomain
= NULL
;
881 new->winname_ttl
= 0;
882 idmap_cache
.uid2sid_winname
.sid_num
++;
884 list_insert(&idmap_cache
.uid2sid_winname
.head
, new);
885 avl_insert(&idmap_cache
.uid2sid_winname
.tree
, new,
888 if ((avl_numnodes(&idmap_cache
.uid2sid_winname
.tree
) >
889 CACHE_UID_TRIGGER_SIZE
) &&
890 (idmap_cache
.uid2sid_winname
.purge_time
+
891 CACHE_PURGE_INTERVAL
< time(NULL
)))
892 idmap_purge_pid2sid_winname_cache(
893 &idmap_cache
.uid2sid_winname
,
894 CACHE_UID_TRIGGER_SIZE
);
897 exit_pid2sid_winname
:
898 (void) pthread_mutex_unlock(&idmap_cache
.uid2sid_winname
.mutex
);
905 idmap_cache_add_sid2gid(const char *sid_prefix
,
906 idmap_rid_t rid
, gid_t gid
, int direction
)
909 time_t ttl
= CACHE_TTL
+ time(NULL
);
912 if (direction
== IDMAP_DIRECTION_BI
||
913 direction
== IDMAP_DIRECTION_W2U
) {
915 sid2uid_gid_t
*result
;
918 find
.sid_prefix
= sid_prefix
;
921 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
922 result
= avl_find(&idmap_cache
.sid2uid_gid
.tree
, &find
, &where
);
925 if (result
->gid_ttl
== 0)
926 idmap_cache
.sid2uid_gid
.gid_num
++;
928 result
->gid_ttl
= ttl
;
930 new = malloc(sizeof (sid2uid_gid_t
));
932 goto exit_sid2uid_gid
;
933 new->sid_prefix
= strdup(sid_prefix
);
934 if (new->sid_prefix
== NULL
) {
936 goto exit_sid2uid_gid
;
939 new->uid
= UNDEF_UID
;
943 new->is_user
= UNDEF_ISUSER
; /* Unknown */
944 idmap_cache
.sid2uid_gid
.gid_num
++;
946 list_insert(&idmap_cache
.sid2uid_gid
.head
, new);
947 avl_insert(&idmap_cache
.sid2uid_gid
.tree
, new, where
);
949 if ((avl_numnodes(&idmap_cache
.sid2uid_gid
.tree
) >
950 CACHE_UID_GID_TRIGGER_SIZE
) &&
951 (idmap_cache
.sid2uid_gid
.purge_time
+ CACHE_PURGE_INTERVAL
<
953 idmap_purge_sid2uid_gid_cache(&idmap_cache
.sid2uid_gid
,
954 CACHE_UID_GID_TRIGGER_SIZE
);
957 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
960 if (direction
== IDMAP_DIRECTION_BI
||
961 direction
== IDMAP_DIRECTION_U2W
) {
962 pid2sid_winname_t find
;
963 pid2sid_winname_t
*result
;
964 pid2sid_winname_t
*new;
968 (void) pthread_mutex_lock(&idmap_cache
.gid2sid_winname
.mutex
);
969 result
= avl_find(&idmap_cache
.gid2sid_winname
.tree
, &find
,
973 if (update_str(&result
->sid_prefix
, sid_prefix
) != 0)
974 goto exit_gid2sid_winname
;
975 if (result
->sid_ttl
== 0)
976 idmap_cache
.gid2sid_winname
.sid_num
++;
978 result
->sid_ttl
= ttl
;
980 new = malloc(sizeof (pid2sid_winname_t
));
982 goto exit_gid2sid_winname
;
983 new->sid_prefix
= strdup(sid_prefix
);
984 if (new->sid_prefix
== NULL
) {
986 goto exit_gid2sid_winname
;
992 new->windomain
= NULL
;
993 new->winname_ttl
= 0;
994 idmap_cache
.gid2sid_winname
.sid_num
++;
996 list_insert(&idmap_cache
.gid2sid_winname
.head
, new);
997 avl_insert(&idmap_cache
.gid2sid_winname
.tree
, new,
1000 if ((avl_numnodes(&idmap_cache
.gid2sid_winname
.tree
) >
1001 CACHE_GID_TRIGGER_SIZE
) &&
1002 (idmap_cache
.gid2sid_winname
.purge_time
+
1003 CACHE_PURGE_INTERVAL
< time(NULL
)))
1004 idmap_purge_pid2sid_winname_cache(
1005 &idmap_cache
.gid2sid_winname
,
1006 CACHE_GID_TRIGGER_SIZE
);
1008 exit_gid2sid_winname
:
1009 (void) pthread_mutex_unlock(&idmap_cache
.gid2sid_winname
.mutex
);
1015 idmap_cache_add_sid2pid(const char *sid_prefix
,
1016 idmap_rid_t rid
, uid_t pid
, int is_user
, int direction
)
1019 time_t ttl
= CACHE_TTL
+ time(NULL
);
1022 if (direction
== IDMAP_DIRECTION_BI
||
1023 direction
== IDMAP_DIRECTION_W2U
) {
1025 sid2uid_gid_t
*result
;
1028 find
.sid_prefix
= sid_prefix
;
1031 (void) pthread_mutex_lock(&idmap_cache
.sid2uid_gid
.mutex
);
1032 result
= avl_find(&idmap_cache
.sid2uid_gid
.tree
, &find
, &where
);
1035 if (result
->is_user
== UNDEF_ISUSER
)
1036 idmap_cache
.sid2uid_gid
.pid_num
++;
1037 result
->is_user
= is_user
;
1039 if (result
->uid_ttl
== 0)
1040 idmap_cache
.sid2uid_gid
.uid_num
++;
1042 result
->uid_ttl
= ttl
;
1044 if (result
->gid_ttl
== 0)
1045 idmap_cache
.sid2uid_gid
.gid_num
++;
1047 result
->gid_ttl
= ttl
;
1050 new = malloc(sizeof (sid2uid_gid_t
));
1052 goto exit_sid2uid_gid
;
1053 new->sid_prefix
= strdup(sid_prefix
);
1054 if (new->sid_prefix
== NULL
) {
1056 goto exit_sid2uid_gid
;
1059 new->is_user
= is_user
;
1063 new->gid
= UNDEF_GID
;
1065 idmap_cache
.sid2uid_gid
.uid_num
++;
1067 new->uid
= UNDEF_UID
;
1071 idmap_cache
.sid2uid_gid
.gid_num
++;
1073 idmap_cache
.sid2uid_gid
.pid_num
++;
1075 list_insert(&idmap_cache
.sid2uid_gid
.head
, new);
1076 avl_insert(&idmap_cache
.sid2uid_gid
.tree
, new, where
);
1078 if ((avl_numnodes(&idmap_cache
.sid2uid_gid
.tree
) >
1079 CACHE_UID_GID_TRIGGER_SIZE
) &&
1080 (idmap_cache
.sid2uid_gid
.purge_time
+ CACHE_PURGE_INTERVAL
<
1082 idmap_purge_sid2uid_gid_cache(&idmap_cache
.sid2uid_gid
,
1083 CACHE_UID_GID_TRIGGER_SIZE
);
1086 (void) pthread_mutex_unlock(&idmap_cache
.sid2uid_gid
.mutex
);
1089 if (direction
== IDMAP_DIRECTION_BI
||
1090 direction
== IDMAP_DIRECTION_U2W
) {
1091 pid2sid_winname_t find
;
1092 pid2sid_winname_t
*result
;
1093 pid2sid_winname_t
*new;
1097 (void) pthread_mutex_lock(
1098 &idmap_cache
.uid2sid_winname
.mutex
);
1099 result
= avl_find(&idmap_cache
.uid2sid_winname
.tree
,
1103 if (update_str(&result
->sid_prefix
, sid_prefix
)
1105 goto exit_uid2sid_winname
;
1106 if (result
->sid_ttl
== 0)
1107 idmap_cache
.uid2sid_winname
.sid_num
++;
1109 result
->sid_ttl
= ttl
;
1111 new = malloc(sizeof (pid2sid_winname_t
));
1113 goto exit_uid2sid_winname
;
1114 new->sid_prefix
= strdup(sid_prefix
);
1115 if (new->sid_prefix
== NULL
) {
1117 goto exit_uid2sid_winname
;
1122 new->winname
= NULL
;
1123 new->windomain
= NULL
;
1124 idmap_cache
.uid2sid_winname
.sid_num
++;
1126 list_insert(&idmap_cache
.uid2sid_winname
.head
,
1128 avl_insert(&idmap_cache
.uid2sid_winname
.tree
,
1131 if ((avl_numnodes(&idmap_cache
.uid2sid_winname
.tree
) >
1132 CACHE_UID_TRIGGER_SIZE
) &&
1133 (idmap_cache
.uid2sid_winname
.purge_time
+
1134 CACHE_PURGE_INTERVAL
< time(NULL
)))
1135 idmap_purge_pid2sid_winname_cache(
1136 &idmap_cache
.uid2sid_winname
,
1137 CACHE_UID_TRIGGER_SIZE
);
1139 exit_uid2sid_winname
:
1140 (void) pthread_mutex_unlock(
1141 &idmap_cache
.uid2sid_winname
.mutex
);
1143 (void) pthread_mutex_lock(
1144 &idmap_cache
.gid2sid_winname
.mutex
);
1145 result
= avl_find(&idmap_cache
.gid2sid_winname
.tree
,
1149 if (update_str(&result
->sid_prefix
, sid_prefix
)
1151 goto exit_gid2sid_winname
;
1152 if (result
->sid_ttl
== 0)
1153 idmap_cache
.gid2sid_winname
.sid_num
++;
1155 result
->sid_ttl
= ttl
;
1157 new = malloc(sizeof (pid2sid_winname_t
));
1159 goto exit_gid2sid_winname
;
1160 new->sid_prefix
= strdup(sid_prefix
);
1161 if (new->sid_prefix
== NULL
) {
1163 goto exit_gid2sid_winname
;
1168 new->winname
= NULL
;
1169 new->windomain
= NULL
;
1170 idmap_cache
.gid2sid_winname
.sid_num
++;
1172 list_insert(&idmap_cache
.gid2sid_winname
.head
,
1174 avl_insert(&idmap_cache
.gid2sid_winname
.tree
,
1177 if ((avl_numnodes(&idmap_cache
.gid2sid_winname
.tree
) >
1178 CACHE_GID_TRIGGER_SIZE
) &&
1179 (idmap_cache
.gid2sid_winname
.purge_time
+
1180 CACHE_PURGE_INTERVAL
< time(NULL
)))
1181 idmap_purge_pid2sid_winname_cache(
1182 &idmap_cache
.gid2sid_winname
,
1183 CACHE_GID_TRIGGER_SIZE
);
1184 exit_gid2sid_winname
:
1185 (void) pthread_mutex_unlock(
1186 &idmap_cache
.gid2sid_winname
.mutex
);
1194 idmap_cache_add_winname2uid(const char *name
, const char *domain
, uid_t uid
,
1198 time_t ttl
= CACHE_TTL
+ time(NULL
);
1201 if (direction
== IDMAP_DIRECTION_BI
||
1202 direction
== IDMAP_DIRECTION_W2U
) {
1203 winname2uid_gid_t find
;
1204 winname2uid_gid_t
*result
;
1205 winname2uid_gid_t
*new;
1207 find
.winname
= name
;
1208 find
.windomain
= domain
;
1210 (void) pthread_mutex_lock(&idmap_cache
.winname2uid_gid
.mutex
);
1211 result
= avl_find(&idmap_cache
.winname2uid_gid
.tree
, &find
,
1215 if (result
->uid_ttl
== 0)
1216 idmap_cache
.winname2uid_gid
.uid_num
++;
1218 result
->uid_ttl
= ttl
;
1220 new = malloc(sizeof (winname2uid_gid_t
));
1222 goto exit_winname2uid_gid
;
1223 new->winname
= strdup(name
);
1224 if (new->winname
== NULL
) {
1226 goto exit_winname2uid_gid
;
1228 if (domain
!= NULL
) {
1229 new->windomain
= strdup(domain
);
1230 if (new->winname
== NULL
) {
1231 free((char *)new->winname
);
1233 goto exit_winname2uid_gid
;
1236 new->windomain
= NULL
;
1239 new->gid
= UNDEF_GID
;
1241 idmap_cache
.winname2uid_gid
.uid_num
++;
1243 list_insert(&idmap_cache
.winname2uid_gid
.head
, new);
1244 avl_insert(&idmap_cache
.winname2uid_gid
.tree
, new,
1247 if ((avl_numnodes(&idmap_cache
.winname2uid_gid
.tree
) >
1248 CACHE_UID_GID_TRIGGER_SIZE
) &&
1249 (idmap_cache
.winname2uid_gid
.purge_time
+
1250 CACHE_PURGE_INTERVAL
< time(NULL
)))
1251 idmap_purge_winname2uid_gid_cache(
1252 &idmap_cache
.winname2uid_gid
,
1253 CACHE_UID_GID_TRIGGER_SIZE
);
1254 exit_winname2uid_gid
:
1255 (void) pthread_mutex_unlock(&idmap_cache
.winname2uid_gid
.mutex
);
1258 if (direction
== IDMAP_DIRECTION_BI
||
1259 direction
== IDMAP_DIRECTION_U2W
) {
1260 pid2sid_winname_t find
;
1261 pid2sid_winname_t
*result
;
1262 pid2sid_winname_t
*new;
1266 (void) pthread_mutex_lock(&idmap_cache
.uid2sid_winname
.mutex
);
1267 result
= avl_find(&idmap_cache
.uid2sid_winname
.tree
, &find
,
1271 if (update_str(&result
->winname
, name
) != 0)
1272 goto exit_uid2sid_winname
;
1273 if (update_str(&result
->windomain
, domain
) != 0)
1274 goto exit_uid2sid_winname
;
1275 if (result
->winname_ttl
== 0)
1276 idmap_cache
.uid2sid_winname
.winname_num
++;
1277 result
->winname_ttl
= ttl
;
1279 new = malloc(sizeof (pid2sid_winname_t
));
1281 goto exit_uid2sid_winname
;
1283 new->winname
= strdup(name
);
1284 if (new->winname
== NULL
) {
1286 goto exit_uid2sid_winname
;
1288 if (domain
!= NULL
) {
1289 new->windomain
= strdup(domain
);
1290 if (new->windomain
== NULL
) {
1291 free((char *)new->winname
);
1293 goto exit_uid2sid_winname
;
1296 new->windomain
= NULL
;
1297 new->winname_ttl
= ttl
;
1298 new->sid_prefix
= NULL
;
1301 idmap_cache
.uid2sid_winname
.winname_num
++;
1303 list_insert(&idmap_cache
.uid2sid_winname
.head
, new);
1304 avl_insert(&idmap_cache
.uid2sid_winname
.tree
, new,
1307 if ((avl_numnodes(&idmap_cache
.uid2sid_winname
.tree
) >
1308 CACHE_UID_TRIGGER_SIZE
) &&
1309 (idmap_cache
.uid2sid_winname
.purge_time
+
1310 CACHE_PURGE_INTERVAL
< time(NULL
)))
1311 idmap_purge_pid2sid_winname_cache(
1312 &idmap_cache
.uid2sid_winname
,
1313 CACHE_UID_TRIGGER_SIZE
);
1314 exit_uid2sid_winname
:
1315 (void) pthread_mutex_unlock(&idmap_cache
.uid2sid_winname
.mutex
);
1324 idmap_cache_add_winname2gid(const char *name
, const char *domain
, gid_t gid
,
1328 time_t ttl
= CACHE_TTL
+ time(NULL
);
1331 if (direction
== IDMAP_DIRECTION_BI
||
1332 direction
== IDMAP_DIRECTION_W2U
) {
1333 winname2uid_gid_t find
;
1334 winname2uid_gid_t
*result
;
1335 winname2uid_gid_t
*new;
1337 find
.winname
= name
;
1338 find
.windomain
= domain
;
1340 (void) pthread_mutex_lock(&idmap_cache
.winname2uid_gid
.mutex
);
1341 result
= avl_find(&idmap_cache
.winname2uid_gid
.tree
, &find
,
1345 if (result
->uid_ttl
== 0)
1346 idmap_cache
.winname2uid_gid
.gid_num
++;
1348 result
->gid_ttl
= ttl
;
1350 new = malloc(sizeof (winname2uid_gid_t
));
1352 goto exit_winname2uid_gid
;
1353 new->winname
= strdup(name
);
1354 if (new->winname
== NULL
) {
1356 goto exit_winname2uid_gid
;
1358 if (domain
!= NULL
) {
1359 new->windomain
= strdup(domain
);
1360 if (new->windomain
== NULL
) {
1361 free((char *)new->winname
);
1363 goto exit_winname2uid_gid
;
1367 new->windomain
= NULL
;
1368 new->uid
= UNDEF_UID
;
1372 idmap_cache
.winname2uid_gid
.gid_num
++;
1374 list_insert(&idmap_cache
.winname2uid_gid
.head
, new);
1375 avl_insert(&idmap_cache
.winname2uid_gid
.tree
, new,
1378 if ((avl_numnodes(&idmap_cache
.winname2uid_gid
.tree
) >
1379 CACHE_UID_GID_TRIGGER_SIZE
) &&
1380 (idmap_cache
.winname2uid_gid
.purge_time
+
1381 CACHE_PURGE_INTERVAL
< time(NULL
)))
1382 idmap_purge_winname2uid_gid_cache(
1383 &idmap_cache
.winname2uid_gid
,
1384 CACHE_UID_GID_TRIGGER_SIZE
);
1385 exit_winname2uid_gid
:
1386 (void) pthread_mutex_unlock(&idmap_cache
.winname2uid_gid
.mutex
);
1389 if (direction
== IDMAP_DIRECTION_BI
||
1390 direction
== IDMAP_DIRECTION_U2W
) {
1391 pid2sid_winname_t find
;
1392 pid2sid_winname_t
*result
;
1393 pid2sid_winname_t
*new;
1397 (void) pthread_mutex_lock(&idmap_cache
.gid2sid_winname
.mutex
);
1398 result
= avl_find(&idmap_cache
.gid2sid_winname
.tree
, &find
,
1402 if (update_str(&result
->winname
, name
) != 0)
1403 goto exit_gid2sid_winname
;
1404 if (update_str(&result
->windomain
, domain
) != 0)
1405 goto exit_gid2sid_winname
;
1406 if (result
->winname_ttl
== 0)
1407 idmap_cache
.gid2sid_winname
.winname_num
++;
1408 result
->winname_ttl
= ttl
;
1410 new = malloc(sizeof (pid2sid_winname_t
));
1412 goto exit_gid2sid_winname
;
1414 new->winname
= strdup(name
);
1415 if (new->winname
== NULL
) {
1417 goto exit_gid2sid_winname
;
1419 if (domain
!= NULL
) {
1420 new->windomain
= strdup(domain
);
1421 if (new->windomain
== NULL
) {
1422 free((char *)new->winname
);
1424 goto exit_gid2sid_winname
;
1428 new->windomain
= NULL
;
1429 new->winname_ttl
= ttl
;
1430 new->sid_prefix
= NULL
;
1433 idmap_cache
.gid2sid_winname
.winname_num
++;
1435 list_insert(&idmap_cache
.gid2sid_winname
.head
, new);
1436 avl_insert(&idmap_cache
.gid2sid_winname
.tree
, new,
1439 if ((avl_numnodes(&idmap_cache
.gid2sid_winname
.tree
) >
1440 CACHE_UID_TRIGGER_SIZE
) &&
1441 (idmap_cache
.gid2sid_winname
.purge_time
+
1442 CACHE_PURGE_INTERVAL
< time(NULL
)))
1443 idmap_purge_pid2sid_winname_cache(
1444 &idmap_cache
.gid2sid_winname
,
1445 CACHE_UID_TRIGGER_SIZE
);
1446 exit_gid2sid_winname
:
1447 (void) pthread_mutex_unlock(&idmap_cache
.gid2sid_winname
.mutex
);
1453 idmap_purge_sid2uid_gid_cache(sid2uid_gid_cache_t
*cache
, size_t limit
)
1455 time_t now
= time(NULL
);
1456 sid2uid_gid_t
*item
;
1458 while (avl_numnodes(&cache
->tree
) > limit
) {
1459 /* Remove least recently used */
1460 item
= cache
->head
.blink
;
1462 avl_remove(&cache
->tree
, item
);
1463 if (item
->uid_ttl
!= 0)
1465 if (item
->gid_ttl
!= 0)
1467 if (item
->is_user
!= UNDEF_ISUSER
)
1470 if (item
->sid_prefix
)
1471 free((char *)item
->sid_prefix
);
1474 cache
->purge_time
= now
;
1479 idmap_purge_winname2uid_gid_cache(winname2uid_gid_cache_t
*cache
, size_t limit
)
1481 time_t now
= time(NULL
);
1482 winname2uid_gid_t
*item
;
1484 while (avl_numnodes(&cache
->tree
) > limit
) {
1485 /* Remove least recently used */
1486 item
= cache
->head
.blink
;
1488 avl_remove(&cache
->tree
, item
);
1489 if (item
->uid_ttl
!= 0)
1491 if (item
->gid_ttl
!= 0)
1495 free((char *)item
->winname
);
1496 if (item
->windomain
)
1497 free((char *)item
->windomain
);
1500 cache
->purge_time
= now
;
1505 idmap_purge_pid2sid_winname_cache(pid2sid_winname_cache_t
*cache
, size_t limit
)
1507 time_t now
= time(NULL
);
1508 pid2sid_winname_t
*item
;
1510 while (avl_numnodes(&cache
->tree
) > limit
) {
1511 /* Remove least recently used */
1512 item
= cache
->head
.blink
;
1514 avl_remove(&cache
->tree
, item
);
1515 if (item
->winname_ttl
!= 0)
1516 cache
->winname_num
--;
1517 if (item
->sid_ttl
!= 0)
1521 free((char *)item
->winname
);
1522 if (item
->windomain
)
1523 free((char *)item
->windomain
);
1524 if (item
->sid_prefix
)
1525 free((char *)item
->sid_prefix
);
1528 cache
->purge_time
= now
;