server.c revision 651c0131ccc65381cbda174bee44a4fd7a518d6b
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * See the License for the specific language governing permissions
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * and limitations under the License.
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 * CDDL HEADER END
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Use is subject to license terms.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#pragma ident "%Z%%M% %I% %E% SMI"
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Service routines
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw retcode = validate_list_cb_data(cb_data, argc, argv, col,\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (0);\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw } else if (retcode < 0) {\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw#define PROCESS_LIST_SVC_SQL(rcode, db, sql, limit, cb, res, len)\
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Init */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Return success if nothing was requested */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get cache handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Allocate result array */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->ids.ids_val = calloc(batch.idmap_mapping_batch_len,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Init our 'done' flags */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* First stage */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Check if we are done */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == TRUE && state.pid2sid_done == TRUE)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Process Windows server lookups for sid2name */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Reset sid2pid 'done' flag */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Second stage */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Process sid to pid ONLY */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Check if we are done */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == TRUE && state.pid2sid_done == TRUE)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Reset our 'done' flags */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Update cache in a single transaction */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (sql_exec_no_cb(cache, "BEGIN TRANSACTION;") != IDMAP_SUCCESS)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Commit if we have atleast one successful update */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == FALSE || state.pid2sid_done == FALSE)
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwlist_mappings_cb(void *parg, int argc, char **argv, char **colnames) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw _VALIDATE_LIST_CB_DATA(9, &result->mappings.mappings_val,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id1.idmap_id_u.sid.prefix =
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id1.idmap_id_u.sid.rid =
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id1.idtype = IDMAP_SID;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id2.idmap_id_u.uid =
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id2.idtype = IDMAP_UID;
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->mappings.mappings_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->mappings.mappings_val[cb_data->next].direction =
651c0131ccc65381cbda174bee44a4fd7a518d6bbaban result->mappings.mappings_val[cb_data->next].direction =
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ptr = &result->mappings.mappings_val[cb_data->next].id1domain;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ptr = &result->mappings.mappings_val[cb_data->next].id1name;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw ptr = &result->mappings.mappings_val[cb_data->next].id2name;
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (0);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_list_mappings_1_svc(bool_t is_user, int64_t lastrowid,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get cache handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Create LIMIT expression. */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(rbuf, sizeof (rbuf), "rowid > %" PRIu64, lastrowid);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Combine all the above into a giant SELECT statement that
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * will return the requested mappings
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sql = sqlite_mprintf("SELECT rowid, sidprefix, rid, pid, w2u, u2w,"
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw " windomain, winname, unixname"
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw " FROM idmap_cache WHERE "
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw " %s AND is_user = %d %s;",
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Execute the SQL statement and update the return buffer */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw PROCESS_LIST_SVC_SQL(retcode, cache, sql, limit, list_mappings_cb,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) xdr_free(xdr_idmap_mappings_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwlist_namerules_cb(void *parg, int argc, char **argv, char **colnames) {
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (0);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_list_namerules_1_svc(idmap_namerule rule, uint64_t lastrowid,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(w2ubuf, sizeof (w2ubuf), "AND w2u_order > 0");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(u2wbuf, sizeof (u2wbuf), "AND u2w_order > 0");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(w2ubuf, sizeof (w2ubuf), "AND w2u_order > 0");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "AND (u2w_order = 0 OR u2w_order ISNULL)");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "AND (w2u_order = 0 OR w2u_order ISNULL)");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(u2wbuf, sizeof (u2wbuf), "AND u2w_order > 0");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Create where statement for windomain */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Create where statement for winname */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Create where statement for unixname */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Create LIMIT expression. */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(rbuf, sizeof (rbuf), "rowid > %" PRIu64, lastrowid);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Combine all the above into a giant SELECT statement that
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * will return the requested rules
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw sql = sqlite_mprintf("SELECT rowid, is_user, windomain, winname, "
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "is_nt4, unixname, w2u_order, u2w_order "
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "FROM namerules WHERE "
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw " %s AND is_user = %d %s %s %s %s %s %s;",
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Execute the SQL statement and update the return buffer */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw PROCESS_LIST_SVC_SQL(retcode, db, sql, limit, list_namerules_cb,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) xdr_free(xdr_idmap_namerules_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "%s: svc_getcallerucred failed (errno=%d)",
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "%s: ucred_geteuid failed (errno=%d)",
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "%s: getpwuid_r(%u) failed (errno=%d)",
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw "%s: %s does not have authorization.",
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_update_1_svc(idmap_update_batch batch, idmap_retcode *result,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Init */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get cache handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Allocate result */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val = calloc(1, sizeof (idmap_mapping));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */