summaryrefslogtreecommitdiff
path: root/usr/src/lib/libidmap/common/idmap_priv.h
blob: e08bd732f3e32cc3e33a6248d3cb49fb8c65904f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * Additional API for Identity Mapping Service
 */

#ifndef _IDMAP_PRIV_H
#define	_IDMAP_PRIV_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <libscf.h>
#include <syslog.h>
#include <resolv.h>

#include "idmap.h"
#include "idmap_prot.h"

#ifdef __cplusplus
extern "C" {
#endif

#define	IDMAP_MAX_NAME_LEN	512

#define	IDMAP_ERROR(rc)		(rc != IDMAP_SUCCESS && rc != IDMAP_NEXT)
#define	IDMAP_FATAL_ERROR(rc)	(rc == IDMAP_ERR_MEMORY ||\
				rc == IDMAP_ERR_DB)


/* is_user values */

#define	IDMAP_YES 1
#define	IDMAP_NO 0
#define	IDMAP_UNKNOWN -1

#define	CHECK_NULL(s)	(s != NULL ? s : "null")
#define	EMPTY_STRING(str)	(str == NULL || *str == '\0')

/* Opaque handle to batch config add/remove operations */
typedef struct idmap_udt_handle idmap_udt_handle_t;

/* Opaque iterator */
typedef struct idmap_iter idmap_iter_t;


/*
 * Directory based name map API
 */

typedef struct idmap_nm_handle idmap_nm_handle_t;

/* Set namemap */
extern idmap_stat idmap_set_namemap(idmap_nm_handle_t *, char *, char *,
    int, int, int);

/* Unset namemap */
extern idmap_stat idmap_unset_namemap(idmap_nm_handle_t *, char *, char *,
    int, int, int);

extern idmap_stat idmap_get_namemap(idmap_nm_handle_t *p, int *, char **,
    char **, int *, char **,  char **);

extern void idmap_fini_namemaps(idmap_nm_handle_t *);

extern idmap_stat idmap_init_namemaps(idmap_handle_t *, idmap_nm_handle_t **,
    char *, char *, char *, char *, int);


/*
 * Update API
 */

/* Create handle for updates */
extern idmap_stat idmap_udt_create(idmap_handle_t *,
	idmap_udt_handle_t **);

/* Commit */
extern idmap_stat idmap_udt_commit(idmap_udt_handle_t *);

/* Get index of the failed batch element */
extern idmap_stat idmap_udt_get_error_index(idmap_udt_handle_t *, int64_t *);

/* Get the rule which caused the batch to failed */
extern idmap_stat idmap_udt_get_error_rule(idmap_udt_handle_t *, char **,
    char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);

/* Get the rule which caused a conflict */
extern idmap_stat idmap_udt_get_conflict_rule(idmap_udt_handle_t *, char **,
    char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);

/* Destroy the update handle */
extern void idmap_udt_destroy(idmap_udt_handle_t *);

/* Add name-based mapping rule */
extern idmap_stat idmap_udt_add_namerule(idmap_udt_handle_t *, const char *,
	boolean_t, boolean_t, const char *, const char *, boolean_t, int);

/* Remove name-based mapping rule */
extern idmap_stat idmap_udt_rm_namerule(idmap_udt_handle_t *, boolean_t,
	boolean_t, const char *, const char *, const char *, int);

/* Flush name-based mapping rules */
extern idmap_stat idmap_udt_flush_namerules(idmap_udt_handle_t *);


/*
 * Iterator API
 */

/* Create a iterator to get SID to UID/GID mappings */
extern idmap_stat idmap_iter_mappings(idmap_handle_t *,	idmap_iter_t **,
	int flag);

/* Iterate through the SID to UID/GID mappings */
extern idmap_stat idmap_iter_next_mapping(idmap_iter_t *, char **,
	idmap_rid_t *, uid_t *, char **, char **, char **, boolean_t *,
	boolean_t *, int *, idmap_info *);

/* Create a iterator to get name-based mapping rules */
extern idmap_stat idmap_iter_namerules(idmap_handle_t *, const char *,
	boolean_t, boolean_t, const char *, const char *, idmap_iter_t **);

/* Iterate through the name-based mapping rules */
extern idmap_stat idmap_iter_next_namerule(idmap_iter_t *, char **,
	char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);

/* Set the number of entries requested per batch */
extern idmap_stat idmap_iter_set_limit(idmap_iter_t *, uint64_t);

/* Destroy the iterator */
extern void idmap_iter_destroy(idmap_iter_t *);


/*
 * Get mapping
 */
extern idmap_stat idmap_get_w2u_mapping(idmap_handle_t *, const char *,
	idmap_rid_t *, const char *, const char *, int, int *, int *,
	uid_t *, char **, int *, idmap_info *);

extern idmap_stat idmap_get_u2w_mapping(idmap_handle_t *, uid_t *,
	const char *, int, int, int *, char **, idmap_rid_t *, char **,
	char **, int *, idmap_info *);


/*
 * Miscellaneous
 */

/* string to status */
extern idmap_stat idmap_string2stat(const char *);

/* internal status to protocol status */
extern idmap_stat idmap_stat4prot(idmap_stat);

/* copy idmap_namerule including strings */
extern idmap_stat idmap_namerule_cpy(idmap_namerule *, idmap_namerule *);

/* copy idmap_info info including strings */
extern idmap_stat idmap_info_cpy(idmap_info *to, idmap_info *from);

/* Move  idmap_info info including strings */
extern idmap_stat idmap_info_mov(idmap_info *to, idmap_info *from);

/* free idmap_info info from  user supplied struct */
extern void idmap_info_free(idmap_info *);


/*
 * Extended API to batch SID to UID/GID mapping requests
 */

/* Given SID, get UID */
extern idmap_stat idmap_getext_uidbysid(idmap_get_handle_t *, char *,
	idmap_rid_t, int, uid_t *, idmap_info *, idmap_stat *);

/* Given SID, get GID */
extern idmap_stat idmap_getext_gidbysid(idmap_get_handle_t *, char *,
	idmap_rid_t, int, gid_t *, idmap_info *, idmap_stat *);

/* Given SID, get UID or GID */
extern idmap_stat idmap_getext_pidbysid(idmap_get_handle_t *, char *,
	idmap_rid_t, int, uid_t *, int *, idmap_info *, idmap_stat *);

/* Given UID, get SID */
extern idmap_stat idmap_getext_sidbyuid(idmap_get_handle_t *, uid_t, int,
	char **, idmap_rid_t *, idmap_info *, idmap_stat *);

/* Given GID, get SID */
extern idmap_stat idmap_getext_sidbygid(idmap_get_handle_t *, gid_t, int,
	char **, idmap_rid_t *, idmap_info *, idmap_stat *);



/* logging */
extern void idmapdlog(int, const char *, ...);

/*
 * The maximal priority to be logged to stderr: set to -1 to suppress
 * stderr logging completely.
 */
extern void idmap_log_stderr(int);

/* write log messages to syslog? */
extern void idmap_log_syslog(bool_t);

/* write log messages to syslog? */
extern void idmap_log_degraded(bool_t);

#ifdef __cplusplus
}
#endif

#endif /* _IDMAP_PRIV_H */