Changeset 745 for trunk/server/source3/modules/nfs4_acls.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/modules/nfs4_acls.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "smbd/smbd.h" 21 22 #include "nfs4_acls.h" 23 #include "librpc/gen_ndr/ndr_security.h" 24 #include "../libcli/security/dom_sid.h" 25 #include "../libcli/security/security.h" 26 #include "include/dbwrap.h" 27 #include "system/filesys.h" 28 #include "passdb/lookup_sid.h" 29 #include "util_tdb.h" 22 30 23 31 #undef DBGC_CLASS … … 45 53 } SMB_ACL4_INT_T; 46 54 55 /************************************************ 56 Split the ACE flag mapping between nfs4 and Windows 57 into two separate functions rather than trying to do 58 it inline. Allows us to carefully control what flags 59 are mapped to what in one place. 60 ************************************************/ 61 62 static uint32_t map_nfs4_ace_flags_to_windows_ace_flags(uint32_t nfs4_ace_flags) 63 { 64 uint32_t win_ace_flags = 0; 65 66 /* The nfs4 flags <= 0xf map perfectly. */ 67 win_ace_flags = nfs4_ace_flags & (SEC_ACE_FLAG_OBJECT_INHERIT| 68 SEC_ACE_FLAG_CONTAINER_INHERIT| 69 SEC_ACE_FLAG_NO_PROPAGATE_INHERIT| 70 SEC_ACE_FLAG_INHERIT_ONLY); 71 72 /* flags greater than 0xf have diverged :-(. */ 73 /* See the nfs4 ace flag definitions here: 74 http://www.ietf.org/rfc/rfc3530.txt. 75 And the Windows ace flag definitions here: 76 librpc/idl/security.idl. */ 77 if (nfs4_ace_flags & SMB_ACE4_INHERITED_ACE) { 78 win_ace_flags |= SEC_ACE_FLAG_INHERITED_ACE; 79 } 80 81 return win_ace_flags; 82 } 83 84 static uint32_t map_windows_ace_flags_to_nfs4_ace_flags(uint32_t win_ace_flags) 85 { 86 uint32_t nfs4_ace_flags = 0; 87 88 /* The windows flags <= 0xf map perfectly. */ 89 nfs4_ace_flags = win_ace_flags & (SMB_ACE4_FILE_INHERIT_ACE| 90 SMB_ACE4_DIRECTORY_INHERIT_ACE| 91 SMB_ACE4_NO_PROPAGATE_INHERIT_ACE| 92 SMB_ACE4_INHERIT_ONLY_ACE); 93 94 /* flags greater than 0xf have diverged :-(. */ 95 /* See the nfs4 ace flag definitions here: 96 http://www.ietf.org/rfc/rfc3530.txt. 97 And the Windows ace flag definitions here: 98 librpc/idl/security.idl. */ 99 if (win_ace_flags & SEC_ACE_FLAG_INHERITED_ACE) { 100 nfs4_ace_flags |= SMB_ACE4_INHERITED_ACE; 101 } 102 103 return nfs4_ace_flags; 104 } 105 47 106 static SMB_ACL4_INT_T *get_validated_aclint(SMB4ACL_T *theacl) 48 107 { … … 183 242 memset(psbuf, 0, sizeof(SMB_STRUCT_STAT)); 184 243 185 if (fsp-> is_directory || fsp->fh->fd == -1) {244 if (fsp->fh->fd == -1) { 186 245 return smbacl4_GetFileOwner(fsp->conn, 187 246 fsp->fsp_name->base_name, psbuf); … … 198 257 199 258 static bool smbacl4_nfs42win(TALLOC_CTX *mem_ctx, SMB4ACL_T *theacl, /* in */ 200 DOM_SID*psid_owner, /* in */201 DOM_SID*psid_group, /* in */259 struct dom_sid *psid_owner, /* in */ 260 struct dom_sid *psid_group, /* in */ 202 261 bool is_directory, /* in */ 203 SEC_ACE**ppnt_ace_list, /* out */262 struct security_ace **ppnt_ace_list, /* out */ 204 263 int *pgood_aces /* out */ 205 264 ) … … 207 266 SMB_ACL4_INT_T *aclint = (SMB_ACL4_INT_T *)theacl; 208 267 SMB_ACE4_INT_T *aceint; 209 SEC_ACE*nt_ace_list = NULL;268 struct security_ace *nt_ace_list = NULL; 210 269 int good_aces = 0; 211 270 … … 215 274 /* We do not check for naces being 0 or theacl being NULL here because it is done upstream */ 216 275 /* in smb_get_nt_acl_nfs4(). */ 217 nt_ace_list = ( SEC_ACE *)TALLOC_ZERO_SIZE(mem_ctx, aclint->naces * sizeof(SEC_ACE));276 nt_ace_list = (struct security_ace *)TALLOC_ZERO_SIZE(mem_ctx, aclint->naces * sizeof(struct security_ace)); 218 277 if (nt_ace_list==NULL) 219 278 { … … 225 284 for (aceint=aclint->first; aceint!=NULL; aceint=(SMB_ACE4_INT_T *)aceint->next) { 226 285 uint32_t mask; 227 DOM_SIDsid;286 struct dom_sid sid; 228 287 SMB_ACE4PROP_T *ace = &aceint->prop; 229 uint32_t mapped_ace_flags;288 uint32_t win_ace_flags; 230 289 231 290 DEBUG(10, ("magic: 0x%x, type: %d, iflags: %x, flags: %x, mask: %x, " … … 264 323 } 265 324 266 mapped_ace_flags = ace->aceFlags & 0xf;267 if (!is_directory && ( mapped_ace_flags & (SMB_ACE4_FILE_INHERIT_ACE|SMB_ACE4_DIRECTORY_INHERIT_ACE))) {325 win_ace_flags = map_nfs4_ace_flags_to_windows_ace_flags(ace->aceFlags); 326 if (!is_directory && (win_ace_flags & (SEC_ACE_FLAG_OBJECT_INHERIT|SEC_ACE_FLAG_CONTAINER_INHERIT))) { 268 327 /* 269 328 * GPFS sets inherits dir_inhert and file_inherit flags … … 272 331 */ 273 332 DEBUG(10, ("removing inherit flags from nfs4 ace\n")); 274 mapped_ace_flags &= ~(SMB_ACE4_FILE_INHERIT_ACE|SMB_ACE4_DIRECTORY_INHERIT_ACE); 275 } 276 DEBUG(10, ("mapped ace flags: 0x%x => 0x%x\n", 277 ace->aceFlags, mapped_ace_flags)); 278 279 mask = ace->aceMask; 333 win_ace_flags &= ~(SEC_ACE_FLAG_OBJECT_INHERIT|SEC_ACE_FLAG_CONTAINER_INHERIT); 334 } 335 DEBUG(10, ("Windows mapped ace flags: 0x%x => 0x%x\n", 336 ace->aceFlags, win_ace_flags)); 337 338 /* Windows clients expect SYNC on acls to 339 correctly allow rename. See bug #7909. */ 340 mask = ace->aceMask | SMB_ACE4_SYNCHRONIZE; 280 341 init_sec_ace(&nt_ace_list[good_aces++], &sid, 281 342 ace->aceType, mask, 282 mapped_ace_flags);343 win_ace_flags); 283 344 } 284 345 … … 291 352 static NTSTATUS smb_get_nt_acl_nfs4_common(const SMB_STRUCT_STAT *sbuf, 292 353 uint32 security_info, 293 SEC_DESC**ppdesc, SMB4ACL_T *theacl)354 struct security_descriptor **ppdesc, SMB4ACL_T *theacl) 294 355 { 295 356 int good_aces = 0; 296 DOM_SIDsid_owner, sid_group;357 struct dom_sid sid_owner, sid_group; 297 358 size_t sd_size = 0; 298 SEC_ACE*nt_ace_list = NULL;299 SEC_ACL*psa = NULL;359 struct security_ace *nt_ace_list = NULL; 360 struct security_acl *psa = NULL; 300 361 TALLOC_CTX *mem_ctx = talloc_tos(); 301 362 … … 322 383 323 384 DEBUG(10,("after make sec_acl\n")); 324 *ppdesc = make_sec_desc(mem_ctx, S EC_DESC_REVISION, SEC_DESC_SELF_RELATIVE,325 (security_info & OWNER_SECURITY_INFORMATION) ? &sid_owner : NULL,326 (security_info & GROUP_SECURITY_INFORMATION) ? &sid_group : NULL,385 *ppdesc = make_sec_desc(mem_ctx, SD_REVISION, SEC_DESC_SELF_RELATIVE, 386 (security_info & SECINFO_OWNER) ? &sid_owner : NULL, 387 (security_info & SECINFO_GROUP) ? &sid_group : NULL, 327 388 NULL, psa, &sd_size); 328 389 if (*ppdesc==NULL) { … … 332 393 333 394 DEBUG(10, ("smb_get_nt_acl_nfs4_common successfully exited with sd_size %d\n", 334 (int)ndr_size_security_descriptor(*ppdesc, NULL,0)));395 (int)ndr_size_security_descriptor(*ppdesc, 0))); 335 396 336 397 return NT_STATUS_OK; … … 339 400 NTSTATUS smb_fget_nt_acl_nfs4(files_struct *fsp, 340 401 uint32 security_info, 341 SEC_DESC**ppdesc, SMB4ACL_T *theacl)402 struct security_descriptor **ppdesc, SMB4ACL_T *theacl) 342 403 { 343 404 SMB_STRUCT_STAT sbuf; … … 355 416 const char *name, 356 417 uint32 security_info, 357 SEC_DESC**ppdesc, SMB4ACL_T *theacl)418 struct security_descriptor **ppdesc, SMB4ACL_T *theacl) 358 419 { 359 420 SMB_STRUCT_STAT sbuf; … … 456 517 if (ace->flags == aceNew->flags && 457 518 ace->aceType==aceNew->aceType && 458 ((ace->aceFlags&SMB_ACE4_INHERIT_ONLY_ACE)== 459 (aceNew->aceFlags&SMB_ACE4_INHERIT_ONLY_ACE)) && 460 (ace->aceFlags&SMB_ACE4_IDENTIFIER_GROUP)== 461 (aceNew->aceFlags&SMB_ACE4_IDENTIFIER_GROUP) 462 ) { 519 ace->aceFlags==aceNew->aceFlags) 520 { 463 521 /* keep type safety; e.g. gid is an u.short */ 464 522 if (ace->flags & SMB_ACE4_ID_SPECIAL) … … 482 540 } 483 541 484 static bool nfs4_map_sid(smbacl4_vfs_params *params, const DOM_SID*src,485 DOM_SID*dst)542 static bool nfs4_map_sid(smbacl4_vfs_params *params, const struct dom_sid *src, 543 struct dom_sid *dst) 486 544 { 487 545 static struct db_context *mapping_db = NULL; … … 544 602 uid_t ownerUID, 545 603 gid_t ownerGID, 546 const SEC_ACE*ace_nt, /* input */604 const struct security_ace *ace_nt, /* input */ 547 605 SMB_ACE4PROP_T *ace_v4 /* output */ 548 606 ) … … 552 610 memset(ace_v4, 0, sizeof(SMB_ACE4PROP_T)); 553 611 ace_v4->aceType = ace_nt->type; /* only ACCESS|DENY supported right now */ 554 ace_v4->aceFlags = ace_nt->flags & SEC_ACE_FLAG_VALID_INHERIT;612 ace_v4->aceFlags = map_windows_ace_flags_to_nfs4_ace_flags(ace_nt->flags); 555 613 ace_v4->aceMask = ace_nt->access_mask & 556 (S TD_RIGHT_ALL_ACCESS | SA_RIGHT_FILE_ALL_ACCESS);614 (SEC_STD_ALL | SEC_FILE_ALL); 557 615 558 616 se_map_generic(&ace_v4->aceMask, &file_generic_mapping); … … 566 624 ace_v4->aceMask, ace_nt->access_mask)); 567 625 568 if ( sid_equal(&ace_nt->trustee, &global_sid_World)) {626 if (dom_sid_equal(&ace_nt->trustee, &global_sid_World)) { 569 627 ace_v4->who.special_id = SMB_ACE4_WHO_EVERYONE; 570 628 ace_v4->flags |= SMB_ACE4_ID_SPECIAL; … … 574 632 uid_t uid; 575 633 gid_t gid; 576 DOM_SIDsid;634 struct dom_sid sid; 577 635 578 636 sid_copy(&sid, &ace_nt->trustee); … … 580 638 if (!lookup_sid(mem_ctx, &sid, &dom, &name, &type)) { 581 639 582 DOM_SIDmapped;640 struct dom_sid mapped; 583 641 584 642 if (!nfs4_map_sid(params, &sid, &mapped)) { … … 676 734 static SMB4ACL_T *smbacl4_win2nfs4( 677 735 const char *filename, 678 const SEC_ACL*dacl,736 const struct security_acl *dacl, 679 737 smbacl4_vfs_params *pparams, 680 738 uid_t ownerUID, … … 720 778 NTSTATUS smb_set_nt_acl_nfs4(files_struct *fsp, 721 779 uint32 security_info_sent, 722 const SEC_DESC*psd,780 const struct security_descriptor *psd, 723 781 set_nfs4acl_native_fn_t set_nfs4_native) 724 782 { … … 735 793 DEBUG(10, ("smb_set_nt_acl_nfs4 invoked for %s\n", fsp_str_dbg(fsp))); 736 794 737 if ((security_info_sent & ( DACL_SECURITY_INFORMATION|738 GROUP_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION)) == 0)795 if ((security_info_sent & (SECINFO_DACL | 796 SECINFO_GROUP | SECINFO_OWNER)) == 0) 739 797 { 740 798 DEBUG(9, ("security_info_sent (0x%x) ignored\n", … … 752 810 if (params.do_chown) { 753 811 /* chown logic is a copy/paste from posix_acl.c:set_nt_acl */ 754 NTSTATUS status = unpack_nt_owners( SNUM(fsp->conn), &newUID, &newGID, security_info_sent, psd);812 NTSTATUS status = unpack_nt_owners(fsp->conn, &newUID, &newGID, security_info_sent, psd); 755 813 if (!NT_STATUS_IS_OK(status)) { 756 814 DEBUG(8, ("unpack_nt_owners failed")); … … 760 818 ((newGID != (gid_t)-1) && (sbuf.st_ex_gid != newGID))) { 761 819 762 if(try_chown(fsp->conn, fsp->fsp_name, newUID,763 newGID)) {820 status = try_chown(fsp, newUID, newGID); 821 if (!NT_STATUS_IS_OK(status)) { 764 822 DEBUG(3,("chown %s, %u, %u failed. Error = " 765 823 "%s.\n", fsp_str_dbg(fsp), 766 824 (unsigned int)newUID, 767 825 (unsigned int)newGID, 768 strerror(errno)));769 return map_nt_error_from_unix(errno);826 nt_errstr(status))); 827 return status; 770 828 } 771 829 … … 785 843 } 786 844 787 if (!(security_info_sent & DACL_SECURITY_INFORMATION) || psd->dacl ==NULL) {845 if (!(security_info_sent & SECINFO_DACL) || psd->dacl ==NULL) { 788 846 DEBUG(10, ("no dacl found; security_info_sent = 0x%x\n", security_info_sent)); 789 847 return NT_STATUS_OK;
Note:
See TracChangeset
for help on using the changeset viewer.