16711Sgwr /*
26711Sgwr * CDDL HEADER START
36711Sgwr *
46711Sgwr * The contents of this file are subject to the terms of the
56711Sgwr * Common Development and Distribution License (the "License").
66711Sgwr * You may not use this file except in compliance with the License.
76711Sgwr *
86711Sgwr * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96711Sgwr * or http://www.opensolaris.org/os/licensing.
106711Sgwr * See the License for the specific language governing permissions
116711Sgwr * and limitations under the License.
126711Sgwr *
136711Sgwr * When distributing Covered Code, include this CDDL HEADER in each
146711Sgwr * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156711Sgwr * If applicable, add the following below this CDDL HEADER, with the
166711Sgwr * fields enclosed by brackets "[]" replaced with your own identifying
176711Sgwr * information: Portions Copyright [yyyy] [name of copyright owner]
186711Sgwr *
196711Sgwr * CDDL HEADER END
206711Sgwr */
216711Sgwr
226711Sgwr /*
23*11564SGordon.Ross@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
246711Sgwr * Use is subject to license terms.
256711Sgwr */
266711Sgwr
276711Sgwr /*
286711Sgwr * Print an NT Security Descriptor (SD) and its sub-components.
296711Sgwr */
306711Sgwr
316711Sgwr #include <sys/types.h>
326711Sgwr #include <sys/errno.h>
336711Sgwr #include <sys/cred.h>
346711Sgwr #include <sys/cmn_err.h>
356711Sgwr #include <sys/kmem.h>
366711Sgwr #include <sys/sunddi.h>
376711Sgwr #include <sys/acl.h>
386711Sgwr #include <sys/vnode.h>
396711Sgwr #include <sys/vfs.h>
406711Sgwr #include <sys/byteorder.h>
416711Sgwr
426711Sgwr #include <errno.h>
436711Sgwr #include <stdio.h>
446711Sgwr #include <string.h>
456711Sgwr #include <strings.h>
466711Sgwr #include <unistd.h>
476711Sgwr
486711Sgwr #include <umem.h>
496711Sgwr #include <idmap.h>
506711Sgwr
516711Sgwr #include <sys/fs/smbfs_ioctl.h>
526711Sgwr
536711Sgwr #include <netsmb/smb_lib.h>
546711Sgwr #include <netsmb/smbfs_acl.h>
5510023SGordon.Ross@Sun.COM
5611332SGordon.Ross@Sun.COM #include "smbfs_ntacl.h"
576711Sgwr
586711Sgwr static void
fprint_sid(FILE * fp,i_ntsid_t * sid)596711Sgwr fprint_sid(FILE *fp, i_ntsid_t *sid)
606711Sgwr {
616711Sgwr static char sidbuf[256];
626711Sgwr
636711Sgwr if (sid == NULL) {
646711Sgwr fprintf(fp, "(null)\n");
656711Sgwr return;
666711Sgwr }
676711Sgwr
686711Sgwr if (smbfs_sid2str(sid, sidbuf, sizeof (sidbuf), NULL) < 0)
696711Sgwr fprintf(fp, "(error)\n");
706711Sgwr else
716711Sgwr fprintf(fp, "%s\n", sidbuf);
726711Sgwr }
736711Sgwr
746711Sgwr static void
fprint_ntace(FILE * fp,i_ntace_t * ace)756711Sgwr fprint_ntace(FILE *fp, i_ntace_t *ace)
766711Sgwr {
776711Sgwr if (ace == NULL) {
786711Sgwr fprintf(fp, " (null)\n");
796711Sgwr return;
806711Sgwr }
816711Sgwr
826711Sgwr /* ACEs are always printed in a list, so indent by 2. */
836711Sgwr fprintf(fp, " ace_type=%d ace_flags=0x%x ace_rights=0x%x\n",
84*11564SGordon.Ross@Sun.COM ace->ace_hdr.ace_type, ace->ace_hdr.ace_flags,
85*11564SGordon.Ross@Sun.COM ace->ace_v2.ace_rights);
866711Sgwr /* Show the SID as a "continuation" line. */
876711Sgwr fprintf(fp, " ace_sid: ");
88*11564SGordon.Ross@Sun.COM fprint_sid(fp, ace->ace_v2.ace_sid);
896711Sgwr }
906711Sgwr
916711Sgwr static void
fprint_ntacl(FILE * fp,i_ntacl_t * acl)926711Sgwr fprint_ntacl(FILE *fp, i_ntacl_t *acl)
936711Sgwr {
946711Sgwr int i;
956711Sgwr
966711Sgwr if (acl == NULL) {
976711Sgwr fprintf(fp, "(null)\n");
986711Sgwr return;
996711Sgwr }
1006711Sgwr
1016711Sgwr fprintf(fp, "acl_rev=%d acl_acecount=%d\n",
1026711Sgwr acl->acl_revision, acl->acl_acecount);
1036711Sgwr for (i = 0; i < acl->acl_acecount; i++)
1046711Sgwr fprint_ntace(fp, acl->acl_acevec[i]);
1056711Sgwr }
1066711Sgwr
1076711Sgwr void
smbfs_acl_print_sd(FILE * fp,i_ntsd_t * sd)1086711Sgwr smbfs_acl_print_sd(FILE *fp, i_ntsd_t *sd)
1096711Sgwr {
1106711Sgwr
1116711Sgwr fprintf(fp, "sd_rev=%d, flags=0x%x\n",
1126711Sgwr sd->sd_revision, sd->sd_flags);
1136711Sgwr fprintf(fp, "owner: ");
1146711Sgwr fprint_sid(fp, sd->sd_owner);
1156711Sgwr fprintf(fp, "group: ");
1166711Sgwr fprint_sid(fp, sd->sd_group);
1176711Sgwr fprintf(fp, "sacl: ");
1186711Sgwr fprint_ntacl(fp, sd->sd_sacl);
1196711Sgwr fprintf(fp, "dacl: ");
1206711Sgwr fprint_ntacl(fp, sd->sd_dacl);
1216711Sgwr }
122