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.
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.
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]
22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
26 %#include <sys/nvpair.h>
28 %#include <libnvpair.h>
32 * XDR support for nvlist_t. libnvpair includes support for serializing
33 * an nvlist, but does not include any direct XDR plug-in support. Support
34 * is made trickier by the fact that on read xdr_pointer() wants to allocate
35 * structures on its own, even when there's a custom xdr_*() function for
36 * the structure. nvlist_unpack *also* wants to allocate the nvlist_t,
37 * and it seems wrong to burn sizeof(nvlist_t) into the program binary.
39 * Another possibility is to use opaque<> in this declaration, but that
40 * requires moving part of the encoding (the interaction with nvlist_pack
41 * and nvlist_unpack) out into the application, instead of keeping it
42 * all encapsulated in this layer.
44 * The resolution here is to put an nvlist_t * into a new typedef, and have
45 * *that* typedef have a custom xdr_*() function. xdr allocates space for
46 * the pointer, but leaves all initialization of it nvlist_t *) to the
50 %typedef nvlist_t *nvlist_t_ptr;
54 %#if !defined(_KERNEL)
60 %xdr_nvlist_t_ptr(XDR *xdrs, nvlist_t_ptr *n)
69 % switch (xdrs->x_op) {
71 % if (!xdr_bool(xdrs, &present))
78 % if (!xdr_bytes(xdrs, &buf, &len, ~0))
81 % err = nvlist_unpack(buf, (size_t)len, n, 0);
83 % kmem_free(buf, len);
89 %#if !defined(_KERNEL)
90 % fprintf(stderr, "xdr_nvlist_t unpack: %s\n",
98 % present = (*n != NULL);
99 % if (!xdr_bool(xdrs, &present))
104 % err = nvlist_pack(*n, &buf, &sz, NV_ENCODE_XDR, 0);
106 %#if !defined(_KERNEL)
107 % fprintf(stderr, "xdr_nvlist_t pack: %s\n",
113 % /* nvlist_pack() and xdr_bytes() want different types */
116 % ret = xdr_bytes(xdrs, &buf, &len, ~0);
117 %#if defined(_KERNEL)
118 % kmem_free(buf, len);
138 /* opaque type to support non-ASCII strings */
139 typedef string idmap_utf8str<>;
140 typedef idmap_utf8str idmap_utf8str_list<>;
143 typedef int idmap_retcode;
156 /* The type of ID mapping */
157 enum idmap_map_type {
158 IDMAP_MAP_TYPE_UNKNOWN = 0,
159 IDMAP_MAP_TYPE_DS_AD,
160 IDMAP_MAP_TYPE_DS_NLDAP,
161 IDMAP_MAP_TYPE_RULE_BASED,
162 IDMAP_MAP_TYPE_EPHEMERAL,
163 IDMAP_MAP_TYPE_LOCAL_SID,
164 IDMAP_MAP_TYPE_KNOWN_SID,
169 /* Source of ID mapping */
171 IDMAP_MAP_SRC_UNKNOWN = 0,
174 IDMAP_MAP_SRC_HARD_CODED,
175 IDMAP_MAP_SRC_ALGORITHMIC
185 /* Identity (sid-posix) */
186 union idmap_id switch(idmap_id_type idtype) {
187 case IDMAP_UID: uint32_t uid;
188 case IDMAP_GID: uint32_t gid;
189 case IDMAP_SID: idmap_sid sid;
190 case IDMAP_USID: idmap_sid usid;
191 case IDMAP_GSID: idmap_sid gsid;
192 case IDMAP_NONE: void;
193 case IDMAP_POSIXID: void;
197 /* Name-based mapping rules */
198 struct idmap_namerule {
202 idmap_utf8str windomain;
203 idmap_utf8str winname;
204 idmap_utf8str unixname;
207 struct idmap_namerules_res {
208 idmap_retcode retcode;
210 idmap_namerule rules<>;
213 /* How ID is mapped */
214 struct idmap_how_ds_based {
220 union idmap_how switch(idmap_map_type map_type) {
221 case IDMAP_MAP_TYPE_UNKNOWN: void;
222 case IDMAP_MAP_TYPE_DS_AD: idmap_how_ds_based ad;
223 case IDMAP_MAP_TYPE_DS_NLDAP: idmap_how_ds_based nldap;
224 case IDMAP_MAP_TYPE_RULE_BASED: idmap_namerule rule;
225 case IDMAP_MAP_TYPE_EPHEMERAL: void;
226 case IDMAP_MAP_TYPE_LOCAL_SID: void;
227 case IDMAP_MAP_TYPE_KNOWN_SID: void;
228 case IDMAP_MAP_TYPE_IDMU: idmap_how_ds_based idmu;
239 struct idmap_id_res {
240 idmap_retcode retcode;
245 struct idmap_ids_res {
246 idmap_retcode retcode;
252 * Flag supported by mapping requests
255 /* Don't allocate a new value for the mapping */
256 const IDMAP_REQ_FLG_NO_NEW_ID_ALLOC = 0x00000001;
258 /* Validate the given identity before mapping */
259 const IDMAP_REQ_FLG_VALIDATE = 0x00000002;
261 /* Avoid name service lookups to prevent looping */
262 const IDMAP_REQ_FLG_NO_NAMESERVICE = 0x00000004;
264 /* Request how a mapping was formed */
265 const IDMAP_REQ_FLG_MAPPING_INFO = 0x00000008;
268 * This libidmap only flag is defined in idmap.h
269 * It enables use of the libidmap cache
270 * const IDMAP_REQ_FLG_USE_CACHE = 0x00000010;
273 /* Request mapping for well-known or local SIDs only */
274 const IDMAP_REQ_FLG_WK_OR_LOCAL_SIDS_ONLY = 0x00000020;
276 /* Request trace of mapping process */
277 const IDMAP_REQ_FLG_TRACE = 0x00000040;
281 * Mapping direction definitions
283 const IDMAP_DIRECTION_UNDEF = -1; /* not defined */
284 const IDMAP_DIRECTION_BI = 0; /* bi-directional */
285 const IDMAP_DIRECTION_W2U = 1; /* windows to unix only */
286 const IDMAP_DIRECTION_U2W = 2; /* unix to windows only */
289 /* Identity mappings (sid-posix) */
290 struct idmap_mapping {
294 idmap_utf8str id1domain;
295 idmap_utf8str id1name;
297 idmap_utf8str id2domain;
298 idmap_utf8str id2name;
302 typedef idmap_mapping idmap_mapping_batch<>;
304 #ifndef IDMAP_XDR_MAPPING_ONLY
305 struct idmap_mappings_res {
306 idmap_retcode retcode;
308 idmap_mapping mappings<>;
313 struct idmap_update_res {
314 idmap_retcode retcode;
316 idmap_namerule error_rule;
317 idmap_namerule conflict_rule;
320 /* Update requests */
325 OP_FLUSH_NAMERULES = 3
327 union idmap_update_op switch(idmap_opnum opnum) {
328 case OP_ADD_NAMERULE:
334 typedef idmap_update_op idmap_update_batch<>;
336 const AD_DISC_MAXHOSTNAME = 256;
338 struct idmap_ad_disc_ds_t {
342 char host[AD_DISC_MAXHOSTNAME];
346 /* get-prop, set-prop */
347 enum idmap_prop_type {
349 PROP_LIST_SIZE_LIMIT = 1,
350 PROP_DEFAULT_DOMAIN = 2, /* default domain name */
351 PROP_DOMAIN_NAME = 3, /* AD domain name */
352 PROP_MACHINE_SID = 4, /* machine sid */
353 PROP_DOMAIN_CONTROLLER = 5, /* domain controller hosts */
354 PROP_FOREST_NAME = 6, /* forest name */
355 PROP_SITE_NAME = 7, /* site name */
356 PROP_GLOBAL_CATALOG = 8, /* global catalog hosts */
357 PROP_AD_UNIXUSER_ATTR = 9,
358 PROP_AD_UNIXGROUP_ATTR = 10,
359 PROP_NLDAP_WINNAME_ATTR = 11,
360 PROP_DIRECTORY_BASED_MAPPING = 12
363 union idmap_prop_val switch(idmap_prop_type prop) {
364 case PROP_LIST_SIZE_LIMIT:
366 case PROP_DEFAULT_DOMAIN:
367 case PROP_DOMAIN_NAME:
368 case PROP_MACHINE_SID:
369 case PROP_FOREST_NAME:
371 case PROP_AD_UNIXUSER_ATTR:
372 case PROP_AD_UNIXGROUP_ATTR:
373 case PROP_NLDAP_WINNAME_ATTR:
374 case PROP_DIRECTORY_BASED_MAPPING:
375 idmap_utf8str utf8val;
376 case PROP_DOMAIN_CONTROLLER:
377 case PROP_GLOBAL_CATALOG:
378 idmap_ad_disc_ds_t dsval;
383 struct idmap_prop_res {
384 idmap_retcode retcode;
385 idmap_prop_val value;
386 bool auto_discovered;
389 enum idmap_flush_op {
390 IDMAP_FLUSH_EXPIRE = 0,
391 IDMAP_FLUSH_DELETE = 1
395 * Represents an error from the directory lookup service.
397 * code is an ASCII string that is a key for the error. It is not
400 * fmt is a format string with %n markers for where to include
401 * params[n-1]. It should be, but NEEDSWORK is not localized to
402 * the caller's locale.
404 * params is a list of parameters for the error - e.g. the name that
405 * encountered a failure, the server that reported the failure, et cetera.
406 * The values are to be used both as marked in fmt and for machine
407 * interpretation of the error.
409 struct directory_error_rpc {
412 idmap_utf8str params<>;
416 * One value of a multivalued attribute.
418 typedef opaque directory_value_rpc<>;
421 * The value of an attribute, if found. Note that this is a list
422 * of directory_value_rpc objects, to support multivalued attributes.
424 union directory_values_rpc switch (bool found) {
426 directory_value_rpc values<>;
432 * The status of the lookup for any particular identifier.
434 enum directory_lookup_status_rpc {
435 DIRECTORY_NOT_FOUND = 0,
441 * This is the data returned for a particular identifier, either a
442 * list of attribute values or an error.
444 union directory_entry_rpc switch (directory_lookup_status_rpc status) {
445 case DIRECTORY_NOT_FOUND:
447 case DIRECTORY_FOUND:
448 directory_values_rpc attrs<>;
449 case DIRECTORY_ERROR:
450 directory_error_rpc err;
454 * This is the result from a request, either a list of the entries for
455 * the identifiers specified, or an error.
457 union directory_results_rpc switch (bool failed) {
459 directory_error_rpc err;
461 directory_entry_rpc entries<>;
463 #endif /* IDMAP_XDR_MAPPING_ONLY */
467 #ifndef IDMAP_XDR_MAPPING_ONLY
469 IDMAP_NULL(void) = 0;
470 #endif /* IDMAP_XDR_MAPPING_ONLY */
472 /* Batch of requests to get mapped identities */
474 IDMAP_GET_MAPPED_IDS(idmap_mapping_batch batch) = 1;
476 #ifndef IDMAP_XDR_MAPPING_ONLY
477 /* List all identity mappings */
479 IDMAP_LIST_MAPPINGS(int64_t lastrowid,
480 uint64_t limit, int32_t flag) = 2;
482 /* List all name-based mapping rules */
484 IDMAP_LIST_NAMERULES(idmap_namerule rule,
485 uint64_t lastrowid, uint64_t limit) = 3;
487 /* Batch of update requests */
489 IDMAP_UPDATE(idmap_update_batch batch) = 4;
491 /* Get mapped identity by name */
493 IDMAP_GET_MAPPED_ID_BY_NAME(idmap_mapping request) = 5;
495 /* Get configuration property */
497 IDMAP_GET_PROP(idmap_prop_type) = 6;
500 * Retrieve directory information about a list of users
501 * or groups by name or SID.
503 * ids is a list of user names, group names, or SIDs.
505 * types is a list of types of the ids in the id list.
506 * If the type list is shorter than the id list, the last
507 * type listed applies to all of the ids from that point.
508 * The defined types are:
509 * 'n' - name (could be user or group)
514 * attrs is a list of attribute names to retrieve.
516 directory_results_rpc DIRECTORY_GET_COMMON(
517 idmap_utf8str_list ids,
519 idmap_utf8str_list attrs) = 7;
522 IDMAP_FLUSH(idmap_flush_op) = 8;
523 #endif /* IDMAP_XDR_MAPPING_ONLY */