xref: /illumos-gate/usr/src/lib/nsswitch/ad/common/ad_common.h (revision 4c28a617e3922d92a58e813a5b955eb526b9c386)
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  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
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 <rpcsvc/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 	uid_t			uid;
86 	adutils_result_t	*result;
87 	nss_ad_db_type_t	db_type;
88 };
89 
90 typedef struct nssad_prop {
91 	char			*domain_name;
92 	ad_disc_ds_t	*domain_controller;
93 } nssad_prop_t;
94 
95 typedef struct nssad_cfg {
96 	pthread_rwlock_t	lock;
97 	nssad_prop_t		props;
98 	ad_disc_t		ad_ctx;
99 	adutils_ad_t		*ad;
100 	struct nssad_cfg	*qnext;
101 } nssad_cfg_t;
102 
103 typedef struct nssad_state {
104 	nssad_cfg_t		*qhead;
105 	nssad_cfg_t		*qtail;
106 	uint32_t		qcount;
107 } nssad_state_t;
108 
109 extern nss_status_t	_nss_ad_destr(ad_backend_ptr be, void *a);
110 extern nss_status_t	_nss_ad_endent(ad_backend_ptr be, void *a);
111 extern nss_status_t	_nss_ad_setent(ad_backend_ptr be, void *a);
112 extern nss_status_t	_nss_ad_getent(ad_backend_ptr be, void *a);
113 nss_backend_t		*_nss_ad_constr(ad_backend_op_t ops[], int nops,
114 			char *tablename, const char **attrs, fnf ldapobj2str);
115 extern nss_status_t	_nss_ad_lookup(ad_backend_ptr be,
116 			nss_XbyY_args_t *argp, const char *database,
117 			const char *searchfilter, const char *dname,
118 			int *try_idmap);
119 extern nss_status_t	_nss_ad_marshall_data(ad_backend_ptr be,
120 			nss_XbyY_args_t *argp);
121 extern nss_status_t	_nss_ad_sanitize_status(ad_backend_ptr be,
122 			nss_XbyY_args_t *argp, nss_status_t stat);
123 extern int		_ldap_filter_name(char *filter_name, const char *name,
124 			int filter_name_size);
125 
126 
127 #ifdef	__cplusplus
128 }
129 #endif
130 
131 #endif	/* _AD_COMMON_H */
132