xref: /titanic_41/usr/src/cmd/fs.d/smbclnt/lsacl/lsacl.c (revision b509e89b2befbaa42939abad9da1d7f5a8c6aaae)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * This is the smbfs/lsacl command.
31  * (just for testing - not installed)
32  */
33 
34 #include <sys/types.h>
35 #include <sys/errno.h>
36 #include <sys/stat.h>
37 #include <sys/acl.h>
38 
39 #include <fcntl.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <unistd.h>
43 #include <string.h>
44 
45 #include <netsmb/smb_lib.h>
46 #include <netsmb/smbfs_acl.h>
47 
48 char *progname;
49 
50 extern void acl_printacl(acl_t *, int, int);
51 
52 
53 void
54 usage(void)
55 {
56 	fprintf(stderr, "usage: %s file\n", progname);
57 	exit(1);
58 }
59 
60 int
61 main(int argc, char **argv)
62 {
63 	struct acl_info *acl;
64 	uid_t uid;
65 	gid_t gid;
66 	int error, fd;
67 	i_ntsd_t *sd;
68 
69 	progname = argv[0];
70 
71 	if (argc < 2)
72 		usage();
73 
74 	fd = open(argv[1], O_RDONLY, 0);
75 	if (fd < 0) {
76 		perror(argv[1]);
77 		exit(1);
78 	}
79 
80 	/* First, get the raw NT SD. */
81 	error = smbfs_acl_getsd(fd, 7, &sd);
82 	if (error) {
83 		fprintf(stderr, "getsd: %s\n",
84 		    smb_strerror(error));
85 		exit(1);
86 	}
87 
88 	/*
89 	 * Print it first in Windows form.  This way,
90 	 * if any of the conversion has problems,
91 	 * one can try mapping each SID by hand, i.e.:
92 	 *    idmap show sid:S-1-xxx-yyy-zzz
93 	 */
94 	printf("CIFS security data:\n");
95 	smbfs_acl_print_sd(stdout, sd);
96 	printf("\n");
97 
98 	/*
99 	 * Get it again as a ZFS-style ACL (ACE_T)
100 	 */
101 	error = smbfs_acl_get(fd, &acl, &uid, &gid);
102 	if (error) {
103 		fprintf(stderr, "getacl: %s\n",
104 		    smb_strerror(error));
105 		exit(1);
106 	}
107 	printf("Solaris security data:\n");
108 	if (uid == (uid_t)-1)
109 		printf("owner: -1\n");
110 	else
111 		printf("owner: %u\n", uid);
112 	if (gid == (gid_t)-1)
113 		printf("group: -1\n");
114 	else
115 		printf("group: %u\n", gid);
116 	acl_printacl(acl, 80, 0);
117 	printf("\n");
118 
119 	return (0);
120 }
121