8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / fs.d / smbclnt / lsacl / lsacl.c
blobd92461195d198bac8b01593e9015a569a03d11ad
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * This is the smbfs/lsacl command.
29 * (just for testing - not installed)
32 #include <sys/types.h>
33 #include <sys/errno.h>
34 #include <sys/stat.h>
35 #include <sys/acl.h>
36 #include <sys/acl_impl.h>
38 #include <fcntl.h>
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <unistd.h>
42 #include <string.h>
43 #include <aclutils.h>
45 #include <netsmb/smbfs_acl.h>
47 extern acl_t *acl_alloc(acl_type_t);
49 char *progname;
50 int Vflag;
52 uint32_t selector = DACL_SECURITY_INFORMATION |
53 OWNER_SECURITY_INFORMATION |
54 GROUP_SECURITY_INFORMATION;
56 void lsacl(char *);
58 void
59 usage(void)
61 fprintf(stderr, "Usage: %s [-v] file ...\n", progname);
62 exit(1);
65 int
66 main(int argc, char **argv)
68 int c;
70 progname = argv[0];
72 while ((c = getopt(argc, argv, "v")) != -1) {
73 switch (c) {
74 case 'v':
75 Vflag++;
76 break;
78 badopt:
79 default:
80 fprintf(stderr, "%s: bad option: %c\n",
81 progname, c);
82 usage();
83 break;
87 if (optind == argc)
88 usage();
89 for (; optind < argc; optind++)
90 lsacl(argv[optind]);
92 return (0);
95 void
96 lsacl(char *file)
98 struct i_ntsd *sd;
99 acl_t *acl;
100 uid_t uid;
101 gid_t gid;
102 int error, fd;
104 fd = open(file, O_RDONLY, 0);
105 if (fd < 0) {
106 perror(file);
107 exit(1);
110 /* First, get the SD in internal form. */
111 error = smbfs_acl_getsd(fd, selector, &sd);
112 (void) close(fd);
114 if (error) {
115 fprintf(stderr, "%s: getsd, %s\n",
116 progname, strerror(error));
117 exit(1);
120 if (Vflag) {
122 * Print it first in Windows form. This way,
123 * if any of the conversion has problems,
124 * one can try mapping each SID by hand, i.e.:
125 * idmap show sid:S-1-xxx-yyy-zzz
127 printf("CIFS security data:\n");
128 smbfs_acl_print_sd(stdout, sd);
129 printf("\n");
133 * Convert the internal SD to a ZFS ACL.
135 acl = acl_alloc(ACE_T);
136 error = smbfs_acl_sd2zfs(sd, acl, &uid, &gid);
137 if (error) {
138 fprintf(stderr, "%s: sd2zfs, %s\n",
139 progname, strerror(error));
140 exit(1);
142 smbfs_acl_free_sd(sd);
145 * Print it as a ZFS-style ACL (ACE_T)
147 printf("Solaris security data:\n");
148 if (uid == (uid_t)-1)
149 printf("owner: -1\n");
150 else
151 printf("owner: %u\n", uid);
152 if (gid == (gid_t)-1)
153 printf("group: -1\n");
154 else
155 printf("group: %u\n", gid);
156 acl_printacl(acl, 80, 1);
157 printf("\n");
159 acl_free(acl);