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 * Print an NT Security Descriptor (SD) and its sub-components.
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 <string.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
7568150a58e78021968b6c22bc28e9787b33496agwr#include <netsmb/smb_lib.h>
7568150a58e78021968b6c22bc28e9787b33496agwr#include <netsmb/smbfs_acl.h>
613a2f6ba31e891e3d947a356daf5e563d43c1ceGordon Ross
02d09e03eb27f3a2dc299de704e45dae5173f43fGordon Ross#include "smbfs_ntacl.h"
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrstatic void
7568150a58e78021968b6c22bc28e9787b33496agwrfprint_sid(FILE *fp, i_ntsid_t *sid)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr static char sidbuf[256];
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr if (sid == NULL) {
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "(null)\n");
7568150a58e78021968b6c22bc28e9787b33496agwr return;
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr if (smbfs_sid2str(sid, sidbuf, sizeof (sidbuf), NULL) < 0)
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "(error)\n");
7568150a58e78021968b6c22bc28e9787b33496agwr else
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "%s\n", sidbuf);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrstatic void
7568150a58e78021968b6c22bc28e9787b33496agwrfprint_ntace(FILE *fp, i_ntace_t *ace)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr if (ace == NULL) {
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, " (null)\n");
7568150a58e78021968b6c22bc28e9787b33496agwr return;
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr /* ACEs are always printed in a list, so indent by 2. */
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, " ace_type=%d ace_flags=0x%x ace_rights=0x%x\n",
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross ace->ace_hdr.ace_type, ace->ace_hdr.ace_flags,
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross ace->ace_v2.ace_rights);
7568150a58e78021968b6c22bc28e9787b33496agwr /* Show the SID as a "continuation" line. */
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, " ace_sid: ");
bd7c6f51f14365fc31d408903b38c02177384d3dGordon Ross fprint_sid(fp, ace->ace_v2.ace_sid);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrstatic void
7568150a58e78021968b6c22bc28e9787b33496agwrfprint_ntacl(FILE *fp, i_ntacl_t *acl)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr int i;
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr if (acl == NULL) {
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "(null)\n");
7568150a58e78021968b6c22bc28e9787b33496agwr return;
7568150a58e78021968b6c22bc28e9787b33496agwr }
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "acl_rev=%d acl_acecount=%d\n",
7568150a58e78021968b6c22bc28e9787b33496agwr acl->acl_revision, acl->acl_acecount);
7568150a58e78021968b6c22bc28e9787b33496agwr for (i = 0; i < acl->acl_acecount; i++)
7568150a58e78021968b6c22bc28e9787b33496agwr fprint_ntace(fp, acl->acl_acevec[i]);
7568150a58e78021968b6c22bc28e9787b33496agwr}
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwrvoid
7568150a58e78021968b6c22bc28e9787b33496agwrsmbfs_acl_print_sd(FILE *fp, i_ntsd_t *sd)
7568150a58e78021968b6c22bc28e9787b33496agwr{
7568150a58e78021968b6c22bc28e9787b33496agwr
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "sd_rev=%d, flags=0x%x\n",
7568150a58e78021968b6c22bc28e9787b33496agwr sd->sd_revision, sd->sd_flags);
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "owner: ");
7568150a58e78021968b6c22bc28e9787b33496agwr fprint_sid(fp, sd->sd_owner);
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "group: ");
7568150a58e78021968b6c22bc28e9787b33496agwr fprint_sid(fp, sd->sd_group);
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "sacl: ");
7568150a58e78021968b6c22bc28e9787b33496agwr fprint_ntacl(fp, sd->sd_sacl);
7568150a58e78021968b6c22bc28e9787b33496agwr fprintf(fp, "dacl: ");
7568150a58e78021968b6c22bc28e9787b33496agwr fprint_ntacl(fp, sd->sd_dacl);
7568150a58e78021968b6c22bc28e9787b33496agwr}