xref: /titanic_41/usr/src/lib/libsmbfs/smb/acl_print.c (revision bd7c6f51f14365fc31d408903b38c02177384d3d)
17568150aSgwr /*
27568150aSgwr  * CDDL HEADER START
37568150aSgwr  *
47568150aSgwr  * The contents of this file are subject to the terms of the
57568150aSgwr  * Common Development and Distribution License (the "License").
67568150aSgwr  * You may not use this file except in compliance with the License.
77568150aSgwr  *
87568150aSgwr  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97568150aSgwr  * or http://www.opensolaris.org/os/licensing.
107568150aSgwr  * See the License for the specific language governing permissions
117568150aSgwr  * and limitations under the License.
127568150aSgwr  *
137568150aSgwr  * When distributing Covered Code, include this CDDL HEADER in each
147568150aSgwr  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157568150aSgwr  * If applicable, add the following below this CDDL HEADER, with the
167568150aSgwr  * fields enclosed by brackets "[]" replaced with your own identifying
177568150aSgwr  * information: Portions Copyright [yyyy] [name of copyright owner]
187568150aSgwr  *
197568150aSgwr  * CDDL HEADER END
207568150aSgwr  */
217568150aSgwr 
227568150aSgwr /*
23*bd7c6f51SGordon Ross  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
247568150aSgwr  * Use is subject to license terms.
257568150aSgwr  */
267568150aSgwr 
277568150aSgwr /*
287568150aSgwr  * Print an NT Security Descriptor (SD) and its sub-components.
297568150aSgwr  */
307568150aSgwr 
317568150aSgwr #include <sys/types.h>
327568150aSgwr #include <sys/errno.h>
337568150aSgwr #include <sys/cred.h>
347568150aSgwr #include <sys/cmn_err.h>
357568150aSgwr #include <sys/kmem.h>
367568150aSgwr #include <sys/sunddi.h>
377568150aSgwr #include <sys/acl.h>
387568150aSgwr #include <sys/vnode.h>
397568150aSgwr #include <sys/vfs.h>
407568150aSgwr #include <sys/byteorder.h>
417568150aSgwr 
427568150aSgwr #include <errno.h>
437568150aSgwr #include <stdio.h>
447568150aSgwr #include <string.h>
457568150aSgwr #include <strings.h>
467568150aSgwr #include <unistd.h>
477568150aSgwr 
487568150aSgwr #include <umem.h>
497568150aSgwr #include <idmap.h>
507568150aSgwr 
517568150aSgwr #include <sys/fs/smbfs_ioctl.h>
527568150aSgwr 
537568150aSgwr #include <netsmb/smb_lib.h>
547568150aSgwr #include <netsmb/smbfs_acl.h>
55613a2f6bSGordon Ross 
5602d09e03SGordon Ross #include "smbfs_ntacl.h"
577568150aSgwr 
587568150aSgwr static void
fprint_sid(FILE * fp,i_ntsid_t * sid)597568150aSgwr fprint_sid(FILE *fp, i_ntsid_t *sid)
607568150aSgwr {
617568150aSgwr 	static char sidbuf[256];
627568150aSgwr 
637568150aSgwr 	if (sid == NULL) {
647568150aSgwr 		fprintf(fp, "(null)\n");
657568150aSgwr 		return;
667568150aSgwr 	}
677568150aSgwr 
687568150aSgwr 	if (smbfs_sid2str(sid, sidbuf, sizeof (sidbuf), NULL) < 0)
697568150aSgwr 		fprintf(fp, "(error)\n");
707568150aSgwr 	else
717568150aSgwr 		fprintf(fp, "%s\n", sidbuf);
727568150aSgwr }
737568150aSgwr 
747568150aSgwr static void
fprint_ntace(FILE * fp,i_ntace_t * ace)757568150aSgwr fprint_ntace(FILE *fp, i_ntace_t *ace)
767568150aSgwr {
777568150aSgwr 	if (ace == NULL) {
787568150aSgwr 		fprintf(fp, "  (null)\n");
797568150aSgwr 		return;
807568150aSgwr 	}
817568150aSgwr 
827568150aSgwr 	/* ACEs are always printed in a list, so indent by 2. */
837568150aSgwr 	fprintf(fp, "  ace_type=%d ace_flags=0x%x ace_rights=0x%x\n",
84*bd7c6f51SGordon Ross 	    ace->ace_hdr.ace_type, ace->ace_hdr.ace_flags,
85*bd7c6f51SGordon Ross 	    ace->ace_v2.ace_rights);
867568150aSgwr 	/* Show the SID as a "continuation" line. */
877568150aSgwr 	fprintf(fp, "    ace_sid: ");
88*bd7c6f51SGordon Ross 	fprint_sid(fp, ace->ace_v2.ace_sid);
897568150aSgwr }
907568150aSgwr 
917568150aSgwr static void
fprint_ntacl(FILE * fp,i_ntacl_t * acl)927568150aSgwr fprint_ntacl(FILE *fp, i_ntacl_t *acl)
937568150aSgwr {
947568150aSgwr 	int i;
957568150aSgwr 
967568150aSgwr 	if (acl == NULL) {
977568150aSgwr 		fprintf(fp, "(null)\n");
987568150aSgwr 		return;
997568150aSgwr 	}
1007568150aSgwr 
1017568150aSgwr 	fprintf(fp, "acl_rev=%d acl_acecount=%d\n",
1027568150aSgwr 	    acl->acl_revision, acl->acl_acecount);
1037568150aSgwr 	for (i = 0; i < acl->acl_acecount; i++)
1047568150aSgwr 		fprint_ntace(fp, acl->acl_acevec[i]);
1057568150aSgwr }
1067568150aSgwr 
1077568150aSgwr void
smbfs_acl_print_sd(FILE * fp,i_ntsd_t * sd)1087568150aSgwr smbfs_acl_print_sd(FILE *fp, i_ntsd_t *sd)
1097568150aSgwr {
1107568150aSgwr 
1117568150aSgwr 	fprintf(fp, "sd_rev=%d, flags=0x%x\n",
1127568150aSgwr 	    sd->sd_revision, sd->sd_flags);
1137568150aSgwr 	fprintf(fp, "owner: ");
1147568150aSgwr 	fprint_sid(fp, sd->sd_owner);
1157568150aSgwr 	fprintf(fp, "group: ");
1167568150aSgwr 	fprint_sid(fp, sd->sd_group);
1177568150aSgwr 	fprintf(fp, "sacl: ");
1187568150aSgwr 	fprint_ntacl(fp, sd->sd_sacl);
1197568150aSgwr 	fprintf(fp, "dacl: ");
1207568150aSgwr 	fprint_ntacl(fp, sd->sd_dacl);
1217568150aSgwr }
122