1 | /*
|
---|
2 | * CAP VFS module for Samba 3.x Version 0.3
|
---|
3 | *
|
---|
4 | * Copyright (C) Tim Potter, 1999-2000
|
---|
5 | * Copyright (C) Alexander Bokovoy, 2002-2003
|
---|
6 | * Copyright (C) Stefan (metze) Metzmacher, 2003
|
---|
7 | * Copyright (C) TAKAHASHI Motonobu (monyo), 2003
|
---|
8 | * Copyright (C) Jeremy Allison, 2007
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 3 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
---|
22 | */
|
---|
23 |
|
---|
24 |
|
---|
25 | #include "includes.h"
|
---|
26 | #include "smbd/smbd.h"
|
---|
27 |
|
---|
28 | /* cap functions */
|
---|
29 | static char *capencode(TALLOC_CTX *ctx, const char *from);
|
---|
30 | static char *capdecode(TALLOC_CTX *ctx, const char *from);
|
---|
31 |
|
---|
32 | static uint64_t cap_disk_free(vfs_handle_struct *handle, const char *path,
|
---|
33 | uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
|
---|
34 | {
|
---|
35 | char *cappath = capencode(talloc_tos(), path);
|
---|
36 |
|
---|
37 | if (!cappath) {
|
---|
38 | errno = ENOMEM;
|
---|
39 | return (uint64_t)-1;
|
---|
40 | }
|
---|
41 | return SMB_VFS_NEXT_DISK_FREE(handle, cappath, bsize, dfree, dsize);
|
---|
42 | }
|
---|
43 |
|
---|
44 | static int cap_get_quota(vfs_handle_struct *handle, const char *path,
|
---|
45 | enum SMB_QUOTA_TYPE qtype, unid_t id,
|
---|
46 | SMB_DISK_QUOTA *dq)
|
---|
47 | {
|
---|
48 | char *cappath = capencode(talloc_tos(), path);
|
---|
49 |
|
---|
50 | if (!cappath) {
|
---|
51 | errno = ENOMEM;
|
---|
52 | return -1;
|
---|
53 | }
|
---|
54 | return SMB_VFS_NEXT_GET_QUOTA(handle, cappath, qtype, id, dq);
|
---|
55 | }
|
---|
56 |
|
---|
57 | static DIR *cap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
|
---|
58 | {
|
---|
59 | char *capname = capencode(talloc_tos(), fname);
|
---|
60 |
|
---|
61 | if (!capname) {
|
---|
62 | errno = ENOMEM;
|
---|
63 | return NULL;
|
---|
64 | }
|
---|
65 | return SMB_VFS_NEXT_OPENDIR(handle, capname, mask, attr);
|
---|
66 | }
|
---|
67 |
|
---|
68 | static struct dirent *cap_readdir(vfs_handle_struct *handle,
|
---|
69 | DIR *dirp,
|
---|
70 | SMB_STRUCT_STAT *sbuf)
|
---|
71 | {
|
---|
72 | struct dirent *result;
|
---|
73 | struct dirent *newdirent;
|
---|
74 | char *newname;
|
---|
75 | size_t newnamelen;
|
---|
76 | DEBUG(3,("cap: cap_readdir\n"));
|
---|
77 |
|
---|
78 | result = SMB_VFS_NEXT_READDIR(handle, dirp, NULL);
|
---|
79 | if (!result) {
|
---|
80 | return NULL;
|
---|
81 | }
|
---|
82 |
|
---|
83 | newname = capdecode(talloc_tos(), result->d_name);
|
---|
84 | if (!newname) {
|
---|
85 | return NULL;
|
---|
86 | }
|
---|
87 | DEBUG(3,("cap: cap_readdir: %s\n", newname));
|
---|
88 | newnamelen = strlen(newname)+1;
|
---|
89 | newdirent = talloc_size(
|
---|
90 | talloc_tos(), sizeof(struct dirent) + newnamelen);
|
---|
91 | if (!newdirent) {
|
---|
92 | return NULL;
|
---|
93 | }
|
---|
94 | talloc_set_name_const(newdirent, "struct dirent");
|
---|
95 | memcpy(newdirent, result, sizeof(struct dirent));
|
---|
96 | memcpy(&newdirent->d_name, newname, newnamelen);
|
---|
97 | return newdirent;
|
---|
98 | }
|
---|
99 |
|
---|
100 | static int cap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
|
---|
101 | {
|
---|
102 | char *cappath = capencode(talloc_tos(), path);
|
---|
103 |
|
---|
104 | if (!cappath) {
|
---|
105 | errno = ENOMEM;
|
---|
106 | return -1;
|
---|
107 | }
|
---|
108 | return SMB_VFS_NEXT_MKDIR(handle, cappath, mode);
|
---|
109 | }
|
---|
110 |
|
---|
111 | static int cap_rmdir(vfs_handle_struct *handle, const char *path)
|
---|
112 | {
|
---|
113 | char *cappath = capencode(talloc_tos(), path);
|
---|
114 |
|
---|
115 | if (!cappath) {
|
---|
116 | errno = ENOMEM;
|
---|
117 | return -1;
|
---|
118 | }
|
---|
119 | return SMB_VFS_NEXT_RMDIR(handle, cappath);
|
---|
120 | }
|
---|
121 |
|
---|
122 | static int cap_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
|
---|
123 | files_struct *fsp, int flags, mode_t mode)
|
---|
124 | {
|
---|
125 | char *cappath;
|
---|
126 | char *tmp_base_name = NULL;
|
---|
127 | int ret;
|
---|
128 |
|
---|
129 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
---|
130 |
|
---|
131 | if (!cappath) {
|
---|
132 | errno = ENOMEM;
|
---|
133 | return -1;
|
---|
134 | }
|
---|
135 |
|
---|
136 | tmp_base_name = smb_fname->base_name;
|
---|
137 | smb_fname->base_name = cappath;
|
---|
138 |
|
---|
139 | DEBUG(3,("cap: cap_open for %s\n", smb_fname_str_dbg(smb_fname)));
|
---|
140 | ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
|
---|
141 |
|
---|
142 | smb_fname->base_name = tmp_base_name;
|
---|
143 | TALLOC_FREE(cappath);
|
---|
144 |
|
---|
145 | return ret;
|
---|
146 | }
|
---|
147 |
|
---|
148 | static int cap_rename(vfs_handle_struct *handle,
|
---|
149 | const struct smb_filename *smb_fname_src,
|
---|
150 | const struct smb_filename *smb_fname_dst)
|
---|
151 | {
|
---|
152 | char *capold = NULL;
|
---|
153 | char *capnew = NULL;
|
---|
154 | struct smb_filename *smb_fname_src_tmp = NULL;
|
---|
155 | struct smb_filename *smb_fname_dst_tmp = NULL;
|
---|
156 | int ret = -1;
|
---|
157 |
|
---|
158 | capold = capencode(talloc_tos(), smb_fname_src->base_name);
|
---|
159 | capnew = capencode(talloc_tos(), smb_fname_dst->base_name);
|
---|
160 | if (!capold || !capnew) {
|
---|
161 | errno = ENOMEM;
|
---|
162 | goto out;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /* Setup temporary smb_filename structs. */
|
---|
166 | smb_fname_src_tmp = cp_smb_filename(talloc_tos(), smb_fname_src);
|
---|
167 | if (smb_fname_src_tmp == NULL) {
|
---|
168 | errno = ENOMEM;
|
---|
169 | goto out;
|
---|
170 | }
|
---|
171 | smb_fname_dst_tmp = cp_smb_filename(talloc_tos(), smb_fname_dst);
|
---|
172 | if (smb_fname_dst_tmp == NULL) {
|
---|
173 | errno = ENOMEM;
|
---|
174 | goto out;
|
---|
175 | }
|
---|
176 |
|
---|
177 | smb_fname_src_tmp->base_name = capold;
|
---|
178 | smb_fname_dst_tmp->base_name = capnew;
|
---|
179 |
|
---|
180 | ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp,
|
---|
181 | smb_fname_dst_tmp);
|
---|
182 | out:
|
---|
183 | TALLOC_FREE(capold);
|
---|
184 | TALLOC_FREE(capnew);
|
---|
185 | TALLOC_FREE(smb_fname_src_tmp);
|
---|
186 | TALLOC_FREE(smb_fname_dst_tmp);
|
---|
187 |
|
---|
188 | return ret;
|
---|
189 | }
|
---|
190 |
|
---|
191 | static int cap_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
|
---|
192 | {
|
---|
193 | char *cappath;
|
---|
194 | char *tmp_base_name = NULL;
|
---|
195 | int ret;
|
---|
196 |
|
---|
197 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
---|
198 |
|
---|
199 | if (!cappath) {
|
---|
200 | errno = ENOMEM;
|
---|
201 | return -1;
|
---|
202 | }
|
---|
203 |
|
---|
204 | tmp_base_name = smb_fname->base_name;
|
---|
205 | smb_fname->base_name = cappath;
|
---|
206 |
|
---|
207 | ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
|
---|
208 |
|
---|
209 | smb_fname->base_name = tmp_base_name;
|
---|
210 | TALLOC_FREE(cappath);
|
---|
211 |
|
---|
212 | return ret;
|
---|
213 | }
|
---|
214 |
|
---|
215 | static int cap_lstat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
|
---|
216 | {
|
---|
217 | char *cappath;
|
---|
218 | char *tmp_base_name = NULL;
|
---|
219 | int ret;
|
---|
220 |
|
---|
221 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
---|
222 |
|
---|
223 | if (!cappath) {
|
---|
224 | errno = ENOMEM;
|
---|
225 | return -1;
|
---|
226 | }
|
---|
227 |
|
---|
228 | tmp_base_name = smb_fname->base_name;
|
---|
229 | smb_fname->base_name = cappath;
|
---|
230 |
|
---|
231 | ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
|
---|
232 |
|
---|
233 | smb_fname->base_name = tmp_base_name;
|
---|
234 | TALLOC_FREE(cappath);
|
---|
235 |
|
---|
236 | return ret;
|
---|
237 | }
|
---|
238 |
|
---|
239 | static int cap_unlink(vfs_handle_struct *handle,
|
---|
240 | const struct smb_filename *smb_fname)
|
---|
241 | {
|
---|
242 | struct smb_filename *smb_fname_tmp = NULL;
|
---|
243 | char *cappath = NULL;
|
---|
244 | int ret;
|
---|
245 |
|
---|
246 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
---|
247 | if (!cappath) {
|
---|
248 | errno = ENOMEM;
|
---|
249 | return -1;
|
---|
250 | }
|
---|
251 |
|
---|
252 | /* Setup temporary smb_filename structs. */
|
---|
253 | smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
|
---|
254 | if (smb_fname_tmp == NULL) {
|
---|
255 | errno = ENOMEM;
|
---|
256 | return -1;
|
---|
257 | }
|
---|
258 |
|
---|
259 | smb_fname_tmp->base_name = cappath;
|
---|
260 |
|
---|
261 | ret = SMB_VFS_NEXT_UNLINK(handle, smb_fname_tmp);
|
---|
262 |
|
---|
263 | TALLOC_FREE(smb_fname_tmp);
|
---|
264 | return ret;
|
---|
265 | }
|
---|
266 |
|
---|
267 | static int cap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
|
---|
268 | {
|
---|
269 | char *cappath = capencode(talloc_tos(), path);
|
---|
270 |
|
---|
271 | if (!cappath) {
|
---|
272 | errno = ENOMEM;
|
---|
273 | return -1;
|
---|
274 | }
|
---|
275 | return SMB_VFS_NEXT_CHMOD(handle, cappath, mode);
|
---|
276 | }
|
---|
277 |
|
---|
278 | static int cap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
|
---|
279 | {
|
---|
280 | char *cappath = capencode(talloc_tos(), path);
|
---|
281 |
|
---|
282 | if (!cappath) {
|
---|
283 | errno = ENOMEM;
|
---|
284 | return -1;
|
---|
285 | }
|
---|
286 | return SMB_VFS_NEXT_CHOWN(handle, cappath, uid, gid);
|
---|
287 | }
|
---|
288 |
|
---|
289 | static int cap_lchown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
|
---|
290 | {
|
---|
291 | char *cappath = capencode(talloc_tos(), path);
|
---|
292 |
|
---|
293 | if (!cappath) {
|
---|
294 | errno = ENOMEM;
|
---|
295 | return -1;
|
---|
296 | }
|
---|
297 | return SMB_VFS_NEXT_LCHOWN(handle, cappath, uid, gid);
|
---|
298 | }
|
---|
299 |
|
---|
300 | static int cap_chdir(vfs_handle_struct *handle, const char *path)
|
---|
301 | {
|
---|
302 | char *cappath = capencode(talloc_tos(), path);
|
---|
303 |
|
---|
304 | if (!cappath) {
|
---|
305 | errno = ENOMEM;
|
---|
306 | return -1;
|
---|
307 | }
|
---|
308 | DEBUG(3,("cap: cap_chdir for %s\n", path));
|
---|
309 | return SMB_VFS_NEXT_CHDIR(handle, cappath);
|
---|
310 | }
|
---|
311 |
|
---|
312 | static int cap_ntimes(vfs_handle_struct *handle,
|
---|
313 | const struct smb_filename *smb_fname,
|
---|
314 | struct smb_file_time *ft)
|
---|
315 | {
|
---|
316 | struct smb_filename *smb_fname_tmp = NULL;
|
---|
317 | char *cappath = NULL;
|
---|
318 | int ret;
|
---|
319 |
|
---|
320 | cappath = capencode(talloc_tos(), smb_fname->base_name);
|
---|
321 |
|
---|
322 | if (!cappath) {
|
---|
323 | errno = ENOMEM;
|
---|
324 | return -1;
|
---|
325 | }
|
---|
326 |
|
---|
327 | /* Setup temporary smb_filename structs. */
|
---|
328 | smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
|
---|
329 | if (smb_fname_tmp == NULL) {
|
---|
330 | errno = ENOMEM;
|
---|
331 | return -1;
|
---|
332 | }
|
---|
333 |
|
---|
334 | smb_fname_tmp->base_name = cappath;
|
---|
335 |
|
---|
336 | ret = SMB_VFS_NEXT_NTIMES(handle, smb_fname_tmp, ft);
|
---|
337 |
|
---|
338 | TALLOC_FREE(smb_fname_tmp);
|
---|
339 | return ret;
|
---|
340 | }
|
---|
341 |
|
---|
342 |
|
---|
343 | static int cap_symlink(vfs_handle_struct *handle, const char *oldpath,
|
---|
344 | const char *newpath)
|
---|
345 | {
|
---|
346 | char *capold = capencode(talloc_tos(), oldpath);
|
---|
347 | char *capnew = capencode(talloc_tos(), newpath);
|
---|
348 |
|
---|
349 | if (!capold || !capnew) {
|
---|
350 | errno = ENOMEM;
|
---|
351 | return -1;
|
---|
352 | }
|
---|
353 | return SMB_VFS_NEXT_SYMLINK(handle, capold, capnew);
|
---|
354 | }
|
---|
355 |
|
---|
356 | static int cap_readlink(vfs_handle_struct *handle, const char *path,
|
---|
357 | char *buf, size_t bufsiz)
|
---|
358 | {
|
---|
359 | char *cappath = capencode(talloc_tos(), path);
|
---|
360 |
|
---|
361 | if (!cappath) {
|
---|
362 | errno = ENOMEM;
|
---|
363 | return -1;
|
---|
364 | }
|
---|
365 | return SMB_VFS_NEXT_READLINK(handle, cappath, buf, bufsiz);
|
---|
366 | }
|
---|
367 |
|
---|
368 | static int cap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
|
---|
369 | {
|
---|
370 | char *capold = capencode(talloc_tos(), oldpath);
|
---|
371 | char *capnew = capencode(talloc_tos(), newpath);
|
---|
372 |
|
---|
373 | if (!capold || !capnew) {
|
---|
374 | errno = ENOMEM;
|
---|
375 | return -1;
|
---|
376 | }
|
---|
377 | return SMB_VFS_NEXT_LINK(handle, capold, capnew);
|
---|
378 | }
|
---|
379 |
|
---|
380 | static int cap_mknod(vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev)
|
---|
381 | {
|
---|
382 | char *cappath = capencode(talloc_tos(), path);
|
---|
383 |
|
---|
384 | if (!cappath) {
|
---|
385 | errno = ENOMEM;
|
---|
386 | return -1;
|
---|
387 | }
|
---|
388 | return SMB_VFS_NEXT_MKNOD(handle, cappath, mode, dev);
|
---|
389 | }
|
---|
390 |
|
---|
391 | static char *cap_realpath(vfs_handle_struct *handle, const char *path)
|
---|
392 | {
|
---|
393 | /* monyo need capencode'ed and capdecode'ed? */
|
---|
394 | char *cappath = capencode(talloc_tos(), path);
|
---|
395 |
|
---|
396 | if (!cappath) {
|
---|
397 | errno = ENOMEM;
|
---|
398 | return NULL;
|
---|
399 | }
|
---|
400 | return SMB_VFS_NEXT_REALPATH(handle, cappath);
|
---|
401 | }
|
---|
402 |
|
---|
403 | static int cap_chmod_acl(vfs_handle_struct *handle, const char *path, mode_t mode)
|
---|
404 | {
|
---|
405 | char *cappath = capencode(talloc_tos(), path);
|
---|
406 |
|
---|
407 | /* If the underlying VFS doesn't have ACL support... */
|
---|
408 | if (!cappath) {
|
---|
409 | errno = ENOMEM;
|
---|
410 | return -1;
|
---|
411 | }
|
---|
412 | return SMB_VFS_NEXT_CHMOD_ACL(handle, cappath, mode);
|
---|
413 | }
|
---|
414 |
|
---|
415 | static SMB_ACL_T cap_sys_acl_get_file(vfs_handle_struct *handle,
|
---|
416 | const char *path, SMB_ACL_TYPE_T type,
|
---|
417 | TALLOC_CTX *mem_ctx)
|
---|
418 | {
|
---|
419 | char *cappath = capencode(talloc_tos(), path);
|
---|
420 |
|
---|
421 | if (!cappath) {
|
---|
422 | errno = ENOMEM;
|
---|
423 | return (SMB_ACL_T)NULL;
|
---|
424 | }
|
---|
425 | return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, cappath, type, mem_ctx);
|
---|
426 | }
|
---|
427 |
|
---|
428 | static int cap_sys_acl_set_file(vfs_handle_struct *handle, const char *path, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
|
---|
429 | {
|
---|
430 | char *cappath = capencode(talloc_tos(), path);
|
---|
431 |
|
---|
432 | if (!cappath) {
|
---|
433 | errno = ENOMEM;
|
---|
434 | return -1;
|
---|
435 | }
|
---|
436 | return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, cappath, acltype, theacl);
|
---|
437 | }
|
---|
438 |
|
---|
439 | static int cap_sys_acl_delete_def_file(vfs_handle_struct *handle, const char *path)
|
---|
440 | {
|
---|
441 | char *cappath = capencode(talloc_tos(), path);
|
---|
442 |
|
---|
443 | if (!cappath) {
|
---|
444 | errno = ENOMEM;
|
---|
445 | return -1;
|
---|
446 | }
|
---|
447 | return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, cappath);
|
---|
448 | }
|
---|
449 |
|
---|
450 | static ssize_t cap_getxattr(vfs_handle_struct *handle, const char *path, const char *name, void *value, size_t size)
|
---|
451 | {
|
---|
452 | char *cappath = capencode(talloc_tos(), path);
|
---|
453 | char *capname = capencode(talloc_tos(), name);
|
---|
454 |
|
---|
455 | if (!cappath || !capname) {
|
---|
456 | errno = ENOMEM;
|
---|
457 | return -1;
|
---|
458 | }
|
---|
459 | return SMB_VFS_NEXT_GETXATTR(handle, cappath, capname, value, size);
|
---|
460 | }
|
---|
461 |
|
---|
462 | static ssize_t cap_fgetxattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path, void *value, size_t size)
|
---|
463 | {
|
---|
464 | char *cappath = capencode(talloc_tos(), path);
|
---|
465 |
|
---|
466 | if (!cappath) {
|
---|
467 | errno = ENOMEM;
|
---|
468 | return -1;
|
---|
469 | }
|
---|
470 | return SMB_VFS_NEXT_FGETXATTR(handle, fsp, cappath, value, size);
|
---|
471 | }
|
---|
472 |
|
---|
473 | static ssize_t cap_listxattr(vfs_handle_struct *handle, const char *path, char *list, size_t size)
|
---|
474 | {
|
---|
475 | char *cappath = capencode(talloc_tos(), path);
|
---|
476 |
|
---|
477 | if (!cappath) {
|
---|
478 | errno = ENOMEM;
|
---|
479 | return -1;
|
---|
480 | }
|
---|
481 | return SMB_VFS_NEXT_LISTXATTR(handle, cappath, list, size);
|
---|
482 | }
|
---|
483 |
|
---|
484 | static int cap_removexattr(vfs_handle_struct *handle, const char *path, const char *name)
|
---|
485 | {
|
---|
486 | char *cappath = capencode(talloc_tos(), path);
|
---|
487 | char *capname = capencode(talloc_tos(), name);
|
---|
488 |
|
---|
489 | if (!cappath || !capname) {
|
---|
490 | errno = ENOMEM;
|
---|
491 | return -1;
|
---|
492 | }
|
---|
493 | return SMB_VFS_NEXT_REMOVEXATTR(handle, cappath, capname);
|
---|
494 | }
|
---|
495 |
|
---|
496 | static int cap_fremovexattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path)
|
---|
497 | {
|
---|
498 | char *cappath = capencode(talloc_tos(), path);
|
---|
499 |
|
---|
500 | if (!cappath) {
|
---|
501 | errno = ENOMEM;
|
---|
502 | return -1;
|
---|
503 | }
|
---|
504 | return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, cappath);
|
---|
505 | }
|
---|
506 |
|
---|
507 | static int cap_setxattr(vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
|
---|
508 | {
|
---|
509 | char *cappath = capencode(talloc_tos(), path);
|
---|
510 | char *capname = capencode(talloc_tos(), name);
|
---|
511 |
|
---|
512 | if (!cappath || !capname) {
|
---|
513 | errno = ENOMEM;
|
---|
514 | return -1;
|
---|
515 | }
|
---|
516 | return SMB_VFS_NEXT_SETXATTR(handle, cappath, capname, value, size, flags);
|
---|
517 | }
|
---|
518 |
|
---|
519 | static int cap_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp, const char *path, const void *value, size_t size, int flags)
|
---|
520 | {
|
---|
521 | char *cappath = capencode(talloc_tos(), path);
|
---|
522 |
|
---|
523 | if (!cappath) {
|
---|
524 | errno = ENOMEM;
|
---|
525 | return -1;
|
---|
526 | }
|
---|
527 | return SMB_VFS_NEXT_FSETXATTR(handle, fsp, cappath, value, size, flags);
|
---|
528 | }
|
---|
529 |
|
---|
530 | static struct vfs_fn_pointers vfs_cap_fns = {
|
---|
531 | .disk_free_fn = cap_disk_free,
|
---|
532 | .get_quota_fn = cap_get_quota,
|
---|
533 | .opendir_fn = cap_opendir,
|
---|
534 | .readdir_fn = cap_readdir,
|
---|
535 | .mkdir_fn = cap_mkdir,
|
---|
536 | .rmdir_fn = cap_rmdir,
|
---|
537 | .open_fn = cap_open,
|
---|
538 | .rename_fn = cap_rename,
|
---|
539 | .stat_fn = cap_stat,
|
---|
540 | .lstat_fn = cap_lstat,
|
---|
541 | .unlink_fn = cap_unlink,
|
---|
542 | .chmod_fn = cap_chmod,
|
---|
543 | .chown_fn = cap_chown,
|
---|
544 | .lchown_fn = cap_lchown,
|
---|
545 | .chdir_fn = cap_chdir,
|
---|
546 | .ntimes_fn = cap_ntimes,
|
---|
547 | .symlink_fn = cap_symlink,
|
---|
548 | .readlink_fn = cap_readlink,
|
---|
549 | .link_fn = cap_link,
|
---|
550 | .mknod_fn = cap_mknod,
|
---|
551 | .realpath_fn = cap_realpath,
|
---|
552 | .chmod_acl_fn = cap_chmod_acl,
|
---|
553 | .sys_acl_get_file_fn = cap_sys_acl_get_file,
|
---|
554 | .sys_acl_set_file_fn = cap_sys_acl_set_file,
|
---|
555 | .sys_acl_delete_def_file_fn = cap_sys_acl_delete_def_file,
|
---|
556 | .getxattr_fn = cap_getxattr,
|
---|
557 | .fgetxattr_fn = cap_fgetxattr,
|
---|
558 | .listxattr_fn = cap_listxattr,
|
---|
559 | .removexattr_fn = cap_removexattr,
|
---|
560 | .fremovexattr_fn = cap_fremovexattr,
|
---|
561 | .setxattr_fn = cap_setxattr,
|
---|
562 | .fsetxattr_fn = cap_fsetxattr
|
---|
563 | };
|
---|
564 |
|
---|
565 | NTSTATUS vfs_cap_init(void);
|
---|
566 | NTSTATUS vfs_cap_init(void)
|
---|
567 | {
|
---|
568 | return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "cap",
|
---|
569 | &vfs_cap_fns);
|
---|
570 | }
|
---|
571 |
|
---|
572 | /* For CAP functions */
|
---|
573 | #define hex_tag ':'
|
---|
574 | #define hex2bin(c) hex2bin_table[(unsigned char)(c)]
|
---|
575 | #define bin2hex(c) bin2hex_table[(unsigned char)(c)]
|
---|
576 | #define is_hex(s) ((s)[0] == hex_tag)
|
---|
577 |
|
---|
578 | static unsigned char hex2bin_table[256] = {
|
---|
579 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 */
|
---|
580 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 */
|
---|
581 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 */
|
---|
582 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, /* 0x30 */
|
---|
583 | 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x40 */
|
---|
584 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
|
---|
585 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 */
|
---|
586 | 0000, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0000, /* 0x60 */
|
---|
587 | 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000,
|
---|
588 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 */
|
---|
589 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 */
|
---|
590 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 */
|
---|
591 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 */
|
---|
592 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 */
|
---|
593 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 */
|
---|
594 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 */
|
---|
595 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 */
|
---|
596 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 /* 0xf0 */
|
---|
597 | };
|
---|
598 | static unsigned char bin2hex_table[256] = "0123456789abcdef";
|
---|
599 |
|
---|
600 | /*******************************************************************
|
---|
601 | original code -> ":xx" - CAP format
|
---|
602 | ********************************************************************/
|
---|
603 |
|
---|
604 | static char *capencode(TALLOC_CTX *ctx, const char *from)
|
---|
605 | {
|
---|
606 | char *out = NULL;
|
---|
607 | const char *p1;
|
---|
608 | char *to = NULL;
|
---|
609 | size_t len = 0;
|
---|
610 |
|
---|
611 | for (p1 = from; *p1; p1++) {
|
---|
612 | if ((unsigned char)*p1 >= 0x80) {
|
---|
613 | len += 3;
|
---|
614 | } else {
|
---|
615 | len++;
|
---|
616 | }
|
---|
617 | }
|
---|
618 | len++;
|
---|
619 |
|
---|
620 | to = talloc_array(ctx, char, len);
|
---|
621 | if (!to) {
|
---|
622 | return NULL;
|
---|
623 | }
|
---|
624 |
|
---|
625 | for (out = to; *from;) {
|
---|
626 | /* buffer husoku error */
|
---|
627 | if ((unsigned char)*from >= 0x80) {
|
---|
628 | *out++ = hex_tag;
|
---|
629 | *out++ = bin2hex (((*from)>>4)&0x0f);
|
---|
630 | *out++ = bin2hex ((*from)&0x0f);
|
---|
631 | from++;
|
---|
632 | } else {
|
---|
633 | *out++ = *from++;
|
---|
634 | }
|
---|
635 | }
|
---|
636 | *out = '\0';
|
---|
637 | return to;
|
---|
638 | }
|
---|
639 |
|
---|
640 | /*******************************************************************
|
---|
641 | CAP -> original code
|
---|
642 | ********************************************************************/
|
---|
643 | /* ":xx" -> a byte */
|
---|
644 |
|
---|
645 | static char *capdecode(TALLOC_CTX *ctx, const char *from)
|
---|
646 | {
|
---|
647 | const char *p1;
|
---|
648 | char *out = NULL;
|
---|
649 | char *to = NULL;
|
---|
650 | size_t len = 0;
|
---|
651 |
|
---|
652 | for (p1 = from; *p1; len++) {
|
---|
653 | if (is_hex(p1)) {
|
---|
654 | p1 += 3;
|
---|
655 | } else {
|
---|
656 | p1++;
|
---|
657 | }
|
---|
658 | }
|
---|
659 | len++;
|
---|
660 |
|
---|
661 | to = talloc_array(ctx, char, len);
|
---|
662 | if (!to) {
|
---|
663 | return NULL;
|
---|
664 | }
|
---|
665 |
|
---|
666 | for (out = to; *from;) {
|
---|
667 | if (is_hex(from)) {
|
---|
668 | *out++ = (hex2bin(from[1])<<4) | (hex2bin(from[2]));
|
---|
669 | from += 3;
|
---|
670 | } else {
|
---|
671 | *out++ = *from++;
|
---|
672 | }
|
---|
673 | }
|
---|
674 | *out = '\0';
|
---|
675 | return to;
|
---|
676 | }
|
---|