xref: /titanic_41/usr/src/lib/libsldap/common/ns_internal.h (revision 18c2aff776a775d34a4c9893a4c72e0434d68e36)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 
27 #ifndef	_NS_INTERNAL_H
28 #define	_NS_INTERNAL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdio.h>
37 #include <sys/types.h>
38 #include <sys/time.h>
39 #include <thread.h>
40 #include <lber.h>
41 #include <ldap.h>
42 #include "ns_sldap.h"
43 
44 /*
45  * INTERNALLY USED CONSTANTS
46  */
47 
48 #define	MAXERROR		2000
49 #define	TRUE			1
50 #define	FALSE			0
51 #define	NSLDAPDIRECTORY		"/var/ldap"
52 #define	NSCONFIGFILE		"/var/ldap/ldap_client_file"
53 #define	NSCONFIGREFRESH		"/var/ldap/ldap_client_file.refresh"
54 #define	NSCREDFILE		"/var/ldap/ldap_client_cred"
55 #define	NSCREDREFRESH		"/var/ldap/ldap_client_cred.refresh"
56 #define	ROTORSIZE		256
57 #define	MASK			0377
58 #define	LDAPMAXHARDLOOKUPTIME	256
59 #define	DONOTEDIT		\
60 	"Do not edit this file manually; your changes will be lost." \
61 	"Please use ldapclient (1M) instead."
62 #define	MAXPORTNUMBER		65535
63 #define	MAXPORTNUMBER_STR	"65535"
64 #define	CREDFILE		0
65 #define	CONFIGFILE		1
66 #define	UIDNUMFILTER		"(&(objectclass=posixAccount)(uidnumber=%s))"
67 #define	UIDNUMFILTER_SSD 	"(&(%%s)(uidnumber=%s))"
68 #define	UIDFILTER		"(&(objectclass=posixAccount)(uid=%s))"
69 #define	UIDFILTER_SSD		"(&(%%s)(uid=%s))"
70 #define	HOSTFILTER		"(&(objectclass=ipHost)(cn=%s))"
71 #define	HOSTFILTER_SSD		"(&(%%s)(cn=%s))"
72 
73 #define	SIMPLEPAGECTRLFLAG	1
74 #define	VLVCTRLFLAG		2
75 
76 #define	LISTPAGESIZE		1000
77 #define	ENUMPAGESIZE		100
78 #define	SORTKEYLIST		"cn uid"
79 
80 #define	DEFMAX			8
81 #define	TOKENSEPARATOR		'='
82 #define	QUOTETOK		'"'
83 #define	SPACETOK		' '
84 #define	COMMATOK		','
85 #define	COLONTOK		':'
86 #define	QUESTTOK		'?'
87 #define	SEMITOK			';'
88 #define	TABTOK			'\t'
89 #define	OPARATOK		'('
90 #define	CPARATOK		')'
91 #define	BSLTOK			'\\'
92 #define	DOORLINESEP		"\07"
93 #define	COMMASEP		", "
94 #define	SPACESEP		" "
95 #define	SEMISEP			";"
96 #define	COLONSEP		":"
97 #define	COLSPSEP		": "
98 #define	EQUALSEP		"="
99 #define	EQUSPSEP		"= "
100 #define	LAST_VALUE		(int)NS_LDAP_HOST_CERTPATH_P
101 #define	BUFSIZE			1024
102 #define	DEFAULTCONFIGNAME	"__default_config"
103 #define	EXP_DEFAULT_TTL		"43200"	/* 12 hours TTL */
104 #define	CRYPTMARK		"{NS1}"
105 #define	DOORBUFFERSIZE		8192
106 
107 #define	LDIF_FMT_STR		"%s: %s"
108 #define	FILE_FMT_STR		"%s= %s"
109 #define	DOOR_FMT_STR		"%s=%s"
110 
111 #define	SESSION_CACHE_INC	8
112 #define	CONID_OFFSET		1024
113 #define	NS_DEFAULT_BIND_TIMEOUT		30 /* timeout value in seconds */
114 #define	NS_DEFAULT_SEARCH_TIMEOUT	30 /* timeout value in seconds */
115 
116 /* max rdn length in conversion routines used by __ns_ldap_addTypedEntry() */
117 #define	RDNSIZE			256
118 
119 
120 /* Phase 1 profile information */
121 #define	_PROFILE1_OBJECTCLASS	"SolarisNamingProfile"
122 #define	_PROFILE_CONTAINER	"profile"
123 #define	_PROFILE_FILTER		"(&(|(objectclass=%s)(objectclass=%s))(cn=%s))"
124 
125 /* Phase 2 profile information */
126 #define	_PROFILE2_OBJECTCLASS		"DUAConfigProfile"
127 
128 /* Common to all profiles */
129 #define	_P_CN			"cn"
130 
131 /* Native LDAP Phase 1 Specific Profile Attributes */
132 #define	_P1_SERVERS			"SolarisLDAPServers"
133 #define	_P1_SEARCHBASEDN		"SolarisSearchBaseDN"
134 #define	_P1_CACHETTL			"SolarisCacheTTL"
135 #define	_P1_BINDDN			"SolarisBindDN"
136 #define	_P1_BINDPASSWORD		"SolarisBindPassword"
137 #define	_P1_AUTHMETHOD			"SolarisAuthMethod"
138 #define	_P1_TRANSPORTSECURITY		"SolarisTransportSecurity"
139 #define	_P1_CERTIFICATEPATH		"SolarisCertificatePath"
140 #define	_P1_CERTIFICATEPASSWORD		"SolarisCertificatePassword"
141 #define	_P1_DATASEARCHDN		"SolarisDataSearchDN"
142 #define	_P1_SEARCHSCOPE			"SolarisSearchScope"
143 #define	_P1_SEARCHTIMELIMIT		"SolarisSearchTimeLimit"
144 #define	_P1_PREFERREDSERVER		"SolarisPreferredServer"
145 #define	_P1_PREFERREDSERVERONLY		"SolarisPreferredServerOnly"
146 #define	_P1_SEARCHREFERRAL		"SolarisSearchReferral"
147 #define	_P1_BINDTIMELIMIT		"SolarisBindTimeLimit"
148 
149 /* Native LDAP Phase 2 Specific Profile Attributes */
150 #define	_P2_PREFERREDSERVER		"preferredServerList"
151 #define	_P2_DEFAULTSERVER		"defaultServerList"
152 #define	_P2_SEARCHBASEDN		"defaultSearchBase"
153 #define	_P2_SEARCHSCOPE			"defaultSearchScope"
154 #define	_P2_AUTHMETHOD			"authenticationMethod"
155 #define	_P2_CREDENTIALLEVEL		"credentialLevel"
156 #define	_P2_SERVICESEARCHDESC		"serviceSearchDescriptor"
157 #define	_P2_SEARCHTIMELIMIT		"searchTimeLimit"
158 #define	_P2_BINDTIMELIMIT		"bindTimeLimit"
159 #define	_P2_FOLLOWREFERRALS		"followReferrals"
160 #define	_P2_PROFILETTL			"profileTTL"
161 #define	_P2_ATTRIBUTEMAP		"attributeMap"
162 #define	_P2_OBJECTCLASSMAP		"objectClassMap"
163 #define	_P2_SERVICECREDLEVEL		"serviceCredentialLevel"
164 #define	_P2_SERVICEAUTHMETHOD		"serviceAuthenticationMethod"
165 
166 /* Control & SASL information from RootDSE door call */
167 #define	_SASLMECHANISM			"supportedSASLmechanisms"
168 #define	_SASLMECHANISM_LEN		23
169 #define	_SUPPORTEDCONTROL		"supportedControl"
170 #define	_SUPPORTEDCONTROL_LEN		16
171 
172 #define	NS_HASH_MAX	257
173 #define	NS_HASH_SCHEMA_MAPPING_EXISTED	"=MAPPING EXISTED="
174 #define	NS_HASH_RC_SUCCESS		1
175 #define	NS_HASH_RC_NO_MEMORY		-1
176 #define	NS_HASH_RC_CONFIG_ERROR		-2
177 #define	NS_HASH_RC_EXISTED		-3
178 #define	NS_HASH_RC_SYNTAX_ERROR		-4
179 
180 /* Password management related error message from iDS ldap server */
181 #define	NS_PWDERR_MAXTRIES		\
182 	"Exceed password retry limit."
183 #define	NS_PWDERR_EXPIRED		\
184 	"password expired!"
185 #define	NS_PWDERR_ACCT_INACTIVATED	\
186 	"Account inactivated. Contact system administrator."
187 #define	NS_PWDERR_CHANGE_NOT_ALLOW	\
188 	"user is not allowed to change password"
189 #define	NS_PWDERR_INVALID_SYNTAX	\
190 	"invalid password syntax"
191 #define	NS_PWDERR_TRIVIAL_PASSWD	\
192 	"Password failed triviality check"
193 #define	NS_PWDERR_IN_HISTORY	\
194 	"password in history"
195 #define	NS_PWDERR_WITHIN_MIN_AGE	\
196 	"within password minimum age"
197 
198 /*
199  * INTERNALLY USED MACROS
200  */
201 
202 void	__s_api_debug_pause(int priority, int st, const char *mesg);
203 
204 #define	NULL_OR_STR(str)	(!(str) || *(str) == '\0' ? "<NULL>" : (str))
205 
206 /*
207  * MKERROR: builds the error structure and fills in the status and
208  * the message.  The message must be a freeable (non-static) string.
209  * If it fails to allocate memory for the error structure,
210  * it will return the retErr.
211  */
212 #define	MKERROR(priority, err, st, mesg, retErr) \
213 	if (((err) = calloc(1, sizeof (struct ns_ldap_error))) == NULL) \
214 		return (retErr); \
215 	(err)->message = mesg; \
216 	(err)->status = (st); \
217 	__s_api_debug_pause(priority, st, (err)->message);
218 
219 /*
220  * MKERROR_PWD_MGMT is almost the same as MKERROR
221  * except that it takes two more inputs to fill in the
222  * password management information part of the
223  * ns_ldap_error structure pointed to by err,
224  * and it does not log a syslog message.
225  */
226 #define	MKERROR_PWD_MGMT(err, st, mesg, pwd_status, sec_until_exp, retErr) \
227 	if (((err) = calloc(1, sizeof (struct ns_ldap_error))) == NULL) \
228 		return (retErr); \
229 	(err)->message = mesg; \
230 	(err)->status = (st); \
231 	(err)->pwd_mgmt.status = (pwd_status); \
232 	(err)->pwd_mgmt.sec_until_expired = (sec_until_exp);
233 
234 #ifdef DEBUG
235 #define	NSLDAPTRACE(variable, setequal, message) \
236 	if (variable > 0 || ((setequal != 0) && (variable == setequal))) { \
237 		char buf[BUFSIZ]; \
238 		(void) snprintf(buf, BUFSIZ, message); \
239 		(void) write(__ldap_debug_file, buf); \
240 	}
241 #endif
242 
243 /*
244  * INTERNAL DATA STRUCTURES
245  */
246 
247 /*
248  * configuration entry type
249  */
250 
251 typedef enum {
252 	SERVERCONFIG	= 1,
253 	CLIENTCONFIG	= 2,
254 	CREDCONFIG	= 3
255 } ns_conftype_t;
256 
257 /*
258  * datatype of a config entry
259  */
260 
261 typedef enum {
262 	NS_UNKNOWN	= 0,
263 	CHARPTR		= 1,		/* Single character pointer */
264 	ARRAYCP		= 2,		/* comma sep array of char pointers */
265 	ARRAYAUTH	= 3,		/* Array of auths */
266 	TIMET		= 4,		/* time relative value (TTL) */
267 	INT		= 5,		/* single integer */
268 	SSDLIST		= 6,		/* service search descriptor */
269 	ATTRMAP		= 7,		/* attribute mapping */
270 	OBJMAP		= 8,		/* objectclass mapping */
271 	SERVLIST	= 9,		/* serverlist (SP sep array) */
272 	ARRAYCRED	= 10,		/* Array of credentialLevels */
273 	SAMLIST		= 11,		/* serviceAuthenticationMethod */
274 	SCLLIST		= 12		/* serviceCredentialLevel */
275 } ns_datatype_t;
276 
277 typedef enum {
278 	NS_SUCCESS,
279 	NS_NOTFOUND,
280 	NS_PARSE_ERR
281 } ns_parse_status;
282 
283 typedef enum {
284 	NS_DOOR_FMT	= 1,
285 	NS_LDIF_FMT	= 2,
286 	NS_FILE_FMT	= 3
287 } ns_strfmt_t;
288 
289 /*
290  * This enum reduces the number of version string compares
291  * against NS_LDAP_VERSION_1 and NS_LDAP_VERSION_2
292  */
293 
294 typedef enum {
295 	NS_LDAP_V1	= 1000,
296 	NS_LDAP_V2	= 2000
297 } ns_version_t;
298 
299 /*
300  * enum<->string mapping construct
301  */
302 
303 typedef struct ns_enum_map {
304 	int	value;
305 	char	*name;
306 } ns_enum_map;
307 
308 #define	ENUM2INT(x)		((int)(x))
309 
310 #define	INT2PARAMINDEXENUM(x)	((ParamIndexType)(x))
311 #define	INT2SEARCHREFENUM(x)	((SearchRef_t)(x))
312 #define	INT2SCOPEENUM(x)	((ScopeType_t)(x))
313 #define	INT2AUTHENUM(x)		((AuthType_t)(x))
314 #define	INT2SECENUM(x)		((TlsType_t)(x))
315 #define	INT2PREFONLYENUM(x)	((PrefOnly_t)(x))
316 #define	INT2CREDLEVELENUM(x)	((CredLevel_t)(x))
317 
318 #define	INT2LDAPRETURN(x)	((ns_ldap_return_code)(x))
319 #define	INT2CONFIGRETURN(x)	((ns_ldap_config_return_code)(x))
320 #define	INT2PARTIALRETURN(x)	((ns_ldap_partial_return_code)(x))
321 
322 /*
323  * This structure maps service name to rdn components
324  * for use in __ns_getDNs. It also defines the SSD-to-use
325  * service for use in __s_api_get_SSDtoUse_service.
326  * The idea of an SSD-to-use service is to reduce the configuration
327  * complexity. For a service, which does not have its own entries in
328  * the LDAP directory, SSD for it is useless, and should not be set.
329  * But since this service must share the container with at least
330  * one other service which does have it own entries, the SSD for
331  * this other service will be shared by this service.
332  * This other service is called the SSD-to-use service.
333  *
334  */
335 
336 typedef struct ns_service_map {
337 	char	*service;
338 	char	*rdn;
339 	char	*SSDtoUse_service;
340 } ns_service_map;
341 
342 /*
343  * This structure contains a single mapping from:
344  * service:orig -> list of mapped
345  */
346 
347 typedef enum {
348 	NS_ATTR_MAP,
349 	NS_OBJ_MAP
350 } ns_maptype_t;
351 
352 typedef struct ns_mapping {
353 	ns_maptype_t	type;
354 	char		*service;
355 	char		*orig;
356 	char		**map;
357 } ns_mapping_t;
358 
359 /*
360  * The following is the list of internal libsldap configuration data
361  * structures.  The configuration is populated normally once per
362  * application.  The assumption is that in applications can be
363  * relatively short lived (IE ls via nsswitch) so it is important to
364  * keep configuration to a minimum, but keep lookups fast.
365  *
366  * Assumptions:
367  * 1 configuration entry per domain, and almost always 1 domain
368  * per app.  Hooks exist for multiple domains per app.
369  *
370  * Configurations are read in from client file cache or from LDAP.
371  * Attribute/objectclass mappings are hashed to improve lookup
372  * speed.
373  */
374 
375 /*
376  * Hash entry types
377  */
378 typedef enum	_ns_hashtype_t {
379 	NS_HASH_AMAP	= 1,		/* attr map */
380 	NS_HASH_RAMAP	= 2,		/* reverse attr map */
381 	NS_HASH_OMAP	= 3,		/* oc map */
382 	NS_HASH_ROMAP	= 4,		/* reverse oc map */
383 	NS_HASH_VOID	= 5
384 } ns_hashtype_t;
385 
386 typedef struct ns_hash {
387 	ns_hashtype_t	h_type;
388 	ns_mapping_t	*h_map;
389 	struct ns_hash	*h_next;
390 	struct ns_hash	*h_llnext;
391 } ns_hash_t;
392 
393 /*
394  * This structure defines the format of an internal configuration
395  * parameter for ns_ldap client.
396  */
397 
398 typedef struct ns_param {
399 	ns_datatype_t	ns_ptype;
400 	int		ns_acnt;
401 	union {
402 		char	**ppc;
403 		int	*pi;
404 		char	*pc;
405 		int	i;
406 		time_t	tm;
407 	} ns_pu;
408 } ns_param_t;
409 
410 #define	ns_ppc	ns_pu.ppc
411 #define	ns_pi	ns_pu.pi
412 #define	ns_pc	ns_pu.pc
413 #define	ns_i	ns_pu.i
414 #define	ns_tm	ns_pu.tm
415 
416 /*
417  * This structure defines an instance of a configuration structure.
418  * paramList contains the current ns_ldap parameter configuration
419  * and hashTbl contain the current attribute/objectclass mappings.
420  * Parameters are indexed by using the value assigned to the parameter
421  * in ParamIndexType.
422  */
423 
424 typedef struct ns_config {
425 	char			*domainName;
426 	ns_version_t		version;
427 	ns_param_t		paramList[NS_LDAP_MAX_PIT_P];
428 	ns_hash_t		*hashTbl[NS_HASH_MAX];
429 	ns_hash_t		*llHead;
430 	ns_ldap_entry_t		*RootDSE;
431 	boolean_t		delete;
432 	mutex_t			config_mutex;
433 	int			nUse;
434 } ns_config_t;
435 
436 /*
437  * This structure defines the mapping of the NSCONFIGFILE file
438  * statements into their corresponding SolarisNamingProfile,
439  * Posix Mapping LDAP attributes, and to their corresponding
440  * ParamIndexType enum mapping.  THe ParamIndexType enum
441  * definitions can be found in ns_ldap.h.  This structure also
442  * defines the default values that are used when a value either
443  * does not exist or is undefined.
444  */
445 
446 typedef struct ns_default_config {
447 	const char	*name;		/* config file parameter name */
448 	ParamIndexType	index;		/* config file enum index */
449 	ns_conftype_t	config_type;	/* CLIENT/SERVER/CREDCONFIG */
450 	ns_datatype_t	data_type;	/* ppc,pi,pc,int etc... */
451 	int		single_valued;	/* TRUE OR FALSE */
452 	ns_version_t 	version;	/* Version # for attribute */
453 	const char	*profile_name;	/* profile schema attribute name */
454 	ns_param_t	defval;		/* config file parameter default */
455 	int		(*ns_verify)(ParamIndexType i,
456 				struct ns_default_config *def,
457 				ns_param_t *param,
458 				char *errbuf);
459 	ns_enum_map	*allowed;	/* allowed values */
460 } ns_default_config;
461 
462 
463 /*
464  * This typedef enumerates all the supported authentication
465  * mechanisms currently supported in this library
466  */
467 
468 typedef enum EnumAuthType {
469 	NS_LDAP_EA_NONE				= 0,
470 	NS_LDAP_EA_SIMPLE			= 1,
471 	NS_LDAP_EA_SASL_NONE			= 2,
472 	NS_LDAP_EA_SASL_CRAM_MD5		= 3,
473 	NS_LDAP_EA_SASL_DIGEST_MD5		= 4,
474 	NS_LDAP_EA_SASL_DIGEST_MD5_INT		= 5,
475 	NS_LDAP_EA_SASL_DIGEST_MD5_CONF		= 6,
476 	NS_LDAP_EA_SASL_EXTERNAL		= 7,
477 	NS_LDAP_EA_SASL_GSSAPI			= 8,
478 	NS_LDAP_EA_SASL_SPNEGO			= 9,	/* unsupported */
479 	NS_LDAP_EA_TLS_NONE			= 10,
480 	NS_LDAP_EA_TLS_SIMPLE			= 11,
481 	NS_LDAP_EA_TLS_SASL_NONE		= 12,
482 	NS_LDAP_EA_TLS_SASL_CRAM_MD5		= 13,
483 	NS_LDAP_EA_TLS_SASL_DIGEST_MD5		= 14,
484 	NS_LDAP_EA_TLS_SASL_DIGEST_MD5_INT	= 15,
485 	NS_LDAP_EA_TLS_SASL_DIGEST_MD5_CONF	= 16,
486 	NS_LDAP_EA_TLS_SASL_EXTERNAL		= 17,
487 	NS_LDAP_EA_TLS_SASL_GSSAPI		= 18,	/* unsupported */
488 	NS_LDAP_EA_TLS_SASL_SPNEGO		= 19	/* unsupported */
489 } EnumAuthType_t;
490 
491 
492 /*
493  * this enum lists the various states of the search state machine
494  */
495 
496 typedef enum {
497 	INIT			= 1,
498 	EXIT			= 2,
499 	NEXT_SEARCH_DESCRIPTOR	= 3,
500 	GET_SESSION		= 4,
501 	NEXT_SESSION		= 5,
502 	RESTART_SESSION		= 6,
503 	NEXT_SEARCH		= 7,
504 	NEXT_VLV		= 8,
505 	NEXT_PAGE		= 9,
506 	ONE_SEARCH		= 10,
507 	DO_SEARCH		= 11,
508 	NEXT_RESULT		= 12,
509 	MULTI_RESULT		= 13,
510 	PROCESS_RESULT		= 14,
511 	END_PROCESS_RESULT	= 15,
512 	END_RESULT		= 16,
513 	NEXT_REFERRAL		= 17,
514 	GET_REFERRAL_SESSION	= 18,
515 	ERROR			= 19,
516 	LDAP_ERROR		= 20,
517 	GET_ACCT_MGMT_INFO	= 21
518 } ns_state_t;
519 
520 /*
521  * this enum lists the various states of the write state machine
522  */
523 typedef enum {
524 	W_INIT			= 1,
525 	W_EXIT			= 2,
526 	GET_CONNECTION		= 3,
527 	SELECT_OPERATION_SYNC	= 4,
528 	SELECT_OPERATION_ASYNC	= 5,
529 	DO_ADD_SYNC		= 6,
530 	DO_DELETE_SYNC		= 7,
531 	DO_MODIFY_SYNC		= 8,
532 	DO_ADD_ASYNC		= 9,
533 	DO_DELETE_ASYNC		= 10,
534 	DO_MODIFY_ASYNC		= 11,
535 	GET_RESULT_SYNC		= 12,
536 	GET_RESULT_ASYNC	= 13,
537 	PARSE_RESULT		= 14,
538 	GET_REFERRAL_CONNECTION	= 15,
539 	W_LDAP_ERROR		= 16,
540 	W_ERROR			= 17
541 } ns_write_state_t;
542 
543 
544 typedef int ConnectionID;
545 
546 /*
547  * This structure is used by ns_connect to create and manage
548  * one or more ldap connections within the library.
549  */
550 typedef struct connection {
551 	ConnectionID		connectionId;
552 	boolean_t		usedBit;	/* true if only used by */
553 						/* one thread and not shared */
554 						/* by other threads */
555 	boolean_t		notAvail;	/* not sharable, delete */
556 						/* when shared == 0 */
557 	int			shared;		/* number of threads */
558 						/* using this connection */
559 	char			*serverAddr;
560 	ns_cred_t		*auth;
561 	LDAP			*ld;
562 	thread_t		threadID;	/* thread ID using it */
563 	struct ns_ldap_cookie	*cookieInfo;
564 	char 			**controls;		/* from server_info */
565 	char			**saslMechanisms;	/* from server_info */
566 } Connection;
567 
568 #define	ONE_STEP			1
569 
570 /*
571  * This structure is for referrals processing.
572  * The data are from referral URLs returned by
573  * LDAP servers
574  */
575 typedef struct ns_referral_info {
576 	struct ns_referral_info	*next;
577 	char			*refHost;
578 	int			refScope;
579 	char			*refDN;
580 	char			*refFilter;
581 } ns_referral_info_t;
582 
583 /*
584  * This structure used internally in searches
585  */
586 
587 typedef struct ns_ldap_cookie {
588 	/* INPUTS */
589 		/* server list position */
590 
591 		/* service search descriptor list & position */
592 	ns_ldap_search_desc_t  **sdlist;
593 	ns_ldap_search_desc_t  **sdpos;
594 
595 		/* search filter callback */
596 	int			use_filtercb;
597 	int 	(*init_filter_cb)(const ns_ldap_search_desc_t *desc,
598 			char **realfilter, const void *userdata);
599 
600 		/* user callback */
601 	int			use_usercb;
602 	int	(*callback)(const ns_ldap_entry_t *entry,
603 			const void *userdata);
604 	const void		*userdata;
605 
606 	int			followRef;
607 	int			use_paging;
608 	char			*service;
609 	char			*i_filter;
610 	const char * const	*i_attr;
611 	const ns_cred_t		*i_auth;
612 	int 			i_flags;
613 
614 	/* OUTPUTS */
615 	ns_ldap_result_t	*result;
616 	ns_ldap_entry_t		*nextEntry;
617 		/* Error data */
618 	int			err_rc;
619 	ns_ldap_error_t		*errorp;
620 
621 	/* PRIVATE */
622 	ns_state_t		state;
623 	ns_state_t		new_state;
624 	ns_state_t		next_state;
625 
626 	Connection		*conn;
627 #define	conn_auth_type	conn->auth->auth.type
628 	ConnectionID		connectionId;
629 
630 	/* paging VLV/SIMPLEPAGE data */
631 	int			listType;
632 	unsigned long		index;
633 	LDAPControl		**p_serverctrls;
634 
635 	int			scope;
636 	char			*basedn;
637 	char			*filter;
638 	char			**attribute;
639 
640 	/* RESULT PROCESSING */
641 	int			msgId;
642 	LDAPMessage		*resultMsg;
643 
644 	char			**dns;
645 	char			*currentdn;
646 	int			flag;
647 	struct berval   	*ctrlCookie;
648 
649 	/* REFERRALS PROCESSING */
650 	/* referralinfo list & position */
651 	ns_referral_info_t  	*reflist;
652 	ns_referral_info_t  	*refpos;
653 	/* search timeout value */
654 	struct timeval		search_timeout;
655 	/* response control to hold account management information */
656 	LDAPControl		**resultctrl;
657 	/* Flag to indicate password less account management is required */
658 	int			nopasswd_acct_mgmt;
659 } ns_ldap_cookie_t;
660 
661 /*
662  * This structure is part of the return value information for
663  * __s_api_requestServer.  The routine that requests a new server
664  * from the cache manager
665  */
666 typedef struct ns_server_info {
667 	char	*server;
668 	char 	**controls;
669 	char	**saslMechanisms;
670 } ns_server_info_t;
671 
672 /*
673  * sasl callback function parameters
674  */
675 typedef struct ns_sasl_cb_param {
676 	char	*mech;
677 	char	*authid;
678 	char	*authzid;
679 	char	*passwd;
680 	char	*realm;
681 } ns_sasl_cb_param_t;
682 
683 /* self/sasl/gssapi variable */
684 extern int sasl_gssapi_inited;
685 
686 /* Multiple threads per connection variable */
687 extern int MTperConn;
688 
689 /*
690  * INTERNAL GLOBAL DEFINITIONS AND FUNCTION DECLARATIONS
691  */
692 
693 #ifdef DEBUG
694 extern int	__ldap_debug_file;
695 extern int	__ldap_debug_api;
696 extern int	__ldap_debug_ldap;
697 extern int	__ldap_debug_servers;
698 #endif
699 
700 /* internal connection APIs */
701 void DropConnection(ConnectionID, int);
702 int __s_api_getServers(char *** servers, ns_ldap_error_t ** error);
703 
704 int __s_get_enum_value(ns_config_t *ptr, char *value, ParamIndexType i);
705 char *__s_get_auth_name(ns_config_t *ptr, AuthType_t type);
706 char *__s_get_security_name(ns_config_t *ptr, TlsType_t type);
707 char *__s_get_scope_name(ns_config_t *ptr, ScopeType_t type);
708 char *__s_get_pref_name(PrefOnly_t type);
709 char *__s_get_searchref_name(ns_config_t *ptr, SearchRef_t type);
710 char *__s_get_hostcertpath(void);
711 
712 
713 /* ************ internal sldap-api functions *********** */
714 void	__ns_ldap_freeEntry(ns_ldap_entry_t *ep);
715 void	__s_api_split_key_value(char *buffer, char **name, char **value);
716 int	__s_api_printResult(ns_ldap_result_t *);
717 int	__s_api_getSearchScope(int *, ns_ldap_error_t **);
718 int	__s_api_getDNs(char ***, const char *,
719 	ns_ldap_error_t **);
720 int	__s_api_get_search_DNs_v1(char ***, const char *,
721 	ns_ldap_error_t **);
722 int	__s_api_getConnection(const char *, const int,
723 	const ns_cred_t *, int *,
724 	Connection **, ns_ldap_error_t **, int, int);
725 char	**__s_api_cp2dArray(char **);
726 void	__s_api_free2dArray(char **);
727 
728 int	__s_api_isCtrlSupported(Connection *, char *);
729 ns_config_t *__ns_ldap_make_config(ns_ldap_result_t *result);
730 ns_auth_t  *__s_api_AuthEnumtoStruct(const EnumAuthType_t i);
731 char	*dvalue(char *);
732 char	*evalue(char *);
733 
734 extern void	get_environment();
735 
736 /* internal Param APIs */
737 int		__ns_ldap_setParamValue(ns_config_t *ptr,
738 			const ParamIndexType type,
739 			const void *data, ns_ldap_error_t **error);
740 int		__s_api_get_type(const char *value, ParamIndexType *type);
741 int		__s_api_get_versiontype(ns_config_t *ptr, char *value,
742 					ParamIndexType *type);
743 int		__s_api_get_profiletype(char *value, ParamIndexType *type);
744 void		__s_api_init_config(ns_config_t *ptr);
745 ns_parse_status __s_api_crosscheck(ns_config_t *domainptr, char *errstr,
746 					int check_dn);
747 ns_config_t	*__s_api_create_config(void);
748 ns_config_t	*__s_api_get_default_config(void);
749 ns_config_t	*__s_api_loadrefresh_config();
750 void		__s_api_destroy_config(ns_config_t *ptr);
751 int		__s_api_get_configtype(ParamIndexType type);
752 const char	*__s_api_get_configname(ParamIndexType type);
753 char		*__s_api_strValue(ns_config_t *ptr, char *str,
754 			int bufsz, ParamIndexType i,
755 			ns_strfmt_t fmt);
756 void		__s_api_release_config(ns_config_t *cfg);
757 
758 /* internal attribute/objectclass mapping api's */
759 int		 __s_api_add_map2hash(ns_config_t *config,
760 				ns_hashtype_t type, ns_mapping_t *map);
761 void		__s_api_destroy_hash(ns_config_t *config);
762 int		__s_api_parse_map(char *cp, char **sid,
763 				char **origA, char ***mapA);
764 char		**__ns_ldap_mapAttributeList(const char *service,
765 				const char * const *origAttrList);
766 
767 /* internal configuration APIs */
768 void		__ns_ldap_setServer(int set);
769 ns_ldap_error_t	*__ns_ldap_LoadConfiguration();
770 ns_ldap_error_t	*__ns_ldap_LoadDoorInfo(LineBuf *configinfo, char *domainname);
771 ns_ldap_error_t *__ns_ldap_DumpConfiguration(char *filename);
772 ns_ldap_error_t	*__ns_ldap_DumpLdif(char *filename);
773 int		__ns_ldap_cache_ping();
774 ns_ldap_error_t *__ns_ldap_print_config(int);
775 void		__ns_ldap_default_config();
776 int		__ns_ldap_download(const char *, char *, char *,
777 				ns_ldap_error_t **);
778 int
779 __ns_ldap_check_dns_preq(int foreground,
780 		int mode_verbose,
781 		int mode_quiet,
782 		const char *fname,
783 		ns_ldap_self_gssapi_config_t config,
784 		ns_ldap_error_t **errpp);
785 int
786 __ns_ldap_check_gssapi_preq(int foreground,
787 		int mode_verbose,
788 		int mode_quiet,
789 		ns_ldap_self_gssapi_config_t config,
790 		ns_ldap_error_t **errpp);
791 int
792 __ns_ldap_check_all_preq(int foreground,
793 		int mode_verbose,
794 		int mode_quiet,
795 		ns_ldap_self_gssapi_config_t config,
796 		ns_ldap_error_t **errpp);
797 
798 /* internal un-exposed APIs */
799 ns_cred_t 	*__ns_ldap_dupAuth(const ns_cred_t *authp);
800 int		__s_api_get_SSD_from_SSDtoUse_service(const char *service,
801 			ns_ldap_search_desc_t ***SSDlist,
802 			ns_ldap_error_t **errorp);
803 int		__s_api_prepend_automountmapname(const char *service,
804 			ns_ldap_search_desc_t ***SSDlist,
805 			ns_ldap_error_t ** errorp);
806 int		__s_api_prepend_automountmapname_to_dn(const char *service,
807 			char **basedn,
808 			ns_ldap_error_t ** errorp);
809 int		__s_api_convert_automountmapname(const char *service,
810 			char **dn, ns_ldap_error_t ** errorp);
811 int		__s_api_replace_mapped_attr_in_dn(
812 			const char *orig_attr, const char *mapped_attr,
813 			const char *dn, char **new_dn);
814 int		__s_api_append_default_basedn(
815 			const char *dn,
816 			char **new_dn,
817 			int *allocated,
818 			ns_ldap_error_t ** errorp);
819 int		__s_api_removeServer(const char *server);
820 void		__s_api_removeBadServers(char **server);
821 
822 /* internal referrals APIs */
823 int 		__s_api_toFollowReferrals(const int flags,
824 			int *toFollow,
825 			ns_ldap_error_t **errorp);
826 int 		__s_api_addRefInfo(ns_referral_info_t **head,
827 			char *url, char *baseDN, int *scope,
828 			char *filter, LDAP *ld);
829 void		__s_api_deleteRefInfo(ns_referral_info_t *head);
830 
831 /* callback routine for SSD filters */
832 int		__s_api_merge_SSD_filter(const ns_ldap_search_desc_t *desc,
833 			char **realfilter,
834 			const void *userdata);
835 
836 /* network address verification api */
837 int		__s_api_isipv4(char *addr);
838 int		__s_api_isipv6(char *addr);
839 int		__s_api_ishost(char *addr);
840 
841 /* password management routine */
842 ns_ldap_passwd_status_t
843 		__s_api_set_passwd_status(int errnum, char *errmsg);
844 int		__s_api_contain_passwd_control_oid(char **oids);
845 
846 /* password less account management routine */
847 int		__s_api_contain_account_usable_control_oid(char **oids);
848 
849 /* RFC 2307 section 5.6. Get a canonical name from entry */
850 char		*__s_api_get_canonical_name(ns_ldap_entry_t *entry,
851 			ns_ldap_attr_t *attrptr, int case_ignore);
852 
853 /* self/sasl/gssapi functions */
854 int		__s_api_sasl_bind_callback(
855 			LDAP		*ld,
856 			unsigned	flags,
857 			void		*defaults,
858 			void		*in);
859 
860 int		__s_api_self_gssapi_only_get(void);
861 int		__s_api_sasl_gssapi_init(void);
862 
863 /* Multiple threads per connection functions */
864 void ns_tsd_cleanup(void *);
865 
866 #ifdef __cplusplus
867 }
868 #endif
869 
870 #endif /* _NS_INTERNAL_H */
871