xref: /illumos-gate/usr/src/lib/libidmap/common/idmap_priv.h (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
1c5c4113dSnw141292 /*
2c5c4113dSnw141292  * CDDL HEADER START
3c5c4113dSnw141292  *
4c5c4113dSnw141292  * The contents of this file are subject to the terms of the
5c5c4113dSnw141292  * Common Development and Distribution License (the "License").
6c5c4113dSnw141292  * You may not use this file except in compliance with the License.
7c5c4113dSnw141292  *
8c5c4113dSnw141292  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c5c4113dSnw141292  * or http://www.opensolaris.org/os/licensing.
10c5c4113dSnw141292  * See the License for the specific language governing permissions
11c5c4113dSnw141292  * and limitations under the License.
12c5c4113dSnw141292  *
13c5c4113dSnw141292  * When distributing Covered Code, include this CDDL HEADER in each
14c5c4113dSnw141292  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c5c4113dSnw141292  * If applicable, add the following below this CDDL HEADER, with the
16c5c4113dSnw141292  * fields enclosed by brackets "[]" replaced with your own identifying
17c5c4113dSnw141292  * information: Portions Copyright [yyyy] [name of copyright owner]
18c5c4113dSnw141292  *
19c5c4113dSnw141292  * CDDL HEADER END
20c5c4113dSnw141292  */
21c5c4113dSnw141292 /*
22c5866007SKeyur Desai  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23c5c4113dSnw141292  */
24c5c4113dSnw141292 
25c5c4113dSnw141292 /*
26c5c4113dSnw141292  * Additional API for Identity Mapping Service
27c5c4113dSnw141292  */
28c5c4113dSnw141292 
29c5c4113dSnw141292 #ifndef _IDMAP_PRIV_H
30c5c4113dSnw141292 #define	_IDMAP_PRIV_H
31c5c4113dSnw141292 
32c5c4113dSnw141292 
33479ac375Sdm199847 #include <libscf.h>
34479ac375Sdm199847 #include <resolv.h>
35479ac375Sdm199847 
36c5c4113dSnw141292 #include "idmap.h"
379b214d32SJordan Brown #include <rpcsvc/idmap_prot.h>
38c5c4113dSnw141292 
39c5c4113dSnw141292 #ifdef __cplusplus
40c5c4113dSnw141292 extern "C" {
41c5c4113dSnw141292 #endif
42c5c4113dSnw141292 
43c5c4113dSnw141292 #define	IDMAP_MAX_NAME_LEN	512
44c5c4113dSnw141292 
450dcc7149Snw141292 #define	IDMAP_ERROR(rc)		(rc != IDMAP_SUCCESS && rc != IDMAP_NEXT)
460dcc7149Snw141292 #define	IDMAP_FATAL_ERROR(rc)	(rc == IDMAP_ERR_MEMORY ||\
470dcc7149Snw141292 				rc == IDMAP_ERR_DB)
48c5c4113dSnw141292 
49479ac375Sdm199847 
50479ac375Sdm199847 /* is_user values */
51479ac375Sdm199847 
52479ac375Sdm199847 #define	IDMAP_YES 1
53479ac375Sdm199847 #define	IDMAP_NO 0
54479ac375Sdm199847 #define	IDMAP_UNKNOWN -1
55479ac375Sdm199847 
5661b364a9Sjp151216 #define	CHECK_NULL(s)	(s != NULL ? s : "null")
5761b364a9Sjp151216 #define	EMPTY_STRING(str)	(str == NULL || *str == '\0')
5861b364a9Sjp151216 
59c5c4113dSnw141292 /* Opaque handle to batch config add/remove operations */
60c5c4113dSnw141292 typedef struct idmap_udt_handle idmap_udt_handle_t;
61c5c4113dSnw141292 
62c5c4113dSnw141292 /* Opaque iterator */
63c5c4113dSnw141292 typedef struct idmap_iter idmap_iter_t;
64c5c4113dSnw141292 
6561b364a9Sjp151216 
6661b364a9Sjp151216 /*
67c5c4113dSnw141292  * Update API
68c5c4113dSnw141292  */
69c5c4113dSnw141292 
70c5c4113dSnw141292 /* Create handle for updates */
71*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_udt_create(idmap_udt_handle_t **);
72c5c4113dSnw141292 
73c5c4113dSnw141292 /* Commit */
74c5c4113dSnw141292 extern idmap_stat idmap_udt_commit(idmap_udt_handle_t *);
75c5c4113dSnw141292 
768e228215Sdm199847 /* Get index of the failed batch element */
778e228215Sdm199847 extern idmap_stat idmap_udt_get_error_index(idmap_udt_handle_t *, int64_t *);
788e228215Sdm199847 
798e228215Sdm199847 /* Get the rule which caused the batch to failed */
808e228215Sdm199847 extern idmap_stat idmap_udt_get_error_rule(idmap_udt_handle_t *, char **,
81cd37da74Snw141292     char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
828e228215Sdm199847 
838e228215Sdm199847 /* Get the rule which caused a conflict */
848e228215Sdm199847 extern idmap_stat idmap_udt_get_conflict_rule(idmap_udt_handle_t *, char **,
85cd37da74Snw141292     char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
868e228215Sdm199847 
87c5c4113dSnw141292 /* Destroy the update handle */
88c5c4113dSnw141292 extern void idmap_udt_destroy(idmap_udt_handle_t *);
89c5c4113dSnw141292 
90c5c4113dSnw141292 /* Add name-based mapping rule */
91c5c4113dSnw141292 extern idmap_stat idmap_udt_add_namerule(idmap_udt_handle_t *, const char *,
92cd37da74Snw141292 	boolean_t, boolean_t, const char *, const char *, boolean_t, int);
93c5c4113dSnw141292 
94c5c4113dSnw141292 /* Remove name-based mapping rule */
95c5c4113dSnw141292 extern idmap_stat idmap_udt_rm_namerule(idmap_udt_handle_t *, boolean_t,
96cd37da74Snw141292 	boolean_t, const char *, const char *, const char *, int);
97c5c4113dSnw141292 
98c5c4113dSnw141292 /* Flush name-based mapping rules */
99cd37da74Snw141292 extern idmap_stat idmap_udt_flush_namerules(idmap_udt_handle_t *);
100c5c4113dSnw141292 
1019fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States /* Flush caches */
102*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_flush(idmap_flush_op);
103c5c4113dSnw141292 
104c5c4113dSnw141292 /*
105c5c4113dSnw141292  * Iterator API
106c5c4113dSnw141292  */
107c5c4113dSnw141292 
108c5c4113dSnw141292 /* Create a iterator to get SID to UID/GID mappings */
109*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_iter_mappings(idmap_iter_t **, int flag);
110c5c4113dSnw141292 
111c5c4113dSnw141292 /* Iterate through the SID to UID/GID mappings */
112c5c4113dSnw141292 extern idmap_stat idmap_iter_next_mapping(idmap_iter_t *, char **,
113cd37da74Snw141292 	idmap_rid_t *, uid_t *, char **, char **, char **, boolean_t *,
11448258c6bSjp151216 	boolean_t *, int *, idmap_info *);
115c5c4113dSnw141292 
116c5c4113dSnw141292 /* Create a iterator to get name-based mapping rules */
117*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_iter_namerules(const char *,
118cd37da74Snw141292 	boolean_t, boolean_t, const char *, const char *, idmap_iter_t **);
119c5c4113dSnw141292 
120c5c4113dSnw141292 /* Iterate through the name-based mapping rules */
121c5c4113dSnw141292 extern idmap_stat idmap_iter_next_namerule(idmap_iter_t *, char **,
122cd37da74Snw141292 	char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
123c5c4113dSnw141292 
124c5c4113dSnw141292 /* Set the number of entries requested per batch */
125c5c4113dSnw141292 extern idmap_stat idmap_iter_set_limit(idmap_iter_t *, uint64_t);
126c5c4113dSnw141292 
127c5c4113dSnw141292 /* Destroy the iterator */
128c5c4113dSnw141292 extern void idmap_iter_destroy(idmap_iter_t *);
129c5c4113dSnw141292 
130c5c4113dSnw141292 
131c5c4113dSnw141292 /*
132c5c4113dSnw141292  * Get mapping
133c5c4113dSnw141292  */
134*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_get_w2u_mapping(const char *,
135cd37da74Snw141292 	idmap_rid_t *, const char *, const char *, int, int *, int *,
13648258c6bSjp151216 	uid_t *, char **, int *, idmap_info *);
137c5c4113dSnw141292 
138*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_get_u2w_mapping(uid_t *,
139cd37da74Snw141292 	const char *, int, int, int *, char **, idmap_rid_t *, char **,
14048258c6bSjp151216 	char **, int *, idmap_info *);
141c5c4113dSnw141292 
142c5c4113dSnw141292 
143c5c4113dSnw141292 /*
144c5c4113dSnw141292  * Miscellaneous
145c5c4113dSnw141292  */
146c5c4113dSnw141292 
147c5c4113dSnw141292 /* string to status */
148c5c4113dSnw141292 extern idmap_stat idmap_string2stat(const char *);
149c5c4113dSnw141292 
150c5c4113dSnw141292 /* internal status to protocol status */
151c5c4113dSnw141292 extern idmap_stat idmap_stat4prot(idmap_stat);
152c5c4113dSnw141292 
1538e228215Sdm199847 /* copy idmap_namerule including strings */
1548e228215Sdm199847 extern idmap_stat idmap_namerule_cpy(idmap_namerule *, idmap_namerule *);
1558e228215Sdm199847 
15648258c6bSjp151216 /* Move  idmap_info info including strings */
157148c5f43SAlan Wright extern void idmap_info_mov(idmap_info *to, idmap_info *from);
15848258c6bSjp151216 
15948258c6bSjp151216 /* free idmap_info info from  user supplied struct */
16048258c6bSjp151216 extern void idmap_info_free(idmap_info *);
161148c5f43SAlan Wright extern void idmap_how_clear(idmap_how *);
16248258c6bSjp151216 
16348258c6bSjp151216 
16448258c6bSjp151216 /*
16548258c6bSjp151216  * Extended API to batch SID to UID/GID mapping requests
16648258c6bSjp151216  */
16748258c6bSjp151216 
16848258c6bSjp151216 /* Given SID, get UID */
16948258c6bSjp151216 extern idmap_stat idmap_getext_uidbysid(idmap_get_handle_t *, char *,
17048258c6bSjp151216 	idmap_rid_t, int, uid_t *, idmap_info *, idmap_stat *);
17148258c6bSjp151216 
17248258c6bSjp151216 /* Given SID, get GID */
17348258c6bSjp151216 extern idmap_stat idmap_getext_gidbysid(idmap_get_handle_t *, char *,
17448258c6bSjp151216 	idmap_rid_t, int, gid_t *, idmap_info *, idmap_stat *);
17548258c6bSjp151216 
17648258c6bSjp151216 /* Given SID, get UID or GID */
17748258c6bSjp151216 extern idmap_stat idmap_getext_pidbysid(idmap_get_handle_t *, char *,
17848258c6bSjp151216 	idmap_rid_t, int, uid_t *, int *, idmap_info *, idmap_stat *);
17948258c6bSjp151216 
18048258c6bSjp151216 /* Given UID, get SID */
18148258c6bSjp151216 extern idmap_stat idmap_getext_sidbyuid(idmap_get_handle_t *, uid_t, int,
18248258c6bSjp151216 	char **, idmap_rid_t *, idmap_info *, idmap_stat *);
18348258c6bSjp151216 
18448258c6bSjp151216 /* Given GID, get SID */
18548258c6bSjp151216 extern idmap_stat idmap_getext_sidbygid(idmap_get_handle_t *, gid_t, int,
18648258c6bSjp151216 	char **, idmap_rid_t *, idmap_info *, idmap_stat *);
18748258c6bSjp151216 
188c5866007SKeyur Desai /* Properties */
189*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_get_prop_ds(idmap_prop_type, idmap_ad_disc_ds_t *);
190*1fdeec65Sjoyce mcintosh extern idmap_stat idmap_get_prop_str(idmap_prop_type, char **);
19148258c6bSjp151216 
192148c5f43SAlan Wright /*
193148c5f43SAlan Wright  * Trace
194148c5f43SAlan Wright  *
195148c5f43SAlan Wright  * These are the names of the trace parameters that may be returned
196148c5f43SAlan Wright  * when tracing is requested.
197148c5f43SAlan Wright  */
198148c5f43SAlan Wright #define	IDMAP_TRACE_NAME_MAX	100	/* max length of a trace param name */
199148c5f43SAlan Wright #define	IDMAP_TRACE_TYPE	"-type"		/* prefix with "from" or "to" */
200148c5f43SAlan Wright #define	IDMAP_TRACE_NAME	"-name"		/* prefix with "from" or "to" */
201148c5f43SAlan Wright #define	IDMAP_TRACE_SID		"-sid"		/* prefix with "from" or "to" */
202148c5f43SAlan Wright #define	IDMAP_TRACE_UNIXID	"-unixid"	/* prefix with "from" or "to" */
203148c5f43SAlan Wright #define	IDMAP_TRACE_ERROR	"error"
204148c5f43SAlan Wright #define	IDMAP_TRACE_MESSAGE	"message"
205148c5f43SAlan Wright 
206148c5f43SAlan Wright extern void idmap_trace_print_1(FILE *out, char *prefix, nvlist_t *entry);
207148c5f43SAlan Wright extern void idmap_trace_print(FILE *out, char *prefix, nvlist_t *trace);
208148c5f43SAlan Wright 
209c5c4113dSnw141292 #ifdef __cplusplus
210c5c4113dSnw141292 }
211c5c4113dSnw141292 #endif
212c5c4113dSnw141292 
213c5c4113dSnw141292 #endif /* _IDMAP_PRIV_H */
214