Home | History | Annotate | Download | only in common
      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 2009 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 
     34 #include <libscf.h>
     35 #include <resolv.h>
     36 
     37 #include "idmap.h"
     38 #include <rpcsvc/idmap_prot.h>
     39 
     40 #ifdef __cplusplus
     41 extern "C" {
     42 #endif
     43 
     44 #define	IDMAP_MAX_NAME_LEN	512
     45 
     46 #define	IDMAP_ERROR(rc)		(rc != IDMAP_SUCCESS && rc != IDMAP_NEXT)
     47 #define	IDMAP_FATAL_ERROR(rc)	(rc == IDMAP_ERR_MEMORY ||\
     48 				rc == IDMAP_ERR_DB)
     49 
     50 
     51 /* is_user values */
     52 
     53 #define	IDMAP_YES 1
     54 #define	IDMAP_NO 0
     55 #define	IDMAP_UNKNOWN -1
     56 
     57 #define	CHECK_NULL(s)	(s != NULL ? s : "null")
     58 #define	EMPTY_STRING(str)	(str == NULL || *str == '\0')
     59 
     60 /* Opaque handle to batch config add/remove operations */
     61 typedef struct idmap_udt_handle idmap_udt_handle_t;
     62 
     63 /* Opaque iterator */
     64 typedef struct idmap_iter idmap_iter_t;
     65 
     66 
     67 /*
     68  * Directory based name map API
     69  */
     70 
     71 typedef struct idmap_nm_handle idmap_nm_handle_t;
     72 
     73 /* Set namemap */
     74 extern idmap_stat idmap_set_namemap(idmap_nm_handle_t *, char *, char *,
     75     int, int, int);
     76 
     77 /* Unset namemap */
     78 extern idmap_stat idmap_unset_namemap(idmap_nm_handle_t *, char *, char *,
     79     int, int, int);
     80 
     81 extern idmap_stat idmap_get_namemap(idmap_nm_handle_t *p, int *, char **,
     82     char **, int *, char **,  char **);
     83 
     84 extern void idmap_fini_namemaps(idmap_nm_handle_t *);
     85 
     86 extern idmap_stat idmap_init_namemaps(idmap_handle_t *, idmap_nm_handle_t **,
     87     char *, char *, char *, char *, int);
     88 
     89 
     90 /*
     91  * Update API
     92  */
     93 
     94 /* Create handle for updates */
     95 extern idmap_stat idmap_udt_create(idmap_handle_t *,
     96 	idmap_udt_handle_t **);
     97 
     98 /* Commit */
     99 extern idmap_stat idmap_udt_commit(idmap_udt_handle_t *);
    100 
    101 /* Get index of the failed batch element */
    102 extern idmap_stat idmap_udt_get_error_index(idmap_udt_handle_t *, int64_t *);
    103 
    104 /* Get the rule which caused the batch to failed */
    105 extern idmap_stat idmap_udt_get_error_rule(idmap_udt_handle_t *, char **,
    106     char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
    107 
    108 /* Get the rule which caused a conflict */
    109 extern idmap_stat idmap_udt_get_conflict_rule(idmap_udt_handle_t *, char **,
    110     char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
    111 
    112 /* Destroy the update handle */
    113 extern void idmap_udt_destroy(idmap_udt_handle_t *);
    114 
    115 /* Add name-based mapping rule */
    116 extern idmap_stat idmap_udt_add_namerule(idmap_udt_handle_t *, const char *,
    117 	boolean_t, boolean_t, const char *, const char *, boolean_t, int);
    118 
    119 /* Remove name-based mapping rule */
    120 extern idmap_stat idmap_udt_rm_namerule(idmap_udt_handle_t *, boolean_t,
    121 	boolean_t, const char *, const char *, const char *, int);
    122 
    123 /* Flush name-based mapping rules */
    124 extern idmap_stat idmap_udt_flush_namerules(idmap_udt_handle_t *);
    125 
    126 
    127 /*
    128  * Iterator API
    129  */
    130 
    131 /* Create a iterator to get SID to UID/GID mappings */
    132 extern idmap_stat idmap_iter_mappings(idmap_handle_t *,	idmap_iter_t **,
    133 	int flag);
    134 
    135 /* Iterate through the SID to UID/GID mappings */
    136 extern idmap_stat idmap_iter_next_mapping(idmap_iter_t *, char **,
    137 	idmap_rid_t *, uid_t *, char **, char **, char **, boolean_t *,
    138 	boolean_t *, int *, idmap_info *);
    139 
    140 /* Create a iterator to get name-based mapping rules */
    141 extern idmap_stat idmap_iter_namerules(idmap_handle_t *, const char *,
    142 	boolean_t, boolean_t, const char *, const char *, idmap_iter_t **);
    143 
    144 /* Iterate through the name-based mapping rules */
    145 extern idmap_stat idmap_iter_next_namerule(idmap_iter_t *, char **,
    146 	char **, char **, boolean_t *, boolean_t *, boolean_t *, int *);
    147 
    148 /* Set the number of entries requested per batch */
    149 extern idmap_stat idmap_iter_set_limit(idmap_iter_t *, uint64_t);
    150 
    151 /* Destroy the iterator */
    152 extern void idmap_iter_destroy(idmap_iter_t *);
    153 
    154 
    155 /*
    156  * Get mapping
    157  */
    158 extern idmap_stat idmap_get_w2u_mapping(idmap_handle_t *, const char *,
    159 	idmap_rid_t *, const char *, const char *, int, int *, int *,
    160 	uid_t *, char **, int *, idmap_info *);
    161 
    162 extern idmap_stat idmap_get_u2w_mapping(idmap_handle_t *, uid_t *,
    163 	const char *, int, int, int *, char **, idmap_rid_t *, char **,
    164 	char **, int *, idmap_info *);
    165 
    166 
    167 /*
    168  * Miscellaneous
    169  */
    170 
    171 /* string to status */
    172 extern idmap_stat idmap_string2stat(const char *);
    173 
    174 /* internal status to protocol status */
    175 extern idmap_stat idmap_stat4prot(idmap_stat);
    176 
    177 /* copy idmap_namerule including strings */
    178 extern idmap_stat idmap_namerule_cpy(idmap_namerule *, idmap_namerule *);
    179 
    180 /* copy idmap_info info including strings */
    181 extern idmap_stat idmap_info_cpy(idmap_info *to, idmap_info *from);
    182 
    183 /* Move  idmap_info info including strings */
    184 extern idmap_stat idmap_info_mov(idmap_info *to, idmap_info *from);
    185 
    186 /* free idmap_info info from  user supplied struct */
    187 extern void idmap_info_free(idmap_info *);
    188 
    189 
    190 /*
    191  * Extended API to batch SID to UID/GID mapping requests
    192  */
    193 
    194 /* Given SID, get UID */
    195 extern idmap_stat idmap_getext_uidbysid(idmap_get_handle_t *, char *,
    196 	idmap_rid_t, int, uid_t *, idmap_info *, idmap_stat *);
    197 
    198 /* Given SID, get GID */
    199 extern idmap_stat idmap_getext_gidbysid(idmap_get_handle_t *, char *,
    200 	idmap_rid_t, int, gid_t *, idmap_info *, idmap_stat *);
    201 
    202 /* Given SID, get UID or GID */
    203 extern idmap_stat idmap_getext_pidbysid(idmap_get_handle_t *, char *,
    204 	idmap_rid_t, int, uid_t *, int *, idmap_info *, idmap_stat *);
    205 
    206 /* Given UID, get SID */
    207 extern idmap_stat idmap_getext_sidbyuid(idmap_get_handle_t *, uid_t, int,
    208 	char **, idmap_rid_t *, idmap_info *, idmap_stat *);
    209 
    210 /* Given GID, get SID */
    211 extern idmap_stat idmap_getext_sidbygid(idmap_get_handle_t *, gid_t, int,
    212 	char **, idmap_rid_t *, idmap_info *, idmap_stat *);
    213 
    214 
    215 #ifdef __cplusplus
    216 }
    217 #endif
    218 
    219 #endif /* _IDMAP_PRIV_H */
    220