server.c revision bbf6f00c25b6a2bed23c35eac6d62998ecdb338c
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
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw * Use is subject to license terms.
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:
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 * 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 * 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 /* 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;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai /* Unknown 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 /* 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 "
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown " %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));
479ac37569625bae44ffb80071d4bc865fc710eddm/* ARGSUSED */
479ac37569625bae44ffb80071d4bc865fc710eddm /* Init */
479ac37569625bae44ffb80071d4bc865fc710eddm /* Just shortcuts: */
479ac37569625bae44ffb80071d4bc865fc710eddm result->value.idmap_prop_val_u.intval = pgcfg->list_size_limit;
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->domain_controller_auto_disc;
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->forest_name_auto_disc;
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->site_name_auto_disc;
4d61c878ad5fbf36c5338bef5994cc5fe88a589aJulian Pullen result->auto_discovered = pgcfg->global_catalog_auto_disc;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai STRDUP_CHECK(result->value.idmap_prop_val_u.utf8val,
c5c4113dfcabb1eed3d4bdf7609de5170027a794nw/* ARGSUSED */
c5c4113dfcabb1eed3d4bdf7609de5170027a794nwidmap_prog_1_freeresult(SVCXPRT *transp, xdrproc_t xdr_result,
1fcced4c370617db71610fecffd5451a5894ca5eJordan Brown * This function is called by rpc_svc.c when it encounters an error.