xref: /onnv-gate/usr/src/cmd/fs.d/smbclnt/lsacl/lsacl.c (revision 6711:d684034ad960)
1*6711Sgwr /*
2*6711Sgwr  * CDDL HEADER START
3*6711Sgwr  *
4*6711Sgwr  * The contents of this file are subject to the terms of the
5*6711Sgwr  * Common Development and Distribution License (the "License").
6*6711Sgwr  * You may not use this file except in compliance with the License.
7*6711Sgwr  *
8*6711Sgwr  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*6711Sgwr  * or http://www.opensolaris.org/os/licensing.
10*6711Sgwr  * See the License for the specific language governing permissions
11*6711Sgwr  * and limitations under the License.
12*6711Sgwr  *
13*6711Sgwr  * When distributing Covered Code, include this CDDL HEADER in each
14*6711Sgwr  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*6711Sgwr  * If applicable, add the following below this CDDL HEADER, with the
16*6711Sgwr  * fields enclosed by brackets "[]" replaced with your own identifying
17*6711Sgwr  * information: Portions Copyright [yyyy] [name of copyright owner]
18*6711Sgwr  *
19*6711Sgwr  * CDDL HEADER END
20*6711Sgwr  */
21*6711Sgwr 
22*6711Sgwr /*
23*6711Sgwr  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24*6711Sgwr  * Use is subject to license terms.
25*6711Sgwr  */
26*6711Sgwr 
27*6711Sgwr #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*6711Sgwr 
29*6711Sgwr /*
30*6711Sgwr  * This is the smbfs/lsacl command.
31*6711Sgwr  * (just for testing - not installed)
32*6711Sgwr  */
33*6711Sgwr 
34*6711Sgwr #include <sys/types.h>
35*6711Sgwr #include <sys/errno.h>
36*6711Sgwr #include <sys/stat.h>
37*6711Sgwr #include <sys/acl.h>
38*6711Sgwr 
39*6711Sgwr #include <fcntl.h>
40*6711Sgwr #include <stdio.h>
41*6711Sgwr #include <stdlib.h>
42*6711Sgwr #include <unistd.h>
43*6711Sgwr #include <string.h>
44*6711Sgwr 
45*6711Sgwr #include <netsmb/smb_lib.h>
46*6711Sgwr #include <netsmb/smbfs_acl.h>
47*6711Sgwr 
48*6711Sgwr char *progname;
49*6711Sgwr 
50*6711Sgwr extern void acl_printacl(acl_t *, int, int);
51*6711Sgwr 
52*6711Sgwr 
53*6711Sgwr void
54*6711Sgwr usage(void)
55*6711Sgwr {
56*6711Sgwr 	fprintf(stderr, "usage: %s file\n", progname);
57*6711Sgwr 	exit(1);
58*6711Sgwr }
59*6711Sgwr 
60*6711Sgwr int
61*6711Sgwr main(int argc, char **argv)
62*6711Sgwr {
63*6711Sgwr 	struct acl_info *acl;
64*6711Sgwr 	uid_t uid;
65*6711Sgwr 	gid_t gid;
66*6711Sgwr 	int error, fd;
67*6711Sgwr 	i_ntsd_t *sd;
68*6711Sgwr 
69*6711Sgwr 	progname = argv[0];
70*6711Sgwr 
71*6711Sgwr 	if (argc < 2)
72*6711Sgwr 		usage();
73*6711Sgwr 
74*6711Sgwr 	fd = open(argv[1], O_RDONLY, 0);
75*6711Sgwr 	if (fd < 0) {
76*6711Sgwr 		perror(argv[1]);
77*6711Sgwr 		exit(1);
78*6711Sgwr 	}
79*6711Sgwr 
80*6711Sgwr 	/* First, get the raw NT SD. */
81*6711Sgwr 	error = smbfs_acl_getsd(fd, 7, &sd);
82*6711Sgwr 	if (error) {
83*6711Sgwr 		fprintf(stderr, "getsd: %s\n",
84*6711Sgwr 		    smb_strerror(error));
85*6711Sgwr 		exit(1);
86*6711Sgwr 	}
87*6711Sgwr 
88*6711Sgwr 	/*
89*6711Sgwr 	 * Print it first in Windows form.  This way,
90*6711Sgwr 	 * if any of the conversion has problems,
91*6711Sgwr 	 * one can try mapping each SID by hand, i.e.:
92*6711Sgwr 	 *    idmap show sid:S-1-xxx-yyy-zzz
93*6711Sgwr 	 */
94*6711Sgwr 	printf("CIFS security data:\n");
95*6711Sgwr 	smbfs_acl_print_sd(stdout, sd);
96*6711Sgwr 	printf("\n");
97*6711Sgwr 
98*6711Sgwr 	/*
99*6711Sgwr 	 * Get it again as a ZFS-style ACL (ACE_T)
100*6711Sgwr 	 */
101*6711Sgwr 	error = smbfs_acl_get(fd, &acl, &uid, &gid);
102*6711Sgwr 	if (error) {
103*6711Sgwr 		fprintf(stderr, "getacl: %s\n",
104*6711Sgwr 		    smb_strerror(error));
105*6711Sgwr 		exit(1);
106*6711Sgwr 	}
107*6711Sgwr 	printf("Solaris security data:\n");
108*6711Sgwr 	if (uid == (uid_t)-1)
109*6711Sgwr 		printf("owner: -1\n");
110*6711Sgwr 	else
111*6711Sgwr 		printf("owner: %u\n", uid);
112*6711Sgwr 	if (gid == (gid_t)-1)
113*6711Sgwr 		printf("group: -1\n");
114*6711Sgwr 	else
115*6711Sgwr 		printf("group: %u\n", gid);
116*6711Sgwr 	acl_printacl(acl, 80, 0);
117*6711Sgwr 	printf("\n");
118*6711Sgwr 
119*6711Sgwr 	return (0);
120*6711Sgwr }
121