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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * libsldap - library side configuration components
28 * Routines to manage the config structure
45 #include <arpa/inet.h>
46 #include <sys/types.h>
50 #include <sys/systeminfo.h>
55 #include "ns_internal.h"
56 #include "ns_cache_door.h"
57 #include "ns_connmgmt.h"
59 #pragma fini(__s_api_shutdown_conn_mgmt, \
60 _free_config, __ns_ldap_doorfd_close)
62 static mutex_t ns_parse_lock
= DEFAULTMUTEX
;
63 static mutex_t ns_loadrefresh_lock
= DEFAULTMUTEX
;
64 static ns_config_t
*current_config
= NULL
;
66 static int cache_server
= FALSE
;
67 extern thread_key_t ns_cmgkey
;
70 * Parameter Index Type validation routines
73 __s_val_postime(ParamIndexType i
, ns_default_config
*def
,
74 ns_param_t
*param
, char *errbuf
);
76 __s_val_basedn(ParamIndexType i
, ns_default_config
*def
,
77 ns_param_t
*param
, char *errbuf
);
80 __s_val_binddn(ParamIndexType i
, ns_default_config
*def
,
81 ns_param_t
*param
, char *errbuf
);
84 __s_val_bindpw(ParamIndexType i
, ns_default_config
*def
,
85 ns_param_t
*param
, char *errbuf
);
88 __s_val_serverList(ParamIndexType i
, ns_default_config
*def
,
89 ns_param_t
*param
, char *errbuf
);
92 * Forward declarations
95 static ns_parse_status
96 verify_value(ns_config_t
*cfg
, char *name
, char *value
, char *errstr
);
99 set_default_value(ns_config_t
*configptr
, char *name
, char *value
,
100 ns_ldap_error_t
**error
);
103 set_curr_config(ns_config_t
*ptr
);
106 __door_getldapconfig(char **buffer
, int *buflen
, ns_ldap_error_t
**error
);
109 SetDoorInfo(char *buffer
, ns_ldap_error_t
**errorp
);
112 timetorefresh(ns_config_t
*cfg
);
115 LoadCacheConfiguration(ns_config_t
*, ns_ldap_error_t
**error
);
118 dupParam(ns_param_t
*ptr
);
124 * Structures used in enum <-> string mapping routines
127 static ns_enum_map ns_auth_enum_v1
[] = {
128 { ENUM2INT(NS_LDAP_EA_NONE
), "NS_LDAP_AUTH_NONE" },
129 { ENUM2INT(NS_LDAP_EA_SIMPLE
), "NS_LDAP_AUTH_SIMPLE" },
130 { ENUM2INT(NS_LDAP_EA_SASL_CRAM_MD5
), "NS_LDAP_AUTH_SASL_CRAM_MD5" },
134 static ns_enum_map ns_auth_enum_v2
[] = {
135 { ENUM2INT(NS_LDAP_EA_NONE
), "none" },
136 { ENUM2INT(NS_LDAP_EA_SIMPLE
), "simple" },
137 { ENUM2INT(NS_LDAP_EA_SASL_CRAM_MD5
), "sasl/CRAM-MD5" },
138 { ENUM2INT(NS_LDAP_EA_SASL_DIGEST_MD5
), "sasl/DIGEST-MD5" },
139 { ENUM2INT(NS_LDAP_EA_SASL_DIGEST_MD5_INT
),
140 "sasl/DIGEST-MD5:auth-int" },
141 { ENUM2INT(NS_LDAP_EA_SASL_DIGEST_MD5_CONF
),
142 "sasl/DIGEST-MD5:auth-conf" },
143 { ENUM2INT(NS_LDAP_EA_SASL_EXTERNAL
), "sasl/EXTERNAL" },
144 { ENUM2INT(NS_LDAP_EA_SASL_GSSAPI
), "sasl/GSSAPI" },
145 { ENUM2INT(NS_LDAP_EA_TLS_NONE
), "tls:none" },
146 { ENUM2INT(NS_LDAP_EA_TLS_SIMPLE
), "tls:simple" },
147 { ENUM2INT(NS_LDAP_EA_TLS_SASL_CRAM_MD5
), "tls:sasl/CRAM-MD5" },
148 { ENUM2INT(NS_LDAP_EA_TLS_SASL_DIGEST_MD5
), "tls:sasl/DIGEST-MD5" },
149 { ENUM2INT(NS_LDAP_EA_TLS_SASL_DIGEST_MD5_INT
),
150 "tls:sasl/DIGEST-MD5:auth-int" },
151 { ENUM2INT(NS_LDAP_EA_TLS_SASL_DIGEST_MD5_CONF
),
152 "tls:sasl/DIGEST-MD5:auth-conf" },
153 { ENUM2INT(NS_LDAP_EA_TLS_SASL_EXTERNAL
), "tls:sasl/EXTERNAL" },
158 static ns_enum_map ns_sec_enum_v1
[] = {
159 { ENUM2INT(NS_LDAP_TLS_NONE
), "NS_LDAP_SEC_NONE" },
164 static ns_enum_map ns_cred_enum_v2
[] = {
165 { ENUM2INT(NS_LDAP_CRED_ANON
), "anonymous" },
166 { ENUM2INT(NS_LDAP_CRED_PROXY
), "proxy" },
167 { ENUM2INT(NS_LDAP_CRED_SELF
), "self" },
171 static ns_enum_map ns_ref_enum_v1
[] = {
172 { ENUM2INT(NS_LDAP_FOLLOWREF
), "NS_LDAP_FOLLOWREF" },
173 { ENUM2INT(NS_LDAP_NOREF
), "NS_LDAP_NOREF" },
177 static ns_enum_map ns_ref_enum_v2
[] = {
178 { ENUM2INT(NS_LDAP_FOLLOWREF
), "TRUE" },
179 { ENUM2INT(NS_LDAP_NOREF
), "FALSE" },
183 static ns_enum_map ns_scope_enum_v1
[] = {
184 { ENUM2INT(NS_LDAP_SCOPE_BASE
), "NS_LDAP_SCOPE_BASE" },
185 { ENUM2INT(NS_LDAP_SCOPE_ONELEVEL
), "NS_LDAP_SCOPE_ONELEVEL" },
186 { ENUM2INT(NS_LDAP_SCOPE_SUBTREE
), "NS_LDAP_SCOPE_SUBTREE" },
190 static ns_enum_map ns_scope_enum_v2
[] = {
191 { ENUM2INT(NS_LDAP_SCOPE_BASE
), "base" },
192 { ENUM2INT(NS_LDAP_SCOPE_ONELEVEL
), "one" },
193 { ENUM2INT(NS_LDAP_SCOPE_SUBTREE
), "sub" },
197 static ns_enum_map ns_pref_enum
[] = {
198 { ENUM2INT(NS_LDAP_PREF_FALSE
), "NS_LDAP_FALSE" },
199 { ENUM2INT(NS_LDAP_PREF_TRUE
), "NS_LDAP_TRUE" },
203 static ns_enum_map ns_shadow_update_enum
[] = {
204 { ENUM2INT(NS_LDAP_ENABLE_SHADOW_UPDATE_FALSE
), "FALSE" },
205 { ENUM2INT(NS_LDAP_ENABLE_SHADOW_UPDATE_TRUE
), "TRUE" },
209 static int ns_def_auth_v1
[] = {
210 ENUM2INT(NS_LDAP_EA_NONE
),
214 static int ns_def_auth_v2
[] = {
215 ENUM2INT(NS_LDAP_EA_NONE
),
219 static int ns_def_cred_v1
[] = {
220 ENUM2INT(NS_LDAP_CRED_PROXY
),
224 static int ns_def_cred_v2
[] = {
225 ENUM2INT(NS_LDAP_CRED_ANON
),
230 * The next macro places an integer in the first sizeof(int) bytes of a
231 * void pointer location. For 32-bit, it is the same as "(void *) i". It
232 * is used to solve a problem found during 64-bit testing. The problem
233 * was that for a configuration parameter such as NS_LDAP_SEARCH_REF_P,
234 * which is of type INT and has defined default value, an int
235 * variable(ns_param.ns_pu.i) defined inside an union(ns_pu) structure, is
236 * used to access the defined default value. This requires the default
237 * value to be in the first sizeof(int) bytes of the union element. If
238 * just using "(void *) intval" to declare the default value in the
239 * following defconfig[] structure, the intval data will be placed is the
240 * last sizeof(int) bytes. In which case, when accessing via ns_pu_i in
241 * a 64-bit system, ZERO will be returned as the default value, not the
244 * Note since amd64 is little-endian, the problem is not an issue.
245 * INT2VOIDPTR will just leave the data (i) unchanged.
248 #define INT2VOIDPTR(i) (void *)i
250 #define INT2VOIDPTR(i) \
251 (void *)(((long)(i))<<(8*(sizeof (void *) - sizeof (int))))
254 * The default configuration table
255 * Version 1 entries are first, V2 entries follow.
257 static ns_default_config defconfig
[] = {
258 /* optional V1 profile */
259 {"NS_LDAP_FILE_VERSION", NS_LDAP_FILE_VERSION_P
,
260 CLIENTCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
261 NULL
, /* No version number defined in V1 */
262 { CHARPTR
, 0, (void *)NS_LDAP_VERSION_1
},
265 /* ---------- V1 profile ---------- */
266 {"NS_LDAP_BINDDN", NS_LDAP_BINDDN_P
,
267 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
269 { CHARPTR
, 0, NULL
},
270 __s_val_binddn
, NULL
},
272 {"NS_LDAP_BINDPASSWD", NS_LDAP_BINDPASSWD_P
,
273 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
275 { CHARPTR
, 0, NULL
},
276 __s_val_bindpw
, NULL
},
278 {"NS_LDAP_SERVERS", NS_LDAP_SERVERS_P
,
279 SERVERCONFIG
, ARRAYCP
, FALSE
, NS_LDAP_V1
,
281 { ARRAYCP
, 0, NULL
},
282 __s_val_serverList
, NULL
},
284 {"NS_LDAP_SEARCH_BASEDN", NS_LDAP_SEARCH_BASEDN_P
,
285 SERVERCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
287 { CHARPTR
, 0, NULL
},
288 __s_val_basedn
, NULL
},
290 {"NS_LDAP_AUTH", NS_LDAP_AUTH_P
,
291 CLIENTCONFIG
, ARRAYAUTH
, FALSE
, NS_LDAP_V1
,
293 { ARRAYAUTH
, 1, (void *)&ns_def_auth_v1
[0] },
294 NULL
, ns_auth_enum_v1
},
296 {"NS_LDAP_TRANSPORT_SEC", NS_LDAP_TRANSPORT_SEC_P
,
297 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V1
,
298 _P1_TRANSPORTSECURITY
,
299 { INT
, 0, INT2VOIDPTR(NS_LDAP_TLS_NONE
) },
300 NULL
, ns_sec_enum_v1
},
302 {"NS_LDAP_SEARCH_REF", NS_LDAP_SEARCH_REF_P
,
303 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V1
,
305 { INT
, 0, INT2VOIDPTR(NS_LDAP_FOLLOWREF
) },
306 NULL
, ns_ref_enum_v1
},
308 {"NS_LDAP_DOMAIN", NS_LDAP_DOMAIN_P
,
309 CLIENTCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
310 NULL
, /* not defined in the Profile */
311 { CHARPTR
, 0, NULL
},
314 {"NS_LDAP_EXP", NS_LDAP_EXP_P
,
315 SERVERCONFIG
, TIMET
, TRUE
, NS_LDAP_V1
,
316 NULL
, /* initialized by code to time+NS_LDAP_CACHETTL */
320 {"NS_LDAP_CERT_PATH", NS_LDAP_CERT_PATH_P
,
321 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
323 { CHARPTR
, 0, NULL
},
326 {"NS_LDAP_CERT_PASS", NS_LDAP_CERT_PASS_P
,
327 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
328 _P1_CERTIFICATEPASSWORD
,
329 { CHARPTR
, 0, NULL
},
332 {"NS_LDAP_SEARCH_DN", NS_LDAP_SEARCH_DN_P
,
333 CLIENTCONFIG
, SSDLIST
, FALSE
, NS_LDAP_V1
,
335 { SSDLIST
, 0, NULL
},
338 {"NS_LDAP_SEARCH_SCOPE", NS_LDAP_SEARCH_SCOPE_P
,
339 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V1
,
341 { INT
, 0, INT2VOIDPTR(NS_LDAP_SCOPE_ONELEVEL
) },
342 NULL
, ns_scope_enum_v1
},
344 {"NS_LDAP_SEARCH_TIME", NS_LDAP_SEARCH_TIME_P
,
345 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V1
,
347 { INT
, 0, INT2VOIDPTR(NS_DEFAULT_SEARCH_TIMEOUT
) },
350 {"NS_LDAP_SERVER_PREF", NS_LDAP_SERVER_PREF_P
,
351 CLIENTCONFIG
, ARRAYCP
, FALSE
, NS_LDAP_V1
,
353 { ARRAYCP
, 0, NULL
},
354 __s_val_serverList
, NULL
},
356 {"NS_LDAP_PREF_ONLY", NS_LDAP_PREF_ONLY_P
,
357 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V1
,
358 _P1_PREFERREDSERVERONLY
,
359 { INT
, 0, INT2VOIDPTR(NS_LDAP_PREF_FALSE
) },
360 NULL
, ns_pref_enum
},
362 {"NS_LDAP_CACHETTL", NS_LDAP_CACHETTL_P
,
363 CLIENTCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
365 { CHARPTR
, 0, (void *)EXP_DEFAULT_TTL
},
366 __s_val_postime
, NULL
},
368 {"NS_LDAP_PROFILE", NS_LDAP_PROFILE_P
,
369 CLIENTCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V1
,
371 { CHARPTR
, 0, (void *)DEFAULTCONFIGNAME
},
374 {"NS_LDAP_BIND_TIME", NS_LDAP_BIND_TIME_P
,
375 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V1
,
377 { INT
, 0, INT2VOIDPTR(NS_DEFAULT_BIND_TIMEOUT
) },
380 /* This configuration option is not visible in V1 */
381 {"NS_LDAP_CREDENTIAL_LEVEL", NS_LDAP_CREDENTIAL_LEVEL_P
,
382 CLIENTCONFIG
, ARRAYCRED
, TRUE
, NS_LDAP_V1
,
383 NULL
, /* No version defined in V1 */
384 { ARRAYCRED
, 0, (void *)&ns_def_cred_v1
[0] },
387 /* ---------- V2 profile ---------- */
388 {"NS_LDAP_FILE_VERSION", NS_LDAP_FILE_VERSION_P
,
389 CLIENTCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
390 NULL
, /* No version number defined in V1 */
391 { CHARPTR
, 0, (void *)NS_LDAP_VERSION_2
},
394 {"NS_LDAP_BINDDN", NS_LDAP_BINDDN_P
,
395 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
396 NULL
, /* not defined in the Profile */
397 { CHARPTR
, 0, NULL
},
398 __s_val_binddn
, NULL
},
400 {"NS_LDAP_BINDPASSWD", NS_LDAP_BINDPASSWD_P
,
401 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
402 NULL
, /* not defined in the Profile */
403 { CHARPTR
, 0, NULL
},
404 __s_val_bindpw
, NULL
},
406 {"NS_LDAP_ENABLE_SHADOW_UPDATE", NS_LDAP_ENABLE_SHADOW_UPDATE_P
,
407 CREDCONFIG
, INT
, TRUE
, NS_LDAP_V2
,
408 NULL
, /* not defined in the Profile */
409 { INT
, 0, INT2VOIDPTR(NS_LDAP_ENABLE_SHADOW_UPDATE_FALSE
) },
410 NULL
, ns_shadow_update_enum
},
412 {"NS_LDAP_ADMIN_BINDDN", NS_LDAP_ADMIN_BINDDN_P
,
413 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
414 NULL
, /* not defined in the Profile */
415 { CHARPTR
, 0, NULL
},
416 __s_val_binddn
, NULL
},
418 {"NS_LDAP_ADMIN_BINDPASSWD", NS_LDAP_ADMIN_BINDPASSWD_P
,
419 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
420 NULL
, /* not defined in the Profile */
421 { CHARPTR
, 0, NULL
},
422 __s_val_bindpw
, NULL
},
424 {"NS_LDAP_EXP", NS_LDAP_EXP_P
,
425 SERVERCONFIG
, TIMET
, TRUE
, NS_LDAP_V2
,
426 NULL
, /* initialized by code to time+NS_LDAP_CACHETTL */
430 {"NS_LDAP_SERVER_PREF", NS_LDAP_SERVER_PREF_P
,
431 CLIENTCONFIG
, SERVLIST
, FALSE
, NS_LDAP_V2
,
433 { SERVLIST
, 0, NULL
},
434 __s_val_serverList
, NULL
},
436 {"NS_LDAP_SERVERS", NS_LDAP_SERVERS_P
,
437 SERVERCONFIG
, SERVLIST
, FALSE
, NS_LDAP_V2
,
439 { SERVLIST
, 0, NULL
},
440 __s_val_serverList
, NULL
},
442 {"NS_LDAP_SEARCH_BASEDN", NS_LDAP_SEARCH_BASEDN_P
,
443 SERVERCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
445 { CHARPTR
, 0, NULL
},
446 __s_val_basedn
, NULL
},
448 {"NS_LDAP_SEARCH_SCOPE", NS_LDAP_SEARCH_SCOPE_P
,
449 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V2
,
451 { INT
, 0, INT2VOIDPTR(NS_LDAP_SCOPE_ONELEVEL
) },
452 NULL
, ns_scope_enum_v2
},
454 {"NS_LDAP_AUTH", NS_LDAP_AUTH_P
,
455 CLIENTCONFIG
, ARRAYAUTH
, FALSE
, NS_LDAP_V2
,
457 { ARRAYAUTH
, 2, (void *)&ns_def_auth_v2
[0] },
458 NULL
, ns_auth_enum_v2
},
460 {"NS_LDAP_CREDENTIAL_LEVEL", NS_LDAP_CREDENTIAL_LEVEL_P
,
461 CLIENTCONFIG
, ARRAYCRED
, FALSE
, NS_LDAP_V2
,
463 { ARRAYCRED
, 0, (void *)&ns_def_cred_v2
[0] },
464 NULL
, ns_cred_enum_v2
},
466 {"NS_LDAP_SERVICE_SEARCH_DESC", NS_LDAP_SERVICE_SEARCH_DESC_P
,
467 CLIENTCONFIG
, SSDLIST
, FALSE
, NS_LDAP_V2
,
468 _P2_SERVICESEARCHDESC
,
469 { SSDLIST
, 0, NULL
},
472 {"NS_LDAP_SEARCH_TIME", NS_LDAP_SEARCH_TIME_P
,
473 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V2
,
475 { INT
, 0, INT2VOIDPTR(NS_DEFAULT_SEARCH_TIMEOUT
) },
478 {"NS_LDAP_BIND_TIME", NS_LDAP_BIND_TIME_P
,
479 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V2
,
481 { INT
, 0, INT2VOIDPTR(NS_DEFAULT_BIND_TIMEOUT
) },
484 {"NS_LDAP_SEARCH_REF", NS_LDAP_SEARCH_REF_P
,
485 CLIENTCONFIG
, INT
, TRUE
, NS_LDAP_V2
,
487 { INT
, 0, INT2VOIDPTR(NS_LDAP_FOLLOWREF
) },
488 NULL
, ns_ref_enum_v2
},
490 {"NS_LDAP_CACHETTL", NS_LDAP_CACHETTL_P
,
491 CLIENTCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
493 { CHARPTR
, 0, (void *)EXP_DEFAULT_TTL
},
494 __s_val_postime
, NULL
},
496 {"NS_LDAP_ATTRIBUTEMAP", NS_LDAP_ATTRIBUTEMAP_P
,
497 CLIENTCONFIG
, ATTRMAP
, FALSE
, NS_LDAP_V2
,
499 { ATTRMAP
, 0, NULL
},
502 {"NS_LDAP_OBJECTCLASSMAP", NS_LDAP_OBJECTCLASSMAP_P
,
503 CLIENTCONFIG
, OBJMAP
, FALSE
, NS_LDAP_V2
,
508 {"NS_LDAP_PROFILE", NS_LDAP_PROFILE_P
,
509 CLIENTCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
511 { CHARPTR
, 0, (void *)DEFAULTCONFIGNAME
},
514 {"NS_LDAP_SERVICE_AUTH_METHOD", NS_LDAP_SERVICE_AUTH_METHOD_P
,
515 CLIENTCONFIG
, SAMLIST
, FALSE
, NS_LDAP_V2
,
516 _P2_SERVICEAUTHMETHOD
,
517 { SAMLIST
, 0, NULL
},
520 {"NS_LDAP_SERVICE_CRED_LEVEL", NS_LDAP_SERVICE_CRED_LEVEL_P
,
521 CLIENTCONFIG
, SCLLIST
, FALSE
, NS_LDAP_V2
,
522 _P2_SERVICECREDLEVEL
,
523 { SCLLIST
, 0, NULL
},
526 {"NS_LDAP_HOST_CERTPATH", NS_LDAP_HOST_CERTPATH_P
,
527 CREDCONFIG
, CHARPTR
, TRUE
, NS_LDAP_V2
,
528 NULL
, /* not defined in the Profile */
529 { CHARPTR
, 0, (void *)NSLDAPDIRECTORY
},
532 /* array terminator [not an entry] */
533 {NULL
, NS_LDAP_FILE_VERSION_P
,
534 CLIENTCONFIG
, NS_UNKNOWN
, TRUE
, NULL
,
536 { NS_UNKNOWN
, 0, NULL
},
544 * The sysinfo man page recommends using a buffer size
545 * of 257 bytes. MAXHOSTNAMELEN is 256. So add 1 here.
547 char buf
[MAXHOSTNAMELEN
+ 1];
550 status
= sysinfo(SI_SRPC_DOMAIN
, buf
, MAXHOSTNAMELEN
);
553 /* error: not enough space to hold returned value */
554 if (status
> sizeof (buf
))
556 return (strdup(buf
));
560 __ns_ldap_setServer(int set
)
566 timetorefresh(ns_config_t
*cfg
)
569 static time_t expire
= 0;
571 if (cfg
== NULL
|| gettimeofday(&tp
, NULL
) == -1)
574 if (cfg
->paramList
[NS_LDAP_EXP_P
].ns_ptype
== TIMET
)
575 expire
= cfg
->paramList
[NS_LDAP_EXP_P
].ns_tm
;
579 return (expire
!= 0 && tp
.tv_sec
> expire
);
583 __s_get_enum_value(ns_config_t
*ptr
, char *value
, ParamIndexType i
)
585 register ns_enum_map
*mapp
;
586 char *pstart
= value
;
593 /* skip leading spaces */
594 while (*pstart
== SPACETOK
)
596 /* skip trailing spaces */
597 pend
= pstart
+ strlen(pstart
) - 1;
598 for (; pend
>= pstart
&& *pend
== SPACETOK
; pend
--)
600 len
= pend
- pstart
+ 1;
606 if (ptr
->version
== NS_LDAP_V1
)
607 mapp
= &ns_auth_enum_v1
[0];
609 mapp
= &ns_auth_enum_v2
[0];
611 case NS_LDAP_TRANSPORT_SEC_P
:
613 case NS_LDAP_SEARCH_SCOPE_P
:
614 if (ptr
->version
== NS_LDAP_V1
)
615 mapp
= &ns_scope_enum_v1
[0];
617 mapp
= &ns_scope_enum_v2
[0];
619 case NS_LDAP_SEARCH_REF_P
:
620 if (ptr
->version
== NS_LDAP_V1
)
621 mapp
= &ns_ref_enum_v1
[0];
623 mapp
= &ns_ref_enum_v2
[0];
625 case NS_LDAP_PREF_ONLY_P
:
626 mapp
= &ns_pref_enum
[0];
628 case NS_LDAP_ENABLE_SHADOW_UPDATE_P
:
629 mapp
= &ns_shadow_update_enum
[0];
631 case NS_LDAP_CREDENTIAL_LEVEL_P
:
632 if (ptr
->version
== NS_LDAP_V1
)
635 mapp
= &ns_cred_enum_v2
[0];
637 case NS_LDAP_SERVICE_AUTH_METHOD_P
:
638 mapp
= &ns_auth_enum_v2
[0];
640 case NS_LDAP_SERVICE_CRED_LEVEL_P
:
641 mapp
= &ns_cred_enum_v2
[0];
647 for (; mapp
->name
!= NULL
; mapp
++) {
648 if (strncasecmp(pstart
, mapp
->name
, len
) == 0 &&
649 (strlen(mapp
->name
) == len
)) {
650 return (mapp
->value
);
657 __s_get_auth_name(ns_config_t
*ptr
, AuthType_t type
)
659 register ns_enum_map
*mapp
;
661 if (ptr
->version
== NS_LDAP_V1
)
662 mapp
= &ns_auth_enum_v1
[0];
664 mapp
= &ns_auth_enum_v2
[0];
666 for (; mapp
->name
!= NULL
; mapp
++) {
667 if (type
== INT2AUTHENUM(mapp
->value
)) {
671 return ("Unknown AuthType_t type specified");
676 __s_get_security_name(ns_config_t
*ptr
, TlsType_t type
)
678 register ns_enum_map
*mapp
;
680 if (ptr
->version
== NS_LDAP_V1
) {
681 mapp
= &ns_sec_enum_v1
[0];
683 for (; mapp
->name
!= NULL
; mapp
++) {
684 if (type
== INT2SECENUM(mapp
->value
)) {
689 return ("Unknown TlsType_t type specified");
694 __s_get_scope_name(ns_config_t
*ptr
, ScopeType_t type
)
696 register ns_enum_map
*mapp
;
698 if (ptr
->version
== NS_LDAP_V1
)
699 mapp
= &ns_scope_enum_v1
[0];
701 mapp
= &ns_scope_enum_v2
[0];
703 for (; mapp
->name
!= NULL
; mapp
++) {
704 if (type
== INT2SCOPEENUM(mapp
->value
)) {
708 return ("Unknown ScopeType_t type specified");
713 __s_get_pref_name(PrefOnly_t type
)
715 register ns_enum_map
*mapp
= &ns_pref_enum
[0];
717 for (; mapp
->name
!= NULL
; mapp
++) {
718 if (type
== INT2PREFONLYENUM(mapp
->value
)) {
722 return ("Unknown PrefOnly_t type specified");
726 __s_get_searchref_name(ns_config_t
*ptr
, SearchRef_t type
)
728 register ns_enum_map
*mapp
;
730 if (ptr
->version
== NS_LDAP_V1
)
731 mapp
= &ns_ref_enum_v1
[0];
733 mapp
= &ns_ref_enum_v2
[0];
735 for (; mapp
->name
!= NULL
; mapp
++) {
736 if (type
== INT2SEARCHREFENUM(mapp
->value
)) {
740 return ("Unknown SearchRef_t type specified");
744 __s_get_shadowupdate_name(enableShadowUpdate_t type
)
746 register ns_enum_map
*mapp
;
748 mapp
= &ns_shadow_update_enum
[0];
750 for (; mapp
->name
!= NULL
; mapp
++) {
751 if (type
== INT2SHADOWUPDATENUM(mapp
->value
)) {
755 return ("Unknown enableShadowUpdate_t type specified");
759 __s_get_credlvl_name(ns_config_t
*ptr
, CredLevel_t type
)
761 register ns_enum_map
*mapp
;
763 if (ptr
->version
== NS_LDAP_V2
) {
764 mapp
= &ns_cred_enum_v2
[0];
765 for (; mapp
->name
!= NULL
; mapp
++) {
766 if (type
== INT2CREDLEVELENUM(mapp
->value
)) {
771 return ("Unknown CredLevel_t type specified");
775 destroy_param(ns_config_t
*ptr
, ParamIndexType type
)
784 * This routine is not lock protected because
785 * the config param it may be destroying is not
786 * necessarily THE config. Mutex protect elsewhere.
788 switch (ptr
->paramList
[type
].ns_ptype
) {
790 if (ptr
->paramList
[type
].ns_pc
) {
791 free(ptr
->paramList
[type
].ns_pc
);
792 ptr
->paramList
[type
].ns_pc
= NULL
;
800 if (ptr
->paramList
[type
].ns_ppc
) {
801 ppc
= ptr
->paramList
[type
].ns_ppc
;
802 j
= ptr
->paramList
[type
].ns_acnt
;
803 for (i
= 0; i
< j
&& ppc
[i
] != NULL
; i
++) {
804 free((void *)ppc
[i
]);
807 ptr
->paramList
[type
].ns_ppc
= NULL
;
812 if (ptr
->paramList
[type
].ns_pi
) {
813 free(ptr
->paramList
[type
].ns_pi
);
814 ptr
->paramList
[type
].ns_pi
= NULL
;
818 ptr
->paramList
[type
].ns_i
= 0;
827 ptr
->paramList
[type
].ns_ptype
= NS_UNKNOWN
;
831 destroy_config(ns_config_t
*ptr
)
836 if (ptr
== current_config
)
837 current_config
= NULL
;
838 free(ptr
->domainName
);
839 ptr
->domainName
= NULL
;
840 for (i
= 0; i
<= LAST_VALUE
; i
++) {
841 destroy_param(ptr
, i
);
843 __s_api_destroy_hash(ptr
);
849 * Marks the ns_config_t to be deleted and then releases it. (If no other
850 * caller is using, then __s_api_release_config will destroy it.)
852 * Note that __s_api_destroy_config should only be called if the caller has
853 * created the ns_config_t with __s_api_create_config (with the exception
854 * of set_curr_config). The ns_config_t should be private to the caller.
856 * This function should not be called with the current_config except by
857 * set_curr_config which locks ns_parse_lock to ensure that no thread
858 * will be waiting on current_config->config_mutex. This ensures that
859 * no caller with be waiting on cfg->config_mutex while it is being
860 * destroyed by __s_api_release_config.
864 __s_api_destroy_config(ns_config_t
*cfg
)
867 (void) mutex_lock(&cfg
->config_mutex
);
869 (void) mutex_unlock(&cfg
->config_mutex
);
870 __s_api_release_config(cfg
);
876 * Increment the configuration use count by one - assumes ns_parse_lock has
881 get_curr_config_unlocked(ns_config_t
*cfg
, boolean_t global
)
887 (void) mutex_lock(&cfg
->config_mutex
);
889 * allow access to per connection management (non-global)
890 * config so operations on connection being closed can still
893 if (cfg
->delete && global
== B_TRUE
)
897 (void) mutex_unlock(&cfg
->config_mutex
);
903 * set_curr_config_global sets the current global config to the
904 * specified ns_config_t. Note that this function is similar
905 * to the project private function __s_api_init_config_global
906 * except that it does not release the new ns_config_t.
909 set_curr_config_global(ns_config_t
*ptr
)
912 ns_config_t
*cur_cfg
;
914 (void) mutex_lock(&ns_parse_lock
);
915 cur_cfg
= current_config
;
916 cfg
= get_curr_config_unlocked(cur_cfg
, B_TRUE
);
918 __s_api_destroy_config(cfg
);
919 current_config
= ptr
;
921 (void) mutex_unlock(&ns_parse_lock
);
926 * set_curr_config sets the current config or the per connection
927 * management one to the specified ns_config_t. Note that this function
928 * is similar to the project private function __s_api_init_config
929 * except that it does not release the new ns_config_t. Also note
930 * that if there's no per connection management one to set, the
931 * global current config will be set.
935 set_curr_config(ns_config_t
*ptr
)
938 ns_config_t
*cur_cfg
;
942 rc
= thr_getspecific(ns_cmgkey
, (void **)&cmg
);
944 /* set the per connection management config if possible */
945 if (rc
== 0 && cmg
!= NULL
&& cmg
->config
!= NULL
) {
946 (void) mutex_lock(&cmg
->cfg_lock
);
947 cur_cfg
= cmg
->config
;
948 cfg
= get_curr_config_unlocked(cur_cfg
, B_FALSE
);
950 __s_api_destroy_config(cfg
);
953 (void) mutex_unlock(&cmg
->cfg_lock
);
957 /* else set the global current config */
958 set_curr_config_global(ptr
);
962 * Decrements the ns_config_t usage count by one. Delete if delete flag
963 * is set and no other callers are using.
967 __s_api_release_config(ns_config_t
*cfg
)
970 (void) mutex_lock(&cfg
->config_mutex
);
972 if (cfg
->nUse
== 0 && cfg
->delete) {
975 (void) mutex_unlock(&cfg
->config_mutex
);
980 * __s_api_init_config function destroys the previous global configuration
981 * sets the new global configuration and then releases it
984 __s_api_init_config_global(ns_config_t
*ptr
)
986 set_curr_config_global(ptr
);
987 __s_api_release_config(ptr
);
991 * __s_api_init_config function destroys the previous configuration
992 * sets the new configuration and then releases it. The configuration
993 * may be the global one or the per connection management one.
996 __s_api_init_config(ns_config_t
*ptr
)
998 set_curr_config(ptr
);
999 __s_api_release_config(ptr
);
1004 * Create an ns_config_t, set the usage count to one
1008 __s_api_create_config(void)
1011 ret
= (ns_config_t
*)calloc(1, sizeof (ns_config_t
));
1015 ret
->domainName
= __getdomainname();
1016 if (ret
->domainName
== NULL
) {
1020 ret
->version
= NS_LDAP_V1
;
1021 (void) mutex_init(&ret
->config_mutex
, USYNC_THREAD
, NULL
);
1023 ret
->delete = B_FALSE
;
1028 * __s_api_get_default_config_global returns the current global config
1031 __s_api_get_default_config_global(void)
1034 ns_config_t
*cur_cfg
;
1036 (void) mutex_lock(&ns_parse_lock
);
1037 cur_cfg
= current_config
;
1038 cfg
= get_curr_config_unlocked(cur_cfg
, B_TRUE
);
1039 (void) mutex_unlock(&ns_parse_lock
);
1045 * __s_api_get_default_config returns the current global config or the
1046 * per connection management one.
1049 __s_api_get_default_config(void)
1052 ns_config_t
*cur_cfg
;
1053 ns_conn_mgmt_t
*cmg
;
1056 rc
= thr_getspecific(ns_cmgkey
, (void **)&cmg
);
1058 /* get the per connection management config if available */
1059 if (rc
== 0 && cmg
!= NULL
&& cmg
->config
!= NULL
) {
1060 (void) mutex_lock(&cmg
->cfg_lock
);
1061 cur_cfg
= cmg
->config
;
1062 cfg
= get_curr_config_unlocked(cur_cfg
, B_FALSE
);
1063 (void) mutex_unlock(&cmg
->cfg_lock
);
1067 /* else get the global current config */
1068 return (__s_api_get_default_config_global());
1072 stripdup(const char *instr
)
1074 char *pstart
= (char *)instr
;
1080 /* remove leading spaces */
1081 while (*pstart
== SPACETOK
)
1083 /* remove trailing spaces */
1084 pend
= pstart
+ strlen(pstart
) - 1;
1085 for (; pend
>= pstart
&& *pend
== SPACETOK
; pend
--)
1087 len
= pend
- pstart
+ 1;
1088 if ((ret
= malloc(len
+ 1)) == NULL
)
1091 (void) strncpy(ret
, pstart
, len
);
1098 * Note that __s_api_crosscheck is assumed to be called with an ns_config_t
1099 * that is properly protected - so that it will not change during the
1100 * duration of the call
1103 /* Size of errstr needs to be MAXERROR */
1105 __s_api_crosscheck(ns_config_t
*ptr
, char *errstr
, int check_dn
)
1109 const char *str
, *str1
;
1114 return (NS_SUCCESS
);
1116 /* check for no server specified */
1117 if (ptr
->paramList
[NS_LDAP_SERVERS_P
].ns_ppc
== NULL
) {
1118 if (ptr
->version
== NS_LDAP_V1
) {
1119 str
= NULL_OR_STR(__s_api_get_configname(
1120 NS_LDAP_SERVERS_P
));
1121 (void) snprintf(errstr
, MAXERROR
,
1122 gettext("Configuration Error: No entry for "
1123 "'%s' found"), str
);
1124 return (NS_PARSE_ERR
);
1125 } else if (ptr
->paramList
[NS_LDAP_SERVER_PREF_P
].ns_ppc
==
1127 str
= NULL_OR_STR(__s_api_get_configname(
1128 NS_LDAP_SERVERS_P
));
1129 str1
= NULL_OR_STR(__s_api_get_configname(
1130 NS_LDAP_SERVER_PREF_P
));
1131 (void) snprintf(errstr
, MAXERROR
,
1132 gettext("Configuration Error: "
1133 "Neither '%s' nor '%s' is defined"), str
, str1
);
1134 return (NS_PARSE_ERR
);
1137 if (ptr
->paramList
[NS_LDAP_CERT_PASS_P
].ns_pc
!= NULL
&&
1138 ptr
->paramList
[NS_LDAP_CERT_PATH_P
].ns_pc
== NULL
) {
1139 str
= NULL_OR_STR(__s_api_get_configname(
1140 NS_LDAP_CERT_PASS_P
));
1141 str1
= NULL_OR_STR(__s_api_get_configname(
1142 NS_LDAP_CERT_PATH_P
));
1143 (void) snprintf(errstr
, MAXERROR
,
1144 gettext("Configuration Error: %s specified "
1145 "but no value for '%s' found"), str
, str1
);
1146 return (NS_PARSE_ERR
);
1148 if (ptr
->paramList
[NS_LDAP_CERT_PASS_P
].ns_pc
== NULL
&&
1149 ptr
->paramList
[NS_LDAP_CERT_PATH_P
].ns_pc
!= NULL
) {
1150 str
= NULL_OR_STR(__s_api_get_configname(
1151 NS_LDAP_CERT_PATH_P
));
1152 str1
= NULL_OR_STR(__s_api_get_configname(
1153 NS_LDAP_CERT_PASS_P
));
1154 (void) snprintf(errstr
, MAXERROR
,
1155 gettext("Configuration Error: %s specified "
1156 "but no value for '%s' found"), str
, str1
);
1157 return (NS_PARSE_ERR
);
1159 /* check if search basedn has been specified */
1160 if (ptr
->paramList
[NS_LDAP_SEARCH_BASEDN_P
].ns_ppc
== NULL
) {
1161 str
= NULL_OR_STR(__s_api_get_configname(
1162 NS_LDAP_SEARCH_BASEDN_P
));
1163 (void) snprintf(errstr
, MAXERROR
,
1164 gettext("Configuration Error: No entry for "
1165 "'%s' found"), str
);
1166 return (NS_PARSE_ERR
);
1170 /* check for auth value....passwd/bindn if necessary */
1172 for (j
= 0; ptr
->paramList
[NS_LDAP_AUTH_P
].ns_pi
!= NULL
&&
1173 ptr
->paramList
[NS_LDAP_AUTH_P
].ns_pi
[j
] != NULL
; j
++) {
1174 value
= ptr
->paramList
[NS_LDAP_AUTH_P
].ns_pi
[j
];
1176 case NS_LDAP_EA_SIMPLE
:
1177 case NS_LDAP_EA_SASL_CRAM_MD5
:
1178 case NS_LDAP_EA_SASL_DIGEST_MD5
:
1179 case NS_LDAP_EA_SASL_DIGEST_MD5_INT
:
1180 case NS_LDAP_EA_SASL_DIGEST_MD5_CONF
:
1181 case NS_LDAP_EA_TLS_SIMPLE
:
1182 case NS_LDAP_EA_TLS_SASL_CRAM_MD5
:
1183 case NS_LDAP_EA_TLS_SASL_DIGEST_MD5
:
1184 case NS_LDAP_EA_TLS_SASL_DIGEST_MD5_INT
:
1185 case NS_LDAP_EA_TLS_SASL_DIGEST_MD5_CONF
:
1186 if (ptr
->paramList
[NS_LDAP_BINDDN_P
].ns_ppc
== NULL
) {
1187 str
= NULL_OR_STR(__s_api_get_configname(
1189 (void) snprintf(errstr
, MAXERROR
,
1190 gettext("Configuration Error: No entry for "
1191 "'%s' found"), str
);
1192 return (NS_PARSE_ERR
);
1194 if (ptr
->paramList
[NS_LDAP_BINDPASSWD_P
].ns_ppc
1196 str
= NULL_OR_STR(__s_api_get_configname(
1197 NS_LDAP_BINDPASSWD_P
));
1198 (void) snprintf(errstr
, MAXERROR
,
1199 gettext("Configuration Error: No entry for "
1200 "'%s' found"), str
);
1201 return (NS_PARSE_ERR
);
1209 * If NS_LDAP_CACHETTL is not specified,
1210 * init NS_LDAP_EXP_P here. Otherwise,
1211 * ldap_cachemgr will never refresh the profile.
1212 * Set it to current time + default
1215 if (ptr
->paramList
[NS_LDAP_CACHETTL_P
].ns_pc
== NULL
) {
1217 defconfig
[NS_LDAP_CACHETTL_P
].defval
.ns_pc
);
1218 ptr
->paramList
[NS_LDAP_EXP_P
].ns_ptype
= TIMET
;
1222 ptr
->paramList
[NS_LDAP_EXP_P
].ns_tm
= tm
;
1225 * If credential level self is defined, there should be
1226 * at least an auth method sasl/GSSAPI and vice versa.
1229 cnt
= ptr
->paramList
[NS_LDAP_CREDENTIAL_LEVEL_P
].ns_acnt
;
1230 for (i
= 0; i
< cnt
; i
++) {
1231 if (ptr
->paramList
[NS_LDAP_CREDENTIAL_LEVEL_P
].ns_pi
[i
] ==
1236 cnt
= ptr
->paramList
[NS_LDAP_AUTH_P
].ns_acnt
;
1237 for (i
= 0; i
< cnt
; i
++) {
1238 if (ptr
->paramList
[NS_LDAP_AUTH_P
].ns_pi
[i
] ==
1239 NS_LDAP_EA_SASL_GSSAPI
)
1242 if (gssapi
== 0 && self
> 0) {
1243 (void) snprintf(errstr
, MAXERROR
,
1244 gettext("Configuration Error: "
1245 "Credential level self requires "
1246 "authentication method sasl/GSSAPI"));
1247 return (NS_PARSE_ERR
);
1249 if (gssapi
> 0 && self
== 0) {
1250 (void) snprintf(errstr
, MAXERROR
,
1251 gettext("Configuration Error: "
1252 "Authentication method sasl/GSSAPI "
1253 "requires credential level self"));
1254 return (NS_PARSE_ERR
);
1256 return (NS_SUCCESS
);
1261 __s_api_get_type(const char *value
, ParamIndexType
*type
)
1265 for (i
= 0; defconfig
[i
].name
!= NULL
; i
++) {
1266 if (strcasecmp(defconfig
[i
].name
, value
) == 0) {
1267 *type
= defconfig
[i
].index
;
1275 * Externally defined version of get_type.
1276 * Includes extra error checking
1280 __ns_ldap_getParamType(const char *value
, ParamIndexType
*type
)
1282 if (value
== NULL
|| type
== NULL
)
1284 return (__s_api_get_type(value
, type
));
1288 __s_api_get_versiontype(ns_config_t
*ptr
, char *value
, ParamIndexType
*type
)
1298 for (i
= 0; defconfig
[i
].name
!= NULL
; i
++) {
1299 if (strcasecmp(defconfig
[i
].name
, value
) == 0) {
1300 if (defconfig
[i
].version
== ver
) {
1301 *type
= defconfig
[i
].index
;
1310 __s_api_get_profiletype(char *value
, ParamIndexType
*type
)
1314 for (i
= 0; defconfig
[i
].name
!= NULL
; i
++) {
1315 if (defconfig
[i
].profile_name
== NULL
)
1317 if (strcasecmp(defconfig
[i
].profile_name
, value
) == 0) {
1318 *type
= defconfig
[i
].index
;
1326 __s_api_get_configtype(ParamIndexType type
)
1330 for (i
= 0; defconfig
[i
].name
!= NULL
; i
++) {
1331 if (defconfig
[i
].index
== type
) {
1332 return (defconfig
[i
].config_type
);
1339 __s_api_get_configname(ParamIndexType type
)
1343 for (i
= 0; defconfig
[i
].name
!= NULL
; i
++) {
1344 if (defconfig
[i
].index
== type
) {
1345 if (defconfig
[i
].name
[0] == '\0')
1348 return (defconfig
[i
].name
);
1354 static ns_default_config
*
1355 get_defconfig(ns_config_t
*ptr
, ParamIndexType type
)
1362 for (i
= 0; defconfig
[i
].name
!= NULL
; i
++) {
1363 if (defconfig
[i
].index
== type
&&
1364 defconfig
[i
].version
== ver
) {
1365 return (&defconfig
[i
]);
1372 set_default_value(ns_config_t
*configptr
, char *name
,
1373 char *value
, ns_ldap_error_t
**error
)
1377 char errstr
[MAXERROR
];
1379 if (__s_api_get_type(name
, &i
) < 0) {
1380 (void) snprintf(errstr
, sizeof (errstr
), gettext(
1381 "Illegal type name (%s).\n"), name
);
1382 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
, strdup(errstr
),
1384 return (NS_LDAP_CONFIG
);
1387 if (i
!= NS_LDAP_SERVERS_P
&&
1388 i
!= NS_LDAP_SERVICE_AUTH_METHOD_P
&&
1389 i
!= NS_LDAP_SERVICE_CRED_LEVEL_P
&&
1390 i
!= NS_LDAP_SERVICE_SEARCH_DESC_P
&&
1391 i
!= NS_LDAP_SERVER_PREF_P
&&
1392 i
!= NS_LDAP_SEARCH_DN_P
) {
1393 if (configptr
->paramList
[i
].ns_ptype
!= NS_UNKNOWN
) {
1394 destroy_param(configptr
, i
);
1398 ret
= __ns_ldap_setParamValue(configptr
, i
, value
, error
);
1404 * Initialize config to a default state
1405 * By default leave configuration empty
1406 * getParam will automatically get the
1407 * appropriate default value if none exists
1411 __ns_ldap_default_config()
1415 ptr
= __s_api_create_config();
1419 set_curr_config(ptr
);
1420 __s_api_release_config(ptr
);
1424 * Get the current configuration pointer and return it.
1425 * If necessary initialize or refresh the current
1426 * configuration as applicable. If global is set, returns
1430 static ns_config_t
*
1431 loadrefresh_config(boolean_t global
)
1434 ns_config_t
*new_cfg
;
1435 ns_ldap_error_t
*errorp
;
1437 /* We want to refresh only one configuration at a time */
1438 (void) mutex_lock(&ns_loadrefresh_lock
);
1439 if (global
== B_TRUE
)
1440 cfg
= __s_api_get_default_config_global();
1442 cfg
= __s_api_get_default_config();
1444 /* (re)initialize configuration if necessary */
1445 if (!__s_api_isStandalone() && timetorefresh(cfg
)) {
1446 new_cfg
= LoadCacheConfiguration(cfg
, &errorp
);
1447 if (new_cfg
!= NULL
&& new_cfg
!= cfg
) {
1448 __s_api_release_config(cfg
);
1449 if (global
== B_TRUE
)
1450 set_curr_config_global(new_cfg
);
1452 set_curr_config(new_cfg
);
1456 (void) __ns_ldap_freeError(&errorp
);
1458 (void) mutex_unlock(&ns_loadrefresh_lock
);
1463 * Get the current global configuration pointer and return it.
1464 * If necessary initialize or refresh the current
1465 * configuration as applicable.
1469 __s_api_loadrefresh_config_global()
1471 return (loadrefresh_config(B_TRUE
));
1475 * Get the current configuration pointer and return it.
1476 * If necessary initialize or refresh the current
1477 * configuration as applicable. The configuration may
1478 * be the global one or the per connection management one.
1482 __s_api_loadrefresh_config()
1484 return (loadrefresh_config(B_FALSE
));
1488 * In general this routine is not very usefull. Individual routines can be
1489 * created to do this job. Once that is done, this function can be removed.
1490 * Size of errstr buffer needs to be MAXERROR.
1492 static ns_parse_status
1493 verify_value(ns_config_t
*cfg
, char *name
, char *value
, char *errstr
)
1495 ParamIndexType index
= 0;
1497 char *ptr
= NULL
, *strptr
= NULL
, buffer
[BUFSIZE
];
1499 ns_default_config
*def
= NULL
;
1501 if (__s_api_get_type(name
, &index
) != 0) {
1502 (void) snprintf(errstr
, MAXERROR
,
1503 gettext("Unknown keyword encountered '%s'."), name
);
1504 return (NS_PARSE_ERR
);
1507 def
= get_defconfig(cfg
, index
);
1509 /* eat up beginning quote, if any */
1510 while (value
!= NULL
&& (*value
== QUOTETOK
|| *value
== SPACETOK
))
1513 /* eat up space/quote at end of value */
1514 if (strlen(value
) > 0)
1515 ptr
= value
+ strlen(value
) - 1;
1518 for (; ptr
!= value
&& (*ptr
== SPACETOK
|| *ptr
== QUOTETOK
); ptr
--) {
1524 case NS_LDAP_CACHETTL_P
:
1525 case NS_LDAP_CERT_PATH_P
:
1526 case NS_LDAP_CERT_PASS_P
:
1527 case NS_LDAP_CERT_NICKNAME_P
:
1528 case NS_LDAP_BINDDN_P
:
1529 case NS_LDAP_BINDPASSWD_P
:
1530 case NS_LDAP_ADMIN_BINDDN_P
:
1531 case NS_LDAP_ADMIN_BINDPASSWD_P
:
1532 case NS_LDAP_DOMAIN_P
:
1533 case NS_LDAP_SEARCH_BASEDN_P
:
1534 case NS_LDAP_SEARCH_TIME_P
:
1535 case NS_LDAP_PROFILE_P
:
1536 case NS_LDAP_AUTH_P
:
1537 case NS_LDAP_SEARCH_SCOPE_P
:
1538 case NS_LDAP_CREDENTIAL_LEVEL_P
:
1539 case NS_LDAP_SERVICE_SEARCH_DESC_P
:
1540 case NS_LDAP_BIND_TIME_P
:
1541 case NS_LDAP_ATTRIBUTEMAP_P
:
1542 case NS_LDAP_OBJECTCLASSMAP_P
:
1543 case NS_LDAP_SERVICE_AUTH_METHOD_P
:
1544 case NS_LDAP_SERVICE_CRED_LEVEL_P
:
1545 case NS_LDAP_HOST_CERTPATH_P
:
1547 case NS_LDAP_SEARCH_DN_P
:
1548 /* depreciated because of service descriptors */
1549 /* Parse as appropriate at descriptor create time */
1551 case NS_LDAP_FILE_VERSION_P
:
1552 if (value
!= NULL
&&
1553 strcasecmp(value
, NS_LDAP_VERSION_1
) != 0 &&
1554 strcasecmp(value
, NS_LDAP_VERSION_2
) != 0) {
1555 (void) snprintf(errstr
, MAXERROR
,
1556 gettext("Version mismatch, expected "
1557 "cache version '%s' or '%s' but "
1558 "encountered version '%s'."),
1560 NS_LDAP_VERSION_2
, value
);
1561 return (NS_PARSE_ERR
);
1564 case NS_LDAP_SERVERS_P
:
1565 case NS_LDAP_SERVER_PREF_P
:
1566 (void) strcpy(buffer
, value
);
1567 strptr
= strtok_r(buffer
, ",", &rest
);
1568 while (strptr
!= NULL
) {
1570 tmp
= stripdup(strptr
);
1571 if (tmp
== NULL
|| (strchr(tmp
, ' ') != NULL
)) {
1572 (void) snprintf(errstr
, MAXERROR
,
1573 gettext("Invalid parameter values "
1574 "'%s' specified for keyword '%s'."),
1577 return (NS_PARSE_ERR
);
1580 strptr
= strtok_r(NULL
, ",", &rest
);
1585 while (def
->allowed
!= NULL
&&
1586 def
->allowed
[j
].name
!= NULL
&& j
< DEFMAX
) {
1587 if (strcmp(def
->allowed
[j
].name
,
1595 (void) snprintf(errstr
, MAXERROR
,
1596 gettext("Invalid option specified for "
1597 "'%s' keyword. '%s' is not a recognized "
1598 "keyword value."), name
, value
);
1599 return (NS_PARSE_ERR
);
1603 return (NS_SUCCESS
);
1607 __s_api_split_key_value(char *buffer
, char **name
, char **value
)
1612 /* split into name value pair */
1613 if ((ptr
= strchr(buffer
, TOKENSEPARATOR
)) != NULL
) {
1616 /* trim whitespace */
1617 while (*ptr
== SPACETOK
)
1624 * Set a parameter value in a generic configuration structure
1625 * Assume any necessary locks are in place. This routine would
1626 * be better named: __ns_ldap_translateString2Param
1628 * This routine translates external string format into internal
1629 * param format and saves the result in the param table.
1632 __ns_ldap_setParamValue(ns_config_t
*ptr
, const ParamIndexType type
,
1633 const void *data
, ns_ldap_error_t
**error
)
1635 ns_default_config
*def
= NULL
;
1637 ns_mapping_t
*map
, *rmap
;
1639 char *cp
, *cp2
, *end
;
1641 char errstr
[2 * MAXERROR
];
1642 char tbuf
[100], *ptbuf
;
1643 char *sid
, *origA
, **mapA
;
1646 int free_memory
, exitrc
;
1649 /* Find ParamIndexType default configuration data */
1650 def
= get_defconfig(ptr
, type
);
1652 (void) snprintf(errstr
, sizeof (errstr
),
1653 gettext("Unable to set value: "
1654 "invalid ParamIndexType (%d)"), type
);
1655 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
, strdup(errstr
),
1657 return (NS_LDAP_CONFIG
);
1660 (void) memset(&conf
, 0, sizeof (conf
));
1662 /* data is actually const char */
1665 /* eat up beginning quote, if any */
1666 while (cp
&& (*cp
== QUOTETOK
|| *cp
== SPACETOK
))
1669 /* eat up space/quote at end of value */
1670 end
= cp2
= cp
+ strlen(cp
) - 1;
1671 for (; cp2
> cp
&& (*cp2
== SPACETOK
|| *cp2
== QUOTETOK
); cp2
--)
1673 /* data is const, must duplicate */
1675 tcp
= (char *)calloc((int)(cp2
- cp
+ 2), sizeof (char));
1677 return (NS_LDAP_MEMORY
);
1687 /* Parse data according to type */
1688 switch (def
->data_type
) {
1690 switch (def
->index
) {
1691 case NS_LDAP_PREF_ONLY_P
:
1692 case NS_LDAP_SEARCH_REF_P
:
1693 case NS_LDAP_SEARCH_SCOPE_P
:
1694 case NS_LDAP_ENABLE_SHADOW_UPDATE_P
:
1695 i
= __s_get_enum_value(ptr
, cp
, def
->index
);
1697 (void) snprintf(errstr
, sizeof (errstr
),
1698 gettext("Unable to set value: "
1699 "invalid %s (%d)"), def
->name
,
1701 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
1702 strdup(errstr
), NULL
);
1705 return (NS_LDAP_CONFIG
);
1709 case NS_LDAP_TRANSPORT_SEC_P
: /* ignore TRANSPORT_SEC */
1713 if ((*cp2
== '+') || (*cp2
== '-'))
1715 for (/* empty */; *cp2
; cp2
++) {
1719 (void) snprintf(errstr
, sizeof (errstr
),
1720 gettext("Unable to set value: "
1721 "invalid %s (%d)"), def
->name
,
1723 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
1724 strdup(errstr
), NULL
);
1727 return (NS_LDAP_CONFIG
);
1735 /* Do nothing with a TIMET. Initialize it below */
1738 conf
.ns_pc
= (char *)strdup(cp
);
1739 if (conf
.ns_pc
== NULL
) {
1742 return (NS_LDAP_MEMORY
);
1746 /* first check to see if colon (:) is there */
1747 if ((strchr(cp
, COLONTOK
)) == NULL
) {
1748 (void) snprintf(errstr
, sizeof (errstr
),
1749 gettext("Unable to set value: "
1750 "invalid serviceAuthenticationMethod (%s)"),
1752 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
1753 strdup(errstr
), NULL
);
1756 return (NS_LDAP_CONFIG
);
1758 /* Appends an entry to the existing list */
1759 if (ptr
->paramList
[type
].ns_ptype
!= SAMLIST
) {
1760 conf
.ns_ppc
= (char **)calloc(2, sizeof (char *));
1761 if (conf
.ns_ppc
== NULL
) {
1764 return (NS_LDAP_MEMORY
);
1767 conf
.ns_ppc
[0] = (char *)strdup(cp
);
1768 if (conf
.ns_ppc
[0] == NULL
) {
1772 return (NS_LDAP_MEMORY
);
1778 /* Attempt to replace if possible */
1779 dpend
= strchr(cp
, COLONTOK
);
1781 dp
= (char *)malloc(len
+1);
1785 return (NS_LDAP_MEMORY
);
1787 (void) strlcpy(dp
, cp
, len
+1);
1789 for (j
= 0; j
< ptr
->paramList
[type
].ns_acnt
; j
++) {
1790 dpend
= strchr(ptr
->paramList
[type
].ns_ppc
[j
],
1794 i
= dpend
- ptr
->paramList
[type
].ns_ppc
[j
];
1797 if (strncmp(ptr
->paramList
[type
].ns_ppc
[j
],
1800 ptr
->paramList
[type
].ns_acnt
;
1802 ptr
->paramList
[type
].ns_ppc
;
1803 ptr
->paramList
[type
].ns_ppc
= NULL
;
1804 free(conf
.ns_ppc
[j
]);
1805 conf
.ns_ppc
[j
] = (char *)strdup(cp
);
1806 if (conf
.ns_ppc
[j
] == NULL
) {
1812 return (NS_LDAP_MEMORY
);
1821 break; /* Replaced completed */
1824 len
= ptr
->paramList
[type
].ns_acnt
+ 1;
1826 p
= (char **)dupParam(&ptr
->paramList
[type
]);
1830 return (NS_LDAP_MEMORY
);
1835 (char **)realloc(p
, (len
+1) * sizeof (char *));
1836 if (conf
.ns_ppc
== NULL
) {
1837 __s_api_free2dArray(p
);
1840 return (NS_LDAP_MEMORY
);
1843 conf
.ns_ppc
[len
-1] = (char *)strdup(cp
);
1844 if (conf
.ns_ppc
[len
-1] == NULL
) {
1845 __s_api_free2dArray(conf
.ns_ppc
);
1848 return (NS_LDAP_MEMORY
);
1850 conf
.ns_ppc
[len
] = NULL
;
1854 /* first check to see if colon (:) is there */
1855 if ((strchr(cp
, COLONTOK
)) == NULL
) {
1856 (void) snprintf(errstr
, sizeof (errstr
),
1857 gettext("Unable to set value: "
1858 "invalid serviceCredentialLevel (%s)"),
1860 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
1861 strdup(errstr
), NULL
);
1864 return (NS_LDAP_CONFIG
);
1866 /* Appends an entry to the existing list */
1867 if (ptr
->paramList
[type
].ns_ptype
!= SCLLIST
) {
1868 conf
.ns_ppc
= (char **)calloc(2, sizeof (char *));
1869 if (conf
.ns_ppc
== NULL
) {
1872 return (NS_LDAP_MEMORY
);
1875 conf
.ns_ppc
[0] = (char *)strdup(cp
);
1876 if (conf
.ns_ppc
[0] == NULL
) {
1880 return (NS_LDAP_MEMORY
);
1886 /* Attempt to replace if possible */
1887 dpend
= strchr(cp
, COLONTOK
);
1889 dp
= (char *)malloc(len
+1);
1893 return (NS_LDAP_MEMORY
);
1895 (void) strlcpy(dp
, cp
, len
+1);
1897 for (j
= 0; j
< ptr
->paramList
[type
].ns_acnt
; j
++) {
1898 dpend
= strchr(ptr
->paramList
[type
].ns_ppc
[j
],
1902 i
= dpend
- ptr
->paramList
[type
].ns_ppc
[j
];
1905 if (strncmp(ptr
->paramList
[type
].ns_ppc
[j
],
1908 ptr
->paramList
[type
].ns_acnt
;
1910 ptr
->paramList
[type
].ns_ppc
;
1911 ptr
->paramList
[type
].ns_ppc
= NULL
;
1912 free(conf
.ns_ppc
[j
]);
1913 conf
.ns_ppc
[j
] = (char *)strdup(cp
);
1914 if (conf
.ns_ppc
[j
] == NULL
) {
1920 return (NS_LDAP_MEMORY
);
1929 break; /* Replaced completed */
1932 len
= ptr
->paramList
[type
].ns_acnt
+ 1;
1934 p
= (char **)dupParam(&ptr
->paramList
[type
]);
1938 return (NS_LDAP_MEMORY
);
1943 (char **)realloc(p
, (len
+1) * sizeof (char *));
1944 if (conf
.ns_ppc
== NULL
) {
1945 __s_api_free2dArray(p
);
1948 return (NS_LDAP_MEMORY
);
1951 conf
.ns_ppc
[len
-1] = (char *)strdup(cp
);
1952 if (conf
.ns_ppc
[len
-1] == NULL
) {
1953 __s_api_free2dArray(conf
.ns_ppc
);
1956 return (NS_LDAP_MEMORY
);
1958 conf
.ns_ppc
[len
] = NULL
;
1963 * first check to see if colon (:) is there,
1964 * if so, make sure the serviceId is specified,
1965 * i.e., colon is not the first character
1967 if ((strchr(cp
, COLONTOK
)) == NULL
|| *cp
== COLONTOK
) {
1968 (void) snprintf(errstr
, sizeof (errstr
),
1969 gettext("Unable to set value: "
1970 "invalid serviceSearchDescriptor (%s)"),
1972 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
1973 strdup(errstr
), NULL
);
1976 return (NS_LDAP_CONFIG
);
1978 /* Appends an entry to the existing list */
1979 if (ptr
->paramList
[type
].ns_ptype
!= SSDLIST
) {
1980 conf
.ns_ppc
= (char **)calloc(2, sizeof (char *));
1981 if (conf
.ns_ppc
== NULL
) {
1984 return (NS_LDAP_MEMORY
);
1987 conf
.ns_ppc
[0] = (char *)strdup(cp
);
1988 if (conf
.ns_ppc
[0] == NULL
) {
1992 return (NS_LDAP_MEMORY
);
1998 /* Attempt to replace if possible */
1999 dpend
= strchr(cp
, COLONTOK
);
2001 dp
= (char *)malloc(len
+1);
2005 return (NS_LDAP_MEMORY
);
2007 (void) strlcpy(dp
, cp
, len
+1);
2009 for (j
= 0; j
< ptr
->paramList
[type
].ns_acnt
; j
++) {
2010 dpend
= strchr(ptr
->paramList
[type
].ns_ppc
[j
],
2014 i
= dpend
- ptr
->paramList
[type
].ns_ppc
[j
];
2017 if (strncmp(ptr
->paramList
[type
].ns_ppc
[j
],
2020 ptr
->paramList
[type
].ns_acnt
;
2022 ptr
->paramList
[type
].ns_ppc
;
2023 ptr
->paramList
[type
].ns_ppc
= NULL
;
2024 free(conf
.ns_ppc
[j
]);
2025 conf
.ns_ppc
[j
] = (char *)strdup(cp
);
2026 if (conf
.ns_ppc
[j
] == NULL
) {
2032 return (NS_LDAP_MEMORY
);
2041 break; /* Replaced completed */
2044 len
= ptr
->paramList
[type
].ns_acnt
+ 1;
2046 p
= (char **)dupParam(&ptr
->paramList
[type
]);
2050 return (NS_LDAP_MEMORY
);
2055 (char **)realloc(p
, (len
+1) * sizeof (char *));
2056 if (conf
.ns_ppc
== NULL
) {
2057 __s_api_free2dArray(p
);
2060 return (NS_LDAP_MEMORY
);
2063 conf
.ns_ppc
[len
-1] = (char *)strdup(cp
);
2064 if (conf
.ns_ppc
[len
-1] == NULL
) {
2065 __s_api_free2dArray(conf
.ns_ppc
);
2068 return (NS_LDAP_MEMORY
);
2070 conf
.ns_ppc
[len
] = NULL
;
2075 for (cp2
= cp
; *cp2
; cp2
++) {
2076 if (*cp2
== COMMATOK
)
2082 conf
.ns_ppc
= (char **)NULL
;
2086 conf
.ns_ppc
= (char **)calloc(len
+ 1, sizeof (char *));
2087 if (conf
.ns_ppc
== NULL
) {
2090 return (NS_LDAP_MEMORY
);
2094 for (cp2
= cp
; *cp2
; cp2
++) {
2095 if (*cp2
== COMMATOK
) {
2097 conf
.ns_ppc
[i
] = (char *)malloc(j
+ 1);
2098 if (conf
.ns_ppc
[i
] == NULL
) {
2099 __s_api_free2dArray(conf
.ns_ppc
);
2102 return (NS_LDAP_MEMORY
);
2104 (void) strlcpy(conf
.ns_ppc
[i
], cp
, j
);
2106 while (*cp
== SPACETOK
|| *cp
== COMMATOK
)
2113 conf
.ns_ppc
[i
] = (char *)malloc(j
+ 1);
2114 if (conf
.ns_ppc
[i
] == NULL
) {
2115 __s_api_free2dArray(conf
.ns_ppc
);
2118 return (NS_LDAP_MEMORY
);
2120 (void) strlcpy(conf
.ns_ppc
[i
], cp
, j
);
2124 for (cp2
= cp
; *cp2
; cp2
++) {
2125 if (*cp2
== SPACETOK
|| *cp2
== COMMATOK
) {
2127 for (; *(cp2
+ 1) == SPACETOK
||
2128 *(cp2
+1) == COMMATOK
; cp2
++)
2135 conf
.ns_ppc
= (char **)NULL
;
2139 conf
.ns_ppc
= (char **)calloc(len
+ 1, sizeof (char *));
2140 if (conf
.ns_ppc
== NULL
) {
2143 return (NS_LDAP_MEMORY
);
2147 for (cp2
= cp
; *cp2
; cp2
++) {
2148 if (*cp2
== SPACETOK
|| *cp2
== COMMATOK
) {
2150 conf
.ns_ppc
[i
] = (char *)malloc(j
+ 1);
2151 if (conf
.ns_ppc
[i
] == NULL
) {
2152 __s_api_free2dArray(conf
.ns_ppc
);
2155 return (NS_LDAP_MEMORY
);
2157 (void) strlcpy(conf
.ns_ppc
[i
], cp
, j
);
2159 while (*cp
== SPACETOK
|| *cp
== COMMATOK
)
2166 conf
.ns_ppc
[i
] = (char *)malloc(j
+ 1);
2167 if (conf
.ns_ppc
[i
] == NULL
) {
2168 __s_api_free2dArray(conf
.ns_ppc
);
2171 return (NS_LDAP_MEMORY
);
2173 (void) strlcpy(conf
.ns_ppc
[i
], cp
, j
);
2177 for (cp2
= cp
; *cp2
; cp2
++) {
2178 if (*cp2
== SEMITOK
|| *cp2
== COMMATOK
)
2184 conf
.ns_pi
= (int *)NULL
;
2188 conf
.ns_pi
= (int *)calloc(len
+ 1, sizeof (int));
2189 if (conf
.ns_pi
== NULL
) {
2192 return (NS_LDAP_MEMORY
);
2196 for (cp2
= cp
; *cp2
; cp2
++) {
2197 if (*cp2
== SEMITOK
|| *cp2
== COMMATOK
) {
2199 if (j
> sizeof (tbuf
)) {
2203 (void) strlcpy(tbuf
, cp
, j
);
2204 j
= __s_get_enum_value(ptr
, tbuf
,
2209 (void) snprintf(errstr
, sizeof (errstr
),
2210 gettext("Unable to set value: "
2212 "authenticationMethod (%s)"),
2214 MKERROR(LOG_ERR
, *error
,
2216 strdup(errstr
), NULL
);
2220 return (NS_LDAP_CONFIG
);
2228 if (j
> sizeof (tbuf
)) {
2232 (void) strlcpy(tbuf
, cp
, j
);
2233 j
= __s_get_enum_value(ptr
, tbuf
, def
->index
);
2237 (void) snprintf(errstr
, sizeof (errstr
),
2238 gettext("Unable to set value: "
2239 "invalid authenticationMethod (%s)"), ptbuf
);
2240 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
2241 strdup(errstr
), NULL
);
2244 return (NS_LDAP_CONFIG
);
2250 for (cp2
= cp
; *cp2
; cp2
++) {
2251 if (*cp2
== SPACETOK
)
2257 conf
.ns_pi
= (int *)NULL
;
2261 conf
.ns_pi
= (int *)calloc(len
+ 1, sizeof (int));
2262 if (conf
.ns_pi
== NULL
) {
2265 return (NS_LDAP_MEMORY
);
2269 for (cp2
= cp
; *cp2
; cp2
++) {
2270 if (*cp2
== SPACETOK
) {
2272 if (j
> sizeof (tbuf
)) {
2276 (void) strlcpy(tbuf
, cp
, j
);
2277 j
= __s_get_enum_value(ptr
, tbuf
,
2282 (void) snprintf(errstr
, sizeof (errstr
),
2283 gettext("Unable to set value: "
2284 "invalid credentialLevel (%s)"),
2286 MKERROR(LOG_ERR
, *error
,
2288 strdup(errstr
), NULL
);
2292 return (NS_LDAP_CONFIG
);
2300 if (j
> sizeof (tbuf
)) {
2304 (void) strlcpy(tbuf
, cp
, j
);
2305 j
= __s_get_enum_value(ptr
, tbuf
, def
->index
);
2309 (void) snprintf(errstr
, sizeof (errstr
),
2310 gettext("Unable to set value: "
2311 "invalid credentialLevel (%s)"), ptbuf
);
2312 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
2313 strdup(errstr
), NULL
);
2316 return (NS_LDAP_CONFIG
);
2322 i
= __s_api_parse_map(cp
, &sid
, &origA
, &mapA
);
2323 if (i
!= NS_HASH_RC_SUCCESS
) {
2324 if (i
== NS_HASH_RC_NO_MEMORY
) {
2325 exitrc
= NS_LDAP_MEMORY
;
2327 (void) snprintf(errstr
, sizeof (errstr
),
2328 gettext("Unable to set value: "
2329 "invalid schema mapping (%s)"), cp
);
2330 exitrc
= NS_LDAP_CONFIG
;
2331 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
,
2332 strdup(errstr
), NULL
);
2340 * Add reverse map first.
2341 * There could be more than one.
2343 for (attr
= mapA
; *attr
; attr
++) {
2346 exitrc
= NS_LDAP_MEMORY
;
2348 rmap
= (ns_mapping_t
*)calloc(1,
2349 sizeof (ns_mapping_t
));
2351 rmap
->service
= strdup(sid
);
2352 if (rmap
->service
) {
2353 rmap
->orig
= strdup(*attr
);
2355 rmap
->map
= (char **)calloc(2,
2367 if (free_memory
== 0) {
2368 if (def
->data_type
== ATTRMAP
) {
2369 rmap
->type
= NS_ATTR_MAP
;
2370 i
= __s_api_add_map2hash(ptr
,
2371 NS_HASH_RAMAP
, rmap
);
2373 rmap
->type
= NS_OBJ_MAP
;
2374 i
= __s_api_add_map2hash(ptr
,
2375 NS_HASH_ROMAP
, rmap
);
2378 if (i
!= NS_HASH_RC_SUCCESS
) {
2380 case NS_HASH_RC_CONFIG_ERROR
:
2381 exitrc
= NS_LDAP_INTERNAL
;
2382 (void) snprintf(errstr
,
2385 "Unable to set value: "
2386 "no configuration info "
2388 "update (%s)"), cp
);
2389 MKERROR(LOG_ERR
, *error
,
2394 case NS_HASH_RC_EXISTED
:
2395 exitrc
= NS_LDAP_CONFIG
;
2396 (void) snprintf(errstr
,
2399 "Unable to set value: "
2401 "already existed for "
2404 MKERROR(LOG_ERR
, *error
,
2409 case NS_HASH_RC_NO_MEMORY
:
2410 exitrc
= NS_LDAP_MEMORY
;
2422 __s_api_free2dArray(mapA
);
2425 free(rmap
->service
);
2430 free((rmap
->map
)[0]);
2440 * For performance gain,
2441 * add a "schema mapping existed" indicator
2442 * for the given service if not already added.
2443 * This dummy map needs not be removed, if
2444 * the next real map add operation fails.
2445 * since the caller, e.g. ldap_cachemgr.
2446 * should exit anyway.
2449 exitrc
= NS_LDAP_MEMORY
;
2451 map
= (ns_mapping_t
*)calloc(1,
2452 sizeof (ns_mapping_t
));
2454 map
->service
= strdup(sid
);
2457 NS_HASH_SCHEMA_MAPPING_EXISTED
);
2459 map
->map
= (char **)calloc(2,
2471 if (free_memory
== 0) {
2472 map
->type
= NS_ATTR_MAP
;
2474 * add to reverse map,
2475 * so that "ldapclient list"
2478 i
= __s_api_add_map2hash(ptr
,
2479 NS_HASH_RAMAP
, map
);
2482 * ignore "map already existed" error,
2483 * just need one per service.
2484 * Need however to free memory allocated
2487 if (i
!= NS_HASH_RC_SUCCESS
&&
2488 i
!= NS_HASH_RC_EXISTED
) {
2490 case NS_HASH_RC_CONFIG_ERROR
:
2491 exitrc
= NS_LDAP_INTERNAL
;
2492 (void) snprintf(errstr
,
2495 "Unable to set value: "
2496 "no configuration info "
2498 "update (%s)"), cp
);
2499 MKERROR(LOG_ERR
, *error
,
2504 case NS_HASH_RC_NO_MEMORY
:
2505 exitrc
= NS_LDAP_MEMORY
;
2509 } else if (i
== NS_HASH_RC_EXISTED
) {
2516 free((map
->map
)[0]);
2529 __s_api_free2dArray(mapA
);
2537 free((map
->map
)[0]);
2546 * add the real schema map
2549 exitrc
= NS_LDAP_MEMORY
;
2550 map
= (ns_mapping_t
*)calloc(1, sizeof (ns_mapping_t
));
2556 if (def
->data_type
== ATTRMAP
) {
2557 map
->type
= NS_ATTR_MAP
;
2558 i
= __s_api_add_map2hash(ptr
,
2561 map
->type
= NS_OBJ_MAP
;
2562 i
= __s_api_add_map2hash(ptr
,
2566 if (i
!= NS_HASH_RC_SUCCESS
) {
2568 case NS_HASH_RC_CONFIG_ERROR
:
2569 exitrc
= NS_LDAP_INTERNAL
;
2570 (void) snprintf(errstr
,
2573 "Unable to set value: "
2574 "no configuration info "
2576 "update (%s)"), cp
);
2577 MKERROR(LOG_ERR
, *error
,
2582 case NS_HASH_RC_EXISTED
:
2583 exitrc
= NS_LDAP_CONFIG
;
2584 (void) snprintf(errstr
,
2587 "Unable to set value: "
2589 "already existed for "
2591 MKERROR(LOG_ERR
, *error
,
2596 case NS_HASH_RC_NO_MEMORY
:
2597 exitrc
= NS_LDAP_MEMORY
;
2610 __s_api_free2dArray(mapA
);
2618 /* This should never happen. */
2619 (void) snprintf(errstr
, sizeof (errstr
),
2620 gettext("Unable to set value: invalid configuration "
2621 "type (%d)"), def
->data_type
);
2622 MKERROR(LOG_ERR
, *error
, NS_CONFIG_SYNTAX
, strdup(errstr
),
2626 return (NS_LDAP_CONFIG
);
2628 conf
.ns_ptype
= def
->data_type
;
2632 /* Individually written verify routines here can replace */
2633 /* verify_value. Verify conf (data) as appropriate here */
2634 if (def
->ns_verify
!= NULL
) {
2635 if ((*def
->ns_verify
)(type
, def
, &conf
, errstr
) != NS_SUCCESS
) {
2636 ns_param_t sav_conf
;
2638 (void) snprintf(errstr
, sizeof (errstr
),
2639 gettext("%s"), errstr
);
2640 MKERROR(LOG_WARNING
, *error
, NS_CONFIG_SYNTAX
,
2641 strdup(errstr
), NULL
);
2643 sav_conf
= ptr
->paramList
[type
];
2644 ptr
->paramList
[type
] = conf
;
2645 destroy_param(ptr
, type
);
2646 ptr
->paramList
[type
] = sav_conf
;
2648 return (NS_LDAP_CONFIG
);
2652 /* post evaluate the data */
2655 * if this is for setting a password,
2656 * encrypt the password first.
2657 * NOTE evalue() is smart and will just return
2658 * the value passed if it is already encrypted.
2660 * Init NS_LDAP_EXP_P here when CACHETTL is updated
2662 if (type
== NS_LDAP_BINDPASSWD_P
||
2663 type
== NS_LDAP_ADMIN_BINDPASSWD_P
) {
2665 cp2
= evalue((char *)cp
);
2669 } else if (type
== NS_LDAP_FILE_VERSION_P
) {
2670 ptr
->version
= NS_LDAP_V1
;
2671 if (strcasecmp(conf
.ns_pc
, NS_LDAP_VERSION_2
) == 0) {
2672 ptr
->version
= NS_LDAP_V2
;
2674 } else if (type
== NS_LDAP_CACHETTL_P
) {
2677 ptr
->paramList
[NS_LDAP_EXP_P
].ns_ptype
= TIMET
;
2681 ptr
->paramList
[NS_LDAP_EXP_P
].ns_tm
= tm
;
2684 /* Everything checks out move new values into param */
2685 destroy_param(ptr
, type
);
2686 /* Assign new/updated value into paramList */
2687 ptr
->paramList
[type
] = conf
;
2689 return (NS_LDAP_SUCCESS
);
2694 * Set a parameter value in the 'config' configuration structure
2695 * Lock as appropriate
2699 __ns_ldap_setParam(const ParamIndexType type
,
2700 const void *data
, ns_ldap_error_t
**error
)
2702 ns_ldap_error_t
*errorp
;
2704 char errstr
[2 * MAXERROR
];
2706 ns_config_t
*cfg_g
= (ns_config_t
*)-1;
2707 ns_config_t
*new_cfg
;
2708 boolean_t reinit_connmgmt
= B_FALSE
;
2710 /* We want to refresh only one configuration at a time */
2711 (void) mutex_lock(&ns_loadrefresh_lock
);
2712 cfg
= __s_api_get_default_config();
2714 if (cache_server
== TRUE
) {
2716 __ns_ldap_default_config();
2717 cfg
= __s_api_get_default_config();
2719 (void) mutex_unlock(&ns_loadrefresh_lock
);
2720 return (NS_LDAP_MEMORY
);
2725 * This code always return error here on client side,
2726 * this needs to change once libsldap is used by more
2727 * applications that need to set parameters.
2729 (void) snprintf(errstr
, sizeof (errstr
),
2730 gettext("Unable to set parameter from a client in "
2731 "__ns_ldap_setParam()"));
2732 MKERROR(LOG_WARNING
, *error
, NS_CONFIG_SYNTAX
, strdup(errstr
),
2735 __s_api_release_config(cfg
);
2736 (void) mutex_unlock(&ns_loadrefresh_lock
);
2737 return (NS_LDAP_CONFIG
);
2740 /* (re)initialize configuration if necessary */
2741 if (!__s_api_isStandalone() &&
2742 cache_server
== FALSE
&& timetorefresh(cfg
))
2743 cfg_g
= __s_api_get_default_config_global();
2744 /* only (re)initialize the global configuration */
2747 __s_api_release_config(cfg_g
);
2748 new_cfg
= LoadCacheConfiguration(cfg
, &errorp
);
2750 __s_api_release_config(cfg
);
2751 if (new_cfg
== NULL
) {
2752 (void) snprintf(errstr
, sizeof (errstr
),
2753 gettext("Unable to load configuration '%s' "
2754 "('%s')."), NSCONFIGFILE
,
2755 errorp
!= NULL
&& errorp
->message
!= NULL
?
2756 errorp
->message
: "");
2757 MKERROR(LOG_WARNING
, *error
, NS_CONFIG_NOTLOADED
,
2758 strdup(errstr
), NULL
);
2760 (void) __ns_ldap_freeError(&errorp
);
2761 (void) mutex_unlock(&ns_loadrefresh_lock
);
2762 return (NS_LDAP_CONFIG
);
2764 if (new_cfg
!= cfg
) {
2765 set_curr_config_global(new_cfg
);
2767 reinit_connmgmt
= B_TRUE
;
2770 (void) mutex_unlock(&ns_loadrefresh_lock
);
2772 if (reinit_connmgmt
== B_TRUE
)
2773 __s_api_reinit_conn_mgmt_new_config(cfg
);
2775 /* translate input and save in the parameter list */
2776 ret
= __ns_ldap_setParamValue(cfg
, type
, data
, error
);
2778 __s_api_release_config(cfg
);
2785 * Make a copy of a parameter entry
2789 dupParam(ns_param_t
*ptr
)
2792 void **dupdata
, *ret
;
2794 char *cp
, tmbuf
[32];
2795 static time_t expire
= 0;
2798 switch (ptr
->ns_ptype
) {
2806 count
= ptr
->ns_acnt
;
2816 dupdata
= (void **)calloc((count
+ 1), sizeof (void *));
2817 if (dupdata
== NULL
)
2820 switch (ptr
->ns_ptype
) {
2822 for (i
= 0; i
< count
; i
++) {
2823 ap
= __s_api_AuthEnumtoStruct(
2824 (EnumAuthType_t
)ptr
->ns_pi
[i
]);
2833 for (i
= 0; i
< count
; i
++) {
2834 intptr
= (int *)malloc(sizeof (int));
2835 if (intptr
== NULL
) {
2839 dupdata
[i
] = (void *)intptr
;
2840 *intptr
= ptr
->ns_pi
[i
];
2848 for (i
= 0; i
< count
; i
++) {
2849 ret
= (void *)strdup(ptr
->ns_ppc
[i
]);
2858 if (ptr
->ns_pc
== NULL
) {
2862 ret
= (void *)strdup(ptr
->ns_pc
);
2870 intptr
= (int *)malloc(sizeof (int));
2871 if (intptr
== NULL
) {
2875 *intptr
= ptr
->ns_i
;
2876 dupdata
[0] = (void *)intptr
;
2879 expire
= ptr
->ns_tm
;
2881 cp
= lltostr((long)expire
, &tmbuf
[31]);
2882 ret
= (void *)strdup(cp
);
2894 __ns_ldap_freeParam(void ***data
)
2900 return (NS_LDAP_SUCCESS
);
2902 for (i
= 0, tmp
= *data
; tmp
[i
] != NULL
; i
++)
2909 return (NS_LDAP_SUCCESS
);
2913 * Get the internal format for a parameter value. This
2914 * routine makes a copy of an internal param value from
2915 * the currently active parameter list and returns it.
2919 __ns_ldap_getParam(const ParamIndexType Param
,
2920 void ***data
, ns_ldap_error_t
**error
)
2922 char errstr
[2 * MAXERROR
];
2923 ns_ldap_error_t
*errorp
;
2924 ns_default_config
*def
;
2926 ns_config_t
*cfg_g
= (ns_config_t
*)-1;
2927 ns_config_t
*new_cfg
;
2928 boolean_t reinit_connmgmt
= B_FALSE
;
2931 return (NS_LDAP_INVALID_PARAM
);
2935 /* We want to refresh only one configuration at a time */
2936 (void) mutex_lock(&ns_loadrefresh_lock
);
2937 cfg
= __s_api_get_default_config();
2939 /* (re)initialize configuration if necessary */
2940 if (!__s_api_isStandalone() &&
2941 cache_server
== FALSE
&& timetorefresh(cfg
))
2942 cfg_g
= __s_api_get_default_config_global();
2943 /* only (re)initialize the global configuration */
2946 __s_api_release_config(cfg_g
);
2947 new_cfg
= LoadCacheConfiguration(cfg
, &errorp
);
2949 __s_api_release_config(cfg
);
2950 if (new_cfg
== NULL
) {
2951 (void) snprintf(errstr
, sizeof (errstr
),
2952 gettext("Unable to load configuration "
2955 errorp
!= NULL
&& errorp
->message
!= NULL
?
2956 errorp
->message
: "");
2957 MKERROR(LOG_WARNING
, *error
, NS_CONFIG_NOTLOADED
,
2958 strdup(errstr
), NULL
);
2960 (void) __ns_ldap_freeError(&errorp
);
2961 (void) mutex_unlock(&ns_loadrefresh_lock
);
2962 return (NS_LDAP_CONFIG
);
2964 if (new_cfg
!= cfg
) {
2965 set_curr_config_global(new_cfg
);
2967 reinit_connmgmt
= B_TRUE
;
2970 (void) mutex_unlock(&ns_loadrefresh_lock
);
2972 if (reinit_connmgmt
== B_TRUE
)
2973 __s_api_reinit_conn_mgmt_new_config(cfg
);
2976 (void) snprintf(errstr
, sizeof (errstr
),
2977 gettext("No configuration information available."));
2978 MKERROR(LOG_ERR
, *error
, NS_CONFIG_NOTLOADED
,
2979 strdup(errstr
), NULL
);
2980 return (NS_LDAP_CONFIG
);
2983 if (Param
== NS_LDAP_DOMAIN_P
) {
2984 *data
= (void **)calloc(2, sizeof (void *));
2985 if (*data
== NULL
) {
2986 __s_api_release_config(cfg
);
2987 return (NS_LDAP_MEMORY
);
2989 (*data
)[0] = (void *)strdup(cfg
->domainName
);
2990 if ((*data
)[0] == NULL
) {
2992 __s_api_release_config(cfg
);
2993 return (NS_LDAP_MEMORY
);
2995 } else if (cfg
->paramList
[Param
].ns_ptype
== NS_UNKNOWN
) {
2997 def
= get_defconfig(cfg
, Param
);
2999 *data
= dupParam(&def
->defval
);
3001 *data
= dupParam(&(cfg
->paramList
[Param
]));
3003 __s_api_release_config(cfg
);
3005 return (NS_LDAP_SUCCESS
);
3009 * This routine takes a parameter in internal format and
3010 * translates it into a variety of string formats for various
3011 * outputs (doors/file/ldif). This routine would be better
3012 * named: __ns_ldap_translateParam2String
3016 __s_api_strValue(ns_config_t
*cfg
, ParamIndexType index
, ns_strfmt_t fmt
)
3018 ns_default_config
*def
= NULL
;
3023 char abuf
[64], **cpp
;
3025 boolean_t first
= B_TRUE
;
3027 LineBuf
*buffer
= &lbuf
;
3034 /* NS_LDAP_EXP and TRANSPORT_SEC are not exported externally */
3035 if (index
== NS_LDAP_EXP_P
|| index
== NS_LDAP_TRANSPORT_SEC_P
)
3038 /* Return nothing if the value is the default */
3039 if (cfg
->paramList
[index
].ns_ptype
== NS_UNKNOWN
)
3042 (void) memset((char *)buffer
, 0, sizeof (LineBuf
));
3044 ptr
= &(cfg
->paramList
[index
]);
3049 def
= get_defconfig(cfg
, index
);
3055 (void) strlcpy(abuf
, def
->name
, sizeof (abuf
));
3056 (void) strlcat(abuf
, EQUALSEP
, sizeof (abuf
));
3059 (void) strlcpy(abuf
, def
->name
, sizeof (abuf
));
3060 (void) strlcat(abuf
, EQUSPSEP
, sizeof (abuf
));
3063 /* If no LDIF attr exists ignore the entry */
3064 if (def
->profile_name
== NULL
)
3066 (void) strlcpy(abuf
, def
->profile_name
, sizeof (abuf
));
3067 (void) strlcat(abuf
, COLSPSEP
, sizeof (abuf
));
3073 if (__print2buf(buffer
, abuf
, NULL
))
3076 switch (ptr
->ns_ptype
) {
3078 count
= ptr
->ns_acnt
;
3079 for (i
= 0; i
< count
; i
++) {
3082 if (cfg
->version
== NS_LDAP_V1
) {
3088 if (__print2buf(buffer
, __s_get_auth_name(cfg
,
3089 (AuthType_t
)(ptr
->ns_pi
[i
])), sepstr
))
3094 count
= ptr
->ns_acnt
;
3095 for (i
= 0; i
< count
; i
++) {
3100 if (__print2buf(buffer
, __s_get_credlvl_name(cfg
,
3101 (CredLevel_t
)ptr
->ns_pi
[i
]), sepstr
))
3108 count
= ptr
->ns_acnt
;
3109 for (i
= 0; i
< count
; i
++) {
3110 if (__print2buf(buffer
, ptr
->ns_ppc
[i
], NULL
))
3116 /* Separate items */
3119 if (__print2buf(buffer
, DOORLINESEP
, NULL
) ||
3120 __print2buf(buffer
, def
->name
, EQUALSEP
))
3124 if (__print2buf(buffer
, "\n", NULL
) ||
3125 __print2buf(buffer
, def
->name
, EQUSPSEP
))
3129 if (__print2buf(buffer
, "\n", NULL
) ||
3130 __print2buf(buffer
, def
->profile_name
,
3138 count
= ptr
->ns_acnt
;
3139 for (i
= 0; i
< count
; i
++) {
3144 if (__print2buf(buffer
, ptr
->ns_ppc
[i
], sepstr
))
3149 count
= ptr
->ns_acnt
;
3150 for (i
= 0; i
< count
; i
++) {
3153 if (fmt
== NS_LDIF_FMT
) {
3159 if (__print2buf(buffer
, ptr
->ns_ppc
[i
], sepstr
))
3164 if (ptr
->ns_pc
== NULL
)
3166 if (__print2buf(buffer
, ptr
->ns_pc
, NULL
))
3170 switch (def
->index
) {
3171 case NS_LDAP_PREF_ONLY_P
:
3172 if (__print2buf(buffer
,
3173 __s_get_pref_name((PrefOnly_t
)ptr
->ns_i
), NULL
))
3176 case NS_LDAP_SEARCH_REF_P
:
3177 if (__print2buf(buffer
, __s_get_searchref_name(cfg
,
3178 (SearchRef_t
)ptr
->ns_i
), NULL
))
3181 case NS_LDAP_SEARCH_SCOPE_P
:
3182 if (__print2buf(buffer
, __s_get_scope_name(cfg
,
3183 (ScopeType_t
)ptr
->ns_i
), NULL
))
3186 case NS_LDAP_ENABLE_SHADOW_UPDATE_P
:
3187 if (__print2buf(buffer
, __s_get_shadowupdate_name(
3188 (enableShadowUpdate_t
)ptr
->ns_i
), NULL
))
3192 (void) snprintf(ibuf
, sizeof (ibuf
),
3194 if (__print2buf(buffer
, ibuf
, NULL
))
3200 for (hptr
= cfg
->llHead
; hptr
; hptr
= hptr
->h_llnext
) {
3201 if (hptr
->h_type
!= NS_HASH_AMAP
) {
3205 /* print abuf as "separator" */
3206 if (fmt
== NS_DOOR_FMT
) {
3207 if (__print2buf(buffer
, DOORLINESEP
,
3211 if (__print2buf(buffer
, "\n", abuf
))
3216 if (__print2buf(buffer
, mptr
->service
, COLONSEP
) ||
3217 __print2buf(buffer
, mptr
->orig
, EQUALSEP
))
3219 for (cpp
= mptr
->map
; cpp
&& *cpp
; cpp
++) {
3220 /* print *cpp as "separator" */
3222 if (cpp
!= mptr
->map
)
3224 if (__print2buf(buffer
, sepstr
, *cpp
))
3231 for (hptr
= cfg
->llHead
; hptr
; hptr
= hptr
->h_llnext
) {
3232 if (hptr
->h_type
!= NS_HASH_OMAP
) {
3236 /* print abuf as "separator" */
3237 if (fmt
== NS_DOOR_FMT
) {
3238 if (__print2buf(buffer
, DOORLINESEP
,
3242 if (__print2buf(buffer
, "\n", abuf
))
3247 if (__print2buf(buffer
, mptr
->service
, COLONSEP
) ||
3248 __print2buf(buffer
, mptr
->orig
, EQUALSEP
))
3250 for (cpp
= mptr
->map
; cpp
&& *cpp
; cpp
++) {
3251 /* print *cpp as "separator" */
3253 if (cpp
!= mptr
->map
)
3255 if (__print2buf(buffer
, sepstr
, *cpp
))
3263 retstring
= buffer
->str
;
3267 if (buffer
->len
> 0)
3272 /* shared by __door_getldapconfig() and __door_getadmincred() */
3274 __door_getconf(char **buffer
, int *buflen
, ns_ldap_error_t
**error
,
3279 char s_b
[DOORBUFFERSIZE
];
3286 char errstr
[MAXERROR
];
3288 ns_ldap_return_code retCode
;
3289 ldap_config_out_t
*cfghdr
;
3293 domainname
= __getdomainname();
3294 if (domainname
== NULL
|| buffer
== NULL
|| buflen
== NULL
||
3295 (strlen(domainname
) >= (sizeof (space_t
)
3296 - sizeof (space
->s_d
.ldap_call
.ldap_callnumber
)))) {
3297 return (NS_LDAP_OP_FAILED
);
3300 space
= (space_t
*)calloc(1, sizeof (space_t
));
3302 return (NS_LDAP_MEMORY
);
3304 adata
= (sizeof (ldap_call_t
) + strlen(domainname
) +1);
3305 ndata
= sizeof (space_t
);
3306 space
->s_d
.ldap_call
.ldap_callnumber
= callnumber
;
3307 (void) strcpy(space
->s_d
.ldap_call
.ldap_u
.domainname
, domainname
);
3312 switch (__ns_ldap_trydoorcall(&sptr
, &ndata
, &adata
)) {
3313 case NS_CACHE_SUCCESS
:
3315 case NS_CACHE_NOTFOUND
:
3316 (void) snprintf(errstr
, sizeof (errstr
),
3317 gettext("Door call to "
3318 "ldap_cachemgr failed - error: %d."),
3319 space
->s_d
.ldap_ret
.ldap_errno
);
3320 MKERROR(LOG_WARNING
, *error
, NS_CONFIG_CACHEMGR
,
3321 strdup(errstr
), NULL
);
3323 return (NS_LDAP_OP_FAILED
);
3326 return (NS_LDAP_OP_FAILED
);
3329 retCode
= NS_LDAP_SUCCESS
;
3331 /* copy info from door call to buffer here */
3332 cfghdr
= &sptr
->ldap_ret
.ldap_u
.config_str
;
3333 *buflen
= offsetof(ldap_config_out_t
, config_str
) +
3334 cfghdr
->data_size
+ 1;
3335 *buffer
= calloc(*buflen
, sizeof (char));
3336 if (*buffer
== NULL
) {
3337 retCode
= NS_LDAP_MEMORY
;
3339 (void) memcpy(*buffer
, cfghdr
, *buflen
- 1);
3341 if (sptr
!= &space
->s_d
) {
3342 (void) munmap((char *)sptr
, ndata
);
3350 __door_getldapconfig(char **buffer
, int *buflen
, ns_ldap_error_t
**error
)
3352 return (__door_getconf(buffer
, buflen
, error
, GETLDAPCONFIGV1
));
3356 * SetDoorInfoToUnixCred parses ldapcachemgr configuration information
3357 * for Admin credentials.
3360 SetDoorInfoToUnixCred(char *buffer
, ns_ldap_error_t
**errorp
,
3364 char errstr
[MAXERROR
];
3365 char *name
, *value
, valbuf
[BUFSIZE
];
3366 char *bufptr
= buffer
;
3369 ParamIndexType index
= 0;
3370 ldap_config_out_t
*cfghdr
;
3372 if (errorp
== NULL
|| cred
== NULL
|| *cred
== NULL
)
3373 return (NS_LDAP_INVALID_PARAM
);
3378 cfghdr
= (ldap_config_out_t
*)bufptr
;
3379 bufptr
= (char *)cfghdr
->config_str
;
3381 strptr
= (char *)strtok_r(bufptr
, DOORLINESEP
, &rest
);
3385 (void) strlcpy(valbuf
, strptr
, sizeof (valbuf
));
3386 __s_api_split_key_value(valbuf
, &name
, &value
);
3387 if (__ns_ldap_getParamType(name
, &index
) != 0) {
3388 (void) snprintf(errstr
, MAXERROR
,
3389 gettext("SetDoorInfoToUnixCred: "
3390 "Unknown keyword encountered '%s'."), name
);
3391 MKERROR(LOG_ERR
, *errorp
, NS_CONFIG_SYNTAX
,
3392 strdup(errstr
), NULL
);
3393 return (NS_LDAP_CONFIG
);
3396 case NS_LDAP_ADMIN_BINDDN_P
:
3397 ptr
->userID
= (char *)strdup(value
);
3399 case NS_LDAP_ADMIN_BINDPASSWD_P
:
3400 ptr
->passwd
= (char *)strdup(value
);
3403 (void) snprintf(errstr
, MAXERROR
,
3404 gettext("SetDoorInfoToUnixCred: "
3405 "Unknown index encountered '%d'."), index
);
3406 MKERROR(LOG_ERR
, *errorp
, NS_CONFIG_SYNTAX
,
3407 strdup(errstr
), NULL
);
3408 return (NS_LDAP_CONFIG
);
3410 strptr
= (char *)strtok_r(NULL
, DOORLINESEP
, &rest
);
3413 return (NS_LDAP_SUCCESS
);
3417 * SetDoorInfo parses ldapcachemgr configuration information
3418 * and verifies that the profile is version 1 or version 2 based.
3419 * version 2 profiles must have a version number as the first profile
3420 * attribute in the configuration.
3422 static ns_config_t
*
3423 SetDoorInfo(char *buffer
, ns_ldap_error_t
**errorp
)
3426 char errstr
[MAXERROR
], errbuf
[MAXERROR
];
3427 char *name
, *value
, valbuf
[BUFSIZE
];
3430 char *bufptr
= buffer
;
3435 ldap_config_out_t
*cfghdr
;
3441 ptr
= __s_api_create_config();
3446 /* get config cookie from the header */
3447 cfghdr
= (ldap_config_out_t
*)bufptr
;
3448 ptr
->config_cookie
= cfghdr
->cookie
;
3449 bufptr
= (char *)cfghdr
->config_str
;
3451 strptr
= (char *)strtok_r(bufptr
, DOORLINESEP
, &rest
);
3455 (void) strlcpy(valbuf
, strptr
, sizeof (valbuf
));
3456 __s_api_split_key_value(valbuf
, &name
, &value
);
3457 /* Use get_versiontype and check for V1 vs V2 prototypes */
3458 if (__s_api_get_versiontype(ptr
, name
, &i
) < 0) {
3459 (void) snprintf(errstr
, sizeof (errstr
),
3461 gettext("Illegal profile entry "
3462 "line in configuration."),
3465 /* Write verify routines and get rid of verify_value here */
3466 } else if (verify_value(ptr
, name
,
3467 value
, errbuf
) != NS_SUCCESS
) {
3468 (void) snprintf(errstr
, sizeof (errstr
),
3469 gettext("%s\n"), errbuf
);
3471 } else if (!first
&& i
== NS_LDAP_FILE_VERSION_P
) {
3472 (void) snprintf(errstr
, sizeof (errstr
),
3473 gettext("Illegal NS_LDAP_FILE_VERSION "
3474 "line in configuration.\n"));
3478 MKERROR(LOG_ERR
, *errorp
, NS_CONFIG_SYNTAX
,
3479 strdup(errstr
), NULL
);
3481 ret
= set_default_value(ptr
, name
, value
, errorp
);
3483 if (errfnd
|| ret
!= NS_SUCCESS
) {
3484 __s_api_destroy_config(ptr
);
3489 strptr
= (char *)strtok_r(NULL
, DOORLINESEP
, &rest
);
3492 if (__s_api_crosscheck(ptr
, errstr
, B_TRUE
) != NS_SUCCESS
) {
3493 __s_api_destroy_config(ptr
);
3494 MKERROR(LOG_WARNING
, *errorp
, NS_CONFIG_SYNTAX
, strdup(errstr
),
3502 static ns_config_t
*
3503 LoadCacheConfiguration(ns_config_t
*oldcfg
, ns_ldap_error_t
**error
)
3505 char *buffer
= NULL
;
3509 ldap_config_out_t
*cfghdr
;
3510 ldap_get_chg_cookie_t old_cookie
;
3511 ldap_get_chg_cookie_t new_cookie
;
3514 ret
= __door_getldapconfig(&buffer
, &buflen
, error
);
3516 if (ret
!= NS_LDAP_SUCCESS
) {
3517 if (*error
!= NULL
&& (*error
)->message
!= NULL
)
3518 syslog(LOG_WARNING
, "libsldap: %s", (*error
)->message
);
3522 /* No need to reload configuration if config cookie is the same */
3523 cfghdr
= (ldap_config_out_t
*)buffer
;
3524 new_cookie
= cfghdr
->cookie
;
3526 old_cookie
= oldcfg
->config_cookie
;
3528 if (oldcfg
!= NULL
&& old_cookie
.mgr_pid
== new_cookie
.mgr_pid
&&
3529 old_cookie
.seq_num
== new_cookie
.seq_num
) {
3534 /* now convert from door format */
3535 cfg
= SetDoorInfo(buffer
, error
);
3538 if (cfg
== NULL
&& *error
!= NULL
&& (*error
)->message
!= NULL
)
3539 syslog(LOG_WARNING
, "libsldap: %s", (*error
)->message
);
3544 * converts the time string into seconds. The time string can be specified
3545 * using one of the following time units:
3551 * NOTE: you can only specify one the above. No combination of the above
3552 * units is allowed. If no unit specified, it will default to "seconds".
3568 case 'w': /* weeks */
3571 case 'd': /* days */
3574 case 'h': /* hours */
3577 case 'm': /* minutes */
3580 case 's': /* seconds */
3583 /* the default case is set to "second" */
3591 if ((0 == tot
) && (EINVAL
== errno
))
3593 if (((LONG_MAX
== tot
) || (LONG_MIN
== tot
)) && (EINVAL
== errno
))
3603 __s_api_AuthEnumtoStruct(const EnumAuthType_t i
)
3607 ap
= (ns_auth_t
*)calloc(1, sizeof (ns_auth_t
));
3611 case NS_LDAP_EA_NONE
:
3613 case NS_LDAP_EA_SIMPLE
:
3614 ap
->type
= NS_LDAP_AUTH_SIMPLE
;
3616 case NS_LDAP_EA_SASL_CRAM_MD5
:
3617 ap
->type
= NS_LDAP_AUTH_SASL
;
3618 ap
->saslmech
= NS_LDAP_SASL_CRAM_MD5
;
3620 case NS_LDAP_EA_SASL_DIGEST_MD5
:
3621 ap
->type
= NS_LDAP_AUTH_SASL
;
3622 ap
->saslmech
= NS_LDAP_SASL_DIGEST_MD5
;
3624 case NS_LDAP_EA_SASL_DIGEST_MD5_INT
:
3625 ap
->type
= NS_LDAP_AUTH_SASL
;
3626 ap
->saslmech
= NS_LDAP_SASL_DIGEST_MD5
;
3627 ap
->saslopt
= NS_LDAP_SASLOPT_INT
;
3629 case NS_LDAP_EA_SASL_DIGEST_MD5_CONF
:
3630 ap
->type
= NS_LDAP_AUTH_SASL
;
3631 ap
->saslmech
= NS_LDAP_SASL_DIGEST_MD5
;
3632 ap
->saslopt
= NS_LDAP_SASLOPT_PRIV
;
3634 case NS_LDAP_EA_SASL_EXTERNAL
:
3635 ap
->type
= NS_LDAP_AUTH_SASL
;
3636 ap
->saslmech
= NS_LDAP_SASL_EXTERNAL
;
3638 case NS_LDAP_EA_SASL_GSSAPI
:
3639 ap
->type
= NS_LDAP_AUTH_SASL
;
3640 ap
->saslmech
= NS_LDAP_SASL_GSSAPI
;
3641 ap
->saslopt
= NS_LDAP_SASLOPT_INT
|
3642 NS_LDAP_SASLOPT_PRIV
;
3644 case NS_LDAP_EA_TLS_NONE
:
3645 ap
->type
= NS_LDAP_AUTH_TLS
;
3646 ap
->tlstype
= NS_LDAP_TLS_NONE
;
3648 case NS_LDAP_EA_TLS_SIMPLE
:
3649 ap
->type
= NS_LDAP_AUTH_TLS
;
3650 ap
->tlstype
= NS_LDAP_TLS_SIMPLE
;
3652 case NS_LDAP_EA_TLS_SASL_CRAM_MD5
:
3653 ap
->type
= NS_LDAP_AUTH_TLS
;
3654 ap
->tlstype
= NS_LDAP_TLS_SASL
;
3655 ap
->saslmech
= NS_LDAP_SASL_CRAM_MD5
;
3657 case NS_LDAP_EA_TLS_SASL_DIGEST_MD5
:
3658 ap
->type
= NS_LDAP_AUTH_TLS
;
3659 ap
->tlstype
= NS_LDAP_TLS_SASL
;
3660 ap
->saslmech
= NS_LDAP_SASL_DIGEST_MD5
;
3662 case NS_LDAP_EA_TLS_SASL_DIGEST_MD5_INT
:
3663 ap
->type
= NS_LDAP_AUTH_TLS
;
3664 ap
->tlstype
= NS_LDAP_TLS_SASL
;
3665 ap
->saslmech
= NS_LDAP_SASL_DIGEST_MD5
;
3666 ap
->saslopt
= NS_LDAP_SASLOPT_INT
;
3668 case NS_LDAP_EA_TLS_SASL_DIGEST_MD5_CONF
:
3669 ap
->type
= NS_LDAP_AUTH_TLS
;
3670 ap
->tlstype
= NS_LDAP_TLS_SASL
;
3671 ap
->saslmech
= NS_LDAP_SASL_DIGEST_MD5
;
3672 ap
->saslopt
= NS_LDAP_SASLOPT_PRIV
;
3674 case NS_LDAP_EA_TLS_SASL_EXTERNAL
:
3675 ap
->type
= NS_LDAP_AUTH_TLS
;
3676 ap
->tlstype
= NS_LDAP_TLS_SASL
;
3677 ap
->saslmech
= NS_LDAP_SASL_EXTERNAL
;
3680 /* should never get here */
3689 * Parameter Index Type validation routines
3692 /* Validate a positive integer */
3693 /* Size of errbuf needs to be MAXERROR */
3696 __s_val_postime(ParamIndexType i
, ns_default_config
*def
,
3697 ns_param_t
*param
, char *errbuf
)
3702 if (param
&& param
->ns_ptype
== CHARPTR
&& param
->ns_pc
) {
3703 for (cp
= param
->ns_pc
; cp
&& *cp
; cp
++) {
3704 if (*cp
>= '0' && *cp
<= '9')
3707 case 'w': /* weeks */
3708 case 'd': /* days */
3709 case 'h': /* hours */
3710 case 'm': /* minutes */
3711 case 's': /* seconds */
3712 if (*(cp
+1) == '\0') {
3716 (void) strcpy(errbuf
, "Illegal time value");
3717 return (NS_PARSE_ERR
);
3720 /* Valid form: [0-9][0-9]*[wdhms]* */
3721 tot
= atol(param
->ns_pc
); /* check overflow */
3723 return (NS_SUCCESS
);
3725 (void) snprintf(errbuf
, MAXERROR
,
3726 gettext("Illegal time value in %s"), def
->name
);
3727 return (NS_PARSE_ERR
);
3731 /* Validate the Base DN */
3732 /* It can be empty (RootDSE request) or needs to have an '=' */
3733 /* Size of errbuf needs to be MAXERROR */
3736 __s_val_basedn(ParamIndexType i
, ns_default_config
*def
,
3737 ns_param_t
*param
, char *errbuf
)
3739 if (param
&& param
->ns_ptype
== CHARPTR
&&
3740 i
== NS_LDAP_SEARCH_BASEDN_P
&&
3741 ((param
->ns_pc
== NULL
) || /* empty */
3742 (*(param
->ns_pc
) == '\0') || /* empty */
3743 (strchr(param
->ns_pc
, '=') != NULL
))) /* '=' */
3745 return (NS_SUCCESS
);
3747 (void) snprintf(errbuf
, MAXERROR
,
3748 gettext("Non-existent or invalid DN in %s"),
3750 return (NS_PARSE_ERR
);
3754 /* Validate the serverList */
3755 /* For each server in list, check if valid IP or hostname */
3756 /* Size of errbuf needs to be MAXERROR */
3759 __s_val_serverList(ParamIndexType i
, ns_default_config
*def
,
3760 ns_param_t
*param
, char *errbuf
)
3762 for (i
= 0; i
< param
->ns_acnt
; i
++) {
3763 if ((__s_api_isipv4(param
->ns_ppc
[i
])) ||
3764 (__s_api_isipv6(param
->ns_ppc
[i
])) ||
3765 (__s_api_ishost(param
->ns_ppc
[i
]))) {
3769 (void) snprintf(errbuf
, MAXERROR
,
3770 gettext("Invalid server (%s) in %s"),
3771 param
->ns_ppc
[i
], def
->name
);
3772 return (NS_PARSE_ERR
);
3775 return (NS_SUCCESS
);
3779 /* Check for a BINDDN */
3780 /* It can not be empty and needs to have an '=' */
3781 /* Size of errbuf needs to be MAXERROR */
3784 __s_val_binddn(ParamIndexType i
, ns_default_config
*def
,
3785 ns_param_t
*param
, char *errbuf
)
3789 if (param
&& param
->ns_ptype
== CHARPTR
&&
3790 (i
== NS_LDAP_BINDDN_P
|| i
== NS_LDAP_ADMIN_BINDDN_P
) &&
3791 ((param
->ns_pc
== NULL
) ||
3792 ((*(param
->ns_pc
) != '\0') &&
3793 (strchr(param
->ns_pc
, '=') != NULL
)))) {
3794 return (NS_SUCCESS
);
3796 if (i
== NS_LDAP_BINDDN_P
)
3800 (void) snprintf(errbuf
, MAXERROR
,
3801 gettext("NULL or invalid %s bind DN"), dntype
);
3802 return (NS_PARSE_ERR
);
3806 /* Check for a BINDPASSWD */
3807 /* The string can not be NULL or empty */
3808 /* Size of errbuf needs to be MAXERROR */
3811 __s_val_bindpw(ParamIndexType i
, ns_default_config
*def
,
3812 ns_param_t
*param
, char *errbuf
)
3816 if (param
&& param
->ns_ptype
== CHARPTR
&&
3817 (i
== NS_LDAP_BINDPASSWD_P
|| i
== NS_LDAP_ADMIN_BINDPASSWD_P
) &&
3818 ((param
->ns_pc
== NULL
) ||
3819 (*(param
->ns_pc
) != '\0'))) {
3820 return (NS_SUCCESS
);
3822 if (i
== NS_LDAP_BINDPASSWD_P
)
3826 (void) snprintf(errbuf
, MAXERROR
,
3827 gettext("NULL %s bind password"), pwtype
);
3828 return (NS_PARSE_ERR
);
3832 * __s_get_hostcertpath returns either the configured host certificate path
3833 * or, if none, the default host certificate path (/var/ldap). Note that this
3834 * does not use __ns_ldap_getParam because it may be called during connection
3835 * setup. This can fail due to insufficient memory.
3839 __s_get_hostcertpath(void)
3845 cfg
= __s_api_get_default_config();
3847 param
= &cfg
->paramList
[NS_LDAP_HOST_CERTPATH_P
];
3848 if (param
->ns_ptype
== CHARPTR
)
3849 ret
= strdup(param
->ns_pc
);
3850 __s_api_release_config(cfg
);
3853 ret
= strdup(NSLDAPDIRECTORY
);
3860 if (current_config
!= NULL
)
3861 destroy_config(current_config
);
3863 current_config
= NULL
;