Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/modules/nfs4_acls.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "smbd/smbd.h"
    2122#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"
    2230
    2331#undef DBGC_CLASS
     
    4553} SMB_ACL4_INT_T;
    4654
     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
     62static 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
     84static 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
    47106static SMB_ACL4_INT_T *get_validated_aclint(SMB4ACL_T *theacl)
    48107{
     
    183242        memset(psbuf, 0, sizeof(SMB_STRUCT_STAT));
    184243
    185         if (fsp->is_directory || fsp->fh->fd == -1) {
     244        if (fsp->fh->fd == -1) {
    186245                return smbacl4_GetFileOwner(fsp->conn,
    187246                                            fsp->fsp_name->base_name, psbuf);
     
    198257
    199258static 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 */
    202261        bool is_directory, /* in */
    203         SEC_ACE **ppnt_ace_list, /* out */
     262        struct security_ace **ppnt_ace_list, /* out */
    204263        int *pgood_aces /* out */
    205264)
     
    207266        SMB_ACL4_INT_T *aclint = (SMB_ACL4_INT_T *)theacl;
    208267        SMB_ACE4_INT_T *aceint;
    209         SEC_ACE *nt_ace_list = NULL;
     268        struct security_ace *nt_ace_list = NULL;
    210269        int good_aces = 0;
    211270
     
    215274        /* We do not check for naces being 0 or theacl being NULL here because it is done upstream */
    216275        /* 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));
    218277        if (nt_ace_list==NULL)
    219278        {
     
    225284        for (aceint=aclint->first; aceint!=NULL; aceint=(SMB_ACE4_INT_T *)aceint->next) {
    226285                uint32_t mask;
    227                 DOM_SID sid;
     286                struct dom_sid sid;
    228287                SMB_ACE4PROP_T  *ace = &aceint->prop;
    229                 uint32_t mapped_ace_flags;
     288                uint32_t win_ace_flags;
    230289
    231290                DEBUG(10, ("magic: 0x%x, type: %d, iflags: %x, flags: %x, mask: %x, "
     
    264323                }
    265324
    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))) {
    268327                        /*
    269328                         * GPFS sets inherits dir_inhert and file_inherit flags
     
    272331                         */
    273332                        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;
    280341                init_sec_ace(&nt_ace_list[good_aces++], &sid,
    281342                        ace->aceType, mask,
    282                         mapped_ace_flags);
     343                        win_ace_flags);
    283344        }
    284345
     
    291352static NTSTATUS smb_get_nt_acl_nfs4_common(const SMB_STRUCT_STAT *sbuf,
    292353        uint32 security_info,
    293         SEC_DESC **ppdesc, SMB4ACL_T *theacl)
     354        struct security_descriptor **ppdesc, SMB4ACL_T *theacl)
    294355{
    295356        int     good_aces = 0;
    296         DOM_SID sid_owner, sid_group;
     357        struct dom_sid sid_owner, sid_group;
    297358        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;
    300361        TALLOC_CTX *mem_ctx = talloc_tos();
    301362
     
    322383
    323384        DEBUG(10,("after make sec_acl\n"));
    324         *ppdesc = make_sec_desc(mem_ctx, SEC_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,
    327388                                NULL, psa, &sd_size);
    328389        if (*ppdesc==NULL) {
     
    332393
    333394        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)));
    335396
    336397        return NT_STATUS_OK;
     
    339400NTSTATUS smb_fget_nt_acl_nfs4(files_struct *fsp,
    340401                               uint32 security_info,
    341                                SEC_DESC **ppdesc, SMB4ACL_T *theacl)
     402                               struct security_descriptor **ppdesc, SMB4ACL_T *theacl)
    342403{
    343404        SMB_STRUCT_STAT sbuf;
     
    355416                              const char *name,
    356417                              uint32 security_info,
    357                               SEC_DESC **ppdesc, SMB4ACL_T *theacl)
     418                              struct security_descriptor **ppdesc, SMB4ACL_T *theacl)
    358419{
    359420        SMB_STRUCT_STAT sbuf;
     
    456517                if (ace->flags == aceNew->flags &&
    457518                        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                {
    463521                        /* keep type safety; e.g. gid is an u.short */
    464522                        if (ace->flags & SMB_ACE4_ID_SPECIAL)
     
    482540}
    483541
    484 static bool nfs4_map_sid(smbacl4_vfs_params *params, const DOM_SID *src,
    485                          DOM_SID *dst)
     542static bool nfs4_map_sid(smbacl4_vfs_params *params, const struct dom_sid *src,
     543                         struct dom_sid *dst)
    486544{
    487545        static struct db_context *mapping_db = NULL;
     
    544602        uid_t ownerUID,
    545603        gid_t ownerGID,
    546         const SEC_ACE *ace_nt, /* input */
     604        const struct security_ace *ace_nt, /* input */
    547605        SMB_ACE4PROP_T *ace_v4 /* output */
    548606)
     
    552610        memset(ace_v4, 0, sizeof(SMB_ACE4PROP_T));
    553611        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);
    555613        ace_v4->aceMask = ace_nt->access_mask &
    556                 (STD_RIGHT_ALL_ACCESS | SA_RIGHT_FILE_ALL_ACCESS);
     614                (SEC_STD_ALL | SEC_FILE_ALL);
    557615
    558616        se_map_generic(&ace_v4->aceMask, &file_generic_mapping);
     
    566624                        ace_v4->aceMask, ace_nt->access_mask));
    567625
    568         if (sid_equal(&ace_nt->trustee, &global_sid_World)) {
     626        if (dom_sid_equal(&ace_nt->trustee, &global_sid_World)) {
    569627                ace_v4->who.special_id = SMB_ACE4_WHO_EVERYONE;
    570628                ace_v4->flags |= SMB_ACE4_ID_SPECIAL;
     
    574632                uid_t uid;
    575633                gid_t gid;
    576                 DOM_SID sid;
     634                struct dom_sid sid;
    577635               
    578636                sid_copy(&sid, &ace_nt->trustee);
     
    580638                if (!lookup_sid(mem_ctx, &sid, &dom, &name, &type)) {
    581639                       
    582                         DOM_SID mapped;
     640                        struct dom_sid mapped;
    583641                       
    584642                        if (!nfs4_map_sid(params, &sid, &mapped)) {
     
    676734static SMB4ACL_T *smbacl4_win2nfs4(
    677735        const char *filename,
    678         const SEC_ACL *dacl,
     736        const struct security_acl *dacl,
    679737        smbacl4_vfs_params *pparams,
    680738        uid_t ownerUID,
     
    720778NTSTATUS smb_set_nt_acl_nfs4(files_struct *fsp,
    721779        uint32 security_info_sent,
    722         const SEC_DESC *psd,
     780        const struct security_descriptor *psd,
    723781        set_nfs4acl_native_fn_t set_nfs4_native)
    724782{
     
    735793        DEBUG(10, ("smb_set_nt_acl_nfs4 invoked for %s\n", fsp_str_dbg(fsp)));
    736794
    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)
    739797        {
    740798                DEBUG(9, ("security_info_sent (0x%x) ignored\n",
     
    752810        if (params.do_chown) {
    753811                /* 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);
    755813                if (!NT_STATUS_IS_OK(status)) {
    756814                        DEBUG(8, ("unpack_nt_owners failed"));
     
    760818                    ((newGID != (gid_t)-1) && (sbuf.st_ex_gid != newGID))) {
    761819
    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)) {
    764822                                DEBUG(3,("chown %s, %u, %u failed. Error = "
    765823                                         "%s.\n", fsp_str_dbg(fsp),
    766824                                         (unsigned int)newUID,
    767825                                         (unsigned int)newGID,
    768                                          strerror(errno)));
    769                                 return map_nt_error_from_unix(errno);
     826                                         nt_errstr(status)));
     827                                return status;
    770828                        }
    771829
     
    785843        }
    786844
    787         if (!(security_info_sent & DACL_SECURITY_INFORMATION) || psd->dacl ==NULL) {
     845        if (!(security_info_sent & SECINFO_DACL) || psd->dacl ==NULL) {
    788846                DEBUG(10, ("no dacl found; security_info_sent = 0x%x\n", security_info_sent));
    789847                return NT_STATUS_OK;
Note: See TracChangeset for help on using the changeset viewer.