4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
34 #include "nis_hashitem.h"
36 #include "ldap_parse.h"
40 * Global structure keeping config state. Since it's created and modified
41 * while the rpc.nisd still is single-threaded, and only read in MT mode,
42 * no locking is needed.
44 __nis_config_t ldapConfig
= {
45 ini_none
, /* nisplusLDAPinitialUpdate */
46 pass_error
, /* nisplusLDAPthreadCreationError */
49 15 /* 15 second timeout */
51 de_retry
, /* nisplusLDAPdumpError */
54 200 /* 200 second timeout */
56 directory_locked
, /* nisplusLDAPresyncService */
57 accumulate
, /* nisplusLDAPupdateBatching */
60 120 /* Accumulate for 120 seconds */
62 block
/* nisplusLDAPexclusiveWaitMOde */
67 * Utility function that accepts a (__nisdb_retry_t *), decrements the
68 * 'attempts' counter, and sleeps for 'timeout' seconds.
70 * NOTE: Don't pass a pointer into the 'ldapConfig' structure to
71 * this function. Instead, initialize a private copy to the
72 * value from 'ldapConfig'.
74 * The value of 'attempts' upon entry determines action as follows:
76 * < 0 Don't change 'attempts', sleep as indicated, return 1
78 * 0 Don't change 'attempts', only sleep if forceSleep is set,
79 * return 0 if we didn't sleep, 1 if we slept.
81 * > 0 Decrement 'attempts', sleep as indicated, return 1
84 __nis_retry_sleep(__nisdb_retry_t
*retry
, int forceSleep
) {
89 if (retry
->attempts
> 0) {
91 } else if (retry
->attempts
== 0 && !forceSleep
) {
95 (void) poll(NULL
, 0, retry
->timeout
*1000);
101 * The root directory is special in NIS+; it's the only directory that
102 * doesn't appear as an entry in another directory. Hence, our method
103 * of keeping the directory/table entry expiration time in the
104 * directory/table doesn't work, and we instead implement the following
107 static time_t rootDirExpire
= 0;
108 static int rootDirTtl
= 0;
111 * Return 1 if the root dir has expired, 0 otherwise.
114 rootDirExpired(void) {
117 (void) gettimeofday(&now
, 0);
119 if (rootDirExpire
>= now
.tv_sec
)
126 * Update the expiration time of the root dir to be now plus the TTL.
127 * Also establishes the TTL if not set.
134 (void) gettimeofday(&now
, 0);
136 /* Do we need to initialize the TTL ? */
137 if (rootDirTtl
== 0) {
138 __nis_table_mapping_t
*t
;
140 t
= __nis_find_item_mt(ROOTDIRFILE
, &ldapMappingList
, 0, 0);
144 interval
= t
->initTtlHi
- t
->initTtlLo
+ 1;
148 ttl
= (lrand48() % interval
);
155 ttl
= rootDirTtl
= 3600;
161 rootDirExpire
= now
.tv_sec
+ ttl
;