7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * CDDL HEADER START
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * The contents of this file are subject to the terms of the
7568150a58e78021968b6c22bc28e9787b33496agwr * Common Development and Distribution License (the "License").
7568150a58e78021968b6c22bc28e9787b33496agwr * You may not use this file except in compliance with the License.
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7568150a58e78021968b6c22bc28e9787b33496agwr * or http://www.opensolaris.org/os/licensing.
7568150a58e78021968b6c22bc28e9787b33496agwr * See the License for the specific language governing permissions
7568150a58e78021968b6c22bc28e9787b33496agwr * and limitations under the License.
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * When distributing Covered Code, include this CDDL HEADER in each
7568150a58e78021968b6c22bc28e9787b33496agwr * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7568150a58e78021968b6c22bc28e9787b33496agwr * If applicable, add the following below this CDDL HEADER, with the
7568150a58e78021968b6c22bc28e9787b33496agwr * fields enclosed by brackets "[]" replaced with your own identifying
7568150a58e78021968b6c22bc28e9787b33496agwr * information: Portions Copyright [yyyy] [name of copyright owner]
7568150a58e78021968b6c22bc28e9787b33496agwr *
7568150a58e78021968b6c22bc28e9787b33496agwr * CDDL HEADER END
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
7568150a58e78021968b6c22bc28e9787b33496agwr * Use is subject to license terms.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * ACL API for smbfs
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/types.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/errno.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/cred.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/cmn_err.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/kmem.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/sunddi.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/acl.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/vnode.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/vfs.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/byteorder.h>
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr#include <errno.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <stdio.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <strings.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <unistd.h>
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr#include <umem.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <idmap.h>
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr#include <sys/fs/smbfs_ioctl.h>
7568150a58e78021968b6c22bc28e9787b33496agwr
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross#include <netsmb/smb.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <netsmb/smb_lib.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <netsmb/smbfs_acl.h>
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross#include "smbfs_ntacl.h"
9c9af2590af49bb395bc8d2eace0f2d4ea16d165Gordon Ross#include "private.h"
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/* Sanity check SD sizes */
7568150a58e78021968b6c22bc28e9787b33496agwr#define MAX_RAW_SD_SIZE 32768
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/* XXX: acl_common.h */
7568150a58e78021968b6c22bc28e9787b33496agwracl_t *acl_alloc(enum acl_type);
7568150a58e78021968b6c22bc28e9787b33496agwrvoid acl_free(acl_t *);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * Get/set a Windows security descriptor (SD)
7568150a58e78021968b6c22bc28e9787b33496agwr * using the (private) smbfs ioctl mechanism.
7568150a58e78021968b6c22bc28e9787b33496agwr * Note: Get allocates mbp->mb_top
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/* ARGSUSED */
7568150a58e78021968b6c22bc28e9787b33496agwrint
7568150a58e78021968b6c22bc28e9787b33496agwrsmbfs_acl_iocget(int fd, uint32_t selector, mbdata_t *mbp)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr ioc_sdbuf_t iocb;
7568150a58e78021968b6c22bc28e9787b33496agwr struct mbuf *m;
7568150a58e78021968b6c22bc28e9787b33496agwr int error;
7568150a58e78021968b6c22bc28e9787b33496agwr
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross error = mb_init_sz(mbp, MAX_RAW_SD_SIZE);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error)
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr m = mbp->mb_top;
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.addr = mtod(m, uintptr_t);
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.alloc = m->m_maxlen;
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.used = 0;
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.selector = selector;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * This does the OTW Get.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr if (ioctl(fd, SMBFSIO_GETSD, &iocb) < 0) {
7568150a58e78021968b6c22bc28e9787b33496agwr error = errno;
7568150a58e78021968b6c22bc28e9787b33496agwr goto errout;
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr m->m_len = iocb.used;
7568150a58e78021968b6c22bc28e9787b33496agwr return (0);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrerrout:
7568150a58e78021968b6c22bc28e9787b33496agwr mb_done(mbp);
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/* ARGSUSED */
7568150a58e78021968b6c22bc28e9787b33496agwrint
7568150a58e78021968b6c22bc28e9787b33496agwrsmbfs_acl_iocset(int fd, uint32_t selector, mbdata_t *mbp)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr ioc_sdbuf_t iocb;
7568150a58e78021968b6c22bc28e9787b33496agwr struct mbuf *m;
7568150a58e78021968b6c22bc28e9787b33496agwr int error;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /* Make the data contiguous. */
7568150a58e78021968b6c22bc28e9787b33496agwr error = m_lineup(mbp->mb_top, &m);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error)
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr if (mbp->mb_top != m)
7568150a58e78021968b6c22bc28e9787b33496agwr mb_initm(mbp, m);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.addr = mtod(m, uintptr_t);
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.alloc = m->m_maxlen;
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.used = m->m_len;
7568150a58e78021968b6c22bc28e9787b33496agwr iocb.selector = selector;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * This does the OTW Set.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr if (ioctl(fd, SMBFSIO_SETSD, &iocb) < 0)
7568150a58e78021968b6c22bc28e9787b33496agwr error = errno;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * Get an NT SD from the open file via ioctl.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwrint
7568150a58e78021968b6c22bc28e9787b33496agwrsmbfs_acl_getsd(int fd, uint32_t selector, i_ntsd_t **sdp)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr mbdata_t *mbp, mb_store;
7568150a58e78021968b6c22bc28e9787b33496agwr int error;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr mbp = &mb_store;
7568150a58e78021968b6c22bc28e9787b33496agwr bzero(mbp, sizeof (*mbp));
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Get the raw Windows SD via ioctl.
7568150a58e78021968b6c22bc28e9787b33496agwr * Returns allocated mbchain in mbp.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr error = smbfs_acl_iocget(fd, selector, mbp);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error == 0) {
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Import the raw SD into "internal" form.
7568150a58e78021968b6c22bc28e9787b33496agwr * (like "absolute" form per. NT docs)
7568150a58e78021968b6c22bc28e9787b33496agwr * Returns allocated data in sdp
7568150a58e78021968b6c22bc28e9787b33496agwr */
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross error = md_get_ntsd(mbp, sdp);
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr mb_done(mbp);
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * Set an NT SD onto the open file via ioctl.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwrint
7568150a58e78021968b6c22bc28e9787b33496agwrsmbfs_acl_setsd(int fd, uint32_t selector, i_ntsd_t *sd)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr mbdata_t *mbp, mb_store;
7568150a58e78021968b6c22bc28e9787b33496agwr int error;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr mbp = &mb_store;
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross error = mb_init_sz(mbp, MAX_RAW_SD_SIZE);
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross if (error)
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Export the "internal" SD into an mb chain.
7568150a58e78021968b6c22bc28e9787b33496agwr * (a.k.a "self-relative" form per. NT docs)
7568150a58e78021968b6c22bc28e9787b33496agwr * Returns allocated mbchain in mbp.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr error = mb_put_ntsd(mbp, sd);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error == 0) {
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Set the raw Windows SD via ioctl.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr error = smbfs_acl_iocset(fd, selector, mbp);
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr mb_done(mbp);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * Convenience function to Get security using a
7568150a58e78021968b6c22bc28e9787b33496agwr * ZFS-style ACL (libsec acl, type=ACE_T)
7568150a58e78021968b6c22bc28e9787b33496agwr * Intentionally similar to: facl_get(3SEC)
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwrint
7568150a58e78021968b6c22bc28e9787b33496agwrsmbfs_acl_get(int fd, acl_t **aclp, uid_t *uidp, gid_t *gidp)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr i_ntsd_t *sd = NULL;
7568150a58e78021968b6c22bc28e9787b33496agwr acl_t *acl = NULL;
7568150a58e78021968b6c22bc28e9787b33496agwr uint32_t selector;
7568150a58e78021968b6c22bc28e9787b33496agwr int error;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Which parts of the SD are being requested?
7568150a58e78021968b6c22bc28e9787b33496agwr * XXX: Should we request the SACL too? If so,
7568150a58e78021968b6c22bc28e9787b33496agwr * might that cause this access to be denied?
7568150a58e78021968b6c22bc28e9787b33496agwr * Or maybe: if we get access denied, try the
7568150a58e78021968b6c22bc28e9787b33496agwr * open/fetch again without the SACL bit.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr selector = 0;
7568150a58e78021968b6c22bc28e9787b33496agwr if (aclp)
7568150a58e78021968b6c22bc28e9787b33496agwr selector |= DACL_SECURITY_INFORMATION;
7568150a58e78021968b6c22bc28e9787b33496agwr if (uidp)
7568150a58e78021968b6c22bc28e9787b33496agwr selector |= OWNER_SECURITY_INFORMATION;
7568150a58e78021968b6c22bc28e9787b33496agwr if (gidp)
7568150a58e78021968b6c22bc28e9787b33496agwr selector |= GROUP_SECURITY_INFORMATION;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr if (selector == 0)
7568150a58e78021968b6c22bc28e9787b33496agwr return (0);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Get the Windows SD via ioctl, in
7568150a58e78021968b6c22bc28e9787b33496agwr * "internal" (absolute) form.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr error = smbfs_acl_getsd(fd, selector, &sd);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error)
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr /* Note: sd now holds allocated data. */
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Convert the internal SD to a ZFS ACL.
7568150a58e78021968b6c22bc28e9787b33496agwr * Get uid/gid too if pointers != NULL.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr if (aclp) {
7568150a58e78021968b6c22bc28e9787b33496agwr acl = acl_alloc(ACE_T);
7568150a58e78021968b6c22bc28e9787b33496agwr if (acl == NULL) {
7568150a58e78021968b6c22bc28e9787b33496agwr error = ENOMEM;
7568150a58e78021968b6c22bc28e9787b33496agwr goto out;
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr error = smbfs_acl_sd2zfs(sd, acl, uidp, gidp);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error)
7568150a58e78021968b6c22bc28e9787b33496agwr goto out;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /* Success! */
7568150a58e78021968b6c22bc28e9787b33496agwr if (aclp) {
7568150a58e78021968b6c22bc28e9787b33496agwr *aclp = acl;
7568150a58e78021968b6c22bc28e9787b33496agwr acl = NULL;
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrout:
7568150a58e78021968b6c22bc28e9787b33496agwr if (acl)
7568150a58e78021968b6c22bc28e9787b33496agwr acl_free(acl);
7568150a58e78021968b6c22bc28e9787b33496agwr smbfs_acl_free_sd(sd);
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr/*
7568150a58e78021968b6c22bc28e9787b33496agwr * Convenience function to Set security using a
7568150a58e78021968b6c22bc28e9787b33496agwr * ZFS-style ACL (libsec acl, type=ACE_T)
7568150a58e78021968b6c22bc28e9787b33496agwr * Intentionally similar to: facl_set(3SEC)
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwrint
7568150a58e78021968b6c22bc28e9787b33496agwrsmbfs_acl_set(int fd, acl_t *acl, uid_t uid, gid_t gid)
7568150a58e78021968b6c22bc28e9787b33496agwr{
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross struct stat st;
7568150a58e78021968b6c22bc28e9787b33496agwr i_ntsd_t *sd = NULL;
7568150a58e78021968b6c22bc28e9787b33496agwr uint32_t selector;
7568150a58e78021968b6c22bc28e9787b33496agwr int error;
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross if (acl && acl->acl_type != ACE_T)
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross return (EINVAL);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Which parts of the SD are being modified?
7568150a58e78021968b6c22bc28e9787b33496agwr * XXX: Ditto comments above re. SACL.
7568150a58e78021968b6c22bc28e9787b33496agwr */
7568150a58e78021968b6c22bc28e9787b33496agwr selector = 0;
7568150a58e78021968b6c22bc28e9787b33496agwr if (acl)
7568150a58e78021968b6c22bc28e9787b33496agwr selector |= DACL_SECURITY_INFORMATION;
7568150a58e78021968b6c22bc28e9787b33496agwr if (uid != (uid_t)-1)
7568150a58e78021968b6c22bc28e9787b33496agwr selector |= OWNER_SECURITY_INFORMATION;
7568150a58e78021968b6c22bc28e9787b33496agwr if (gid != (gid_t)-1)
7568150a58e78021968b6c22bc28e9787b33496agwr selector |= GROUP_SECURITY_INFORMATION;
7568150a58e78021968b6c22bc28e9787b33496agwr if (selector == 0)
7568150a58e78021968b6c22bc28e9787b33496agwr return (0);
7568150a58e78021968b6c22bc28e9787b33496agwr
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross if (uid == (uid_t)-1 || gid == (gid_t)-1) {
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross /*
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * If not setting owner or group, we need the
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * current owner and group for translating
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross * references via owner@ or group@ ACEs.
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross */
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross if (fstat(fd, &st) != 0)
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross return (errno);
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross if (uid == (uid_t)-1)
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross uid = st.st_uid;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross if (gid == (gid_t)-1)
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross gid = st.st_gid;
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /*
7568150a58e78021968b6c22bc28e9787b33496agwr * Convert the ZFS ACL to an internal SD.
7568150a58e78021968b6c22bc28e9787b33496agwr * Returns allocated data in sd
7568150a58e78021968b6c22bc28e9787b33496agwr */
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross error = smbfs_acl_zfs2sd(acl, uid, gid, selector, &sd);
7568150a58e78021968b6c22bc28e9787b33496agwr if (error == 0)
7568150a58e78021968b6c22bc28e9787b33496agwr error = smbfs_acl_setsd(fd, selector, sd);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr smbfs_acl_free_sd(sd);
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr return (error);
7568150a58e78021968b6c22bc28e9787b33496agwr}