Print this page
10133 smatch fixes for usr/src/cmd/fs.d
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/fs.d/smbclnt/chacl/chacl.c
+++ new/usr/src/cmd/fs.d/smbclnt/chacl/chacl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 + * Copyright (c) 2018, Joyent, Inc.
29 + */
30 +
31 +/*
28 32 * This is the smbfs/chacl command.
29 33 * (just for testing - not installed)
30 34 *
31 35 * Works like chmod(1), but only supporting A=... forms.
32 36 * i.e. chacl A=everyone@:full_set:fd:allow /mnt/foo
33 37 *
34 38 * Some more test cases:
35 39 * /usr/lib/fs/smbfs/chacl -v
36 40 * A=user:2147483649:rwxpdDaARWcCos::allow,
37 41 * user:2147483653:raRcs::allow,
38 42 * everyone@:raRcs::allow
39 43 */
40 44
41 45 #include <sys/types.h>
42 46 #include <sys/errno.h>
43 47 #include <sys/stat.h>
44 48 #include <sys/acl.h>
45 49 #include <sys/acl_impl.h>
46 50
47 51 #include <fcntl.h>
48 52 #include <stdio.h>
49 53 #include <stdlib.h>
50 54 #include <unistd.h>
51 55 #include <string.h>
52 56 #include <aclutils.h>
53 57
54 58 #include <netsmb/smbfs_acl.h>
55 59
56 60 char *progname;
57 61 int Vflag;
58 62
59 63 void chacl(char *, uint32_t, uid_t, gid_t, acl_t *);
60 64
61 65 static const char Usage[] =
62 66 "Usage: %s [-v] [-u UID] [-g GID] A=ACL... file ...\n"
63 67 "\twhere A=ACL is like chmod(1)\n";
64 68
65 69 void
66 70 usage(void)
67 71 {
68 72 fprintf(stderr, Usage, progname);
69 73 exit(1);
70 74 }
71 75
72 76 int
73 77 main(int argc, char **argv)
74 78 {
75 79 uid_t uid = (uid_t)-1;
76 80 gid_t gid = (gid_t)-1;
77 81 acl_t *acl = NULL;
78 82 char *acl_arg;
79 83 ulong_t tl;
80 84 int c, error;
81 85 uint32_t selector;
82 86
83 87 progname = argv[0];
84 88
85 89 while ((c = getopt(argc, argv, "vu:g:")) != -1) {
86 90 switch (c) {
87 91 case 'v':
88 92 Vflag++;
89 93 break;
90 94 case 'u':
91 95 tl = strtoul(optarg, NULL, 10);
92 96 if (tl == 0)
93 97 goto badopt;
94 98 uid = (uid_t)tl;
95 99 break;
96 100 case 'g':
97 101 tl = strtoul(optarg, NULL, 10);
98 102 if (tl == 0)
99 103 goto badopt;
100 104 gid = (gid_t)tl;
101 105 break;
102 106 case ':':
103 107 fprintf(stderr, "%s: option %c requires arg\n",
104 108 progname, c);
105 109 usage();
106 110 break;
107 111
108 112 badopt:
109 113 default:
110 114 fprintf(stderr, "%s: bad option: %c\n",
111 115 progname, c);
112 116 usage();
113 117 break;
114 118 }
115 119 }
116 120
117 121 if (optind + 1 > argc)
118 122 usage();
119 123 acl_arg = argv[optind++];
120 124
121 125 /*
122 126 * Ask libsec to parse the ACL arg.
123 127 */
124 128 if (strncmp(acl_arg, "A=", 2) != 0)
125 129 usage();
126 130 error = acl_parse(acl_arg + 2, &acl);
127 131 if (error) {
128 132 fprintf(stderr, "%s: can not parse ACL: %s\n",
129 133 progname, acl_arg);
130 134 exit(1);
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
131 135 }
132 136 if (acl->acl_type != ACE_T) {
133 137 fprintf(stderr, "%s: ACL not ACE_T type: %s\n",
134 138 progname, acl_arg);
135 139 exit(1);
136 140 }
137 141
138 142 /*
139 143 * Which parts of the SD are being modified?
140 144 */
141 - selector = 0;
142 - if (acl)
143 - selector |= DACL_SECURITY_INFORMATION;
145 + selector = DACL_SECURITY_INFORMATION;
146 +
144 147 if (uid != (uid_t)-1)
145 148 selector |= OWNER_SECURITY_INFORMATION;
146 149 if (gid != (gid_t)-1)
147 150 selector |= GROUP_SECURITY_INFORMATION;
148 151
149 152 if (optind == argc)
150 153 usage();
151 154 for (; optind < argc; optind++)
152 155 chacl(argv[optind], selector, uid, gid, acl);
153 156
154 157 done:
155 158 acl_free(acl);
156 159 return (0);
157 160 }
158 161
159 162 void
160 163 chacl(char *file, uint32_t selector, uid_t uid, gid_t gid, acl_t *acl)
161 164 {
162 165 struct stat st;
163 166 struct i_ntsd *sd = NULL;
164 167 int error, fd;
165 168
166 169 /*
167 170 * OK, try setting the ACL (via ioctl). Open
168 171 * read-only because we're NOT writing data.
169 172 * The driver will re-open with the necessary
170 173 * access rights to set the ACL.
171 174 */
172 175 fd = open(file, O_RDONLY, 0);
173 176 if (fd < 0) {
174 177 perror(file);
175 178 exit(1);
176 179 }
177 180
178 181 if (uid == (uid_t)-1 || gid == (gid_t)-1) {
179 182 /*
180 183 * If not setting owner or group, we need the
181 184 * current owner and group for translating
182 185 * references via owner@ or group@ ACEs.
183 186 */
184 187 if (fstat(fd, &st) != 0) {
185 188 perror(file);
186 189 exit(1);
187 190 }
188 191 if (uid == (uid_t)-1)
189 192 uid = st.st_uid;
190 193 if (gid == (gid_t)-1)
191 194 gid = st.st_gid;
192 195 }
193 196
194 197 /*
195 198 * Convert the ZFS ACL to an NT SD.
196 199 */
197 200 error = smbfs_acl_zfs2sd(acl, uid, gid, selector, &sd);
198 201 if (error) {
199 202 fprintf(stderr, "%s: failed to convert ACL\n", progname);
200 203 exit(1);
201 204 }
202 205
203 206 if (Vflag) {
204 207
205 208 /*
206 209 * Print the SD in ZFS form.
207 210 */
208 211 printf("Solaris security data:\n");
209 212 if (uid == (uid_t)-1)
210 213 printf("owner: -1\n");
211 214 else
212 215 printf("owner: %u\n", uid);
213 216 if (gid == (gid_t)-1)
214 217 printf("group: -1\n");
215 218 else
216 219 printf("group: %u\n", gid);
217 220 acl_printacl(acl, 80, 1);
218 221 printf("\n");
219 222
220 223 /*
221 224 * Print the SD in Windows form.
222 225 */
223 226 printf("CIFS security data:\n");
224 227 smbfs_acl_print_sd(stdout, sd);
225 228 printf("\n");
226 229 }
227 230
228 231 error = smbfs_acl_setsd(fd, selector, sd);
229 232 (void) close(fd);
230 233
231 234 if (error) {
232 235 fprintf(stderr, "%s: ACL set failed, %s\n",
233 236 file, strerror(error));
234 237 exit(1);
235 238 }
236 239
237 240 smbfs_acl_free_sd(sd);
238 241 }
↓ open down ↓ |
85 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX