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