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