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. 23ad8ef92aSMilan Jurik * Copyright Milan Jurik 2012. All rights reserved. 248ce3a038SMarcel Telka * Copyright 2014 Nexenta Systems, Inc. All rights reserved. 25*29d55245SJerry Jelinek * Copyright 2015 Joyent, Inc. 26c5c4113dSnw141292 */ 27c5c4113dSnw141292 28c5c4113dSnw141292 29c5c4113dSnw141292 /* 30c5c4113dSnw141292 * libidmap API 31c5c4113dSnw141292 */ 32c5c4113dSnw141292 33c5c4113dSnw141292 #include <stdlib.h> 34479ac375Sdm199847 #include <sys/varargs.h> 35c5c4113dSnw141292 #include <inttypes.h> 36c5c4113dSnw141292 #include <errno.h> 37c5c4113dSnw141292 #include <strings.h> 38c5c4113dSnw141292 #include <ctype.h> 39c5c4113dSnw141292 #include <sys/param.h> 40c5c4113dSnw141292 #include <sys/types.h> 41c5c4113dSnw141292 #include <sys/stat.h> 42c5c4113dSnw141292 #include <dlfcn.h> 43c5c4113dSnw141292 #include <libintl.h> 44c5866007SKeyur Desai #include <syslog.h> 45148c5f43SAlan Wright #include <assert.h> 46c5c4113dSnw141292 #include "idmap_impl.h" 473ee87bcaSJulian Pullen #include "idmap_cache.h" 48c5c4113dSnw141292 49c5c4113dSnw141292 static struct timeval TIMEOUT = { 25, 0 }; 50c5c4113dSnw141292 51c5c4113dSnw141292 static int idmap_stat2errno(idmap_stat); 528e228215Sdm199847 static idmap_stat idmap_strdupnull(char **, const char *); 53c5c4113dSnw141292 541fdeec65Sjoyce mcintosh #define __ITER_CREATE(itera, argu, ityp)\ 55c5c4113dSnw141292 itera = calloc(1, sizeof (*itera));\ 56c5c4113dSnw141292 if (itera == NULL) {\ 57c5c4113dSnw141292 errno = ENOMEM;\ 58c5c4113dSnw141292 return (IDMAP_ERR_MEMORY);\ 59c5c4113dSnw141292 }\ 60c5c4113dSnw141292 argu = calloc(1, sizeof (*argu));\ 61c5c4113dSnw141292 if (argu == NULL) {\ 62c5c4113dSnw141292 free(itera);\ 63c5c4113dSnw141292 errno = ENOMEM;\ 64c5c4113dSnw141292 return (IDMAP_ERR_MEMORY);\ 65c5c4113dSnw141292 }\ 66c5c4113dSnw141292 itera->type = ityp;\ 67c5c4113dSnw141292 itera->retcode = IDMAP_NEXT;\ 68c5c4113dSnw141292 itera->limit = 1024;\ 69c5c4113dSnw141292 itera->arg = argu; 70c5c4113dSnw141292 71c5c4113dSnw141292 #define __ITER_CHECK(itera, ityp)\ 72c5c4113dSnw141292 if (itera == NULL) {\ 73c5c4113dSnw141292 errno = EINVAL;\ 74c5c4113dSnw141292 return (IDMAP_ERR_ARG);\ 75c5c4113dSnw141292 }\ 76c5c4113dSnw141292 if (itera->type != ityp) {\ 77c5c4113dSnw141292 errno = EINVAL;\ 78c5c4113dSnw141292 return (IDMAP_ERR_ARG);\ 79c5c4113dSnw141292 } 80c5c4113dSnw141292 81c5c4113dSnw141292 /* 82c5c4113dSnw141292 * Free memory allocated by libidmap API 83c5c4113dSnw141292 * 84c5c4113dSnw141292 * Input: 85c5c4113dSnw141292 * ptr - memory to be freed 86c5c4113dSnw141292 */ 87c5c4113dSnw141292 void 88cd37da74Snw141292 idmap_free(void *ptr) 89cd37da74Snw141292 { 90c5c4113dSnw141292 free(ptr); 91c5c4113dSnw141292 } 92c5c4113dSnw141292 93c5c4113dSnw141292 944d61c878SJulian Pullen static idmap_stat 951fdeec65Sjoyce mcintosh idmap_get_prop(idmap_prop_type pr, idmap_prop_res *res) 96479ac375Sdm199847 { 971fdeec65Sjoyce mcintosh idmap_stat retcode; 98479ac375Sdm199847 99479ac375Sdm199847 (void) memset(res, 0, sizeof (*res)); 100479ac375Sdm199847 1011fdeec65Sjoyce mcintosh retcode = _idmap_clnt_call(IDMAP_GET_PROP, 102479ac375Sdm199847 (xdrproc_t)xdr_idmap_prop_type, (caddr_t)&pr, 103479ac375Sdm199847 (xdrproc_t)xdr_idmap_prop_res, (caddr_t)res, TIMEOUT); 1041fdeec65Sjoyce mcintosh if (retcode != IDMAP_SUCCESS) 1051fdeec65Sjoyce mcintosh return (retcode); 106479ac375Sdm199847 107479ac375Sdm199847 return (res->retcode); /* This might not be IDMAP_SUCCESS! */ 108479ac375Sdm199847 } 109479ac375Sdm199847 110479ac375Sdm199847 111479ac375Sdm199847 idmap_stat 1121fdeec65Sjoyce mcintosh idmap_get_prop_ds(idmap_prop_type pr, idmap_ad_disc_ds_t *dc) 113479ac375Sdm199847 { 114479ac375Sdm199847 idmap_prop_res res; 115479ac375Sdm199847 idmap_stat rc = IDMAP_SUCCESS; 116479ac375Sdm199847 1171fdeec65Sjoyce mcintosh rc = idmap_get_prop(pr, &res); 118479ac375Sdm199847 if (rc < 0) 119479ac375Sdm199847 return (rc); 120479ac375Sdm199847 121479ac375Sdm199847 dc->port = res.value.idmap_prop_val_u.dsval.port; 122479ac375Sdm199847 (void) strlcpy(dc->host, res.value.idmap_prop_val_u.dsval.host, 123479ac375Sdm199847 AD_DISC_MAXHOSTNAME); 124479ac375Sdm199847 125479ac375Sdm199847 /* xdr doesn't guarantee 0-termination of char[]: */ 126479ac375Sdm199847 dc->host[AD_DISC_MAXHOSTNAME - 1] = '\0'; 127479ac375Sdm199847 128479ac375Sdm199847 return (rc); 129479ac375Sdm199847 } 130479ac375Sdm199847 131479ac375Sdm199847 132479ac375Sdm199847 /* 133479ac375Sdm199847 * Sometimes the property is not set. In that case, str is set to NULL but 134479ac375Sdm199847 * otherwise IDMAP_SUCCESS is returned. 135479ac375Sdm199847 */ 136479ac375Sdm199847 idmap_stat 1371fdeec65Sjoyce mcintosh idmap_get_prop_str(idmap_prop_type pr, char **str) 138479ac375Sdm199847 { 139479ac375Sdm199847 idmap_prop_res res; 140479ac375Sdm199847 idmap_stat rc = IDMAP_SUCCESS; 141479ac375Sdm199847 1421fdeec65Sjoyce mcintosh rc = idmap_get_prop(pr, &res); 143479ac375Sdm199847 if (rc < 0) 144479ac375Sdm199847 return (rc); 145479ac375Sdm199847 146479ac375Sdm199847 rc = idmap_strdupnull(str, res.value.idmap_prop_val_u.utf8val); 147479ac375Sdm199847 return (rc); 148479ac375Sdm199847 } 149c5c4113dSnw141292 150c5c4113dSnw141292 /* 151c5c4113dSnw141292 * Create/Initialize handle for updates 152c5c4113dSnw141292 * 153c5c4113dSnw141292 * Output: 154c5c4113dSnw141292 * udthandle - update handle 155c5c4113dSnw141292 */ 156c5c4113dSnw141292 idmap_stat 1571fdeec65Sjoyce mcintosh idmap_udt_create(idmap_udt_handle_t **udthandle) 158cd37da74Snw141292 { 159c5c4113dSnw141292 idmap_udt_handle_t *tmp; 160c5c4113dSnw141292 1611fdeec65Sjoyce mcintosh if (udthandle == NULL) { 162c5c4113dSnw141292 errno = EINVAL; 163c5c4113dSnw141292 return (IDMAP_ERR_ARG); 164c5c4113dSnw141292 } 165c5c4113dSnw141292 if ((tmp = calloc(1, sizeof (*tmp))) == NULL) { 166c5c4113dSnw141292 errno = ENOMEM; 167c5c4113dSnw141292 return (IDMAP_ERR_MEMORY); 168c5c4113dSnw141292 } 169c5c4113dSnw141292 170c5c4113dSnw141292 *udthandle = tmp; 171c5c4113dSnw141292 return (IDMAP_SUCCESS); 172c5c4113dSnw141292 } 173c5c4113dSnw141292 174c5c4113dSnw141292 175c5c4113dSnw141292 /* 176c5c4113dSnw141292 * All the updates specified by the update handle are committed 177c5c4113dSnw141292 * in a single transaction. i.e either all succeed or none. 178c5c4113dSnw141292 * 179c5c4113dSnw141292 * Input: 180c5c4113dSnw141292 * udthandle - update handle with the update requests 181c5c4113dSnw141292 * 182c5c4113dSnw141292 * Return value: 183c5c4113dSnw141292 * Status of the commit 184c5c4113dSnw141292 */ 185c5c4113dSnw141292 idmap_stat 186cd37da74Snw141292 idmap_udt_commit(idmap_udt_handle_t *udthandle) 187cd37da74Snw141292 { 1888e228215Sdm199847 idmap_update_res res; 1898e228215Sdm199847 idmap_stat retcode; 190c5c4113dSnw141292 191c5c4113dSnw141292 if (udthandle == NULL) { 192c5c4113dSnw141292 errno = EINVAL; 193c5c4113dSnw141292 return (IDMAP_ERR_ARG); 194c5c4113dSnw141292 } 1958e228215Sdm199847 1968e228215Sdm199847 (void) memset(&res, 0, sizeof (res)); 1978e228215Sdm199847 1981fdeec65Sjoyce mcintosh retcode = _idmap_clnt_call(IDMAP_UPDATE, 199c5c4113dSnw141292 (xdrproc_t)xdr_idmap_update_batch, (caddr_t)&udthandle->batch, 2008e228215Sdm199847 (xdrproc_t)xdr_idmap_update_res, (caddr_t)&res, 201c5c4113dSnw141292 TIMEOUT); 2021fdeec65Sjoyce mcintosh if (retcode != IDMAP_SUCCESS) 2038e228215Sdm199847 goto out; 204651c0131Sbaban 2058e228215Sdm199847 retcode = udthandle->commit_stat = res.retcode; 2068e228215Sdm199847 udthandle->error_index = res.error_index; 2078e228215Sdm199847 2088e228215Sdm199847 if (retcode != IDMAP_SUCCESS) { 2098e228215Sdm199847 2108e228215Sdm199847 if (udthandle->error_index < 0) 2118e228215Sdm199847 goto out; 2128e228215Sdm199847 2138e228215Sdm199847 retcode = idmap_namerule_cpy(&udthandle->error_rule, 2148e228215Sdm199847 &res.error_rule); 2158e228215Sdm199847 if (retcode != IDMAP_SUCCESS) { 2168e228215Sdm199847 udthandle->error_index = -2; 2178e228215Sdm199847 goto out; 2188e228215Sdm199847 } 2198e228215Sdm199847 2208e228215Sdm199847 retcode = idmap_namerule_cpy(&udthandle->conflict_rule, 2218e228215Sdm199847 &res.conflict_rule); 2228e228215Sdm199847 if (retcode != IDMAP_SUCCESS) { 2238e228215Sdm199847 udthandle->error_index = -2; 2248e228215Sdm199847 goto out; 2258e228215Sdm199847 } 2268e228215Sdm199847 } 2278e228215Sdm199847 2288e228215Sdm199847 retcode = res.retcode; 2298e228215Sdm199847 2308e228215Sdm199847 2318e228215Sdm199847 out: 2328e228215Sdm199847 /* reset handle so that it can be used again */ 2338e228215Sdm199847 if (retcode == IDMAP_SUCCESS) { 2348e228215Sdm199847 _IDMAP_RESET_UDT_HANDLE(udthandle); 2358e228215Sdm199847 } 2368e228215Sdm199847 2378e228215Sdm199847 (void) xdr_free(xdr_idmap_update_res, (caddr_t)&res); 238c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 239c5c4113dSnw141292 return (retcode); 240c5c4113dSnw141292 } 241c5c4113dSnw141292 242c5c4113dSnw141292 2438e228215Sdm199847 static void 2448e228215Sdm199847 idmap_namerule_parts_clear(char **windomain, char **winname, 245cd37da74Snw141292 char **unixname, boolean_t *is_user, boolean_t *is_wuser, 246cd37da74Snw141292 boolean_t *is_nt4, int *direction) 247cd37da74Snw141292 { 2488e228215Sdm199847 if (windomain) 2498e228215Sdm199847 *windomain = NULL; 2508e228215Sdm199847 if (winname) 2518e228215Sdm199847 *winname = NULL; 2528e228215Sdm199847 if (unixname) 2538e228215Sdm199847 *unixname = NULL; 2548e228215Sdm199847 2558e228215Sdm199847 if (is_nt4) 2568e228215Sdm199847 *is_nt4 = 0; 2578e228215Sdm199847 if (is_user) 2588e228215Sdm199847 *is_user = -1; 259cd37da74Snw141292 if (is_wuser) 260cd37da74Snw141292 *is_wuser = -1; 2618e228215Sdm199847 if (direction) 2628e228215Sdm199847 *direction = IDMAP_DIRECTION_UNDEF; 2638e228215Sdm199847 } 2648e228215Sdm199847 2658e228215Sdm199847 static idmap_stat 2668e228215Sdm199847 idmap_namerule2parts(idmap_namerule *rule, 2678e228215Sdm199847 char **windomain, char **winname, 268cd37da74Snw141292 char **unixname, boolean_t *is_user, boolean_t *is_wuser, 269cd37da74Snw141292 boolean_t *is_nt4, int *direction) 270cd37da74Snw141292 { 2718e228215Sdm199847 idmap_stat retcode; 2728e228215Sdm199847 2738e228215Sdm199847 if (EMPTY_STRING(rule->winname) && EMPTY_STRING(rule->unixname)) 2748e228215Sdm199847 return (IDMAP_ERR_NORESULT); 2758e228215Sdm199847 2768e228215Sdm199847 2778e228215Sdm199847 retcode = idmap_strdupnull(windomain, rule->windomain); 2788e228215Sdm199847 if (retcode != IDMAP_SUCCESS) 2798e228215Sdm199847 goto errout; 2808e228215Sdm199847 2818e228215Sdm199847 retcode = idmap_strdupnull(winname, rule->winname); 2828e228215Sdm199847 if (retcode != IDMAP_SUCCESS) 2838e228215Sdm199847 goto errout; 2848e228215Sdm199847 2858e228215Sdm199847 retcode = idmap_strdupnull(unixname, rule->unixname); 2868e228215Sdm199847 if (retcode != IDMAP_SUCCESS) 2878e228215Sdm199847 goto errout; 2888e228215Sdm199847 2898e228215Sdm199847 2908e228215Sdm199847 if (is_user) 2918e228215Sdm199847 *is_user = rule->is_user; 292cd37da74Snw141292 if (is_wuser) 293cd37da74Snw141292 *is_wuser = rule->is_wuser; 2948e228215Sdm199847 if (is_nt4) 2958e228215Sdm199847 *is_nt4 = rule->is_nt4; 2968e228215Sdm199847 if (direction) 2978e228215Sdm199847 *direction = rule->direction; 2988e228215Sdm199847 2998e228215Sdm199847 3008e228215Sdm199847 return (IDMAP_SUCCESS); 3018e228215Sdm199847 3028e228215Sdm199847 errout: 3038e228215Sdm199847 if (windomain && *windomain) 3048e228215Sdm199847 free(*windomain); 3058e228215Sdm199847 if (winname && *winname) 3068e228215Sdm199847 free(*winname); 3078e228215Sdm199847 if (unixname && *unixname) 3088e228215Sdm199847 free(*unixname); 3098e228215Sdm199847 3108e228215Sdm199847 idmap_namerule_parts_clear(windomain, winname, 311cd37da74Snw141292 unixname, is_user, is_wuser, is_nt4, direction); 3128e228215Sdm199847 3138e228215Sdm199847 return (retcode); 3148e228215Sdm199847 3158e228215Sdm199847 } 3168e228215Sdm199847 3178e228215Sdm199847 /* 3188e228215Sdm199847 * Retrieve the index of the failed batch element. error_index == -1 3198e228215Sdm199847 * indicates failure at the beginning, -2 at the end. 3208e228215Sdm199847 * 3218e228215Sdm199847 * If idmap_udt_commit didn't return error, the returned value is undefined. 3228e228215Sdm199847 * 3238e228215Sdm199847 * Return value: 3248e228215Sdm199847 * IDMAP_SUCCESS 3258e228215Sdm199847 */ 3268e228215Sdm199847 3278e228215Sdm199847 idmap_stat 3288e228215Sdm199847 idmap_udt_get_error_index(idmap_udt_handle_t *udthandle, 329cd37da74Snw141292 int64_t *error_index) 330cd37da74Snw141292 { 3318e228215Sdm199847 if (error_index) 3328e228215Sdm199847 *error_index = udthandle->error_index; 3338e228215Sdm199847 3348e228215Sdm199847 return (IDMAP_SUCCESS); 3358e228215Sdm199847 } 3368e228215Sdm199847 3378e228215Sdm199847 3388e228215Sdm199847 /* 3398e228215Sdm199847 * Retrieve the rule which caused the batch to fail. If 3408e228215Sdm199847 * idmap_udt_commit didn't return error or if error_index is < 0, the 3418e228215Sdm199847 * retrieved rule is undefined. 3428e228215Sdm199847 * 3438e228215Sdm199847 * Return value: 3448e228215Sdm199847 * IDMAP_ERR_NORESULT if there is no error rule. 3458e228215Sdm199847 * IDMAP_SUCCESS if the rule was obtained OK. 3468e228215Sdm199847 * other error code (IDMAP_ERR_NOMEMORY etc) 3478e228215Sdm199847 */ 3488e228215Sdm199847 3498e228215Sdm199847 idmap_stat 3508e228215Sdm199847 idmap_udt_get_error_rule(idmap_udt_handle_t *udthandle, 3518e228215Sdm199847 char **windomain, char **winname, 352cd37da74Snw141292 char **unixname, boolean_t *is_user, boolean_t *is_wuser, 353cd37da74Snw141292 boolean_t *is_nt4, int *direction) 354cd37da74Snw141292 { 3558e228215Sdm199847 idmap_namerule_parts_clear(windomain, winname, 356cd37da74Snw141292 unixname, is_user, is_wuser, is_nt4, direction); 3578e228215Sdm199847 3588e228215Sdm199847 if (udthandle->commit_stat == IDMAP_SUCCESS || 3598e228215Sdm199847 udthandle->error_index < 0) 3608e228215Sdm199847 return (IDMAP_ERR_NORESULT); 3618e228215Sdm199847 3628e228215Sdm199847 return (idmap_namerule2parts( 3638e228215Sdm199847 &udthandle->error_rule, 3648e228215Sdm199847 windomain, 3658e228215Sdm199847 winname, 3668e228215Sdm199847 unixname, 3678e228215Sdm199847 is_user, 368cd37da74Snw141292 is_wuser, 3698e228215Sdm199847 is_nt4, 3708e228215Sdm199847 direction)); 3718e228215Sdm199847 } 3728e228215Sdm199847 3738e228215Sdm199847 /* 3748e228215Sdm199847 * Retrieve the rule with which there was a conflict. TODO: retrieve 3758e228215Sdm199847 * the value. 3768e228215Sdm199847 * 3778e228215Sdm199847 * Return value: 3788e228215Sdm199847 * IDMAP_ERR_NORESULT if there is no error rule. 3798e228215Sdm199847 * IDMAP_SUCCESS if the rule was obtained OK. 3808e228215Sdm199847 * other error code (IDMAP_ERR_NOMEMORY etc) 3818e228215Sdm199847 */ 3828e228215Sdm199847 3838e228215Sdm199847 idmap_stat 3848e228215Sdm199847 idmap_udt_get_conflict_rule(idmap_udt_handle_t *udthandle, 3858e228215Sdm199847 char **windomain, char **winname, 386cd37da74Snw141292 char **unixname, boolean_t *is_user, boolean_t *is_wuser, 387cd37da74Snw141292 boolean_t *is_nt4, int *direction) 388cd37da74Snw141292 { 3898e228215Sdm199847 idmap_namerule_parts_clear(windomain, winname, 390cd37da74Snw141292 unixname, is_user, is_wuser, is_nt4, direction); 3918e228215Sdm199847 3928e228215Sdm199847 if (udthandle->commit_stat != IDMAP_ERR_W2U_NAMERULE_CONFLICT && 3938e228215Sdm199847 udthandle->commit_stat != IDMAP_ERR_U2W_NAMERULE_CONFLICT) { 3948e228215Sdm199847 return (IDMAP_ERR_NORESULT); 3958e228215Sdm199847 } 3968e228215Sdm199847 3978e228215Sdm199847 return (idmap_namerule2parts( 3988e228215Sdm199847 &udthandle->conflict_rule, 3998e228215Sdm199847 windomain, 4008e228215Sdm199847 winname, 4018e228215Sdm199847 unixname, 4028e228215Sdm199847 is_user, 403cd37da74Snw141292 is_wuser, 4048e228215Sdm199847 is_nt4, 4058e228215Sdm199847 direction)); 4068e228215Sdm199847 } 4078e228215Sdm199847 4088e228215Sdm199847 409c5c4113dSnw141292 /* 410c5c4113dSnw141292 * Destroy the update handle 411c5c4113dSnw141292 */ 412c5c4113dSnw141292 void 413cd37da74Snw141292 idmap_udt_destroy(idmap_udt_handle_t *udthandle) 414cd37da74Snw141292 { 415c5c4113dSnw141292 if (udthandle == NULL) 416c5c4113dSnw141292 return; 417c5c4113dSnw141292 (void) xdr_free(xdr_idmap_update_batch, (caddr_t)&udthandle->batch); 4188e228215Sdm199847 (void) xdr_free(xdr_idmap_namerule, (caddr_t)&udthandle->error_rule); 4198e228215Sdm199847 (void) xdr_free(xdr_idmap_namerule, (caddr_t)&udthandle->conflict_rule); 420c5c4113dSnw141292 free(udthandle); 421c5c4113dSnw141292 } 422c5c4113dSnw141292 423c5c4113dSnw141292 424c5c4113dSnw141292 idmap_stat 425c5c4113dSnw141292 idmap_udt_add_namerule(idmap_udt_handle_t *udthandle, const char *windomain, 426cd37da74Snw141292 boolean_t is_user, boolean_t is_wuser, const char *winname, 427cd37da74Snw141292 const char *unixname, boolean_t is_nt4, int direction) 428cd37da74Snw141292 { 429c5c4113dSnw141292 idmap_retcode retcode; 430651c0131Sbaban idmap_namerule *rule = NULL; 431c5c4113dSnw141292 432651c0131Sbaban retcode = _udt_extend_batch(udthandle); 433c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 434c5c4113dSnw141292 goto errout; 435c5c4113dSnw141292 436c5c4113dSnw141292 rule = &udthandle->batch. 437c5c4113dSnw141292 idmap_update_batch_val[udthandle->next]. 438c5c4113dSnw141292 idmap_update_op_u.rule; 439c5c4113dSnw141292 rule->is_user = is_user; 440cd37da74Snw141292 rule->is_wuser = is_wuser; 441c5c4113dSnw141292 rule->direction = direction; 442c5c4113dSnw141292 rule->is_nt4 = is_nt4; 4438e228215Sdm199847 4448e228215Sdm199847 retcode = idmap_strdupnull(&rule->windomain, windomain); 445c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 446c5c4113dSnw141292 goto errout; 4478e228215Sdm199847 4488e228215Sdm199847 retcode = idmap_strdupnull(&rule->winname, winname); 449c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 450c5c4113dSnw141292 goto errout; 4518e228215Sdm199847 4528e228215Sdm199847 retcode = idmap_strdupnull(&rule->unixname, unixname); 453c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 454c5c4113dSnw141292 goto errout; 455651c0131Sbaban 456651c0131Sbaban udthandle->batch.idmap_update_batch_val[udthandle->next].opnum = 457651c0131Sbaban OP_ADD_NAMERULE; 458c5c4113dSnw141292 udthandle->next++; 459c5c4113dSnw141292 return (IDMAP_SUCCESS); 460c5c4113dSnw141292 461c5c4113dSnw141292 errout: 462651c0131Sbaban /* The batch should still be usable */ 463651c0131Sbaban if (rule) 464651c0131Sbaban (void) xdr_free(xdr_idmap_namerule, (caddr_t)rule); 465c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 466c5c4113dSnw141292 return (retcode); 467c5c4113dSnw141292 } 468c5c4113dSnw141292 469c5c4113dSnw141292 470c5c4113dSnw141292 /* ARGSUSED */ 471c5c4113dSnw141292 idmap_stat 472c5c4113dSnw141292 idmap_udt_rm_namerule(idmap_udt_handle_t *udthandle, boolean_t is_user, 473cd37da74Snw141292 boolean_t is_wuser, const char *windomain, const char *winname, 474cd37da74Snw141292 const char *unixname, int direction) 475cd37da74Snw141292 { 476c5c4113dSnw141292 idmap_retcode retcode; 477651c0131Sbaban idmap_namerule *rule = NULL; 478c5c4113dSnw141292 479651c0131Sbaban retcode = _udt_extend_batch(udthandle); 480c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 481c5c4113dSnw141292 goto errout; 482c5c4113dSnw141292 483c5c4113dSnw141292 rule = &udthandle->batch. 484c5c4113dSnw141292 idmap_update_batch_val[udthandle->next]. 485c5c4113dSnw141292 idmap_update_op_u.rule; 486c5c4113dSnw141292 rule->is_user = is_user; 487cd37da74Snw141292 rule->is_wuser = is_wuser; 488c5c4113dSnw141292 rule->direction = direction; 4898e228215Sdm199847 4908e228215Sdm199847 retcode = idmap_strdupnull(&rule->windomain, windomain); 491c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 492c5c4113dSnw141292 goto errout; 4938e228215Sdm199847 4948e228215Sdm199847 retcode = idmap_strdupnull(&rule->winname, winname); 495c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 496c5c4113dSnw141292 goto errout; 4978e228215Sdm199847 4988e228215Sdm199847 retcode = idmap_strdupnull(&rule->unixname, unixname); 499c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 500c5c4113dSnw141292 goto errout; 5018e228215Sdm199847 502651c0131Sbaban udthandle->batch.idmap_update_batch_val[udthandle->next].opnum = 503651c0131Sbaban OP_RM_NAMERULE; 504c5c4113dSnw141292 udthandle->next++; 505c5c4113dSnw141292 return (IDMAP_SUCCESS); 506c5c4113dSnw141292 507c5c4113dSnw141292 errout: 508651c0131Sbaban if (rule) 509651c0131Sbaban (void) xdr_free(xdr_idmap_namerule, (caddr_t)rule); 510c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 511c5c4113dSnw141292 return (retcode); 512c5c4113dSnw141292 } 513c5c4113dSnw141292 514c5c4113dSnw141292 515c5c4113dSnw141292 /* ARGSUSED */ 516c5c4113dSnw141292 idmap_stat 517cd37da74Snw141292 idmap_udt_flush_namerules(idmap_udt_handle_t *udthandle) 518cd37da74Snw141292 { 519c5c4113dSnw141292 idmap_retcode retcode; 520c5c4113dSnw141292 521651c0131Sbaban retcode = _udt_extend_batch(udthandle); 522c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 523c5c4113dSnw141292 goto errout; 524c5c4113dSnw141292 525651c0131Sbaban udthandle->batch.idmap_update_batch_val[udthandle->next].opnum = 526651c0131Sbaban OP_FLUSH_NAMERULES; 527c5c4113dSnw141292 udthandle->next++; 528c5c4113dSnw141292 return (IDMAP_SUCCESS); 529c5c4113dSnw141292 530c5c4113dSnw141292 errout: 531c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 532c5c4113dSnw141292 return (retcode); 533c5c4113dSnw141292 } 534c5c4113dSnw141292 535c5c4113dSnw141292 536c5c4113dSnw141292 /* 537c5c4113dSnw141292 * Set the number of entries requested per batch by the iterator 538c5c4113dSnw141292 * 539c5c4113dSnw141292 * Input: 540c5c4113dSnw141292 * iter - iterator 541c5c4113dSnw141292 * limit - number of entries requested per batch 542c5c4113dSnw141292 */ 543c5c4113dSnw141292 idmap_stat 544cd37da74Snw141292 idmap_iter_set_limit(idmap_iter_t *iter, uint64_t limit) 545cd37da74Snw141292 { 546c5c4113dSnw141292 if (iter == NULL) { 547c5c4113dSnw141292 errno = EINVAL; 548c5c4113dSnw141292 return (IDMAP_ERR_ARG); 549c5c4113dSnw141292 } 550c5c4113dSnw141292 iter->limit = limit; 551c5c4113dSnw141292 return (IDMAP_SUCCESS); 552c5c4113dSnw141292 } 553c5c4113dSnw141292 554c5c4113dSnw141292 555c5c4113dSnw141292 /* 556c5c4113dSnw141292 * Create iterator to get name-based mapping rules 557c5c4113dSnw141292 * 558c5c4113dSnw141292 * Input: 559c5c4113dSnw141292 * windomain - Windows domain 560c5c4113dSnw141292 * is_user - user or group rules 561c5c4113dSnw141292 * winname - Windows user or group name 562c5c4113dSnw141292 * unixname - Unix user or group name 563c5c4113dSnw141292 * 564c5c4113dSnw141292 * Output: 565c5c4113dSnw141292 * iter - iterator 566c5c4113dSnw141292 */ 567c5c4113dSnw141292 idmap_stat 5681fdeec65Sjoyce mcintosh idmap_iter_namerules(const char *windomain, 569cd37da74Snw141292 boolean_t is_user, boolean_t is_wuser, const char *winname, 570cd37da74Snw141292 const char *unixname, idmap_iter_t **iter) 571cd37da74Snw141292 { 572c5c4113dSnw141292 573c5c4113dSnw141292 idmap_iter_t *tmpiter; 574c5c4113dSnw141292 idmap_list_namerules_1_argument *arg = NULL; 575c5c4113dSnw141292 idmap_namerule *rule; 576c5c4113dSnw141292 idmap_retcode retcode; 577c5c4113dSnw141292 5781fdeec65Sjoyce mcintosh __ITER_CREATE(tmpiter, arg, IDMAP_LIST_NAMERULES); 579c5c4113dSnw141292 580c5c4113dSnw141292 rule = &arg->rule; 581c5c4113dSnw141292 rule->is_user = is_user; 582cd37da74Snw141292 rule->is_wuser = is_wuser; 583651c0131Sbaban rule->direction = IDMAP_DIRECTION_UNDEF; 5848e228215Sdm199847 5858e228215Sdm199847 retcode = idmap_strdupnull(&rule->windomain, windomain); 5868e228215Sdm199847 if (retcode != IDMAP_SUCCESS) 587c5c4113dSnw141292 goto errout; 5888e228215Sdm199847 5898e228215Sdm199847 retcode = idmap_strdupnull(&rule->winname, winname); 5908e228215Sdm199847 if (retcode != IDMAP_SUCCESS) 591c5c4113dSnw141292 goto errout; 5928e228215Sdm199847 5938e228215Sdm199847 retcode = idmap_strdupnull(&rule->unixname, unixname); 5948e228215Sdm199847 if (retcode != IDMAP_SUCCESS) 595c5c4113dSnw141292 goto errout; 596c5c4113dSnw141292 597c5c4113dSnw141292 *iter = tmpiter; 598c5c4113dSnw141292 return (IDMAP_SUCCESS); 599c5c4113dSnw141292 600c5c4113dSnw141292 errout: 601ad8ef92aSMilan Jurik if (arg) { 602ad8ef92aSMilan Jurik xdr_free(xdr_idmap_list_namerules_1_argument, (char *)arg); 603ad8ef92aSMilan Jurik free(arg); 604ad8ef92aSMilan Jurik } 605ad8ef92aSMilan Jurik if (tmpiter) 606ad8ef92aSMilan Jurik free(tmpiter); 607ad8ef92aSMilan Jurik 608ad8ef92aSMilan Jurik return (retcode); 609c5c4113dSnw141292 } 610c5c4113dSnw141292 611c5c4113dSnw141292 612c5c4113dSnw141292 /* 613c5c4113dSnw141292 * Iterate through the name-based mapping rules 614c5c4113dSnw141292 * 615c5c4113dSnw141292 * Input: 616c5c4113dSnw141292 * iter - iterator 617c5c4113dSnw141292 * 618c5c4113dSnw141292 * Output: 619c5c4113dSnw141292 * windomain - Windows domain 620c5c4113dSnw141292 * winname - Windows user or group name 621c5c4113dSnw141292 * unixname - Unix user or group name 622c5c4113dSnw141292 * is_nt4 - NT4 or AD 623c5c4113dSnw141292 * direction - bi(0), win2unix(1), unix2win(2) 624c5c4113dSnw141292 * 625c5c4113dSnw141292 * Return value: 626c5c4113dSnw141292 * 0 - done 627c5c4113dSnw141292 * 1 - more results available 628c5c4113dSnw141292 * < 0 - error 629c5c4113dSnw141292 */ 630c5c4113dSnw141292 idmap_stat 631c5c4113dSnw141292 idmap_iter_next_namerule(idmap_iter_t *iter, char **windomain, 632cd37da74Snw141292 char **winname, char **unixname, boolean_t *is_user, 633cd37da74Snw141292 boolean_t *is_wuser, boolean_t *is_nt4, int *direction) 634cd37da74Snw141292 { 635c5c4113dSnw141292 idmap_namerules_res *namerules; 636c5c4113dSnw141292 idmap_list_namerules_1_argument *arg; 637c5c4113dSnw141292 idmap_retcode retcode; 638c5c4113dSnw141292 639cd37da74Snw141292 idmap_namerule_parts_clear(windomain, winname, 640cd37da74Snw141292 unixname, is_user, is_wuser, is_nt4, direction); 641cd37da74Snw141292 642c5c4113dSnw141292 643c5c4113dSnw141292 __ITER_CHECK(iter, IDMAP_LIST_NAMERULES); 644c5c4113dSnw141292 645c5c4113dSnw141292 namerules = (idmap_namerules_res *)iter->retlist; 646c5c4113dSnw141292 if (iter->retcode == IDMAP_NEXT && (namerules == NULL || 647c5c4113dSnw141292 iter->next >= namerules->rules.rules_len)) { 648c5c4113dSnw141292 649c5c4113dSnw141292 if ((arg = iter->arg) == NULL) { 650c5c4113dSnw141292 errno = EINVAL; 651c5c4113dSnw141292 return (IDMAP_ERR_ARG); 652c5c4113dSnw141292 } 653c5c4113dSnw141292 arg->limit = iter->limit; 654c5c4113dSnw141292 655c5c4113dSnw141292 retcode = _iter_get_next_list(IDMAP_LIST_NAMERULES, 656c5c4113dSnw141292 iter, arg, 657c5c4113dSnw141292 (uchar_t **)&namerules, sizeof (*namerules), 658c5c4113dSnw141292 (xdrproc_t)xdr_idmap_list_namerules_1_argument, 659c5c4113dSnw141292 (xdrproc_t)xdr_idmap_namerules_res); 660c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 661c5c4113dSnw141292 return (retcode); 662c5c4113dSnw141292 663c5c4113dSnw141292 if (IDMAP_ERROR(namerules->retcode)) { 664c5c4113dSnw141292 retcode = namerules->retcode; 665c5c4113dSnw141292 xdr_free(xdr_idmap_namerules_res, (caddr_t)namerules); 666c5c4113dSnw141292 free(namerules); 667c5c4113dSnw141292 iter->retlist = NULL; 668c5c4113dSnw141292 return (retcode); 669c5c4113dSnw141292 } 670c5c4113dSnw141292 iter->retcode = namerules->retcode; 671c5c4113dSnw141292 arg->lastrowid = namerules->lastrowid; 672c5c4113dSnw141292 } 673c5c4113dSnw141292 674c5c4113dSnw141292 if (namerules == NULL || namerules->rules.rules_len == 0) 675c5c4113dSnw141292 return (IDMAP_SUCCESS); 676c5c4113dSnw141292 677c5c4113dSnw141292 if (iter->next >= namerules->rules.rules_len) { 678c5c4113dSnw141292 return (IDMAP_ERR_ARG); 679c5c4113dSnw141292 } 680c5c4113dSnw141292 6818e228215Sdm199847 retcode = idmap_strdupnull(windomain, 6828e228215Sdm199847 namerules->rules.rules_val[iter->next].windomain); 683c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 684c5c4113dSnw141292 goto errout; 6858e228215Sdm199847 6868e228215Sdm199847 retcode = idmap_strdupnull(winname, 6878e228215Sdm199847 namerules->rules.rules_val[iter->next].winname); 688c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 689c5c4113dSnw141292 goto errout; 6908e228215Sdm199847 6918e228215Sdm199847 retcode = idmap_strdupnull(unixname, 6928e228215Sdm199847 namerules->rules.rules_val[iter->next].unixname); 693c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 694c5c4113dSnw141292 goto errout; 6958e228215Sdm199847 696c5c4113dSnw141292 if (is_nt4) 697c5c4113dSnw141292 *is_nt4 = namerules->rules.rules_val[iter->next].is_nt4; 698cd37da74Snw141292 if (is_user) 699cd37da74Snw141292 *is_user = namerules->rules.rules_val[iter->next].is_user; 700cd37da74Snw141292 if (is_wuser) 701cd37da74Snw141292 *is_wuser = namerules->rules.rules_val[iter->next].is_wuser; 702c5c4113dSnw141292 if (direction) 703c5c4113dSnw141292 *direction = namerules->rules.rules_val[iter->next].direction; 704c5c4113dSnw141292 iter->next++; 705c5c4113dSnw141292 706c5c4113dSnw141292 if (iter->next == namerules->rules.rules_len) 707c5c4113dSnw141292 return (iter->retcode); 708c5c4113dSnw141292 else 709c5c4113dSnw141292 return (IDMAP_NEXT); 710c5c4113dSnw141292 711c5c4113dSnw141292 errout: 712c5c4113dSnw141292 if (windomain && *windomain) 713c5c4113dSnw141292 free(*windomain); 714c5c4113dSnw141292 if (winname && *winname) 715c5c4113dSnw141292 free(*winname); 716c5c4113dSnw141292 if (unixname && *unixname) 717c5c4113dSnw141292 free(*unixname); 718c5c4113dSnw141292 return (retcode); 719c5c4113dSnw141292 } 720c5c4113dSnw141292 721c5c4113dSnw141292 722c5c4113dSnw141292 /* 723c5c4113dSnw141292 * Create iterator to get SID to UID/GID mappings 724c5c4113dSnw141292 * 725c5c4113dSnw141292 * Output: 726c5c4113dSnw141292 * iter - iterator 727c5c4113dSnw141292 */ 728c5c4113dSnw141292 idmap_stat 7291fdeec65Sjoyce mcintosh idmap_iter_mappings(idmap_iter_t **iter, int flag) 730cd37da74Snw141292 { 731c5c4113dSnw141292 idmap_iter_t *tmpiter; 732c5c4113dSnw141292 idmap_list_mappings_1_argument *arg = NULL; 733c5c4113dSnw141292 7341fdeec65Sjoyce mcintosh __ITER_CREATE(tmpiter, arg, IDMAP_LIST_MAPPINGS); 735c5c4113dSnw141292 73648258c6bSjp151216 arg->flag = flag; 737c5c4113dSnw141292 *iter = tmpiter; 738c5c4113dSnw141292 return (IDMAP_SUCCESS); 739c5c4113dSnw141292 } 740c5c4113dSnw141292 741c5c4113dSnw141292 742c5c4113dSnw141292 /* 743c5c4113dSnw141292 * Iterate through the SID to UID/GID mappings 744c5c4113dSnw141292 * 745c5c4113dSnw141292 * Input: 746c5c4113dSnw141292 * iter - iterator 747c5c4113dSnw141292 * 748c5c4113dSnw141292 * Output: 749c5c4113dSnw141292 * sid - SID in canonical form 750c5c4113dSnw141292 * pid - UID or GID 751c5c4113dSnw141292 * 752c5c4113dSnw141292 * Return value: 753c5c4113dSnw141292 * 0 - done 754c5c4113dSnw141292 * 1 - more results available 755c5c4113dSnw141292 * < 0 - error 756c5c4113dSnw141292 */ 757c5c4113dSnw141292 idmap_stat 758c5c4113dSnw141292 idmap_iter_next_mapping(idmap_iter_t *iter, char **sidprefix, 759c5c4113dSnw141292 idmap_rid_t *rid, uid_t *pid, char **winname, 760cd37da74Snw141292 char **windomain, char **unixname, boolean_t *is_user, 76148258c6bSjp151216 boolean_t *is_wuser, int *direction, idmap_info *info) 762cd37da74Snw141292 { 763c5c4113dSnw141292 idmap_mappings_res *mappings; 764c5c4113dSnw141292 idmap_list_mappings_1_argument *arg; 765c5c4113dSnw141292 idmap_retcode retcode; 766c5c4113dSnw141292 char *str; 767c5c4113dSnw141292 768c5c4113dSnw141292 if (sidprefix) 769c5c4113dSnw141292 *sidprefix = NULL; 770c5c4113dSnw141292 if (rid) 771c5c4113dSnw141292 *rid = UINT32_MAX; 772c5c4113dSnw141292 if (winname) 773c5c4113dSnw141292 *winname = NULL; 774c5c4113dSnw141292 if (windomain) 775c5c4113dSnw141292 *windomain = NULL; 776c5c4113dSnw141292 if (unixname) 777c5c4113dSnw141292 *unixname = NULL; 778c5c4113dSnw141292 if (pid) 779c5c4113dSnw141292 *pid = UINT32_MAX; 780cd37da74Snw141292 if (is_user) 781cd37da74Snw141292 *is_user = -1; 782cd37da74Snw141292 if (is_wuser) 783cd37da74Snw141292 *is_wuser = -1; 784c5c4113dSnw141292 if (direction) 785651c0131Sbaban *direction = IDMAP_DIRECTION_UNDEF; 786c5c4113dSnw141292 787c5c4113dSnw141292 __ITER_CHECK(iter, IDMAP_LIST_MAPPINGS); 788c5c4113dSnw141292 789c5c4113dSnw141292 mappings = (idmap_mappings_res *)iter->retlist; 790c5c4113dSnw141292 if (iter->retcode == IDMAP_NEXT && (mappings == NULL || 791c5c4113dSnw141292 iter->next >= mappings->mappings.mappings_len)) { 792c5c4113dSnw141292 793c5c4113dSnw141292 if ((arg = iter->arg) == NULL) { 794c5c4113dSnw141292 errno = EINVAL; 795c5c4113dSnw141292 return (IDMAP_ERR_ARG); 796c5c4113dSnw141292 } 797c5c4113dSnw141292 arg->limit = iter->limit; 798c5c4113dSnw141292 799c5c4113dSnw141292 retcode = _iter_get_next_list(IDMAP_LIST_MAPPINGS, 800c5c4113dSnw141292 iter, arg, 801c5c4113dSnw141292 (uchar_t **)&mappings, sizeof (*mappings), 802c5c4113dSnw141292 (xdrproc_t)xdr_idmap_list_mappings_1_argument, 803c5c4113dSnw141292 (xdrproc_t)xdr_idmap_mappings_res); 804c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 805c5c4113dSnw141292 return (retcode); 806c5c4113dSnw141292 807c5c4113dSnw141292 if (IDMAP_ERROR(mappings->retcode)) { 808c5c4113dSnw141292 retcode = mappings->retcode; 809c5c4113dSnw141292 xdr_free(xdr_idmap_mappings_res, (caddr_t)mappings); 810c5c4113dSnw141292 free(mappings); 811c5c4113dSnw141292 iter->retlist = NULL; 812c5c4113dSnw141292 return (retcode); 813c5c4113dSnw141292 } 814c5c4113dSnw141292 iter->retcode = mappings->retcode; 815c5c4113dSnw141292 arg->lastrowid = mappings->lastrowid; 816c5c4113dSnw141292 } 817c5c4113dSnw141292 818c5c4113dSnw141292 if (mappings == NULL || mappings->mappings.mappings_len == 0) 819c5c4113dSnw141292 return (IDMAP_SUCCESS); 820c5c4113dSnw141292 821c5c4113dSnw141292 if (iter->next >= mappings->mappings.mappings_len) { 822c5c4113dSnw141292 return (IDMAP_ERR_ARG); 823c5c4113dSnw141292 } 824c5c4113dSnw141292 825c5c4113dSnw141292 if (sidprefix) { 826c5c4113dSnw141292 str = mappings->mappings.mappings_val[iter->next].id1. 827c5c4113dSnw141292 idmap_id_u.sid.prefix; 8288edda628Sbaban if (str && *str != '\0') { 829c5c4113dSnw141292 *sidprefix = strdup(str); 830c5c4113dSnw141292 if (*sidprefix == NULL) { 831c5c4113dSnw141292 retcode = IDMAP_ERR_MEMORY; 832c5c4113dSnw141292 goto errout; 833c5c4113dSnw141292 } 834c5c4113dSnw141292 } 8359581d9f4Sbaban } 836c5c4113dSnw141292 if (rid) 837c5c4113dSnw141292 *rid = mappings->mappings.mappings_val[iter->next].id1. 838c5c4113dSnw141292 idmap_id_u.sid.rid; 8398e228215Sdm199847 8408e228215Sdm199847 retcode = idmap_strdupnull(windomain, 8418e228215Sdm199847 mappings->mappings.mappings_val[iter->next].id1domain); 842c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 843c5c4113dSnw141292 goto errout; 8448e228215Sdm199847 8458e228215Sdm199847 retcode = idmap_strdupnull(winname, 8468e228215Sdm199847 mappings->mappings.mappings_val[iter->next].id1name); 847c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 848c5c4113dSnw141292 goto errout; 8498e228215Sdm199847 8508e228215Sdm199847 retcode = idmap_strdupnull(unixname, 8518e228215Sdm199847 mappings->mappings.mappings_val[iter->next].id2name); 852c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 853c5c4113dSnw141292 goto errout; 8548e228215Sdm199847 8558e228215Sdm199847 856c5c4113dSnw141292 if (pid) 857c5c4113dSnw141292 *pid = mappings->mappings.mappings_val[iter->next].id2. 858c5c4113dSnw141292 idmap_id_u.uid; 859c5c4113dSnw141292 if (direction) 860c5c4113dSnw141292 *direction = mappings->mappings.mappings_val[iter->next]. 861c5c4113dSnw141292 direction; 862cd37da74Snw141292 if (is_user) 863cd37da74Snw141292 *is_user = (mappings->mappings.mappings_val[iter->next].id2 864cd37da74Snw141292 .idtype == IDMAP_UID)?1:0; 865cd37da74Snw141292 if (is_wuser) 866cd37da74Snw141292 *is_wuser = (mappings->mappings.mappings_val[iter->next].id1 867cd37da74Snw141292 .idtype == IDMAP_USID)?1:0; 868cd37da74Snw141292 86948258c6bSjp151216 if (info) { 870148c5f43SAlan Wright idmap_info_mov(info, 87148258c6bSjp151216 &mappings->mappings.mappings_val[iter->next].info); 87248258c6bSjp151216 } 873c5c4113dSnw141292 iter->next++; 874c5c4113dSnw141292 875c5c4113dSnw141292 if (iter->next == mappings->mappings.mappings_len) 876c5c4113dSnw141292 return (iter->retcode); 877c5c4113dSnw141292 else 878c5c4113dSnw141292 return (IDMAP_NEXT); 879c5c4113dSnw141292 880c5c4113dSnw141292 errout: 881c5c4113dSnw141292 if (sidprefix && *sidprefix) 882c5c4113dSnw141292 free(*sidprefix); 883c5c4113dSnw141292 if (winname && *winname) 884c5c4113dSnw141292 free(*winname); 885c5c4113dSnw141292 if (windomain && *windomain) 886c5c4113dSnw141292 free(*windomain); 887c5c4113dSnw141292 if (unixname && *unixname) 888c5c4113dSnw141292 free(*unixname); 889c5c4113dSnw141292 return (retcode); 890c5c4113dSnw141292 } 891c5c4113dSnw141292 892c5c4113dSnw141292 893c5c4113dSnw141292 /* 894c5c4113dSnw141292 * Destroy the iterator 895c5c4113dSnw141292 */ 896c5c4113dSnw141292 void 897cd37da74Snw141292 idmap_iter_destroy(idmap_iter_t *iter) 898cd37da74Snw141292 { 899c5c4113dSnw141292 xdrproc_t _xdr_argument, _xdr_result; 900c5c4113dSnw141292 901c5c4113dSnw141292 if (iter == NULL) 902c5c4113dSnw141292 return; 903c5c4113dSnw141292 904c5c4113dSnw141292 switch (iter->type) { 905c5c4113dSnw141292 case IDMAP_LIST_NAMERULES: 906c5c4113dSnw141292 _xdr_argument = (xdrproc_t)xdr_idmap_list_namerules_1_argument; 907c5c4113dSnw141292 _xdr_result = (xdrproc_t)xdr_idmap_namerules_res; 908c5c4113dSnw141292 break; 909c5c4113dSnw141292 case IDMAP_LIST_MAPPINGS: 910c5c4113dSnw141292 _xdr_argument = (xdrproc_t)xdr_idmap_list_mappings_1_argument; 911c5c4113dSnw141292 _xdr_result = (xdrproc_t)xdr_idmap_mappings_res; 912c5c4113dSnw141292 break; 913c5c4113dSnw141292 default: 914c5c4113dSnw141292 free(iter); 915c5c4113dSnw141292 return; 916c5c4113dSnw141292 }; 917c5c4113dSnw141292 918c5c4113dSnw141292 if (iter->arg) { 919c5c4113dSnw141292 xdr_free(_xdr_argument, (caddr_t)iter->arg); 920c5c4113dSnw141292 free(iter->arg); 921c5c4113dSnw141292 } 922c5c4113dSnw141292 if (iter->retlist) { 923c5c4113dSnw141292 xdr_free(_xdr_result, (caddr_t)iter->retlist); 924c5c4113dSnw141292 free(iter->retlist); 925c5c4113dSnw141292 } 926c5c4113dSnw141292 free(iter); 927c5c4113dSnw141292 } 928c5c4113dSnw141292 929c5c4113dSnw141292 930c5c4113dSnw141292 /* 931c5c4113dSnw141292 * Create handle to get SID to UID/GID mapping entries 932c5c4113dSnw141292 * 933c5c4113dSnw141292 * Input: 934c5c4113dSnw141292 * gh - "get mapping" handle 935c5c4113dSnw141292 */ 936c5c4113dSnw141292 idmap_stat 9371fdeec65Sjoyce mcintosh idmap_get_create(idmap_get_handle_t **gh) 938cd37da74Snw141292 { 939c5c4113dSnw141292 idmap_get_handle_t *tmp; 940c5c4113dSnw141292 941c5c4113dSnw141292 /* allocate the handle */ 942c5c4113dSnw141292 if ((tmp = calloc(1, sizeof (*tmp))) == NULL) { 943c5c4113dSnw141292 errno = ENOMEM; 944c5c4113dSnw141292 return (IDMAP_ERR_MEMORY); 945c5c4113dSnw141292 } 946c5c4113dSnw141292 947c5c4113dSnw141292 *gh = tmp; 948c5c4113dSnw141292 return (IDMAP_SUCCESS); 949c5c4113dSnw141292 } 950c5c4113dSnw141292 951c5c4113dSnw141292 952c5c4113dSnw141292 /* 953c5c4113dSnw141292 * Given SID, get UID 954c5c4113dSnw141292 * 955c5c4113dSnw141292 * Input: 956c5c4113dSnw141292 * sidprefix - SID prefix 957c5c4113dSnw141292 * rid - RID 958c5c4113dSnw141292 * flag - flag 959c5c4113dSnw141292 * 960c5c4113dSnw141292 * Output: 961c5c4113dSnw141292 * stat - status of the get request 962c5c4113dSnw141292 * uid - POSIX UID if stat = 0 963c5c4113dSnw141292 * 964c5c4113dSnw141292 * Note: The output parameters will be set by idmap_get_mappings() 965c5c4113dSnw141292 */ 966c5c4113dSnw141292 idmap_stat 967c5c4113dSnw141292 idmap_get_uidbysid(idmap_get_handle_t *gh, char *sidprefix, idmap_rid_t rid, 968cd37da74Snw141292 int flag, uid_t *uid, idmap_stat *stat) 969cd37da74Snw141292 { 97048258c6bSjp151216 return (idmap_getext_uidbysid(gh, sidprefix, rid, flag, uid, 97148258c6bSjp151216 NULL, stat)); 97248258c6bSjp151216 } 973c5c4113dSnw141292 97448258c6bSjp151216 /* 97548258c6bSjp151216 * Given SID, get UID 97648258c6bSjp151216 * 97748258c6bSjp151216 * Input: 97848258c6bSjp151216 * sidprefix - SID prefix 97948258c6bSjp151216 * rid - RID 98048258c6bSjp151216 * flag - flag 98148258c6bSjp151216 * 98248258c6bSjp151216 * Output: 98348258c6bSjp151216 * stat - status of the get request 98448258c6bSjp151216 * uid - POSIX UID if stat = 0 98548258c6bSjp151216 * how - mapping type if stat = 0 98648258c6bSjp151216 * 98748258c6bSjp151216 * Note: The output parameters will be set by idmap_get_mappings() 98848258c6bSjp151216 */ 98948258c6bSjp151216 99048258c6bSjp151216 idmap_stat 99148258c6bSjp151216 idmap_getext_uidbysid(idmap_get_handle_t *gh, char *sidprefix, idmap_rid_t rid, 99248258c6bSjp151216 int flag, uid_t *uid, idmap_info *info, idmap_stat *stat) 99348258c6bSjp151216 { 994c5c4113dSnw141292 idmap_retcode retcode; 995651c0131Sbaban idmap_mapping *mapping = NULL; 996c5c4113dSnw141292 997c5c4113dSnw141292 /* sanity checks */ 998c5c4113dSnw141292 if (gh == NULL) 999c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1000c5c4113dSnw141292 if (uid == NULL || sidprefix == NULL) 1001c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1002c5c4113dSnw141292 10033ee87bcaSJulian Pullen if ((flag & IDMAP_REQ_FLG_USE_CACHE) && 10043ee87bcaSJulian Pullen !(flag & IDMAP_REQ_FLG_MAPPING_INFO)) { 10053ee87bcaSJulian Pullen retcode = idmap_cache_lookup_uidbysid(sidprefix, rid, uid); 10063ee87bcaSJulian Pullen if (retcode == IDMAP_SUCCESS || retcode == IDMAP_ERR_MEMORY) { 10073ee87bcaSJulian Pullen *stat = retcode; 10083ee87bcaSJulian Pullen return (retcode); 10093ee87bcaSJulian Pullen } 10103ee87bcaSJulian Pullen } 10113ee87bcaSJulian Pullen 1012c5c4113dSnw141292 /* Extend the request array and the return list */ 1013c5c4113dSnw141292 if ((retcode = _get_ids_extend_batch(gh)) != IDMAP_SUCCESS) 1014c5c4113dSnw141292 goto errout; 1015c5c4113dSnw141292 1016c5c4113dSnw141292 /* Setup the request */ 1017c5c4113dSnw141292 mapping = &gh->batch.idmap_mapping_batch_val[gh->next]; 1018c5c4113dSnw141292 mapping->flag = flag; 1019c5c4113dSnw141292 mapping->id1.idtype = IDMAP_SID; 1020c5c4113dSnw141292 mapping->id1.idmap_id_u.sid.rid = rid; 1021c5c4113dSnw141292 if ((mapping->id1.idmap_id_u.sid.prefix = strdup(sidprefix)) == NULL) { 1022c5c4113dSnw141292 retcode = IDMAP_ERR_MEMORY; 1023c5c4113dSnw141292 goto errout; 1024c5c4113dSnw141292 } 1025c5c4113dSnw141292 mapping->id2.idtype = IDMAP_UID; 1026c5c4113dSnw141292 1027c5c4113dSnw141292 /* Setup pointers for the result */ 1028c5c4113dSnw141292 gh->retlist[gh->next].idtype = IDMAP_UID; 1029c5c4113dSnw141292 gh->retlist[gh->next].uid = uid; 1030c5c4113dSnw141292 gh->retlist[gh->next].stat = stat; 103148258c6bSjp151216 gh->retlist[gh->next].info = info; 10323ee87bcaSJulian Pullen gh->retlist[gh->next].cache_res = flag & IDMAP_REQ_FLG_USE_CACHE; 1033c5c4113dSnw141292 1034c5c4113dSnw141292 gh->next++; 1035c5c4113dSnw141292 return (IDMAP_SUCCESS); 1036c5c4113dSnw141292 1037c5c4113dSnw141292 errout: 1038651c0131Sbaban /* Batch created so far should still be usable */ 1039651c0131Sbaban if (mapping) 1040651c0131Sbaban (void) memset(mapping, 0, sizeof (*mapping)); 1041c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1042c5c4113dSnw141292 return (retcode); 1043c5c4113dSnw141292 } 1044c5c4113dSnw141292 1045c5c4113dSnw141292 1046c5c4113dSnw141292 /* 1047c5c4113dSnw141292 * Given SID, get GID 1048c5c4113dSnw141292 * 1049c5c4113dSnw141292 * Input: 1050c5c4113dSnw141292 * sidprefix - SID prefix 1051c5c4113dSnw141292 * rid - rid 1052c5c4113dSnw141292 * flag - flag 1053c5c4113dSnw141292 * 1054c5c4113dSnw141292 * Output: 1055c5c4113dSnw141292 * stat - status of the get request 1056c5c4113dSnw141292 * gid - POSIX GID if stat = 0 1057c5c4113dSnw141292 * 1058c5c4113dSnw141292 * Note: The output parameters will be set by idmap_get_mappings() 1059c5c4113dSnw141292 */ 1060c5c4113dSnw141292 idmap_stat 1061c5c4113dSnw141292 idmap_get_gidbysid(idmap_get_handle_t *gh, char *sidprefix, idmap_rid_t rid, 1062cd37da74Snw141292 int flag, gid_t *gid, idmap_stat *stat) 1063cd37da74Snw141292 { 106448258c6bSjp151216 return (idmap_getext_gidbysid(gh, sidprefix, rid, flag, gid, 106548258c6bSjp151216 NULL, stat)); 106648258c6bSjp151216 } 106748258c6bSjp151216 106848258c6bSjp151216 106948258c6bSjp151216 /* 107048258c6bSjp151216 * Given SID, get GID 107148258c6bSjp151216 * 107248258c6bSjp151216 * Input: 107348258c6bSjp151216 * sidprefix - SID prefix 107448258c6bSjp151216 * rid - rid 107548258c6bSjp151216 * flag - flag 107648258c6bSjp151216 * 107748258c6bSjp151216 * Output: 107848258c6bSjp151216 * stat - status of the get request 107948258c6bSjp151216 * gid - POSIX GID if stat = 0 108048258c6bSjp151216 * how - mapping type if stat = 0 108148258c6bSjp151216 * 108248258c6bSjp151216 * Note: The output parameters will be set by idmap_get_mappings() 108348258c6bSjp151216 */ 108448258c6bSjp151216 idmap_stat 108548258c6bSjp151216 idmap_getext_gidbysid(idmap_get_handle_t *gh, char *sidprefix, idmap_rid_t rid, 108648258c6bSjp151216 int flag, gid_t *gid, idmap_info *info, idmap_stat *stat) 108748258c6bSjp151216 { 1088c5c4113dSnw141292 1089c5c4113dSnw141292 idmap_retcode retcode; 1090651c0131Sbaban idmap_mapping *mapping = NULL; 1091c5c4113dSnw141292 1092c5c4113dSnw141292 /* sanity checks */ 1093c5c4113dSnw141292 if (gh == NULL) 1094c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1095c5c4113dSnw141292 if (gid == NULL || sidprefix == NULL) 1096c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1097c5c4113dSnw141292 10983ee87bcaSJulian Pullen if ((flag & IDMAP_REQ_FLG_USE_CACHE) && 10993ee87bcaSJulian Pullen !(flag & IDMAP_REQ_FLG_MAPPING_INFO)) { 11003ee87bcaSJulian Pullen retcode = idmap_cache_lookup_gidbysid(sidprefix, rid, gid); 11013ee87bcaSJulian Pullen if (retcode == IDMAP_SUCCESS || retcode == IDMAP_ERR_MEMORY) { 11023ee87bcaSJulian Pullen *stat = retcode; 11033ee87bcaSJulian Pullen return (retcode); 11043ee87bcaSJulian Pullen } 11053ee87bcaSJulian Pullen } 11063ee87bcaSJulian Pullen 1107c5c4113dSnw141292 /* Extend the request array and the return list */ 1108c5c4113dSnw141292 if ((retcode = _get_ids_extend_batch(gh)) != IDMAP_SUCCESS) 1109c5c4113dSnw141292 goto errout; 1110c5c4113dSnw141292 1111c5c4113dSnw141292 /* Setup the request */ 1112c5c4113dSnw141292 mapping = &gh->batch.idmap_mapping_batch_val[gh->next]; 1113c5c4113dSnw141292 mapping->flag = flag; 1114c5c4113dSnw141292 mapping->id1.idtype = IDMAP_SID; 1115c5c4113dSnw141292 mapping->id1.idmap_id_u.sid.rid = rid; 1116c5c4113dSnw141292 if ((mapping->id1.idmap_id_u.sid.prefix = strdup(sidprefix)) == NULL) { 1117c5c4113dSnw141292 retcode = IDMAP_ERR_MEMORY; 1118c5c4113dSnw141292 goto errout; 1119c5c4113dSnw141292 } 1120c5c4113dSnw141292 mapping->id2.idtype = IDMAP_GID; 1121c5c4113dSnw141292 1122c5c4113dSnw141292 /* Setup pointers for the result */ 1123c5c4113dSnw141292 gh->retlist[gh->next].idtype = IDMAP_GID; 1124c5c4113dSnw141292 gh->retlist[gh->next].gid = gid; 1125c5c4113dSnw141292 gh->retlist[gh->next].stat = stat; 112648258c6bSjp151216 gh->retlist[gh->next].info = info; 11273ee87bcaSJulian Pullen gh->retlist[gh->next].cache_res = flag & IDMAP_REQ_FLG_USE_CACHE; 1128c5c4113dSnw141292 1129c5c4113dSnw141292 gh->next++; 1130c5c4113dSnw141292 return (IDMAP_SUCCESS); 1131c5c4113dSnw141292 1132c5c4113dSnw141292 errout: 1133651c0131Sbaban if (mapping) 1134651c0131Sbaban (void) memset(mapping, 0, sizeof (*mapping)); 1135c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1136c5c4113dSnw141292 return (retcode); 1137c5c4113dSnw141292 } 1138c5c4113dSnw141292 1139c5c4113dSnw141292 114048258c6bSjp151216 1141c5c4113dSnw141292 /* 1142c5c4113dSnw141292 * Given SID, get POSIX ID i.e. UID/GID 1143c5c4113dSnw141292 * 1144c5c4113dSnw141292 * Input: 1145c5c4113dSnw141292 * sidprefix - SID prefix 1146c5c4113dSnw141292 * rid - rid 1147c5c4113dSnw141292 * flag - flag 1148c5c4113dSnw141292 * 1149c5c4113dSnw141292 * Output: 1150c5c4113dSnw141292 * stat - status of the get request 1151c5c4113dSnw141292 * is_user - user or group 1152c5c4113dSnw141292 * pid - POSIX UID if stat = 0 and is_user = 1 1153c5c4113dSnw141292 * POSIX GID if stat = 0 and is_user = 0 1154c5c4113dSnw141292 * 1155c5c4113dSnw141292 * Note: The output parameters will be set by idmap_get_mappings() 1156c5c4113dSnw141292 */ 1157c5c4113dSnw141292 idmap_stat 1158c5c4113dSnw141292 idmap_get_pidbysid(idmap_get_handle_t *gh, char *sidprefix, idmap_rid_t rid, 1159cd37da74Snw141292 int flag, uid_t *pid, int *is_user, idmap_stat *stat) 1160cd37da74Snw141292 { 116148258c6bSjp151216 return (idmap_getext_pidbysid(gh, sidprefix, rid, flag, pid, is_user, 116248258c6bSjp151216 NULL, stat)); 116348258c6bSjp151216 } 116448258c6bSjp151216 116548258c6bSjp151216 116648258c6bSjp151216 116748258c6bSjp151216 /* 116848258c6bSjp151216 * Given SID, get POSIX ID i.e. UID/GID 116948258c6bSjp151216 * 117048258c6bSjp151216 * Input: 117148258c6bSjp151216 * sidprefix - SID prefix 117248258c6bSjp151216 * rid - rid 117348258c6bSjp151216 * flag - flag 117448258c6bSjp151216 * 117548258c6bSjp151216 * Output: 117648258c6bSjp151216 * stat - status of the get request 117748258c6bSjp151216 * is_user - user or group 117848258c6bSjp151216 * pid - POSIX UID if stat = 0 and is_user = 1 117948258c6bSjp151216 * POSIX GID if stat = 0 and is_user = 0 118048258c6bSjp151216 * how - mapping type if stat = 0 118148258c6bSjp151216 * 118248258c6bSjp151216 * Note: The output parameters will be set by idmap_get_mappings() 118348258c6bSjp151216 */ 118448258c6bSjp151216 idmap_stat 118548258c6bSjp151216 idmap_getext_pidbysid(idmap_get_handle_t *gh, char *sidprefix, idmap_rid_t rid, 118648258c6bSjp151216 int flag, uid_t *pid, int *is_user, idmap_info *info, idmap_stat *stat) 118748258c6bSjp151216 { 1188c5c4113dSnw141292 idmap_retcode retcode; 1189651c0131Sbaban idmap_mapping *mapping = NULL; 1190c5c4113dSnw141292 1191c5c4113dSnw141292 /* sanity checks */ 1192c5c4113dSnw141292 if (gh == NULL) 1193c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1194c5c4113dSnw141292 if (pid == NULL || sidprefix == NULL || is_user == NULL) 1195c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1196c5c4113dSnw141292 11973ee87bcaSJulian Pullen if ((flag & IDMAP_REQ_FLG_USE_CACHE) && 11983ee87bcaSJulian Pullen !(flag & IDMAP_REQ_FLG_MAPPING_INFO)) { 11993ee87bcaSJulian Pullen retcode = idmap_cache_lookup_pidbysid(sidprefix, rid, pid, 12003ee87bcaSJulian Pullen is_user); 12013ee87bcaSJulian Pullen if (retcode == IDMAP_SUCCESS || retcode == IDMAP_ERR_MEMORY) { 12023ee87bcaSJulian Pullen *stat = retcode; 12033ee87bcaSJulian Pullen return (retcode); 12043ee87bcaSJulian Pullen } 12053ee87bcaSJulian Pullen } 12063ee87bcaSJulian Pullen 1207c5c4113dSnw141292 /* Extend the request array and the return list */ 1208c5c4113dSnw141292 if ((retcode = _get_ids_extend_batch(gh)) != IDMAP_SUCCESS) 1209c5c4113dSnw141292 goto errout; 1210c5c4113dSnw141292 1211c5c4113dSnw141292 /* Setup the request */ 1212c5c4113dSnw141292 mapping = &gh->batch.idmap_mapping_batch_val[gh->next]; 1213c5c4113dSnw141292 mapping->flag = flag; 1214c5c4113dSnw141292 mapping->id1.idtype = IDMAP_SID; 1215c5c4113dSnw141292 mapping->id1.idmap_id_u.sid.rid = rid; 1216c5c4113dSnw141292 if ((mapping->id1.idmap_id_u.sid.prefix = strdup(sidprefix)) == NULL) { 1217c5c4113dSnw141292 retcode = IDMAP_ERR_MEMORY; 1218c5c4113dSnw141292 goto errout; 1219c5c4113dSnw141292 } 1220c5c4113dSnw141292 mapping->id2.idtype = IDMAP_POSIXID; 1221c5c4113dSnw141292 1222c5c4113dSnw141292 /* Setup pointers for the result */ 1223c5c4113dSnw141292 gh->retlist[gh->next].idtype = IDMAP_POSIXID; 1224c5c4113dSnw141292 gh->retlist[gh->next].uid = pid; 1225c5c4113dSnw141292 gh->retlist[gh->next].gid = pid; 1226c5c4113dSnw141292 gh->retlist[gh->next].is_user = is_user; 1227c5c4113dSnw141292 gh->retlist[gh->next].stat = stat; 122848258c6bSjp151216 gh->retlist[gh->next].info = info; 12293ee87bcaSJulian Pullen gh->retlist[gh->next].cache_res = flag & IDMAP_REQ_FLG_USE_CACHE; 1230c5c4113dSnw141292 1231c5c4113dSnw141292 gh->next++; 1232c5c4113dSnw141292 return (IDMAP_SUCCESS); 1233c5c4113dSnw141292 1234c5c4113dSnw141292 errout: 1235651c0131Sbaban if (mapping) 1236651c0131Sbaban (void) memset(mapping, 0, sizeof (*mapping)); 1237c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1238c5c4113dSnw141292 return (retcode); 1239c5c4113dSnw141292 } 1240c5c4113dSnw141292 1241c5c4113dSnw141292 1242c5c4113dSnw141292 /* 1243c5c4113dSnw141292 * Given UID, get SID 1244c5c4113dSnw141292 * 1245c5c4113dSnw141292 * Input: 1246c5c4113dSnw141292 * uid - POSIX UID 1247c5c4113dSnw141292 * flag - flag 1248c5c4113dSnw141292 * 1249c5c4113dSnw141292 * Output: 1250c5c4113dSnw141292 * stat - status of the get request 1251c5c4113dSnw141292 * sid - SID prefix (if stat == 0) 1252c5c4113dSnw141292 * rid - rid 1253c5c4113dSnw141292 * 1254c5c4113dSnw141292 * Note: The output parameters will be set by idmap_get_mappings() 1255c5c4113dSnw141292 */ 1256c5c4113dSnw141292 idmap_stat 1257c5c4113dSnw141292 idmap_get_sidbyuid(idmap_get_handle_t *gh, uid_t uid, int flag, 1258cd37da74Snw141292 char **sidprefix, idmap_rid_t *rid, idmap_stat *stat) 1259cd37da74Snw141292 { 126048258c6bSjp151216 return (idmap_getext_sidbyuid(gh, uid, flag, sidprefix, rid, 126148258c6bSjp151216 NULL, stat)); 126248258c6bSjp151216 } 126348258c6bSjp151216 126448258c6bSjp151216 126548258c6bSjp151216 /* 126648258c6bSjp151216 * Given UID, get SID 126748258c6bSjp151216 * 126848258c6bSjp151216 * Input: 126948258c6bSjp151216 * uid - POSIX UID 127048258c6bSjp151216 * flag - flag 127148258c6bSjp151216 * 127248258c6bSjp151216 * Output: 127348258c6bSjp151216 * stat - status of the get request 127448258c6bSjp151216 * sid - SID prefix (if stat == 0) 127548258c6bSjp151216 * rid - rid 127648258c6bSjp151216 * how - mapping type if stat = 0 127748258c6bSjp151216 * 127848258c6bSjp151216 * Note: The output parameters will be set by idmap_get_mappings() 127948258c6bSjp151216 */ 128048258c6bSjp151216 idmap_stat 128148258c6bSjp151216 idmap_getext_sidbyuid(idmap_get_handle_t *gh, uid_t uid, int flag, 128248258c6bSjp151216 char **sidprefix, idmap_rid_t *rid, idmap_info *info, idmap_stat *stat) 128348258c6bSjp151216 { 1284c5c4113dSnw141292 1285c5c4113dSnw141292 idmap_retcode retcode; 1286651c0131Sbaban idmap_mapping *mapping = NULL; 1287c5c4113dSnw141292 1288c5c4113dSnw141292 /* sanity checks */ 1289c5c4113dSnw141292 if (gh == NULL) 1290c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1291c5c4113dSnw141292 if (sidprefix == NULL) 1292c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1293c5c4113dSnw141292 12943ee87bcaSJulian Pullen if ((flag & IDMAP_REQ_FLG_USE_CACHE) && 12953ee87bcaSJulian Pullen !(flag & IDMAP_REQ_FLG_MAPPING_INFO)) { 12963ee87bcaSJulian Pullen retcode = idmap_cache_lookup_sidbyuid(sidprefix, rid, uid); 12973ee87bcaSJulian Pullen if (retcode == IDMAP_SUCCESS || retcode == IDMAP_ERR_MEMORY) { 12983ee87bcaSJulian Pullen *stat = retcode; 12993ee87bcaSJulian Pullen return (retcode); 13003ee87bcaSJulian Pullen } 13013ee87bcaSJulian Pullen } 13023ee87bcaSJulian Pullen 1303c5c4113dSnw141292 /* Extend the request array and the return list */ 1304c5c4113dSnw141292 if ((retcode = _get_ids_extend_batch(gh)) != IDMAP_SUCCESS) 1305c5c4113dSnw141292 goto errout; 1306c5c4113dSnw141292 1307c5c4113dSnw141292 /* Setup the request */ 1308c5c4113dSnw141292 mapping = &gh->batch.idmap_mapping_batch_val[gh->next]; 1309c5c4113dSnw141292 mapping->flag = flag; 1310c5c4113dSnw141292 mapping->id1.idtype = IDMAP_UID; 1311c5c4113dSnw141292 mapping->id1.idmap_id_u.uid = uid; 1312c5c4113dSnw141292 mapping->id2.idtype = IDMAP_SID; 1313c5c4113dSnw141292 1314c5c4113dSnw141292 /* Setup pointers for the result */ 1315c5c4113dSnw141292 gh->retlist[gh->next].idtype = IDMAP_SID; 1316c5c4113dSnw141292 gh->retlist[gh->next].sidprefix = sidprefix; 1317c5c4113dSnw141292 gh->retlist[gh->next].rid = rid; 1318c5c4113dSnw141292 gh->retlist[gh->next].stat = stat; 131948258c6bSjp151216 gh->retlist[gh->next].info = info; 13203ee87bcaSJulian Pullen gh->retlist[gh->next].cache_res = flag & IDMAP_REQ_FLG_USE_CACHE; 1321c5c4113dSnw141292 1322c5c4113dSnw141292 gh->next++; 1323c5c4113dSnw141292 return (IDMAP_SUCCESS); 1324c5c4113dSnw141292 1325c5c4113dSnw141292 errout: 1326651c0131Sbaban if (mapping) 1327651c0131Sbaban (void) memset(mapping, 0, sizeof (*mapping)); 1328c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1329c5c4113dSnw141292 return (retcode); 1330c5c4113dSnw141292 } 1331c5c4113dSnw141292 1332c5c4113dSnw141292 1333c5c4113dSnw141292 /* 1334c5c4113dSnw141292 * Given GID, get SID 1335c5c4113dSnw141292 * 1336c5c4113dSnw141292 * Input: 1337c5c4113dSnw141292 * gid - POSIX GID 1338c5c4113dSnw141292 * flag - flag 1339c5c4113dSnw141292 * 1340c5c4113dSnw141292 * Output: 1341c5c4113dSnw141292 * stat - status of the get request 1342c5c4113dSnw141292 * sidprefix - SID prefix (if stat == 0) 1343c5c4113dSnw141292 * rid - rid 1344c5c4113dSnw141292 * 1345c5c4113dSnw141292 * Note: The output parameters will be set by idmap_get_mappings() 1346c5c4113dSnw141292 */ 1347c5c4113dSnw141292 idmap_stat 1348c5c4113dSnw141292 idmap_get_sidbygid(idmap_get_handle_t *gh, gid_t gid, int flag, 1349cd37da74Snw141292 char **sidprefix, idmap_rid_t *rid, idmap_stat *stat) 1350cd37da74Snw141292 { 135148258c6bSjp151216 return (idmap_getext_sidbygid(gh, gid, flag, sidprefix, rid, 135248258c6bSjp151216 NULL, stat)); 135348258c6bSjp151216 } 135448258c6bSjp151216 135548258c6bSjp151216 135648258c6bSjp151216 /* 135748258c6bSjp151216 * Given GID, get SID 135848258c6bSjp151216 * 135948258c6bSjp151216 * Input: 136048258c6bSjp151216 * gid - POSIX GID 136148258c6bSjp151216 * flag - flag 136248258c6bSjp151216 * 136348258c6bSjp151216 * Output: 136448258c6bSjp151216 * stat - status of the get request 136548258c6bSjp151216 * sidprefix - SID prefix (if stat == 0) 136648258c6bSjp151216 * rid - rid 136748258c6bSjp151216 * how - mapping type if stat = 0 136848258c6bSjp151216 * 136948258c6bSjp151216 * Note: The output parameters will be set by idmap_get_mappings() 137048258c6bSjp151216 */ 137148258c6bSjp151216 idmap_stat 137248258c6bSjp151216 idmap_getext_sidbygid(idmap_get_handle_t *gh, gid_t gid, int flag, 137348258c6bSjp151216 char **sidprefix, idmap_rid_t *rid, idmap_info *info, idmap_stat *stat) 137448258c6bSjp151216 { 1375c5c4113dSnw141292 1376c5c4113dSnw141292 idmap_retcode retcode; 1377651c0131Sbaban idmap_mapping *mapping = NULL; 1378c5c4113dSnw141292 1379c5c4113dSnw141292 /* sanity checks */ 1380c5c4113dSnw141292 if (gh == NULL) 1381c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1382c5c4113dSnw141292 if (sidprefix == NULL) 1383c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1384c5c4113dSnw141292 13853ee87bcaSJulian Pullen if ((flag & IDMAP_REQ_FLG_USE_CACHE) && 13863ee87bcaSJulian Pullen !(flag & IDMAP_REQ_FLG_MAPPING_INFO)) { 13873ee87bcaSJulian Pullen retcode = idmap_cache_lookup_sidbygid(sidprefix, rid, gid); 13883ee87bcaSJulian Pullen if (retcode == IDMAP_SUCCESS || retcode == IDMAP_ERR_MEMORY) { 13893ee87bcaSJulian Pullen *stat = retcode; 13903ee87bcaSJulian Pullen return (retcode); 13913ee87bcaSJulian Pullen } 13923ee87bcaSJulian Pullen } 13933ee87bcaSJulian Pullen 1394c5c4113dSnw141292 /* Extend the request array and the return list */ 1395c5c4113dSnw141292 if ((retcode = _get_ids_extend_batch(gh)) != IDMAP_SUCCESS) 1396c5c4113dSnw141292 goto errout; 1397c5c4113dSnw141292 1398c5c4113dSnw141292 /* Setup the request */ 1399c5c4113dSnw141292 mapping = &gh->batch.idmap_mapping_batch_val[gh->next]; 1400c5c4113dSnw141292 mapping->flag = flag; 1401c5c4113dSnw141292 mapping->id1.idtype = IDMAP_GID; 1402c5c4113dSnw141292 mapping->id1.idmap_id_u.gid = gid; 1403c5c4113dSnw141292 mapping->id2.idtype = IDMAP_SID; 1404c5c4113dSnw141292 1405c5c4113dSnw141292 /* Setup pointers for the result */ 1406c5c4113dSnw141292 gh->retlist[gh->next].idtype = IDMAP_SID; 1407c5c4113dSnw141292 gh->retlist[gh->next].sidprefix = sidprefix; 1408c5c4113dSnw141292 gh->retlist[gh->next].rid = rid; 1409c5c4113dSnw141292 gh->retlist[gh->next].stat = stat; 141048258c6bSjp151216 gh->retlist[gh->next].info = info; 14113ee87bcaSJulian Pullen gh->retlist[gh->next].cache_res = flag & IDMAP_REQ_FLG_USE_CACHE; 1412c5c4113dSnw141292 1413c5c4113dSnw141292 gh->next++; 1414c5c4113dSnw141292 return (IDMAP_SUCCESS); 1415c5c4113dSnw141292 1416c5c4113dSnw141292 errout: 1417651c0131Sbaban if (mapping) 1418651c0131Sbaban (void) memset(mapping, 0, sizeof (*mapping)); 1419c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1420c5c4113dSnw141292 return (retcode); 1421c5c4113dSnw141292 } 1422c5c4113dSnw141292 1423c5c4113dSnw141292 1424c5c4113dSnw141292 /* 1425c5c4113dSnw141292 * Process the batched "get mapping" requests. The results (i.e. 1426c5c4113dSnw141292 * status and identity) will be available in the data areas 1427c5c4113dSnw141292 * provided by individual requests. 1428c5c4113dSnw141292 */ 1429c5c4113dSnw141292 idmap_stat 1430cd37da74Snw141292 idmap_get_mappings(idmap_get_handle_t *gh) 1431cd37da74Snw141292 { 1432c5c4113dSnw141292 idmap_retcode retcode; 1433c5c4113dSnw141292 idmap_ids_res res; 14343ee87bcaSJulian Pullen idmap_id *res_id; 1435c5c4113dSnw141292 int i; 14363ee87bcaSJulian Pullen idmap_id *req_id; 14373ee87bcaSJulian Pullen int direction; 1438c5c4113dSnw141292 1439c5c4113dSnw141292 if (gh == NULL) { 1440c5c4113dSnw141292 errno = EINVAL; 1441c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1442c5c4113dSnw141292 } 1443c5c4113dSnw141292 1444c5c4113dSnw141292 (void) memset(&res, 0, sizeof (idmap_ids_res)); 14451fdeec65Sjoyce mcintosh retcode = _idmap_clnt_call(IDMAP_GET_MAPPED_IDS, 1446c5c4113dSnw141292 (xdrproc_t)xdr_idmap_mapping_batch, 1447c5c4113dSnw141292 (caddr_t)&gh->batch, 1448c5c4113dSnw141292 (xdrproc_t)xdr_idmap_ids_res, 1449c5c4113dSnw141292 (caddr_t)&res, 1450c5c4113dSnw141292 TIMEOUT); 14511fdeec65Sjoyce mcintosh if (retcode != IDMAP_SUCCESS) { 1452c5c4113dSnw141292 goto out; 1453c5c4113dSnw141292 } 1454c5c4113dSnw141292 if (res.retcode != IDMAP_SUCCESS) { 1455c5c4113dSnw141292 retcode = res.retcode; 1456c5c4113dSnw141292 goto out; 1457c5c4113dSnw141292 } 1458c5c4113dSnw141292 for (i = 0; i < gh->next; i++) { 1459c5c4113dSnw141292 if (i >= res.ids.ids_len) { 1460c5c4113dSnw141292 *gh->retlist[i].stat = IDMAP_ERR_NORESULT; 1461c5c4113dSnw141292 continue; 1462c5c4113dSnw141292 } 1463c5c4113dSnw141292 *gh->retlist[i].stat = res.ids.ids_val[i].retcode; 14643ee87bcaSJulian Pullen res_id = &res.ids.ids_val[i].id; 14653ee87bcaSJulian Pullen direction = res.ids.ids_val[i].direction; 14663ee87bcaSJulian Pullen req_id = &gh->batch.idmap_mapping_batch_val[i].id1; 14673ee87bcaSJulian Pullen switch (res_id->idtype) { 1468c5c4113dSnw141292 case IDMAP_UID: 1469c5c4113dSnw141292 if (gh->retlist[i].uid) 14703ee87bcaSJulian Pullen *gh->retlist[i].uid = res_id->idmap_id_u.uid; 1471c5c4113dSnw141292 if (gh->retlist[i].is_user) 1472c5c4113dSnw141292 *gh->retlist[i].is_user = 1; 14733ee87bcaSJulian Pullen 14743ee87bcaSJulian Pullen if (res.ids.ids_val[i].retcode == IDMAP_SUCCESS && 14753ee87bcaSJulian Pullen gh->retlist[i].cache_res) { 14763ee87bcaSJulian Pullen if (gh->retlist[i].is_user != NULL) 14773ee87bcaSJulian Pullen idmap_cache_add_sid2pid( 14783ee87bcaSJulian Pullen req_id->idmap_id_u.sid.prefix, 14793ee87bcaSJulian Pullen req_id->idmap_id_u.sid.rid, 14803ee87bcaSJulian Pullen res_id->idmap_id_u.uid, 1, 14813ee87bcaSJulian Pullen direction); 14823ee87bcaSJulian Pullen else 14833ee87bcaSJulian Pullen idmap_cache_add_sid2uid( 14843ee87bcaSJulian Pullen req_id->idmap_id_u.sid.prefix, 14853ee87bcaSJulian Pullen req_id->idmap_id_u.sid.rid, 14863ee87bcaSJulian Pullen res_id->idmap_id_u.uid, 14873ee87bcaSJulian Pullen direction); 14883ee87bcaSJulian Pullen } 1489c5c4113dSnw141292 break; 14903ee87bcaSJulian Pullen 1491c5c4113dSnw141292 case IDMAP_GID: 1492c5c4113dSnw141292 if (gh->retlist[i].gid) 14933ee87bcaSJulian Pullen *gh->retlist[i].gid = res_id->idmap_id_u.gid; 1494c5c4113dSnw141292 if (gh->retlist[i].is_user) 1495c5c4113dSnw141292 *gh->retlist[i].is_user = 0; 14963ee87bcaSJulian Pullen 14973ee87bcaSJulian Pullen if (res.ids.ids_val[i].retcode == IDMAP_SUCCESS && 14983ee87bcaSJulian Pullen gh->retlist[i].cache_res) { 14993ee87bcaSJulian Pullen if (gh->retlist[i].is_user != NULL) 15003ee87bcaSJulian Pullen idmap_cache_add_sid2pid( 15013ee87bcaSJulian Pullen req_id->idmap_id_u.sid.prefix, 15023ee87bcaSJulian Pullen req_id->idmap_id_u.sid.rid, 15033ee87bcaSJulian Pullen res_id->idmap_id_u.gid, 0, 15043ee87bcaSJulian Pullen direction); 15053ee87bcaSJulian Pullen else 15063ee87bcaSJulian Pullen idmap_cache_add_sid2gid( 15073ee87bcaSJulian Pullen req_id->idmap_id_u.sid.prefix, 15083ee87bcaSJulian Pullen req_id->idmap_id_u.sid.rid, 15093ee87bcaSJulian Pullen res_id->idmap_id_u.gid, 15103ee87bcaSJulian Pullen direction); 15113ee87bcaSJulian Pullen } 1512c5c4113dSnw141292 break; 15133ee87bcaSJulian Pullen 151462c60062Sbaban case IDMAP_POSIXID: 151562c60062Sbaban if (gh->retlist[i].uid) 151662c60062Sbaban *gh->retlist[i].uid = 60001; 151762c60062Sbaban if (gh->retlist[i].is_user) 151862c60062Sbaban *gh->retlist[i].is_user = -1; 151962c60062Sbaban break; 15203ee87bcaSJulian Pullen 1521c5c4113dSnw141292 case IDMAP_SID: 1522cd37da74Snw141292 case IDMAP_USID: 1523cd37da74Snw141292 case IDMAP_GSID: 1524c5c4113dSnw141292 if (gh->retlist[i].rid) 15253ee87bcaSJulian Pullen *gh->retlist[i].rid = 15263ee87bcaSJulian Pullen res_id->idmap_id_u.sid.rid; 1527c5c4113dSnw141292 if (gh->retlist[i].sidprefix) { 15283ee87bcaSJulian Pullen if (res_id->idmap_id_u.sid.prefix == NULL || 15293ee87bcaSJulian Pullen *res_id->idmap_id_u.sid.prefix == '\0') { 1530c5c4113dSnw141292 *gh->retlist[i].sidprefix = NULL; 1531c5c4113dSnw141292 break; 1532c5c4113dSnw141292 } 1533c5c4113dSnw141292 *gh->retlist[i].sidprefix = 15343ee87bcaSJulian Pullen strdup(res_id->idmap_id_u.sid.prefix); 1535c5c4113dSnw141292 if (*gh->retlist[i].sidprefix == NULL) 1536c5c4113dSnw141292 *gh->retlist[i].stat = 1537c5c4113dSnw141292 IDMAP_ERR_MEMORY; 1538c5c4113dSnw141292 } 15393ee87bcaSJulian Pullen if (res.ids.ids_val[i].retcode == IDMAP_SUCCESS && 15403ee87bcaSJulian Pullen gh->retlist[i].cache_res) { 15413ee87bcaSJulian Pullen if (req_id->idtype == IDMAP_UID) 15423ee87bcaSJulian Pullen idmap_cache_add_sid2uid( 15433ee87bcaSJulian Pullen res_id->idmap_id_u.sid.prefix, 15443ee87bcaSJulian Pullen res_id->idmap_id_u.sid.rid, 15453ee87bcaSJulian Pullen req_id->idmap_id_u.uid, 15463ee87bcaSJulian Pullen direction); 15473ee87bcaSJulian Pullen else /* req_id->idtype == IDMAP_GID */ 15483ee87bcaSJulian Pullen idmap_cache_add_sid2gid( 15493ee87bcaSJulian Pullen res_id->idmap_id_u.sid.prefix, 15503ee87bcaSJulian Pullen res_id->idmap_id_u.sid.rid, 15513ee87bcaSJulian Pullen req_id->idmap_id_u.gid, 15523ee87bcaSJulian Pullen direction); 15533ee87bcaSJulian Pullen } 1554c5c4113dSnw141292 break; 15553ee87bcaSJulian Pullen 1556c5c4113dSnw141292 case IDMAP_NONE: 1557c5c4113dSnw141292 break; 15583ee87bcaSJulian Pullen 1559c5c4113dSnw141292 default: 1560c5c4113dSnw141292 *gh->retlist[i].stat = IDMAP_ERR_NORESULT; 1561c5c4113dSnw141292 break; 1562c5c4113dSnw141292 } 1563148c5f43SAlan Wright if (gh->retlist[i].info != NULL) { 1564148c5f43SAlan Wright idmap_info_mov(gh->retlist[i].info, 156548258c6bSjp151216 &res.ids.ids_val[i].info); 1566c5c4113dSnw141292 } 1567148c5f43SAlan Wright } 1568c5c4113dSnw141292 retcode = IDMAP_SUCCESS; 1569c5c4113dSnw141292 1570c5c4113dSnw141292 out: 1571651c0131Sbaban _IDMAP_RESET_GET_HANDLE(gh); 1572c5c4113dSnw141292 (void) xdr_free(xdr_idmap_ids_res, (caddr_t)&res); 1573c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1574c5c4113dSnw141292 return (retcode); 1575c5c4113dSnw141292 } 1576c5c4113dSnw141292 1577c5c4113dSnw141292 1578c5c4113dSnw141292 /* 1579c5c4113dSnw141292 * Destroy the "get mapping" handle 1580c5c4113dSnw141292 */ 1581c5c4113dSnw141292 void 1582cd37da74Snw141292 idmap_get_destroy(idmap_get_handle_t *gh) 1583cd37da74Snw141292 { 1584c5c4113dSnw141292 if (gh == NULL) 1585c5c4113dSnw141292 return; 1586c5c4113dSnw141292 (void) xdr_free(xdr_idmap_mapping_batch, (caddr_t)&gh->batch); 1587c5c4113dSnw141292 if (gh->retlist) 1588c5c4113dSnw141292 free(gh->retlist); 1589c5c4113dSnw141292 free(gh); 1590c5c4113dSnw141292 } 1591c5c4113dSnw141292 1592c5c4113dSnw141292 1593c5c4113dSnw141292 /* 1594c5c4113dSnw141292 * Get windows to unix mapping 1595c5c4113dSnw141292 */ 1596c5c4113dSnw141292 idmap_stat 15971fdeec65Sjoyce mcintosh idmap_get_w2u_mapping( 1598c5c4113dSnw141292 const char *sidprefix, idmap_rid_t *rid, 1599c5c4113dSnw141292 const char *winname, const char *windomain, 1600cd37da74Snw141292 int flag, int *is_user, int *is_wuser, 160148258c6bSjp151216 uid_t *pid, char **unixname, int *direction, idmap_info *info) 1602cd37da74Snw141292 { 1603c5c4113dSnw141292 idmap_mapping request, *mapping; 1604c5c4113dSnw141292 idmap_mappings_res result; 1605c5c4113dSnw141292 idmap_retcode retcode, rc; 1606c5c4113dSnw141292 1607c5c4113dSnw141292 (void) memset(&request, 0, sizeof (request)); 1608c5c4113dSnw141292 (void) memset(&result, 0, sizeof (result)); 1609c5c4113dSnw141292 1610c5c4113dSnw141292 if (pid) 1611c5c4113dSnw141292 *pid = UINT32_MAX; 1612c5c4113dSnw141292 if (unixname) 1613c5c4113dSnw141292 *unixname = NULL; 1614c5c4113dSnw141292 if (direction) 1615651c0131Sbaban *direction = IDMAP_DIRECTION_UNDEF; 1616c5c4113dSnw141292 1617c5c4113dSnw141292 request.flag = flag; 1618c5c4113dSnw141292 request.id1.idtype = IDMAP_SID; 1619c5c4113dSnw141292 if (sidprefix && rid) { 1620c5c4113dSnw141292 request.id1.idmap_id_u.sid.prefix = (char *)sidprefix; 1621c5c4113dSnw141292 request.id1.idmap_id_u.sid.rid = *rid; 1622c5c4113dSnw141292 } else if (winname) { 16238e228215Sdm199847 retcode = idmap_strdupnull(&request.id1name, winname); 1624c5a946baSbaban if (retcode != IDMAP_SUCCESS) 1625c5c4113dSnw141292 goto out; 16268e228215Sdm199847 16278e228215Sdm199847 retcode = idmap_strdupnull(&request.id1domain, windomain); 1628c5a946baSbaban if (retcode != IDMAP_SUCCESS) 16298e228215Sdm199847 goto out; 16308e228215Sdm199847 1631c5c4113dSnw141292 request.id1.idmap_id_u.sid.prefix = NULL; 1632c5c4113dSnw141292 } else { 1633c5c4113dSnw141292 errno = EINVAL; 1634c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1635c5c4113dSnw141292 } 1636c5c4113dSnw141292 1637cd37da74Snw141292 if (*is_user == 1) 1638c5c4113dSnw141292 request.id2.idtype = IDMAP_UID; 1639c5c4113dSnw141292 else if (*is_user == 0) 1640c5c4113dSnw141292 request.id2.idtype = IDMAP_GID; 1641c5c4113dSnw141292 else 1642c5c4113dSnw141292 request.id2.idtype = IDMAP_POSIXID; 1643c5c4113dSnw141292 1644cd37da74Snw141292 if (*is_wuser == 1) 1645cd37da74Snw141292 request.id1.idtype = IDMAP_USID; 1646cd37da74Snw141292 else if (*is_wuser == 0) 1647cd37da74Snw141292 request.id1.idtype = IDMAP_GSID; 1648cd37da74Snw141292 else 1649cd37da74Snw141292 request.id1.idtype = IDMAP_SID; 1650cd37da74Snw141292 16511fdeec65Sjoyce mcintosh retcode = _idmap_clnt_call(IDMAP_GET_MAPPED_ID_BY_NAME, 1652c5c4113dSnw141292 (xdrproc_t)xdr_idmap_mapping, (caddr_t)&request, 1653c5c4113dSnw141292 (xdrproc_t)xdr_idmap_mappings_res, (caddr_t)&result, 1654c5c4113dSnw141292 TIMEOUT); 1655c5c4113dSnw141292 16561fdeec65Sjoyce mcintosh if (retcode != IDMAP_SUCCESS) 1657*29d55245SJerry Jelinek goto out; 1658c5c4113dSnw141292 1659c5c4113dSnw141292 retcode = result.retcode; 1660c5c4113dSnw141292 1661c5c4113dSnw141292 if ((mapping = result.mappings.mappings_val) == NULL) { 1662c5c4113dSnw141292 if (retcode == IDMAP_SUCCESS) 1663c5c4113dSnw141292 retcode = IDMAP_ERR_NORESULT; 1664c5c4113dSnw141292 goto out; 1665c5c4113dSnw141292 } 1666c5c4113dSnw141292 1667148c5f43SAlan Wright if (info != NULL) 1668148c5f43SAlan Wright idmap_info_mov(info, &mapping->info); 1669148c5f43SAlan Wright 167062c60062Sbaban if (mapping->id2.idtype == IDMAP_UID) { 1671cd37da74Snw141292 *is_user = 1; 167262c60062Sbaban } else if (mapping->id2.idtype == IDMAP_GID) { 1673cd37da74Snw141292 *is_user = 0; 167462c60062Sbaban } else { 167562c60062Sbaban goto out; 167662c60062Sbaban } 1677cd37da74Snw141292 1678cd37da74Snw141292 if (mapping->id1.idtype == IDMAP_USID) { 1679cd37da74Snw141292 *is_wuser = 1; 1680cd37da74Snw141292 } else if (mapping->id1.idtype == IDMAP_GSID) { 1681cd37da74Snw141292 *is_wuser = 0; 1682cd37da74Snw141292 } else { 1683cd37da74Snw141292 goto out; 1684cd37da74Snw141292 } 1685cd37da74Snw141292 1686c5c4113dSnw141292 if (direction) 1687c5c4113dSnw141292 *direction = mapping->direction; 1688c5c4113dSnw141292 if (pid) 1689c5c4113dSnw141292 *pid = mapping->id2.idmap_id_u.uid; 16908e228215Sdm199847 16918e228215Sdm199847 rc = idmap_strdupnull(unixname, mapping->id2name); 1692c5c4113dSnw141292 if (rc != IDMAP_SUCCESS) 1693c5c4113dSnw141292 retcode = rc; 1694c5c4113dSnw141292 1695c5c4113dSnw141292 out: 1696f7b4b2feSjp151216 if (request.id1name != NULL) 1697f7b4b2feSjp151216 free(request.id1name); 1698f7b4b2feSjp151216 if (request.id1domain != NULL) 1699f7b4b2feSjp151216 free(request.id1domain); 1700c5c4113dSnw141292 xdr_free(xdr_idmap_mappings_res, (caddr_t)&result); 1701c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 1702c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1703c5c4113dSnw141292 return (retcode); 1704c5c4113dSnw141292 } 1705c5c4113dSnw141292 1706c5c4113dSnw141292 1707c5c4113dSnw141292 /* 1708c5c4113dSnw141292 * Get unix to windows mapping 1709c5c4113dSnw141292 */ 1710c5c4113dSnw141292 idmap_stat 17111fdeec65Sjoyce mcintosh idmap_get_u2w_mapping( 1712c5c4113dSnw141292 uid_t *pid, const char *unixname, 1713cd37da74Snw141292 int flag, int is_user, int *is_wuser, 1714c5c4113dSnw141292 char **sidprefix, idmap_rid_t *rid, 1715c5c4113dSnw141292 char **winname, char **windomain, 171648258c6bSjp151216 int *direction, idmap_info *info) 1717cd37da74Snw141292 { 1718c5c4113dSnw141292 idmap_mapping request, *mapping; 1719c5c4113dSnw141292 idmap_mappings_res result; 1720c5c4113dSnw141292 idmap_retcode retcode, rc; 1721c5c4113dSnw141292 1722c5c4113dSnw141292 if (sidprefix) 1723c5c4113dSnw141292 *sidprefix = NULL; 1724c5c4113dSnw141292 if (winname) 1725c5c4113dSnw141292 *winname = NULL; 1726c5c4113dSnw141292 if (windomain) 1727c5c4113dSnw141292 *windomain = NULL; 1728c5c4113dSnw141292 if (rid) 1729c5c4113dSnw141292 *rid = UINT32_MAX; 1730c5c4113dSnw141292 if (direction) 1731651c0131Sbaban *direction = IDMAP_DIRECTION_UNDEF; 1732c5c4113dSnw141292 1733c5c4113dSnw141292 (void) memset(&request, 0, sizeof (request)); 1734c5c4113dSnw141292 (void) memset(&result, 0, sizeof (result)); 1735c5c4113dSnw141292 1736c5c4113dSnw141292 request.flag = flag; 1737c5c4113dSnw141292 request.id1.idtype = is_user?IDMAP_UID:IDMAP_GID; 1738c5c4113dSnw141292 1739c5c4113dSnw141292 if (pid && *pid != UINT32_MAX) { 1740c5c4113dSnw141292 request.id1.idmap_id_u.uid = *pid; 1741c5c4113dSnw141292 } else if (unixname) { 17428e228215Sdm199847 request.id1name = (char *)unixname; 1743c5c4113dSnw141292 request.id1.idmap_id_u.uid = UINT32_MAX; 1744c5c4113dSnw141292 } else { 1745c5c4113dSnw141292 errno = EINVAL; 1746c5c4113dSnw141292 return (IDMAP_ERR_ARG); 1747c5c4113dSnw141292 } 1748c5c4113dSnw141292 1749cd37da74Snw141292 if (is_wuser == NULL) 1750c5c4113dSnw141292 request.id2.idtype = IDMAP_SID; 1751cd37da74Snw141292 else if (*is_wuser == -1) 1752cd37da74Snw141292 request.id2.idtype = IDMAP_SID; 1753cd37da74Snw141292 else if (*is_wuser == 0) 1754cd37da74Snw141292 request.id2.idtype = IDMAP_GSID; 1755cd37da74Snw141292 else if (*is_wuser == 1) 1756cd37da74Snw141292 request.id2.idtype = IDMAP_USID; 1757c5c4113dSnw141292 17581fdeec65Sjoyce mcintosh retcode = _idmap_clnt_call(IDMAP_GET_MAPPED_ID_BY_NAME, 1759c5c4113dSnw141292 (xdrproc_t)xdr_idmap_mapping, (caddr_t)&request, 1760c5c4113dSnw141292 (xdrproc_t)xdr_idmap_mappings_res, (caddr_t)&result, 1761c5c4113dSnw141292 TIMEOUT); 1762c5c4113dSnw141292 17631fdeec65Sjoyce mcintosh if (retcode != IDMAP_SUCCESS) 17641fdeec65Sjoyce mcintosh return (retcode); 1765c5c4113dSnw141292 1766c5c4113dSnw141292 retcode = result.retcode; 1767c5c4113dSnw141292 1768c5c4113dSnw141292 if ((mapping = result.mappings.mappings_val) == NULL) { 1769c5c4113dSnw141292 if (retcode == IDMAP_SUCCESS) 1770c5c4113dSnw141292 retcode = IDMAP_ERR_NORESULT; 1771c5c4113dSnw141292 goto out; 1772c5c4113dSnw141292 } 1773c5c4113dSnw141292 1774148c5f43SAlan Wright if (info != NULL) 1775148c5f43SAlan Wright idmap_info_mov(info, &mapping->info); 1776148c5f43SAlan Wright 1777cd37da74Snw141292 if (direction != NULL) 1778c5c4113dSnw141292 *direction = mapping->direction; 1779cd37da74Snw141292 178048258c6bSjp151216 if (is_wuser != NULL) { 178148258c6bSjp151216 if (mapping->id2.idtype == IDMAP_USID) 178248258c6bSjp151216 *is_wuser = 1; 178348258c6bSjp151216 else if (mapping->id2.idtype == IDMAP_GSID) 178448258c6bSjp151216 *is_wuser = 0; 178548258c6bSjp151216 else 178648258c6bSjp151216 *is_wuser = -1; 178748258c6bSjp151216 } 1788cd37da74Snw141292 17898edda628Sbaban if (sidprefix && mapping->id2.idmap_id_u.sid.prefix && 17908edda628Sbaban *mapping->id2.idmap_id_u.sid.prefix != '\0') { 1791c5c4113dSnw141292 *sidprefix = strdup(mapping->id2.idmap_id_u.sid.prefix); 1792c5c4113dSnw141292 if (*sidprefix == NULL) { 1793c5c4113dSnw141292 retcode = IDMAP_ERR_MEMORY; 1794c5c4113dSnw141292 goto errout; 1795c5c4113dSnw141292 } 1796c5c4113dSnw141292 } 1797c5c4113dSnw141292 if (rid) 1798c5c4113dSnw141292 *rid = mapping->id2.idmap_id_u.sid.rid; 17998e228215Sdm199847 18008e228215Sdm199847 rc = idmap_strdupnull(winname, mapping->id2name); 18018e228215Sdm199847 if (rc != IDMAP_SUCCESS) 1802c5c4113dSnw141292 retcode = rc; 18038e228215Sdm199847 18048e228215Sdm199847 rc = idmap_strdupnull(windomain, mapping->id2domain); 18058e228215Sdm199847 if (rc != IDMAP_SUCCESS) 1806c5c4113dSnw141292 retcode = rc; 1807c5c4113dSnw141292 1808c5c4113dSnw141292 goto out; 1809c5c4113dSnw141292 1810c5c4113dSnw141292 errout: 1811c5c4113dSnw141292 if (sidprefix && *sidprefix) { 1812c5c4113dSnw141292 free(*sidprefix); 1813c5c4113dSnw141292 *sidprefix = NULL; 1814c5c4113dSnw141292 } 1815c5c4113dSnw141292 if (winname && *winname) { 1816c5c4113dSnw141292 free(*winname); 1817c5c4113dSnw141292 *winname = NULL; 1818c5c4113dSnw141292 } 1819c5c4113dSnw141292 if (windomain && *windomain) { 1820c5c4113dSnw141292 free(*windomain); 1821c5c4113dSnw141292 *windomain = NULL; 1822c5c4113dSnw141292 } 1823c5c4113dSnw141292 1824c5c4113dSnw141292 out: 1825c5c4113dSnw141292 xdr_free(xdr_idmap_mappings_res, (caddr_t)&result); 1826c5c4113dSnw141292 if (retcode != IDMAP_SUCCESS) 1827c5c4113dSnw141292 errno = idmap_stat2errno(retcode); 1828c5c4113dSnw141292 return (retcode); 1829c5c4113dSnw141292 } 1830c5c4113dSnw141292 1831c5c4113dSnw141292 1832c5c4113dSnw141292 1833c5c4113dSnw141292 #define gettext(s) s 1834c5c4113dSnw141292 static stat_table_t stattable[] = { 1835c5c4113dSnw141292 {IDMAP_SUCCESS, gettext("Success"), 0}, 1836c5c4113dSnw141292 {IDMAP_NEXT, gettext("More results available"), 0}, 1837c5c4113dSnw141292 {IDMAP_ERR_OTHER, gettext("Undefined error"), EINVAL}, 1838c5c4113dSnw141292 {IDMAP_ERR_INTERNAL, gettext("Internal error"), EINVAL}, 1839c5c4113dSnw141292 {IDMAP_ERR_MEMORY, gettext("Out of memory"), ENOMEM}, 1840c5c4113dSnw141292 {IDMAP_ERR_NORESULT, gettext("No results available"), EINVAL}, 1841c5c4113dSnw141292 {IDMAP_ERR_NOTUSER, gettext("Not a user"), EINVAL}, 1842c5c4113dSnw141292 {IDMAP_ERR_NOTGROUP, gettext("Not a group"), EINVAL}, 1843651c0131Sbaban {IDMAP_ERR_NOTSUPPORTED, gettext("Operation not supported"), ENOTSUP}, 1844c5c4113dSnw141292 {IDMAP_ERR_W2U_NAMERULE, 1845c5c4113dSnw141292 gettext("Invalid Windows to UNIX name-based rule"), EINVAL}, 1846c5c4113dSnw141292 {IDMAP_ERR_U2W_NAMERULE, 1847c5c4113dSnw141292 gettext("Invalid UNIX to Windows name-based rule"), EINVAL}, 1848c5c4113dSnw141292 {IDMAP_ERR_CACHE, gettext("Invalid cache"), EINVAL}, 1849c5c4113dSnw141292 {IDMAP_ERR_DB, gettext("Invalid database"), EINVAL}, 1850c5c4113dSnw141292 {IDMAP_ERR_ARG, gettext("Invalid argument"), EINVAL}, 1851c5c4113dSnw141292 {IDMAP_ERR_SID, gettext("Invalid SID"), EINVAL}, 1852c5c4113dSnw141292 {IDMAP_ERR_IDTYPE, gettext("Invalid identity type"), EINVAL}, 1853651c0131Sbaban {IDMAP_ERR_RPC_HANDLE, gettext("Bad RPC handle"), EBADF}, 1854c5c4113dSnw141292 {IDMAP_ERR_RPC, gettext("RPC error"), EINVAL}, 1855c5c4113dSnw141292 {IDMAP_ERR_CLIENT_HANDLE, gettext("Bad client handle"), EINVAL}, 1856651c0131Sbaban {IDMAP_ERR_BUSY, gettext("Server is busy"), EBUSY}, 18578edda628Sbaban {IDMAP_ERR_PERMISSION_DENIED, gettext("Permission denied"), EACCES}, 1858c5c4113dSnw141292 {IDMAP_ERR_NOMAPPING, 1859c5c4113dSnw141292 gettext("Mapping not found or inhibited"), EINVAL}, 1860c5c4113dSnw141292 {IDMAP_ERR_NEW_ID_ALLOC_REQD, 1861c5c4113dSnw141292 gettext("New mapping needs to be created"), EINVAL}, 1862c5c4113dSnw141292 {IDMAP_ERR_DOMAIN, gettext("Invalid domain"), EINVAL}, 1863c5c4113dSnw141292 {IDMAP_ERR_SECURITY, gettext("Security issue"), EINVAL}, 1864c5c4113dSnw141292 {IDMAP_ERR_NOTFOUND, gettext("Not found"), EINVAL}, 1865c5c4113dSnw141292 {IDMAP_ERR_DOMAIN_NOTFOUND, gettext("Domain not found"), EINVAL}, 1866c5c4113dSnw141292 {IDMAP_ERR_UPDATE_NOTALLOWED, gettext("Update not allowed"), EINVAL}, 1867c5c4113dSnw141292 {IDMAP_ERR_CFG, gettext("Configuration error"), EINVAL}, 1868c5c4113dSnw141292 {IDMAP_ERR_CFG_CHANGE, gettext("Invalid configuration change"), EINVAL}, 1869c5c4113dSnw141292 {IDMAP_ERR_NOTMAPPED_WELLKNOWN, 1870c5c4113dSnw141292 gettext("No mapping for well-known SID"), EINVAL}, 1871c5c4113dSnw141292 {IDMAP_ERR_RETRIABLE_NET_ERR, 187262c60062Sbaban gettext("Windows lookup failed"), EINVAL}, 187362c60062Sbaban {IDMAP_ERR_W2U_NAMERULE_CONFLICT, 187462c60062Sbaban gettext("Duplicate rule or conflicts with an existing " 187562c60062Sbaban "Windows to UNIX name-based rule"), EINVAL}, 187662c60062Sbaban {IDMAP_ERR_U2W_NAMERULE_CONFLICT, 187762c60062Sbaban gettext("Duplicate rule or conflicts with an existing " 187862c60062Sbaban "Unix to Windows name-based rule"), EINVAL}, 18790dcc7149Snw141292 {IDMAP_ERR_BAD_UTF8, 18800dcc7149Snw141292 gettext("Invalid or illegal UTF-8 sequence found in " 18810dcc7149Snw141292 "a given Windows entity name or domain name"), EINVAL}, 18824d61c878SJulian Pullen {IDMAP_ERR_NONE_GENERATED, 188348258c6bSjp151216 gettext("Mapping not found and none created (see -c option)"), 188448258c6bSjp151216 EINVAL}, 1885479ac375Sdm199847 {IDMAP_ERR_PROP_UNKNOWN, 1886479ac375Sdm199847 gettext("Undefined property"), 1887479ac375Sdm199847 EINVAL}, 1888479ac375Sdm199847 {IDMAP_ERR_NS_LDAP_CFG, 1889479ac375Sdm199847 gettext("Native LDAP configuration error"), EINVAL}, 1890479ac375Sdm199847 {IDMAP_ERR_NS_LDAP_PARTIAL, 1891479ac375Sdm199847 gettext("Partial result from Native LDAP"), EINVAL}, 1892479ac375Sdm199847 {IDMAP_ERR_NS_LDAP_OP_FAILED, 1893479ac375Sdm199847 gettext("Native LDAP operation failed"), EINVAL}, 1894479ac375Sdm199847 {IDMAP_ERR_NS_LDAP_BAD_WINNAME, 1895479ac375Sdm199847 gettext("Improper winname form found in Native LDAP"), EINVAL}, 18964d61c878SJulian Pullen {IDMAP_ERR_NO_ACTIVEDIRECTORY, 18974d61c878SJulian Pullen gettext("No AD servers"), 18984d61c878SJulian Pullen EINVAL}, 1899c5c4113dSnw141292 {-1, NULL, 0} 1900c5c4113dSnw141292 }; 1901c5c4113dSnw141292 #undef gettext 1902c5c4113dSnw141292 1903c5c4113dSnw141292 1904c5c4113dSnw141292 /* 1905c5c4113dSnw141292 * Get description of status code 1906c5c4113dSnw141292 * 1907c5c4113dSnw141292 * Input: 1908c5c4113dSnw141292 * status - Status code returned by libidmap API call 1909c5c4113dSnw141292 * 1910c5c4113dSnw141292 * Return Value: 1911c5c4113dSnw141292 * human-readable localized description of idmap_stat 1912c5c4113dSnw141292 */ 1913c5c4113dSnw141292 const char * 19141fdeec65Sjoyce mcintosh idmap_stat2string(idmap_stat status) 1915cd37da74Snw141292 { 1916c5c4113dSnw141292 int i; 1917c5c4113dSnw141292 1918c5c4113dSnw141292 for (i = 0; stattable[i].msg; i++) { 1919c5c4113dSnw141292 if (stattable[i].retcode == status) 19201fcced4cSJordan Brown return (dgettext(TEXT_DOMAIN, stattable[i].msg)); 1921c5c4113dSnw141292 } 19221fcced4cSJordan Brown return (dgettext(TEXT_DOMAIN, "Unknown error")); 1923c5c4113dSnw141292 } 1924c5c4113dSnw141292 1925c5c4113dSnw141292 1926c5c4113dSnw141292 static int 1927cd37da74Snw141292 idmap_stat2errno(idmap_stat stat) 1928cd37da74Snw141292 { 1929c5c4113dSnw141292 int i; 1930c5c4113dSnw141292 for (i = 0; stattable[i].msg; i++) { 1931c5c4113dSnw141292 if (stattable[i].retcode == stat) 1932c5c4113dSnw141292 return (stattable[i].errnum); 1933c5c4113dSnw141292 } 1934c5c4113dSnw141292 return (EINVAL); 1935c5c4113dSnw141292 } 1936c5c4113dSnw141292 1937c5c4113dSnw141292 1938c5c4113dSnw141292 /* 1939c5c4113dSnw141292 * Get status code from string 1940c5c4113dSnw141292 */ 1941c5c4113dSnw141292 idmap_stat 1942cd37da74Snw141292 idmap_string2stat(const char *str) 1943cd37da74Snw141292 { 1944c5c4113dSnw141292 if (str == NULL) 1945c5c4113dSnw141292 return (IDMAP_ERR_INTERNAL); 1946c5c4113dSnw141292 1947c5c4113dSnw141292 #define return_cmp(a) \ 1948c5c4113dSnw141292 if (0 == strcmp(str, "IDMAP_ERR_" #a)) \ 1949c5c4113dSnw141292 return (IDMAP_ERR_ ## a); 1950c5c4113dSnw141292 1951c5c4113dSnw141292 return_cmp(OTHER); 1952c5c4113dSnw141292 return_cmp(INTERNAL); 1953c5c4113dSnw141292 return_cmp(MEMORY); 1954c5c4113dSnw141292 return_cmp(NORESULT); 1955c5c4113dSnw141292 return_cmp(NOTUSER); 1956c5c4113dSnw141292 return_cmp(NOTGROUP); 1957c5c4113dSnw141292 return_cmp(NOTSUPPORTED); 1958c5c4113dSnw141292 return_cmp(W2U_NAMERULE); 1959c5c4113dSnw141292 return_cmp(U2W_NAMERULE); 1960c5c4113dSnw141292 return_cmp(CACHE); 1961c5c4113dSnw141292 return_cmp(DB); 1962c5c4113dSnw141292 return_cmp(ARG); 1963c5c4113dSnw141292 return_cmp(SID); 1964c5c4113dSnw141292 return_cmp(IDTYPE); 1965c5c4113dSnw141292 return_cmp(RPC_HANDLE); 1966c5c4113dSnw141292 return_cmp(RPC); 1967c5c4113dSnw141292 return_cmp(CLIENT_HANDLE); 1968c5c4113dSnw141292 return_cmp(BUSY); 1969c5c4113dSnw141292 return_cmp(PERMISSION_DENIED); 1970c5c4113dSnw141292 return_cmp(NOMAPPING); 1971c5c4113dSnw141292 return_cmp(NEW_ID_ALLOC_REQD); 1972c5c4113dSnw141292 return_cmp(DOMAIN); 1973c5c4113dSnw141292 return_cmp(SECURITY); 1974c5c4113dSnw141292 return_cmp(NOTFOUND); 1975c5c4113dSnw141292 return_cmp(DOMAIN_NOTFOUND); 1976c5c4113dSnw141292 return_cmp(MEMORY); 1977c5c4113dSnw141292 return_cmp(UPDATE_NOTALLOWED); 1978c5c4113dSnw141292 return_cmp(CFG); 1979c5c4113dSnw141292 return_cmp(CFG_CHANGE); 1980c5c4113dSnw141292 return_cmp(NOTMAPPED_WELLKNOWN); 1981c5c4113dSnw141292 return_cmp(RETRIABLE_NET_ERR); 198262c60062Sbaban return_cmp(W2U_NAMERULE_CONFLICT); 198362c60062Sbaban return_cmp(U2W_NAMERULE_CONFLICT); 1984479ac375Sdm199847 return_cmp(BAD_UTF8); 19854d61c878SJulian Pullen return_cmp(NONE_GENERATED); 1986479ac375Sdm199847 return_cmp(PROP_UNKNOWN); 1987479ac375Sdm199847 return_cmp(NS_LDAP_CFG); 1988479ac375Sdm199847 return_cmp(NS_LDAP_PARTIAL); 1989479ac375Sdm199847 return_cmp(NS_LDAP_OP_FAILED); 1990479ac375Sdm199847 return_cmp(NS_LDAP_BAD_WINNAME); 19914d61c878SJulian Pullen return_cmp(NO_ACTIVEDIRECTORY); 1992c5c4113dSnw141292 #undef return_cmp 1993c5c4113dSnw141292 1994c5c4113dSnw141292 return (IDMAP_ERR_OTHER); 1995c5c4113dSnw141292 } 1996c5c4113dSnw141292 1997c5c4113dSnw141292 1998c5c4113dSnw141292 /* 1999c5c4113dSnw141292 * Map the given status to one that can be returned by the protocol 2000c5c4113dSnw141292 */ 2001c5c4113dSnw141292 idmap_stat 2002cd37da74Snw141292 idmap_stat4prot(idmap_stat status) 2003cd37da74Snw141292 { 2004c5c4113dSnw141292 switch (status) { 2005c5c4113dSnw141292 case IDMAP_ERR_MEMORY: 2006c5c4113dSnw141292 case IDMAP_ERR_CACHE: 2007c5c4113dSnw141292 return (IDMAP_ERR_INTERNAL); 2008c5c4113dSnw141292 } 2009c5c4113dSnw141292 return (status); 2010c5c4113dSnw141292 } 2011dd5829d1Sbaban 2012dd5829d1Sbaban 2013dd5829d1Sbaban /* 2014c5a946baSbaban * This is a convenience routine which duplicates a string after 2015c5a946baSbaban * checking for NULL pointers. This function will return success if 2016c5a946baSbaban * either the 'to' OR 'from' pointers are NULL. 20178e228215Sdm199847 */ 20188e228215Sdm199847 static idmap_stat 2019cd37da74Snw141292 idmap_strdupnull(char **to, const char *from) 2020cd37da74Snw141292 { 2021c5a946baSbaban if (to == NULL) 2022c5a946baSbaban return (IDMAP_SUCCESS); 2023c5a946baSbaban 20248e228215Sdm199847 if (from == NULL || *from == '\0') { 20258e228215Sdm199847 *to = NULL; 20268e228215Sdm199847 return (IDMAP_SUCCESS); 20278e228215Sdm199847 } 20288e228215Sdm199847 20298e228215Sdm199847 *to = strdup(from); 20308e228215Sdm199847 if (*to == NULL) 20318e228215Sdm199847 return (IDMAP_ERR_MEMORY); 20328e228215Sdm199847 return (IDMAP_SUCCESS); 20338e228215Sdm199847 } 20348e228215Sdm199847 203548258c6bSjp151216 20368e228215Sdm199847 idmap_stat 2037cd37da74Snw141292 idmap_namerule_cpy(idmap_namerule *to, idmap_namerule *from) 2038cd37da74Snw141292 { 20398e228215Sdm199847 idmap_stat retval; 20408e228215Sdm199847 204148258c6bSjp151216 if (to == NULL) 204248258c6bSjp151216 return (IDMAP_SUCCESS); 204348258c6bSjp151216 20448e228215Sdm199847 (void) memcpy(to, from, sizeof (idmap_namerule)); 204548258c6bSjp151216 to->windomain = NULL; 204648258c6bSjp151216 to->winname = NULL; 204748258c6bSjp151216 to->unixname = NULL; 20488e228215Sdm199847 20498e228215Sdm199847 retval = idmap_strdupnull(&to->windomain, from->windomain); 20508e228215Sdm199847 if (retval != IDMAP_SUCCESS) 20518e228215Sdm199847 return (retval); 20528e228215Sdm199847 20538e228215Sdm199847 retval = idmap_strdupnull(&to->winname, from->winname); 205448258c6bSjp151216 if (retval != IDMAP_SUCCESS) { 205548258c6bSjp151216 free(to->windomain); 205648258c6bSjp151216 to->windomain = NULL; 205748258c6bSjp151216 return (retval); 205848258c6bSjp151216 } 205948258c6bSjp151216 206048258c6bSjp151216 retval = idmap_strdupnull(&to->unixname, from->unixname); 206148258c6bSjp151216 if (retval != IDMAP_SUCCESS) { 206248258c6bSjp151216 free(to->windomain); 206348258c6bSjp151216 to->windomain = NULL; 206448258c6bSjp151216 free(to->winname); 206548258c6bSjp151216 to->winname = NULL; 206648258c6bSjp151216 return (retval); 206748258c6bSjp151216 } 206848258c6bSjp151216 206948258c6bSjp151216 return (retval); 207048258c6bSjp151216 } 207148258c6bSjp151216 207248258c6bSjp151216 207348258c6bSjp151216 /* 2074148c5f43SAlan Wright * Move the contents of the "info" structure from "from" to "to". 207548258c6bSjp151216 */ 2076148c5f43SAlan Wright void 207748258c6bSjp151216 idmap_info_mov(idmap_info *to, idmap_info *from) 207848258c6bSjp151216 { 207948258c6bSjp151216 (void) memcpy(to, from, sizeof (idmap_info)); 208048258c6bSjp151216 (void) memset(from, 0, sizeof (idmap_info)); 208148258c6bSjp151216 } 208248258c6bSjp151216 208348258c6bSjp151216 208448258c6bSjp151216 void 208548258c6bSjp151216 idmap_info_free(idmap_info *info) 208648258c6bSjp151216 { 208748258c6bSjp151216 if (info == NULL) 208848258c6bSjp151216 return; 208948258c6bSjp151216 2090148c5f43SAlan Wright xdr_free(xdr_idmap_info, (caddr_t)info); 2091148c5f43SAlan Wright (void) memset(info, 0, sizeof (idmap_info)); 209248258c6bSjp151216 } 2093148c5f43SAlan Wright 2094148c5f43SAlan Wright 2095148c5f43SAlan Wright void 2096148c5f43SAlan Wright idmap_how_clear(idmap_how *how) 2097148c5f43SAlan Wright { 2098148c5f43SAlan Wright xdr_free(xdr_idmap_how, (caddr_t)how); 2099148c5f43SAlan Wright (void) memset(how, 0, sizeof (*how)); 210048258c6bSjp151216 } 210148258c6bSjp151216 210248258c6bSjp151216 21038e228215Sdm199847 /* 2104dd5829d1Sbaban * Get uid given Windows name 2105dd5829d1Sbaban */ 2106dd5829d1Sbaban idmap_stat 21073ee87bcaSJulian Pullen idmap_getuidbywinname(const char *name, const char *domain, int flag, 21083ee87bcaSJulian Pullen uid_t *uid) 2109cd37da74Snw141292 { 2110dd5829d1Sbaban idmap_retcode rc; 2111cd37da74Snw141292 int is_user = 1; 2112cd37da74Snw141292 int is_wuser = -1; 21133ee87bcaSJulian Pullen int direction; 2114dd5829d1Sbaban 2115dd5829d1Sbaban if (uid == NULL) 2116dd5829d1Sbaban return (IDMAP_ERR_ARG); 2117dd5829d1Sbaban 21183ee87bcaSJulian Pullen if (flag & IDMAP_REQ_FLG_USE_CACHE) { 21193ee87bcaSJulian Pullen rc = idmap_cache_lookup_uidbywinname(name, domain, uid); 21203ee87bcaSJulian Pullen if (rc == IDMAP_SUCCESS || rc == IDMAP_ERR_MEMORY) 21213ee87bcaSJulian Pullen return (rc); 21223ee87bcaSJulian Pullen } 2123dd5829d1Sbaban /* Get mapping */ 21241fdeec65Sjoyce mcintosh rc = idmap_get_w2u_mapping(NULL, NULL, name, domain, flag, 21253ee87bcaSJulian Pullen &is_user, &is_wuser, uid, NULL, &direction, NULL); 2126dd5829d1Sbaban 21273ee87bcaSJulian Pullen if (rc == IDMAP_SUCCESS && (flag & IDMAP_REQ_FLG_USE_CACHE)) { 21283ee87bcaSJulian Pullen /* If we have not got the domain don't store UID to winname */ 21293ee87bcaSJulian Pullen if (domain == NULL) 21303ee87bcaSJulian Pullen direction = IDMAP_DIRECTION_W2U; 21313ee87bcaSJulian Pullen idmap_cache_add_winname2uid(name, domain, *uid, direction); 21323ee87bcaSJulian Pullen } 21333ee87bcaSJulian Pullen 2134dd5829d1Sbaban return (rc); 2135dd5829d1Sbaban } 2136dd5829d1Sbaban 2137dd5829d1Sbaban 2138dd5829d1Sbaban /* 2139dd5829d1Sbaban * Get gid given Windows name 2140dd5829d1Sbaban */ 2141dd5829d1Sbaban idmap_stat 21423ee87bcaSJulian Pullen idmap_getgidbywinname(const char *name, const char *domain, int flag, 21433ee87bcaSJulian Pullen gid_t *gid) 2144cd37da74Snw141292 { 2145dd5829d1Sbaban idmap_retcode rc; 2146cd37da74Snw141292 int is_user = 0; 2147cd37da74Snw141292 int is_wuser = -1; 21483ee87bcaSJulian Pullen int direction; 2149dd5829d1Sbaban 2150dd5829d1Sbaban if (gid == NULL) 2151dd5829d1Sbaban return (IDMAP_ERR_ARG); 2152dd5829d1Sbaban 21533ee87bcaSJulian Pullen if (flag & IDMAP_REQ_FLG_USE_CACHE) { 21543ee87bcaSJulian Pullen rc = idmap_cache_lookup_gidbywinname(name, domain, gid); 21553ee87bcaSJulian Pullen if (rc == IDMAP_SUCCESS || rc == IDMAP_ERR_MEMORY) 21563ee87bcaSJulian Pullen return (rc); 21573ee87bcaSJulian Pullen } 21583ee87bcaSJulian Pullen 2159dd5829d1Sbaban /* Get mapping */ 21601fdeec65Sjoyce mcintosh rc = idmap_get_w2u_mapping(NULL, NULL, name, domain, flag, 21613ee87bcaSJulian Pullen &is_user, &is_wuser, gid, NULL, &direction, NULL); 2162dd5829d1Sbaban 21633ee87bcaSJulian Pullen if (rc == IDMAP_SUCCESS && (flag & IDMAP_REQ_FLG_USE_CACHE)) { 21643ee87bcaSJulian Pullen /* If we have not got the domain don't store GID to winname */ 21653ee87bcaSJulian Pullen if (domain == NULL) 21663ee87bcaSJulian Pullen direction = IDMAP_DIRECTION_W2U; 21673ee87bcaSJulian Pullen idmap_cache_add_winname2gid(name, domain, *gid, direction); 21683ee87bcaSJulian Pullen } 21693ee87bcaSJulian Pullen 2170dd5829d1Sbaban return (rc); 2171dd5829d1Sbaban } 2172dd5829d1Sbaban 2173dd5829d1Sbaban 2174dd5829d1Sbaban /* 2175dd5829d1Sbaban * Get winname given pid 2176dd5829d1Sbaban */ 21771ed6b69aSGordon Ross idmap_stat 21783ee87bcaSJulian Pullen idmap_getwinnamebypid(uid_t pid, int is_user, int flag, char **name, 21793ee87bcaSJulian Pullen char **domain) 2180cd37da74Snw141292 { 2181dd5829d1Sbaban idmap_retcode rc; 2182dd5829d1Sbaban int len; 2183dd5829d1Sbaban char *winname, *windomain; 21843ee87bcaSJulian Pullen int direction; 2185dd5829d1Sbaban 2186dd5829d1Sbaban if (name == NULL) 2187dd5829d1Sbaban return (IDMAP_ERR_ARG); 2188dd5829d1Sbaban 21893ee87bcaSJulian Pullen if (flag & IDMAP_REQ_FLG_USE_CACHE) { 21903ee87bcaSJulian Pullen if (is_user) 21913ee87bcaSJulian Pullen rc = idmap_cache_lookup_winnamebyuid(&winname, 21923ee87bcaSJulian Pullen &windomain, pid); 21933ee87bcaSJulian Pullen else 21943ee87bcaSJulian Pullen rc = idmap_cache_lookup_winnamebygid(&winname, 21953ee87bcaSJulian Pullen &windomain, pid); 21963ee87bcaSJulian Pullen if (rc == IDMAP_SUCCESS) 21973ee87bcaSJulian Pullen goto out; 21983ee87bcaSJulian Pullen if (rc == IDMAP_ERR_MEMORY) 21993ee87bcaSJulian Pullen return (rc); 22003ee87bcaSJulian Pullen } 22013ee87bcaSJulian Pullen 2202dd5829d1Sbaban /* Get mapping */ 22031fdeec65Sjoyce mcintosh rc = idmap_get_u2w_mapping(&pid, NULL, flag, is_user, NULL, 22043ee87bcaSJulian Pullen NULL, NULL, &winname, &windomain, &direction, NULL); 2205dd5829d1Sbaban 2206dd5829d1Sbaban /* Return on error */ 2207dd5829d1Sbaban if (rc != IDMAP_SUCCESS) 2208dd5829d1Sbaban return (rc); 2209dd5829d1Sbaban 2210dd5829d1Sbaban /* 2211dd5829d1Sbaban * The given PID may have been mapped to a locally 2212dd5829d1Sbaban * generated SID in which case there isn't any 2213dd5829d1Sbaban * Windows name 2214dd5829d1Sbaban */ 22158ce3a038SMarcel Telka if (winname == NULL) { 2216dd5829d1Sbaban idmap_free(windomain); 2217dd5829d1Sbaban return (IDMAP_ERR_NORESULT); 2218dd5829d1Sbaban } 2219dd5829d1Sbaban 22203ee87bcaSJulian Pullen if (flag & IDMAP_REQ_FLG_USE_CACHE) { 22213ee87bcaSJulian Pullen if (is_user) 22223ee87bcaSJulian Pullen idmap_cache_add_winname2uid(winname, windomain, 22233ee87bcaSJulian Pullen pid, direction); 22243ee87bcaSJulian Pullen else 22253ee87bcaSJulian Pullen idmap_cache_add_winname2gid(winname, windomain, 22263ee87bcaSJulian Pullen pid, direction); 22273ee87bcaSJulian Pullen } 22283ee87bcaSJulian Pullen 22293ee87bcaSJulian Pullen out: 2230dd5829d1Sbaban if (domain != NULL) { 2231dd5829d1Sbaban *name = winname; 2232dd5829d1Sbaban *domain = windomain; 2233dd5829d1Sbaban } else { 22348ce3a038SMarcel Telka char *wd = windomain != NULL ? windomain : ""; 22358ce3a038SMarcel Telka len = snprintf(NULL, 0, "%s@%s", winname, wd) + 1; 2236dd5829d1Sbaban if ((*name = malloc(len)) != NULL) 22378ce3a038SMarcel Telka (void) snprintf(*name, len, "%s@%s", winname, wd); 2238dd5829d1Sbaban else 2239dd5829d1Sbaban rc = IDMAP_ERR_MEMORY; 2240dd5829d1Sbaban idmap_free(winname); 2241dd5829d1Sbaban idmap_free(windomain); 2242dd5829d1Sbaban } 22433ee87bcaSJulian Pullen 2244dd5829d1Sbaban return (rc); 2245dd5829d1Sbaban } 2246dd5829d1Sbaban 2247dd5829d1Sbaban 2248dd5829d1Sbaban /* 2249dd5829d1Sbaban * Get winname given uid 2250dd5829d1Sbaban */ 2251dd5829d1Sbaban idmap_stat 22523ee87bcaSJulian Pullen idmap_getwinnamebyuid(uid_t uid, int flag, char **name, char **domain) 2253cd37da74Snw141292 { 22543ee87bcaSJulian Pullen return (idmap_getwinnamebypid(uid, 1, flag, name, domain)); 2255dd5829d1Sbaban } 2256dd5829d1Sbaban 2257dd5829d1Sbaban 2258dd5829d1Sbaban /* 2259dd5829d1Sbaban * Get winname given gid 2260dd5829d1Sbaban */ 2261dd5829d1Sbaban idmap_stat 22623ee87bcaSJulian Pullen idmap_getwinnamebygid(gid_t gid, int flag, char **name, char **domain) 2263cd37da74Snw141292 { 22643ee87bcaSJulian Pullen return (idmap_getwinnamebypid(gid, 0, flag, name, domain)); 2265dd5829d1Sbaban } 22669fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 22679fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States idmap_stat 22681fdeec65Sjoyce mcintosh idmap_flush(idmap_flush_op op) 22699fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States { 22701fdeec65Sjoyce mcintosh idmap_retcode rc1, rc2; 22719fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 22721fdeec65Sjoyce mcintosh rc1 = _idmap_clnt_call(IDMAP_FLUSH, 22739fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States (xdrproc_t)xdr_idmap_flush_op, (caddr_t)&op, 22741fdeec65Sjoyce mcintosh (xdrproc_t)xdr_idmap_retcode, (caddr_t)&rc2, TIMEOUT); 22759fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States 22761fdeec65Sjoyce mcintosh if (rc1 != IDMAP_SUCCESS) 22771fdeec65Sjoyce mcintosh return (rc1); 22781fdeec65Sjoyce mcintosh return (rc2); 22799fb67ea3Safshin salek ardakani - Sun Microsystems - Irvine United States } 2280c5866007SKeyur Desai 2281c5866007SKeyur Desai 2282c5866007SKeyur Desai /* 2283c5866007SKeyur Desai * syslog is the default logger. 2284c5866007SKeyur Desai * It can be overwritten by supplying a logger 2285c5866007SKeyur Desai * with idmap_set_logger() 2286c5866007SKeyur Desai */ 2287c5866007SKeyur Desai idmap_logger_t logger = syslog; 2288c5866007SKeyur Desai 2289c5866007SKeyur Desai 2290c5866007SKeyur Desai void 2291c5866007SKeyur Desai idmap_set_logger(idmap_logger_t funct) 2292c5866007SKeyur Desai { 2293c5866007SKeyur Desai logger = funct; 2294c5866007SKeyur Desai } 2295148c5f43SAlan Wright 2296148c5f43SAlan Wright /* 2297148c5f43SAlan Wright * Helper functions that concatenate two parts of a name and then 2298148c5f43SAlan Wright * look up a value, so that the same set of functions can be used to 2299148c5f43SAlan Wright * process both "in" and "out" parameters. 2300148c5f43SAlan Wright */ 2301148c5f43SAlan Wright static 2302148c5f43SAlan Wright boolean_t 2303148c5f43SAlan Wright idmap_trace_get_str(nvlist_t *entry, char *n1, char *n2, char **ret) 2304148c5f43SAlan Wright { 2305148c5f43SAlan Wright char name[IDMAP_TRACE_NAME_MAX+1]; /* Max used is about 11 */ 2306148c5f43SAlan Wright int err; 2307148c5f43SAlan Wright 2308148c5f43SAlan Wright (void) strlcpy(name, n1, sizeof (name)); 2309148c5f43SAlan Wright if (n2 != NULL) 2310148c5f43SAlan Wright (void) strlcat(name, n2, sizeof (name)); 2311148c5f43SAlan Wright 2312148c5f43SAlan Wright err = nvlist_lookup_string(entry, name, ret); 2313148c5f43SAlan Wright return (err == 0); 2314148c5f43SAlan Wright } 2315148c5f43SAlan Wright 2316148c5f43SAlan Wright static 2317148c5f43SAlan Wright boolean_t 2318148c5f43SAlan Wright idmap_trace_get_int(nvlist_t *entry, char *n1, char *n2, int64_t *ret) 2319148c5f43SAlan Wright { 2320148c5f43SAlan Wright char name[IDMAP_TRACE_NAME_MAX+1]; /* Max used is about 11 */ 2321148c5f43SAlan Wright int err; 2322148c5f43SAlan Wright 2323148c5f43SAlan Wright (void) strlcpy(name, n1, sizeof (name)); 2324148c5f43SAlan Wright if (n2 != NULL) 2325148c5f43SAlan Wright (void) strlcat(name, n2, sizeof (name)); 2326148c5f43SAlan Wright 2327148c5f43SAlan Wright err = nvlist_lookup_int64(entry, name, ret); 2328148c5f43SAlan Wright return (err == 0); 2329148c5f43SAlan Wright } 2330148c5f43SAlan Wright 2331148c5f43SAlan Wright static 2332148c5f43SAlan Wright void 2333148c5f43SAlan Wright idmap_trace_print_id(FILE *out, nvlist_t *entry, char *fromto) 2334148c5f43SAlan Wright { 2335148c5f43SAlan Wright char *s; 2336148c5f43SAlan Wright int64_t i64; 2337148c5f43SAlan Wright 2338148c5f43SAlan Wright if (idmap_trace_get_int(entry, fromto, IDMAP_TRACE_TYPE, &i64)) { 2339148c5f43SAlan Wright switch (i64) { 2340148c5f43SAlan Wright case IDMAP_POSIXID: 2341148c5f43SAlan Wright (void) fprintf(out, "unixname "); 2342148c5f43SAlan Wright break; 2343148c5f43SAlan Wright case IDMAP_UID: 2344148c5f43SAlan Wright (void) fprintf(out, "unixuser "); 2345148c5f43SAlan Wright break; 2346148c5f43SAlan Wright case IDMAP_GID: 2347148c5f43SAlan Wright (void) fprintf(out, "unixgroup "); 2348148c5f43SAlan Wright break; 2349148c5f43SAlan Wright case IDMAP_SID: 2350148c5f43SAlan Wright (void) fprintf(out, "winname "); 2351148c5f43SAlan Wright break; 2352148c5f43SAlan Wright case IDMAP_USID: 2353148c5f43SAlan Wright (void) fprintf(out, "winuser "); 2354148c5f43SAlan Wright break; 2355148c5f43SAlan Wright case IDMAP_GSID: 2356148c5f43SAlan Wright (void) fprintf(out, "wingroup "); 2357148c5f43SAlan Wright break; 2358148c5f43SAlan Wright case IDMAP_NONE: 2359148c5f43SAlan Wright (void) fprintf(out, gettext("unknown ")); 2360148c5f43SAlan Wright break; 2361148c5f43SAlan Wright default: 2362148c5f43SAlan Wright (void) fprintf(out, gettext("bad %d "), (int)i64); 2363148c5f43SAlan Wright break; 2364148c5f43SAlan Wright } 2365148c5f43SAlan Wright } 2366148c5f43SAlan Wright 2367148c5f43SAlan Wright if (idmap_trace_get_str(entry, fromto, IDMAP_TRACE_NAME, &s)) 2368148c5f43SAlan Wright (void) fprintf(out, "%s ", s); 2369148c5f43SAlan Wright 2370148c5f43SAlan Wright if (idmap_trace_get_str(entry, fromto, IDMAP_TRACE_SID, &s)) 2371148c5f43SAlan Wright (void) fprintf(out, "%s ", s); 2372148c5f43SAlan Wright 2373148c5f43SAlan Wright if (idmap_trace_get_int(entry, fromto, IDMAP_TRACE_UNIXID, &i64)) 2374148c5f43SAlan Wright (void) fprintf(out, "%u ", (uid_t)i64); 2375148c5f43SAlan Wright } 2376148c5f43SAlan Wright 2377148c5f43SAlan Wright void 2378148c5f43SAlan Wright idmap_trace_print_1(FILE *out, char *prefix, nvlist_t *entry) 2379148c5f43SAlan Wright { 2380148c5f43SAlan Wright char *s; 2381148c5f43SAlan Wright int64_t i64; 2382148c5f43SAlan Wright 2383148c5f43SAlan Wright (void) fprintf(out, "%s", prefix); 2384148c5f43SAlan Wright idmap_trace_print_id(out, entry, "from"); 2385148c5f43SAlan Wright (void) fprintf(out, "-> "); 2386148c5f43SAlan Wright idmap_trace_print_id(out, entry, "to"); 2387148c5f43SAlan Wright if (idmap_trace_get_int(entry, IDMAP_TRACE_ERROR, NULL, &i64)) 2388148c5f43SAlan Wright (void) fprintf(out, gettext("Error %d "), (int)i64); 2389148c5f43SAlan Wright (void) fprintf(out, "-"); 2390148c5f43SAlan Wright if (idmap_trace_get_str(entry, IDMAP_TRACE_MESSAGE, NULL, &s)) 2391148c5f43SAlan Wright (void) fprintf(out, " %s", s); 2392148c5f43SAlan Wright (void) fprintf(out, "\n"); 2393148c5f43SAlan Wright } 2394148c5f43SAlan Wright 2395148c5f43SAlan Wright void 2396148c5f43SAlan Wright idmap_trace_print(FILE *out, char *prefix, nvlist_t *trace) 2397148c5f43SAlan Wright { 2398148c5f43SAlan Wright nvpair_t *nvp; 2399148c5f43SAlan Wright 2400148c5f43SAlan Wright for (nvp = nvlist_next_nvpair(trace, NULL); 2401148c5f43SAlan Wright nvp != NULL; 2402148c5f43SAlan Wright nvp = nvlist_next_nvpair(trace, nvp)) { 2403148c5f43SAlan Wright nvlist_t *entry; 2404148c5f43SAlan Wright int err; 2405148c5f43SAlan Wright 2406148c5f43SAlan Wright err = nvpair_value_nvlist(nvp, &entry); 2407148c5f43SAlan Wright assert(err == 0); 2408148c5f43SAlan Wright 2409148c5f43SAlan Wright idmap_trace_print_1(out, prefix, entry); 2410148c5f43SAlan Wright } 2411148c5f43SAlan Wright } 2412