1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
|
/*
Unix SMB/CIFS implementation.
Wrap VxFS calls in vfs functions.
This module is for ACL and XATTR handling.
Copyright (C) Symantec Corporation <www.symantec.com> 2014
Copyright (C) Veritas Technologies LLC <www.veritas.com> 2016
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "smbd/smbd.h"
#include "librpc/gen_ndr/ndr_xattr.h"
#include "../libcli/security/security.h"
#include "../librpc/gen_ndr/ndr_security.h"
#include "system/filesys.h"
#include "vfs_vxfs.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
#define MODULE_NAME "vxfs"
/*
* WARNING !! WARNING !!
*
* DO NOT CHANGE THIS FROM "system." space to
* "user." space unless you are shipping a product
* that RESTRICTS access to extended attributes
* to smbd-only. "system." space is restricted
* to root access only, "user." space is available
* to ANY USER.
*
* If this is changed to "user." and access
* to extended attributes is available via
* local processes or other remote file system
* (e.g. NFS) then the security of the system
* WILL BE COMPROMISED. i.e. non-root users
* WILL be able to overwrite Samba ACLs on
* the file system.
*
* If you need to modify this define, do
* so using CFLAGS on your build command
* line.
* e.g. CFLAGS=-DXATTR_USER_NTACL="user.NTACL"
*
* Added by: <jra@samba.org> 17 Sept. 2014.
*
*/
#ifndef XATTR_USER_NTACL
#define XATTR_USER_NTACL "system.NTACL"
#endif
/* type values */
#define VXFS_ACL_UNDEFINED_TYPE 0
#define VXFS_ACL_USER_OBJ 1
#define VXFS_ACL_GROUP_OBJ 2
#define VXFS_ACL_USER 3
#define VXFS_ACL_GROUP 4
#define VXFS_ACL_OTHER 5
#define VXFS_ACL_MASK 6
/*
* Compare aces
* This will compare two ace entries for sorting
* each entry contains: type, perms and id
* Sort by type first, if type is same sort by id.
*/
static int vxfs_ace_cmp(const void *ace1, const void *ace2)
{
int ret = 0;
uint16_t type_a1, type_a2;
uint32_t id_a1, id_a2;
/* Type must be compared first */
type_a1 = SVAL(ace1, 0);
type_a2 = SVAL(ace2, 0);
ret = (type_a1 - type_a2);
if (!ret) {
/* Compare ID under type */
/* skip perm thus take offset as 4*/
id_a1 = IVAL(ace1, 4);
id_a2 = IVAL(ace2, 4);
ret = id_a1 - id_a2;
}
return ret;
}
static void vxfs_print_ace_buf(char *buf, int count) {
int i, offset = 0;
uint16_t type, perm;
uint32_t id;
DEBUG(10, ("vfs_vxfs: Printing aces:\n"));
for (i = 0; i < count; i++) {
type = SVAL(buf, offset);
offset += 2;
perm = SVAL(buf, offset);
offset += 2;
id = IVAL(buf, offset);
offset += 4;
DEBUG(10, ("vfs_vxfs: type = %u, perm = %u, id = %u\n",
(unsigned int)type, (unsigned int)perm,
(unsigned int)id));
}
}
/*
* Sort aces so that comparing 2 ACLs will be straight forward.
* This function will fill buffer as follows:
* For each ace:
* 1. ace->a_type will be filled as first 2 bytes in buf.
* 2. ace->a_perm will be filled as next 2 bytes.
* 3. ace->xid will be filled as next 4 bytes.
* Thus each ace entry in buf is equal to 8 bytes.
* Also a_type is mapped to VXFS_ACL_* so that ordering aces
* becomes easy.
*/
static char * vxfs_sort_acl(SMB_ACL_T theacl, TALLOC_CTX *mem_ctx,
uint32_t o_uid,
uint32_t o_gid) {
struct smb_acl_entry *smb_ace;
int i, count;
uint16_t type, perm;
uint32_t id;
int offset = 0;
char *buf = NULL;
count = theacl->count;
buf = talloc_zero_size(mem_ctx, count * 8);
if (!buf) {
return NULL;
}
smb_ace = theacl->acl;
for (i = 0; i < count; i++) {
/* Calculate type */
/* Map type to SMB_ACL_* to VXFS_ACL_* */
switch(smb_ace->a_type) {
case SMB_ACL_USER:
type = VXFS_ACL_USER;
break;
case SMB_ACL_USER_OBJ:
type = VXFS_ACL_USER_OBJ;
break;
case SMB_ACL_GROUP:
type = VXFS_ACL_GROUP;
break;
case SMB_ACL_GROUP_OBJ:
type = VXFS_ACL_GROUP_OBJ;
break;
case SMB_ACL_OTHER:
type = VXFS_ACL_OTHER;
break;
case SMB_ACL_MASK:
type = VXFS_ACL_MASK;
break;
default:
type = -1;
talloc_free(buf);
return NULL;
}
type = type & 0xff;
/* Calculate id:
* We get owner uid and owner group gid in o_uid and o_gid
* Put these ids instead of -1
*/
switch(smb_ace->a_type) {
case SMB_ACL_USER:
id = smb_ace->info.user.uid;
break;
case SMB_ACL_GROUP:
id = smb_ace->info.group.gid;
break;
case SMB_ACL_USER_OBJ:
id = o_uid;
break;
case SMB_ACL_GROUP_OBJ:
id = o_gid;
break;
case SMB_ACL_MASK:
case SMB_ACL_OTHER:
id = -1;
break;
default:
/* Can't happen.. */
id = -1;
break;
}
/* Calculate perm */
perm = smb_ace->a_perm & 0xff;
/* TYPE is the first 2 bytes of an entry */
SSVAL(buf, offset, type);
offset += 2;
/* PERM is the next 2 bytes of an entry */
SSVAL(buf, offset, perm);
offset += 2;
/* ID is the last 4 bytes of an entry */
SIVAL(buf, offset, id);
offset += 4;
smb_ace++;
}
qsort(buf, count, 8, vxfs_ace_cmp);
DEBUG(10, ("vfs_vxfs: Print sorted aces:\n"));
vxfs_print_ace_buf(buf, count);
return buf;
}
/* This function gets e_buf as an arg which is sorted and created out of
* existing ACL. This function will compact this e_buf to c_buf where USER
* and GROUP aces matching with USER_OBJ and GROUP_OBJ will be merged
* respectively.
* This is similar to what posix_acls.c does. This will make sure existing
* acls are converted much similar to what posix_acls calculates.
*/
static char * vxfs_compact_buf(char *e_buf, int *new_count, int count,
TALLOC_CTX *mem_ctx)
{
int i, e_offset = 0, c_offset = 0;
uint16_t type, perm, o_perm;
uint32_t id, owner_id, group_id;
char *c_buf = NULL;
if (count < 2) {
return NULL;
}
c_buf = talloc_zero_size(mem_ctx, count * 8);
if (!c_buf) {
return NULL;
}
/*Copy first two enries from e_buf to c_buf
*These are USER_OBJ and GROUP_OBJ
*/
memcpy(c_buf, e_buf, 16);
(*new_count) = 2;
owner_id = IVAL(e_buf, 4);
group_id = IVAL(e_buf, 12);
c_offset = e_offset = 16;
/* Start comparing other entries */
for (i = 2; i < count; i++) {
type = SVAL(e_buf, e_offset);
e_offset += 2;
perm = SVAL(e_buf, e_offset);
e_offset += 2;
id = IVAL(e_buf, e_offset);
e_offset += 4;
switch(type) {
case VXFS_ACL_USER:
if (id == owner_id) {
o_perm = SVAL(c_buf, 2);
o_perm |= perm;
SSVAL(c_buf, 2, o_perm);
DEBUG(10, ("vfs_vxfs: merging with owner"
"e_type = %u,"
"e_perm = %u,"
"e_id = %u\n", (unsigned int)type,
(unsigned int)perm,
(unsigned int)id));
continue;
}
break;
case VXFS_ACL_GROUP:
if (id == group_id) {
o_perm = SVAL(c_buf, 10);
o_perm |= perm;
SSVAL(c_buf, 10, o_perm);
DEBUG(10, ("vfs_vxfs: merging with owner group"
"e_type = %u,"
"e_perm = %u,"
"e_id = %u\n", (unsigned int)type,
(unsigned int)perm,
(unsigned int)id));
continue;
}
break;
}
SSVAL(c_buf, c_offset, type);
c_offset += 2;
SSVAL(c_buf, c_offset, perm);
c_offset += 2;
SIVAL(c_buf, c_offset, id);
c_offset += 4;
(*new_count)++;
}
DEBUG(10, ("vfs_vxfs: new_count is %d\n", *new_count));
return c_buf;
}
/* Actually compare New ACL and existing ACL buf */
static bool vxfs_compare_acls(char *e_buf, char *n_buf, int n_count,
int e_count) {
uint16_t e_type, n_type, e_perm, n_perm;
uint32_t e_id, n_id;
int i, offset = 0;
if (!e_buf && !n_buf) {
DEBUG(10, ("vfs_vxfs: Empty buffers!\n"));
return false;
}
if ((e_count < 2) || (n_count < 2)) {
return false;
}
/*Get type from last entry from both buffers.
* It may or may not be ACL_MASK
*/
n_type = SVAL(n_buf, offset + (8 * (n_count-1)));
e_type = SVAL(e_buf, offset + (8 * (e_count-1)));
/* Check for ACL_MASK entry properly. Handle all 4 cases*/
/* If ACL_MASK entry is present in any of the buffers,
* it will be always the last one. Calculate count to compare
* based on if ACL_MASK is present on new and existing ACL
*/
if ((n_type != VXFS_ACL_MASK) && (e_type == VXFS_ACL_MASK)){
DEBUG(10, ("vfs_vxfs: New ACL does not have mask entry,"
"reduce count by 1 and compare\n"));
e_count = e_count -1;
}
if ((n_type == VXFS_ACL_MASK) && (e_type != VXFS_ACL_MASK)){
DEBUG(10, ("vfs_vxfs: new ACL to be set contains mask"
"existing ACL does not have mask entry\n"
"Need to set New ACL\n"));
return false;
}
if (memcmp(e_buf, n_buf, (e_count * 8)) != 0) {
DEBUG(10, ("vfs_vxfs: Compare with memcmp,"
"buffers not same!\n"));
return false;
}
return true;
}
/* In VxFS, POSIX ACLs are pointed by separate inode for each file/dir.
* However, files/dir share same POSIX ACL inode if ACLs are inherited
* from parent.
* To retain this behaviour, below function avoids ACL set call if
* underlying ACLs are already same and thus saves creating extra inode.
*
* This function will execute following steps:
* 1. Get existing ACL
* 2. Sort New ACL and existing ACL into buffers
* 3. Compact existing ACL buf
* 4. Finally compare New ACL buf and Compact buf
* 5. If same, return true
* 6. Else need to set New ACL
*/
static bool vxfs_compare(connection_struct *conn, char *name, SMB_ACL_T the_acl,
SMB_ACL_TYPE_T the_acl_type)
{
SMB_ACL_T existing_acl = NULL;
bool ret = false;
int i, count = 0;
TALLOC_CTX *mem_ctx = talloc_tos();
char *existing_buf = NULL, *new_buf = NULL, *compact_buf = NULL;
struct smb_filename *smb_fname = NULL;
int status;
DEBUG(10, ("vfs_vxfs: Getting existing ACL for %s\n", name));
existing_acl = SMB_VFS_SYS_ACL_GET_FILE(conn, name, the_acl_type,
mem_ctx);
if (existing_acl == NULL) {
DEBUG(10, ("vfs_vxfs: Failed to get ACL\n"));
goto out;
}
DEBUG(10, ("vfs_vxfs: Existing ACL count=%d\n", existing_acl->count));
DEBUG(10, ("vfs_vxfs: New ACL count=%d\n", the_acl->count));
if (existing_acl->count == 0) {
DEBUG(10, ("vfs_vxfs: ACL count is 0, Need to set\n"));
goto out;
}
smb_fname = synthetic_smb_fname(mem_ctx, name, NULL, NULL, 0);
if (smb_fname == NULL) {
DEBUG(10, ("vfs_vxfs: Failed to create smb_fname\n"));
goto out;
}
status = SMB_VFS_STAT(conn, smb_fname);
if (status == -1) {
DEBUG(10, ("vfs_vxfs: stat failed!\n"));
goto out;
}
DEBUG(10, ("vfs_vxfs: Sorting existing ACL\n"));
existing_buf = vxfs_sort_acl(existing_acl, mem_ctx,
smb_fname->st.st_ex_uid,
smb_fname->st.st_ex_gid);
if (!existing_buf)
goto out;
DEBUG(10, ("vfs_vxfs: Sorting new ACL\n"));
new_buf = vxfs_sort_acl(the_acl, mem_ctx, smb_fname->st.st_ex_uid,
smb_fname->st.st_ex_gid);
if (!new_buf) {
goto out;
}
DEBUG(10, ("vfs_vxfs: Compact existing buf\n"));
compact_buf = vxfs_compact_buf(existing_buf, &count,
existing_acl->count,
mem_ctx);
if (!compact_buf) {
goto out;
}
vxfs_print_ace_buf(compact_buf, count);
/* COmpare ACLs only if count is same or mismatch by 1 */
if ((count == the_acl->count) ||
(count == the_acl->count + 1) ||
(count+1 == the_acl->count)) {
if (vxfs_compare_acls(compact_buf, new_buf, the_acl->count,
count)) {
DEBUG(10, ("vfs_vxfs: ACLs matched. Not setting.\n"));
ret = true;
goto out;
} else
DEBUG(10, ("vfs_vxfs: ACLs NOT matched. Setting\n"));
} else {
DEBUG(10, ("vfs_vxfs: ACLs count does not match. Setting\n"));
}
out:
TALLOC_FREE(existing_acl);
TALLOC_FREE(smb_fname);
TALLOC_FREE(existing_buf);
TALLOC_FREE(compact_buf);
TALLOC_FREE(new_buf);
return ret;
}
static int vxfs_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
SMB_ACL_T theacl)
{
if (vxfs_compare(fsp->conn, fsp->fsp_name->base_name, theacl,
SMB_ACL_TYPE_ACCESS)) {
return 0;
}
return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
}
static int vxfs_sys_acl_set_file(vfs_handle_struct *handle, const char *name,
SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
{
if (vxfs_compare(handle->conn, (char *)name, theacl, acltype)) {
return 0;
}
return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype, theacl);
}
static int vxfs_set_xattr(struct vfs_handle_struct *handle, const char *path,
const char *name, const void *value, size_t size,
int flags){
struct smb_filename *smb_fname;
bool is_dir = false;
int ret = 0;
DEBUG(10, ("In vxfs_set_xattr\n"));
smb_fname = synthetic_smb_fname(talloc_tos(), path, NULL, NULL, 0);
if (smb_fname == NULL) {
errno = ENOMEM;
return -1;
}
if (SMB_VFS_NEXT_STAT(handle, smb_fname) != 0) {
TALLOC_FREE(smb_fname);
return -1;
}
is_dir = S_ISDIR(smb_fname->st.st_ex_mode);
TALLOC_FREE(smb_fname);
ret = vxfs_setxattr_path(path, name, value, size, flags,
is_dir);
if ((ret == 0) ||
((ret == -1) && (errno != ENOTSUP) && (errno != ENOSYS))) {
/*
* Now remve old style xattr if it exists
*/
SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
/*
* Do not bother about return value
*/
return ret;
}
DEBUG(10, ("Fallback to xattr\n"));
if (strcmp(name, XATTR_NTACL_NAME) == 0) {
return SMB_VFS_NEXT_SETXATTR(handle, path, XATTR_USER_NTACL,
value, size, flags);
}
/* Clients can't set XATTR_USER_NTACL directly. */
if (strcasecmp(name, XATTR_USER_NTACL) == 0) {
errno = EACCES;
return -1;
}
return SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size, flags);
}
static int vxfs_fset_xattr(struct vfs_handle_struct *handle,
struct files_struct *fsp, const char *name,
const void *value, size_t size, int flags){
int ret = 0;
DEBUG(10, ("In vxfs_fset_xattr\n"));
ret = vxfs_setxattr_fd(fsp->fh->fd, name, value, size, flags);
if ((ret == 0) ||
((ret == -1) && (errno != ENOTSUP) && (errno != ENOSYS))) {
SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
return ret;
}
DEBUG(10, ("Fallback to xattr"));
if (strcmp(name, XATTR_NTACL_NAME) == 0) {
return SMB_VFS_NEXT_FSETXATTR(handle, fsp, XATTR_USER_NTACL,
value, size, flags);
}
/* Clients can't set XATTR_USER_NTACL directly. */
if (strcasecmp(name, XATTR_USER_NTACL) == 0) {
errno = EACCES;
return -1;
}
return SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
}
static ssize_t vxfs_get_xattr(struct vfs_handle_struct *handle,
const char *path, const char *name,
void *value, size_t size){
int ret;
DEBUG(10, ("In vxfs_get_xattr\n"));
ret = vxfs_getxattr_path(path, name, value, size);
if ((ret != -1) || ((errno != ENOTSUP) &&
(errno != ENOSYS) && (errno != ENODATA))) {
return ret;
}
DEBUG(10, ("Fallback to xattr\n"));
if (strcmp(name, XATTR_NTACL_NAME) == 0) {
return SMB_VFS_NEXT_GETXATTR(handle, path, XATTR_USER_NTACL,
value, size);
}
/* Clients can't see XATTR_USER_NTACL directly. */
if (strcasecmp(name, XATTR_USER_NTACL) == 0) {
errno = ENOATTR;
return -1;
}
return SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
}
static ssize_t vxfs_fget_xattr(struct vfs_handle_struct *handle,
struct files_struct *fsp, const char *name,
void *value, size_t size){
int ret;
DEBUG(10, ("In vxfs_fget_xattr\n"));
ret = vxfs_getxattr_fd(fsp->fh->fd, name, value, size);
if ((ret != -1) || ((errno != ENOTSUP) &&
(errno != ENOSYS) && (errno != ENODATA))) {
return ret;
}
DEBUG(10, ("Fallback to xattr\n"));
if (strcmp(name, XATTR_NTACL_NAME) == 0) {
return SMB_VFS_NEXT_FGETXATTR(handle, fsp, XATTR_USER_NTACL,
value, size);
}
/* Clients can't see XATTR_USER_NTACL directly. */
if (strcasecmp(name, XATTR_USER_NTACL) == 0) {
errno = ENOATTR;
return -1;
}
return SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
}
static int vxfs_remove_xattr(struct vfs_handle_struct *handle,
const char *path, const char *name){
struct smb_filename *smb_fname;
bool is_dir = false;
int ret = 0, ret_new = 0, old_errno;
DEBUG(10, ("In vxfs_remove_xattr\n"));
/* Remove with old way */
if (strcmp(name, XATTR_NTACL_NAME) == 0) {
ret = SMB_VFS_NEXT_REMOVEXATTR(handle, path,
XATTR_USER_NTACL);
} else {
if (strcasecmp(name, XATTR_USER_NTACL) != 0) {
ret = SMB_VFS_NEXT_REMOVEXATTR(handle, path,
name);
}
}
old_errno = errno;
/* Remove with new way */
smb_fname = synthetic_smb_fname(talloc_tos(), path, NULL, NULL, 0);
if (smb_fname == NULL) {
errno = ENOMEM;
return -1;
}
if (SMB_VFS_NEXT_STAT(handle, smb_fname) != 0) {
TALLOC_FREE(smb_fname);
return -1;
}
is_dir = S_ISDIR(smb_fname->st.st_ex_mode);
TALLOC_FREE(smb_fname);
/*
* If both fail, return failuer else return whichever succeeded
*/
ret_new = vxfs_removexattr_path(path, name, is_dir);
if (errno == ENOTSUP || errno == ENOSYS) {
errno = old_errno;
}
if ((ret_new != -1) && (ret == -1)) {
ret = ret_new;
}
return ret;
}
static int vxfs_fremove_xattr(struct vfs_handle_struct *handle,
struct files_struct *fsp, const char *name){
int ret = 0, ret_new = 0, old_errno;
DEBUG(10, ("In vxfs_fremove_xattr\n"));
/* Remove with old way */
if (strcmp(name, XATTR_NTACL_NAME) == 0) {
ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp,
XATTR_USER_NTACL);
} else {
/* Clients can't remove XATTR_USER_NTACL directly. */
if (strcasecmp(name, XATTR_USER_NTACL) != 0) {
ret = SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp,
name);
}
}
old_errno = errno;
/* Remove with new way */
ret_new = vxfs_removexattr_fd(fsp->fh->fd, name);
/*
* If both fail, return failuer else return whichever succeeded
*/
if (errno == ENOTSUP || errno == ENOSYS) {
errno = old_errno;
}
if ((ret_new != -1) && (ret == -1)) {
ret = ret_new;
}
return ret;
}
static size_t vxfs_filter_list(char *list, size_t size)
{
char *str = list;
while (str - list < size) {
size_t element_len = strlen(str) + 1;
if (strcasecmp(str, XATTR_USER_NTACL) == 0) {
memmove(str,
str + element_len,
size - (str - list) - element_len);
size -= element_len;
continue;
}
str += element_len;
}
return size;
}
static ssize_t vxfs_listxattr(vfs_handle_struct *handle, const char *path,
char *list, size_t size)
{
ssize_t result;
result = vxfs_listxattr_path(path, list, size);
if (result >= 0 || ((errno != ENOTSUP) && (errno != ENOSYS))) {
return result;
}
result = SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
if (result <= 0) {
return result;
}
/* Remove any XATTR_USER_NTACL elements from the returned list. */
result = vxfs_filter_list(list, result);
return result;
}
static ssize_t vxfs_flistxattr(struct vfs_handle_struct *handle,
struct files_struct *fsp, char *list,
size_t size)
{
ssize_t result;
result = vxfs_listxattr_fd(fsp->fh->fd, list, size);
if (result >= 0 || ((errno != ENOTSUP) && (errno != ENOSYS))) {
return result;
}
result = SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
if (result <= 0) {
return result;
}
/* Remove any XATTR_USER_NTACL elements from the returned list. */
result = vxfs_filter_list(list, result);
return result;
}
static int vfs_vxfs_connect(struct vfs_handle_struct *handle,
const char *service, const char *user)
{
int ret;
ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
if (ret < 0) {
return ret;
}
vxfs_init();
return 0;
}
static struct vfs_fn_pointers vfs_vxfs_fns = {
.connect_fn = vfs_vxfs_connect,
#ifdef VXFS_ACL_SHARE
.sys_acl_set_file_fn = vxfs_sys_acl_set_file,
.sys_acl_set_fd_fn = vxfs_sys_acl_set_fd,
#endif
.getxattr_fn = vxfs_get_xattr,
.fgetxattr_fn = vxfs_fget_xattr,
.listxattr_fn = vxfs_listxattr,
.flistxattr_fn = vxfs_flistxattr,
.removexattr_fn = vxfs_remove_xattr,
.fremovexattr_fn = vxfs_fremove_xattr,
.setxattr_fn = vxfs_set_xattr,
.fsetxattr_fn = vxfs_fset_xattr,
};
NTSTATUS vfs_vxfs_init(void);
NTSTATUS vfs_vxfs_init(void)
{
return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "vxfs",
&vfs_vxfs_fns);
}
|