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 deleted
25 edited
5 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/ntvfs/posix/pvfs_acl.c

    r414 r745  
    2626#include "libcli/security/security.h"
    2727#include "param/param.h"
    28 
     28#include "../lib/util/unix_privs.h"
     29
     30#if defined(UID_WRAPPER)
     31#if !defined(UID_WRAPPER_REPLACE) && !defined(UID_WRAPPER_NOT_REPLACE)
     32#define UID_WRAPPER_REPLACE
     33#include "../uid_wrapper/uid_wrapper.h"
     34#endif
     35#else
     36#define uwrap_enabled() 0
     37#endif
    2938
    3039/* the list of currently registered ACL backends */
     
    8493{
    8594        static bool initialized = false;
    86         extern NTSTATUS pvfs_acl_nfs4_init(void);
    87         extern NTSTATUS pvfs_acl_xattr_init(void);
     95#define _MODULE_PROTO(init) extern NTSTATUS init(void);
     96        STATIC_pvfs_acl_MODULES_PROTO;
    8897        init_module_fn static_init[] = { STATIC_pvfs_acl_MODULES };
    8998        init_module_fn *shared_init;
     
    149158        struct security_ace ace;
    150159        mode_t mode;
    151         struct id_mapping *ids;
     160        struct id_map *ids;
    152161        struct composite_context *ctx;
    153162
     
    158167        sd = *psd;
    159168
    160         ids = talloc_zero_array(sd, struct id_mapping, 2);
     169        ids = talloc_zero_array(sd, struct id_map, 2);
    161170        NT_STATUS_HAVE_NO_MEMORY(ids);
    162171
    163         ids[0].unixid = talloc(ids, struct unixid);
    164         NT_STATUS_HAVE_NO_MEMORY(ids[0].unixid);
    165 
    166         ids[0].unixid->id = name->st.st_uid;
    167         ids[0].unixid->type = ID_TYPE_UID;
     172        ids[0].xid.id = name->st.st_uid;
     173        ids[0].xid.type = ID_TYPE_UID;
    168174        ids[0].sid = NULL;
    169175
    170         ids[1].unixid = talloc(ids, struct unixid);
    171         NT_STATUS_HAVE_NO_MEMORY(ids[1].unixid);
    172 
    173         ids[1].unixid->id = name->st.st_gid;
    174         ids[1].unixid->type = ID_TYPE_GID;
     176        ids[1].xid.id = name->st.st_gid;
     177        ids[1].xid.type = ID_TYPE_GID;
    175178        ids[1].sid = NULL;
    176179
     
    291294        uid_t new_uid = -1;
    292295        gid_t new_gid = -1;
    293         struct id_mapping *ids;
     296        struct id_map *ids;
    294297        struct composite_context *ctx;
    295298
     
    304307        }
    305308
    306         ids = talloc(req, struct id_mapping);
     309        ids = talloc(req, struct id_map);
    307310        NT_STATUS_HAVE_NO_MEMORY(ids);
    308         ids->unixid = NULL;
     311        ZERO_STRUCT(ids->xid);
    309312        ids->sid = NULL;
    310         ids->status = NT_STATUS_NONE_MAPPED;
     313        ids->status = ID_UNKNOWN;
    311314
    312315        new_sd = info->set_secdesc.in.sd;
     
    328331                        NT_STATUS_NOT_OK_RETURN(status);
    329332
    330                         if (ids->unixid->type == ID_TYPE_BOTH ||
    331                             ids->unixid->type == ID_TYPE_UID) {
    332                                 new_uid = ids->unixid->id;
     333                        if (ids->xid.type == ID_TYPE_BOTH ||
     334                            ids->xid.type == ID_TYPE_UID) {
     335                                new_uid = ids->xid.id;
    333336                        }
    334337                }
     
    346349                        NT_STATUS_NOT_OK_RETURN(status);
    347350
    348                         if (ids->unixid->type == ID_TYPE_BOTH ||
    349                             ids->unixid->type == ID_TYPE_GID) {
    350                                 new_gid = ids->unixid->id;
     351                        if (ids->xid.type == ID_TYPE_BOTH ||
     352                            ids->xid.type == ID_TYPE_GID) {
     353                                new_gid = ids->xid.id;
    351354                        }
    352355
     
    384387                } else {
    385388                        ret = fchown(fd, new_uid, new_gid);
     389                }
     390                if (errno == EPERM) {
     391                        if (uwrap_enabled()) {
     392                                ret = 0;
     393                        } else {
     394                                /* try again as root if we have SEC_PRIV_RESTORE or
     395                                   SEC_PRIV_TAKE_OWNERSHIP */
     396                                if (security_token_has_privilege(req->session_info->security_token,
     397                                                                 SEC_PRIV_RESTORE) ||
     398                                    security_token_has_privilege(req->session_info->security_token,
     399                                                                 SEC_PRIV_TAKE_OWNERSHIP)) {
     400                                        void *privs;
     401                                        privs = root_privileges();
     402                                        if (fd == -1) {
     403                                                ret = chown(name->full_name, new_uid, new_gid);
     404                                        } else {
     405                                                ret = fchown(fd, new_uid, new_gid);
     406                                        }
     407                                        talloc_free(privs);
     408                                }
     409                        }
    386410                }
    387411                if (ret == -1) {
     
    483507  for the common case of access check on files with no
    484508  specific NT ACL
    485 */
    486 NTSTATUS pvfs_access_check_unix(struct pvfs_state *pvfs,
    487                                 struct ntvfs_request *req,
    488                                 struct pvfs_filename *name,
    489                                 uint32_t *access_mask)
     509
     510  If name is NULL then treat as a new file creation
     511*/
     512static NTSTATUS pvfs_access_check_unix(struct pvfs_state *pvfs,
     513                                       struct ntvfs_request *req,
     514                                       struct pvfs_filename *name,
     515                                       uint32_t *access_mask)
    490516{
    491517        uid_t uid = geteuid();
    492518        uint32_t max_bits = SEC_RIGHTS_FILE_READ | SEC_FILE_ALL;
     519        struct security_token *token = req->session_info->security_token;
    493520
    494521        if (pvfs_read_only(pvfs, *access_mask)) {
     
    496523        }
    497524
    498         /* owner and root get extra permissions */
    499         if (uid == 0) {
    500                 max_bits |= SEC_STD_ALL | SEC_FLAG_SYSTEM_SECURITY;
    501         } else if (uid == name->st.st_uid) {
     525        if (name == NULL || uid == name->st.st_uid) {
    502526                max_bits |= SEC_STD_ALL;
    503         }
    504 
    505         if ((name->st.st_mode & S_IWOTH) ||
     527        } else if (security_token_has_privilege(token, SEC_PRIV_RESTORE)) {
     528                max_bits |= SEC_STD_DELETE;
     529        }
     530
     531        if (name == NULL ||
     532            (name->st.st_mode & S_IWOTH) ||
    506533            ((name->st.st_mode & S_IWGRP) &&
    507534             pvfs_group_member(pvfs, name->st.st_gid))) {
     
    517544        }
    518545
    519         if (*access_mask == SEC_FLAG_MAXIMUM_ALLOWED) {
    520                 *access_mask = max_bits;
    521                 return NT_STATUS_OK;
    522         }
    523 
    524         if (uid != 0 && (*access_mask & SEC_FLAG_SYSTEM_SECURITY)) {
    525                 return NT_STATUS_ACCESS_DENIED;
     546        if (*access_mask & SEC_FLAG_MAXIMUM_ALLOWED) {
     547                *access_mask |= max_bits;
     548                *access_mask &= ~SEC_FLAG_MAXIMUM_ALLOWED;
     549        }
     550
     551        if ((*access_mask & SEC_FLAG_SYSTEM_SECURITY) &&
     552            security_token_has_privilege(token, SEC_PRIV_SECURITY)) {
     553                max_bits |= SEC_FLAG_SYSTEM_SECURITY;
     554        }
     555       
     556        if (((*access_mask & ~max_bits) & SEC_RIGHTS_PRIV_RESTORE) &&
     557            security_token_has_privilege(token, SEC_PRIV_RESTORE)) {
     558                max_bits |= ~(SEC_RIGHTS_PRIV_RESTORE);
     559        }
     560        if (((*access_mask & ~max_bits) & SEC_RIGHTS_PRIV_BACKUP) &&
     561            security_token_has_privilege(token, SEC_PRIV_BACKUP)) {
     562                max_bits |= ~(SEC_RIGHTS_PRIV_BACKUP);
    526563        }
    527564
    528565        if (*access_mask & ~max_bits) {
    529566                DEBUG(0,(__location__ " denied access to '%s' - wanted 0x%08x but got 0x%08x (missing 0x%08x)\n",
    530                          name->full_name, *access_mask, max_bits, *access_mask & ~max_bits));
     567                         name?name->full_name:"(new file)", *access_mask, max_bits, *access_mask & ~max_bits));
    531568                return NT_STATUS_ACCESS_DENIED;
    532569        }
     
    556593        NTSTATUS status;
    557594        struct security_descriptor *sd;
     595        bool allow_delete = false;
    558596
    559597        /* on SMB2 a blank access mask is always denied */
     
    567605        }
    568606
     607        if (*access_mask & SEC_FLAG_MAXIMUM_ALLOWED ||
     608            *access_mask & SEC_STD_DELETE) {
     609                status = pvfs_access_check_parent(pvfs, req,
     610                                                  name, SEC_DIR_DELETE_CHILD);
     611                if (NT_STATUS_IS_OK(status)) {
     612                        allow_delete = true;
     613                        *access_mask &= ~SEC_STD_DELETE;
     614                }
     615        }
     616
    569617        acl = talloc(req, struct xattr_NTACL);
    570618        if (acl == NULL) {
     
    581629        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
    582630                talloc_free(acl);
    583                 return pvfs_access_check_unix(pvfs, req, name, access_mask);
     631                status = pvfs_access_check_unix(pvfs, req, name, access_mask);
     632                goto done;
    584633        }
    585634        if (!NT_STATUS_IS_OK(status)) {
     
    596645
    597646        /* check the acl against the required access mask */
    598         status = sec_access_check(sd, token, *access_mask, access_mask);
    599 
     647        status = se_access_check(sd, token, *access_mask, access_mask);
     648        talloc_free(acl);
     649done:
    600650        if (pvfs->ntvfs->ctx->protocol != PROTOCOL_SMB2) {
    601651                /* on SMB, this bit is always granted, even if not
     
    604654        }
    605655
    606         talloc_free(acl);
    607        
     656        if (allow_delete) {
     657                *access_mask |= SEC_STD_DELETE;
     658        }
     659
    608660        return status;
    609661}
     
    631683                                  struct ntvfs_request *req,
    632684                                  struct pvfs_filename *name,
    633                                   uint32_t *access_mask)
     685                                  uint32_t *access_mask,
     686                                  bool container,
     687                                  struct security_descriptor **sd)
    634688{
    635689        struct pvfs_filename *parent;
    636690        NTSTATUS status;
     691        uint32_t parent_mask;
     692        bool allow_delete = false;
     693
     694        if (pvfs_read_only(pvfs, *access_mask)) {
     695                return NT_STATUS_ACCESS_DENIED;
     696        }
    637697
    638698        status = pvfs_resolve_parent(pvfs, req, name, &parent);
     699        NT_STATUS_NOT_OK_RETURN(status);
     700
     701        if (container) {
     702                parent_mask = SEC_DIR_ADD_SUBDIR;
     703        } else {
     704                parent_mask = SEC_DIR_ADD_FILE;
     705        }
     706        if (*access_mask & SEC_FLAG_MAXIMUM_ALLOWED ||
     707            *access_mask & SEC_STD_DELETE) {
     708                parent_mask |= SEC_DIR_DELETE_CHILD;
     709        }
     710
     711        status = pvfs_access_check(pvfs, req, parent, &parent_mask);
     712        if (NT_STATUS_IS_OK(status)) {
     713                if (parent_mask & SEC_DIR_DELETE_CHILD) {
     714                        allow_delete = true;
     715                }
     716        } else if (NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
     717                /*
     718                 * on ACCESS_DENIED we get the rejected bits
     719                 * remove the non critical SEC_DIR_DELETE_CHILD
     720                 * and check if something else was rejected.
     721                 */
     722                parent_mask &= ~SEC_DIR_DELETE_CHILD;
     723                if (parent_mask != 0) {
     724                        return NT_STATUS_ACCESS_DENIED;
     725                }
     726                status = NT_STATUS_OK;
     727        } else {
     728                return status;
     729        }
     730
     731        if (*sd == NULL) {
     732                status = pvfs_acl_inherited_sd(pvfs, req, req, parent, container, sd);
     733        }
     734
     735        talloc_free(parent);
    639736        if (!NT_STATUS_IS_OK(status)) {
    640737                return status;
    641738        }
    642739
    643         status = pvfs_access_check(pvfs, req, parent, access_mask);
    644         if (!NT_STATUS_IS_OK(status)) {
    645                 return status;
    646         }
    647 
    648         if (! ((*access_mask) & SEC_DIR_ADD_FILE)) {
    649                 return pvfs_access_check_simple(pvfs, req, parent, SEC_DIR_ADD_FILE);
    650         }
    651 
    652         return status;
     740        /* expand the generic access bits to file specific bits */
     741        *access_mask = pvfs_translate_mask(*access_mask);
     742
     743        if (*access_mask & SEC_FLAG_MAXIMUM_ALLOWED) {
     744                *access_mask |= SEC_RIGHTS_FILE_ALL;
     745                *access_mask &= ~SEC_FLAG_MAXIMUM_ALLOWED;
     746        }
     747
     748        if (pvfs->ntvfs->ctx->protocol != PROTOCOL_SMB2) {
     749                /* on SMB, this bit is always granted, even if not
     750                   asked for */
     751                *access_mask |= SEC_FILE_READ_ATTRIBUTE;
     752        }
     753
     754        if (allow_delete) {
     755                *access_mask |= SEC_STD_DELETE;
     756        }
     757
     758        return NT_STATUS_OK;
    653759}
    654760
     
    778884
    779885/*
    780   setup an ACL on a new file/directory based on the inherited ACL from
    781   the parent. If there is no inherited ACL then we don't set anything,
    782   as the default ACL applies anyway
    783 */
    784 NTSTATUS pvfs_acl_inherit(struct pvfs_state *pvfs,
    785                           struct ntvfs_request *req,
    786                           struct pvfs_filename *name,
    787                           int fd)
     886  calculate the ACL on a new file/directory based on the inherited ACL
     887  from the parent. If there is no inherited ACL then return a NULL
     888  ACL, which means the default ACL should be used
     889*/
     890NTSTATUS pvfs_acl_inherited_sd(struct pvfs_state *pvfs,
     891                               TALLOC_CTX *mem_ctx,
     892                               struct ntvfs_request *req,
     893                               struct pvfs_filename *parent,
     894                               bool container,
     895                               struct security_descriptor **ret_sd)
    788896{
    789897        struct xattr_NTACL *acl;
    790898        NTSTATUS status;
    791         struct pvfs_filename *parent;
    792899        struct security_descriptor *parent_sd, *sd;
    793         bool container;
    794         struct id_mapping *ids;
     900        struct id_map *ids;
    795901        struct composite_context *ctx;
    796 
    797         /* form the parents path */
    798         status = pvfs_resolve_parent(pvfs, req, name, &parent);
    799         if (!NT_STATUS_IS_OK(status)) {
    800                 return status;
    801         }
     902        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
     903
     904        *ret_sd = NULL;
    802905
    803906        acl = talloc(req, struct xattr_NTACL);
    804         if (acl == NULL) {
    805                 return NT_STATUS_NO_MEMORY;
    806         }
     907        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(acl, tmp_ctx);
    807908
    808909        status = pvfs_acl_load(pvfs, parent, -1, acl);
    809910        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
     911                talloc_free(tmp_ctx);
    810912                return NT_STATUS_OK;
    811913        }
    812         if (!NT_STATUS_IS_OK(status)) {
    813                 return status;
    814         }
     914        NT_STATUS_NOT_OK_RETURN_AND_FREE(status, tmp_ctx);
    815915
    816916        switch (acl->version) {
     
    819919                break;
    820920        default:
     921                talloc_free(tmp_ctx);
    821922                return NT_STATUS_INVALID_ACL;
    822923        }
     
    826927            parent_sd->dacl->num_aces == 0) {
    827928                /* go with the default ACL */
     929                talloc_free(tmp_ctx);
    828930                return NT_STATUS_OK;
    829931        }
     
    831933        /* create the new sd */
    832934        sd = security_descriptor_initialise(req);
    833         if (sd == NULL) {
    834                 return NT_STATUS_NO_MEMORY;
    835         }
    836 
    837         ids = talloc_array(sd, struct id_mapping, 2);
    838         NT_STATUS_HAVE_NO_MEMORY(ids);
    839 
    840         ids[0].unixid = talloc(ids, struct unixid);
    841         NT_STATUS_HAVE_NO_MEMORY(ids[0].unixid);
    842         ids[0].unixid->id = name->st.st_uid;
    843         ids[0].unixid->type = ID_TYPE_UID;
     935        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(sd, tmp_ctx);
     936
     937        ids = talloc_array(sd, struct id_map, 2);
     938        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(ids, tmp_ctx);
     939
     940        ids[0].xid.id = geteuid();
     941        ids[0].xid.type = ID_TYPE_UID;
    844942        ids[0].sid = NULL;
    845         ids[0].status = NT_STATUS_NONE_MAPPED;
    846 
    847         ids[1].unixid = talloc(ids, struct unixid);
    848         NT_STATUS_HAVE_NO_MEMORY(ids[1].unixid);
    849         ids[1].unixid->id = name->st.st_gid;
    850         ids[1].unixid->type = ID_TYPE_GID;
     943        ids[0].status = ID_UNKNOWN;
     944
     945        ids[1].xid.id = getegid();
     946        ids[1].xid.type = ID_TYPE_GID;
    851947        ids[1].sid = NULL;
    852         ids[1].status = NT_STATUS_NONE_MAPPED;
     948        ids[1].status = ID_UNKNOWN;
    853949
    854950        ctx = wbc_xids_to_sids_send(pvfs->wbc_ctx, ids, 2, ids);
    855         NT_STATUS_HAVE_NO_MEMORY(ctx);
     951        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(ctx, tmp_ctx);
    856952
    857953        status = wbc_xids_to_sids_recv(ctx, &ids);
    858         NT_STATUS_NOT_OK_RETURN(status);
     954        NT_STATUS_NOT_OK_RETURN_AND_FREE(status, tmp_ctx);
    859955
    860956        sd->owner_sid = talloc_steal(sd, ids[0].sid);
     
    863959        sd->type |= SEC_DESC_DACL_PRESENT;
    864960
    865         container = (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) ? true:false;
    866 
    867961        /* fill in the aces from the parent */
    868962        status = pvfs_acl_inherit_aces(pvfs, parent_sd, sd, container);
    869         if (!NT_STATUS_IS_OK(status)) {
    870                 return status;
    871         }
     963        NT_STATUS_NOT_OK_RETURN_AND_FREE(status, tmp_ctx);
    872964
    873965        /* if there is nothing to inherit then we fallback to the
    874966           default acl */
    875967        if (sd->dacl == NULL || sd->dacl->num_aces == 0) {
     968                talloc_free(tmp_ctx);
    876969                return NT_STATUS_OK;
    877970        }
    878971
    879         acl->info.sd = sd;
    880 
    881         status = pvfs_acl_save(pvfs, name, fd, acl);
    882        
     972        *ret_sd = talloc_steal(mem_ctx, sd);
     973
     974        talloc_free(tmp_ctx);
     975        return NT_STATUS_OK;
     976}
     977
     978
     979/*
     980  setup an ACL on a new file/directory based on the inherited ACL from
     981  the parent. If there is no inherited ACL then we don't set anything,
     982  as the default ACL applies anyway
     983*/
     984NTSTATUS pvfs_acl_inherit(struct pvfs_state *pvfs,
     985                          struct ntvfs_request *req,
     986                          struct pvfs_filename *name,
     987                          int fd)
     988{
     989        struct xattr_NTACL acl;
     990        NTSTATUS status;
     991        struct security_descriptor *sd;
     992        struct pvfs_filename *parent;
     993        bool container;
     994
     995        /* form the parents path */
     996        status = pvfs_resolve_parent(pvfs, req, name, &parent);
     997        NT_STATUS_NOT_OK_RETURN(status);
     998
     999        container = (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) ? true:false;
     1000
     1001        status = pvfs_acl_inherited_sd(pvfs, req, req, parent, container, &sd);
     1002        if (!NT_STATUS_IS_OK(status)) {
     1003                talloc_free(parent);
     1004                return status;
     1005        }
     1006
     1007        if (sd == NULL) {
     1008                return NT_STATUS_OK;
     1009        }
     1010
     1011        acl.version = 1;
     1012        acl.info.sd = sd;
     1013
     1014        status = pvfs_acl_save(pvfs, name, fd, &acl);
     1015        talloc_free(sd);
     1016        talloc_free(parent);
     1017
    8831018        return status;
    8841019}
  • trunk/server/source4/ntvfs/posix/pvfs_acl_nfs4.c

    r414 r745  
    4040        struct security_descriptor *sd;
    4141        int i, num_ids;
    42         struct id_mapping *ids;
     42        struct id_map *ids;
    4343        struct composite_context *ctx;
    4444
     
    4848        status = pvfs_xattr_ndr_load(pvfs, mem_ctx, name->full_name, fd,
    4949                                     NFS4ACL_XATTR_NAME,
    50                                      acl, ndr_pull_nfs4acl);
     50                                     acl, (void *) ndr_pull_nfs4acl);
    5151        if (!NT_STATUS_IS_OK(status)) {
    5252                talloc_free(acl);
     
    6363        /* the number of ids to map is the acl count plus uid and gid */
    6464        num_ids = acl->a_count +2;
    65         ids = talloc_array(sd, struct id_mapping, num_ids);
     65        ids = talloc_array(sd, struct id_map, num_ids);
    6666        NT_STATUS_HAVE_NO_MEMORY(ids);
    6767
    68         ids[0].unixid = talloc(ids, struct unixid);
    69         NT_STATUS_HAVE_NO_MEMORY(ids[0].unixid);
    70         ids[0].unixid->id = name->st.st_uid;
    71         ids[0].unixid->type = ID_TYPE_UID;
     68        ids[0].xid.id = name->st.st_uid;
     69        ids[0].xid.type = ID_TYPE_UID;
    7270        ids[0].sid = NULL;
    73         ids[0].status = NT_STATUS_NONE_MAPPED;
    74 
    75         ids[1].unixid = talloc(ids, struct unixid);
    76         NT_STATUS_HAVE_NO_MEMORY(ids[1].unixid);
    77         ids[1].unixid->id = name->st.st_gid;
    78         ids[1].unixid->type = ID_TYPE_GID;
     71        ids[0].status = ID_UNKNOWN;
     72
     73        ids[1].xid.id = name->st.st_gid;
     74        ids[1].xid.type = ID_TYPE_GID;
    7975        ids[1].sid = NULL;
    80         ids[1].status = NT_STATUS_NONE_MAPPED;
     76        ids[1].status = ID_UNKNOWN;
    8177
    8278        for (i=0;i<acl->a_count;i++) {
    8379                struct nfs4ace *a = &acl->ace[i];
    84                 ids[i+2].unixid = talloc(ids, struct unixid);
    85                 NT_STATUS_HAVE_NO_MEMORY(ids[i+2].unixid);
    86                 ids[i+2].unixid->id = a->e_id;
     80                ids[i+2].xid.id = a->e_id;
    8781                if (a->e_flags & ACE4_IDENTIFIER_GROUP) {
    88                         ids[i+2].unixid->type = ID_TYPE_GID;
     82                        ids[i+2].xid.type = ID_TYPE_GID;
    8983                } else {
    90                         ids[i+2].unixid->type = ID_TYPE_UID;
     84                        ids[i+2].xid.type = ID_TYPE_UID;
    9185                }
    9286                ids[i+2].sid = NULL;
    93                 ids[i+2].status = NT_STATUS_NONE_MAPPED;
     87                ids[i+2].status = ID_UNKNOWN;
    9488        }
    9589
     
    128122        int i;
    129123        TALLOC_CTX *tmp_ctx;
    130         struct id_mapping *ids;
     124        struct id_map *ids;
    131125        struct composite_context *ctx;
    132126
     
    147141        }
    148142
    149         ids = talloc_array(tmp_ctx, struct id_mapping, acl.a_count);
     143        ids = talloc_array(tmp_ctx, struct id_map, acl.a_count);
    150144        if (ids == NULL) {
    151145                talloc_free(tmp_ctx);
     
    155149        for (i=0;i<acl.a_count;i++) {
    156150                struct security_ace *ace = &sd->dacl->aces[i];
    157                 ids[i].unixid = NULL;
     151                ZERO_STRUCT(ids[i].xid);
    158152                ids[i].sid = dom_sid_dup(ids, &ace->trustee);
    159153                if (ids[i].sid == NULL) {
     
    161155                        return NT_STATUS_NO_MEMORY;
    162156                }
    163                 ids[i].status = NT_STATUS_NONE_MAPPED;
     157                ids[i].status = ID_UNKNOWN;
    164158        }
    165159
     
    181175                a->e_flags = ace->flags;
    182176                a->e_mask  = ace->access_mask;
    183                 if (ids[i].unixid->type != ID_TYPE_UID) {
     177                if (ids[i].xid.type != ID_TYPE_UID) {
    184178                        a->e_flags |= ACE4_IDENTIFIER_GROUP;
    185179                }
    186                 a->e_id = ids[i].unixid->id;
     180                a->e_id = ids[i].xid.id;
    187181                a->e_who   = "";
    188182        }
     
    191185        status = pvfs_xattr_ndr_save(pvfs, name->full_name, fd,
    192186                                     NFS4ACL_XATTR_NAME,
    193                                      &acl, ndr_push_nfs4acl);
     187                                     &acl, (void *) ndr_push_nfs4acl);
    194188        talloc_free(privs);
    195189
  • trunk/server/source4/ntvfs/posix/pvfs_acl_xattr.c

    r414 r745  
    4444        status = pvfs_xattr_ndr_load(pvfs, mem_ctx, name->full_name, fd,
    4545                                     XATTR_NTACL_NAME,
    46                                      acl,
    47                                      (ndr_pull_flags_fn_t)ndr_pull_xattr_NTACL);
     46                                     acl, (void *) ndr_pull_xattr_NTACL);
    4847
    4948        if (!NT_STATUS_IS_OK(status)) {
     
    8483        status = pvfs_xattr_ndr_save(pvfs, name->full_name, fd,
    8584                                     XATTR_NTACL_NAME,
    86                                      &acl,
    87                                      (ndr_push_flags_fn_t)ndr_push_xattr_NTACL);
     85                                     &acl, (void *) ndr_push_xattr_NTACL);
    8886        talloc_free(privs);
    8987        return status;
  • trunk/server/source4/ntvfs/posix/pvfs_fileinfo.c

    r414 r745  
    5454*/
    5555NTSTATUS pvfs_fill_dos_info(struct pvfs_state *pvfs, struct pvfs_filename *name,
    56                             uint_t flags, int fd)
     56                            unsigned int flags, int fd)
    5757{
    5858        NTSTATUS status;
  • trunk/server/source4/ntvfs/posix/pvfs_fsinfo.c

    r414 r745  
    8989                                  struct pvfs_state);
    9090        uint64_t blocks_free, blocks_total;
    91         uint_t bpunit;
     91        unsigned int bpunit;
    9292        struct stat st;
    9393        const uint16_t block_size = 512;
  • trunk/server/source4/ntvfs/posix/pvfs_lock.c

    r414 r745  
    117117        /* we don't retry on a cancel */
    118118        if (reason == PVFS_WAIT_CANCEL) {
    119                 status = NT_STATUS_FILE_LOCK_CONFLICT;
     119                if (pvfs->ntvfs->ctx->protocol != PROTOCOL_SMB2) {
     120                        status = NT_STATUS_FILE_LOCK_CONFLICT;
     121                } else {
     122                        status = NT_STATUS_CANCELLED;
     123                }
    120124        } else {
    121125                /*
  • trunk/server/source4/ntvfs/posix/pvfs_mkdir.c

    r414 r745  
    5252        mode = pvfs_fileperms(pvfs, FILE_ATTRIBUTE_DIRECTORY);
    5353
    54         if (mkdir(name->full_name, mode) == -1) {
     54        if (pvfs_sys_mkdir(pvfs, name->full_name, mode) == -1) {
    5555                return pvfs_map_errno(pvfs, errno);
    5656        }
     
    7070        status = pvfs_acl_inherit(pvfs, req, name, -1);
    7171        if (!NT_STATUS_IS_OK(status)) {
    72                 rmdir(name->full_name);
     72                pvfs_sys_rmdir(pvfs, name->full_name);
    7373                return status;
    7474        }
     
    7979                                         md->t2mkdir.in.eas);
    8080        if (!NT_STATUS_IS_OK(status)) {
    81                 rmdir(name->full_name);
     81                pvfs_sys_rmdir(pvfs, name->full_name);
    8282                return status;
    8383        }
     
    128128        mode = pvfs_fileperms(pvfs, FILE_ATTRIBUTE_DIRECTORY);
    129129
    130         if (mkdir(name->full_name, mode) == -1) {
     130        if (pvfs_sys_mkdir(pvfs, name->full_name, mode) == -1) {
    131131                return pvfs_map_errno(pvfs, errno);
    132132        }
     
    137137        status = pvfs_acl_inherit(pvfs, req, name, -1);
    138138        if (!NT_STATUS_IS_OK(status)) {
    139                 rmdir(name->full_name);
     139                pvfs_sys_rmdir(pvfs, name->full_name);
    140140                return status;
    141141        }
     
    180180        }
    181181
    182         if (rmdir(name->full_name) == -1) {
     182        if (pvfs_sys_rmdir(pvfs, name->full_name) == -1) {
    183183                /* some olders systems don't return ENOTEMPTY to rmdir() */
    184184                if (errno == EEXIST) {
  • trunk/server/source4/ntvfs/posix/pvfs_notify.c

    r414 r745  
    180180        NTSTATUS status;
    181181        struct notify_entry e;
     182       
     183        /* We may not fill in all the elements in this entry -
     184         * structure may in future be shared with Samba3 */
     185        ZERO_STRUCT(e);
     186
     187        /* We may not fill in all the elements in this entry -
     188         * structure may in future be shared with Samba3 */
     189        ZERO_STRUCT(e);
    182190
    183191        f->notify_buffer = talloc_zero(f, struct pvfs_notify_buffer);
  • trunk/server/source4/ntvfs/posix/pvfs_open.c

    r414 r745  
    7474                                         delete_path, nt_errstr(status)));
    7575                        }
    76                         if (rmdir(delete_path) != 0) {
     76                        if (pvfs_sys_rmdir(h->pvfs, delete_path) != 0) {
    7777                                DEBUG(0,("pvfs_dir_handle_destructor: failed to rmdir '%s' - %s\n",
    7878                                         delete_path, strerror(errno)));
     
    104104                                        struct pvfs_filename *name,
    105105                                        int fd, struct pvfs_file *f,
    106                                         union smb_open *io)
    107 {
    108         NTSTATUS status;
    109         struct security_descriptor *sd;
     106                                        union smb_open *io,
     107                                        struct security_descriptor *sd)
     108{
     109        NTSTATUS status = NT_STATUS_OK;
    110110
    111111        /* setup any EAs that were asked for */
     
    119119        }
    120120
    121         sd = io->ntcreatex.in.sec_desc;
    122121        /* setup an initial sec_desc if requested */
    123122        if (sd && (sd->type & SEC_DESC_DACL_PRESENT)) {
     
    135134
    136135                status = pvfs_acl_set(pvfs, req, name, fd, SEC_STD_WRITE_DAC, &set);
    137         } else {
    138                 /* otherwise setup an inherited acl from the parent */
    139                 status = pvfs_acl_inherit(pvfs, req, name, fd);
    140136        }
    141137
     
    186182        uint32_t share_access;
    187183        bool forced;
     184        struct security_descriptor *sd = NULL;
    188185
    189186        create_options = io->generic.in.create_options;
     
    210207            (io->ntcreatex.in.create_options & NTCREATEX_OPTIONS_DIRECTORY) &&
    211208            (io->ntcreatex.in.create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) {
     209                DEBUG(3,(__location__ ": Invalid access_mask/create_options 0x%08x 0x%08x for %s\n",
     210                         io->ntcreatex.in.access_mask, io->ntcreatex.in.create_options, name->original_name));
    212211                return NT_STATUS_INVALID_PARAMETER;
    213212        }
     
    233232        case NTCREATEX_DISP_SUPERSEDE:
    234233        default:
     234                DEBUG(3,(__location__ ": Invalid open disposition 0x%08x for %s\n",
     235                         io->generic.in.open_disposition, name->original_name));
    235236                return NT_STATUS_INVALID_PARAMETER;
    236237        }
     
    252253                /* check the security descriptor */
    253254                status = pvfs_access_check(pvfs, req, name, &access_mask);
    254         } else {
    255                 status = pvfs_access_check_create(pvfs, req, name, &access_mask);
     255        } else {               
     256                sd = io->ntcreatex.in.sec_desc;
     257                status = pvfs_access_check_create(pvfs, req, name, &access_mask, true, &sd);
    256258        }
    257259        NT_STATUS_NOT_OK_RETURN(status);
     
    279281        f->handle->odb_locking_key   = data_blob(NULL, 0);
    280282        f->handle->create_options    = io->generic.in.create_options;
     283        f->handle->private_flags     = io->generic.in.private_flags;
    281284        f->handle->seek_offset       = 0;
    282285        f->handle->position          = 0;
     
    342345                mode_t mode = pvfs_fileperms(pvfs, attrib);
    343346
    344                 if (mkdir(name->full_name, mode) == -1) {
     347                if (pvfs_sys_mkdir(pvfs, name->full_name, mode) == -1) {
    345348                        return pvfs_map_errno(pvfs,errno);
    346349                }
     
    353356                }
    354357
    355                 status = pvfs_open_setup_eas_acl(pvfs, req, name, -1, f, io);
     358                status = pvfs_open_setup_eas_acl(pvfs, req, name, -1, f, io, sd);
    356359                if (!NT_STATUS_IS_OK(status)) {
    357360                        goto cleanup_delete;
     
    430433
    431434cleanup_delete:
    432         rmdir(name->full_name);
     435        pvfs_sys_rmdir(pvfs, name->full_name);
    433436        return status;
    434437}
     
    512515                                         delete_path, nt_errstr(status)));
    513516                        }
    514                         if (unlink(delete_path) != 0) {
     517                        if (pvfs_sys_unlink(h->pvfs, delete_path) != 0) {
    515518                                DEBUG(0,("pvfs_close: failed to delete '%s' - %s\n",
    516519                                         delete_path, strerror(errno)));
     
    617620        uint32_t oplock_level = OPLOCK_NONE, oplock_granted;
    618621        bool allow_level_II_oplock = false;
     622        struct security_descriptor *sd = NULL;
    619623
    620624        if (io->ntcreatex.in.file_attr & ~FILE_ATTRIBUTE_ALL_MASK) {
     625                DEBUG(3,(__location__ ": Invalid file_attr 0x%08x for %s\n",
     626                         io->ntcreatex.in.file_attr, name->original_name));
    621627                return NT_STATUS_INVALID_PARAMETER;
    622628        }
    623629
    624630        if (io->ntcreatex.in.file_attr & FILE_ATTRIBUTE_ENCRYPTED) {
     631                DEBUG(3,(__location__ ": Invalid encryption request for %s\n",
     632                         name->original_name));
    625633                return NT_STATUS_ACCESS_DENIED;
    626634        }
     
    628636        if ((io->ntcreatex.in.file_attr & FILE_ATTRIBUTE_READONLY) &&
    629637            (create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE)) {
     638                DEBUG(4,(__location__ ": Invalid delete on close for readonly file %s\n",
     639                         name->original_name));
    630640                return NT_STATUS_CANNOT_DELETE;
    631641        }
    632642
    633         status = pvfs_access_check_create(pvfs, req, name, &access_mask);
     643        sd = io->ntcreatex.in.sec_desc;
     644        status = pvfs_access_check_create(pvfs, req, name, &access_mask, false, &sd);
    634645        NT_STATUS_NOT_OK_RETURN(status);
    635646
     
    667678
    668679        /* create the file */
    669         fd = open(name->full_name, flags | O_CREAT | O_EXCL| O_NONBLOCK, mode);
     680        fd = pvfs_sys_open(pvfs, name->full_name, flags | O_CREAT | O_EXCL| O_NONBLOCK, mode);
    670681        if (fd == -1) {
    671682                return pvfs_map_errno(pvfs, errno);
     
    699710
    700711
    701         status = pvfs_open_setup_eas_acl(pvfs, req, name, fd, f, io);
     712        status = pvfs_open_setup_eas_acl(pvfs, req, name, fd, f, io, sd);
    702713        if (!NT_STATUS_IS_OK(status)) {
    703714                goto cleanup_delete;
     
    777788        f->handle->fd                = fd;
    778789        f->handle->create_options    = io->generic.in.create_options;
     790        f->handle->private_flags     = io->generic.in.private_flags;
    779791        f->handle->seek_offset       = 0;
    780792        f->handle->position          = 0;
     
    845857cleanup_delete:
    846858        close(fd);
    847         unlink(name->full_name);
     859        pvfs_sys_unlink(pvfs, name->full_name);
    848860        return status;
    849861}
     
    10621074                    f2->ntvfs->session_info == req->session_info &&
    10631075                    f2->ntvfs->smbpid == req->smbpid &&
    1064                     (f2->handle->create_options &
     1076                    (f2->handle->private_flags &
    10651077                     (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS |
    10661078                      NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) &&
     
    10781090        /* quite an insane set of semantics ... */
    10791091        if (is_exe_filename(io->generic.in.fname) &&
    1080             (f2->handle->create_options & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS)) {
     1092            (f2->handle->private_flags & NTCREATEX_OPTIONS_PRIVATE_DENY_DOS)) {
    10811093                return NT_STATUS_SHARING_VIOLATION;
    10821094        }
     
    11301142        struct timeval *final_timeout = NULL;
    11311143
    1132         if (io->generic.in.create_options &
     1144        if (io->generic.in.private_flags &
    11331145            (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS | NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) {
    11341146                /* see if we can satisfy the request using the special DENY_DOS
     
    11861198        struct ntvfs_handle *h;
    11871199        NTSTATUS status;
    1188         int fd;
     1200        int fd, count;
    11891201        struct odb_lock *lck;
    11901202        uint32_t create_options;
     
    12121224
    12131225        if (share_access & ~NTCREATEX_SHARE_ACCESS_MASK) {
     1226                DEBUG(3,(__location__ ": Invalid share_access 0x%08x for %s\n",
     1227                         share_access, io->ntcreatex.in.fname));
    12141228                return NT_STATUS_INVALID_PARAMETER;
    12151229        }
     
    12201234         */
    12211235        create_options_must_ignore_mask = NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
    1222         create_options_must_ignore_mask &= ~NTCREATEX_OPTIONS_PRIVATE_MASK;
    12231236        create_options &= ~create_options_must_ignore_mask;
    12241237
     
    12301243
    12311244        if (create_options & NTCREATEX_OPTIONS_INVALID_PARAM_MASK) {
     1245                DEBUG(3,(__location__ ": Invalid create_options 0x%08x for %s\n",
     1246                         create_options, io->ntcreatex.in.fname));
    12321247                return NT_STATUS_INVALID_PARAMETER;
    12331248        }
     
    12601275        if ((create_options & NTCREATEX_OPTIONS_DELETE_ON_CLOSE) &&
    12611276            !(access_mask & SEC_STD_DELETE)) {
     1277                DEBUG(3,(__location__ ": Invalid delete_on_close option 0x%08x with access_mask 0x%08x for %s\n",
     1278                         create_options, access_mask, io->ntcreatex.in.fname));
    12621279                return NT_STATUS_INVALID_PARAMETER;
    12631280        }
     
    12731290        }
    12741291
     1292        /* cope with non-zero root_fid */
     1293        if (io->ntcreatex.in.root_fid.ntvfs != NULL) {
     1294                f = pvfs_find_fd(pvfs, req, io->ntcreatex.in.root_fid.ntvfs);
     1295                if (f == NULL) {
     1296                        return NT_STATUS_INVALID_HANDLE;
     1297                }
     1298                if (f->handle->fd != -1) {
     1299                        return NT_STATUS_INVALID_DEVICE_REQUEST;
     1300                }
     1301                io->ntcreatex.in.fname = talloc_asprintf(req, "%s\\%s",
     1302                                                         f->handle->name->original_name,
     1303                                                         io->ntcreatex.in.fname);
     1304                NT_STATUS_HAVE_NO_MEMORY(io->ntcreatex.in.fname);                       
     1305        }
     1306
    12751307        if (io->ntcreatex.in.file_attr & (FILE_ATTRIBUTE_DEVICE|
    12761308                                          FILE_ATTRIBUTE_VOLUME|
    12771309                                          (~FILE_ATTRIBUTE_ALL_MASK))) {
     1310                DEBUG(3,(__location__ ": Invalid file_attr 0x%08x for %s\n",
     1311                         io->ntcreatex.in.file_attr, io->ntcreatex.in.fname));
    12781312                return NT_STATUS_INVALID_PARAMETER;
    12791313        }
     
    13591393
    13601394        default:
     1395                DEBUG(3,(__location__ ": Invalid open disposition 0x%08x for %s\n",
     1396                         io->generic.in.open_disposition, name->original_name));
    13611397                return NT_STATUS_INVALID_PARAMETER;
    13621398        }
     
    14241460        f->handle->name              = talloc_steal(f->handle, name);
    14251461        f->handle->create_options    = io->generic.in.create_options;
     1462        f->handle->private_flags     = io->generic.in.private_flags;
    14261463        f->handle->seek_offset       = 0;
    14271464        f->handle->position          = 0;
     
    15131550
    15141551        /* do the actual open */
    1515         fd = open(f->handle->name->full_name, flags | O_NONBLOCK);
     1552        fd = pvfs_sys_open(pvfs, f->handle->name->full_name, flags | O_NONBLOCK, 0);
    15161553        if (fd == -1) {
    15171554                status = pvfs_map_errno(f->pvfs, errno);
     
    15331570        f->handle->fd = fd;
    15341571
     1572        status = brl_count(f->pvfs->brl_context, f->brl_handle, &count);
     1573        if (!NT_STATUS_IS_OK(status)) {
     1574                talloc_free(lck);
     1575                return status;
     1576        }
     1577
     1578        if (count != 0) {
     1579                oplock_level = OPLOCK_NONE;
     1580        }
     1581
    15351582        /* now really mark the file as open */
    15361583        status = odb_open_file(lck, f->handle, name->full_name,
     
    15891636                if (f->handle->name->st.st_mode != mode &&
    15901637                    f->handle->name->dos.attrib != attrib &&
    1591                     fchmod(fd, mode) == -1) {
     1638                    pvfs_sys_fchmod(pvfs, fd, mode) == -1) {
    15921639                        talloc_free(lck);
    15931640                        return pvfs_map_errno(pvfs, errno);
     
    16991746        struct pvfs_file *f, *next;
    17001747
     1748        /* If pvfs is NULL, we never logged on, and no files are open. */
     1749        if(pvfs == NULL) {
     1750                return NT_STATUS_OK;
     1751        }
     1752
    17011753        for (f=pvfs->files.list;f;f=next) {
    17021754                next = f->next;
     
    19271979                          NTCREATEX_SHARE_ACCESS_DELETE;
    19281980        /*
    1929          * I would have thought that we would need to pass
    1930          * SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA here too
    1931          *
    1932          * But you only need SEC_FILE_WRITE_ATTRIBUTE permissions
    1933          * to set the filesize.
    1934          *
    1935          * --metze
     1981         * this code previous set only SEC_FILE_WRITE_ATTRIBUTE, with
     1982         * a comment that this seemed to be wrong, but matched windows
     1983         * behaviour. It now appears that this windows behaviour is
     1984         * just a bug.
    19361985         */
    1937         access_mask     = SEC_FILE_WRITE_ATTRIBUTE;
     1986        access_mask     = SEC_FILE_WRITE_ATTRIBUTE | SEC_FILE_WRITE_DATA | SEC_FILE_APPEND_DATA;
    19381987        delete_on_close = false;
    19391988        break_to_none   = true;
  • trunk/server/source4/ntvfs/posix/pvfs_qfileinfo.c

    r414 r745  
    4646                break;
    4747
     48        case RAW_FILEINFO_STREAM_INFO:
     49        case RAW_FILEINFO_STREAM_INFORMATION:
     50                needed = 0;
     51                break;
     52
    4853        case RAW_FILEINFO_SEC_DESC:
    4954                needed = 0;
     
    7277NTSTATUS pvfs_query_ea_list(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
    7378                            struct pvfs_filename *name, int fd,
    74                             uint_t num_names,
     79                            unsigned int num_names,
    7580                            struct ea_name *names,
    7681                            struct smb_ea_list *eas)
     
    319324                info->all_info2.out.position       = 0; /* only set by qfileinfo */
    320325                info->all_info2.out.mode           = 0; /* only set by qfileinfo */
     326                info->all_info2.out.alignment_requirement = 0;
    321327                /* windows wants the full path on disk for this
    322328                   result, but I really don't want to expose that on
  • trunk/server/source4/ntvfs/posix/pvfs_read.c

    r414 r745  
    6161        maxcnt = rd->readx.in.maxcnt;
    6262        if (maxcnt > 2*UINT16_MAX && req->ctx->protocol < PROTOCOL_SMB2) {
     63                DEBUG(3,(__location__ ": Invalid SMB maxcnt 0x%x\n", maxcnt));
    6364                return NT_STATUS_INVALID_PARAMETER;
    6465        }
  • trunk/server/source4/ntvfs/posix/pvfs_rename.c

    r414 r745  
    3838        NTSTATUS status;
    3939
    40         if (rename(name1->full_name, name2) == -1) {
     40        if (pvfs_sys_rename(pvfs, name1->full_name, name2) == -1) {
    4141                return pvfs_map_errno(pvfs, errno);
    4242        }
     
    9696*/
    9797static const char *pvfs_resolve_wildcard_component(TALLOC_CTX *mem_ctx,
    98                                                    struct smb_iconv_convenience *iconv_convenience,
    9998                                                   const char *fname,
    10099                                                   const char *pattern)
     
    116115                codepoint_t c1, c2;
    117116                size_t c_size1, c_size2;
    118                 c1 = next_codepoint_convenience(iconv_convenience, p1, &c_size1);
    119                 c2 = next_codepoint_convenience(iconv_convenience, p2, &c_size2);
     117                c1 = next_codepoint(p1, &c_size1);
     118                c2 = next_codepoint(p2, &c_size2);
    120119                if (c2 == '?') {
    121                         d += push_codepoint_convenience(iconv_convenience, d, c1);
     120                        d += push_codepoint(d, c1);
    122121                } else if (c2 == '*') {
    123122                        memcpy(d, p1, strlen(p1));
     
    125124                        break;
    126125                } else {
    127                         d += push_codepoint_convenience(iconv_convenience, d, c2);
     126                        d += push_codepoint(d, c2);
    128127                }
    129128
     
    143142*/
    144143static const char *pvfs_resolve_wildcard(TALLOC_CTX *mem_ctx,
    145                                          struct smb_iconv_convenience *iconv_convenience,
    146144                                         const char *fname,
    147145                                         const char *pattern)
     
    176174        }
    177175
    178         base1 = pvfs_resolve_wildcard_component(mem_ctx, iconv_convenience, base1, base2);
    179         ext1 = pvfs_resolve_wildcard_component(mem_ctx, iconv_convenience, ext1, ext2);
     176        base1 = pvfs_resolve_wildcard_component(mem_ctx, base1, base2);
     177        ext1 = pvfs_resolve_wildcard_component(mem_ctx, ext1, ext2);
    180178        if (base1 == NULL || ext1 == NULL) {
    181179                return NULL;
     
    284282
    285283        /* resolve the wildcard pattern for this name */
    286         fname2 = pvfs_resolve_wildcard(mem_ctx, lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx), fname1, fname2);
     284        fname2 = pvfs_resolve_wildcard(mem_ctx, fname1, fname2);
    287285        if (fname2 == NULL) {
    288286                return NT_STATUS_NO_MEMORY;
     
    367365            name2->full_name[strlen(dir_path)] != '/' ||
    368366            strchr(name2->full_name + strlen(dir_path) + 1, '/')) {
     367                DEBUG(3,(__location__ ": Invalid rename for %s -> %s\n",
     368                         name1->original_name, name2->original_name));
    369369                return NT_STATUS_INVALID_PARAMETER;
    370370        }
     
    481481
    482482        if (name1->has_wildcard) {
     483                DEBUG(3,(__location__ ": Invalid wildcard rename for %s\n",
     484                         name1->original_name));
    483485                return NT_STATUS_INVALID_PARAMETER;
    484486        }
    485487
    486488        if (ren->ntrename.in.new_name[0] != ':') {
     489                DEBUG(3,(__location__ ": Invalid rename for %s\n",
     490                         ren->ntrename.in.new_name));
    487491                return NT_STATUS_INVALID_PARAMETER;
    488492        }
     
    493497
    494498        if (ren->ntrename.in.flags != RENAME_FLAG_RENAME) {
     499                DEBUG(3,(__location__ ": Invalid rename flags 0x%x for %s\n",
     500                         ren->ntrename.in.flags, ren->ntrename.in.new_name));
    495501                return NT_STATUS_INVALID_PARAMETER;
    496502        }
     
    516522
    517523        status = pvfs_stream_rename(pvfs, name1, -1,
    518                                     ren->ntrename.in.new_name+1);
     524                                    ren->ntrename.in.new_name+1,
     525                                    true);
    519526        NT_STATUS_NOT_OK_RETURN(status);
    520527       
     
    621628
    622629        case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
     630                DEBUG(3,(__location__ ": Invalid rename cluster for %s\n",
     631                         name1->original_name));
    623632                return NT_STATUS_INVALID_PARAMETER;
    624633
  • trunk/server/source4/ntvfs/posix/pvfs_resolve.c

    r414 r745  
    6060static NTSTATUS pvfs_case_search(struct pvfs_state *pvfs,
    6161                                 struct pvfs_filename *name,
    62                                  uint_t flags)
     62                                 unsigned int flags)
    6363{
    6464        /* break into a series of components */
     
    187187  parse a alternate data stream name
    188188*/
    189 static NTSTATUS parse_stream_name(struct smb_iconv_convenience *ic,
    190                                   struct pvfs_filename *name,
     189static NTSTATUS parse_stream_name(struct pvfs_filename *name,
    191190                                  const char *s)
    192191{
     
    204203        while (*p) {
    205204                size_t c_size;
    206                 codepoint_t c = next_codepoint_convenience(ic, p, &c_size);
     205                codepoint_t c = next_codepoint(p, &c_size);
    207206
    208207                switch (c) {
     
    257256*/
    258257static NTSTATUS pvfs_unix_path(struct pvfs_state *pvfs, const char *cifs_name,
    259                                uint_t flags, struct pvfs_filename *name)
     258                               unsigned int flags, struct pvfs_filename *name)
    260259{
    261260        char *ret, *p, *p_start;
    262         struct smb_iconv_convenience *ic = NULL;
    263261        NTSTATUS status;
    264262
    265263        name->original_name = talloc_strdup(name, cifs_name);
     264
     265        /* remove any :$DATA */
     266        p = strrchr(name->original_name, ':');
     267        if (p && strcasecmp_m(p, ":$DATA") == 0) {
     268                if (p > name->original_name && p[-1] == ':') {
     269                        p--;
     270                }
     271                *p = 0;
     272        }
     273
    266274        name->stream_name = NULL;
    267275        name->stream_id = 0;
     
    291299        p_start = p;
    292300
    293         ic = lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx);
    294301        while (*p) {
    295302                size_t c_size;
    296                 codepoint_t c = next_codepoint_convenience(ic, p, &c_size);
     303                codepoint_t c = next_codepoint(p, &c_size);
    297304
    298305                if (c <= 0x1F) {
     
    327334                                return NT_STATUS_OBJECT_NAME_INVALID;
    328335                        }
    329                         status = parse_stream_name(ic, name, p);
     336                        status = parse_stream_name(name, p);
    330337                        if (!NT_STATUS_IS_OK(status)) {
    331338                                return status;
     
    379386*/
    380387static NTSTATUS pvfs_reduce_name(TALLOC_CTX *mem_ctx,
    381                                  struct smb_iconv_convenience *iconv_convenience,
    382                                  const char **fname, uint_t flags)
     388                                 const char **fname, unsigned int flags)
    383389{
    384390        codepoint_t c;
     
    392398
    393399        for (num_components=1, p=s; *p; p += c_size) {
    394                 c = next_codepoint_convenience(iconv_convenience, p, &c_size);
     400                c = next_codepoint(p, &c_size);
    395401                if (c == '\\') num_components++;
    396402        }
     
    404410        components[0] = s;
    405411        for (i=0, p=s; *p; p += c_size) {
    406                 c = next_codepoint_convenience(iconv_convenience, p, &c_size);
     412                c = next_codepoint(p, &c_size);
    407413                if (c == '\\') {
    408414                        *p = 0;
     
    499505     TODO: ../ collapsing, and outside share checking
    500506*/
    501 NTSTATUS pvfs_resolve_name(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
     507NTSTATUS pvfs_resolve_name(struct pvfs_state *pvfs,
     508                           struct ntvfs_request *req,
    502509                           const char *cifs_name,
    503                            uint_t flags, struct pvfs_filename **name)
     510                           unsigned int flags, struct pvfs_filename **name)
    504511{
    505512        NTSTATUS status;
    506513
    507         *name = talloc(mem_ctx, struct pvfs_filename);
     514        *name = talloc(req, struct pvfs_filename);
    508515        if (*name == NULL) {
    509516                return NT_STATUS_NO_MEMORY;
     
    515522        if (!(pvfs->fs_attribs & FS_ATTR_NAMED_STREAMS)) {
    516523                flags &= ~PVFS_RESOLVE_STREAMS;
     524        }
     525
     526        /* SMB2 doesn't allow a leading slash */
     527        if (req->ctx->protocol == PROTOCOL_SMB2 &&
     528            *cifs_name == '\\') {
     529                return NT_STATUS_INVALID_PARAMETER;
    517530        }
    518531
     
    523536        if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_PATH_SYNTAX_BAD)) {
    524537                /* it might contain .. components which need to be reduced */
    525                 status = pvfs_reduce_name(*name, lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx), &cifs_name, flags);
     538                status = pvfs_reduce_name(*name, &cifs_name, flags);
    526539                if (!NT_STATUS_IS_OK(status)) {
    527540                        return status;
     
    594607NTSTATUS pvfs_resolve_partial(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
    595608                              const char *unix_dir, const char *fname,
    596                               uint_t flags, struct pvfs_filename **name)
     609                              unsigned int flags, struct pvfs_filename **name)
    597610{
    598611        NTSTATUS status;
     
    631644*/
    632645NTSTATUS pvfs_resolve_name_fd(struct pvfs_state *pvfs, int fd,
    633                               struct pvfs_filename *name, uint_t flags)
     646                              struct pvfs_filename *name, unsigned int flags)
    634647{
    635648        dev_t device = (dev_t)0;
     
    680693        if (h->have_opendb_entry) {
    681694                struct odb_lock *lck;
    682                 const char *name = NULL;
     695                char *name = NULL;
    683696
    684697                lck = odb_lock(h, h->pvfs->odb_context, &h->odb_locking_key);
     
    691704                }
    692705
    693                 status = odb_get_path(lck, &name);
     706                status = odb_get_path(lck, (const char **) &name);
    694707                if (NT_STATUS_IS_OK(status)) {
    695708                        /*
     
    703716                                const char *orig_dir;
    704717                                const char *new_file;
    705                                 const char *new_orig;
     718                                char *new_orig;
    706719                                char *delim;
    707720
  • trunk/server/source4/ntvfs/posix/pvfs_search.c

    r414 r745  
    233233*/
    234234static NTSTATUS pvfs_search_fill(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
    235                                  uint_t max_count,
     235                                 unsigned int max_count,
    236236                                 struct pvfs_search_state *search,
    237237                                 enum smb_search_data_level level,
    238                                  uint_t *reply_count,
     238                                 unsigned int *reply_count,
    239239                                 void *search_private,
    240240                                 bool (*callback)(void *, const union smb_search_data *))
     
    292292{
    293293        int i;
    294         time_t t = time(NULL);
     294        time_t t = time_mono(NULL);
    295295
    296296        for (i=0;i<MAX_OLD_SEARCHES;i++) {
     
    324324                                  struct pvfs_state);
    325325        struct pvfs_search_state *search;
    326         uint_t reply_count;
     326        unsigned int reply_count;
    327327        uint16_t search_attrib;
    328328        const char *pattern;
     
    380380        search->search_attrib = search_attrib & 0xFF;
    381381        search->must_attrib = (search_attrib>>8) & 0xFF;
    382         search->last_used = time(NULL);
     382        search->last_used = time_mono(NULL);
    383383        search->te = NULL;
    384384
     
    416416        struct pvfs_search_state *search;
    417417        struct pvfs_dir *dir;
    418         uint_t reply_count, max_count;
     418        unsigned int reply_count, max_count;
    419419        uint16_t handle;
    420420        NTSTATUS status;
     
    438438                return status;
    439439        }
    440         search->last_used = time(NULL);
     440        search->last_used = time_mono(NULL);
    441441
    442442        status = pvfs_search_fill(pvfs, req, max_count, search, io->generic.data_level,
     
    468468                                  struct pvfs_state);
    469469        struct pvfs_search_state *search;
    470         uint_t reply_count;
     470        unsigned int reply_count;
    471471        uint16_t search_attrib, max_count;
    472472        const char *pattern;
     
    566566        struct pvfs_search_state *search;
    567567        struct pvfs_dir *dir;
    568         uint_t reply_count;
     568        unsigned int reply_count;
    569569        uint16_t handle;
    570570        NTSTATUS status;
     
    630630                                  struct pvfs_state);
    631631        struct pvfs_search_state *search;
    632         uint_t reply_count;
     632        unsigned int reply_count;
    633633        uint16_t max_count;
    634634        const char *pattern;
     
    667667
    668668        if (strequal("", f->handle->name->original_name)) {
    669                 pattern = talloc_asprintf(req, "\\%s", io->in.pattern);
     669                pattern = talloc_asprintf(req, "%s", io->in.pattern);
    670670                NT_STATUS_HAVE_NO_MEMORY(pattern);
    671671        } else {
    672                 pattern = talloc_asprintf(req, "\\%s\\%s",
     672                pattern = talloc_asprintf(req, "%s\\%s",
    673673                                          f->handle->name->original_name,
    674674                                          io->in.pattern);
     
    733733                                  struct pvfs_state);
    734734        struct pvfs_search_state *search;
    735         uint_t reply_count;
     735        unsigned int reply_count;
    736736        uint16_t max_count;
    737737        NTSTATUS status;
  • trunk/server/source4/ntvfs/posix/pvfs_setfileinfo.c

    r414 r745  
    9090        struct odb_lock *lck = NULL;
    9191
     92        /* strangely, this gives a sharing violation, not invalid
     93           parameter */
    9294        if (info->rename_information.in.new_name[0] != ':') {
    93                 return NT_STATUS_INVALID_PARAMETER;
     95                return NT_STATUS_SHARING_VIOLATION;
    9496        }
    9597
     
    107109
    108110        status = pvfs_stream_rename(pvfs, name, fd,
    109                                     info->rename_information.in.new_name+1);
     111                                    info->rename_information.in.new_name+1,
     112                                    info->rename_information.in.overwrite);
    110113        return status;
    111114}
     
    169172
    170173        /* resolve the new name */
    171         status = pvfs_resolve_name(pvfs, name, new_name, 0, &name2);
     174        status = pvfs_resolve_name(pvfs, req, new_name, 0, &name2);
    172175        if (!NT_STATUS_IS_OK(status)) {
    173176                return status;
     
    532535                mode = pvfs_fileperms(pvfs, newstats.dos.attrib);
    533536                if (!(h->name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY)) {
    534                         if (fchmod(h->fd, mode) == -1) {
     537                        if (pvfs_sys_fchmod(pvfs, h->fd, mode) == -1) {
    535538                                return pvfs_map_errno(pvfs, errno);
    536539                        }
     
    857860        if (newstats.dos.attrib != name->dos.attrib) {
    858861                mode_t mode = pvfs_fileperms(pvfs, newstats.dos.attrib);
    859                 if (chmod(name->full_name, mode) == -1) {
     862                if (pvfs_sys_chmod(pvfs, name->full_name, mode) == -1) {
    860863                        return pvfs_map_errno(pvfs, errno);
    861864                }
  • trunk/server/source4/ntvfs/posix/pvfs_shortname.c

    r414 r745  
    105105        /* this is used to reverse the base 36 mapping */
    106106        unsigned char base_reverse[256];
    107 
    108         struct smb_iconv_convenience *iconv_convenience;
    109107};
    110108
     
    391389        while (*name) {
    392390                size_t c_size;
    393                 codepoint_t c = next_codepoint_convenience(ctx->iconv_convenience, name, &c_size);
     391                codepoint_t c = next_codepoint(name, &c_size);
    394392                if (c == INVALID_CODEPOINT) {
    395393                        return false;
     
    616614        }
    617615
    618         ctx->iconv_convenience = lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx);
    619 
    620616        /* by default have a max of 512 entries in the cache. */
    621         ctx->cache_size = lp_parm_int(pvfs->ntvfs->ctx->lp_ctx, NULL, "mangle", "cachesize", 512);
     617        ctx->cache_size = lpcfg_parm_int(pvfs->ntvfs->ctx->lp_ctx, NULL, "mangle", "cachesize", 512);
    622618
    623619        ctx->prefix_cache = talloc_array(ctx, char *, ctx->cache_size);
     
    633629        memset(ctx->prefix_cache_hashes, 0, sizeof(uint32_t) * ctx->cache_size);
    634630
    635         ctx->mangle_prefix = lp_parm_int(pvfs->ntvfs->ctx->lp_ctx, NULL, "mangle", "prefix", -1);
     631        ctx->mangle_prefix = lpcfg_parm_int(pvfs->ntvfs->ctx->lp_ctx, NULL, "mangle", "prefix", -1);
    636632        if (ctx->mangle_prefix < 0 || ctx->mangle_prefix > 6) {
    637633                ctx->mangle_prefix = DEFAULT_MANGLE_PREFIX;
  • trunk/server/source4/ntvfs/posix/pvfs_streams.c

    r414 r745  
    241241*/
    242242NTSTATUS pvfs_stream_rename(struct pvfs_state *pvfs, struct pvfs_filename *name, int fd,
    243                             const char *new_name)
     243                            const char *new_name, bool overwrite)
    244244{
    245245        struct xattr_DosStreams *streams;
     
    290290                s->name = new_name;
    291291        } else {
    292                 /* remove the old one and replace with the new one */
    293                 streams->streams[found_old].name = new_name;
    294                 memmove(&streams->streams[found_new],
    295                         &streams->streams[found_new+1],
    296                         sizeof(streams->streams[0]) *
    297                         (streams->num_streams - (found_new+1)));
     292                if (!overwrite) {
     293                        return NT_STATUS_OBJECT_NAME_COLLISION;
     294                }
     295                if (found_old != found_new) {
     296                        /* remove the old one and replace with the new one */
     297                        streams->streams[found_old].name = new_name;
     298                        memmove(&streams->streams[found_new],
     299                                &streams->streams[found_new+1],
     300                                sizeof(streams->streams[0]) *
     301                                (streams->num_streams - (found_new+1)));
     302                        streams->num_streams--;
     303                }
    298304        }
    299305
    300306        status = pvfs_streams_save(pvfs, name, fd, streams);
    301         talloc_free(streams);
     307
     308        if (NT_STATUS_IS_OK(status)) {
     309
     310                /* update the in-memory copy of the name of the open file */
     311                talloc_free(name->stream_name);
     312                name->stream_name = talloc_strdup(name, new_name);
     313
     314                talloc_free(streams);
     315        }
    302316
    303317        return status;
     
    533547        status = pvfs_xattr_save(pvfs, name->full_name, fd, XATTR_DOSSTREAM_PREFIX,
    534548                                 name->stream_name, &blob);
    535         data_blob_free(&blob);
    536549
    537550        if (NT_STATUS_IS_OK(status)) {
    538551                status = pvfs_stream_update_size(pvfs, name, fd, blob.length);
    539552        }
     553        data_blob_free(&blob);
    540554
    541555        return status;
  • trunk/server/source4/ntvfs/posix/pvfs_unlink.c

    r414 r745  
    110110                                 struct pvfs_filename *name)
    111111{
    112         NTSTATUS status;
     112        NTSTATUS status = NT_STATUS_OK;
    113113
    114114        if (name->dos.attrib & FILE_ATTRIBUTE_DIRECTORY) {
     
    124124
    125125        /* finally try the actual unlink */
    126         if (unlink(name->full_name) == -1) {
     126        if (pvfs_sys_unlink(pvfs, name->full_name) == -1) {
    127127                status = pvfs_map_errno(pvfs, errno);
    128128        }
  • trunk/server/source4/ntvfs/posix/pvfs_util.c

    r414 r745  
    103103        }
    104104
    105         fd1 = open(name1->full_name, O_RDONLY);
     105        fd1 = pvfs_sys_open(pvfs, name1->full_name, O_RDONLY, 0);
    106106        if (fd1 == -1) {
    107107                talloc_free(buf);
     
    109109        }
    110110
    111         fd2 = open(name2->full_name, O_CREAT|O_EXCL|O_WRONLY, 0);
     111        fd2 = pvfs_sys_open(pvfs, name2->full_name, O_CREAT|O_EXCL|O_WRONLY, 0);
    112112        if (fd2 == -1) {
    113113                close(fd1);
     
    134134                        close(fd2);
    135135                        talloc_free(buf);
    136                         unlink(name2->full_name);
     136                        pvfs_sys_unlink(pvfs, name2->full_name);
    137137                        if (ret2 == -1) {
    138138                                return pvfs_map_errno(pvfs, errno);
     
    146146
    147147        mode = pvfs_fileperms(pvfs, name1->dos.attrib);
    148         if (fchmod(fd2, mode) == -1) {
     148        if (pvfs_sys_fchmod(pvfs, fd2, mode) == -1) {
    149149                status = pvfs_map_errno(pvfs, errno);
    150150                close(fd2);
    151                 unlink(name2->full_name);
     151                pvfs_sys_unlink(pvfs, name2->full_name);
    152152                return status;
    153153        }
     
    159159        if (!NT_STATUS_IS_OK(status)) {
    160160                close(fd2);
    161                 unlink(name2->full_name);
     161                pvfs_sys_unlink(pvfs, name2->full_name);
    162162                return status;
    163163        }
  • trunk/server/source4/ntvfs/posix/pvfs_wait.c

    r414 r745  
    103103        pwait->reason = PVFS_WAIT_TIMEOUT;
    104104
    105         talloc_increase_ref_count(req);
    106         ntvfs_async_setup(pwait->req, pwait);
    107         talloc_free(req);
     105        req = talloc_reference(ev, req);
     106        if (req != NULL) {
     107                ntvfs_async_setup(req, pwait);
     108                talloc_unlink(ev, req);
     109        }
    108110}
    109111
  • trunk/server/source4/ntvfs/posix/pvfs_xattr.c

    r414 r745  
    118118
    119119        /* pull the blob */
    120         ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx),
    121                                        p, (ndr_pull_flags_fn_t)pull_fn);
     120        ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, p,
     121                                                                  (ndr_pull_flags_fn_t)pull_fn);
    122122        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    123123                return ndr_map_error2ntstatus(ndr_err);
     
    141141        enum ndr_err_code ndr_err;
    142142
    143         ndr_err = ndr_push_struct_blob(&blob, mem_ctx, lp_iconv_convenience(pvfs->ntvfs->ctx->lp_ctx), p, (ndr_push_flags_fn_t)push_fn);
     143        ndr_err = ndr_push_struct_blob(&blob, mem_ctx, p, (ndr_push_flags_fn_t)push_fn);
    144144        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    145145                talloc_free(mem_ctx);
     
    177177        status = pvfs_xattr_ndr_load(pvfs, mem_ctx, name->full_name,
    178178                                     fd, XATTR_DOSATTRIB_NAME,
    179                                      &attrib, 
    180                                      (ndr_pull_flags_fn_t)ndr_pull_xattr_DosAttrib);
     179                                     &attrib,
     180                                     (void *) ndr_pull_xattr_DosAttrib);
    181181
    182182        /* not having a DosAttrib is not an error */
     
    272272        return pvfs_xattr_ndr_save(pvfs, name->full_name, fd,
    273273                                   XATTR_DOSATTRIB_NAME, &attrib,
    274                                    (ndr_push_flags_fn_t)ndr_push_xattr_DosAttrib);
     274                                   (void *) ndr_push_xattr_DosAttrib);
    275275}
    276276
     
    288288        }
    289289        status = pvfs_xattr_ndr_load(pvfs, eas, name->full_name, fd, XATTR_DOSEAS_NAME,
    290                                      eas, (ndr_pull_flags_fn_t)ndr_pull_xattr_DosEAs);
     290                                     eas, (void *) ndr_pull_xattr_DosEAs);
    291291        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
    292292                return NT_STATUS_OK;
     
    305305        }
    306306        return pvfs_xattr_ndr_save(pvfs, name->full_name, fd, XATTR_DOSEAS_NAME, eas,
    307                                    (ndr_push_flags_fn_t)ndr_push_xattr_DosEAs);
     307                                   (void *) ndr_push_xattr_DosEAs);
    308308}
    309309
     
    323323                                     XATTR_DOSSTREAMS_NAME,
    324324                                     streams,
    325                                      (ndr_pull_flags_fn_t)ndr_pull_xattr_DosStreams);
     325                                     (void *) ndr_pull_xattr_DosStreams);
    326326        if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
    327327                return NT_STATUS_OK;
     
    342342                                   XATTR_DOSSTREAMS_NAME,
    343343                                   streams,
    344                                    (ndr_push_flags_fn_t)ndr_push_xattr_DosStreams);
     344                                   (void *) ndr_push_xattr_DosStreams);
    345345}
    346346
     
    360360                                     XATTR_NTACL_NAME,
    361361                                     acl,
    362                                      (ndr_pull_flags_fn_t)ndr_pull_xattr_NTACL);
     362                                     (void *) ndr_pull_xattr_NTACL);
    363363        return status;
    364364}
     
    383383                                     XATTR_NTACL_NAME,
    384384                                     acl,
    385                                      (ndr_push_flags_fn_t)ndr_push_xattr_NTACL);
     385                                     (void *) ndr_push_xattr_NTACL);
    386386        talloc_free(privs);
    387387        return status;
  • trunk/server/source4/ntvfs/posix/vfs_posix.c

    r414 r745  
    2727#include "vfs_posix.h"
    2828#include "librpc/gen_ndr/security.h"
    29 #include "../tdb/include/tdb.h"
    30 #include "tdb_wrap.h"
     29#include <tdb.h>
     30#include "lib/util/tdb_wrap.h"
    3131#include "libcli/security/security.h"
    3232#include "lib/events/events.h"
     
    4040        struct share_config *scfg = pvfs->ntvfs->ctx->config;
    4141        const char *eadb;
     42        bool def_perm_override = false;
    4243
    4344        if (share_bool_option(scfg, SHARE_MAP_HIDDEN, SHARE_MAP_HIDDEN_DEFAULT))
     
    6061                pvfs->flags |= PVFS_FLAG_LINUX_AIO;
    6162
     63#if defined(O_DIRECTORY) && defined(O_NOFOLLOW)
     64        /* set PVFS_PERM_OVERRIDE by default only if the system
     65         * supports the necessary capabilities to make it secure
     66         */
     67        def_perm_override = true;
     68#endif
     69        if (share_bool_option(scfg, PVFS_PERM_OVERRIDE, def_perm_override))
     70                pvfs->flags |= PVFS_FLAG_PERM_OVERRIDE;
     71
    6272        /* file perm options */
    6373        pvfs->options.create_mask       = share_int_option(scfg,
     
    257267                                           pvfs->ntvfs->ctx->server_id, 
    258268                                           pvfs->ntvfs->ctx->msg_ctx,
    259                                            pvfs->ntvfs->ctx->lp_ctx, 
     269                                           pvfs->ntvfs->ctx->lp_ctx,
    260270                                           pvfs->ntvfs->ctx->event_ctx,
    261271                                           pvfs->ntvfs->ctx->config);
  • trunk/server/source4/ntvfs/posix/vfs_posix.h

    r414 r745  
    4141
    4242        const char *share_name;
    43         uint_t flags;
     43        unsigned int flags;
    4444
    4545        struct pvfs_mangle_context *mangle_ctx;
     
    5555
    5656        /* the sharing violation timeout (nsecs) */
    57         uint_t sharing_violation_delay;
     57        unsigned int sharing_violation_delay;
    5858
    5959        /* the oplock break timeout (secs) */
    60         uint_t oplock_break_timeout;
     60        unsigned int oplock_break_timeout;
    6161
    6262        /* the write time update delay (nsecs) */
    63         uint_t writetime_delay;
     63        unsigned int writetime_delay;
    6464
    6565        /* filesystem attributes (see FS_ATTR_*) */
     
    8585
    8686                /* how long to keep inactive searches around for */
    87                 uint_t inactivity_time;
     87                unsigned int inactivity_time;
    8888        } search;
    8989
     
    125125*/
    126126struct pvfs_filename {
    127         const char *original_name;
     127        char *original_name;
    128128        char *full_name;
    129         const char *stream_name; /* does not include :$DATA suffix */
     129        char *stream_name; /* does not include :$DATA suffix */
    130130        uint32_t stream_id;      /* this uses a hash, so is probabilistic */
    131131        bool has_wildcard;
     
    183183        /* the open went through to completion */
    184184        bool open_completed;
     185
     186        uint8_t private_flags;
    185187};
    186188
     
    223225        uint16_t must_attrib;
    224226        struct pvfs_dir *dir;
    225         time_t last_used;
    226         uint_t num_ea_names;
     227        time_t last_used; /* monotonic clock time */
     228        unsigned int num_ea_names;
    227229        struct ea_name *ea_names;
    228230        struct tevent_timer *te;
     
    245247#define PVFS_FLAG_FAKE_OPLOCKS   (1<<8)
    246248#define PVFS_FLAG_LINUX_AIO      (1<<9)
     249#define PVFS_FLAG_PERM_OVERRIDE  (1<<10)
    247250
    248251/* forward declare some anonymous structures */
     
    267270#define PVFS_ACL                        "posix:acl"
    268271#define PVFS_AIO                        "posix:aio"
     272#define PVFS_PERM_OVERRIDE              "posix:permission override"
    269273
    270274#define PVFS_XATTR_DEFAULT                      true
  • trunk/server/source4/ntvfs/posix/xattr_tdb.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "lib/util/tdb_wrap.h"
     24#include <tdb.h>
    2325#include "vfs_posix.h"
    24 #include "../tdb/include/tdb.h"
    25 #include "tdb_wrap.h"
    2626
    2727#define XATTR_LIST_ATTR ".xattr_list"
     
    3131  can automatically clean them up
    3232*/
    33 static NTSTATUS xattr_tdb_add_list(struct pvfs_state *pvfs, const char *attr_name,
     33static NTSTATUS xattr_tdb_add_list(struct tdb_wrap *ea_tdb, TALLOC_CTX *ctx, const char *attr_name,
    3434                                   const char *fname, int fd)
    3535{
     
    4444        }
    4545
    46         mem_ctx = talloc_new(pvfs);
    47 
    48         status = pull_xattr_blob_tdb(pvfs, mem_ctx, XATTR_LIST_ATTR,
     46        mem_ctx = talloc_new(ctx);
     47
     48        status = pull_xattr_blob_tdb_raw(ea_tdb, mem_ctx, XATTR_LIST_ATTR,
    4949                                     fname, fd, 100, &blob);
    5050        if (!NT_STATUS_IS_OK(status)) {
     
    6969        blob.length += len;
    7070
    71         status = push_xattr_blob_tdb(pvfs, XATTR_LIST_ATTR, fname, fd, &blob);
     71        status = push_xattr_blob_tdb_raw(ea_tdb,ctx, XATTR_LIST_ATTR, fname, fd, &blob);
    7272        talloc_free(mem_ctx);
    7373
     
    7676
    7777/*
    78   form a key for using in the ea_db
    79 */
    80 static NTSTATUS get_ea_db_key(TALLOC_CTX *mem_ctx,
     78  form a key for using in the ea_tdb
     79*/
     80static NTSTATUS get_ea_tdb_key(TALLOC_CTX *mem_ctx,
    8181                              const char *attr_name,
    8282                              const char *fname, int fd,
     
    109109}
    110110
    111 /*
    112   pull a xattr as a blob, using the ea_db tdb
    113 */
    114 NTSTATUS pull_xattr_blob_tdb(struct pvfs_state *pvfs,
     111
     112
     113/*
     114  pull a xattr as a blob, using the ea_tdb_context tdb
     115*/
     116NTSTATUS pull_xattr_blob_tdb_raw(struct tdb_wrap *ea_tdb,
    115117                             TALLOC_CTX *mem_ctx,
    116                              const char *attr_name, 
    117                              const char *fname, 
    118                              int fd, 
     118                             const char *attr_name,
     119                             const char *fname,
     120                             int fd,
    119121                             size_t estimated_size,
    120122                             DATA_BLOB *blob)
     
    123125        NTSTATUS status;
    124126
    125         status = get_ea_db_key(mem_ctx, attr_name, fname, fd, &tkey);
     127        status = get_ea_tdb_key(mem_ctx, attr_name, fname, fd, &tkey);
    126128        if (!NT_STATUS_IS_OK(status)) {
    127129                return status;
    128130        }
    129131
    130         tdata = tdb_fetch(pvfs->ea_db->tdb, tkey);
     132        tdata = tdb_fetch(ea_tdb->tdb, tkey);
    131133        if (tdata.dptr == NULL) {
    132134                return NT_STATUS_NOT_FOUND;
     
    142144}
    143145
    144 /*
    145   push a xattr as a blob, using ea_db
    146 */
    147 NTSTATUS push_xattr_blob_tdb(struct pvfs_state *pvfs,
    148                              const char *attr_name,
    149                              const char *fname,
    150                              int fd,
     146NTSTATUS pull_xattr_blob_tdb(struct pvfs_state *pvfs,
     147                             TALLOC_CTX *mem_ctx,
     148                             const char *attr_name,
     149                             const char *fname,
     150                             int fd,
     151                             size_t estimated_size,
     152                             DATA_BLOB *blob)
     153{
     154        return pull_xattr_blob_tdb_raw(pvfs->ea_db,mem_ctx,attr_name,fname,fd,estimated_size,blob);
     155}
     156
     157/*
     158  push a xattr as a blob, using ea_tdb
     159*/
     160NTSTATUS push_xattr_blob_tdb_raw(struct tdb_wrap *ea_tdb,
     161                             TALLOC_CTX *mem_ctx,
     162                             const char *attr_name,
     163                             const char *fname,
     164                             int fd,
    151165                             const DATA_BLOB *blob)
    152166{
     
    154168        NTSTATUS status;
    155169
    156         status = get_ea_db_key(pvfs, attr_name, fname, fd, &tkey);
     170        status = get_ea_tdb_key(mem_ctx, attr_name, fname, fd, &tkey);
    157171        if (!NT_STATUS_IS_OK(status)) {
    158172                return status;
     
    162176        tdata.dsize = blob->length;
    163177
    164         if (tdb_chainlock(pvfs->ea_db->tdb, tkey) != 0) {
     178        if (tdb_chainlock(ea_tdb->tdb, tkey) != 0) {
    165179                talloc_free(tkey.dptr);
    166180                return NT_STATUS_INTERNAL_DB_CORRUPTION;
    167181        }
    168182
    169         status = xattr_tdb_add_list(pvfs, attr_name, fname, fd);
     183        status = xattr_tdb_add_list(ea_tdb,mem_ctx, attr_name, fname, fd);
    170184        if (!NT_STATUS_IS_OK(status)) {
    171185                goto done;
    172186        }
    173187
    174         if (tdb_store(pvfs->ea_db->tdb, tkey, tdata, TDB_REPLACE) == -1) {
     188        if (tdb_store(ea_tdb->tdb, tkey, tdata, TDB_REPLACE) == -1) {
    175189                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
    176190        }
    177191
    178192done:
    179         tdb_chainunlock(pvfs->ea_db->tdb, tkey);
     193        tdb_chainunlock(ea_tdb->tdb, tkey);
    180194        talloc_free(tkey.dptr);
    181195        return status; 
    182196}
     197NTSTATUS push_xattr_blob_tdb(struct pvfs_state *pvfs,
     198                             const char *attr_name,
     199                             const char *fname,
     200                             int fd,
     201                             const DATA_BLOB *blob)
     202{
     203        return push_xattr_blob_tdb_raw(pvfs->ea_db,pvfs,attr_name,fname,fd,blob);
     204}
    183205
    184206
     
    192214        NTSTATUS status;
    193215
    194         status = get_ea_db_key(NULL, attr_name, fname, fd, &tkey);
     216        status = get_ea_tdb_key(NULL, attr_name, fname, fd, &tkey);
    195217        if (!NT_STATUS_IS_OK(status)) {
    196218                return status;
     
    218240        NTSTATUS status;
    219241
    220         status = pull_xattr_blob_tdb(pvfs, mem_ctx, XATTR_LIST_ATTR, 
     242        status = pull_xattr_blob_tdb(pvfs, mem_ctx, XATTR_LIST_ATTR,
    221243                                     fname, -1, 100, &blob);
    222244        if (!NT_STATUS_IS_OK(status)) {
Note: See TracChangeset for help on using the changeset viewer.