server.c revision 48258c6b4e17f36ab09fba0bd6307d1fec9dcbce
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
0dcc71495bad040a0c83830efc85acf8d897350dnw * Copyright 2008 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);\
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);\
8e22821528b08c6dba4e8176351560f316f6d0dedm return (1); \
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
334e34639228c5021a69504cca69d70d851c52fababan * RPC layer allocates empty strings to replace NULL char *.
334e34639228c5021a69504cca69d70d851c52fababan * This utility function frees these empty strings.
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,
62c6006265c37877b7a5b3c8ffce913ef559b955baban /* Allocate hash table to check for duplicate sids */
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.sid_history = calloc(batch.idmap_mapping_batch_len,
62c6006265c37877b7a5b3c8ffce913ef559b955baban state.sid_history_size = batch.idmap_mapping_batch_len;
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /* Get directory-based name mapping info */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Init our 'done' flags */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* First stage */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Check if we are done */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == TRUE && state.pid2sid_done == TRUE)
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * native LDAP lookups:
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * If nldap or mixed mode is enabled then pid2sid mapping requests
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * need to lookup native LDAP directory service by uid/gid to get
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * winname and unixname.
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * AD lookups:
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * 1. The pid2sid requests in the preceding step which successfully
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * retrieved winname from native LDAP objects will now need to
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * lookup AD by winname to get sid.
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * 2. The sid2pid requests will need to lookup AD by sid to get
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * winname and unixname (AD or mixed mode).
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * 3. If AD-based name mapping is enabled then pid2sid mapping
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * requests need to lookup AD by unixname to get winname and sid.
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * native LDAP lookups:
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * If nldap mode is enabled then sid2pid mapping requests
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * which successfully retrieved winname from AD objects in the
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * preceding step, will now need to lookup native LDAP directory
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban * service by winname to get unixname and pid.
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /* Reset 'done' flags */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Second stage */
e8c27ec857e6e2db8c4fe56938b70a89b5bed9f3baban /* First stage has already set the error */
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 */
71590c90e239661c113497da3ca8b7301dfbe24cnw if (sql_exec_no_cb(cache, IDMAP_CACHENAME, "BEGIN TRANSACTION;")
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* Commit if we have at least one successful update */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw if (state.sid2pid_done == FALSE || state.pid2sid_done == FALSE)
71590c90e239661c113497da3ca8b7301dfbe24cnw "COMMIT TRANSACTION;");
71590c90e239661c113497da3ca8b7301dfbe24cnw "END TRANSACTION;");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
cd37da7426f0c49c14ad9a8a07638ca971477566nwlist_mappings_cb(void *parg, int argc, char **argv, char **colnames)
cd37da7426f0c49c14ad9a8a07638ca971477566nw static int validated_column_names = 0;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp _VALIDATE_LIST_CB_DATA(19, &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 =
cd37da7426f0c49c14ad9a8a07638ca971477566nw result->mappings.mappings_val[cb_data->next].id1.idtype =
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val[cb_data->next].id2.idmap_id_u.uid =
cd37da7426f0c49c14ad9a8a07638ca971477566nw result->mappings.mappings_val[cb_data->next].id2.idtype =
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 =
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->mappings.mappings_val[cb_data->next].id1domain,
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->mappings.mappings_val[cb_data->next].id1name,
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->mappings.mappings_val[cb_data->next].id2name,
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp how = &result->mappings.mappings_val[cb_data->next].info.how;
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp /* Unknow mapping type */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (0);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejpidmap_list_mappings_1_svc(int64_t lastrowid, uint64_t limit, int32_t flag,
48258c6b4e17f36ab09fba0bd6307d1fec9dcbcejp /* Current time */
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
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)) "
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 (void) xdr_free(xdr_idmap_mappings_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
cd37da7426f0c49c14ad9a8a07638ca971477566nwlist_namerules_cb(void *parg, int argc, char **argv, char **colnames)
cd37da7426f0c49c14ad9a8a07638ca971477566nw static int validated_column_names = 0;
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->rules.rules_val[cb_data->next].windomain,
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->rules.rules_val[cb_data->next].winname,
8e22821528b08c6dba4e8176351560f316f6d0dedm STRDUP_OR_FAIL(result->rules.rules_val[cb_data->next].unixname,
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");
cd37da7426f0c49c14ad9a8a07638ca971477566nw "AND (u2w_order = 0 OR u2w_order ISNULL)");
cd37da7426f0c49c14ad9a8a07638ca971477566nw "AND (w2u_order = 0 OR w2u_order ISNULL)");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) snprintf(u2wbuf, sizeof (u2wbuf), "AND u2w_order > 0");
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
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 "
cd37da7426f0c49c14ad9a8a07638ca971477566nw " %s %s %s %s %s;",
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Execute the SQL statement and update the return buffer */
71590c90e239661c113497da3ca8b7301dfbe24cnw PROCESS_LIST_SVC_SQL(retcode, db, IDMAP_DBNAME, sql, limit,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw (void) xdr_free(xdr_idmap_namerules_res, (caddr_t)result);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (-1);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw return (1);
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.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
8e22821528b08c6dba4e8176351560f316f6d0dedmidmap_update_1_svc(idmap_update_batch batch, idmap_update_res *res,
8e22821528b08c6dba4e8176351560f316f6d0dedm (void) memset(&res->error_rule, 0, sizeof (res->error_rule));
8e22821528b08c6dba4e8176351560f316f6d0dedm (void) memset(&res->conflict_rule, 0, sizeof (res->conflict_rule));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
71590c90e239661c113497da3ca8b7301dfbe24cnw res->retcode = sql_exec_no_cb(db, IDMAP_DBNAME, "BEGIN TRANSACTION;");
71590c90e239661c113497da3ca8b7301dfbe24cnw "COMMIT TRANSACTION;");
71590c90e239661c113497da3ca8b7301dfbe24cnw "ROLLBACK TRANSACTION;");
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Init */
0dcc71495bad040a0c83830efc85acf8d897350dnw result->retcode = validate_mapped_id_by_name_req(&request);
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get cache handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Get db handle */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw /* Allocate result */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw result->mappings.mappings_val = calloc(1, sizeof (idmap_mapping));
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */