xref: /titanic_52/usr/src/lib/libidmap/common/idmap_priv.h (revision a1d92fe4831144630aa0b262cde1629785c37f23)
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 /*
27  * Additional API for Identity Mapping Service
28  */
29 
30 #ifndef _IDMAP_PRIV_H
31 #define	_IDMAP_PRIV_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <libscf.h>
36 #include <syslog.h>
37 #include <resolv.h>
38 
39 #include "idmap.h"
40 #include "idmap_prot.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #define	IDMAP_MAX_NAME_LEN	512
47 
48 #define	IDMAP_ERROR(rc)		(rc != IDMAP_SUCCESS && rc != IDMAP_NEXT)
49 #define	IDMAP_FATAL_ERROR(rc)	(rc == IDMAP_ERR_MEMORY ||\
50 				rc == IDMAP_ERR_DB)
51 
52 /* Direction in which mapping is valid */
53 #define	IDMAP_DIRECTION_UNDEF	-1	/* not defined */
54 #define	IDMAP_DIRECTION_BI	0	/* bi-directional */
55 #define	IDMAP_DIRECTION_W2U	1	/* windows to unix only */
56 #define	IDMAP_DIRECTION_U2W	2	/* unix to windows only */
57 
58 
59 /* is_user values */
60 
61 #define	IDMAP_YES 1
62 #define	IDMAP_NO 0
63 #define	IDMAP_UNKNOWN -1
64 
65 /* Opaque handle to batch config add/remove operations */
66 typedef struct idmap_udt_handle idmap_udt_handle_t;
67 
68 /* Opaque iterator */
69 typedef struct idmap_iter idmap_iter_t;
70 
71 /*
72  * Update API
73  */
74 
75 /* Create handle for updates */
76 extern idmap_stat idmap_udt_create(idmap_handle_t *,
77 	idmap_udt_handle_t **);
78 
79 /* Commit */
80 extern idmap_stat idmap_udt_commit(idmap_udt_handle_t *);
81 
82 /* Get index of the failed batch element */
83 extern idmap_stat idmap_udt_get_error_index(idmap_udt_handle_t *, int64_t *);
84 
85 /* Get the rule which caused the batch to failed */
86 extern idmap_stat idmap_udt_get_error_rule(idmap_udt_handle_t *, char **,
87     char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
88 
89 /* Get the rule which caused a conflict */
90 extern idmap_stat idmap_udt_get_conflict_rule(idmap_udt_handle_t *, char **,
91     char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
92 
93 /* Destroy the update handle */
94 extern void idmap_udt_destroy(idmap_udt_handle_t *);
95 
96 /* Add name-based mapping rule */
97 extern idmap_stat idmap_udt_add_namerule(idmap_udt_handle_t *, const char *,
98 	boolean_t, boolean_t, const char *, const char *, boolean_t, int);
99 
100 /* Remove name-based mapping rule */
101 extern idmap_stat idmap_udt_rm_namerule(idmap_udt_handle_t *, boolean_t,
102 	boolean_t, const char *, const char *, const char *, int);
103 
104 /* Flush name-based mapping rules */
105 extern idmap_stat idmap_udt_flush_namerules(idmap_udt_handle_t *);
106 
107 
108 /*
109  * Iterator API
110  */
111 
112 /* Create a iterator to get SID to UID/GID mappings */
113 extern idmap_stat idmap_iter_mappings(idmap_handle_t *,	idmap_iter_t **,
114 	int flag);
115 
116 /* Iterate through the SID to UID/GID mappings */
117 extern idmap_stat idmap_iter_next_mapping(idmap_iter_t *, char **,
118 	idmap_rid_t *, uid_t *, char **, char **, char **, boolean_t *,
119 	boolean_t *, int *, idmap_info *);
120 
121 /* Create a iterator to get name-based mapping rules */
122 extern idmap_stat idmap_iter_namerules(idmap_handle_t *, const char *,
123 	boolean_t, boolean_t, const char *, const char *, idmap_iter_t **);
124 
125 /* Iterate through the name-based mapping rules */
126 extern idmap_stat idmap_iter_next_namerule(idmap_iter_t *, char **,
127 	char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
128 
129 /* Set the number of entries requested per batch */
130 extern idmap_stat idmap_iter_set_limit(idmap_iter_t *, uint64_t);
131 
132 /* Destroy the iterator */
133 extern void idmap_iter_destroy(idmap_iter_t *);
134 
135 
136 /*
137  * Get mapping
138  */
139 extern idmap_stat idmap_get_w2u_mapping(idmap_handle_t *, const char *,
140 	idmap_rid_t *, const char *, const char *, int, int *, int *,
141 	uid_t *, char **, int *, idmap_info *);
142 
143 extern idmap_stat idmap_get_u2w_mapping(idmap_handle_t *, uid_t *,
144 	const char *, int, int, int *, char **, idmap_rid_t *, char **,
145 	char **, int *, idmap_info *);
146 
147 
148 /*
149  * Miscellaneous
150  */
151 
152 /* string to status */
153 extern idmap_stat idmap_string2stat(const char *);
154 
155 /* internal status to protocol status */
156 extern idmap_stat idmap_stat4prot(idmap_stat);
157 
158 /* copy idmap_namerule including strings */
159 extern idmap_stat idmap_namerule_cpy(idmap_namerule *, idmap_namerule *);
160 
161 /* copy idmap_info info including strings */
162 extern idmap_stat idmap_info_cpy(idmap_info *to, idmap_info *from);
163 
164 /* Move  idmap_info info including strings */
165 extern idmap_stat idmap_info_mov(idmap_info *to, idmap_info *from);
166 
167 /* free idmap_info info from  user supplied struct */
168 extern void idmap_info_free(idmap_info *);
169 
170 
171 /*
172  * Extended API to batch SID to UID/GID mapping requests
173  */
174 
175 /* Given SID, get UID */
176 extern idmap_stat idmap_getext_uidbysid(idmap_get_handle_t *, char *,
177 	idmap_rid_t, int, uid_t *, idmap_info *, idmap_stat *);
178 
179 /* Given SID, get GID */
180 extern idmap_stat idmap_getext_gidbysid(idmap_get_handle_t *, char *,
181 	idmap_rid_t, int, gid_t *, idmap_info *, idmap_stat *);
182 
183 /* Given SID, get UID or GID */
184 extern idmap_stat idmap_getext_pidbysid(idmap_get_handle_t *, char *,
185 	idmap_rid_t, int, uid_t *, int *, idmap_info *, idmap_stat *);
186 
187 /* Given UID, get SID */
188 extern idmap_stat idmap_getext_sidbyuid(idmap_get_handle_t *, uid_t, int,
189 	char **, idmap_rid_t *, idmap_info *, idmap_stat *);
190 
191 /* Given GID, get SID */
192 extern idmap_stat idmap_getext_sidbygid(idmap_get_handle_t *, gid_t, int,
193 	char **, idmap_rid_t *, idmap_info *, idmap_stat *);
194 
195 
196 
197 /* logging */
198 extern void idmapdlog(int, const char *, ...);
199 
200 /*
201  * The maximal priority to be logged to stderr: set to -1 to suppress
202  * stderr logging completely.
203  */
204 extern void idmap_log_stderr(int);
205 
206 /* write log messages to syslog? */
207 extern void idmap_log_syslog(bool_t);
208 
209 /* write log messages to syslog? */
210 extern void idmap_log_degraded(bool_t);
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif /* _IDMAP_PRIV_H */
217