xref: /titanic_41/usr/src/lib/nsswitch/ad/common/ad_common.h (revision ff5ca3bd17dee7e2bf2e4f2e3a2b354e0ecbd00d)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_AD_COMMON_H
27 #define	_AD_COMMON_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <ctype.h>
34 #include <nss_dbdefs.h>
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <strings.h>
39 #include <signal.h>
40 #include <idmap.h>
41 #include <sys/idmap.h>
42 #include <idmap_prot.h>
43 #include <idmap_priv.h>
44 #include "addisc.h"
45 #include "libadutils.h"
46 
47 #define	_GROUP	"group"
48 #define	_PASSWD	"passwd"
49 #define	_SHADOW	"shadow"
50 
51 #define	WK_DOMAIN	"BUILTIN"
52 #define	CFG_QUEUE_MAX_SIZE	15
53 
54 #define	SEARCHFILTERLEN		256
55 #define	RESET_ERRNO()\
56 	if (errno == EINVAL)\
57 		errno = 0;
58 
59 /*
60  * Superset the nss_backend_t abstract data type. This ADT has
61  * been extended to include AD associated data structures.
62  */
63 
64 typedef struct ad_backend *ad_backend_ptr;
65 typedef nss_status_t (*ad_backend_op_t)(ad_backend_ptr, void *);
66 typedef int (*fnf)(ad_backend_ptr be, nss_XbyY_args_t *argp);
67 
68 typedef enum {
69 	NSS_AD_DB_NONE		= 0,
70 	NSS_AD_DB_PASSWD_BYNAME	= 1,
71 	NSS_AD_DB_PASSWD_BYUID	= 2,
72 	NSS_AD_DB_GROUP_BYNAME	= 3,
73 	NSS_AD_DB_GROUP_BYGID	= 4,
74 	NSS_AD_DB_SHADOW_BYNAME	= 5
75 } nss_ad_db_type_t;
76 
77 struct ad_backend {
78 	ad_backend_op_t		*ops;
79 	nss_dbop_t		nops;
80 	char			*tablename;
81 	const char		**attrs;
82 	fnf			adobj2str;
83 	char			*buffer;
84 	int			buflen;
85 	idmap_handle_t		*ih;
86 	uid_t			uid;
87 	adutils_result_t	*result;
88 	nss_ad_db_type_t	db_type;
89 };
90 
91 typedef struct nssad_prop {
92 	char			*domain_name;
93 	idmap_ad_disc_ds_t	*domain_controller;
94 } nssad_prop_t;
95 
96 typedef struct nssad_cfg {
97 	pthread_rwlock_t	lock;
98 	nssad_prop_t		props;
99 	ad_disc_t		ad_ctx;
100 	adutils_ad_t		*ad;
101 	struct nssad_cfg	*qnext;
102 } nssad_cfg_t;
103 
104 typedef struct nssad_state {
105 	nssad_cfg_t		*qhead;
106 	nssad_cfg_t		*qtail;
107 	uint32_t		qcount;
108 } nssad_state_t;
109 
110 extern nss_status_t	_nss_ad_destr(ad_backend_ptr be, void *a);
111 extern nss_status_t	_nss_ad_endent(ad_backend_ptr be, void *a);
112 extern nss_status_t	_nss_ad_setent(ad_backend_ptr be, void *a);
113 extern nss_status_t	_nss_ad_getent(ad_backend_ptr be, void *a);
114 nss_backend_t		*_nss_ad_constr(ad_backend_op_t ops[], int nops,
115 			char *tablename, const char **attrs, fnf ldapobj2str);
116 extern nss_status_t	_nss_ad_lookup(ad_backend_ptr be,
117 			nss_XbyY_args_t *argp, const char *database,
118 			const char *searchfilter, const char *dname,
119 			int *try_idmap);
120 extern nss_status_t	_nss_ad_marshall_data(ad_backend_ptr be,
121 			nss_XbyY_args_t *argp);
122 extern nss_status_t	_nss_ad_sanitize_status(ad_backend_ptr be,
123 			nss_XbyY_args_t *argp, nss_status_t stat);
124 extern int		_ldap_filter_name(char *filter_name, const char *name,
125 			int filter_name_size);
126 
127 
128 #ifdef	__cplusplus
129 }
130 #endif
131 
132 #endif	/* _AD_COMMON_H */
133