server.c revision 148c5f43199ca0b43fc8e3b643aab11cd66ea327
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/*
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * CDDL HEADER START
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw *
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * The contents of this file are subject to the terms of the
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Common Development and Distribution License (the "License").
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * You may not use this file except in compliance with the License.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw *
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * or http://www.opensolaris.org/os/licensing.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * See the License for the specific language governing permissions
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * and limitations under the License.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw *
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * When distributing Covered Code, include this CDDL HEADER in each
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * If applicable, add the following below this CDDL HEADER, with the
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * fields enclosed by brackets "[]" replaced with your own identifying
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * information: Portions Copyright [yyyy] [name of copyright owner]
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw *
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * CDDL HEADER END
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/*
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/*
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Service routines
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include "idmapd.h"
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include "idmap_priv.h"
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban#include "nldaputils.h"
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <signal.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <thread.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <string.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <strings.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <errno.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <assert.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <sys/types.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <sys/stat.h>
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States#include <sys/sid.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <ucred.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <pwd.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <auth_attr.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#include <secdb.h>
0dcc71495bad040a0c83830efc85acf8d897350dnw#include <sys/u8_textprep.h>
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown#include <note.h>
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#define _VALIDATE_LIST_CB_DATA(col, val, siz)\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw retcode = validate_list_cb_data(cb_data, argc, argv, col,\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (uchar_t **)val, siz);\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (retcode == IDMAP_NEXT) {\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = IDMAP_NEXT;\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (0);\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw } else if (retcode < 0) {\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = retcode;\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp#define PROCESS_LIST_SVC_SQL(rcode, db, dbname, sql, limit, flag, cb, res, len)\
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp rcode = process_list_svc_sql(db, dbname, sql, limit, flag, cb, res);\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (rcode == IDMAP_ERR_BUSY)\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw res->retcode = IDMAP_ERR_BUSY;\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw else if (rcode == IDMAP_SUCCESS && len == 0)\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw res->retcode = IDMAP_ERR_NOTFOUND;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm#define STRDUP_OR_FAIL(to, from) \
8e22821528b08c6dba4e8176351560f316f6d0dedm if ((from) == NULL) \
8e22821528b08c6dba4e8176351560f316f6d0dedm to = NULL; \
8e22821528b08c6dba4e8176351560f316f6d0dedm else { \
8e22821528b08c6dba4e8176351560f316f6d0dedm if ((to = strdup(from)) == NULL) \
8e22821528b08c6dba4e8176351560f316f6d0dedm return (1); \
8e22821528b08c6dba4e8176351560f316f6d0dedm }
8e22821528b08c6dba4e8176351560f316f6d0dedm
479ac37569625bae44ffb80071d4bc865fc710eddm#define STRDUP_CHECK(to, from) \
479ac37569625bae44ffb80071d4bc865fc710eddm if ((from) != NULL) { \
479ac37569625bae44ffb80071d4bc865fc710eddm to = strdup(from); \
479ac37569625bae44ffb80071d4bc865fc710eddm if (to == NULL) { \
479ac37569625bae44ffb80071d4bc865fc710eddm result->retcode = IDMAP_ERR_MEMORY; \
479ac37569625bae44ffb80071d4bc865fc710eddm goto out; \
479ac37569625bae44ffb80071d4bc865fc710eddm } \
479ac37569625bae44ffb80071d4bc865fc710eddm }
479ac37569625bae44ffb80071d4bc865fc710eddm
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwbool_t
cd37da7426f0c49c14ad9a8a07638ca971477566nwidmap_null_1_svc(void *result, struct svc_req *rqstp)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (TRUE);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
334e34639228c5021a69504cca69d70d851c52fababan/*
334e34639228c5021a69504cca69d70d851c52fababan * RPC layer allocates empty strings to replace NULL char *.
334e34639228c5021a69504cca69d70d851c52fababan * This utility function frees these empty strings.
334e34639228c5021a69504cca69d70d851c52fababan */
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3babanstatic
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3babanvoid
334e34639228c5021a69504cca69d70d851c52fababansanitize_mapping_request(idmap_mapping *req)
334e34639228c5021a69504cca69d70d851c52fababan{
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (EMPTY_STRING(req->id1name)) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(req->id1name);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier req->id1name = NULL;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (EMPTY_STRING(req->id1domain)) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(req->id1domain);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier req->id1domain = NULL;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (EMPTY_STRING(req->id2name)) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(req->id2name);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier req->id2name = NULL;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (EMPTY_STRING(req->id2domain)) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(req->id2domain);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier req->id2domain = NULL;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban req->direction = _IDMAP_F_DONE;
334e34639228c5021a69504cca69d70d851c52fababan}
334e34639228c5021a69504cca69d70d851c52fababan
0dcc71495bad040a0c83830efc85acf8d897350dnwstatic
0dcc71495bad040a0c83830efc85acf8d897350dnwint
0dcc71495bad040a0c83830efc85acf8d897350dnwvalidate_mapped_id_by_name_req(idmap_mapping *req)
0dcc71495bad040a0c83830efc85acf8d897350dnw{
0dcc71495bad040a0c83830efc85acf8d897350dnw int e;
0dcc71495bad040a0c83830efc85acf8d897350dnw
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (IS_ID_UID(req->id1) || IS_ID_GID(req->id1))
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_SUCCESS);
0dcc71495bad040a0c83830efc85acf8d897350dnw
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (IS_ID_SID(req->id1)) {
0dcc71495bad040a0c83830efc85acf8d897350dnw if (!EMPTY_STRING(req->id1name) &&
0dcc71495bad040a0c83830efc85acf8d897350dnw u8_validate(req->id1name, strlen(req->id1name),
0dcc71495bad040a0c83830efc85acf8d897350dnw NULL, U8_VALIDATE_ENTIRE, &e) < 0)
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_ERR_BAD_UTF8);
0dcc71495bad040a0c83830efc85acf8d897350dnw if (!EMPTY_STRING(req->id1domain) &&
0dcc71495bad040a0c83830efc85acf8d897350dnw u8_validate(req->id1domain, strlen(req->id1domain),
0dcc71495bad040a0c83830efc85acf8d897350dnw NULL, U8_VALIDATE_ENTIRE, &e) < 0)
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_ERR_BAD_UTF8);
0dcc71495bad040a0c83830efc85acf8d897350dnw }
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_SUCCESS);
0dcc71495bad040a0c83830efc85acf8d897350dnw}
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnwstatic
0dcc71495bad040a0c83830efc85acf8d897350dnwint
0dcc71495bad040a0c83830efc85acf8d897350dnwvalidate_rule(idmap_namerule *rule)
0dcc71495bad040a0c83830efc85acf8d897350dnw{
0dcc71495bad040a0c83830efc85acf8d897350dnw int e;
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnw if (!EMPTY_STRING(rule->winname) &&
0dcc71495bad040a0c83830efc85acf8d897350dnw u8_validate(rule->winname, strlen(rule->winname),
0dcc71495bad040a0c83830efc85acf8d897350dnw NULL, U8_VALIDATE_ENTIRE, &e) < 0)
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_ERR_BAD_UTF8);
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnw if (!EMPTY_STRING(rule->windomain) &&
0dcc71495bad040a0c83830efc85acf8d897350dnw u8_validate(rule->windomain, strlen(rule->windomain),
0dcc71495bad040a0c83830efc85acf8d897350dnw NULL, U8_VALIDATE_ENTIRE, &e) < 0)
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_ERR_BAD_UTF8);
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_SUCCESS);
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnw}
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnwstatic
0dcc71495bad040a0c83830efc85acf8d897350dnwbool_t
0dcc71495bad040a0c83830efc85acf8d897350dnwvalidate_rules(idmap_update_batch *batch)
0dcc71495bad040a0c83830efc85acf8d897350dnw{
0dcc71495bad040a0c83830efc85acf8d897350dnw idmap_update_op *up;
0dcc71495bad040a0c83830efc85acf8d897350dnw int i;
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnw for (i = 0; i < batch->idmap_update_batch_len; i++) {
0dcc71495bad040a0c83830efc85acf8d897350dnw up = &(batch->idmap_update_batch_val[i]);
0dcc71495bad040a0c83830efc85acf8d897350dnw if (validate_rule(&(up->idmap_update_op_u.rule))
0dcc71495bad040a0c83830efc85acf8d897350dnw != IDMAP_SUCCESS)
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_ERR_BAD_UTF8);
0dcc71495bad040a0c83830efc85acf8d897350dnw }
0dcc71495bad040a0c83830efc85acf8d897350dnw
0dcc71495bad040a0c83830efc85acf8d897350dnw return (IDMAP_SUCCESS);
0dcc71495bad040a0c83830efc85acf8d897350dnw}
0dcc71495bad040a0c83830efc85acf8d897350dnw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwbool_t
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_get_mapped_ids_1_svc(idmap_mapping_batch batch,
cd37da7426f0c49c14ad9a8a07638ca971477566nw idmap_ids_res *result, struct svc_req *rqstp)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sqlite *cache = NULL, *db = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw lookup_state_t state;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban idmap_retcode retcode;
62c6006265c37877b7a5b3c8ffce913ef559b955baban uint_t i;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright idmap_mapping *req;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright idmap_id_res *res;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright boolean_t any_tracing;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Init */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) memset(result, 0, sizeof (*result));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) memset(&state, 0, sizeof (state));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Return success if nothing was requested */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (batch.idmap_mapping_batch_len < 1)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get cache handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = get_cache_handle(&cache);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (result->retcode != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
479ac37569625bae44ffb80071d4bc865fc710eddm state.cache = cache;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = get_db_handle(&db);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (result->retcode != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
479ac37569625bae44ffb80071d4bc865fc710eddm state.db = db;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Allocate result array */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->ids.ids_val = calloc(batch.idmap_mapping_batch_len,
cd37da7426f0c49c14ad9a8a07638ca971477566nw sizeof (idmap_id_res));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (result->ids.ids_val == NULL) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmapdlog(LOG_ERR, "Out of memory");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = IDMAP_ERR_MEMORY;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->ids.ids_len = batch.idmap_mapping_batch_len;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
62c6006265c37877b7a5b3c8ffce913ef559b955baban /* Allocate hash table to check for duplicate sids */
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.sid_history = calloc(batch.idmap_mapping_batch_len,
cd37da7426f0c49c14ad9a8a07638ca971477566nw sizeof (*state.sid_history));
62c6006265c37877b7a5b3c8ffce913ef559b955baban if (state.sid_history == NULL) {
62c6006265c37877b7a5b3c8ffce913ef559b955baban idmapdlog(LOG_ERR, "Out of memory");
62c6006265c37877b7a5b3c8ffce913ef559b955baban result->retcode = IDMAP_ERR_MEMORY;
62c6006265c37877b7a5b3c8ffce913ef559b955baban goto out;
62c6006265c37877b7a5b3c8ffce913ef559b955baban }
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.sid_history_size = batch.idmap_mapping_batch_len;
62c6006265c37877b7a5b3c8ffce913ef559b955baban for (i = 0; i < state.sid_history_size; i++) {
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.sid_history[i].key = state.sid_history_size;
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.sid_history[i].next = state.sid_history_size;
62c6006265c37877b7a5b3c8ffce913ef559b955baban }
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.batch = &batch;
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.result = result;
62c6006265c37877b7a5b3c8ffce913ef559b955baban
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /* Get directory-based name mapping info */
479ac37569625bae44ffb80071d4bc865fc710eddm result->retcode = load_cfg_in_state(&state);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban if (result->retcode != IDMAP_SUCCESS)
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban goto out;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Init our 'done' flags */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw state.sid2pid_done = state.pid2sid_done = TRUE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright any_tracing = B_FALSE;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* First stage */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (TRACING(req))
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright any_tracing = B_TRUE;
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.curpos = i;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (void) sanitize_mapping_request(req);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Start mapping");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (IS_ID_SID(req->id1)) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw retcode = sid2pid_first_pass(
cd37da7426f0c49c14ad9a8a07638ca971477566nw &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright } else if (IS_ID_UID(req->id1)) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw retcode = pid2sid_first_pass(
cd37da7426f0c49c14ad9a8a07638ca971477566nw &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res, 1);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright } else if (IS_ID_GID(req->id1)) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw retcode = pid2sid_first_pass(
cd37da7426f0c49c14ad9a8a07638ca971477566nw &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res, 0);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw } else {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res->retcode = IDMAP_ERR_IDTYPE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw continue;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (IDMAP_FATAL_ERROR(retcode)) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = retcode;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Check if we are done */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == TRUE && state.pid2sid_done == TRUE)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /*
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * native LDAP lookups:
479ac37569625bae44ffb80071d4bc865fc710eddm * pid2sid:
479ac37569625bae44ffb80071d4bc865fc710eddm * - nldap or mixed mode. Lookup nldap by pid or unixname to get
479ac37569625bae44ffb80071d4bc865fc710eddm * winname.
479ac37569625bae44ffb80071d4bc865fc710eddm * sid2pid:
479ac37569625bae44ffb80071d4bc865fc710eddm * - nldap mode. Got winname and sid (either given or found in
479ac37569625bae44ffb80071d4bc865fc710eddm * name_cache). Lookup nldap by winname to get pid and
479ac37569625bae44ffb80071d4bc865fc710eddm * unixname.
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban */
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban if (state.nldap_nqueries) {
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban retcode = nldap_lookup_batch(&state, &batch, result);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban if (IDMAP_FATAL_ERROR(retcode)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Native LDAP lookup error=%d", retcode);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban result->retcode = retcode;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban goto out;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (any_tracing) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (IDMAP_ERROR(res->retcode)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "Native LDAP lookup error=%d",
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res->retcode);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright } else {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Native LDAP lookup");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban }
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /*
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * AD lookups:
479ac37569625bae44ffb80071d4bc865fc710eddm * pid2sid:
479ac37569625bae44ffb80071d4bc865fc710eddm * - nldap or mixed mode. Got winname from nldap lookup.
479ac37569625bae44ffb80071d4bc865fc710eddm * winname2sid could not be resolved locally. Lookup AD
479ac37569625bae44ffb80071d4bc865fc710eddm * by winname to get sid.
479ac37569625bae44ffb80071d4bc865fc710eddm * - ad mode. Got unixname. Lookup AD by unixname to get
479ac37569625bae44ffb80071d4bc865fc710eddm * winname and sid.
479ac37569625bae44ffb80071d4bc865fc710eddm * sid2pid:
479ac37569625bae44ffb80071d4bc865fc710eddm * - ad or mixed mode. Lookup AD by sid or winname to get
479ac37569625bae44ffb80071d4bc865fc710eddm * winname, sid and unixname.
479ac37569625bae44ffb80071d4bc865fc710eddm * - any mode. Got either sid or winname but not both. Lookup
479ac37569625bae44ffb80071d4bc865fc710eddm * AD by sid or winname to get winname, sid.
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.ad_nqueries) {
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban retcode = ad_lookup_batch(&state, &batch, result);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban if (IDMAP_FATAL_ERROR(retcode)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "AD lookup error=%d", retcode);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban result->retcode = retcode;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban goto out;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (res->retcode == IDMAP_ERR_DOMAIN_NOTFOUND &&
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req->id1.idmap_id_u.sid.prefix != NULL &&
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req->id1name != NULL) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright /*
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * If AD lookup failed Domain Not Found but
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * we have a winname and SID, it means that
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * - LSA succeeded
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * - it's a request a cross-forest trust
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * and
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * - we were looking for directory-based
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * mapping information.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * In that case, we're OK, just go on.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright *
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * If this seems more convoluted than it
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * should be, it is - really, we probably
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * shouldn't even be attempting AD lookups
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * in this situation, but that's a more
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * intricate cleanup that will have to wait
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright * for later.
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright */
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res->retcode = IDMAP_SUCCESS;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "AD lookup - domain not found (ignored)");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright continue;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (res->retcode == IDMAP_SUCCESS)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Found in AD");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright else if (res->retcode == IDMAP_ERR_NOTFOUND)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Not found in AD");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright else
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "AD lookup error");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban }
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /*
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * native LDAP lookups:
479ac37569625bae44ffb80071d4bc865fc710eddm * sid2pid:
479ac37569625bae44ffb80071d4bc865fc710eddm * - nldap mode. Got winname and sid from AD lookup. Lookup nldap
479ac37569625bae44ffb80071d4bc865fc710eddm * by winname to get pid and unixname.
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban */
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban if (state.nldap_nqueries) {
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban retcode = nldap_lookup_batch(&state, &batch, result);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban if (IDMAP_FATAL_ERROR(retcode)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Native LDAP lookup error=%d", retcode);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban result->retcode = retcode;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (any_tracing) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Native LDAP lookup");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /* Reset 'done' flags */
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban state.sid2pid_done = state.pid2sid_done = TRUE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Second stage */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.curpos = i;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (IS_ID_SID(req->id1)) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw retcode = sid2pid_second_pass(
cd37da7426f0c49c14ad9a8a07638ca971477566nw &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright } else if (IS_ID_UID(req->id1)) {
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban retcode = pid2sid_second_pass(
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res, 1);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright } else if (IS_ID_GID(req->id1)) {
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban retcode = pid2sid_second_pass(
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res, 0);
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban } else {
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /* First stage has already set the error */
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban continue;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban }
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban if (IDMAP_FATAL_ERROR(retcode)) {
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban result->retcode = retcode;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Check if we are done */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == TRUE && state.pid2sid_done == TRUE)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Reset our 'done' flags */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw state.sid2pid_done = state.pid2sid_done = TRUE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Update cache in a single transaction */
71590c90e239661c113497da3ca8b7301dfbe24cnw if (sql_exec_no_cb(cache, IDMAP_CACHENAME, "BEGIN TRANSACTION;")
71590c90e239661c113497da3ca8b7301dfbe24cnw != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.curpos = i;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (IS_ID_SID(req->id1)) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) update_cache_sid2pid(
cd37da7426f0c49c14ad9a8a07638ca971477566nw &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright } else if ((IS_ID_UID(req->id1)) ||
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright (IS_ID_GID(req->id1))) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) update_cache_pid2sid(
cd37da7426f0c49c14ad9a8a07638ca971477566nw &state,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Commit if we have at least one successful update */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == FALSE || state.pid2sid_done == FALSE)
71590c90e239661c113497da3ca8b7301dfbe24cnw (void) sql_exec_no_cb(cache, IDMAP_CACHENAME,
71590c90e239661c113497da3ca8b7301dfbe24cnw "COMMIT TRANSACTION;");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw else
71590c90e239661c113497da3ca8b7301dfbe24cnw (void) sql_exec_no_cb(cache, IDMAP_CACHENAME,
71590c90e239661c113497da3ca8b7301dfbe24cnw "END TRANSACTION;");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwout:
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban cleanup_lookup_state(&state);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (IDMAP_ERROR(result->retcode)) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (any_tracing) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res,
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright "Failure code %d", result->retcode);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw xdr_free(xdr_idmap_ids_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->ids.ids_len = 0;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->ids.ids_val = NULL;
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright } else {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (any_tracing) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < batch.idmap_mapping_batch_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright TRACE(req, res, "Done");
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = idmap_stat4prot(result->retcode);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright for (i = 0; i < result->ids.ids_len; i++) {
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright req = &batch.idmap_mapping_batch_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res = &result->ids.ids_val[i];
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright if (!(req->flag & IDMAP_REQ_FLG_MAPPING_INFO) &&
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright res->retcode == IDMAP_SUCCESS)
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright idmap_how_clear(&res->info.how);
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (TRUE);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
cd37da7426f0c49c14ad9a8a07638ca971477566nwstatic
cd37da7426f0c49c14ad9a8a07638ca971477566nwint
cd37da7426f0c49c14ad9a8a07638ca971477566nwlist_mappings_cb(void *parg, int argc, char **argv, char **colnames)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw list_cb_data_t *cb_data;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char *str;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmap_mappings_res *result;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmap_retcode retcode;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw int w2u, u2w;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char *end;
cd37da7426f0c49c14ad9a8a07638ca971477566nw static int validated_column_names = 0;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp idmap_how *how;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp cb_data = (list_cb_data_t *)parg;
cd37da7426f0c49c14ad9a8a07638ca971477566nw
cd37da7426f0c49c14ad9a8a07638ca971477566nw if (!validated_column_names) {
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[0], "rowid") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[1], "sidprefix") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[2], "rid") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[3], "pid") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[4], "w2u") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[5], "u2w") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[6], "windomain") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[7], "canon_winname") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[8], "unixname") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[9], "is_user") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[10], "is_wuser") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[11], "map_type") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[12], "map_dn") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[13], "map_attr") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[14], "map_value") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[15], "map_windomain") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[16], "map_winname") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[17], "map_unixname") == 0);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(strcmp(colnames[18], "map_is_nt4") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw validated_column_names = 1;
cd37da7426f0c49c14ad9a8a07638ca971477566nw }
cd37da7426f0c49c14ad9a8a07638ca971477566nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result = (idmap_mappings_res *)cb_data->result;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp _VALIDATE_LIST_CB_DATA(19, &result->mappings.mappings_val,
cd37da7426f0c49c14ad9a8a07638ca971477566nw sizeof (idmap_mapping));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_len++;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if ((str = strdup(argv[1])) == NULL)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id1.idmap_id_u.sid.prefix =
cd37da7426f0c49c14ad9a8a07638ca971477566nw str;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id1.idmap_id_u.sid.rid =
cd37da7426f0c49c14ad9a8a07638ca971477566nw strtoul(argv[2], &end, 10);
cd37da7426f0c49c14ad9a8a07638ca971477566nw result->mappings.mappings_val[cb_data->next].id1.idtype =
cd37da7426f0c49c14ad9a8a07638ca971477566nw strtol(argv[10], &end, 10) ? IDMAP_USID : IDMAP_GSID;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id2.idmap_id_u.uid =
cd37da7426f0c49c14ad9a8a07638ca971477566nw strtoul(argv[3], &end, 10);
cd37da7426f0c49c14ad9a8a07638ca971477566nw result->mappings.mappings_val[cb_data->next].id2.idtype =
cd37da7426f0c49c14ad9a8a07638ca971477566nw strtol(argv[9], &end, 10) ? IDMAP_UID : IDMAP_GID;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
cd37da7426f0c49c14ad9a8a07638ca971477566nw w2u = argv[4] ? strtol(argv[4], &end, 10) : 0;
cd37da7426f0c49c14ad9a8a07638ca971477566nw u2w = argv[5] ? strtol(argv[5], &end, 10) : 0;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (w2u > 0 && u2w == 0)
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->mappings.mappings_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban IDMAP_DIRECTION_W2U;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw else if (w2u == 0 && u2w > 0)
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->mappings.mappings_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban IDMAP_DIRECTION_U2W;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw else
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->mappings.mappings_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban IDMAP_DIRECTION_BI;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->mappings.mappings_val[cb_data->next].id1domain,
8e22821528b08c6dba4e8176351560f316f6d0dedm argv[6]);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->mappings.mappings_val[cb_data->next].id1name,
8e22821528b08c6dba4e8176351560f316f6d0dedm argv[7]);
8e22821528b08c6dba4e8176351560f316f6d0dedm
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->mappings.mappings_val[cb_data->next].id2name,
8e22821528b08c6dba4e8176351560f316f6d0dedm argv[8]);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp if (cb_data->flag & IDMAP_REQ_FLG_MAPPING_INFO) {
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how = &result->mappings.mappings_val[cb_data->next].info.how;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->map_type = strtoul(argv[11], &end, 10);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp switch (how->map_type) {
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp case IDMAP_MAP_TYPE_DS_AD:
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.ad.dn =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[12]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.ad.attr =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[13]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.ad.value =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[14]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp break;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp case IDMAP_MAP_TYPE_DS_NLDAP:
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.nldap.dn =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[12]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.nldap.attr =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[13]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.nldap.value =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[14]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp break;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp case IDMAP_MAP_TYPE_RULE_BASED:
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.rule.windomain =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[15]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.rule.winname =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[16]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.rule.unixname =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strdup(argv[17]);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.rule.is_nt4 =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strtoul(argv[18], &end, 10);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.rule.is_user =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strtol(argv[9], &end, 10);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how->idmap_how_u.rule.is_wuser =
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strtol(argv[10], &end, 10);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp break;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp case IDMAP_MAP_TYPE_EPHEMERAL:
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp break;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp case IDMAP_MAP_TYPE_LOCAL_SID:
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp break;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai case IDMAP_MAP_TYPE_IDMU:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai how->idmap_how_u.idmu.dn =
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai strdup(argv[12]);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai how->idmap_how_u.idmu.attr =
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai strdup(argv[13]);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai how->idmap_how_u.idmu.value =
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai strdup(argv[14]);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai break;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp default:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai /* Unknown mapping type */
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp assert(FALSE);
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp }
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->lastrowid = strtoll(argv[0], &end, 10);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw cb_data->next++;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = IDMAP_SUCCESS;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (0);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwbool_t
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejpidmap_list_mappings_1_svc(int64_t lastrowid, uint64_t limit, int32_t flag,
cd37da7426f0c49c14ad9a8a07638ca971477566nw idmap_mappings_res *result, struct svc_req *rqstp)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sqlite *cache = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char lbuf[30], rbuf[30];
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw uint64_t maxlimit;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmap_retcode retcode;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char *sql = NULL;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp time_t curtime;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) memset(result, 0, sizeof (*result));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp /* Current time */
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp errno = 0;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp if ((curtime = time(NULL)) == (time_t)-1) {
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp idmapdlog(LOG_ERR, "Failed to get current time (%s)",
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp strerror(errno));
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp retcode = IDMAP_ERR_INTERNAL;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp goto out;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp }
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw RDLOCK_CONFIG();
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw maxlimit = _idmapdstate.cfg->pgcfg.list_size_limit;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw UNLOCK_CONFIG();
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get cache handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = get_cache_handle(&cache);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (result->retcode != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = IDMAP_ERR_INTERNAL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Create LIMIT expression. */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (limit == 0 || (maxlimit > 0 && maxlimit < limit))
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw limit = maxlimit;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (limit > 0)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(lbuf, sizeof (lbuf),
cd37da7426f0c49c14ad9a8a07638ca971477566nw "LIMIT %" PRIu64, limit + 1ULL);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown else
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown lbuf[0] = '\0';
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(rbuf, sizeof (rbuf), "rowid > %" PRIu64, lastrowid);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /*
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Combine all the above into a giant SELECT statement that
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * will return the requested mappings
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw */
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp sql = sqlite_mprintf("SELECT rowid, sidprefix, rid, pid, w2u, "
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp "u2w, windomain, canon_winname, unixname, is_user, is_wuser, "
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp "map_type, map_dn, map_attr, map_value, map_windomain, "
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp "map_winname, map_unixname, map_is_nt4 "
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp "FROM idmap_cache WHERE %s AND "
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp "(pid >= 2147483648 OR (expiration = 0 OR "
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp "expiration ISNULL OR expiration > %d)) "
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp "%s;",
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp rbuf, curtime, lbuf);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (sql == NULL) {
479ac37569625bae44ffb80071d4bc865fc710eddm result->retcode = IDMAP_ERR_MEMORY;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmapdlog(LOG_ERR, "Out of memory");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Execute the SQL statement and update the return buffer */
71590c90e239661c113497da3ca8b7301dfbe24cnw PROCESS_LIST_SVC_SQL(retcode, cache, IDMAP_CACHENAME, sql, limit,
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp flag, list_mappings_cb, result, result->mappings.mappings_len);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwout:
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (sql)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sqlite_freemem(sql);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (IDMAP_ERROR(result->retcode))
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) xdr_free(xdr_idmap_mappings_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = idmap_stat4prot(result->retcode);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (TRUE);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
cd37da7426f0c49c14ad9a8a07638ca971477566nwstatic
cd37da7426f0c49c14ad9a8a07638ca971477566nwint
cd37da7426f0c49c14ad9a8a07638ca971477566nwlist_namerules_cb(void *parg, int argc, char **argv, char **colnames)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw list_cb_data_t *cb_data;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmap_namerules_res *result;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmap_retcode retcode;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw int w2u_order, u2w_order;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char *end;
cd37da7426f0c49c14ad9a8a07638ca971477566nw static int validated_column_names = 0;
cd37da7426f0c49c14ad9a8a07638ca971477566nw
cd37da7426f0c49c14ad9a8a07638ca971477566nw if (!validated_column_names) {
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[0], "rowid") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[1], "is_user") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[2], "is_wuser") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[3], "windomain") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[4], "winname_display") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[5], "is_nt4") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[6], "unixname") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[7], "w2u_order") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw assert(strcmp(colnames[8], "u2w_order") == 0);
cd37da7426f0c49c14ad9a8a07638ca971477566nw validated_column_names = 1;
cd37da7426f0c49c14ad9a8a07638ca971477566nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw cb_data = (list_cb_data_t *)parg;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result = (idmap_namerules_res *)cb_data->result;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
cd37da7426f0c49c14ad9a8a07638ca971477566nw _VALIDATE_LIST_CB_DATA(9, &result->rules.rules_val,
cd37da7426f0c49c14ad9a8a07638ca971477566nw sizeof (idmap_namerule));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->rules.rules_len++;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->rules.rules_val[cb_data->next].is_user =
cd37da7426f0c49c14ad9a8a07638ca971477566nw strtol(argv[1], &end, 10);
cd37da7426f0c49c14ad9a8a07638ca971477566nw
cd37da7426f0c49c14ad9a8a07638ca971477566nw result->rules.rules_val[cb_data->next].is_wuser =
cd37da7426f0c49c14ad9a8a07638ca971477566nw strtol(argv[2], &end, 10);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->rules.rules_val[cb_data->next].windomain,
cd37da7426f0c49c14ad9a8a07638ca971477566nw argv[3]);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->rules.rules_val[cb_data->next].winname,
cd37da7426f0c49c14ad9a8a07638ca971477566nw argv[4]);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->rules.rules_val[cb_data->next].is_nt4 =
cd37da7426f0c49c14ad9a8a07638ca971477566nw strtol(argv[5], &end, 10);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->rules.rules_val[cb_data->next].unixname,
cd37da7426f0c49c14ad9a8a07638ca971477566nw argv[6]);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
cd37da7426f0c49c14ad9a8a07638ca971477566nw w2u_order = argv[7] ? strtol(argv[7], &end, 10) : 0;
cd37da7426f0c49c14ad9a8a07638ca971477566nw u2w_order = argv[8] ? strtol(argv[8], &end, 10) : 0;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (w2u_order > 0 && u2w_order == 0)
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->rules.rules_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban IDMAP_DIRECTION_W2U;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw else if (w2u_order == 0 && u2w_order > 0)
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->rules.rules_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban IDMAP_DIRECTION_U2W;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw else
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->rules.rules_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban IDMAP_DIRECTION_BI;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->lastrowid = strtoll(argv[0], &end, 10);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw cb_data->next++;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = IDMAP_SUCCESS;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (0);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwbool_t
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_list_namerules_1_svc(idmap_namerule rule, uint64_t lastrowid,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw uint64_t limit, idmap_namerules_res *result,
cd37da7426f0c49c14ad9a8a07638ca971477566nw struct svc_req *rqstp)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sqlite *db = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char lbuf[30], rbuf[30];
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char *sql = NULL;
cd37da7426f0c49c14ad9a8a07638ca971477566nw char *expr = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw uint64_t maxlimit;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmap_retcode retcode;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) memset(result, 0, sizeof (*result));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
0dcc71495bad040a0c83830efc85acf8d897350dnw result->retcode = validate_rule(&rule);
0dcc71495bad040a0c83830efc85acf8d897350dnw if (result->retcode != IDMAP_SUCCESS)
0dcc71495bad040a0c83830efc85acf8d897350dnw goto out;
0dcc71495bad040a0c83830efc85acf8d897350dnw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw RDLOCK_CONFIG();
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw maxlimit = _idmapdstate.cfg->pgcfg.list_size_limit;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw UNLOCK_CONFIG();
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = get_db_handle(&db);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (result->retcode != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
0dcc71495bad040a0c83830efc85acf8d897350dnw result->retcode = gen_sql_expr_from_rule(&rule, &expr);
0dcc71495bad040a0c83830efc85acf8d897350dnw if (result->retcode != IDMAP_SUCCESS)
cd37da7426f0c49c14ad9a8a07638ca971477566nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Create LIMIT expression. */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (limit == 0 || (maxlimit > 0 && maxlimit < limit))
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw limit = maxlimit;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (limit > 0)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(lbuf, sizeof (lbuf),
cd37da7426f0c49c14ad9a8a07638ca971477566nw "LIMIT %" PRIu64, limit + 1ULL);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown else
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown lbuf[0] = '\0';
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(rbuf, sizeof (rbuf), "rowid > %" PRIu64, lastrowid);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /*
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Combine all the above into a giant SELECT statement that
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * will return the requested rules
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw */
cd37da7426f0c49c14ad9a8a07638ca971477566nw sql = sqlite_mprintf("SELECT rowid, is_user, is_wuser, windomain, "
cd37da7426f0c49c14ad9a8a07638ca971477566nw "winname_display, is_nt4, unixname, w2u_order, u2w_order "
cd37da7426f0c49c14ad9a8a07638ca971477566nw "FROM namerules WHERE "
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown " %s %s %s;",
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown rbuf, expr, lbuf);
cd37da7426f0c49c14ad9a8a07638ca971477566nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (sql == NULL) {
479ac37569625bae44ffb80071d4bc865fc710eddm result->retcode = IDMAP_ERR_MEMORY;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmapdlog(LOG_ERR, "Out of memory");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Execute the SQL statement and update the return buffer */
71590c90e239661c113497da3ca8b7301dfbe24cnw PROCESS_LIST_SVC_SQL(retcode, db, IDMAP_DBNAME, sql, limit,
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp 0, list_namerules_cb, result, result->rules.rules_len);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwout:
cd37da7426f0c49c14ad9a8a07638ca971477566nw if (expr)
cd37da7426f0c49c14ad9a8a07638ca971477566nw sqlite_freemem(expr);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (sql)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sqlite_freemem(sql);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (IDMAP_ERROR(result->retcode))
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) xdr_free(xdr_idmap_namerules_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = idmap_stat4prot(result->retcode);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (TRUE);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#define IDMAP_RULES_AUTH "solaris.admin.idmap.rules"
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwstatic int
cd37da7426f0c49c14ad9a8a07638ca971477566nwverify_rules_auth(struct svc_req *rqstp)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ucred_t *uc = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw uid_t uid;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw char buf[1024];
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw struct passwd pwd;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (svc_getcallerucred(rqstp->rq_xprt, &uc) != 0) {
71590c90e239661c113497da3ca8b7301dfbe24cnw idmapdlog(LOG_ERR, "svc_getcallerucred failed during "
71590c90e239661c113497da3ca8b7301dfbe24cnw "authorization (%s)", strerror(errno));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw uid = ucred_geteuid(uc);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (uid == (uid_t)-1) {
71590c90e239661c113497da3ca8b7301dfbe24cnw idmapdlog(LOG_ERR, "ucred_geteuid failed during "
71590c90e239661c113497da3ca8b7301dfbe24cnw "authorization (%s)", strerror(errno));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ucred_free(uc);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (getpwuid_r(uid, &pwd, buf, sizeof (buf)) == NULL) {
71590c90e239661c113497da3ca8b7301dfbe24cnw idmapdlog(LOG_ERR, "getpwuid_r(%u) failed during "
71590c90e239661c113497da3ca8b7301dfbe24cnw "authorization (%s)", uid, strerror(errno));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ucred_free(uc);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (chkauthattr(IDMAP_RULES_AUTH, pwd.pw_name) != 1) {
71590c90e239661c113497da3ca8b7301dfbe24cnw idmapdlog(LOG_INFO, "%s is not authorized (%s)",
71590c90e239661c113497da3ca8b7301dfbe24cnw pwd.pw_name, IDMAP_RULES_AUTH);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ucred_free(uc);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ucred_free(uc);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm/*
8e22821528b08c6dba4e8176351560f316f6d0dedm * Meaning of the return values is the following: For retcode ==
8e22821528b08c6dba4e8176351560f316f6d0dedm * IDMAP_SUCCESS, everything went OK and error_index is
8e22821528b08c6dba4e8176351560f316f6d0dedm * undefined. Otherwise, error_index >=0 shows the failed batch
8e22821528b08c6dba4e8176351560f316f6d0dedm * element. errro_index == -1 indicates failure at the beginning,
8e22821528b08c6dba4e8176351560f316f6d0dedm * error_index == -2 at the end.
8e22821528b08c6dba4e8176351560f316f6d0dedm */
8e22821528b08c6dba4e8176351560f316f6d0dedm
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwbool_t
8e22821528b08c6dba4e8176351560f316f6d0dedmidmap_update_1_svc(idmap_update_batch batch, idmap_update_res *res,
cd37da7426f0c49c14ad9a8a07638ca971477566nw struct svc_req *rqstp)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sqlite *db = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw idmap_update_op *up;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw int i;
84decf41e1c0970e397cc8710dfcf81db5b8c6dajp int trans = FALSE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm res->error_index = -1;
8e22821528b08c6dba4e8176351560f316f6d0dedm (void) memset(&res->error_rule, 0, sizeof (res->error_rule));
8e22821528b08c6dba4e8176351560f316f6d0dedm (void) memset(&res->conflict_rule, 0, sizeof (res->conflict_rule));
8e22821528b08c6dba4e8176351560f316f6d0dedm
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (verify_rules_auth(rqstp) < 0) {
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = IDMAP_ERR_PERMISSION_DENIED;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (batch.idmap_update_batch_len == 0 ||
cd37da7426f0c49c14ad9a8a07638ca971477566nw batch.idmap_update_batch_val == NULL) {
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = IDMAP_SUCCESS;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
0dcc71495bad040a0c83830efc85acf8d897350dnw res->retcode = validate_rules(&batch);
0dcc71495bad040a0c83830efc85acf8d897350dnw if (res->retcode != IDMAP_SUCCESS)
0dcc71495bad040a0c83830efc85acf8d897350dnw goto out;
0dcc71495bad040a0c83830efc85acf8d897350dnw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = get_db_handle(&db);
8e22821528b08c6dba4e8176351560f316f6d0dedm if (res->retcode != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
71590c90e239661c113497da3ca8b7301dfbe24cnw res->retcode = sql_exec_no_cb(db, IDMAP_DBNAME, "BEGIN TRANSACTION;");
8e22821528b08c6dba4e8176351560f316f6d0dedm if (res->retcode != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
84decf41e1c0970e397cc8710dfcf81db5b8c6dajp trans = TRUE;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw for (i = 0; i < batch.idmap_update_batch_len; i++) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw up = &batch.idmap_update_batch_val[i];
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw switch (up->opnum) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw case OP_NONE:
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = IDMAP_SUCCESS;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw break;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw case OP_ADD_NAMERULE:
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = add_namerule(db,
cd37da7426f0c49c14ad9a8a07638ca971477566nw &up->idmap_update_op_u.rule);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw break;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw case OP_RM_NAMERULE:
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = rm_namerule(db,
cd37da7426f0c49c14ad9a8a07638ca971477566nw &up->idmap_update_op_u.rule);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw break;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw case OP_FLUSH_NAMERULES:
cd37da7426f0c49c14ad9a8a07638ca971477566nw res->retcode = flush_namerules(db);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw break;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw default:
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = IDMAP_ERR_NOTSUPPORTED;
8e22821528b08c6dba4e8176351560f316f6d0dedm break;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw };
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
8e22821528b08c6dba4e8176351560f316f6d0dedm if (res->retcode != IDMAP_SUCCESS) {
8e22821528b08c6dba4e8176351560f316f6d0dedm res->error_index = i;
8e22821528b08c6dba4e8176351560f316f6d0dedm if (up->opnum == OP_ADD_NAMERULE ||
8e22821528b08c6dba4e8176351560f316f6d0dedm up->opnum == OP_RM_NAMERULE) {
8e22821528b08c6dba4e8176351560f316f6d0dedm idmap_stat r2 =
8e22821528b08c6dba4e8176351560f316f6d0dedm idmap_namerule_cpy(&res->error_rule,
cd37da7426f0c49c14ad9a8a07638ca971477566nw &up->idmap_update_op_u.rule);
8e22821528b08c6dba4e8176351560f316f6d0dedm if (r2 != IDMAP_SUCCESS)
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = r2;
8e22821528b08c6dba4e8176351560f316f6d0dedm }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
8e22821528b08c6dba4e8176351560f316f6d0dedm }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwout:
84decf41e1c0970e397cc8710dfcf81db5b8c6dajp if (trans) {
8e22821528b08c6dba4e8176351560f316f6d0dedm if (res->retcode == IDMAP_SUCCESS) {
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode =
71590c90e239661c113497da3ca8b7301dfbe24cnw sql_exec_no_cb(db, IDMAP_DBNAME,
71590c90e239661c113497da3ca8b7301dfbe24cnw "COMMIT TRANSACTION;");
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (res->retcode == IDMAP_SUCCESS) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States /*
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * We've updated the rules. Expire the cache
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * so that existing mappings will be
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States * reconsidered.
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States */
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States res->retcode =
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States idmap_cache_flush(IDMAP_FLUSH_EXPIRE);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States } else {
8e22821528b08c6dba4e8176351560f316f6d0dedm res->error_index = -2;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
8e22821528b08c6dba4e8176351560f316f6d0dedm }
84decf41e1c0970e397cc8710dfcf81db5b8c6dajp else
71590c90e239661c113497da3ca8b7301dfbe24cnw (void) sql_exec_no_cb(db, IDMAP_DBNAME,
71590c90e239661c113497da3ca8b7301dfbe24cnw "ROLLBACK TRANSACTION;");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
8e22821528b08c6dba4e8176351560f316f6d0dedm
8e22821528b08c6dba4e8176351560f316f6d0dedm res->retcode = idmap_stat4prot(res->retcode);
8e22821528b08c6dba4e8176351560f316f6d0dedm
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (TRUE);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krierstatic
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krierint
fe1c642d06e14b412cd83ae2179303186ab08972Bill Kriercopy_string(char **to, char *from)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier{
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (EMPTY_STRING(from)) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier *to = NULL;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier } else {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier *to = strdup(from);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (*to == NULL) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier idmapdlog(LOG_ERR, "Out of memory");
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (IDMAP_ERR_MEMORY);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (IDMAP_SUCCESS);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier}
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krierstatic
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krierint
fe1c642d06e14b412cd83ae2179303186ab08972Bill Kriercopy_id(idmap_id *to, idmap_id *from)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier{
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier (void) memset(to, 0, sizeof (*to));
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier to->idtype = from->idtype;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (IS_ID_SID(*from)) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier idmap_retcode retcode;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier to->idmap_id_u.sid.rid = from->idmap_id_u.sid.rid;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier retcode = copy_string(&to->idmap_id_u.sid.prefix,
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier from->idmap_id_u.sid.prefix);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (retcode);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier } else {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier to->idmap_id_u.uid = from->idmap_id_u.uid;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (IDMAP_SUCCESS);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier}
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krierstatic
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krierint
fe1c642d06e14b412cd83ae2179303186ab08972Bill Kriercopy_mapping(idmap_mapping *mapping, idmap_mapping *request)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier{
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier idmap_retcode retcode;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier (void) memset(mapping, 0, sizeof (*mapping));
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier mapping->flag = request->flag;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier mapping->direction = _IDMAP_F_DONE;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier retcode = copy_id(&mapping->id1, &request->id1);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (retcode != IDMAP_SUCCESS)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier goto errout;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier retcode = copy_string(&mapping->id1domain, request->id1domain);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (retcode != IDMAP_SUCCESS)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier goto errout;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier retcode = copy_string(&mapping->id1name, request->id1name);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (retcode != IDMAP_SUCCESS)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier goto errout;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier retcode = copy_id(&mapping->id2, &request->id2);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (retcode != IDMAP_SUCCESS)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier goto errout;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier retcode = copy_string(&mapping->id2domain, request->id2domain);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (retcode != IDMAP_SUCCESS)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier goto errout;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier retcode = copy_string(&mapping->id2name, request->id2name);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (retcode != IDMAP_SUCCESS)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier goto errout;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (IDMAP_SUCCESS);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Kriererrout:
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (IS_ID_SID(mapping->id1))
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(mapping->id1.idmap_id_u.sid.prefix);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(mapping->id1domain);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(mapping->id1name);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (IS_ID_SID(mapping->id2))
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(mapping->id2.idmap_id_u.sid.prefix);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(mapping->id2domain);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier free(mapping->id2name);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier (void) memset(mapping, 0, sizeof (*mapping));
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier return (retcode);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier}
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwbool_t
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_get_mapped_id_by_name_1_svc(idmap_mapping request,
cd37da7426f0c49c14ad9a8a07638ca971477566nw idmap_mappings_res *result, struct svc_req *rqstp)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier idmap_mapping_batch batch_request;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier idmap_ids_res batch_result;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier idmap_mapping *map;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier /* Clear out things we might want to xdr_free on error */
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier (void) memset(&batch_result, 0, sizeof (batch_result));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) memset(result, 0, sizeof (*result));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
0dcc71495bad040a0c83830efc85acf8d897350dnw result->retcode = validate_mapped_id_by_name_req(&request);
0dcc71495bad040a0c83830efc85acf8d897350dnw if (result->retcode != IDMAP_SUCCESS)
0dcc71495bad040a0c83830efc85acf8d897350dnw goto out;
0dcc71495bad040a0c83830efc85acf8d897350dnw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier /*
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Copy the request. We need to modify it, and
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * what we have is a shallow copy. Freeing pointers from
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * our copy will lead to problems, since the RPC framework
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * has its own copy of those pointers. Besides, we need
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * a copy to return.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier */
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier map = calloc(1, sizeof (idmap_mapping));
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (map == NULL) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier idmapdlog(LOG_ERR, "Out of memory");
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier result->retcode = IDMAP_ERR_MEMORY;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier /*
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Set up to return the filled-in mapping structure.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * Note that we xdr_free result on error, and that'll take
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier * care of freeing the mapping structure.
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier */
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier result->mappings.mappings_val = map;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier result->mappings.mappings_len = 1;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier result->retcode = copy_mapping(map, &request);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (result->retcode != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier /* Set up for the request to the batch API */
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier batch_request.idmap_mapping_batch_val = map;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier batch_request.idmap_mapping_batch_len = 1;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier /* Do the real work. */
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier (void) idmap_get_mapped_ids_1_svc(batch_request,
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier &batch_result, rqstp);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier /* Copy what we need out of the batch response */
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (batch_result.retcode != IDMAP_SUCCESS) {
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier result->retcode = batch_result.retcode;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw goto out;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier result->retcode = copy_id(&map->id2, &batch_result.ids.ids_val[0].id);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier if (result->retcode != IDMAP_SUCCESS)
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier goto out;
cd37da7426f0c49c14ad9a8a07638ca971477566nw
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier map->direction = batch_result.ids.ids_val[0].direction;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier result->retcode = batch_result.ids.ids_val[0].retcode;
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
148c5f43199ca0b43fc8e3b643aab11cd66ea327Alan Wright idmap_info_mov(&map->info, &batch_result.ids.ids_val[0].info);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwout:
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (IDMAP_FATAL_ERROR(result->retcode)) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw xdr_free(xdr_idmap_mappings_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_len = 0;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val = NULL;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw }
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->retcode = idmap_stat4prot(result->retcode);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier xdr_free(xdr_idmap_ids_res, (char *)&batch_result);
fe1c642d06e14b412cd83ae2179303186ab08972Bill Krier
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (TRUE);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
479ac37569625bae44ffb80071d4bc865fc710eddm/* ARGSUSED */
479ac37569625bae44ffb80071d4bc865fc710eddmbool_t
479ac37569625bae44ffb80071d4bc865fc710eddmidmap_get_prop_1_svc(idmap_prop_type request,
479ac37569625bae44ffb80071d4bc865fc710eddm idmap_prop_res *result, struct svc_req *rqstp)
479ac37569625bae44ffb80071d4bc865fc710eddm{
479ac37569625bae44ffb80071d4bc865fc710eddm idmap_pg_config_t *pgcfg;
479ac37569625bae44ffb80071d4bc865fc710eddm
479ac37569625bae44ffb80071d4bc865fc710eddm /* Init */
479ac37569625bae44ffb80071d4bc865fc710eddm (void) memset(result, 0, sizeof (*result));
479ac37569625bae44ffb80071d4bc865fc710eddm result->retcode = IDMAP_SUCCESS;
479ac37569625bae44ffb80071d4bc865fc710eddm result->value.prop = request;
479ac37569625bae44ffb80071d4bc865fc710eddm
479ac37569625bae44ffb80071d4bc865fc710eddm RDLOCK_CONFIG();
479ac37569625bae44ffb80071d4bc865fc710eddm
479ac37569625bae44ffb80071d4bc865fc710eddm /* Just shortcuts: */
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg = &_idmapdstate.cfg->pgcfg;
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen
479ac37569625bae44ffb80071d4bc865fc710eddm
479ac37569625bae44ffb80071d4bc865fc710eddm switch (request) {
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_LIST_SIZE_LIMIT:
479ac37569625bae44ffb80071d4bc865fc710eddm result->value.idmap_prop_val_u.intval = pgcfg->list_size_limit;
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered = FALSE;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_DEFAULT_DOMAIN:
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered = FALSE;
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->default_domain);
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_DOMAIN_NAME:
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->domain_name);
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered =
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen pgcfg->domain_name_auto_disc;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_MACHINE_SID:
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered = FALSE;
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->machine_sid);
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_DOMAIN_CONTROLLER:
479ac37569625bae44ffb80071d4bc865fc710eddm if (pgcfg->domain_controller != NULL) {
479ac37569625bae44ffb80071d4bc865fc710eddm (void) memcpy(&result->value.idmap_prop_val_u.dsval,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->domain_controller,
479ac37569625bae44ffb80071d4bc865fc710eddm sizeof (idmap_ad_disc_ds_t));
479ac37569625bae44ffb80071d4bc865fc710eddm }
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->domain_controller_auto_disc;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_FOREST_NAME:
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->forest_name);
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->forest_name_auto_disc;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_SITE_NAME:
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->site_name);
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->site_name_auto_disc;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_GLOBAL_CATALOG:
479ac37569625bae44ffb80071d4bc865fc710eddm if (pgcfg->global_catalog != NULL) {
479ac37569625bae44ffb80071d4bc865fc710eddm (void) memcpy(&result->value.idmap_prop_val_u.dsval,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->global_catalog, sizeof (idmap_ad_disc_ds_t));
479ac37569625bae44ffb80071d4bc865fc710eddm }
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->global_catalog_auto_disc;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_AD_UNIXUSER_ATTR:
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->ad_unixuser_attr);
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered = FALSE;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_AD_UNIXGROUP_ATTR:
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->ad_unixgroup_attr);
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered = FALSE;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm case PROP_NLDAP_WINNAME_ATTR:
479ac37569625bae44ffb80071d4bc865fc710eddm STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
479ac37569625bae44ffb80071d4bc865fc710eddm pgcfg->nldap_winname_attr);
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered = FALSE;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai case PROP_DIRECTORY_BASED_MAPPING:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai enum_lookup(pgcfg->directory_based_mapping,
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai directory_mapping_map));
479ac37569625bae44ffb80071d4bc865fc710eddm result->auto_discovered = FALSE;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm default:
479ac37569625bae44ffb80071d4bc865fc710eddm result->retcode = IDMAP_ERR_PROP_UNKNOWN;
479ac37569625bae44ffb80071d4bc865fc710eddm break;
479ac37569625bae44ffb80071d4bc865fc710eddm }
479ac37569625bae44ffb80071d4bc865fc710eddm
479ac37569625bae44ffb80071d4bc865fc710eddmout:
479ac37569625bae44ffb80071d4bc865fc710eddm UNLOCK_CONFIG();
479ac37569625bae44ffb80071d4bc865fc710eddm if (IDMAP_FATAL_ERROR(result->retcode)) {
479ac37569625bae44ffb80071d4bc865fc710eddm xdr_free(xdr_idmap_prop_res, (caddr_t)result);
479ac37569625bae44ffb80071d4bc865fc710eddm result->value.prop = PROP_UNKNOWN;
479ac37569625bae44ffb80071d4bc865fc710eddm }
479ac37569625bae44ffb80071d4bc865fc710eddm result->retcode = idmap_stat4prot(result->retcode);
479ac37569625bae44ffb80071d4bc865fc710eddm return (TRUE);
479ac37569625bae44ffb80071d4bc865fc710eddm}
479ac37569625bae44ffb80071d4bc865fc710eddm
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesint
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United Statesidmap_flush_1_svc(
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States idmap_flush_op op,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States idmap_retcode *result,
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States struct svc_req *rqstp)
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States{
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States NOTE(ARGUNUSED(rqstp))
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States if (verify_rules_auth(rqstp) < 0) {
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *result = IDMAP_ERR_PERMISSION_DENIED;
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (TRUE);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States }
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States *result = idmap_cache_flush(op);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States return (TRUE);
9fb67ea305c66b6a297583b9b0db6796b0dfe497afshin salek ardakani - Sun Microsystems - Irvine United States}
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwint
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_prog_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result,
cd37da7426f0c49c14ad9a8a07638ca971477566nw caddr_t result)
cd37da7426f0c49c14ad9a8a07638ca971477566nw{
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) xdr_free(xdr_result, result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (TRUE);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw}
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown/*
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * This function is called by rpc_svc.c when it encounters an error.
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown */
1fcced4c370617db71610fecffd5451a5894ca5eJordan BrownNOTE(PRINTFLIKE(1))
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brownvoid
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brownidmap_rpc_msgout(const char *fmt, ...)
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown{
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown va_list va;
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown char buf[1000];
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown va_start(va, fmt);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown (void) vsnprintf(buf, sizeof (buf), fmt, va);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown va_end(va);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown idmapdlog(LOG_ERR, "idmap RPC: %s", buf);
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown}