xref: /titanic_50/usr/src/lib/libsldap/common/ns_internal.h (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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 2007 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 	pid_t			pid;		/* process id */
560 	char			*serverAddr;
561 	ns_cred_t		*auth;
562 	LDAP			*ld;
563 	thread_t		threadID;	/* thread ID using it */
564 	struct ns_ldap_cookie	*cookieInfo;
565 	char 			**controls;		/* from server_info */
566 	char			**saslMechanisms;	/* from server_info */
567 } Connection;
568 
569 #define	ONE_STEP			1
570 
571 /*
572  * This structure is for referrals processing.
573  * The data are from referral URLs returned by
574  * LDAP servers
575  */
576 typedef struct ns_referral_info {
577 	struct ns_referral_info	*next;
578 	char			*refHost;
579 	int			refScope;
580 	char			*refDN;
581 	char			*refFilter;
582 } ns_referral_info_t;
583 
584 /*
585  * This structure used internally in searches
586  */
587 
588 typedef struct ns_ldap_cookie {
589 	/* INPUTS */
590 		/* server list position */
591 
592 		/* service search descriptor list & position */
593 	ns_ldap_search_desc_t  **sdlist;
594 	ns_ldap_search_desc_t  **sdpos;
595 
596 		/* search filter callback */
597 	int			use_filtercb;
598 	int 	(*init_filter_cb)(const ns_ldap_search_desc_t *desc,
599 			char **realfilter, const void *userdata);
600 
601 		/* user callback */
602 	int			use_usercb;
603 	int	(*callback)(const ns_ldap_entry_t *entry,
604 			const void *userdata);
605 	const void		*userdata;
606 
607 	int			followRef;
608 	int			use_paging;
609 	char			*service;
610 	char			*i_filter;
611 	const char * const	*i_attr;
612 	const ns_cred_t		*i_auth;
613 	int 			i_flags;
614 
615 	/* OUTPUTS */
616 	ns_ldap_result_t	*result;
617 	ns_ldap_entry_t		*nextEntry;
618 		/* Error data */
619 	int			err_rc;
620 	ns_ldap_error_t		*errorp;
621 
622 	/* PRIVATE */
623 	ns_state_t		state;
624 	ns_state_t		new_state;
625 	ns_state_t		next_state;
626 
627 	Connection		*conn;
628 #define	conn_auth_type	conn->auth->auth.type
629 	ConnectionID		connectionId;
630 
631 	/* paging VLV/SIMPLEPAGE data */
632 	int			listType;
633 	unsigned long		index;
634 	LDAPControl		**p_serverctrls;
635 
636 	int			scope;
637 	char			*basedn;
638 	char			*filter;
639 	char			**attribute;
640 
641 	/* RESULT PROCESSING */
642 	int			msgId;
643 	LDAPMessage		*resultMsg;
644 
645 	char			**dns;
646 	char			*currentdn;
647 	int			flag;
648 	struct berval   	*ctrlCookie;
649 
650 	/* REFERRALS PROCESSING */
651 	/* referralinfo list & position */
652 	ns_referral_info_t  	*reflist;
653 	ns_referral_info_t  	*refpos;
654 	/* search timeout value */
655 	struct timeval		search_timeout;
656 	/* response control to hold account management information */
657 	LDAPControl		**resultctrl;
658 	/* Flag to indicate password less account management is required */
659 	int			nopasswd_acct_mgmt;
660 	int			err_from_result;
661 } ns_ldap_cookie_t;
662 
663 /*
664  * This structure is part of the return value information for
665  * __s_api_requestServer.  The routine that requests a new server
666  * from the cache manager
667  */
668 typedef struct ns_server_info {
669 	char	*server;
670 	char 	**controls;
671 	char	**saslMechanisms;
672 } ns_server_info_t;
673 
674 /*
675  * sasl callback function parameters
676  */
677 typedef struct ns_sasl_cb_param {
678 	char	*mech;
679 	char	*authid;
680 	char	*authzid;
681 	char	*passwd;
682 	char	*realm;
683 } ns_sasl_cb_param_t;
684 
685 /* self/sasl/gssapi variable */
686 extern int sasl_gssapi_inited;
687 
688 /* Multiple threads per connection variable */
689 extern int MTperConn;
690 
691 /*
692  * INTERNAL GLOBAL DEFINITIONS AND FUNCTION DECLARATIONS
693  */
694 
695 #ifdef DEBUG
696 extern int	__ldap_debug_file;
697 extern int	__ldap_debug_api;
698 extern int	__ldap_debug_ldap;
699 extern int	__ldap_debug_servers;
700 #endif
701 
702 /* internal connection APIs */
703 void DropConnection(ConnectionID, int);
704 int __s_api_getServers(char *** servers, ns_ldap_error_t ** error);
705 
706 int __s_get_enum_value(ns_config_t *ptr, char *value, ParamIndexType i);
707 char *__s_get_auth_name(ns_config_t *ptr, AuthType_t type);
708 char *__s_get_security_name(ns_config_t *ptr, TlsType_t type);
709 char *__s_get_scope_name(ns_config_t *ptr, ScopeType_t type);
710 char *__s_get_pref_name(PrefOnly_t type);
711 char *__s_get_searchref_name(ns_config_t *ptr, SearchRef_t type);
712 char *__s_get_hostcertpath(void);
713 
714 
715 /* ************ internal sldap-api functions *********** */
716 void	__ns_ldap_freeEntry(ns_ldap_entry_t *ep);
717 void	__s_api_split_key_value(char *buffer, char **name, char **value);
718 int	__s_api_printResult(ns_ldap_result_t *);
719 int	__s_api_getSearchScope(int *, ns_ldap_error_t **);
720 int	__s_api_getDNs(char ***, const char *,
721 	ns_ldap_error_t **);
722 int	__s_api_get_search_DNs_v1(char ***, const char *,
723 	ns_ldap_error_t **);
724 int	__s_api_getConnection(const char *, const int,
725 	const ns_cred_t *, int *,
726 	Connection **, ns_ldap_error_t **, int, int);
727 char	**__s_api_cp2dArray(char **);
728 void	__s_api_free2dArray(char **);
729 
730 int	__s_api_isCtrlSupported(Connection *, char *);
731 ns_config_t *__ns_ldap_make_config(ns_ldap_result_t *result);
732 ns_auth_t  *__s_api_AuthEnumtoStruct(const EnumAuthType_t i);
733 char	*dvalue(char *);
734 char	*evalue(char *);
735 
736 extern void	get_environment();
737 
738 /* internal Param APIs */
739 int		__ns_ldap_setParamValue(ns_config_t *ptr,
740 			const ParamIndexType type,
741 			const void *data, ns_ldap_error_t **error);
742 int		__s_api_get_type(const char *value, ParamIndexType *type);
743 int		__s_api_get_versiontype(ns_config_t *ptr, char *value,
744 					ParamIndexType *type);
745 int		__s_api_get_profiletype(char *value, ParamIndexType *type);
746 void		__s_api_init_config(ns_config_t *ptr);
747 ns_parse_status __s_api_crosscheck(ns_config_t *domainptr, char *errstr,
748 					int check_dn);
749 ns_config_t	*__s_api_create_config(void);
750 ns_config_t	*__s_api_get_default_config(void);
751 ns_config_t	*__s_api_loadrefresh_config();
752 void		__s_api_destroy_config(ns_config_t *ptr);
753 int		__s_api_get_configtype(ParamIndexType type);
754 const char	*__s_api_get_configname(ParamIndexType type);
755 char		*__s_api_strValue(ns_config_t *ptr, char *str,
756 			int bufsz, ParamIndexType i,
757 			ns_strfmt_t fmt);
758 void		__s_api_release_config(ns_config_t *cfg);
759 
760 /* internal attribute/objectclass mapping api's */
761 int		 __s_api_add_map2hash(ns_config_t *config,
762 				ns_hashtype_t type, ns_mapping_t *map);
763 void		__s_api_destroy_hash(ns_config_t *config);
764 int		__s_api_parse_map(char *cp, char **sid,
765 				char **origA, char ***mapA);
766 char		**__ns_ldap_mapAttributeList(const char *service,
767 				const char * const *origAttrList);
768 
769 /* internal configuration APIs */
770 void		__ns_ldap_setServer(int set);
771 ns_ldap_error_t	*__ns_ldap_LoadConfiguration();
772 ns_ldap_error_t	*__ns_ldap_LoadDoorInfo(LineBuf *configinfo, char *domainname);
773 ns_ldap_error_t *__ns_ldap_DumpConfiguration(char *filename);
774 ns_ldap_error_t	*__ns_ldap_DumpLdif(char *filename);
775 int		__ns_ldap_cache_ping();
776 ns_ldap_error_t *__ns_ldap_print_config(int);
777 void		__ns_ldap_default_config();
778 int		__ns_ldap_download(const char *, char *, char *,
779 				ns_ldap_error_t **);
780 int
781 __ns_ldap_check_dns_preq(int foreground,
782 		int mode_verbose,
783 		int mode_quiet,
784 		const char *fname,
785 		ns_ldap_self_gssapi_config_t config,
786 		ns_ldap_error_t **errpp);
787 int
788 __ns_ldap_check_gssapi_preq(int foreground,
789 		int mode_verbose,
790 		int mode_quiet,
791 		ns_ldap_self_gssapi_config_t config,
792 		ns_ldap_error_t **errpp);
793 int
794 __ns_ldap_check_all_preq(int foreground,
795 		int mode_verbose,
796 		int mode_quiet,
797 		ns_ldap_self_gssapi_config_t config,
798 		ns_ldap_error_t **errpp);
799 
800 /* internal un-exposed APIs */
801 ns_cred_t 	*__ns_ldap_dupAuth(const ns_cred_t *authp);
802 int		__s_api_get_SSD_from_SSDtoUse_service(const char *service,
803 			ns_ldap_search_desc_t ***SSDlist,
804 			ns_ldap_error_t **errorp);
805 int		__s_api_prepend_automountmapname(const char *service,
806 			ns_ldap_search_desc_t ***SSDlist,
807 			ns_ldap_error_t ** errorp);
808 int		__s_api_prepend_automountmapname_to_dn(const char *service,
809 			char **basedn,
810 			ns_ldap_error_t ** errorp);
811 int		__s_api_convert_automountmapname(const char *service,
812 			char **dn, ns_ldap_error_t ** errorp);
813 int		__s_api_replace_mapped_attr_in_dn(
814 			const char *orig_attr, const char *mapped_attr,
815 			const char *dn, char **new_dn);
816 int		__s_api_append_default_basedn(
817 			const char *dn,
818 			char **new_dn,
819 			int *allocated,
820 			ns_ldap_error_t ** errorp);
821 int		__s_api_removeServer(const char *server);
822 void		__s_api_removeBadServers(char **server);
823 
824 /* internal referrals APIs */
825 int 		__s_api_toFollowReferrals(const int flags,
826 			int *toFollow,
827 			ns_ldap_error_t **errorp);
828 int 		__s_api_addRefInfo(ns_referral_info_t **head,
829 			char *url, char *baseDN, int *scope,
830 			char *filter, LDAP *ld);
831 void		__s_api_deleteRefInfo(ns_referral_info_t *head);
832 
833 /* callback routine for SSD filters */
834 int		__s_api_merge_SSD_filter(const ns_ldap_search_desc_t *desc,
835 			char **realfilter,
836 			const void *userdata);
837 
838 /* network address verification api */
839 int		__s_api_isipv4(char *addr);
840 int		__s_api_isipv6(char *addr);
841 int		__s_api_ishost(char *addr);
842 
843 /* password management routine */
844 ns_ldap_passwd_status_t
845 		__s_api_set_passwd_status(int errnum, char *errmsg);
846 int		__s_api_contain_passwd_control_oid(char **oids);
847 
848 /* password less account management routine */
849 int		__s_api_contain_account_usable_control_oid(char **oids);
850 
851 /* RFC 2307 section 5.6. Get a canonical name from entry */
852 char		*__s_api_get_canonical_name(ns_ldap_entry_t *entry,
853 			ns_ldap_attr_t *attrptr, int case_ignore);
854 
855 /* self/sasl/gssapi functions */
856 int		__s_api_sasl_bind_callback(
857 			LDAP		*ld,
858 			unsigned	flags,
859 			void		*defaults,
860 			void		*in);
861 
862 int		__s_api_self_gssapi_only_get(void);
863 int		__s_api_sasl_gssapi_init(void);
864 int		__s_api_check_MTC_tsd();
865 
866 /* Multiple threads per connection functions */
867 void ns_tsd_cleanup(void *);
868 
869 #ifdef __cplusplus
870 }
871 #endif
872 
873 #endif /* _NS_INTERNAL_H */
874