fksmb_idmap.c revision b819cea2f73f98c5662230cc9affc8cc84f77fcf
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER START
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * The contents of this file are subject to the terms of the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Common Development and Distribution License (the "License").
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You may not use this file except in compliance with the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * See the License for the specific language governing permissions
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * and limitations under the License.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * When distributing Covered Code, include this CDDL HEADER in each
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If applicable, add the following below this CDDL HEADER, with the
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * fields enclosed by brackets "[]" replaced with your own identifying
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * information: Portions Copyright [yyyy] [name of copyright owner]
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * CDDL HEADER END
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * SMB server interface to idmap
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * (smb_idmap_get..., smb_idmap_batch_...)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * There are three implementations of this interface:
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * uts/common/fs/smbsrv/smb_idmap.c (smbsrv kmod)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * lib/smbsrv/libfksmbsrv/common/fksmb_idmap.c (libfksmbsrv)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * There are enough differences (relative to the code size)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * that it's more trouble than it's worth to merge them.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * This one differs from the others in that it:
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * calls idmap interfaces (libidmap)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * uses kmem_... interfaces (libfakekernel)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * uses cmn_err instead of syslog, etc.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rossstatic int smb_idmap_batch_binsid(smb_idmap_batch_t *sib);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Report an idmap error.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross s = "smb_idmap_check";
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_getsid
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Tries to get a mapping for the given uid/gid
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Allocates ->sim_domsid
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmb_idmap_getsid(uid_t id, int idtype, smb_sid_t **sid)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross stat = smb_idmap_batch_create(&sib, 1, SMB_IDMAP_ID2SID);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross stat = smb_idmap_batch_getsid(sib.sib_idmaph, &sib.sib_maps[0],
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_getid
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Tries to get a mapping for the given SID
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmb_idmap_getid(smb_sid_t *sid, uid_t *id, int *id_type)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross stat = smb_idmap_batch_create(&sib, 1, SMB_IDMAP_SID2ID);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross stat = smb_idmap_batch_getid(sib.sib_idmaph, sim, sid, *id_type);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_batch_create
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Creates and initializes the context for batch ID mapping.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmb_idmap_batch_create(smb_idmap_batch_t *sib, uint16_t nmap, int flags)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross sib->sib_maps = kmem_zalloc(sib->sib_size, KM_SLEEP);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_batch_destroy
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Frees the batch ID mapping context.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * SIDs are allocated only when mapping
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* from strdup() in libidmap */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_batch_getid
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Queue a request to map the given SID to a UID or GID.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * sim->sim_id should point to variable that's supposed to
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * hold the returned UID/GID. This needs to be setup by caller
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * of this function.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * If requested ID type is known, it's passed as 'idtype',
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * if it's unknown it'll be returned in sim->sim_idtype.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmb_idmap_batch_getid(idmap_get_handle_t *idmaph, smb_idmap_t *sim,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (idmaph == NULL || sim == NULL || sid == NULL)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if (smb_sid_splitstr(sidstr, &sim->sim_rid) != 0)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross stat = idmap_get_uidbysid(idmaph, sim->sim_domsid,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross sim->sim_rid, flag, sim->sim_id, &sim->sim_stat);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross stat = idmap_get_gidbysid(idmaph, sim->sim_domsid,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross sim->sim_rid, flag, sim->sim_id, &sim->sim_stat);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross stat = idmap_get_pidbysid(idmaph, sim->sim_domsid,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross sim->sim_rid, flag, sim->sim_id, &sim->sim_idtype,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* This was copied by idmap_get_Xbysid. */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_batch_getsid
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Queue a request to map the given UID/GID to a SID.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * sim->sim_domsid and sim->sim_rid will contain the mapping
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * result upon successful process of the batched request.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * NB: sim_domsid allocated by strdup, here or in libidmap
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmb_idmap_batch_getsid(idmap_get_handle_t *idmaph, smb_idmap_t *sim,
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross &sim->sim_domsid, &sim->sim_rid, &sim->sim_stat);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross &sim->sim_domsid, &sim->sim_rid, &sim->sim_stat);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Current Owner S-1-5-32-766 */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross sim->sim_domsid = strdup(NT_BUILTIN_DOMAIN_SIDSTR);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Current Group S-1-5-32-767 */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross sim->sim_domsid = strdup(NT_BUILTIN_DOMAIN_SIDSTR);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* Everyone S-1-1-0 */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_batch_getmappings
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * trigger ID mapping service to get the mappings for queued
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Checks the result of all the queued requests.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Rosssmb_idmap_batch_getmappings(smb_idmap_batch_t *sib)
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross if ((stat = idmap_get_mappings(sib->sib_idmaph)) != IDMAP_SUCCESS) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Check the status for all the queued requests
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross for (i = 0, sim = sib->sib_maps; i < sib->sib_nmap; i++, sim++) {
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * smb_idmap_batch_binsid
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Convert sidrids to binary sids
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross * Returns 0 if successful and non-zero upon failure.
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross /* This operation is not required */
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (-1);
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross return (-1);