xref: /illumos-gate/usr/src/lib/libidmap/common/idmap_impl.h (revision 8e22821528b08c6dba4e8176351560f316f6d0de)
1c5c4113dSnw /*
2c5c4113dSnw  * CDDL HEADER START
3c5c4113dSnw  *
4c5c4113dSnw  * The contents of this file are subject to the terms of the
5c5c4113dSnw  * Common Development and Distribution License (the "License").
6c5c4113dSnw  * You may not use this file except in compliance with the License.
7c5c4113dSnw  *
8c5c4113dSnw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c5c4113dSnw  * or http://www.opensolaris.org/os/licensing.
10c5c4113dSnw  * See the License for the specific language governing permissions
11c5c4113dSnw  * and limitations under the License.
12c5c4113dSnw  *
13c5c4113dSnw  * When distributing Covered Code, include this CDDL HEADER in each
14c5c4113dSnw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c5c4113dSnw  * If applicable, add the following below this CDDL HEADER, with the
16c5c4113dSnw  * fields enclosed by brackets "[]" replaced with your own identifying
17c5c4113dSnw  * information: Portions Copyright [yyyy] [name of copyright owner]
18c5c4113dSnw  *
19c5c4113dSnw  * CDDL HEADER END
20c5c4113dSnw  */
21c5c4113dSnw /*
22c5c4113dSnw  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23c5c4113dSnw  * Use is subject to license terms.
24c5c4113dSnw  */
25c5c4113dSnw 
26c5c4113dSnw /*
27c5c4113dSnw  * Private Header for Identity Mapping
28c5c4113dSnw  */
29c5c4113dSnw 
30c5c4113dSnw #ifndef _IDMAP_IMPL_H
31c5c4113dSnw #define	_IDMAP_IMPL_H
32c5c4113dSnw 
33c5c4113dSnw #pragma ident	"%Z%%M%	%I%	%E% SMI"
34c5c4113dSnw 
35c5c4113dSnw #include "idmap_prot.h"
36c5c4113dSnw #include "idmap_priv.h"
37c5c4113dSnw #include <rpc/xdr.h>
38c5c4113dSnw 
39c5c4113dSnw #ifdef __cplusplus
40c5c4113dSnw extern "C" {
41c5c4113dSnw #endif
42c5c4113dSnw 
43c5c4113dSnw #define	_IDMAP_HANDLE_RPC_DOORS		1
44c5c4113dSnw 
45c5c4113dSnw #define	_IDMAP_GET_CLIENT_HANDLE(h, clnt) \
46c5c4113dSnw 		if (h == NULL) \
47c5c4113dSnw 			return (IDMAP_ERR_CLIENT_HANDLE);\
48c5c4113dSnw 		if (h->type != _IDMAP_HANDLE_RPC_DOORS) \
49c5c4113dSnw 			return (IDMAP_ERR_NOTSUPPORTED);\
50c5c4113dSnw 		clnt = (CLIENT *)h->privhandle;\
51c5c4113dSnw 		if (clnt == NULL)\
52c5c4113dSnw 			return (IDMAP_ERR_RPC_HANDLE);
53c5c4113dSnw 
54c5c4113dSnw struct idmap_handle {
55c5c4113dSnw 	int	type;
56c5c4113dSnw 	void	*privhandle;
57c5c4113dSnw 	/* locks */
58c5c4113dSnw };
59c5c4113dSnw 
60c5c4113dSnw struct idmap_udt_handle {
61c5c4113dSnw 	struct idmap_handle	*ih;
62c5c4113dSnw 	idmap_update_batch	batch;
63c5c4113dSnw 	uint64_t		next;
64*8e228215Sdm 	int64_t			error_index;
65*8e228215Sdm 	idmap_stat		commit_stat;
66*8e228215Sdm 	idmap_namerule		error_rule;
67*8e228215Sdm 	idmap_namerule		conflict_rule;
68c5c4113dSnw };
69c5c4113dSnw 
70651c0131Sbaban #define	_IDMAP_RESET_UDT_HANDLE(uh) \
71651c0131Sbaban 	(void) xdr_free(xdr_idmap_update_batch, (caddr_t)&uh->batch);\
72*8e228215Sdm 	uh->next = 0;\
73*8e228215Sdm 	uh->error_index = -1;\
74*8e228215Sdm 	(void) xdr_free(xdr_idmap_namerule, (caddr_t)&uh->error_rule);\
75*8e228215Sdm 	(void) xdr_free(xdr_idmap_namerule, (caddr_t)&uh->conflict_rule);
76651c0131Sbaban 
77c5c4113dSnw typedef struct idmap_get_res {
78c5c4113dSnw 	idmap_id_type	idtype;
79c5c4113dSnw 	uid_t		*uid;
80c5c4113dSnw 	gid_t		*gid;
81c5c4113dSnw 	int		*is_user;
82c5c4113dSnw 	char		**sidprefix;
83c5c4113dSnw 	idmap_rid_t	*rid;
84c5c4113dSnw 	idmap_stat	*stat;
85c5c4113dSnw } idmap_get_res_t;
86c5c4113dSnw 
87c5c4113dSnw struct idmap_get_handle {
88c5c4113dSnw 	struct idmap_handle	*ih;
89c5c4113dSnw 	idmap_mapping_batch	batch;
90c5c4113dSnw 	idmap_get_res_t		*retlist;
91c5c4113dSnw 	uint64_t		next;
92c5c4113dSnw };
93c5c4113dSnw 
94651c0131Sbaban #define	_IDMAP_RESET_GET_HANDLE(gh) \
95651c0131Sbaban 	(void) xdr_free(xdr_idmap_mapping_batch, (caddr_t)&gh->batch);\
96651c0131Sbaban 	if (gh->retlist) \
97651c0131Sbaban 		free(gh->retlist);\
98651c0131Sbaban 	gh->retlist = NULL;\
99651c0131Sbaban 	gh->next = 0;
100651c0131Sbaban 
101c5c4113dSnw struct idmap_iter {
102c5c4113dSnw 	struct idmap_handle	*ih;
103c5c4113dSnw 	int			type;
104c5c4113dSnw 	uint64_t		limit;
105c5c4113dSnw 	void			*arg;
106c5c4113dSnw 	idmap_retcode		retcode;
107c5c4113dSnw 	uint64_t		lastrowid;
108c5c4113dSnw 	uint64_t		next;
109c5c4113dSnw 	void			*retlist;
110c5c4113dSnw };
111c5c4113dSnw 
112c5c4113dSnw typedef struct stat_table {
113c5c4113dSnw 	idmap_retcode	retcode;
114c5c4113dSnw 	const char	*msg;
115c5c4113dSnw 	int		errnum;
116c5c4113dSnw } stat_table_t;
117c5c4113dSnw 
118c5c4113dSnw typedef idmap_retcode	_idmap_stat;
119c5c4113dSnw 
120651c0131Sbaban extern idmap_retcode	_udt_extend_batch(idmap_udt_handle_t *);
121c5c4113dSnw extern idmap_retcode	_get_ids_extend_batch(idmap_get_handle_t *);
122c5c4113dSnw extern idmap_stat	_iter_get_next_list(int, idmap_iter_t *, void *,
123c5c4113dSnw 				uchar_t **, size_t, xdrproc_t, xdrproc_t);
124651c0131Sbaban extern idmap_stat	_idmap_rpc2stat(CLIENT *);
125c5c4113dSnw 
126c5c4113dSnw #ifdef __cplusplus
127c5c4113dSnw }
128c5c4113dSnw #endif
129c5c4113dSnw 
130c5c4113dSnw #endif /* _IDMAP_IMPL_H */
131