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:
66 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

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

    r414 r745  
    596596NTSTATUS charset_macosxfs_init(void)
    597597{
    598         return smb_register_charset(&macosxfs_encoding_functions);
     598        if (!smb_register_charset(&macosxfs_encoding_functions)) {
     599                return NT_STATUS_INTERNAL_ERROR;
     600        }
     601        return NT_STATUS_OK;
    599602}
    600603
  • trunk/server/source3/modules/developer.c

    r414 r745  
    125125struct charset_functions weird_functions = {"WEIRD", weird_pull, weird_push};
    126126
    127 int charset_weird_init(void)
     127NTSTATUS charset_weird_init(void)
    128128{
    129         smb_register_charset(&weird_functions);
    130         return True;
     129        if (!smb_register_charset(&weird_functions)) {
     130                return NT_STATUS_INTERNAL_ERROR;
     131        }
     132        return NT_STATUS_OK;
    131133}
  • trunk/server/source3/modules/gpfs.c

    r599 r745  
    1919
    2020#include "includes.h"
     21#include "smbd/smbd.h"
    2122
    2223#ifdef HAVE_GPFS
    2324
     25#include "libcli/security/security.h"
    2426#include "gpfs_gpl.h"
    2527#include "vfs_gpfs.h"
     
    3941static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
    4042static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
     43static int (*gpfs_lib_init_fn)(int flags);
    4144
    4245bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
     
    133136}
    134137
    135 int smbd_gpfs_ftrunctate(int fd, gpfs_off64_t length)
    136 {
    137        if (!gpfs_do_ftruncate || (gpfs_ftruncate_fn == NULL)) {
    138                errno = ENOSYS;
    139                return -1;
    140        }
    141 
    142        return gpfs_ftruncate_fn(fd, length);
     138int smbd_gpfs_ftruncate(int fd, gpfs_off64_t length)
     139{
     140        if (!gpfs_do_ftruncate || (gpfs_ftruncate_fn == NULL)) {
     141                errno = ENOSYS;
     142                return -1;
     143        }
     144
     145        return gpfs_ftruncate_fn(fd, length);
    143146}
    144147
     
    186189        DEBUG(10, ("gpfs_set_winattrs_path:open call %s\n",pathname));
    187190        return gpfs_set_winattrs_path_fn(pathname,flags, attrs);
     191}
     192
     193void smbd_gpfs_lib_init()
     194{
     195        if (gpfs_lib_init_fn) {
     196                int rc = gpfs_lib_init_fn(0);
     197                DEBUG(10, ("gpfs_lib_init() finished with rc %d "
     198                           "and errno %d\n", rc, errno));
     199        } else {
     200                DEBUG(10, ("libgpfs lacks gpfs_lib_init\n"));
     201        }
    188202}
    189203
     
    249263        init_gpfs_function(&gpfs_set_winattrs_path_fn,"gpfs_set_winattrs_path");
    250264        init_gpfs_function(&gpfs_get_winattrs_fn,"gpfs_get_winattrs");
    251         init_gpfs_function(&gpfs_ftruncate_fn,"gpfs_ftruncate");
     265        init_gpfs_function(&gpfs_ftruncate_fn, "gpfs_ftruncate");
     266        init_gpfs_function(&gpfs_lib_init_fn,"gpfs_lib_init");
    252267
    253268        gpfs_getrealfilename = lp_parm_bool(-1, "gpfs", "getrealfilename",
    254269                                            True);
    255270        gpfs_winattr = lp_parm_bool(-1, "gpfs", "winattr", False);
    256 
    257271        gpfs_do_ftruncate = lp_parm_bool(-1, "gpfs", "ftruncate", True);
    258272
     
    311325}
    312326
     327void smbd_gpfs_lib_init()
     328{
     329        return;
     330}
     331
    313332void init_gpfs(void)
    314333{
  • 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;
  • trunk/server/source3/modules/nfs4_acls.h

    r414 r745  
    7777#define SMB_ACE4_FAILED_ACCESS_ACE_FLAG       0x00000020
    7878#define SMB_ACE4_IDENTIFIER_GROUP             0x00000040
     79#define SMB_ACE4_INHERITED_ACE                0x00000080
    7980#define SMB_ACE4_ALL_FLAGS      ( SMB_ACE4_FILE_INHERIT_ACE | SMB_ACE4_DIRECTORY_INHERIT_ACE \
    8081| SMB_ACE4_NO_PROPAGATE_INHERIT_ACE | SMB_ACE4_INHERIT_ONLY_ACE | SMB_ACE4_SUCCESSFUL_ACCESS_ACE_FLAG \
    81 | SMB_ACE4_FAILED_ACCESS_ACE_FLAG | SMB_ACE4_IDENTIFIER_GROUP )
     82| SMB_ACE4_FAILED_ACCESS_ACE_FLAG | SMB_ACE4_IDENTIFIER_GROUP | SMB_ACE4_INHERITED_ACE)
    8283
    8384        uint32  aceMask;        /* Access rights */
     
    132133NTSTATUS smb_fget_nt_acl_nfs4(files_struct *fsp,
    133134        uint32 security_info,
    134         SEC_DESC **ppdesc, SMB4ACL_T *theacl);
     135        struct security_descriptor **ppdesc, SMB4ACL_T *theacl);
    135136
    136137NTSTATUS smb_get_nt_acl_nfs4(connection_struct *conn,
    137138        const char *name,
    138139        uint32 security_info,
    139         SEC_DESC **ppdesc, SMB4ACL_T *theacl);
     140        struct security_descriptor **ppdesc, SMB4ACL_T *theacl);
    140141
    141142/* Callback function needed to set the native acl
     
    145146NTSTATUS smb_set_nt_acl_nfs4(files_struct *fsp,
    146147        uint32 security_info_sent,
    147         const SEC_DESC *psd,
     148        const struct security_descriptor *psd,
    148149        set_nfs4acl_native_fn_t set_nfs4_native);
    149150
  • trunk/server/source3/modules/onefs.h

    r414 r745  
    121121
    122122NTSTATUS onefs_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
    123                            uint32 security_info, SEC_DESC **ppdesc);
     123                           uint32 security_info, struct security_descriptor **ppdesc);
    124124
    125125NTSTATUS onefs_get_nt_acl(vfs_handle_struct *handle, const char* name,
    126                           uint32 security_info, SEC_DESC **ppdesc);
     126                          uint32 security_info, struct security_descriptor **ppdesc);
    127127
    128128NTSTATUS onefs_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
    129                            uint32 security_info_sent, const SEC_DESC *psd);
     129                           uint32 security_info_sent,
     130                           const struct security_descriptor *psd);
    130131
    131132/*
     
    133134 */
    134135struct ifs_security_descriptor;
    135 NTSTATUS onefs_samba_sd_to_sd(uint32_t security_info_sent, const SEC_DESC *psd,
     136NTSTATUS onefs_samba_sd_to_sd(uint32_t security_info_sent,
     137                              const struct security_descriptor *psd,
    136138                              struct ifs_security_descriptor *sd, int snum,
    137139                              uint32_t *security_info_effective);
    138 
    139 NTSTATUS onefs_split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
    140                                       char **pbase, char **pstream);
    141140
    142141NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
  • trunk/server/source3/modules/onefs_acl.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "smbd/smbd.h"
    2324#include "onefs.h"
    2425#include "onefs_config.h"
     
    3940 */
    4041static bool
    41 onefs_sid_to_identity(const DOM_SID *sid, struct ifs_identity *id,
     42onefs_sid_to_identity(const struct dom_sid *sid, struct ifs_identity *id,
    4243    bool is_group)
    4344{
     
    8182 */
    8283static bool
    83 onefs_identity_to_sid(struct ifs_identity *id, DOM_SID *sid)
     84onefs_identity_to_sid(struct ifs_identity *id, struct dom_sid *sid)
    8485{
    8586        if (!id || !sid)
     
    117118
    118119static bool
    119 onefs_og_to_identity(DOM_SID *sid, struct ifs_identity * ident,
     120onefs_og_to_identity(struct dom_sid *sid, struct ifs_identity * ident,
    120121    bool is_group, int snum)
    121122{
    122         const DOM_SID *b_admin_sid = &global_sid_Builtin_Administrators;
     123        const struct dom_sid *b_admin_sid = &global_sid_Builtin_Administrators;
    123124
    124125        if (!onefs_sid_to_identity(sid, ident, is_group)) {
     
    141142
    142143static bool
    143 sid_in_ignore_list(DOM_SID * sid, int snum)
     144sid_in_ignore_list(struct dom_sid * sid, int snum)
    144145{
    145146        const char ** sid_list = NULL;
    146         DOM_SID match;
     147        struct dom_sid match;
    147148
    148149        sid_list = lp_parm_string_list(snum, PARM_ONEFS_TYPE,
     
    168169 */
    169170static bool
    170 onefs_samba_ace_to_ace(SEC_ACE * samba_ace, struct ifs_ace * ace,
     171onefs_samba_ace_to_ace(struct security_ace * samba_ace, struct ifs_ace * ace,
    171172    bool *mapped, int snum)
    172173{
     
    233234
    234235/**
    235  * Convert a SEC_ACL to a struct ifs_security_acl
     236 * Convert a struct security_acl to a struct ifs_security_acl
    236237 */
    237238static bool
    238 onefs_samba_acl_to_acl(SEC_ACL *samba_acl, struct ifs_security_acl **acl,
     239onefs_samba_acl_to_acl(struct security_acl *samba_acl, struct ifs_security_acl **acl,
    239240    bool * ignore_aces, int snum)
    240241{
    241242        int num_aces = 0;
    242243        struct ifs_ace *aces = NULL;
    243         SEC_ACE *samba_aces;
     244        struct security_ace *samba_aces;
    244245        bool mapped;
    245246        int i, j;
     
    288289
    289290/**
    290  * Convert a struct ifs_security_acl to a SEC_ACL
     291 * Convert a struct ifs_security_acl to a struct security_acl
    291292 */
    292293static bool
    293 onefs_acl_to_samba_acl(struct ifs_security_acl *acl, SEC_ACL **samba_acl)
    294 {
    295         SEC_ACE *samba_aces = NULL;
    296         SEC_ACL *tmp_samba_acl = NULL;
     294onefs_acl_to_samba_acl(struct ifs_security_acl *acl, struct security_acl **samba_acl)
     295{
     296        struct security_ace *samba_aces = NULL;
     297        struct security_acl *tmp_samba_acl = NULL;
    297298        int i, num_aces = 0;
    298299
     
    314315        /* Allocate the ace list. */
    315316        if (num_aces > 0) {
    316                 if ((samba_aces = SMB_MALLOC_ARRAY(SEC_ACE, num_aces)) == NULL)
     317                if ((samba_aces = SMB_MALLOC_ARRAY(struct security_ace, num_aces)) == NULL)
    317318                {
    318319                        DEBUG(0, ("Unable to malloc space for %d aces.\n",
     
    320321                        return false;
    321322                }
    322                 memset(samba_aces, '\0', (num_aces) * sizeof(SEC_ACE));
     323                memset(samba_aces, '\0', (num_aces) * sizeof(struct security_ace));
    323324        }
    324325
    325326        for (i = 0; i < num_aces; i++) {
    326                 DOM_SID sid;
     327                struct dom_sid sid;
    327328
    328329                if (!onefs_identity_to_sid(&acl->aces[i].trustee, &sid))
     
    554555                /* Use existing samba logic to derive the mode bits. */
    555556                file_mode = unix_mode(fsp->conn, 0, fsp->fsp_name, NULL);
    556                 dir_mode = unix_mode(fsp->conn, aDIR, fsp->fsp_name, NULL);
     557                dir_mode = unix_mode(fsp->conn, FILE_ATTRIBUTE_DIRECTORY, fsp->fsp_name, NULL);
    557558
    558559                /* Initialize ACEs. */
     
    605606NTSTATUS
    606607onefs_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
    607                   uint32 security_info, SEC_DESC **ppdesc)
     608                  uint32 security_info, struct security_descriptor **ppdesc)
    608609{
    609610        int error;
     
    611612        size_t size = 0;
    612613        struct ifs_security_descriptor *sd = NULL;
    613         DOM_SID owner_sid, group_sid;
    614         DOM_SID *ownerp, *groupp;
    615         SEC_ACL *dacl, *sacl;
    616         SEC_DESC *pdesc;
     614        struct dom_sid owner_sid, group_sid;
     615        struct dom_sid *ownerp, *groupp;
     616        struct security_acl *dacl, *sacl;
     617        struct security_descriptor *pdesc;
    617618        bool alloced = false;
    618619        bool new_aces_alloced = false;
     
    630631                PARM_IGNORE_SACLS, PARM_IGNORE_SACLS_DEFAULT)) {
    631632                DEBUG(5, ("Ignoring SACL on %s.\n", fsp_str_dbg(fsp)));
    632                 security_info &= ~SACL_SECURITY_INFORMATION;
     633                security_info &= ~SECINFO_SACL;
    633634        }
    634635
     
    706707
    707708        /* Copy owner into ppdesc */
    708         if (security_info & OWNER_SECURITY_INFORMATION) {
     709        if (security_info & SECINFO_OWNER) {
    709710                if (!onefs_identity_to_sid(sd->owner, &owner_sid)) {
    710711                        status = NT_STATUS_INVALID_PARAMETER;
     
    716717
    717718        /* Copy group into ppdesc */
    718         if (security_info & GROUP_SECURITY_INFORMATION) {
     719        if (security_info & SECINFO_GROUP) {
    719720                if (!onefs_identity_to_sid(sd->group, &group_sid)) {
    720721                        status = NT_STATUS_INVALID_PARAMETER;
     
    726727
    727728        /* Copy DACL into ppdesc */
    728         if (security_info & DACL_SECURITY_INFORMATION) {
     729        if (security_info & SECINFO_DACL) {
    729730                if (!onefs_acl_to_samba_acl(sd->dacl, &dacl)) {
    730731                        status = NT_STATUS_INVALID_PARAMETER;
     
    734735
    735736        /* Copy SACL into ppdesc */
    736         if (security_info & SACL_SECURITY_INFORMATION) {
     737        if (security_info & SECINFO_SACL) {
    737738                if (!onefs_acl_to_samba_acl(sd->sacl, &sacl)) {
    738739                        status = NT_STATUS_INVALID_PARAMETER;
     
    791792NTSTATUS
    792793onefs_get_nt_acl(vfs_handle_struct *handle, const char* name,
    793                  uint32 security_info, SEC_DESC **ppdesc)
     794                 uint32 security_info, struct security_descriptor **ppdesc)
    794795{
    795796        files_struct finfo;
     
    818819/**
    819820 * Isilon-specific function for setting up an ifs_security_descriptor, given a
    820  * samba SEC_DESC.
     821 * samba struct security_descriptor
    821822 *
    822823 * @param[out] sd ifs_security_descriptor to fill in
     
    824825 * @return NTSTATUS_OK if successful
    825826 */
    826 NTSTATUS onefs_samba_sd_to_sd(uint32_t security_info_sent, const SEC_DESC *psd,
     827NTSTATUS onefs_samba_sd_to_sd(uint32_t security_info_sent,
     828                              const struct security_descriptor *psd,
    827829                              struct ifs_security_descriptor *sd, int snum,
    828830                              uint32_t *security_info_effective)
     
    840842
    841843        /* Setup owner */
    842         if (security_info_sent & OWNER_SECURITY_INFORMATION) {
     844        if (security_info_sent & SECINFO_OWNER) {
    843845                if (!onefs_og_to_identity(psd->owner_sid, &owner, false, snum))
    844846                        return NT_STATUS_ACCESS_DENIED;
     
    850852
    851853        /* Setup group */
    852         if (security_info_sent & GROUP_SECURITY_INFORMATION) {
     854        if (security_info_sent & SECINFO_GROUP) {
    853855                if (!onefs_og_to_identity(psd->group_sid, &group, true, snum))
    854856                        return NT_STATUS_ACCESS_DENIED;
     
    860862
    861863        /* Setup DACL */
    862         if ((security_info_sent & DACL_SECURITY_INFORMATION) && (psd->dacl)) {
     864        if ((security_info_sent & SECINFO_DACL) && (psd->dacl)) {
    863865                if (!onefs_samba_acl_to_acl(psd->dacl, &daclp, &ignore_aces,
    864866                        snum))
     
    866868
    867869                if (ignore_aces == true)
    868                         *security_info_effective &= ~DACL_SECURITY_INFORMATION;
     870                        *security_info_effective &= ~SECINFO_DACL;
    869871        }
    870872
    871873        /* Setup SACL */
    872         if (security_info_sent & SACL_SECURITY_INFORMATION) {
     874        if (security_info_sent & SECINFO_SACL) {
    873875
    874876                if (lp_parm_bool(snum, PARM_ONEFS_TYPE,
    875877                            PARM_IGNORE_SACLS, PARM_IGNORE_SACLS_DEFAULT)) {
    876878                        DEBUG(5, ("Ignoring SACL.\n"));
    877                         *security_info_effective &= ~SACL_SECURITY_INFORMATION;
     879                        *security_info_effective &= ~SECINFO_SACL;
    878880                } else {
    879881                        if (psd->sacl) {
     
    884886                                if (ignore_aces == true) {
    885887                                        *security_info_effective &=
    886                                             ~SACL_SECURITY_INFORMATION;
     888                                            ~SECINFO_SACL;
    887889                                }
    888890                        }
     
    910912NTSTATUS
    911913onefs_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
    912                   uint32_t sec_info_sent, const SEC_DESC *psd)
     914                  uint32_t sec_info_sent, const struct security_descriptor *psd)
    913915{
    914916        struct ifs_security_descriptor sd = {};
  • trunk/server/source3/modules/onefs_cbrl.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
    2223#include "onefs.h"
    2324
     
    2829#undef DBGC_CLASS
    2930#define DBGC_CLASS DBGC_LOCKING
    30 
    31 extern struct blocking_lock_record *blocking_lock_queue;
    3231
    3332static uint64_t onefs_get_new_id(void) {
     
    8584static void onefs_cbrl_enumerate_blq(const char *fn)
    8685{
     86        struct smbd_server_connection *sconn = smbd_server_conn;
    8787        struct blocking_lock_record *blr;
    8888
     
    9292        DEBUG(10, ("CBRL BLR records (%s):\n", fn));
    9393
    94         for (blr = blocking_lock_queue; blr; blr = blr->next)
    95                 DEBUGADD(10, ("%s\n", onefs_cbrl_blr_state_str(blr)));
     94        if (sconn->using_smb2) {
     95                struct smbd_smb2_request *smb2req;
     96                for (smb2req = sconn->smb2.requests; smb2req; smb2req = nextreq) {
     97                        blr = get_pending_smb2req_blr(smb2req);
     98                        if (blr) {
     99                                DEBUGADD(10, ("%s\n", onefs_cbrl_blr_state_str(blr)));
     100                        }
     101                }
     102        } else {
     103                for (blr = sconn->smb1.locks.blocking_lock_queue; blr; blr = blr->next)
     104                        DEBUGADD(10, ("%s\n", onefs_cbrl_blr_state_str(blr)));
     105        }
    96106}
    97107
    98108static struct blocking_lock_record *onefs_cbrl_find_blr(uint64_t id)
    99109{
     110        struct smbd_server_connection *sconn = smbd_server_conn;
    100111        struct blocking_lock_record *blr;
    101112        struct onefs_cbrl_blr_state *bs;
     
    103114        onefs_cbrl_enumerate_blq("onefs_cbrl_find_blr");
    104115
    105         for (blr = blocking_lock_queue; blr; blr = blr->next) {
    106                 bs = (struct onefs_cbrl_blr_state *)blr->blr_private;
    107 
    108                 /* We don't control all of the BLRs on the BLQ. */
    109                 if (bs == NULL)
    110                         continue;
    111 
    112                 if (bs->id == id) {
    113                         DEBUG(10, ("found %s\n",
    114                             onefs_cbrl_blr_state_str(blr)));
    115                         break;
     116        if (sconn->using_smb2) {
     117                struct smbd_smb2_request *smb2req;
     118                for (smb2req = sconn->smb2.requests; smb2req; smb2req = nextreq) {
     119                        blr = get_pending_smb2req_blr(smb2req);
     120                        if (!blr) {
     121                                continue;
     122                        }
     123                        bs = (struct onefs_cbrl_blr_state *)blr->blr_private;
     124                        if (bs == NULL) {
     125                                continue;
     126                        }
     127                        if (bs->id == id) {
     128                                DEBUG(10, ("found %s\n",
     129                                    onefs_cbrl_blr_state_str(blr)));
     130                                break;
     131                        }
     132                }
     133        } else {
     134                for (blr = sconn->smb1.locks.blocking_lock_queue; blr; blr = blr->next) {
     135                        bs = (struct onefs_cbrl_blr_state *)blr->blr_private;
     136
     137                        /* We don't control all of the BLRs on the BLQ. */
     138                        if (bs == NULL)
     139                                continue;
     140
     141                        if (bs->id == id) {
     142                                DEBUG(10, ("found %s\n",
     143                                    onefs_cbrl_blr_state_str(blr)));
     144                                break;
     145                        }
    116146                }
    117147        }
     
    157187
    158188        /* Process the queue, to try the next lock or finish up. */
    159         process_blocking_lock_queue();
     189        process_blocking_lock_queue(smbd_server_conn);
    160190}
    161191
     
    180210        /* Process the queue. It will end up trying to retake the same lock,
    181211         * see the error in onefs_cbrl_lock_windows() and fail. */
    182         process_blocking_lock_queue();
     212        process_blocking_lock_queue(smbd_server_conn);
    183213}
    184214
  • trunk/server/source3/modules/onefs_config.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "smbd/smbd.h"
    2324#include "onefs_config.h"
    2425
  • trunk/server/source3/modules/onefs_dir.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "smbd/smbd.h"
    2324#include "onefs.h"
    2425#include "onefs_config.h"
  • trunk/server/source3/modules/onefs_notify.c

    r414 r745  
    3535
    3636#include "includes.h"
     37#include "smbd/smbd.h"
    3738#include "onefs.h"
    3839
  • trunk/server/source3/modules/onefs_open.c

    r596 r745  
    3434
    3535#include "includes.h"
     36#include "smbd/smbd.h"
    3637#include "onefs.h"
    3738#include "onefs_config.h"
     
    5556                              uint32_t oplock_request,
    5657                              uint64_t allocation_size,
     58                              uint32_t private_flags,
    5759                              struct security_descriptor *sd,
    5860                              struct ea_list *ea_list,
     
    313315                        True : False;
    314316        }
    315         fsp->print_file = False;
     317        fsp->print_file = NULL;
    316318        fsp->modified = False;
    317319        fsp->sent_oplock_break = NO_BREAK_SENT;
     
    326328
    327329        DEBUG(2,("%s opened file %s read=%s write=%s (numopen=%d)\n",
    328                  conn->server_info->unix_name,
     330                 conn->session_info->unix_name,
    329331                 smb_fname_str_dbg(smb_fname),
    330332                 BOOLSTR(fsp->can_read), BOOLSTR(fsp->can_write),
     
    358360                if (procid_is_me(&e->pid) && (e->op_mid == req->mid)) {
    359361                        DEBUG(0, ("Trying to defer an already deferred "
    360                                   "request: mid=%d, exiting\n", req->mid));
     362                                "request: mid=%llu, exiting\n",
     363                                (unsigned long long)req->mid));
    361364                        exit_server("attempt to defer a deferred request");
    362365                }
     
    366369
    367370        DEBUG(10,("defer_open_sharing_error: time [%u.%06u] adding deferred "
    368                   "open entry for mid %u\n",
     371                  "open entry for mid %llu\n",
    369372                  (unsigned int)request_time.tv_sec,
    370373                  (unsigned int)request_time.tv_usec,
    371                   (unsigned int)req->mid));
    372 
    373         if (!push_deferred_smb_message(req, request_time, timeout,
    374                                        (char *)state, sizeof(*state))) {
    375                 exit_server("push_deferred_smb_message failed");
     374                  (unsigned long long)req->mid));
     375
     376        if (!push_deferred_open_message_smb(req, request_time, timeout,
     377                                       state->id, (char *)state, sizeof(*state))) {
     378                exit_server("push_deferred_open_message_smb failed");
    376379        }
    377380        add_deferred_open(lck, req->mid, request_time, state->id);
     
    439442                                  uint32 new_dos_attributes,
    440443                                  int oplock_request,
     444                                  uint32_t private_flags,
    441445                                  struct security_descriptor *sd,
    442446                                  files_struct *fsp,
     
    456460        int info;
    457461        uint32 existing_dos_attributes = 0;
    458         struct pending_message_list *pml = NULL;
    459462        struct timeval request_time = timeval_zero();
    460463        struct share_mode_lock *lck = NULL;
     
    482485                           smb_fname_str_dbg(smb_fname)));
    483486
    484                 return print_fsp_open(req, conn, smb_fname->base_name,
    485                                       req->vuid, fsp);
     487                return print_spool_open(fsp, smb_fname->base_name,
     488                                        req->vuid);
    486489        }
    487490
     
    496499                new_dos_attributes = 0;
    497500        } else {
    498                 /* We add aARCH to this as this mode is only used if the file is
     501                /* We add FILE_ATTRIBUTE_ARCHIVE to this as this mode is only used if the file is
    499502                 * created new. */
    500                 unx_mode = unix_mode(conn, new_dos_attributes | aARCH,
     503                unx_mode = unix_mode(conn, new_dos_attributes | FILE_ATTRIBUTE_ARCHIVE,
    501504                                     smb_fname, parent_dir);
    502505        }
     
    541544         */
    542545
    543         if ((req != NULL)
    544             && ((pml = get_open_deferred_message(req->mid)) != NULL)) {
    545                 struct deferred_open_record *state =
    546                         (struct deferred_open_record *)pml->private_data.data;
    547 
    548                 /* Remember the absolute time of the original
    549                    request with this mid. We'll use it later to
    550                    see if this has timed out. */
    551 
    552                 request_time = pml->request_time;
    553 
    554                 /* Remove the deferred open entry under lock. */
    555                 lck = get_share_mode_lock(talloc_tos(), state->id, NULL, NULL,
    556                                           NULL);
    557                 if (lck == NULL) {
    558                         DEBUG(0, ("could not get share mode lock\n"));
    559                 } else {
    560                         del_deferred_open_entry(lck, req->mid);
    561                         TALLOC_FREE(lck);
    562                 }
    563 
    564                 /* Ensure we don't reprocess this message. */
    565                 remove_deferred_open_smb_message(req->mid);
    566 
    567                 /*
    568                  * When receiving a semlock_async_failure message, the
    569                  * deferred open will be marked as "failed". Returning
    570                  * INTERNAL_ERROR.
    571                  */
    572                 if (state->failed) {
    573                         DEBUG(0, ("onefs_open_file_ntcreate: "
    574                                   "semlock_async_failure detected!\n"));
    575                         return NT_STATUS_INTERNAL_ERROR;
     546        if (req) {
     547                void *ptr;
     548                if (get_deferred_open_message_state(req,
     549                                &request_time,
     550                                &ptr)) {
     551                        struct deferred_open_record *state = (struct deferred_open_record *)ptr;
     552
     553                        /* Remember the absolute time of the original
     554                           request with this mid. We'll use it later to
     555                           see if this has timed out. */
     556
     557                        /* Remove the deferred open entry under lock. */
     558                        remove_deferred_open_entry(state->id, req->mid);
     559
     560                        /* Ensure we don't reprocess this message. */
     561                        remove_deferred_open_message_smb(req->mid);
     562
     563                        /*
     564                         * When receiving a semlock_async_failure message, the
     565                         * deferred open will be marked as "failed". Returning
     566                         * INTERNAL_ERROR.
     567                         */
     568                        if (state->failed) {
     569                                DEBUG(0, ("onefs_open_file_ntcreate: "
     570                                          "semlock_async_failure detected!\n"));
     571                                return NT_STATUS_INTERNAL_ERROR;
     572                        }
    576573                }
    577574        }
     
    591588        /* Setup dos_attributes to be set by ifs_createfile */
    592589        if (lp_store_dos_attributes(SNUM(conn))) {
    593                 createfile_attributes = (new_dos_attributes | aARCH) &
     590                createfile_attributes = (new_dos_attributes | FILE_ATTRIBUTE_ARCHIVE) &
    594591                    ~(FILE_ATTRIBUTE_NONINDEXED | FILE_ATTRIBUTE_COMPRESSED);
    595592        }
    596593
    597594        /* Ignore oplock requests if oplocks are disabled. */
    598         if (!lp_oplocks(SNUM(conn)) || global_client_failed_oplock_break ||
     595        if (!lp_oplocks(SNUM(conn)) ||
    599596            IS_VETO_OPLOCK_PATH(conn, smb_fname->base_name)) {
    600597                /* Mask off everything except the private Samba bits. */
     
    819816
    820817        fsp->share_access = share_access;
    821         fsp->fh->private_options = create_options;
     818        fsp->fh->private_options = private_flags;
    822819        fsp->access_mask = open_access_mask; /* We change this to the
    823820                                              * requested access_mask after
     
    993990
    994991                        /* Try to find dup fsp if possible. */
    995                         if (create_options &
     992                        if (private_flags &
    996993                            (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS|
    997994                             NTCREATEX_OPTIONS_PRIVATE_DENY_FCB)) {
     
    12621259         */
    12631260
    1264         /* Record the options we were opened with. */
    1265         fsp->share_access = share_access;
    1266         fsp->fh->private_options = create_options;
    12671261        /*
    12681262         * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
     
    13171311        }
    13181312
    1319         set_share_mode(lck, fsp, conn->server_info->utok.uid, 0,
     1313        set_share_mode(lck, fsp, get_current_uid(conn),
     1314                        req ? req->mid : 0,
    13201315                       fsp->oplock_type);
    13211316
     
    14891484                file_attributes = 0;
    14901485        } else {
    1491                 mode = unix_mode(conn, aDIR, smb_dname, parent_dir);
     1486                mode = unix_mode(conn, FILE_ATTRIBUTE_DIRECTORY, smb_dname, parent_dir);
    14921487        }
    14931488
     
    16301625
    16311626        fsp->share_access = share_access;
    1632         fsp->fh->private_options = create_options;
     1627        fsp->fh->private_options = 0;
    16331628        /*
    16341629         * According to Samba4, SEC_FILE_READ_ATTRIBUTE is always granted,
    16351630         */
    16361631        fsp->access_mask = access_mask | FILE_READ_ATTRIBUTES;
    1637         fsp->print_file = False;
     1632        fsp->print_file = NULL;
    16381633        fsp->modified = False;
    16391634        fsp->oplock_type = NO_OPLOCK;
     
    16731668        }
    16741669
    1675         set_share_mode(lck, fsp, conn->server_info->utok.uid, 0, NO_OPLOCK);
     1670        set_share_mode(lck, fsp, get_current_uid(conn),
     1671                req ? req->mid : 0, NO_OPLOCK);
    16761672
    16771673        /*
     
    17191715                                           uint32_t oplock_request,
    17201716                                           uint64_t allocation_size,
     1717                                           uint32_t private_flags,
    17211718                                           struct security_descriptor *sd,
    17221719                                           struct ea_list *ea_list,
     
    17331730                  "file_attributes = 0x%x, share_access = 0x%x, "
    17341731                  "create_disposition = 0x%x create_options = 0x%x "
    1735                   "oplock_request = 0x%x ea_list = 0x%p, sd = 0x%p, "
     1732                  "oplock_request = 0x%x private_flags = 0x%x "
     1733                  "ea_list = 0x%p, sd = 0x%p, "
    17361734                  "fname = %s\n",
    17371735                  (unsigned int)access_mask,
     
    17411739                  (unsigned int)create_options,
    17421740                  (unsigned int)oplock_request,
     1741                  (unsigned int)private_flags,
    17431742                  ea_list, sd, smb_fname_str_dbg(smb_fname)));
    17441743
     
    18241823                        NO_OPLOCK,                      /* oplock_request */
    18251824                        0,                              /* allocation_size */
     1825                        0,                              /* private_flags */
    18261826                        NULL,                           /* sd */
    18271827                        NULL,                           /* ea_list */
     
    20672067                           uint32_t oplock_request,
    20682068                           uint64_t allocation_size,
     2069                           uint32_t private_flags,
    20692070                           struct security_descriptor *sd,
    20702071                           struct ea_list *ea_list,
     
    20812082                  "file_attributes = 0x%x, share_access = 0x%x, "
    20822083                  "create_disposition = 0x%x create_options = 0x%x "
    2083                   "oplock_request = 0x%x "
     2084                  "oplock_request = 0x%x private_flags = 0x%x"
    20842085                  "root_dir_fid = 0x%x, ea_list = 0x%p, sd = 0x%p, "
    20852086                  "fname = %s\n",
     
    20902091                  (unsigned int)create_options,
    20912092                  (unsigned int)oplock_request,
     2093                  (unsigned int)private_flags,
    20922094                  (unsigned int)root_dir_fid,
    20932095                  ea_list, sd, smb_fname_str_dbg(smb_fname)));
     
    21082110        if (!NT_STATUS_IS_OK(status)) {
    21092111                goto fail;
     2112        }
     2113
     2114        if (is_ntfs_stream_smb_fname(smb_fname)) {
     2115                if (!(conn->fs_capabilities & FILE_NAMED_STREAMS)) {
     2116                        status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
     2117                        goto fail;
     2118                }
     2119
     2120                if (is_ntfs_default_stream_smb_fname(smb_fname)) {
     2121                        int ret;
     2122                        smb_fname->stream_name = NULL;
     2123                        /* We have to handle this error here. */
     2124                        if (create_options & FILE_DIRECTORY_FILE) {
     2125                                status = NT_STATUS_NOT_A_DIRECTORY;
     2126                                goto fail;
     2127                        }
     2128                        if (lp_posix_pathnames()) {
     2129                                ret = SMB_VFS_LSTAT(conn, smb_fname);
     2130                        } else {
     2131                                ret = SMB_VFS_STAT(conn, smb_fname);
     2132                        }
     2133
     2134                        if (ret == 0 && VALID_STAT_OF_DIR(smb_fname->st)) {
     2135                                status = NT_STATUS_FILE_IS_A_DIRECTORY;
     2136                                goto fail;
     2137                        }
     2138                }
    21102139        }
    21112140
     
    21212150                oplock_request,                         /* oplock_request */
    21222151                allocation_size,                        /* allocation_size */
     2152                private_flags,
    21232153                sd,                                     /* sd */
    21242154                ea_list,                                /* ea_list */
  • trunk/server/source3/modules/onefs_shadow_copy.c

    r414 r745  
    2222 */
    2323
     24#include "smbd/smbd.h"
    2425#include <ifs/ifs_syscalls.h>
    2526#include <sys/types.h>
  • trunk/server/source3/modules/onefs_streams.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "smbd/smbd.h"
    2324#include "onefs.h"
    2425#include "onefs_config.h"
  • trunk/server/source3/modules/onefs_system.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
    2223#include "onefs.h"
    2324#include "onefs_config.h"
     
    270271                        ret = sendfile(fromfd, tofd, offset, total, &hdr,
    271272                                       &nwritten, flags);
    272                 } while (ret == -1 && errno == EINTR);
     273#if defined(EWOULDBLOCK)
     274                } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
     275#else
     276                } while (ret == -1 && (errno == EINTR || errno == EAGAIN));
     277#endif
    273278
    274279                /* On error we're done. */
  • trunk/server/source3/modules/perfcount_onefs.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
    2223#include <sys/isi_stats_protocol.h>
    2324#include <sys/isi_stats_client.h>
     
    303304        /* get address info once, doesn't change for process */
    304305        if (rem_addr == 0) {
    305                 struct sockaddr_storage sa;
    306                 socklen_t sa_len;
    307                 int fd = smbd_server_fd();
    308 
    309                 sa_len = sizeof sa;
    310                 if (getpeername(fd, (struct sockaddr *)&sa, &sa_len) == 0 &&
    311                     sa.ss_family == AF_INET)
    312                         rem_addr = ((struct sockaddr_in *)&sa)->sin_addr.s_addr;
    313                 else
     306
     307#error Isilon, please remove this after testing the code below
     308
     309                char *addr;
     310
     311                addr = talloc_sub_basic(talloc_tos(), "", "", "%I");
     312                if (addr != NULL) {
     313                        rem_addr = interpret_addr(addr);
     314                        TALLOC_FREE(addr);
     315                } else {
    314316                        rem_addr = ISC_MASKED_ADDR;
    315 
    316                 sa_len = sizeof sa;
    317                 if (getsockname(fd, (struct sockaddr *)&sa, &sa_len) == 0 &&
    318                     sa.ss_family == AF_INET)
    319                         loc_addr = ((struct sockaddr_in *)&sa)->sin_addr.s_addr;
    320                 else
     317                }
     318
     319                addr = talloc_sub_basic(talloc_tos(), "", "", "%i");
     320                if (addr != NULL) {
     321                        loc_addr = interpret_addr(addr);
     322                        TALLOC_FREE(addr);
     323                } else {
    321324                        loc_addr = ISC_MASKED_ADDR;
     325                }
    322326        }
    323327
     
    336340                        tmp->iod.in_bytes, tmp->iod.out_bytes));
    337341#endif
    338                 SAFE_FREE(tmp->prev);
     342                SAFE_FREE(DLIST_PREV(tmp));
    339343        }
    340344
  • trunk/server/source3/modules/perfcount_test.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
    2223
    2324#define PARM_PC_TEST_TYPE               "pc_test"
     
    177178        DEBUG(0,("#####  Dumping Performance Counters #####\n"));
    178179
    179         for (i=0; i < 256; i++) {
    180                for (head = g_list[i]; head != NULL; head = head->next) {
    181                        perfcount_test_dump_counter(head, 0);
    182                        head->prev = NULL;
    183                        SAFE_FREE(head->prev);
    184                }
    185                SAFE_FREE(head);
     180        for (i=0; i < MAX_OP; i++) {
     181                struct perfcount_test_counter *next;
     182                for (head = g_list[i]; head != NULL; head = next) {
     183                        next = head->next;
     184                        perfcount_test_dump_counter(head, 0);
     185                        SAFE_FREE(head);
     186                }
     187                g_list[i] = NULL;
    186188        }
    187189}
  • trunk/server/source3/modules/vfs_acl_common.c

    r599 r745  
    2020 */
    2121
     22#include "smbd/smbd.h"
     23#include "system/filesys.h"
     24#include "../libcli/security/security.h"
     25#include "../librpc/gen_ndr/ndr_security.h"
     26
    2227static NTSTATUS create_acl_blob(const struct security_descriptor *psd,
    2328                        DATA_BLOB *pblob,
     
    3540                        DATA_BLOB *pblob);
    3641
    37 #define HASH_SECURITY_INFO (OWNER_SECURITY_INFORMATION | \
    38                                 GROUP_SECURITY_INFORMATION | \
    39                                 DACL_SECURITY_INFORMATION | \
    40                                 SACL_SECURITY_INFORMATION)
     42#define HASH_SECURITY_INFO (SECINFO_OWNER | \
     43                                SECINFO_GROUP | \
     44                                SECINFO_DACL | \
     45                                SECINFO_SACL)
    4146
    4247/*******************************************************************
     
    7883        size_t sd_size;
    7984
    80         ndr_err = ndr_pull_struct_blob(pblob, ctx, NULL, &xacl,
     85        ndr_err = ndr_pull_struct_blob(pblob, ctx, &xacl,
    8186                        (ndr_pull_flags_fn_t)ndr_pull_xattr_NTACL);
    8287
     
    8489                DEBUG(5, ("parse_acl_blob: ndr_pull_xattr_NTACL failed: %s\n",
    8590                        ndr_errstr(ndr_err)));
    86                 return ndr_map_error2ntstatus(ndr_err);;
     91                return ndr_map_error2ntstatus(ndr_err);
    8792        }
    8893
    8994        switch (xacl.version) {
    9095                case 2:
    91                         *ppdesc = make_sec_desc(ctx, SEC_DESC_REVISION,
     96                        *ppdesc = make_sec_desc(ctx, SD_REVISION,
    9297                                        xacl.info.sd_hs2->sd->type | SEC_DESC_SELF_RELATIVE,
    9398                                        xacl.info.sd_hs2->sd->owner_sid,
     
    101106                        break;
    102107                case 3:
    103                         *ppdesc = make_sec_desc(ctx, SEC_DESC_REVISION,
     108                        *ppdesc = make_sec_desc(ctx, SD_REVISION,
    104109                                        xacl.info.sd_hs3->sd->type | SEC_DESC_SELF_RELATIVE,
    105110                                        xacl.info.sd_hs3->sd->owner_sid,
     
    145150
    146151        ndr_err = ndr_push_struct_blob(
    147                         pblob, ctx, NULL, &xacl,
     152                        pblob, ctx, &xacl,
    148153                        (ndr_push_flags_fn_t)ndr_push_xattr_NTACL);
    149154
     
    151156                DEBUG(5, ("create_acl_blob: ndr_push_xattr_NTACL failed: %s\n",
    152157                        ndr_errstr(ndr_err)));
    153                 return ndr_map_error2ntstatus(ndr_err);;
     158                return ndr_map_error2ntstatus(ndr_err);
    154159        }
    155160
     
    250255        DATA_BLOB blob;
    251256        NTSTATUS status;
    252         uint16_t hash_type;
     257        uint16_t hash_type = XATTR_SD_HASH_TYPE_NONE;
    253258        uint8_t hash[XATTR_SD_HASH_SIZE];
    254259        uint8_t hash_tmp[XATTR_SD_HASH_SIZE];
     
    402407        }
    403408
    404         if (!(security_info & OWNER_SECURITY_INFORMATION)) {
     409        if (!(security_info & SECINFO_OWNER)) {
    405410                psd->owner_sid = NULL;
    406411        }
    407         if (!(security_info & GROUP_SECURITY_INFORMATION)) {
     412        if (!(security_info & SECINFO_GROUP)) {
    408413                psd->group_sid = NULL;
    409414        }
    410         if (!(security_info & DACL_SECURITY_INFORMATION)) {
     415        if (!(security_info & SECINFO_DACL)) {
    411416                psd->dacl = NULL;
    412417        }
    413         if (!(security_info & SACL_SECURITY_INFORMATION)) {
     418        if (!(security_info & SECINFO_SACL)) {
    414419                psd->sacl = NULL;
    415420        }
     
    444449        struct dom_sid *owner_sid = NULL;
    445450        struct dom_sid *group_sid = NULL;
    446         uint32_t security_info_sent = (OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION);
    447         size_t size;
     451        uint32_t security_info_sent = (SECINFO_OWNER | SECINFO_GROUP | SECINFO_DACL);
    448452        bool inherit_owner = lp_inherit_owner(SNUM(handle->conn));
    449453        bool inheritable_components = sd_has_inheritable_components(parent_desc,
    450454                                        is_directory);
     455        size_t size;
    451456
    452457        if (!inheritable_components && !inherit_owner) {
     
    470475
    471476        if (owner_sid == NULL) {
    472                 owner_sid = &handle->conn->server_info->ptok->user_sids[PRIMARY_USER_SID_INDEX];
     477                owner_sid = &handle->conn->session_info->security_token->sids[PRIMARY_USER_SID_INDEX];
    473478        }
    474479        if (group_sid == NULL) {
    475                 group_sid = &handle->conn->server_info->ptok->user_sids[PRIMARY_GROUP_SID_INDEX];
     480                group_sid = &handle->conn->session_info->security_token->sids[PRIMARY_GROUP_SID_INDEX];
    476481        }
    477482
     
    566571        status = smb1_file_se_access_check(handle->conn,
    567572                                        parent_desc,
    568                                         handle->conn->server_info->ptok,
     573                                        get_current_nttok(handle->conn),
    569574                                        access_mask,
    570575                                        &access_granted);
     
    614619                                NULL,
    615620                                fname,
    616                                 (OWNER_SECURITY_INFORMATION |
    617                                  GROUP_SECURITY_INFORMATION |
    618                                  DACL_SECURITY_INFORMATION),
     621                                (SECINFO_OWNER |
     622                                 SECINFO_GROUP |
     623                                 SECINFO_DACL),
    619624                                &pdesc);
    620625        if (NT_STATUS_IS_OK(status)) {
     
    622627                status = smb1_file_se_access_check(handle->conn,
    623628                                        pdesc,
    624                                         handle->conn->server_info->ptok,
     629                                        get_current_nttok(handle->conn),
    625630                                        fsp->access_mask,
    626631                                        &access_granted);
     
    837842                parent_dir, final_component ));
    838843
    839         /* cd into the parent dir to pin it. */
     844        /* cd into the parent dir to pin it. */
    840845        ret = SMB_VFS_CHDIR(conn, parent_dir);
    841846        if (ret == -1) {
     
    856861        /* Ensure we have this file open with DELETE access. */
    857862        id = vfs_file_id_from_sbuf(conn, &local_fname.st);
    858         for (fsp = file_find_di_first(id); fsp; file_find_di_next(fsp)) {
     863        for (fsp = file_find_di_first(conn->sconn, id); fsp;
     864             file_find_di_next(fsp)) {
    859865                if (fsp->access_mask & DELETE_ACCESS &&
    860866                                fsp->delete_on_close) {
     
    927933                                uint32_t oplock_request,
    928934                                uint64_t allocation_size,
     935                                uint32_t private_flags,
    929936                                struct security_descriptor *sd,
    930937                                struct ea_list *ea_list,
     
    949956                                        oplock_request,
    950957                                        allocation_size,
     958                                        private_flags,
    951959                                        sd,
    952960                                        ea_list,
  • trunk/server/source3/modules/vfs_acl_tdb.c

    r599 r745  
    2222
    2323#include "includes.h"
     24#include "smbd/smbd.h"
     25#include "system/filesys.h"
    2426#include "librpc/gen_ndr/xattr.h"
    2527#include "librpc/gen_ndr/ndr_xattr.h"
    2628#include "../lib/crypto/crypto.h"
     29#include "dbwrap.h"
     30#include "auth.h"
     31#include "util_tdb.h"
    2732
    2833#undef DBGC_CLASS
     
    399404        .mkdir = mkdir_acl_common,
    400405        .rmdir = rmdir_acl_tdb,
    401         .open = open_acl_common,
     406        .open_fn = open_acl_common,
    402407        .create_file = create_file_acl_common,
    403408        .unlink = unlink_acl_tdb,
  • trunk/server/source3/modules/vfs_acl_xattr.c

    r599 r745  
    2222
    2323#include "includes.h"
     24#include "smbd/smbd.h"
    2425#include "librpc/gen_ndr/xattr.h"
    2526#include "librpc/gen_ndr/ndr_xattr.h"
    2627#include "../lib/crypto/crypto.h"
     28#include "auth.h"
    2729
    2830#undef DBGC_CLASS
     
    186188        }
    187189
    188         /* Ensure we have the parameters correct if we're
    189         * using this module. */
    190         DEBUG(2,("connect_acl_xattr: setting 'inherit acls = true' "
    191                 "'dos filemode = true' and "
    192                 "'force unknown acl user = true' for service %s\n",
    193                 service ));
     190        /* Ensure we have the parameters correct if we're
     191        * using this module. */
     192        DEBUG(2,("connect_acl_xattr: setting 'inherit acls = true' "
     193                "'dos filemode = true' and "
     194                "'force unknown acl user = true' for service %s\n",
     195                service ));
    194196
    195197        lp_do_parameter(SNUM(handle->conn), "inherit acls", "true");
     
    205207        .mkdir = mkdir_acl_common,
    206208        .rmdir = rmdir_acl_common,
    207         .open = open_acl_common,
     209        .open_fn = open_acl_common,
    208210        .create_file = create_file_acl_common,
    209211        .unlink = unlink_acl_common,
  • trunk/server/source3/modules/vfs_afsacl.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
     23#include "../librpc/gen_ndr/lsa.h"
     24#include "../libcli/security/security.h"
     25#include "../libcli/security/dom_sid.h"
     26#include "passdb.h"
    2127
    2228#undef DBGC_CLASS
     
    3137#define MAXSIZE 2048
    3238
    33 extern const DOM_SID global_sid_World;
    34 extern const DOM_SID global_sid_Builtin_Administrators;
    35 extern const DOM_SID global_sid_Builtin_Backup_Operators;
    36 extern const DOM_SID global_sid_Authenticated_Users;
    37 extern const DOM_SID global_sid_NULL;
     39extern const struct dom_sid global_sid_World;
     40extern const struct dom_sid global_sid_Builtin_Administrators;
     41extern const struct dom_sid global_sid_Builtin_Backup_Operators;
     42extern const struct dom_sid global_sid_Authenticated_Users;
     43extern const struct dom_sid global_sid_NULL;
    3844
    3945static char space_replacement = '%';
     
    4753        bool positive;
    4854        char *name;
    49         DOM_SID sid;
     55        struct dom_sid sid;
    5056        enum lsa_SidType type;
    5157        uint32 rights;
     
    109115                                   const char *name, uint32 rights)
    110116{
    111         DOM_SID sid;
     117        struct dom_sid sid;
    112118        enum lsa_SidType type;
    113119        struct afs_ace *result;
     
    418424{
    419425        return ( (x->positive == y->positive) &&
    420                  (sid_compare(&x->sid, &y->sid) == 0) );
     426                 (dom_sid_compare(&x->sid, &y->sid) == 0) );
    421427}
    422428
     
    515521        /* FULL inherit only -- counterpart to previous one */
    516522        { 0, SEC_ACE_FLAG_OBJECT_INHERIT|SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_INHERIT_ONLY,
    517           PERMS_FULL | GENERIC_RIGHT_WRITE_ACCESS, 127 /* rlidwka */ },
     523          PERMS_FULL | SEC_GENERIC_WRITE, 127 /* rlidwka */ },
    518524
    519525        /* CHANGE without inheritance -- in all cases here we also get
     
    523529        /* CHANGE inherit only -- counterpart to previous one */
    524530        { 0, SEC_ACE_FLAG_OBJECT_INHERIT|SEC_ACE_FLAG_CONTAINER_INHERIT|SEC_ACE_FLAG_INHERIT_ONLY,
    525           PERMS_CHANGE | GENERIC_RIGHT_WRITE_ACCESS, 63 /* rlidwk */ },
     531          PERMS_CHANGE | SEC_GENERIC_WRITE, 63 /* rlidwk */ },
    526532
    527533        /* End marker, hopefully there's no afs right 9999 :-) */
     
    529535};
    530536
    531 static uint32 nt_to_afs_dir_rights(const char *filename, const SEC_ACE *ace)
     537static uint32 nt_to_afs_dir_rights(const char *filename, const struct security_ace *ace)
    532538{
    533539        uint32 result = 0;
     
    570576}
    571577
    572 static uint32 nt_to_afs_file_rights(const char *filename, const SEC_ACE *ace)
     578static uint32 nt_to_afs_file_rights(const char *filename, const struct security_ace *ace)
    573579{
    574580        uint32 result = 0;
     
    591597                                   struct security_descriptor **ppdesc)
    592598{
    593         SEC_ACE *nt_ace_list;
    594         DOM_SID owner_sid, group_sid;
    595         SEC_ACL *psa = NULL;
     599        struct security_ace *nt_ace_list;
     600        struct dom_sid owner_sid, group_sid;
     601        struct security_acl *psa = NULL;
    596602        int good_aces;
    597603        size_t sd_size;
     
    604610
    605611        if (afs_acl->num_aces) {
    606                 nt_ace_list = TALLOC_ARRAY(mem_ctx, SEC_ACE, afs_acl->num_aces);
     612                nt_ace_list = TALLOC_ARRAY(mem_ctx, struct security_ace, afs_acl->num_aces);
    607613
    608614                if (nt_ace_list == NULL)
     
    643649                return 0;
    644650
    645         *ppdesc = make_sec_desc(mem_ctx, SEC_DESC_REVISION,
     651        *ppdesc = make_sec_desc(mem_ctx, SD_REVISION,
    646652                                SEC_DESC_SELF_RELATIVE,
    647                                 (security_info & OWNER_SECURITY_INFORMATION)
     653                                (security_info & SECINFO_OWNER)
    648654                                ? &owner_sid : NULL,
    649                                 (security_info & GROUP_SECURITY_INFORMATION)
     655                                (security_info & SECINFO_GROUP)
    650656                                ? &group_sid : NULL,
    651657                                NULL, psa, &sd_size);
     
    683689        SMB_STRUCT_STAT sbuf;
    684690
    685         if (fsp->is_directory || fsp->fh->fd == -1) {
     691        if (fsp->fh->fd == -1) {
    686692                /* Get the stat struct for the owner info. */
    687693                return afs_to_nt_acl(afs_acl, fsp->conn, fsp->fsp_name,
     
    696702}
    697703
    698 static bool mappable_sid(const DOM_SID *sid)
    699 {
    700         DOM_SID domain_sid;
     704static bool mappable_sid(const struct dom_sid *sid)
     705{
     706        struct dom_sid domain_sid;
    701707       
    702         if (sid_compare(sid, &global_sid_Builtin_Administrators) == 0)
     708        if (dom_sid_compare(sid, &global_sid_Builtin_Administrators) == 0)
    703709                return True;
    704710
    705         if (sid_compare(sid, &global_sid_World) == 0)
     711        if (dom_sid_compare(sid, &global_sid_World) == 0)
    706712                return True;
    707713
    708         if (sid_compare(sid, &global_sid_Authenticated_Users) == 0)
     714        if (dom_sid_compare(sid, &global_sid_Authenticated_Users) == 0)
    709715                return True;
    710716
    711         if (sid_compare(sid, &global_sid_Builtin_Backup_Operators) == 0)
     717        if (dom_sid_compare(sid, &global_sid_Builtin_Backup_Operators) == 0)
    712718                return True;
    713719
     
    724730                          const struct security_descriptor *psd,
    725731                          uint32 (*nt_to_afs_rights)(const char *filename,
    726                                                      const SEC_ACE *ace),
     732                                                     const struct security_ace *ace),
    727733                          struct afs_acl *afs_acl)
    728734{
    729         const SEC_ACL *dacl;
     735        const struct security_acl *dacl;
    730736        int i;
    731737
    732738        /* Currently we *only* look at the dacl */
    733739
    734         if (((security_info_sent & DACL_SECURITY_INFORMATION) == 0) ||
     740        if (((security_info_sent & SECINFO_DACL) == 0) ||
    735741            (psd->dacl == NULL))
    736742                return True;
     
    742748
    743749        for (i = 0; i < dacl->num_aces; i++) {
    744                 const SEC_ACE *ace = &(dacl->aces[i]);
     750                const struct security_ace *ace = &(dacl->aces[i]);
    745751                const char *dom_name, *name;
    746752                enum lsa_SidType name_type;
     
    758764                }
    759765
    760                 if (sid_compare(&ace->trustee,
     766                if (dom_sid_compare(&ace->trustee,
    761767                                &global_sid_Builtin_Administrators) == 0) {
    762768
    763769                        name = "system:administrators";
    764770
    765                 } else if (sid_compare(&ace->trustee,
     771                } else if (dom_sid_compare(&ace->trustee,
    766772                                       &global_sid_World) == 0) {
    767773
    768774                        name = "system:anyuser";
    769775
    770                 } else if (sid_compare(&ace->trustee,
     776                } else if (dom_sid_compare(&ace->trustee,
    771777                                       &global_sid_Authenticated_Users) == 0) {
    772778
    773779                        name = "system:authuser";
    774780
    775                 } else if (sid_compare(&ace->trustee,
     781                } else if (dom_sid_compare(&ace->trustee,
    776782                                       &global_sid_Builtin_Backup_Operators)
    777783                           == 0) {
     
    10571063                         files_struct *fsp,
    10581064                         uint32 security_info_sent,
    1059                          const SEC_DESC *psd)
     1065                         const struct security_descriptor *psd)
    10601066{
    10611067        return afs_set_nt_acl(handle, fsp, security_info_sent, psd);
  • trunk/server/source3/modules/vfs_aio_fork.c

    r414 r745  
    33 *
    44 * Copyright (C) Volker Lendecke 2008
     5 * Copyright (C) Jeremy Allison 2010
    56 *
    67 * This program is free software; you can redistribute it and/or modify
     
    2021
    2122#include "includes.h"
     23#include "system/filesys.h"
     24#include "system/shmem.h"
     25#include "smbd/smbd.h"
     26
     27#ifndef MAP_FILE
     28#define MAP_FILE 0
     29#endif
    2230
    2331struct mmap_area {
     
    246254
    247255                TALLOC_FREE(child);
     256                child = next;
    248257        }
    249258
     
    344353                                fd, (void *)map->ptr, cmd_struct.n,
    345354                                cmd_struct.offset);
     355#if 0
     356/* This breaks "make test" when run with aio_fork module. */
    346357#ifdef ENABLE_BUILD_FARM_HACKS
    347358                        ret_struct.size = MAX(1, ret_struct.size * 0.9);
     359#endif
    348360#endif
    349361                }
     
    383395                                  void *p)
    384396{
     397        struct aio_extra *aio_ex = NULL;
    385398        struct aio_child *child = (struct aio_child *)p;
    386         uint16 mid;
     399        NTSTATUS status;
    387400
    388401        DEBUG(10, ("handle_aio_completion called with flags=%d\n", flags));
     
    392405        }
    393406
    394         if (!NT_STATUS_IS_OK(read_data(child->sockfd,
    395                                        (char *)&child->retval,
    396                                        sizeof(child->retval)))) {
    397                 DEBUG(0, ("aio child %d died\n", (int)child->pid));
     407        status = read_data(child->sockfd, (char *)&child->retval,
     408                           sizeof(child->retval));
     409
     410        if (!NT_STATUS_IS_OK(status)) {
     411                DEBUG(1, ("aio child %d died: %s\n", (int)child->pid,
     412                          nt_errstr(status)));
    398413                child->retval.size = -1;
    399414                child->retval.ret_errno = EIO;
     415        }
     416
     417        if (child->aiocb == NULL) {
     418                DEBUG(1, ("Inactive child died\n"));
     419                TALLOC_FREE(child);
     420                return;
    400421        }
    401422
     
    412433        }
    413434
    414         mid = child->aiocb->aio_sigevent.sigev_value.sival_int;
    415 
    416         DEBUG(10, ("mid %d finished\n", (int)mid));
    417 
    418         smbd_aio_complete_mid(mid);
     435        aio_ex = (struct aio_extra *)child->aiocb->aio_sigevent.sigev_value.sival_ptr;
     436        smbd_aio_complete_aio_ex(aio_ex);
    419437}
    420438
    421439static int aio_child_destructor(struct aio_child *child)
    422440{
     441        char c=0;
     442
    423443        SMB_ASSERT((child->aiocb == NULL) || child->cancelled);
     444
     445        DEBUG(10, ("aio_child_destructor: removing child %d on fd %d\n",
     446                        child->pid, child->sockfd));
     447
     448        /*
     449         * closing the sockfd makes the child not return from recvmsg() on RHEL
     450         * 5.5 so instead force the child to exit by writing bad data to it
     451         */
     452        write(child->sockfd, &c, sizeof(c));
    424453        close(child->sockfd);
    425454        DLIST_REMOVE(child->list->children, child);
     
    442471}
    443472
    444 static NTSTATUS create_aio_child(struct aio_child_list *children,
     473static NTSTATUS create_aio_child(struct smbd_server_connection *sconn,
     474                                 struct aio_child_list *children,
    445475                                 size_t map_size,
    446476                                 struct aio_child **presult)
     
    480510                close(fdpair[0]);
    481511                result->sockfd = fdpair[1];
    482                 file_walk_table(close_fsp_fd, NULL);
     512                files_forall(sconn, close_fsp_fd, NULL);
    483513                aio_child_loop(result->sockfd, result->map);
    484514        }
    485515
    486         DEBUG(10, ("Child %d created\n", result->pid));
     516        DEBUG(10, ("Child %d created with sockfd %d\n",
     517                        result->pid, fdpair[0]));
    487518
    488519        result->sockfd = fdpair[0];
     
    538569                DEBUG(10, ("no idle child found, creating new one\n"));
    539570
    540                 status = create_aio_child(children, 128*1024, &child);
     571                status = create_aio_child(handle->conn->sconn, children,
     572                                          128*1024, &child);
    541573                if (!NT_STATUS_IS_OK(status)) {
    542574                        DEBUG(10, ("create_aio_child failed: %s\n",
     
    725757
    726758        return child->retval.ret_errno;
     759}
     760
     761static void aio_fork_suspend_timed_out(struct tevent_context *event_ctx,
     762                                        struct tevent_timer *te,
     763                                        struct timeval now,
     764                                        void *private_data)
     765{
     766        bool *timed_out = (bool *)private_data;
     767        /* Remove this timed event handler. */
     768        TALLOC_FREE(te);
     769        *timed_out = true;
     770}
     771
     772static int aio_fork_suspend(struct vfs_handle_struct *handle,
     773                        struct files_struct *fsp,
     774                        const SMB_STRUCT_AIOCB * const aiocb_array[],
     775                        int n,
     776                        const struct timespec *timeout)
     777{
     778        struct aio_child_list *children = NULL;
     779        TALLOC_CTX *frame = talloc_stackframe();
     780        struct event_context *ev = NULL;
     781        int i;
     782        int ret = -1;
     783        bool timed_out = false;
     784
     785        children = init_aio_children(handle);
     786        if (children == NULL) {
     787                errno = EINVAL;
     788                goto out;
     789        }
     790
     791        /* This is a blocking call, and has to use a sub-event loop. */
     792        ev = event_context_init(frame);
     793        if (ev == NULL) {
     794                errno = ENOMEM;
     795                goto out;
     796        }
     797
     798        if (timeout) {
     799                struct timeval tv = convert_timespec_to_timeval(*timeout);
     800                struct tevent_timer *te = tevent_add_timer(ev,
     801                                                frame,
     802                                                timeval_current_ofs(tv.tv_sec,
     803                                                                    tv.tv_usec),
     804                                                aio_fork_suspend_timed_out,
     805                                                &timed_out);
     806                if (!te) {
     807                        errno = ENOMEM;
     808                        goto out;
     809                }
     810        }
     811
     812        for (i = 0; i < n; i++) {
     813                struct aio_child *child = NULL;
     814                const SMB_STRUCT_AIOCB *aiocb = aiocb_array[i];
     815
     816                if (!aiocb) {
     817                        continue;
     818                }
     819
     820                /*
     821                 * We're going to cheat here. We know that smbd/aio.c
     822                 * only calls this when it's waiting for every single
     823                 * outstanding call to finish on a close, so just wait
     824                 * individually for each IO to complete. We don't care
     825                 * what order they finish - only that they all do. JRA.
     826                 */
     827
     828                for (child = children->children; child != NULL; child = child->next) {
     829                        if (child->aiocb == NULL) {
     830                                continue;
     831                        }
     832                        if (child->aiocb->aio_fildes != fsp->fh->fd) {
     833                                continue;
     834                        }
     835                        if (child->aiocb != aiocb) {
     836                                continue;
     837                        }
     838
     839                        if (child->aiocb->aio_sigevent.sigev_value.sival_ptr == NULL) {
     840                                continue;
     841                        }
     842
     843                        /* We're never using this event on the
     844                         * main event context again... */
     845                        TALLOC_FREE(child->sock_event);
     846
     847                        child->sock_event = event_add_fd(ev,
     848                                                child,
     849                                                child->sockfd,
     850                                                EVENT_FD_READ,
     851                                                handle_aio_completion,
     852                                                child);
     853
     854                        while (1) {
     855                                if (tevent_loop_once(ev) == -1) {
     856                                        goto out;
     857                                }
     858
     859                                if (timed_out) {
     860                                        errno = EAGAIN;
     861                                        goto out;
     862                                }
     863
     864                                /* We set child->aiocb to NULL in our hooked
     865                                 * AIO_RETURN(). */
     866                                if (child->aiocb == NULL) {
     867                                        break;
     868                                }
     869                        }
     870                }
     871        }
     872
     873        ret = 0;
     874
     875  out:
     876
     877        TALLOC_FREE(frame);
     878        return ret;
    727879}
    728880
     
    733885        .aio_cancel = aio_fork_cancel,
    734886        .aio_error_fn = aio_fork_error_fn,
     887        .aio_suspend = aio_fork_suspend,
    735888};
    736889
  • trunk/server/source3/modules/vfs_aixacl.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
    2123
    2224extern SMB_ACL_T aixacl_to_smbacl( struct acl *file_acl);
  • trunk/server/source3/modules/vfs_aixacl2.c

    r429 r745  
    1919
    2020#include "includes.h"
     21#include "smbd/smbd.h"
    2122#include "nfs4_acls.h"
    2223
     
    156157static NTSTATUS aixjfs2_fget_nt_acl(vfs_handle_struct *handle,
    157158        files_struct *fsp, uint32 security_info,
    158         SEC_DESC **ppdesc)
     159        struct security_descriptor **ppdesc)
    159160{
    160161        SMB4ACL_T *pacl = NULL;
     
    178179static NTSTATUS aixjfs2_get_nt_acl(vfs_handle_struct *handle,
    179180        const char *name,
    180         uint32 security_info, SEC_DESC **ppdesc)
     181        uint32 security_info, struct security_descriptor **ppdesc)
    181182{
    182183        SMB4ACL_T *pacl = NULL;
     
    371372}
    372373
    373 static NTSTATUS aixjfs2_set_nt_acl_common(files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
     374static NTSTATUS aixjfs2_set_nt_acl_common(files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
    374375{
    375376        acl_type_t      acl_type_info;
     
    395396}
    396397
    397 NTSTATUS aixjfs2_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
     398NTSTATUS aixjfs2_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
    398399{
    399400        return aixjfs2_set_nt_acl_common(fsp, security_info_sent, psd);
  • trunk/server/source3/modules/vfs_aixacl_util.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
    2123
    2224SMB_ACL_T aixacl_to_smbacl(struct acl *file_acl)
  • trunk/server/source3/modules/vfs_audit.c

    r414 r745  
    2323
    2424#include "includes.h"
     25#include "system/filesys.h"
     26#include "system/syslog.h"
     27#include "smbd/smbd.h"
    2528
    2629#undef DBGC_CLASS
     
    268271        .mkdir = audit_mkdir,
    269272        .rmdir = audit_rmdir,
    270         .open = audit_open,
     273        .open_fn = audit_open,
    271274        .close_fn = audit_close,
    272275        .rename = audit_rename,
  • trunk/server/source3/modules/vfs_cacheprime.c

    r414 r745  
    1717
    1818#include "includes.h"
     19#include "smbd/smbd.h"
    1920
    2021/* Cache priming module.
  • trunk/server/source3/modules/vfs_cap.c

    r414 r745  
    2424
    2525#include "includes.h"
     26#include "smbd/smbd.h"
    2627
    2728/* cap functions */
     
    385386}
    386387
    387 static char *cap_realpath(vfs_handle_struct *handle, const char *path, char *resolved_path)
     388static char *cap_realpath(vfs_handle_struct *handle, const char *path)
    388389{
    389390        /* monyo need capencode'ed and capdecode'ed? */
     
    394395                return NULL;
    395396        }
    396         return SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
     397        return SMB_VFS_NEXT_REALPATH(handle, cappath);
    397398}
    398399
     
    576577        .mkdir = cap_mkdir,
    577578        .rmdir = cap_rmdir,
    578         .open = cap_open,
     579        .open_fn = cap_open,
    579580        .rename = cap_rename,
    580581        .stat = cap_stat,
  • trunk/server/source3/modules/vfs_catia.c

    r414 r745  
    2828
    2929#include "includes.h"
     30#include "smbd/smbd.h"
    3031
    3132#define GLOBAL_SNUM     0xFFFFFFF
     
    236237
    237238        if ((push_ucs2_talloc(ctx, &tmpbuf, name_in,
    238                               &converted_size)) == -1) {
     239                              &converted_size)) == false) {
    239240                return map_nt_error_from_unix(errno);
    240241        }
     
    253254
    254255        if ((pull_ucs2_talloc(ctx, mapped_name, tmpbuf,
    255                               &converted_size)) == -1) {
     256                              &converted_size)) == false) {
    256257                TALLOC_FREE(tmpbuf);
    257258                return map_nt_error_from_unix(errno);
     
    635636
    636637static char *
    637 catia_realpath(vfs_handle_struct *handle, const char *path,
    638                char *resolved_path)
     638catia_realpath(vfs_handle_struct *handle, const char *path)
    639639{
    640640        char *mapped_name = NULL;
     
    649649        }
    650650
    651         ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name, resolved_path);
     651        ret = SMB_VFS_NEXT_REALPATH(handle, mapped_name);
    652652        TALLOC_FREE(mapped_name);
    653653
     
    991991        .rmdir = catia_rmdir,
    992992        .opendir = catia_opendir,
    993         .open = catia_open,
     993        .open_fn = catia_open,
    994994        .rename = catia_rename,
    995995        .stat = catia_stat,
  • trunk/server/source3/modules/vfs_commit.c

    r414 r745  
    1818
    1919#include "includes.h"
     20#include "system/filesys.h"
     21#include "smbd/smbd.h"
    2022
    2123/* Commit data module.
     
    8991        result = fsync(fd);
    9092#else
     93        DEBUG(0, ("%s: WARNING: no commit support on this platform\n",
     94                MODULE));
    9195        result = 0
    9296#endif
     
    302306
    303307static struct vfs_fn_pointers vfs_commit_fns = {
    304         .open = commit_open,
     308        .open_fn = commit_open,
    305309        .close_fn = commit_close,
    306310        .write = commit_write,
  • trunk/server/source3/modules/vfs_default.c

    r596 r745  
    2020
    2121#include "includes.h"
     22#include "system/time.h"
     23#include "system/filesys.h"
     24#include "smbd/smbd.h"
     25#include "ntioctl.h"
     26#include "smbprofile.h"
    2227
    2328#undef DBGC_CLASS
     
    8085}
    8186
    82 static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, bool labels)
     87static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle,
     88                                        struct files_struct *fsp,
     89                                        struct shadow_copy_data *shadow_copy_data,
     90                                        bool labels)
    8391{
    8492        errno = ENOSYS;
     
    168176}
    169177
     178static SMB_STRUCT_DIR *vfswrap_fdopendir(vfs_handle_struct *handle,
     179                        files_struct *fsp,
     180                        const char *mask,
     181                        uint32 attr)
     182{
     183        SMB_STRUCT_DIR *result;
     184
     185        START_PROFILE(syscall_fdopendir);
     186        result = sys_fdopendir(fsp->fh->fd);
     187        END_PROFILE(syscall_fdopendir);
     188        return result;
     189}
     190
     191
    170192static SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle,
    171193                                          SMB_STRUCT_DIR *dirp,
     
    299321                                    uint32_t oplock_request,
    300322                                    uint64_t allocation_size,
     323                                    uint32_t private_flags,
    301324                                    struct security_descriptor *sd,
    302325                                    struct ea_list *ea_list,
     
    308331                                   create_disposition, create_options,
    309332                                   file_attributes, oplock_request,
    310                                    allocation_size, sd, ea_list, result,
     333                                   allocation_size, private_flags,
     334                                   sd, ea_list, result,
    311335                                   pinfo);
    312336}
     
    476500}
    477501
    478 /*********************************************************
    479  For rename across filesystems Patch from Warren Birnbaum
    480  <warrenb@hpcvscdp.cv.hp.com>
    481 **********************************************************/
    482 
    483 static int copy_reg(const char *source, const char *dest)
    484 {
    485         SMB_STRUCT_STAT source_stats;
    486         int saved_errno;
    487         int ifd = -1;
    488         int ofd = -1;
    489 
    490         if (sys_lstat(source, &source_stats, false) == -1)
    491                 return -1;
    492 
    493         if (!S_ISREG (source_stats.st_ex_mode))
    494                 return -1;
    495 
    496         if((ifd = sys_open (source, O_RDONLY, 0)) < 0)
    497                 return -1;
    498 
    499         if (unlink (dest) && errno != ENOENT)
    500                 return -1;
    501 
    502 #ifdef O_NOFOLLOW
    503         if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 )
    504 #else
    505         if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 )
    506 #endif
    507                 goto err;
    508 
    509         if (transfer_file(ifd, ofd, (size_t)-1) == -1)
    510                 goto err;
    511 
    512         /*
    513          * Try to preserve ownership.  For non-root it might fail, but that's ok.
    514          * But root probably wants to know, e.g. if NFS disallows it.
    515          */
    516 
    517 #ifdef HAVE_FCHOWN
    518         if ((fchown(ofd, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM))
    519 #else
    520         if ((chown(dest, source_stats.st_ex_uid, source_stats.st_ex_gid) == -1) && (errno != EPERM))
    521 #endif
    522                 goto err;
    523 
    524         /*
    525          * fchown turns off set[ug]id bits for non-root,
    526          * so do the chmod last.
    527          */
    528 
    529 #if defined(HAVE_FCHMOD)
    530         if (fchmod (ofd, source_stats.st_ex_mode & 07777))
    531 #else
    532         if (chmod (dest, source_stats.st_ex_mode & 07777))
    533 #endif
    534                 goto err;
    535 
    536         if (close (ifd) == -1)
    537                 goto err;
    538 
    539         if (close (ofd) == -1)
    540                 return -1;
    541 
    542         /* Try to copy the old file's modtime and access time.  */
    543 #if defined(HAVE_UTIMENSAT)
    544         {
    545                 struct timespec ts[2];
    546 
    547                 ts[0] = source_stats.st_ex_atime;
    548                 ts[1] = source_stats.st_ex_mtime;
    549                 utimensat(AT_FDCWD, dest, ts, AT_SYMLINK_NOFOLLOW);
    550         }
    551 #elif defined(HAVE_UTIMES)
    552         {
    553                 struct timeval tv[2];
    554 
    555                 tv[0] = convert_timespec_to_timeval(source_stats.st_ex_atime);
    556                 tv[1] = convert_timespec_to_timeval(source_stats.st_ex_mtime);
    557 #ifdef HAVE_LUTIMES
    558                 lutimes(dest, tv);
    559 #else
    560                 utimes(dest, tv);
    561 #endif
    562         }
    563 #elif defined(HAVE_UTIME)
    564         {
    565                 struct utimbuf tv;
    566 
    567                 tv.actime = convert_timespec_to_time_t(source_stats.st_ex_atime);
    568                 tv.modtime = convert_timespec_to_time_t(source_stats.st_ex_mtime);
    569                 utime(dest, &tv);
    570         }
    571 #endif
    572 
    573         if (unlink (source) == -1)
    574                 return -1;
    575 
    576         return 0;
    577 
    578   err:
    579 
    580         saved_errno = errno;
    581         if (ifd != -1)
    582                 close(ifd);
    583         if (ofd != -1)
    584                 close(ofd);
    585         errno = saved_errno;
    586         return -1;
    587 }
    588 
    589502static int vfswrap_rename(vfs_handle_struct *handle,
    590503                          const struct smb_filename *smb_fname_src,
     
    601514
    602515        result = rename(smb_fname_src->base_name, smb_fname_dst->base_name);
    603         if ((result == -1) && (errno == EXDEV)) {
    604                 /* Rename across filesystems needed. */
    605                 result = copy_reg(smb_fname_src->base_name,
    606                                   smb_fname_dst->base_name);
    607         }
    608516
    609517 out:
     
    869777        }
    870778
    871         if (null_timespec(ft->atime)) {
    872                 ft->atime= smb_fname->st.st_ex_atime;
    873         }
    874 
    875         if (null_timespec(ft->mtime)) {
    876                 ft->mtime = smb_fname->st.st_ex_mtime;
    877         }
    878 
    879         if (!null_timespec(ft->create_time)) {
    880                 set_create_timespec_ea(handle->conn,
    881                                 smb_fname,
    882                                 ft->create_time);
    883         }
    884 
    885         if ((timespec_compare(&ft->atime,
    886                                 &smb_fname->st.st_ex_atime) == 0) &&
    887                         (timespec_compare(&ft->mtime,
    888                                 &smb_fname->st.st_ex_mtime) == 0)) {
    889                 return 0;
     779        if (ft != NULL) {
     780                if (null_timespec(ft->atime)) {
     781                        ft->atime= smb_fname->st.st_ex_atime;
     782                }
     783
     784                if (null_timespec(ft->mtime)) {
     785                        ft->mtime = smb_fname->st.st_ex_mtime;
     786                }
     787
     788                if (!null_timespec(ft->create_time)) {
     789                        set_create_timespec_ea(handle->conn,
     790                                               smb_fname,
     791                                               ft->create_time);
     792                }
     793
     794                if ((timespec_compare(&ft->atime,
     795                                      &smb_fname->st.st_ex_atime) == 0) &&
     796                    (timespec_compare(&ft->mtime,
     797                                      &smb_fname->st.st_ex_mtime) == 0)) {
     798                        return 0;
     799                }
    890800        }
    891801
     
    944854static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len)
    945855{
    946         SMB_STRUCT_STAT st;
    947         SMB_OFF_T currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
    948         unsigned char zero_space[4096];
    949856        SMB_OFF_T space_to_write;
    950857        uint64_t space_avail;
    951858        uint64_t bsize,dfree,dsize;
    952859        int ret;
    953 
    954         if (currpos == -1)
     860        NTSTATUS status;
     861        SMB_STRUCT_STAT *pst;
     862
     863        status = vfs_stat_fsp(fsp);
     864        if (!NT_STATUS_IS_OK(status)) {
    955865                return -1;
    956 
    957         if (SMB_VFS_FSTAT(fsp, &st) == -1)
    958                 return -1;
     866        }
     867        pst = &fsp->fsp_name->st;
    959868
    960869#ifdef S_ISFIFO
    961         if (S_ISFIFO(st.st_ex_mode))
     870        if (S_ISFIFO(pst->st_ex_mode))
    962871                return 0;
    963872#endif
    964873
    965         if (st.st_ex_size == len)
     874        if (pst->st_ex_size == len)
    966875                return 0;
    967876
    968877        /* Shrink - just ftruncate. */
    969         if (st.st_ex_size > len)
     878        if (pst->st_ex_size > len)
    970879                return sys_ftruncate(fsp->fh->fd, len);
    971880
    972         space_to_write = len - st.st_ex_size;
    973 
    974         /* for allocation try posix_fallocate first. This can fail on some
     881        space_to_write = len - pst->st_ex_size;
     882
     883        /* for allocation try fallocate first. This can fail on some
    975884           platforms e.g. when the filesystem doesn't support it and no
    976885           emulation is being done by the libc (like on AIX with JFS1). In that
    977            case we do our own emulation. posix_fallocate implementations can
     886           case we do our own emulation. fallocate implementations can
    978887           return ENOTSUP or EINVAL in cases like that. */
    979         ret = sys_posix_fallocate(fsp->fh->fd, st.st_ex_size, space_to_write);
     888        ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_EXTEND_SIZE,
     889                                pst->st_ex_size, space_to_write);
    980890        if (ret == ENOSPC) {
    981891                errno = ENOSPC;
     
    985895                return 0;
    986896        }
    987         DEBUG(10,("strict_allocate_ftruncate: sys_posix_fallocate failed with "
     897        DEBUG(10,("strict_allocate_ftruncate: SMB_VFS_FALLOCATE failed with "
    988898                "error %d. Falling back to slow manual allocation\n", ret));
    989899
     
    1000910
    1001911        /* Write out the real space on disk. */
    1002         if (SMB_VFS_LSEEK(fsp, st.st_ex_size, SEEK_SET) != st.st_ex_size)
    1003                 return -1;
    1004 
    1005         memset(zero_space, '\0', sizeof(zero_space));
    1006         while ( space_to_write > 0) {
    1007                 SMB_OFF_T retlen;
    1008                 SMB_OFF_T current_len_to_write = MIN(sizeof(zero_space),space_to_write);
    1009 
    1010                 retlen = SMB_VFS_WRITE(fsp,(char *)zero_space,current_len_to_write);
    1011                 if (retlen <= 0)
    1012                         return -1;
    1013 
    1014                 space_to_write -= retlen;
    1015         }
    1016 
    1017         /* Seek to where we were */
    1018         if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
    1019                 return -1;
     912        ret = vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
     913        if (ret != 0) {
     914                errno = ret;
     915                ret = -1;
     916        }
    1020917
    1021918        return 0;
     
    1025922{
    1026923        int result = -1;
    1027         SMB_STRUCT_STAT st;
     924        SMB_STRUCT_STAT *pst;
     925        NTSTATUS status;
    1028926        char c = 0;
    1029         SMB_OFF_T currpos;
    1030927
    1031928        START_PROFILE(syscall_ftruncate);
    1032929
    1033         if (lp_strict_allocate(SNUM(fsp->conn))) {
     930        if (lp_strict_allocate(SNUM(fsp->conn)) && !fsp->is_sparse) {
    1034931                result = strict_allocate_ftruncate(handle, fsp, len);
    1035932                END_PROFILE(syscall_ftruncate);
     
    1050947           extend a file with ftruncate. Provide alternate implementation
    1051948           for this */
    1052         currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
    1053         if (currpos == -1) {
    1054                 goto done;
    1055         }
    1056949
    1057950        /* Do an fstat to see if the file is longer than the requested
     
    1059952           succeeded or shorter, in which case seek to len - 1 and
    1060953           write 1 byte of zero */
    1061         if (SMB_VFS_FSTAT(fsp, &st) == -1) {
     954        status = vfs_stat_fsp(fsp);
     955        if (!NT_STATUS_IS_OK(status)) {
    1062956                goto done;
    1063957        }
     958        pst = &fsp->fsp_name->st;
    1064959
    1065960#ifdef S_ISFIFO
    1066         if (S_ISFIFO(st.st_ex_mode)) {
     961        if (S_ISFIFO(pst->st_ex_mode)) {
    1067962                result = 0;
    1068963                goto done;
     
    1070965#endif
    1071966
    1072         if (st.st_ex_size == len) {
     967        if (pst->st_ex_size == len) {
    1073968                result = 0;
    1074969                goto done;
    1075970        }
    1076971
    1077         if (st.st_ex_size > len) {
     972        if (pst->st_ex_size > len) {
    1078973                /* the sys_ftruncate should have worked */
    1079974                goto done;
    1080975        }
    1081976
    1082         if (SMB_VFS_LSEEK(fsp, len-1, SEEK_SET) != len -1)
     977        if (SMB_VFS_PWRITE(fsp, &c, 1, len-1)!=1) {
    1083978                goto done;
    1084 
    1085         if (SMB_VFS_WRITE(fsp, &c, 1)!=1)
    1086                 goto done;
    1087 
    1088         /* Seek to where we were */
    1089         if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
    1090                 goto done;
     979        }
     980
    1091981        result = 0;
    1092982
     
    1094984
    1095985        END_PROFILE(syscall_ftruncate);
     986        return result;
     987}
     988
     989static int vfswrap_fallocate(vfs_handle_struct *handle,
     990                        files_struct *fsp,
     991                        enum vfs_fallocate_mode mode,
     992                        SMB_OFF_T offset,
     993                        SMB_OFF_T len)
     994{
     995        int result;
     996
     997        START_PROFILE(syscall_fallocate);
     998        if (mode == VFS_FALLOCATE_EXTEND_SIZE) {
     999                result = sys_posix_fallocate(fsp->fh->fd, offset, len);
     1000        } else if (mode == VFS_FALLOCATE_KEEP_SIZE) {
     1001                result = sys_fallocate(fsp->fh->fd, mode, offset, len);
     1002        } else {
     1003                errno = EINVAL;
     1004                result = -1;
     1005        }
     1006        END_PROFILE(syscall_fallocate);
    10961007        return result;
    10971008}
     
    11871098}
    11881099
    1189 static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path, char *resolved_path)
     1100static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path)
    11901101{
    11911102        char *result;
    11921103
    11931104        START_PROFILE(syscall_realpath);
    1194         result = realpath(path, resolved_path);
     1105#ifdef REALPATH_TAKES_NULL
     1106        result = realpath(path, NULL);
     1107#else
     1108        result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
     1109        if (result) {
     1110                char *resolved_path = realpath(path, result);
     1111                if (!resolved_path) {
     1112                        SAFE_FREE(result);
     1113                } else {
     1114                        /* SMB_ASSERT(result == resolved_path) ? */
     1115                        result = resolved_path;
     1116                }
     1117        }
     1118#endif
    11951119        END_PROFILE(syscall_realpath);
    11961120        return result;
     
    13941318static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
    13951319                                    files_struct *fsp,
    1396                                     uint32 security_info, SEC_DESC **ppdesc)
     1320                                    uint32 security_info,
     1321                                    struct security_descriptor **ppdesc)
    13971322{
    13981323        NTSTATUS result;
     
    14061331static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
    14071332                                   const char *name,
    1408                                    uint32 security_info, SEC_DESC **ppdesc)
     1333                                   uint32 security_info,
     1334                                   struct security_descriptor **ppdesc)
    14091335{
    14101336        NTSTATUS result;
     
    14161342}
    14171343
    1418 static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
     1344static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
    14191345{
    14201346        NTSTATUS result;
     
    15901516}
    15911517
    1592 ssize_t vfswrap_llistxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
     1518static ssize_t vfswrap_llistxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
    15931519{
    15941520        return sys_llistxattr(path, list, size);
    15951521}
    15961522
    1597 ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
     1523static ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
    15981524{
    15991525        return sys_flistxattr(fsp->fh->fd, list, size);
     
    16901616}
    16911617
    1692 static bool vfswrap_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
    1693 {
    1694         if (ISDOT(path) || ISDOTDOT(path)) {
     1618static bool vfswrap_is_offline(struct vfs_handle_struct *handle,
     1619                               const struct smb_filename *fname,
     1620                               SMB_STRUCT_STAT *sbuf)
     1621{
     1622        NTSTATUS status;
     1623        char *path;
     1624
     1625        if (ISDOT(fname->base_name) || ISDOTDOT(fname->base_name)) {
    16951626                return false;
    16961627        }
     
    17031634        }
    17041635
     1636        status = get_full_smb_filename(talloc_tos(), fname, &path);
     1637        if (!NT_STATUS_IS_OK(status)) {
     1638                errno = map_errno_from_nt_status(status);
     1639                return false;
     1640        }
     1641
    17051642        return (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
    17061643}
    17071644
    1708 static int vfswrap_set_offline(struct vfs_handle_struct *handle, const char *path)
     1645static int vfswrap_set_offline(struct vfs_handle_struct *handle,
     1646                               const struct smb_filename *fname)
    17091647{
    17101648        /* We don't know how to set offline bit by default, needs to be overriden in the vfs modules */
     
    17301668
    17311669        .opendir = vfswrap_opendir,
     1670        .fdopendir = vfswrap_fdopendir,
    17321671        .readdir = vfswrap_readdir,
    17331672        .seekdir = vfswrap_seekdir,
     
    17411680        /* File operations */
    17421681
    1743         .open = vfswrap_open,
     1682        .open_fn = vfswrap_open,
    17441683        .create_file = vfswrap_create_file,
    17451684        .close_fn = vfswrap_close,
     
    17671706        .ntimes = vfswrap_ntimes,
    17681707        .ftruncate = vfswrap_ftruncate,
     1708        .fallocate = vfswrap_fallocate,
    17691709        .lock = vfswrap_lock,
    17701710        .kernel_flock = vfswrap_kernel_flock,
  • trunk/server/source3/modules/vfs_default_quota.c

    r414 r745  
    6969
    7070#include "includes.h"
     71#include "smbd/smbd.h"
    7172
    7273#undef DBGC_CLASS
  • trunk/server/source3/modules/vfs_dirsort.c

    r414 r745  
    2020
    2121#include "includes.h"
    22 
    23 static int compare_dirent (const void *a, const void *b) {
    24         const SMB_STRUCT_DIRENT *da = (const SMB_STRUCT_DIRENT *) a;
    25         const SMB_STRUCT_DIRENT *db = (const SMB_STRUCT_DIRENT *) b;
     22#include "smbd/smbd.h"
     23#include "system/filesys.h"
     24
     25static int compare_dirent (const SMB_STRUCT_DIRENT *da, const SMB_STRUCT_DIRENT *db)
     26{
    2627        return StrCaseCmp(da->d_name, db->d_name);
    2728}
     
    4546}
    4647
    47 static void open_and_sort_dir (vfs_handle_struct *handle)
     48static bool open_and_sort_dir (vfs_handle_struct *handle)
    4849{
    4950        SMB_STRUCT_DIRENT *dp;
     
    5253        struct dirsort_privates *data = NULL;
    5354
    54         SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates, return);
     55        SMB_VFS_HANDLE_GET_DATA(handle, data, struct dirsort_privates,
     56                                return false);
    5557
    5658        data->number_of_entries = 0;
     
    7375        data->directory_list = (SMB_STRUCT_DIRENT *)SMB_MALLOC(
    7476                data->number_of_entries * sizeof(SMB_STRUCT_DIRENT));
     77        if (!data->directory_list) {
     78                return false;
     79        }
    7580        current_pos = data->pos;
    7681        data->pos = 0;
     
    8287        /* Sort the directory entries by name */
    8388        data->pos = current_pos;
    84         qsort(data->directory_list, data->number_of_entries,
    85               sizeof(SMB_STRUCT_DIRENT), compare_dirent);
     89        TYPESAFE_QSORT(data->directory_list, data->number_of_entries, compare_dirent);
     90        return true;
    8691}
    8792
     
    96101                sizeof(struct dirsort_privates));
    97102
     103        if (!data) {
     104                return NULL;
     105        }
     106
    98107        data->directory_list = NULL;
    99108        data->pos = 0;
     
    108117                                struct dirsort_privates, return NULL);
    109118
    110         open_and_sort_dir(handle);
     119        if (!open_and_sort_dir(handle)) {
     120                SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
     121                return NULL;
     122        }
     123
     124        return data->source_directory;
     125}
     126
     127static SMB_STRUCT_DIR *dirsort_fdopendir(vfs_handle_struct *handle,
     128                                        files_struct *fsp,
     129                                        const char *mask,
     130                                        uint32 attr)
     131{
     132        struct dirsort_privates *data = NULL;
     133
     134        /* set up our private data about this directory */
     135        data = (struct dirsort_privates *)SMB_MALLOC(
     136                sizeof(struct dirsort_privates));
     137
     138        if (!data) {
     139                return NULL;
     140        }
     141
     142        data->directory_list = NULL;
     143        data->pos = 0;
     144
     145        /* Open the underlying directory and count the number of entries */
     146        data->source_directory = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask,
     147                                                      attr);
     148
     149        if (data->source_directory == NULL) {
     150                SAFE_FREE(data);
     151                return NULL;
     152        }
     153
     154        data->fd = dirfd(data->source_directory);
     155
     156        SMB_VFS_HANDLE_SET_DATA(handle, data, free_dirsort_privates,
     157                                struct dirsort_privates, return NULL);
     158
     159        if (!open_and_sort_dir(handle)) {
     160                SMB_VFS_NEXT_CLOSEDIR(handle,data->source_directory);
     161                /* fd is now closed. */
     162                fsp->fh->fd = -1;
     163                return NULL;
     164        }
    111165
    112166        return data->source_directory;
     
    170224static struct vfs_fn_pointers vfs_dirsort_fns = {
    171225        .opendir = dirsort_opendir,
     226        .fdopendir = dirsort_fdopendir,
    172227        .readdir = dirsort_readdir,
    173228        .seekdir = dirsort_seekdir,
  • trunk/server/source3/modules/vfs_expand_msdfs.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
     23#include "../librpc/gen_ndr/ndr_netlogon.h"
     24#include "smbd/globals.h"
     25#include "auth.h"
    2126
    2227#undef DBGC_CLASS
     
    3641***********************************************************/
    3742
    38 static char *read_target_host(TALLOC_CTX *ctx, const char *mapfile)
     43static char *read_target_host(TALLOC_CTX *ctx, const char *mapfile,
     44                              const char *clientaddr)
    3945{
    4046        XFILE *f;
     
    5460
    5561        while (x_fgets(buf, sizeof(buf), f) != NULL) {
    56                 char addr[INET6_ADDRSTRLEN];
    5762
    5863                if ((strlen(buf) > 0) && (buf[strlen(buf)-1] == '\n'))
     
    7075                *space = '\0';
    7176
    72                 if (strncmp(client_addr(get_client_fd(),addr,sizeof(addr)),
    73                                 buf, strlen(buf)) == 0) {
     77                if (strncmp(clientaddr, buf, strlen(buf)) == 0) {
    7478                        found = true;
    7579                        break;
     
    136140        DEBUG(10, ("Expanding from table [%s]\n", mapfilename));
    137141
    138         if ((targethost = read_target_host(ctx, mapfilename)) == NULL) {
     142        targethost = read_target_host(
     143                ctx, conn->sconn->client_id.addr, mapfilename);
     144        if (targethost == NULL) {
    139145                DEBUG(1, ("Could not expand target host from file %s\n",
    140146                          mapfilename));
     
    144150        targethost = talloc_sub_advanced(ctx,
    145151                                lp_servicename(SNUM(conn)),
    146                                 conn->server_info->unix_name,
     152                                conn->session_info->unix_name,
    147153                                conn->connectpath,
    148                                 conn->server_info->utok.gid,
    149                                 conn->server_info->sanitized_username,
    150                                 pdb_get_domain(conn->server_info->sam_account),
     154                                conn->session_info->utok.gid,
     155                                conn->session_info->sanitized_username,
     156                                conn->session_info->info3->base.domain.string,
    151157                                targethost);
    152158
  • trunk/server/source3/modules/vfs_extd_audit.c

    r414 r745  
    2424
    2525#include "includes.h"
     26#include "system/filesys.h"
     27#include "system/syslog.h"
     28#include "smbd/smbd.h"
    2629
    2730static int vfs_extd_audit_debug_level = DBGC_VFS;
     
    345348        .mkdir = audit_mkdir,
    346349        .rmdir = audit_rmdir,
    347         .open = audit_open,
     350        .open_fn = audit_open,
    348351        .close_fn = audit_close,
    349352        .rename = audit_rename,
  • trunk/server/source3/modules/vfs_fake_perms.c

    r414 r745  
    2323
    2424#include "includes.h"
     25#include "smbd/smbd.h"
     26#include "system/filesys.h"
     27#include "auth.h"
    2528
    2629#undef DBGC_CLASS
     
    3942                        smb_fname->st.st_ex_mode = S_IRWXU;
    4043                }
    41                 smb_fname->st.st_ex_uid = handle->conn->server_info->utok.uid;
    42                 smb_fname->st.st_ex_gid = handle->conn->server_info->utok.gid;
     44                smb_fname->st.st_ex_uid = handle->conn->session_info->utok.uid;
     45                smb_fname->st.st_ex_gid = handle->conn->session_info->utok.gid;
    4346        }
    4447
     
    5760                        sbuf->st_ex_mode = S_IRWXU;
    5861                }
    59                 sbuf->st_ex_uid = handle->conn->server_info->utok.uid;
    60                 sbuf->st_ex_gid = handle->conn->server_info->utok.gid;
     62                sbuf->st_ex_uid = handle->conn->session_info->utok.uid;
     63                sbuf->st_ex_gid = handle->conn->session_info->utok.gid;
    6164        }
    6265        return ret;
  • trunk/server/source3/modules/vfs_fileid.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include "smbd/smbd.h"
     24#include "system/filesys.h"
    2325
    2426static int vfs_fileid_debug_level = DBGC_VFS;
  • trunk/server/source3/modules/vfs_full_audit.c

    r480 r745  
    5959
    6060#include "includes.h"
     61#include "system/filesys.h"
     62#include "system/syslog.h"
     63#include "smbd/smbd.h"
     64#include "../librpc/gen_ndr/ndr_netlogon.h"
     65#include "auth.h"
     66#include "ntioctl.h"
    6167
    6268static int vfs_full_audit_debug_level = DBGC_VFS;
     
    8793
    8894        SMB_VFS_OP_OPENDIR,
     95        SMB_VFS_OP_FDOPENDIR,
    8996        SMB_VFS_OP_READDIR,
    9097        SMB_VFS_OP_SEEKDIR,
     
    124131        SMB_VFS_OP_NTIMES,
    125132        SMB_VFS_OP_FTRUNCATE,
     133        SMB_VFS_OP_FALLOCATE,
    126134        SMB_VFS_OP_LOCK,
    127135        SMB_VFS_OP_KERNEL_FLOCK,
     
    228236        { SMB_VFS_OP_FS_CAPABILITIES,   "fs_capabilities" },
    229237        { SMB_VFS_OP_OPENDIR,   "opendir" },
     238        { SMB_VFS_OP_FDOPENDIR, "fdopendir" },
    230239        { SMB_VFS_OP_READDIR,   "readdir" },
    231240        { SMB_VFS_OP_SEEKDIR,   "seekdir" },
     
    262271        { SMB_VFS_OP_NTIMES,    "ntimes" },
    263272        { SMB_VFS_OP_FTRUNCATE, "ftruncate" },
     273        { SMB_VFS_OP_FALLOCATE,"fallocate" },
    264274        { SMB_VFS_OP_LOCK,      "lock" },
    265275        { SMB_VFS_OP_KERNEL_FLOCK,      "kernel_flock" },
     
    330340        { SMB_VFS_OP_AIO_SUSPEND,"aio_suspend" },
    331341        { SMB_VFS_OP_AIO_FORCE, "aio_force" },
    332         { SMB_VFS_OP_IS_OFFLINE, "aio_is_offline" },
    333         { SMB_VFS_OP_SET_OFFLINE, "aio_set_offline" },
     342        { SMB_VFS_OP_IS_OFFLINE, "is_offline" },
     343        { SMB_VFS_OP_SET_OFFLINE, "set_offline" },
    334344        { SMB_VFS_OP_LAST, NULL }
    335345};
     
    393403        result = talloc_sub_advanced(ctx,
    394404                        lp_servicename(SNUM(conn)),
    395                         conn->server_info->unix_name,
     405                        conn->session_info->unix_name,
    396406                        conn->connectpath,
    397                         conn->server_info->utok.gid,
    398                         conn->server_info->sanitized_username,
    399                         pdb_get_domain(conn->server_info->sam_account),
     407                        conn->session_info->utok.gid,
     408                        conn->session_info->sanitized_username,
     409                        conn->session_info->info3->base.domain.string,
    400410                        prefix);
    401411        TALLOC_FREE(prefix);
     
    432442}
    433443
    434 static void init_bitmap(struct bitmap **bm, const char **ops)
    435 {
    436         bool log_all = False;
    437 
    438         if (*bm != NULL)
    439                 return;
    440 
    441         *bm = bitmap_allocate(SMB_VFS_OP_LAST);
    442 
    443         if (*bm == NULL) {
     444static struct bitmap *init_bitmap(TALLOC_CTX *mem_ctx, const char **ops)
     445{
     446        struct bitmap *bm;
     447
     448        if (ops == NULL) {
     449                return NULL;
     450        }
     451
     452        bm = bitmap_talloc(mem_ctx, SMB_VFS_OP_LAST);
     453        if (bm == NULL) {
    444454                DEBUG(0, ("Could not alloc bitmap -- "
    445455                          "defaulting to logging everything\n"));
    446                 return;
     456                return NULL;
    447457        }
    448458
    449         while (*ops != NULL) {
     459        for (; *ops != NULL; ops += 1) {
    450460                int i;
    451                 bool found = False;
     461                bool neg = false;
     462                const char *op;
    452463
    453464                if (strequal(*ops, "all")) {
    454                         log_all = True;
     465                        for (i=0; i<SMB_VFS_OP_LAST; i++) {
     466                                bitmap_set(bm, i);
     467                        }
     468                        continue;
     469                }
     470
     471                if (strequal(*ops, "none")) {
    455472                        break;
    456473                }
    457474
    458                 if (strequal(*ops, "none")) {
    459                         break;
     475                op = ops[0];
     476                if (op[0] == '!') {
     477                        neg = true;
     478                        op += 1;
    460479                }
    461480
     
    465484                                          "in sync with vfs.h\n");
    466485                        }
    467 
    468                         if (strequal(*ops, vfs_op_names[i].name)) {
    469                                 bitmap_set(*bm, i);
    470                                 found = True;
     486                        if (strequal(op, vfs_op_names[i].name)) {
     487                                if (neg) {
     488                                        bitmap_clear(bm, i);
     489                                } else {
     490                                        bitmap_set(bm, i);
     491                                }
     492                                break;
    471493                        }
    472494                }
    473                 if (!found) {
     495                if (i == SMB_VFS_OP_LAST) {
    474496                        DEBUG(0, ("Could not find opname %s, logging all\n",
    475497                                  *ops));
    476                         log_all = True;
    477                         break;
     498                        TALLOC_FREE(bm);
     499                        return NULL;
    478500                }
    479                 ops += 1;
    480501        }
    481 
    482         if (log_all) {
    483                 /* The query functions default to True */
    484                 bitmap_free(*bm);
    485                 *bm = NULL;
    486         }
     502        return bm;
    487503}
    488504
     
    580596}
    581597
    582 /* Free function for the private data. */
    583 
    584 static void free_private_data(void **p_data)
    585 {
    586         struct vfs_full_audit_private_data *pd = *(struct vfs_full_audit_private_data **)p_data;
    587 
    588         if (pd->success_ops) {
    589                 bitmap_free(pd->success_ops);
    590         }
    591         if (pd->failure_ops) {
    592                 bitmap_free(pd->failure_ops);
    593         }
    594         SAFE_FREE(pd);
    595         *p_data = NULL;
    596 }
    597 
    598598/* Implementation of vfs_ops.  Pass everything on to the default
    599599   operation but log event first. */
     
    604604        int result;
    605605        struct vfs_full_audit_private_data *pd = NULL;
    606         const char *none[] = { NULL };
    607         const char *all [] = { "all" };
    608606
    609607        result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
     
    612610        }
    613611
    614         pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
     612        pd = TALLOC_ZERO_P(handle, struct vfs_full_audit_private_data);
    615613        if (!pd) {
    616614                SMB_VFS_NEXT_DISCONNECT(handle);
    617615                return -1;
    618616        }
    619         ZERO_STRUCTP(pd);
    620617
    621618#ifndef WITH_SYSLOG
     
    623620#endif
    624621
    625         init_bitmap(&pd->success_ops,
    626                     lp_parm_string_list(SNUM(handle->conn), "full_audit", "success",
    627                                         none));
    628         init_bitmap(&pd->failure_ops,
    629                     lp_parm_string_list(SNUM(handle->conn), "full_audit", "failure",
    630                                         all));
     622        pd->success_ops = init_bitmap(
     623                pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
     624                                        "success", NULL));
     625        pd->failure_ops = init_bitmap(
     626                pd, lp_parm_string_list(SNUM(handle->conn), "full_audit",
     627                                        "failure", NULL));
    631628
    632629        /* Store the private data. */
    633         SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
     630        SMB_VFS_HANDLE_SET_DATA(handle, pd, NULL,
    634631                                struct vfs_full_audit_private_data, return -1);
    635632
     
    699696static int smb_full_audit_get_shadow_copy_data(struct vfs_handle_struct *handle,
    700697                                struct files_struct *fsp,
    701                                 SHADOW_COPY_DATA *shadow_copy_data, bool labels)
     698                                struct shadow_copy_data *shadow_copy_data,
     699                                bool labels)
    702700{
    703701        int result;
     
    742740
    743741        do_log(SMB_VFS_OP_OPENDIR, (result != NULL), handle, "%s", fname);
     742
     743        return result;
     744}
     745
     746static SMB_STRUCT_DIR *smb_full_audit_fdopendir(vfs_handle_struct *handle,
     747                          files_struct *fsp, const char *mask, uint32 attr)
     748{
     749        SMB_STRUCT_DIR *result;
     750
     751        result = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
     752
     753        do_log(SMB_VFS_OP_FDOPENDIR, (result != NULL), handle, "%s",
     754                        fsp_str_do_log(fsp));
    744755
    745756        return result;
     
    862873                                      uint32_t oplock_request,
    863874                                      uint64_t allocation_size,
     875                                      uint32_t private_flags,
    864876                                      struct security_descriptor *sd,
    865877                                      struct ea_list *ea_list,
     
    905917                oplock_request,                         /* oplock_request */
    906918                allocation_size,                        /* allocation_size */
     919                private_flags,
    907920                sd,                                     /* sd */
    908921                ea_list,                                /* ea_list */
     
    10991112        result = SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
    11001113
    1101         do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result >= 0), handle, "%d", result);
     1114        do_log(SMB_VFS_OP_GET_ALLOC_SIZE, (result != (uint64_t)-1), handle,
     1115                        "%llu", result);
    11021116
    11031117        return result;
     
    12321246}
    12331247
     1248static int smb_full_audit_fallocate(vfs_handle_struct *handle, files_struct *fsp,
     1249                           enum vfs_fallocate_mode mode,
     1250                           SMB_OFF_T offset,
     1251                           SMB_OFF_T len)
     1252{
     1253        int result;
     1254
     1255        result = SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
     1256
     1257        do_log(SMB_VFS_OP_FALLOCATE, (result >= 0), handle,
     1258               "%s", fsp_str_do_log(fsp));
     1259
     1260        return result;
     1261}
     1262
    12341263static bool smb_full_audit_lock(vfs_handle_struct *handle, files_struct *fsp,
    12351264                       int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
     
    13341363
    13351364static char *smb_full_audit_realpath(vfs_handle_struct *handle,
    1336                             const char *path, char *resolved_path)
     1365                            const char *path)
    13371366{
    13381367        char *result;
    13391368
    1340         result = SMB_VFS_NEXT_REALPATH(handle, path, resolved_path);
     1369        result = SMB_VFS_NEXT_REALPATH(handle, path);
    13411370
    13421371        do_log(SMB_VFS_OP_REALPATH, (result != NULL), handle, "%s", path);
     
    15361565static NTSTATUS smb_full_audit_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
    15371566                                uint32 security_info,
    1538                                 SEC_DESC **ppdesc)
     1567                                struct security_descriptor **ppdesc)
    15391568{
    15401569        NTSTATUS result;
     
    15511580                                          const char *name,
    15521581                                          uint32 security_info,
    1553                                           SEC_DESC **ppdesc)
     1582                                          struct security_descriptor **ppdesc)
    15541583{
    15551584        NTSTATUS result;
     
    15651594static NTSTATUS smb_full_audit_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
    15661595                              uint32 security_info_sent,
    1567                               const SEC_DESC *psd)
     1596                              const struct security_descriptor *psd)
    15681597{
    15691598        NTSTATUS result;
     
    21782207                "%s", fsp_str_do_log(fsp));
    21792208
     2209        return result;
     2210}
     2211
     2212static bool smb_full_audit_is_offline(struct vfs_handle_struct *handle,
     2213                                      const struct smb_filename *fname,
     2214                                      SMB_STRUCT_STAT *sbuf)
     2215{
     2216        bool result;
     2217
     2218        result = SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
     2219        do_log(SMB_VFS_OP_IS_OFFLINE, result, handle, "%s",
     2220               smb_fname_str_do_log(fname));
     2221        return result;
     2222}
     2223
     2224static int smb_full_audit_set_offline(struct vfs_handle_struct *handle,
     2225                                      const struct smb_filename *fname)
     2226{
     2227        int result;
     2228
     2229        result = SMB_VFS_NEXT_SET_OFFLINE(handle, fname);
     2230        do_log(SMB_VFS_OP_SET_OFFLINE, result >= 0, handle, "%s",
     2231               smb_fname_str_do_log(fname));
    21802232        return result;
    21812233}
     
    21942246        .fs_capabilities = smb_full_audit_fs_capabilities,
    21952247        .opendir = smb_full_audit_opendir,
     2248        .fdopendir = smb_full_audit_fdopendir,
    21962249        .readdir = smb_full_audit_readdir,
    21972250        .seekdir = smb_full_audit_seekdir,
     
    22022255        .closedir = smb_full_audit_closedir,
    22032256        .init_search_op = smb_full_audit_init_search_op,
    2204         .open = smb_full_audit_open,
     2257        .open_fn = smb_full_audit_open,
    22052258        .create_file = smb_full_audit_create_file,
    22062259        .close_fn = smb_full_audit_close,
     
    22282281        .ntimes = smb_full_audit_ntimes,
    22292282        .ftruncate = smb_full_audit_ftruncate,
     2283        .fallocate = smb_full_audit_fallocate,
    22302284        .lock = smb_full_audit_lock,
    22312285        .kernel_flock = smb_full_audit_kernel_flock,
     
    22962350        .aio_suspend = smb_full_audit_aio_suspend,
    22972351        .aio_force = smb_full_audit_aio_force,
     2352        .is_offline = smb_full_audit_is_offline,
     2353        .set_offline = smb_full_audit_set_offline,
    22982354};
    22992355
  • trunk/server/source3/modules/vfs_gpfs.c

    r599 r745  
    2323
    2424#include "includes.h"
     25#include "smbd/smbd.h"
     26#include "librpc/gen_ndr/ndr_xattr.h"
     27#include "include/smbprofile.h"
    2528
    2629#undef DBGC_CLASS
     
    3033#include "nfs4_acls.h"
    3134#include "vfs_gpfs.h"
     35#include "system/filesys.h"
    3236
    3337struct gpfs_config_data {
    3438        bool sharemodes;
    3539        bool leases;
     40        bool hsm;
    3641};
    3742
     
    117122        char real_pathname[PATH_MAX+1];
    118123        int buflen;
     124        bool mangled;
     125
     126        mangled = mangle_is_mangled(name, handle->conn->params);
     127        if (mangled) {
     128                return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
     129                                                      mem_ctx, found_name);
     130        }
    119131
    120132        full_path = talloc_asprintf(talloc_tos(), "%s/%s", path, name);
     
    323335static NTSTATUS gpfsacl_fget_nt_acl(vfs_handle_struct *handle,
    324336        files_struct *fsp, uint32 security_info,
    325         SEC_DESC **ppdesc)
     337        struct security_descriptor **ppdesc)
    326338{
    327339        SMB4ACL_T *pacl = NULL;
     
    345357static NTSTATUS gpfsacl_get_nt_acl(vfs_handle_struct *handle,
    346358        const char *name,
    347         uint32 security_info, SEC_DESC **ppdesc)
     359        uint32 security_info, struct security_descriptor **ppdesc)
    348360{
    349361        SMB4ACL_T *pacl = NULL;
     
    461473}
    462474
    463 static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
     475static NTSTATUS gpfsacl_set_nt_acl_internal(files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
    464476{
    465477        struct gpfs_acl *acl;
     
    489501}
    490502
    491 static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
     503static NTSTATUS gpfsacl_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
    492504{
    493505        return gpfsacl_set_nt_acl_internal(fsp, security_info_sent, psd);
     
    927939static int gpfs_set_xattr(struct vfs_handle_struct *handle,  const char *path,
    928940                           const char *name, const void *value, size_t size,  int flags){
     941        struct xattr_DOSATTRIB dosattrib;
     942        enum ndr_err_code ndr_err;
     943        DATA_BLOB blob;
    929944        const char *attrstr = value;
    930945        unsigned int dosmode=0;
     
    940955        }
    941956
    942         if (size < 2 || attrstr[0] != '0' || attrstr[1] != 'x' ||
    943                                 sscanf(attrstr, "%x", &dosmode) != 1) {
    944                         DEBUG(1,("gpfs_set_xattr: Trying to set badly formed DOSATTRIB on file %s - %s\n", path, attrstr));
    945                 return False;
    946         }
     957        blob.data = (uint8_t *)attrstr;
     958        blob.length = size;
     959
     960        ndr_err = ndr_pull_struct_blob(&blob, talloc_tos(), &dosattrib,
     961                        (ndr_pull_flags_fn_t)ndr_pull_xattr_DOSATTRIB);
     962
     963        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     964                DEBUG(1, ("gpfs_set_xattr: bad ndr decode "
     965                          "from EA on file %s: Error = %s\n",
     966                          path, ndr_errstr(ndr_err)));
     967                return false;
     968        }
     969
     970        if (dosattrib.version != 3) {
     971                DEBUG(1, ("gpfs_set_xattr: expected dosattrib version 3, got "
     972                          "%d\n", (int)dosattrib.version));
     973                return false;
     974        }
     975        if (!(dosattrib.info.info3.valid_flags & XATTR_DOSINFO_ATTRIB)) {
     976                DEBUG(10, ("gpfs_set_xattr: XATTR_DOSINFO_ATTRIB not "
     977                           "valid, ignoring\n"));
     978                return true;
     979        }
     980
     981        dosmode = dosattrib.info.info3.attrib;
    947982
    948983        attrs.winAttrs = 0;
    949         /*Just map RD_ONLY, ARCHIVE, SYSTEM and HIDDEN. Ignore the others*/
     984        /*Just map RD_ONLY, ARCHIVE, SYSTEM HIDDEN and SPARSE. Ignore the others*/
    950985        if (dosmode & FILE_ATTRIBUTE_ARCHIVE){
    951986                attrs.winAttrs |= GPFS_WINATTR_ARCHIVE;
     
    960995                        attrs.winAttrs |= GPFS_WINATTR_READONLY;
    961996        }
     997        if (dosmode & FILE_ATTRIBUTE_SPARSE) {
     998                attrs.winAttrs |= GPFS_WINATTR_SPARSE_FILE;
     999        }
    9621000
    9631001
     
    9841022        struct gpfs_winattr attrs;
    9851023        int ret = 0;
    986         ssize_t result;
    9871024
    9881025        DEBUG(10, ("gpfs_get_xattr: %s \n",path));
     
    10011038                }
    10021039
    1003                 DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: %d\n",ret));
     1040                DEBUG(1, ("gpfs_get_xattr: Get GPFS attributes failed: "
     1041                          "%d (%s)\n", ret, strerror(errno)));
    10041042                return -1;
    10051043        }
     
    10071045        DEBUG(10, ("gpfs_get_xattr:Got attributes: 0x%x\n",attrs.winAttrs));
    10081046
    1009         /*Just map RD_ONLY, ARCHIVE, SYSTEM and HIDDEN. Ignore the others*/
     1047        /*Just map RD_ONLY, ARCHIVE, SYSTEM, HIDDEN and SPARSE. Ignore the others*/
    10101048        if (attrs.winAttrs & GPFS_WINATTR_ARCHIVE){
    10111049                dosmode |= FILE_ATTRIBUTE_ARCHIVE;
     
    10201058                dosmode |= FILE_ATTRIBUTE_READONLY;
    10211059        }
    1022 
    1023         result = snprintf(attrstr, size, "0x%x",
    1024                           dosmode & SAMBA_ATTRIBUTES_MASK) + 1;
    1025 
     1060        if (attrs.winAttrs & GPFS_WINATTR_SPARSE_FILE) {
     1061                dosmode |= FILE_ATTRIBUTE_SPARSE;
     1062        }
     1063
     1064        snprintf(attrstr, size, "0x%2.2x",
     1065                 (unsigned int)(dosmode & SAMBA_ATTRIBUTES_MASK));
    10261066        DEBUG(10, ("gpfs_get_xattr: returning %s\n",attrstr));
    1027         return result;
     1067        return 4;
    10281068}
    10291069
     
    10501090                smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
    10511091                smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
     1092                smb_fname->st.vfs_private = attrs.winAttrs;
    10521093        }
    10531094        return 0;
     
    10971138                smb_fname->st.st_ex_btime.tv_sec = attrs.creationTime.tv_sec;
    10981139                smb_fname->st.st_ex_btime.tv_nsec = attrs.creationTime.tv_nsec;
     1140                smb_fname->st.vfs_private = attrs.winAttrs;
    10991141        }
    11001142        return 0;
     
    11421184}
    11431185
     1186static int vfs_gpfs_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
     1187                                SMB_OFF_T len)
     1188{
     1189        int result;
     1190
     1191        result = smbd_gpfs_ftruncate(fsp->fh->fd, len);
     1192        if ((result == -1) && (errno == ENOSYS)) {
     1193                return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
     1194        }
     1195        return result;
     1196}
     1197
     1198static bool vfs_gpfs_is_offline(struct vfs_handle_struct *handle,
     1199                                const struct smb_filename *fname,
     1200                                SMB_STRUCT_STAT *sbuf)
     1201{
     1202        struct gpfs_winattr attrs;
     1203        char *path = NULL;
     1204        NTSTATUS status;
     1205
     1206        status = get_full_smb_filename(talloc_tos(), fname, &path);
     1207        if (!NT_STATUS_IS_OK(status)) {
     1208                errno = map_errno_from_nt_status(status);
     1209                return -1;
     1210        }
     1211
     1212        if (VALID_STAT(*sbuf)) {
     1213                attrs.winAttrs = sbuf->vfs_private;
     1214        } else {
     1215                int ret;
     1216                ret = get_gpfs_winattrs(path, &attrs);
     1217
     1218                if (ret == -1) {
     1219                        TALLOC_FREE(path);
     1220                        return false;
     1221                }
     1222        }
     1223        if ((attrs.winAttrs & GPFS_WINATTR_OFFLINE) != 0) {
     1224                DEBUG(10, ("%s is offline\n", path));
     1225                TALLOC_FREE(path);
     1226                return true;
     1227        }
     1228        DEBUG(10, ("%s is online\n", path));
     1229        TALLOC_FREE(path);
     1230        return SMB_VFS_NEXT_IS_OFFLINE(handle, fname, sbuf);
     1231}
     1232
     1233static bool vfs_gpfs_aio_force(struct vfs_handle_struct *handle,
     1234                               struct files_struct *fsp)
     1235{
     1236        return vfs_gpfs_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
     1237}
     1238
     1239static ssize_t vfs_gpfs_sendfile(vfs_handle_struct *handle, int tofd,
     1240                                 files_struct *fsp, const DATA_BLOB *hdr,
     1241                                 SMB_OFF_T offset, size_t n)
     1242{
     1243        if ((fsp->fsp_name->st.vfs_private & GPFS_WINATTR_OFFLINE) != 0) {
     1244                errno = ENOSYS;
     1245                return -1;
     1246        }
     1247        return SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, hdr, offset, n);
     1248}
     1249
    11441250int vfs_gpfs_connect(struct vfs_handle_struct *handle, const char *service,
    11451251                        const char *user)
    11461252{
    11471253        struct gpfs_config_data *config;
     1254
     1255        smbd_gpfs_lib_init();
     1256
    11481257        int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
    11491258
     
    11641273                                        "leases", true);
    11651274
     1275        config->hsm = lp_parm_bool(SNUM(handle->conn), "gpfs",
     1276                                   "hsm", false);
     1277
    11661278        SMB_VFS_HANDLE_SET_DATA(handle, config,
    11671279                                NULL, struct gpfs_config_data,
     
    11711283}
    11721284
    1173 
    1174 static int vfs_gpfs_ftruncate(struct vfs_handle_struct *handle,
    1175                               struct files_struct *fsp,
    1176                               SMB_OFF_T len)
    1177 {
    1178        int result;
    1179 
    1180        result = smbd_gpfs_ftrunctate(fsp->fh->fd, len);
    1181        if ((result == -1) && (errno == ENOSYS)) {
    1182                return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, len);
    1183        }
    1184        return result;
    1185 }
     1285static uint32_t vfs_gpfs_capabilities(struct vfs_handle_struct *handle,
     1286                                      enum timestamp_set_resolution *p_ts_res)
     1287{
     1288        struct gpfs_config_data *config;
     1289        uint32_t next;
     1290
     1291        next = SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
     1292
     1293        SMB_VFS_HANDLE_GET_DATA(handle, config,
     1294                                struct gpfs_config_data,
     1295                                return next);
     1296
     1297        if (config->hsm) {
     1298                next |= FILE_SUPPORTS_REMOTE_STORAGE;
     1299        }
     1300        return next;
     1301}
     1302
     1303static int vfs_gpfs_open(struct vfs_handle_struct *handle,
     1304                         struct smb_filename *smb_fname, files_struct *fsp,
     1305                         int flags, mode_t mode)
     1306{
     1307        if (lp_parm_bool(fsp->conn->params->service, "gpfs", "syncio",
     1308                         false)) {
     1309                flags |= O_SYNC;
     1310        }
     1311        return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
     1312}
     1313
    11861314
    11871315static struct vfs_fn_pointers vfs_gpfs_fns = {
    11881316        .connect_fn = vfs_gpfs_connect,
     1317        .fs_capabilities = vfs_gpfs_capabilities,
    11891318        .kernel_flock = vfs_gpfs_kernel_flock,
    11901319        .linux_setlease = vfs_gpfs_setlease,
     
    12071336        .lstat = vfs_gpfs_lstat,
    12081337        .ntimes = vfs_gpfs_ntimes,
    1209         .ftruncate = vfs_gpfs_ftruncate,
     1338        .is_offline = vfs_gpfs_is_offline,
     1339        .aio_force = vfs_gpfs_aio_force,
     1340        .sendfile = vfs_gpfs_sendfile,
     1341        .open_fn = vfs_gpfs_open,
     1342        .ftruncate = vfs_gpfs_ftruncate
    12101343};
    12111344
  • trunk/server/source3/modules/vfs_gpfs.h

    r599 r745  
    3535int get_gpfs_winattrs(char * pathname,struct gpfs_winattr *attrs);
    3636int set_gpfs_winattrs(char * pathname,int flags,struct gpfs_winattr *attrs);
    37 int smbd_gpfs_ftrunctate(int fd, gpfs_off64_t length);
     37int smbd_gpfs_ftruncate(int fd, gpfs_off64_t length);
    3838void init_gpfs(void);
     39void smbd_gpfs_lib_init();
  • trunk/server/source3/modules/vfs_hpuxacl.c

    r414 r745  
    4848
    4949#include "includes.h"
     50#include "system/filesys.h"
     51#include "smbd/smbd.h"
     52#include "modules/vfs_hpuxacl.h"
     53
    5054
    5155/*
     
    190194        /* For all I see, the info should already be in the fsp
    191195         * parameter, but get it again to be safe --- necessary? */
    192         files_struct *file_struct_p = file_find_fd(fsp->fh->fd);
     196        files_struct *file_struct_p = file_find_fd(fsp->conn->sconn,
     197                                                   fsp->fh->fd);
    193198        if (file_struct_p == NULL) {
    194199                errno = EBADF;
     
    329334        /* For all I see, the info should already be in the fsp
    330335         * parameter, but get it again to be safe --- necessary? */
    331         files_struct *file_struct_p = file_find_fd(fsp->fh->fd);
     336        files_struct *file_struct_p = file_find_fd(fsp->conn->sconn,
     337                                                   fsp->fh->fd);
    332338        if (file_struct_p == NULL) {
    333339                errno = EBADF;
  • trunk/server/source3/modules/vfs_irixacl.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
     23#include "modules/vfs_irixacl.h"
     24
    2125
    2226/* prototypes for private functions first - for clarity */
  • trunk/server/source3/modules/vfs_netatalk.c

    r429 r745  
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
     23#include "system/filesys.h"
    2224
    2325#undef DBGC_CLASS
     
    199201}
    200202
     203static SMB_STRUCT_DIR *atalk_fdopendir(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
     204{
     205        SMB_STRUCT_DIR *ret = 0;
     206
     207        ret = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
     208
     209        if (ret == NULL) {
     210                return ret;
     211        }
     212
     213        /*
     214         * when we try to perform delete operation upon file which has fork
     215         * in ./.AppleDouble and this directory wasn't hidden by Samba,
     216         * MS Windows explorer causes the error: "Cannot find the specified file"
     217         * There is some workaround to avoid this situation, i.e. if
     218         * connection has not .AppleDouble entry in either veto or hide
     219         * list then it would be nice to add one.
     220         */
     221
     222        atalk_add_to_list(&handle->conn->hide_list);
     223        atalk_add_to_list(&handle->conn->veto_list);
     224
     225        return ret;
     226}
     227
    201228static int atalk_rmdir(struct vfs_handle_struct *handle, const char *path)
    202229{
     
    433460static struct vfs_fn_pointers vfs_netatalk_fns = {
    434461        .opendir = atalk_opendir,
     462        .fdopendir = atalk_fdopendir,
    435463        .rmdir = atalk_rmdir,
    436464        .rename = atalk_rename,
  • trunk/server/source3/modules/vfs_notify_fam.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
     23#include "librpc/gen_ndr/notify.h"
    2224
    2325#include <fam.h>
     
    8082        FAMCONNECTION_GETFD(fam_conn) = -1;
    8183
     84
     85#ifdef HAVE_FAMNOEXISTS
     86        /* We should honor outside setting of the GAM_CLIENT_ID. */
     87        setenv("GAM_CLIENT_ID","SAMBA",0);
     88#endif
     89
    8290        if (asprintf(&name, "smbd (%lu)", (unsigned long)sys_getpid()) == -1) {
    8391                DEBUG(0, ("No memory\n"));
     
    8694
    8795        res = FAMOpen2(fam_conn, name);
     96
     97#ifdef HAVE_FAMNOEXISTS
     98        /*
     99         * This reduces the chatter between GAMIN and samba making the pair
     100         * much more reliable.
     101         */
     102        FAMNoExists(fam_conn);
     103#endif
     104
    88105        SAFE_FREE(name);
    89106
  • trunk/server/source3/modules/vfs_onefs.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "smbd/smbd.h"
    2223#include "onefs.h"
    2324#include "onefs_config.h"
     
    265266        .closedir = onefs_closedir,
    266267        .init_search_op = onefs_init_search_op,
    267         .open = onefs_open,
     268        .open_fn = onefs_open,
    268269        .create_file = onefs_create_file,
    269270        .close_fn = onefs_close,
  • trunk/server/source3/modules/vfs_onefs_shadow_copy.c

    r414 r745  
    2323
    2424#include "includes.h"
     25#include "smbd/smbd.h"
    2526#include "onefs_shadow_copy.h"
    2627
     
    234235                              uint32_t oplock_request,
    235236                              uint64_t allocation_size,
     237                              uint32_t private_flags,
    236238                              struct security_descriptor *sd,
    237239                              struct ea_list *ea_list,
     
    244246                                  create_disposition, create_options,
    245247                                  file_attributes, oplock_request,
    246                                   allocation_size, sd, ea_list, result, pinfo),
     248                                  allocation_size, private_flags,
     249                                  sd, ea_list, result, pinfo),
    247250                              NTSTATUS);
    248251}
     
    470473
    471474static char *
    472 onefs_shadow_copy_realpath(vfs_handle_struct *handle, const char *path,
    473                            char *resolved_path)
     475onefs_shadow_copy_realpath(vfs_handle_struct *handle, const char *path)
    474476{
    475477        SHADOW_NEXT(REALPATH,
    476                     (handle, cpath ?: path, resolved_path),
     478                    (handle, cpath ?: path),
    477479                    char *);
    478480}
     
    634636static bool
    635637onefs_shadow_copy_is_offline(struct vfs_handle_struct *handle,
    636                              const char *path, SMB_STRUCT_STAT *sbuf)
    637 {
     638                             const struct smb_fname *fname,
     639                             SMB_STRUCT_STAT *sbuf)
     640{
     641#error Isilon, please convert "char *path" to "struct smb_fname *fname"
    638642        SHADOW_NEXT(IS_OFFLINE,
    639643                    (handle, cpath ?: path, sbuf),
     
    643647static int
    644648onefs_shadow_copy_set_offline(struct vfs_handle_struct *handle,
    645                               const char *path)
    646 {
     649                               const struct smb_filename *fname)
     650{
     651#error Isilon, please convert "char *path" to "struct smb_fname *fname"
    647652        SHADOW_NEXT(SET_OFFLINE,
    648653                    (handle, cpath ?: path),
     
    659664        .mkdir = onefs_shadow_copy_mkdir,
    660665        .rmdir = onefs_shadow_copy_rmdir,
    661         .open = onefs_shadow_copy_open,
     666        .open_fn = onefs_shadow_copy_open,
    662667        .create_file = onefs_shadow_copy_create_file,
    663668        .rename = onefs_shadow_copy_rename,
  • trunk/server/source3/modules/vfs_posixacl.c

    r414 r745  
    1919
    2020#include "includes.h"
    21 
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
     23#include "modules/vfs_posixacl.h"
    2224
    2325/* prototypes for static functions first - for clarity */
  • trunk/server/source3/modules/vfs_prealloc.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "smbd/smbd.h"
    2122
    2223/* Extent preallocation module.
     
    214215
    215216static struct vfs_fn_pointers prealloc_fns = {
    216         .open = prealloc_open,
     217        .open_fn = prealloc_open,
    217218        .ftruncate = prealloc_ftruncate,
    218219        .connect_fn = prealloc_connect,
  • trunk/server/source3/modules/vfs_preopen.c

    r414 r745  
    2020
    2121#include "includes.h"
     22#include "system/filesys.h"
     23#include "smbd/smbd.h"
    2224
    2325struct preopen_state;
     
    442444
    443445static struct vfs_fn_pointers vfs_preopen_fns = {
    444         .open = preopen_open
     446        .open_fn = preopen_open
    445447};
    446448
  • trunk/server/source3/modules/vfs_readahead.c

    r414 r745  
    1717
    1818#include "includes.h"
     19#include "system/filesys.h"
     20#include "smbd/smbd.h"
     21
     22#if defined(HAVE_LINUX_READAHEAD) && ! defined(HAVE_READAHEAD_DECL)
     23ssize_t readahead(int fd, off64_t offset, size_t count);
     24#endif
    1925
    2026struct readahead_data {
  • trunk/server/source3/modules/vfs_readonly.c

    r414 r745  
    2222
    2323#include "includes.h"
     24#include "smbd/smbd.h"
    2425#include "getdate.h"
    2526
     
    8485        struct vuid_cache_entry *ent = ent = &conn->vuid_cache.array[i];
    8586        ent->vuid = UID_FIELD_INVALID;
    86         TALLOC_FREE(ent->server_info);
     87        TALLOC_FREE(ent->session_info);
    8788        ent->read_only = false;
    88         ent->admin_user = false;
    8989      }
    9090      conn->vuid_cache.next_entry = 0;
  • trunk/server/source3/modules/vfs_recycle.c

    r414 r745  
    2424
    2525#include "includes.h"
     26#include "smbd/smbd.h"
     27#include "system/filesys.h"
     28#include "../librpc/gen_ndr/ndr_netlogon.h"
     29#include "auth.h"
    2630
    2731#define ALLOC_CHECK(ptr, label) do { if ((ptr) == NULL) { DEBUG(0, ("recycle.bin: out of memory!\n")); errno = ENOMEM; goto label; } } while(0)
     
    6266{
    6367        const char *tmp_str = NULL;
    64        
    6568
    6669        tmp_str = lp_parm_const_string(SNUM(handle->conn), "recycle", "repository",".recycle");
    6770
    6871        DEBUG(10, ("recycle: repository = %s\n", tmp_str));
    69        
     72
    7073        return tmp_str;
    7174}
     
    7477{
    7578        bool ret;
    76        
     79
    7780        ret = lp_parm_bool(SNUM(handle->conn), "recycle", "keeptree", False);
    7881
    7982        DEBUG(10, ("recycle_bin: keeptree = %s\n", ret?"True":"False"));
    80        
     83
    8184        return ret;
    8285}
     
    8992
    9093        DEBUG(10, ("recycle: versions = %s\n", ret?"True":"False"));
    91        
     94
    9295        return ret;
    9396}
     
    100103
    101104        DEBUG(10, ("recycle: touch = %s\n", ret?"True":"False"));
    102        
     105
    103106        return ret;
    104107}
     
    111114
    112115        DEBUG(10, ("recycle: touch_mtime = %s\n", ret?"True":"False"));
    113        
     116
    114117        return ret;
    115118}
     
    118121{
    119122        const char **tmp_lp;
    120        
     123
    121124        tmp_lp = lp_parm_string_list(SNUM(handle->conn), "recycle", "exclude", NULL);
    122125
    123126        DEBUG(10, ("recycle: exclude = %s ...\n", tmp_lp?*tmp_lp:""));
    124        
     127
    125128        return tmp_lp;
    126129}
     
    129132{
    130133        const char **tmp_lp;
    131        
     134
    132135        tmp_lp = lp_parm_string_list(SNUM(handle->conn), "recycle", "exclude_dir", NULL);
    133136
    134137        DEBUG(10, ("recycle: exclude_dir = %s ...\n", tmp_lp?*tmp_lp:""));
    135        
     138
    136139        return tmp_lp;
    137140}
     
    140143{
    141144        const char **tmp_lp;
    142        
     145
    143146        tmp_lp = lp_parm_string_list(SNUM(handle->conn), "recycle", "noversions", NULL);
    144147
    145148        DEBUG(10, ("recycle: noversions = %s\n", tmp_lp?*tmp_lp:""));
    146        
     149
    147150        return tmp_lp;
    148151}
     
    151154{
    152155        SMB_OFF_T maxsize;
    153        
     156
    154157        maxsize = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
    155158                                            "recycle", "maxsize", NULL));
    156159
    157160        DEBUG(10, ("recycle: maxsize = %lu\n", (long unsigned int)maxsize));
    158        
     161
    159162        return maxsize;
    160163}
     
    163166{
    164167        SMB_OFF_T minsize;
    165        
     168
    166169        minsize = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
    167170                                            "recycle", "minsize", NULL));
    168171
    169172        DEBUG(10, ("recycle: minsize = %lu\n", (long unsigned int)minsize));
    170        
     173
    171174        return minsize;
    172175}
     
    465468
    466469        repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)),
    467                                         conn->server_info->unix_name,
     470                                        conn->session_info->unix_name,
    468471                                        conn->connectpath,
    469                                         conn->server_info->utok.gid,
    470                                         conn->server_info->sanitized_username,
    471                                         pdb_get_domain(conn->server_info->sam_account),
     472                                        conn->session_info->utok.gid,
     473                                        conn->session_info->sanitized_username,
     474                                        conn->session_info->info3->base.domain.string,
    472475                                        recycle_repository(handle));
    473476        ALLOC_CHECK(repository, done);
     
    475478        /* Yes :-). JRA. */
    476479        trim_char(repository, '\0', '/');
    477        
     480
    478481        if(!repository || *(repository) == '\0') {
    479482                DEBUG(3, ("recycle: repository path not set, purging %s...\n",
     
    674677        if (!NT_STATUS_IS_OK(ret))
    675678                return ret;
    676        
     679
    677680        vfs_recycle_debug_level = debug_add_class("recycle");
    678681        if (vfs_recycle_debug_level == -1) {
     
    682685                DEBUG(10, ("vfs_recycle: Debug class number of 'recycle': %d\n", vfs_recycle_debug_level));
    683686        }
    684        
     687
    685688        return ret;
    686689}
  • trunk/server/source3/modules/vfs_scannedonly.c

    r596 r745  
    22 * scannedonly VFS module for Samba 3.5
    33 *
    4  * Copyright 2007,2008,2009 (C) Olivier Sessink
     4 * Copyright 2007,2008,2009,2010 (C) Olivier Sessink
    55 *
    66 * This program is free software; you can redistribute it and/or modify
     
    4949
    5050#include "includes.h"
     51#include "smbd/smbd.h"
     52#include "system/filesys.h"
    5153
    5254#include "config.h"
     
    378380        TALLOC_CTX *ctx=talloc_tos();
    379381        char *cachefile;
    380         int retval;
     382        int retval = -1;
    381383        int didloop;
    382384        DEBUG(SCANNEDONLY_DEBUG,
     
    477479                while (retval != 0      /*&& errno == ENOENT */
    478480                       && i < recheck_tries) {
    479                         struct timespec req = { 0, recheck_time * 10000 };
    480481                        DEBUG(SCANNEDONLY_DEBUG,
    481482                              ("scannedonly_allow_access, wait (try=%d "
     
    483484                               i, recheck_tries,
    484485                               recheck_time, cache_smb_fname->base_name));
    485                         nanosleep(&req, NULL);
     486                        smb_msleep(recheck_time);
    486487                        retval = SMB_VFS_NEXT_STAT(handle, cache_smb_fname);
    487488                        i++;
     
    527528        return (SMB_STRUCT_DIR *) sDIR;
    528529}
     530
     531static SMB_STRUCT_DIR *scannedonly_fdopendir(vfs_handle_struct * handle,
     532                                           files_struct *fsp,
     533                                           const char *mask, uint32 attr)
     534{
     535        SMB_STRUCT_DIR *DIRp;
     536        struct scannedonly_DIR *sDIR;
     537        const char *fname;
     538
     539        DIRp = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
     540        if (!DIRp) {
     541                return NULL;
     542        }
     543
     544        fname = (const char *)fsp->fsp_name->base_name;
     545
     546        sDIR = TALLOC_P(NULL, struct scannedonly_DIR);
     547        if (fname[0] != '/') {
     548                sDIR->base = construct_full_path(sDIR,handle, fname, true);
     549        } else {
     550                sDIR->base = name_w_ending_slash(sDIR, fname);
     551        }
     552        DEBUG(SCANNEDONLY_DEBUG,
     553                        ("scannedonly_fdopendir, fname=%s, base=%s\n",fname,sDIR->base));
     554        sDIR->DIR = DIRp;
     555        sDIR->notify_loop_done = 0;
     556        return (SMB_STRUCT_DIR *) sDIR;
     557}
     558
    529559
    530560static SMB_STRUCT_DIRENT *scannedonly_readdir(vfs_handle_struct *handle,
     
    767797        struct smb_filename *smb_fname_dst_tmp = NULL;
    768798        char *cachefile_src, *cachefile_dst;
     799        bool needscandst=false;
     800        int ret;
    769801        TALLOC_CTX *ctx = talloc_tos();
    770802
     
    778810                smb_fname_dst->base_name,
    779811                STRUCTSCANO(handle->data)->p_scanned);
    780 
    781812        create_synthetic_smb_fname(ctx, cachefile_src,NULL,NULL,
    782813                                   &smb_fname_src_tmp);
     
    784815                                   &smb_fname_dst_tmp);
    785816
    786         if (SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp, smb_fname_dst_tmp)
    787             != 0) {
     817        ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src_tmp, smb_fname_dst_tmp);
     818        if (ret == ENOENT) {
     819                needscandst=true;
     820        } else if (ret != 0) {
    788821                DEBUG(SCANNEDONLY_DEBUG,
    789                       ("failed to rename %s into %s\n", cachefile_src,
    790                        cachefile_dst));
    791         }
    792         return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
     822                      ("failed to rename %s into %s error %d: %s\n", cachefile_src,
     823                       cachefile_dst, ret, strerror(ret)));
     824                needscandst=true;
     825        }
     826        ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
     827        if (ret == 0 && needscandst) {
     828                notify_scanner(handle, smb_fname_dst->base_name);
     829                flush_sendbuffer(handle);
     830        }
     831        return ret;
    793832}
    794833
     
    9791018static struct vfs_fn_pointers vfs_scannedonly_fns = {
    9801019        .opendir = scannedonly_opendir,
     1020        .fdopendir = scannedonly_fdopendir,
    9811021        .readdir = scannedonly_readdir,
    9821022        .seekdir = scannedonly_seekdir,
     
    9871027        .stat = scannedonly_stat,
    9881028        .lstat = scannedonly_lstat,
    989         .open = scannedonly_open,
     1029        .open_fn = scannedonly_open,
    9901030        .close_fn = scannedonly_close,
    9911031        .rename = scannedonly_rename,
  • trunk/server/source3/modules/vfs_shadow_copy.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "smbd/smbd.h"
     22#include "ntioctl.h"
    2123
    2224/*
     
    119121}
    120122
     123static SMB_STRUCT_DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
     124{
     125        shadow_copy_Dir *dirp;
     126        SMB_STRUCT_DIR *p = SMB_VFS_NEXT_FDOPENDIR(handle,fsp,mask,attr);
     127
     128        if (!p) {
     129                DEBUG(10,("shadow_copy_opendir: SMB_VFS_NEXT_FDOPENDIR() failed for [%s]\n",
     130                        smb_fname_str_dbg(fsp->fsp_name)));
     131                return NULL;
     132        }
     133
     134        dirp = SMB_MALLOC_P(shadow_copy_Dir);
     135        if (!dirp) {
     136                DEBUG(0,("shadow_copy_fdopendir: Out of memory\n"));
     137                SMB_VFS_NEXT_CLOSEDIR(handle,p);
     138                /* We have now closed the fd in fsp. */
     139                fsp->fh->fd = -1;
     140                return NULL;
     141        }
     142
     143        ZERO_STRUCTP(dirp);
     144
     145        while (True) {
     146                SMB_STRUCT_DIRENT *d;
     147
     148                d = SMB_VFS_NEXT_READDIR(handle, p, NULL);
     149                if (d == NULL) {
     150                        break;
     151                }
     152
     153                if (shadow_copy_match_name(d->d_name)) {
     154                        DEBUG(8,("shadow_copy_fdopendir: hide [%s]\n",d->d_name));
     155                        continue;
     156                }
     157
     158                DEBUG(10,("shadow_copy_fdopendir: not hide [%s]\n",d->d_name));
     159
     160                dirp->dirs = SMB_REALLOC_ARRAY(dirp->dirs,SMB_STRUCT_DIRENT, dirp->num+1);
     161                if (!dirp->dirs) {
     162                        DEBUG(0,("shadow_copy_fdopendir: Out of memory\n"));
     163                        break;
     164                }
     165
     166                dirp->dirs[dirp->num++] = *d;
     167        }
     168
     169        SMB_VFS_NEXT_CLOSEDIR(handle,p);
     170        /* We have now closed the fd in fsp. */
     171        fsp->fh->fd = -1;
     172        return((SMB_STRUCT_DIR *)dirp);
     173}
     174
    121175static SMB_STRUCT_DIRENT *shadow_copy_readdir(vfs_handle_struct *handle,
    122176                                              SMB_STRUCT_DIR *_dirp,
     
    163217}
    164218
    165 static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, bool labels)
     219static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle,
     220                                            files_struct *fsp,
     221                                            struct shadow_copy_data *shadow_copy_data,
     222                                            bool labels)
    166223{
    167224        SMB_STRUCT_DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fsp->conn->connectpath,NULL,0);
     
    197254                }
    198255
    199                 tlabels = (SHADOW_COPY_LABEL *)TALLOC_REALLOC(shadow_copy_data->mem_ctx,
     256                tlabels = (SHADOW_COPY_LABEL *)TALLOC_REALLOC(shadow_copy_data,
    200257                                                                        shadow_copy_data->labels,
    201258                                                                        (shadow_copy_data->num_volumes+1)*sizeof(SHADOW_COPY_LABEL));
     
    217274static struct vfs_fn_pointers vfs_shadow_copy_fns = {
    218275        .opendir = shadow_copy_opendir,
     276        .fdopendir = shadow_copy_fdopendir,
    219277        .readdir = shadow_copy_readdir,
    220278        .seekdir = shadow_copy_seekdir,
  • trunk/server/source3/modules/vfs_shadow_copy2.c

    r599 r745  
    33 *
    44 * Copyright (C) Andrew Tridgell     2007
     5 * Copyright (C) Ed Plese            2009
    56 *
    67 * This program is free software; you can redistribute it and/or modify
     
    2021
    2122#include "includes.h"
     23#include "smbd/smbd.h"
     24#include "system/filesys.h"
     25#include "ntioctl.h"
    2226
    2327/*
     
    3438     from the original. This allows the 'restore' button to work
    3539     without a sharing violation
     40
     41     3) shadow copy results can be sorted before being sent to the
     42     client.  This is beneficial for filesystems that don't read
     43     directories alphabetically (the default unix).
     44
     45     4) vanity naming for snapshots. Snapshots can be named in any
     46     format compatible with str[fp]time conversions.
     47
     48     5) time stamps in snapshot names can be represented in localtime
     49     rather than UTC.
    3650
    3751  Module options:
     
    5973      copy UI will fail with a sharing violation.
    6074
    61   Note that the directory names in the snapshot directory must take the form
    62   @GMT-YYYY.MM.DD-HH.MM.SS
    63  
    64   The following command would generate a correctly formatted directory name:
     75      shadow:sort = asc/desc, or not specified for unsorted (default)
     76
     77      This is an optional parameter that specifies that the shadow
     78      copy directories should be sorted before sending them to the
     79      client.  This can be beneficial as unix filesystems are usually
     80      not listed alphabetically sorted.  If enabled, you typically
     81      want to specify descending order.
     82
     83      shadow:format = <format specification for snapshot names>
     84
     85      This is an optional parameter that specifies the format
     86      specification for the naming of snapshots.  The format must
     87      be compatible with the conversion specifications recognized
     88      by str[fp]time.  The default value is "@GMT-%Y.%m.%d-%H.%M.%S".
     89
     90      shadow:localtime = yes/no (default is no)
     91
     92      This is an optional parameter that indicates whether the
     93      snapshot names are in UTC/GMT or the local time.
     94
     95
     96  The following command would generate a correctly formatted directory name
     97  for use with the default parameters:
    6598     date -u +@GMT-%Y.%m.%d-%H.%M.%S
    6699 
     
    73106
    74107#define GMT_NAME_LEN 24 /* length of a @GMT- name */
     108#define SHADOW_COPY2_GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
     109
     110#define SHADOW_COPY2_DEFAULT_SORT NULL
     111#define SHADOW_COPY2_DEFAULT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
     112#define SHADOW_COPY2_DEFAULT_LOCALTIME false
    75113
    76114/*
     
    98136        }
    99137        return True;
     138}
     139
     140static char *shadow_copy2_snapshot_to_gmt(TALLOC_CTX *mem_ctx,
     141                                vfs_handle_struct *handle, const char *name)
     142{
     143        struct tm timestamp;
     144        time_t timestamp_t;
     145        char gmt[GMT_NAME_LEN + 1];
     146        const char *fmt;
     147
     148        fmt = lp_parm_const_string(SNUM(handle->conn), "shadow",
     149                                   "format", SHADOW_COPY2_DEFAULT_FORMAT);
     150
     151        ZERO_STRUCT(timestamp);
     152        if (strptime(name, fmt, &timestamp) == NULL) {
     153                DEBUG(10, ("shadow_copy2_snapshot_to_gmt: no match %s: %s\n",
     154                           fmt, name));
     155                return NULL;
     156        }
     157
     158        DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n", fmt, name));
     159        if (lp_parm_bool(SNUM(handle->conn), "shadow", "localtime",
     160                         SHADOW_COPY2_DEFAULT_LOCALTIME))
     161        {
     162                timestamp.tm_isdst = -1;
     163                timestamp_t = mktime(&timestamp);
     164                gmtime_r(&timestamp_t, &timestamp);
     165        }
     166        strftime(gmt, sizeof(gmt), SHADOW_COPY2_GMT_FORMAT, &timestamp);
     167
     168        return talloc_strdup(mem_ctx, gmt);
    100169}
    101170
     
    185254
    186255#define _SHADOW2_NEXT_SMB_FNAME(op, args, rtype, eret, extra) do { \
    187                 const char *gmt_start; \
    188                 if (shadow_copy2_match_name(smb_fname->base_name, &gmt_start)) {        \
     256        const char *gmt_start; \
     257        if (shadow_copy2_match_name(smb_fname->base_name, &gmt_start)) { \
    189258                char *name2; \
    190259                char *smb_base_name_tmp = NULL; \
     
    346415        const char *snapdir, *relpath, *baseoffset, *basedir;
    347416        size_t baselen;
    348         char *ret;
     417        char *ret, *prefix;
     418
     419        struct tm timestamp;
     420        time_t timestamp_t;
     421        char snapshot[MAXPATHLEN];
     422        const char *fmt;
     423
     424        fmt = lp_parm_const_string(SNUM(handle->conn), "shadow",
     425                                   "format", SHADOW_COPY2_DEFAULT_FORMAT);
    349426
    350427        snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
     
    360437                talloc_free(tmp_ctx);
    361438                return NULL;
     439        }
     440
     441        prefix = talloc_asprintf(tmp_ctx, "%s/@GMT-", snapdir);
     442        if (strncmp(fname, prefix, (talloc_get_size(prefix)-1)) == 0) {
     443                /* this looks like as we have already normalized it, leave it untouched*/
     444                talloc_free(tmp_ctx);
     445                return talloc_strdup(handle->data, fname);
    362446        }
    363447
     
    370454        }
    371455
    372         relpath = fname + GMT_NAME_LEN;
     456        ZERO_STRUCT(timestamp);
     457        relpath = strptime(fname, SHADOW_COPY2_GMT_FORMAT, &timestamp);
     458        if (relpath == NULL) {
     459                talloc_free(tmp_ctx);
     460                return NULL;
     461        }
     462
     463        /* relpath is the remaining portion of the path after the @GMT-xxx */
     464
     465        if (lp_parm_bool(SNUM(handle->conn), "shadow", "localtime",
     466                         SHADOW_COPY2_DEFAULT_LOCALTIME))
     467        {
     468                timestamp_t = timegm(&timestamp);
     469                localtime_r(&timestamp_t, &timestamp);
     470        }
     471
     472        strftime(snapshot, MAXPATHLEN, fmt, &timestamp);
     473
    373474        baselen = strlen(basedir);
    374475        baseoffset = handle->conn->connectpath + baselen;
     
    386487        if (*baseoffset == '/') baseoffset++;
    387488
    388         ret = talloc_asprintf(handle->data, "%s/%.*s/%s/%s",
     489        ret = talloc_asprintf(handle->data, "%s/%s/%s/%s",
    389490                              snapdir,
    390                               GMT_NAME_LEN, fname,
     491                              snapshot,
    391492                              baseoffset,
    392493                              relpath);
     
    438539                               const struct smb_filename *smb_fname_dst)
    439540{
     541        if (shadow_copy2_match_name(smb_fname_src->base_name, NULL)) {
     542                errno = EXDEV;
     543                return -1;
     544        }
    440545        SHADOW2_NEXT2_SMB_FNAME(RENAME,
    441546                                (handle, smb_fname_src, smb_fname_dst));
     
    556661
    557662static char *shadow_copy2_realpath(vfs_handle_struct *handle,
    558                             const char *fname, char *resolved_path)
     663                            const char *fname)
    559664{
    560665        const char *gmt;
     
    562667        if (shadow_copy2_match_name(fname, &gmt)
    563668            && (gmt[GMT_NAME_LEN] == '\0')) {
    564                 char *copy, *result;
     669                char *copy;
    565670
    566671                copy = talloc_strdup(talloc_tos(), fname);
     
    571676
    572677                copy[gmt - fname] = '.';
     678                copy[gmt - fname + 1] = '\0';
    573679
    574680                DEBUG(10, ("calling NEXT_REALPATH with %s\n", copy));
    575                 result = SMB_VFS_NEXT_REALPATH(handle, copy, resolved_path);
    576                 TALLOC_FREE(copy);
    577                 return result;
    578         }
    579         SHADOW2_NEXT(REALPATH, (handle, name, resolved_path), char *, NULL);
     681                SHADOW2_NEXT(REALPATH, (handle, name), char *,
     682                             NULL);
     683        }
     684        SHADOW2_NEXT(REALPATH, (handle, name), char *, NULL);
    580685}
    581686
     
    719824}
    720825
     826static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
     827{
     828        return strncmp((char *)x, (char *)y, sizeof(SHADOW_COPY_LABEL));
     829}
     830
     831static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
     832{
     833        return -strncmp((char *)x, (char *)y, sizeof(SHADOW_COPY_LABEL));
     834}
     835
     836/*
     837  sort the shadow copy data in ascending or descending order
     838 */
     839static void shadow_copy2_sort_data(vfs_handle_struct *handle,
     840                                   struct shadow_copy_data *shadow_copy2_data)
     841{
     842        int (*cmpfunc)(const void *, const void *);
     843        const char *sort;
     844
     845        sort = lp_parm_const_string(SNUM(handle->conn), "shadow",
     846                                    "sort", SHADOW_COPY2_DEFAULT_SORT);
     847        if (sort == NULL) {
     848                return;
     849        }
     850
     851        if (strcmp(sort, "asc") == 0) {
     852                cmpfunc = shadow_copy2_label_cmp_asc;
     853        } else if (strcmp(sort, "desc") == 0) {
     854                cmpfunc = shadow_copy2_label_cmp_desc;
     855        } else {
     856                return;
     857        }
     858
     859        if (shadow_copy2_data && shadow_copy2_data->num_volumes > 0 &&
     860            shadow_copy2_data->labels)
     861        {
     862                TYPESAFE_QSORT(shadow_copy2_data->labels,
     863                               shadow_copy2_data->num_volumes,
     864                               cmpfunc);
     865        }
     866
     867        return;
     868}
     869
    721870static int shadow_copy2_get_shadow_copy2_data(vfs_handle_struct *handle,
    722871                                              files_struct *fsp,
    723                                               SHADOW_COPY_DATA *shadow_copy2_data,
     872                                              struct shadow_copy_data *shadow_copy2_data,
    724873                                              bool labels)
    725874{
     
    728877        SMB_STRUCT_DIRENT *d;
    729878        TALLOC_CTX *tmp_ctx = talloc_new(handle->data);
     879        char *snapshot;
    730880
    731881        snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
     
    748898        }
    749899
    750         talloc_free(tmp_ctx);
    751 
    752900        shadow_copy2_data->num_volumes = 0;
    753901        shadow_copy2_data->labels      = NULL;
     
    757905
    758906                /* ignore names not of the right form in the snapshot directory */
    759                 if (!shadow_copy2_match_name(d->d_name, NULL)) {
     907                snapshot = shadow_copy2_snapshot_to_gmt(tmp_ctx, handle,
     908                                                        d->d_name);
     909                DEBUG(6,("shadow_copy2_get_shadow_copy2_data: %s -> %s\n",
     910                         d->d_name, snapshot));
     911                if (!snapshot) {
    760912                        continue;
    761913                }
     
    767919                }
    768920
    769                 tlabels = talloc_realloc(shadow_copy2_data->mem_ctx,
     921                tlabels = talloc_realloc(shadow_copy2_data,
    770922                                         shadow_copy2_data->labels,
    771923                                         SHADOW_COPY_LABEL, shadow_copy2_data->num_volumes+1);
     
    773925                        DEBUG(0,("shadow_copy2: out of memory\n"));
    774926                        SMB_VFS_NEXT_CLOSEDIR(handle, p);
     927                        talloc_free(tmp_ctx);
    775928                        return -1;
    776929                }
    777930
    778                 strlcpy(tlabels[shadow_copy2_data->num_volumes], d->d_name, sizeof(*tlabels));
     931                strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot,
     932                        sizeof(*tlabels));
     933                talloc_free(snapshot);
     934
    779935                shadow_copy2_data->num_volumes++;
    780936                shadow_copy2_data->labels = tlabels;
     
    782938
    783939        SMB_VFS_NEXT_CLOSEDIR(handle,p);
     940
     941        shadow_copy2_sort_data(handle, shadow_copy2_data);
     942
     943        talloc_free(tmp_ctx);
    784944        return 0;
    785945}
     
    797957        .setxattr = shadow_copy2_setxattr,
    798958        .lsetxattr = shadow_copy2_lsetxattr,
    799         .open = shadow_copy2_open,
     959        .open_fn = shadow_copy2_open,
    800960        .rename = shadow_copy2_rename,
    801961        .stat = shadow_copy2_stat,
  • trunk/server/source3/modules/vfs_smb_traffic_analyzer.c

    r414 r745  
    33 * on the net.
    44 *
    5  * Copyright (C) Holger Hetterich, 2008
     5 * Copyright (C) Holger Hetterich, 2008-2010
    66 * Copyright (C) Jeremy Allison, 2008
    77 *
     
    2121
    2222#include "includes.h"
     23#include "smbd/smbd.h"
     24#include "../smbd/globals.h"
     25#include "../lib/crypto/crypto.h"
     26#include "vfs_smb_traffic_analyzer.h"
     27#include "../libcli/security/security.h"
     28#include "secrets.h"
     29#include "../librpc/gen_ndr/ndr_netlogon.h"
     30#include "auth.h"
    2331
    2432/* abstraction for the send_over_network function */
    25 
    2633enum sock_type {INTERNET_SOCKET = 0, UNIX_DOMAIN_SOCKET};
    2734
     
    4552
    4653/* Connect to an internet socket */
    47 
    4854static int smb_traffic_analyzer_connect_inet_socket(vfs_handle_struct *handle,
    4955                                        const char *name, uint16_t port)
     
    109115
    110116/* Connect to a unix domain socket */
    111 
    112117static int smb_traffic_analyzer_connect_unix_socket(vfs_handle_struct *handle,
    113118                                                const char *name)
     
    142147
    143148/* Private data allowing shared connection sockets. */
    144 
    145149struct refcounted_sock {
    146150        struct refcounted_sock *next, *prev;
     
    151155};
    152156
    153 /* Send data over a socket */
     157
     158/**
     159 * Encryption of a data block with AES
     160 * TALLOC_CTX *ctx      Talloc context to work on
     161 * const char *akey     128bit key for the encryption
     162 * const char *str      Data buffer to encrypt, \0 terminated
     163 * int *len             Will be set to the length of the
     164 *                      resulting data block
     165 * The caller has to take care for the memory
     166 * allocated on the context.
     167 */
     168static char *smb_traffic_analyzer_encrypt( TALLOC_CTX *ctx,
     169        const char *akey, const char *str, size_t *len)
     170{
     171        int s1,s2,h,d;
     172        AES_KEY key;
     173        unsigned char filler[17]= "................";
     174        char *output;
     175        unsigned char crypted[18];
     176        if (akey == NULL) return NULL;
     177        samba_AES_set_encrypt_key((unsigned char *) akey, 128, &key);
     178        s1 = strlen(str) / 16;
     179        s2 = strlen(str) % 16;
     180        for (h = 0; h < s2; h++) *(filler+h)=*(str+(s1*16)+h);
     181        DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created %s"
     182                " as filling block.\n", filler));
     183        output = talloc_array(ctx, char, (s1*16)+17 );
     184        d=0;
     185        for (h = 0; h < s1; h++) {
     186                samba_AES_encrypt((unsigned char *) str+(16*h), crypted, &key);
     187                for (d = 0; d<16; d++) output[d+(16*h)]=crypted[d];
     188        }
     189        samba_AES_encrypt( (unsigned char *) str+(16*h), filler, &key );
     190        for (d = 0;d < 16; d++) output[d+(16*h)]=*(filler+d);
     191        *len = (s1*16)+16;
     192        return output; 
     193}
     194
     195/**
     196 * Create a v2 header.
     197 * TALLLOC_CTX *ctx             Talloc context to work on
     198 * const char *state_flags      State flag string
     199 * int len                      length of the data block
     200 */
     201static char *smb_traffic_analyzer_create_header( TALLOC_CTX *ctx,
     202        const char *state_flags, size_t data_len)
     203{
     204        char *header = talloc_asprintf( ctx, "V2.%s%017u",
     205                                        state_flags, (unsigned int) data_len);
     206        DEBUG(10, ("smb_traffic_analyzer_send_data_socket: created Header:\n"));
     207        dump_data(10, (uint8_t *)header, strlen(header));
     208        return header;
     209}
     210
     211
     212/**
     213 * Actually send header and data over the network
     214 * char *header         Header data
     215 * char *data           Data Block
     216 * int dlength          Length of data block
     217 * int socket
     218 */
     219static void smb_traffic_analyzer_write_data( char *header, char *data,
     220                        int dlength, int _socket)
     221{
     222                int len = strlen(header);
     223                if (write_data( _socket, header, len) != len) {
     224                        DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
     225                                                "error sending the header"
     226                                                " over the socket!\n"));
     227                }
     228                DEBUG(10,("smb_traffic_analyzer_write_data: sending data:\n"));
     229                dump_data( 10, (uint8_t *)data, dlength);
     230
     231                if (write_data( _socket, data, dlength) != dlength) {
     232                        DEBUG(1, ("smb_traffic_analyzer_write_data: "
     233                                "error sending crypted data to socket!\n"));
     234                }
     235}
     236
     237
     238/*
     239 * Anonymize a string if required.
     240 * TALLOC_CTX *ctx                      The talloc context to work on
     241 * const char *str                      The string to anonymize
     242 * vfs_handle_struct *handle            The handle struct to work on
     243 *
     244 * Returns a newly allocated string, either the anonymized one,
     245 * or a copy of const char *str. The caller has to take care for
     246 * freeing the allocated memory.
     247 */
     248static char *smb_traffic_analyzer_anonymize( TALLOC_CTX *ctx,
     249                                        const char *str,
     250                                        vfs_handle_struct *handle )
     251{
     252        const char *total_anonymization;
     253        const char *anon_prefix;
     254        char *output;
     255        total_anonymization=lp_parm_const_string(SNUM(handle->conn),
     256                                        "smb_traffic_analyzer",
     257                                        "total_anonymization", NULL);
     258
     259        anon_prefix=lp_parm_const_string(SNUM(handle->conn),
     260                                        "smb_traffic_analyzer",
     261                                        "anonymize_prefix", NULL );
     262        if (anon_prefix != NULL) {
     263                if (total_anonymization != NULL) {
     264                        output = talloc_asprintf(ctx, "%s",
     265                                        anon_prefix);
     266                } else {
     267                output = talloc_asprintf(ctx, "%s%i", anon_prefix,
     268                                                str_checksum(str));
     269                }
     270        } else {
     271                output = talloc_asprintf(ctx, "%s", str);
     272        }
     273
     274        return output;
     275}
     276
     277
     278/**
     279 * The marshalling function for protocol v2.
     280 * TALLOC_CTX *ctx              Talloc context to work on
     281 * struct tm *tm                tm struct for the timestamp
     282 * int seconds                  milliseconds of the timestamp
     283 * vfs_handle_struct *handle    vfs_handle_struct
     284 * char *username               Name of the user
     285 * int vfs_operation            VFS operation identifier
     286 * int count                    Number of the common data blocks
     287 * [...] variable args          data blocks taken from the individual
     288 *                              VFS data structures
     289 *
     290 * Returns the complete data block to send. The caller has to
     291 * take care for freeing the allocated buffer.
     292 */
     293static char *smb_traffic_analyzer_create_string( TALLOC_CTX *ctx,
     294        struct tm *tm, int seconds, vfs_handle_struct *handle, \
     295        char *username, int vfs_operation, int count, ... )
     296{
     297       
     298        va_list ap;
     299        char *arg = NULL;
     300        int len;
     301        char *common_data_count_str = NULL;
     302        char *timestr = NULL;
     303        char *sidstr = NULL;
     304        char *usersid = NULL;
     305        char *buf = NULL;
     306        char *vfs_operation_str = NULL;
     307        const char *service_name = lp_const_servicename(handle->conn->params->service);
     308
     309        /*
     310         * first create the data that is transfered with any VFS op
     311         * These are, in the following order:
     312         *(0) number of data to come [6 in v2.0]
     313         * 1.vfs_operation identifier
     314         * 2.username
     315         * 3.user-SID
     316         * 4.affected share
     317         * 5.domain
     318         * 6.timestamp
     319         * 7.IP Addresss of client
     320         */
     321
     322        /*
     323         * number of common data blocks to come,
     324         * this is a #define in vfs_smb_traffic_anaylzer.h,
     325         * it's length is known at compile time
     326         */
     327        common_data_count_str = talloc_strdup( ctx, SMBTA_COMMON_DATA_COUNT);
     328        /* vfs operation identifier */
     329        vfs_operation_str = talloc_asprintf( common_data_count_str, "%i",
     330                                                        vfs_operation);
     331        /*
     332         * Handle anonymization. In protocol v2, we have to anonymize
     333         * both the SID and the username. The name is already
     334         * anonymized if needed, by the calling function.
     335         */
     336        usersid = dom_sid_string( common_data_count_str,
     337                &handle->conn->session_info->security_token->sids[0]);
     338
     339        sidstr = smb_traffic_analyzer_anonymize(
     340                common_data_count_str,
     341                usersid,
     342                handle);
     343       
     344        /* time stamp */
     345        timestr = talloc_asprintf( common_data_count_str, \
     346                "%04d-%02d-%02d %02d:%02d:%02d.%03d", \
     347                tm->tm_year+1900, \
     348                tm->tm_mon+1, \
     349                tm->tm_mday, \
     350                tm->tm_hour, \
     351                tm->tm_min, \
     352                tm->tm_sec, \
     353                (int)seconds);
     354        len = strlen( timestr );
     355        /* create the string of common data */
     356        buf = talloc_asprintf(ctx,
     357                "%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s%04u%s",
     358                common_data_count_str,
     359                (unsigned int) strlen(vfs_operation_str),
     360                vfs_operation_str,
     361                (unsigned int) strlen(username),
     362                username,
     363                (unsigned int) strlen(sidstr),
     364                sidstr,
     365                (unsigned int) strlen(service_name),
     366                service_name,
     367                (unsigned int)
     368                strlen(handle->conn->session_info->info3->base.domain.string),
     369                handle->conn->session_info->info3->base.domain.string,
     370                (unsigned int) strlen(timestr),
     371                timestr,
     372                (unsigned int) strlen(handle->conn->sconn->client_id.addr),
     373                handle->conn->sconn->client_id.addr);
     374
     375        talloc_free(common_data_count_str);
     376
     377        /* data blocks depending on the VFS function */
     378        va_start( ap, count );
     379        while ( count-- ) {
     380                arg = va_arg( ap, char * );
     381                /*
     382                 *  protocol v2 sends a four byte string
     383                 * as a header to each block, including
     384                 * the numbers of bytes to come in the
     385                 * next string.
     386                 */
     387                len = strlen( arg );
     388                buf = talloc_asprintf_append( buf, "%04u%s", len, arg);
     389        }
     390        va_end( ap );
     391        return buf;
     392}
    154393
    155394static void smb_traffic_analyzer_send_data(vfs_handle_struct *handle,
    156                                         ssize_t result,
    157                                         const char *file_name,
    158                                         bool Write)
     395                                        void *data,
     396                                        enum vfs_id vfs_operation )
    159397{
    160398        struct refcounted_sock *rf_sock = NULL;
     
    165403        char *str = NULL;
    166404        char *username = NULL;
    167         const char *anon_prefix = NULL;
    168         const char *total_anonymization = NULL;
     405        char *header = NULL;
     406        const char *protocol_version = NULL;
     407        bool Write = false;
    169408        size_t len;
     409        size_t size;
     410        char *akey, *output;
     411
     412        /*
     413         * The state flags are part of the header
     414         * and are descripted in the protocol description
     415         * in vfs_smb_traffic_analyzer.h. They begin at byte
     416         * 03 of the header.
     417         */
     418        char state_flags[9] = "000000\0";
     419
     420        /**
     421         * The first byte of the state flag string represents
     422         * the modules protocol subversion number, defined
     423         * in smb_traffic_analyzer.h. smbtatools/smbtad are designed
     424         * to handle not yet implemented protocol enhancements
     425         * by ignoring them. By recognizing the SMBTA_SUBRELEASE
     426         * smbtatools can tell the user to update the client
     427         * software.
     428         */
     429        state_flags[0] = SMBTA_SUBRELEASE;
    170430
    171431        SMB_VFS_HANDLE_GET_DATA(handle, rf_sock, struct refcounted_sock, return);
     
    178438
    179439        GetTimeOfDay(&tv);
    180         tv_sec = convert_timespec_to_time_t(convert_timeval_to_timespec(tv));
     440        tv_sec = tv.tv_sec;
    181441        tm = localtime(&tv_sec);
    182442        if (!tm) {
     
    185445        seconds=(float) (tv.tv_usec / 1000);
    186446
    187         /* check if anonymization is required */
    188 
    189         total_anonymization=lp_parm_const_string(SNUM(handle->conn),"smb_traffic_analyzer",
    190                                         "total_anonymization", NULL);
    191 
    192         anon_prefix=lp_parm_const_string(SNUM(handle->conn),"smb_traffic_analyzer",\
    193                                         "anonymize_prefix", NULL );
    194         if (anon_prefix!=NULL) {
    195                 if (total_anonymization!=NULL) {
    196                         username = talloc_asprintf(talloc_tos(),
    197                                 "%s",
    198                                 anon_prefix);
    199                 } else {
    200                         username = talloc_asprintf(talloc_tos(),
    201                                 "%s%i",
    202                                 anon_prefix,
    203                                 str_checksum(
    204                                         handle->conn->server_info->sanitized_username ) );
    205                 }
    206 
    207         } else {
    208                 username = handle->conn->server_info->sanitized_username;
    209         }
     447        /*
     448         * Check if anonymization is required, and if yes do this only for
     449         * the username here, needed vor protocol version 1. In v2 we
     450         * additionally anonymize the SID, which is done in it's marshalling
     451         * function.
     452         */
     453        username = smb_traffic_analyzer_anonymize( talloc_tos(),
     454                        handle->conn->session_info->sanitized_username,
     455                        handle);
    210456
    211457        if (!username) {
     
    213459        }
    214460
    215         str = talloc_asprintf(talloc_tos(),
     461        protocol_version = lp_parm_const_string(SNUM(handle->conn),
     462                                        "smb_traffic_analyzer",
     463                                        "protocol_version", NULL );
     464
     465
     466        if (protocol_version != NULL && strcmp(protocol_version,"V1") == 0) {
     467
     468                struct rw_data *s_data = (struct rw_data *) data;
     469
     470                /*
     471                 * in case of protocol v1, ignore any vfs operations
     472                 * except read,pread,write,pwrite, and set the "Write"
     473                 * bool accordingly, send data and return.
     474                 */
     475                if ( vfs_operation > vfs_id_pwrite ) return;
     476
     477                if ( vfs_operation <= vfs_id_pread ) Write=false;
     478                        else Write=true;
     479
     480                str = talloc_asprintf(talloc_tos(),
    216481                        "V1,%u,\"%s\",\"%s\",\"%c\",\"%s\",\"%s\","
    217482                        "\"%04d-%02d-%02d %02d:%02d:%02d.%03d\"\n",
    218                         (unsigned int)result,
     483                        (unsigned int) s_data->len,
    219484                        username,
    220                         pdb_get_domain(handle->conn->server_info->sam_account),
     485                        handle->conn->session_info->info3->base.domain.string,
    221486                        Write ? 'W' : 'R',
    222487                        handle->conn->connectpath,
    223                         file_name,
     488                        s_data->filename,
    224489                        tm->tm_year+1900,
    225490                        tm->tm_mon+1,
     
    229494                        tm->tm_sec,
    230495                        (int)seconds);
     496                len = strlen(str);
     497                if (write_data(rf_sock->sock, str, len) != len) {
     498                        DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
     499                        "error sending V1 protocol data to socket!\n"));
     500                return;
     501                }
     502
     503        } else {
     504                /**
     505                 * Protocol 2 is used by default.
     506                 */
     507
     508                switch( vfs_operation ) {
     509                case vfs_id_open: ;
     510                        str = smb_traffic_analyzer_create_string( talloc_tos(),
     511                                tm, seconds, handle, username, vfs_id_open,
     512                                3, ((struct open_data *) data)->filename,
     513                                talloc_asprintf( talloc_tos(), "%u",
     514                                ((struct open_data *) data)->mode),
     515                                talloc_asprintf( talloc_tos(), "%u",
     516                                ((struct open_data *) data)->result));
     517                        break;
     518                case vfs_id_close: ;
     519                        str = smb_traffic_analyzer_create_string( talloc_tos(),
     520                                tm, seconds, handle, username, vfs_id_close,
     521                                2, ((struct close_data *) data)->filename,
     522                                talloc_asprintf( talloc_tos(), "%u",
     523                                ((struct close_data *) data)->result));
     524                        break;
     525                case vfs_id_mkdir: ;
     526                        str = smb_traffic_analyzer_create_string( talloc_tos(),
     527                                tm, seconds, handle, username, vfs_id_mkdir, \
     528                                3, ((struct mkdir_data *) data)->path, \
     529                                talloc_asprintf( talloc_tos(), "%u", \
     530                                ((struct mkdir_data *) data)->mode), \
     531                                talloc_asprintf( talloc_tos(), "%u", \
     532                                ((struct mkdir_data *) data)->result ));
     533                        break;
     534                case vfs_id_rmdir: ;
     535                        str = smb_traffic_analyzer_create_string( talloc_tos(),
     536                                tm, seconds, handle, username, vfs_id_rmdir,
     537                                2, ((struct rmdir_data *) data)->path, \
     538                                talloc_asprintf( talloc_tos(), "%u", \
     539                                ((struct rmdir_data *) data)->result ));
     540                        break;
     541                case vfs_id_rename: ;
     542                        str = smb_traffic_analyzer_create_string( talloc_tos(),
     543                                tm, seconds, handle, username, vfs_id_rename,
     544                                3, ((struct rename_data *) data)->src, \
     545                                ((struct rename_data *) data)->dst,
     546                                talloc_asprintf(talloc_tos(), "%u", \
     547                                ((struct rename_data *) data)->result));
     548                        break;
     549                case vfs_id_chdir: ;
     550                        str = smb_traffic_analyzer_create_string( talloc_tos(),
     551                                tm, seconds, handle, username, vfs_id_chdir,
     552                                2, ((struct chdir_data *) data)->path, \
     553                                talloc_asprintf(talloc_tos(), "%u", \
     554                                ((struct chdir_data *) data)->result));
     555                        break;
     556
     557                case vfs_id_write:
     558                case vfs_id_pwrite:
     559                case vfs_id_read:
     560                case vfs_id_pread: ;
     561                        str = smb_traffic_analyzer_create_string( talloc_tos(),
     562                                tm, seconds, handle, username, vfs_operation,
     563                                2, ((struct rw_data *) data)->filename, \
     564                                talloc_asprintf(talloc_tos(), "%u", \
     565                                (unsigned int)
     566                                        ((struct rw_data *) data)->len));
     567                        break;
     568                default:
     569                        DEBUG(1, ("smb_traffic_analyzer: error! "
     570                                "wrong VFS operation id detected!\n"));
     571                        return;
     572                }
     573
     574        }
    231575
    232576        if (!str) {
     577                DEBUG(1, ("smb_traffic_analyzer_send_data: "
     578                        "unable to create string to send!\n"));
    233579                return;
    234580        }
    235581
    236         len = strlen(str);
    237 
    238         DEBUG(10, ("smb_traffic_analyzer_send_data_socket: sending %s\n",
    239                         str));
    240         if (write_data(rf_sock->sock, str, len) != len) {
    241                 DEBUG(1, ("smb_traffic_analyzer_send_data_socket: "
    242                         "error sending data to socket!\n"));
    243                 return ;
    244         }
     582
     583        /*
     584         * If configured, optain the key and run AES encryption
     585         * over the data.
     586         */
     587        become_root();
     588        akey = (char *) secrets_fetch("smb_traffic_analyzer_key", &size);
     589        unbecome_root();
     590        if ( akey != NULL ) {
     591                state_flags[2] = 'E';
     592                DEBUG(10, ("smb_traffic_analyzer_send_data_socket: a key was"
     593                        " found, encrypting data!\n"));
     594                output = smb_traffic_analyzer_encrypt( talloc_tos(),
     595                                                akey, str, &len);
     596                SAFE_FREE(akey);
     597                header = smb_traffic_analyzer_create_header( talloc_tos(),
     598                                                state_flags, len);
     599
     600                DEBUG(10, ("smb_traffic_analyzer_send_data_socket:"
     601                        " header created for crypted data: %s\n", header));
     602                smb_traffic_analyzer_write_data(header, output, len,
     603                                                        rf_sock->sock);
     604                return;
     605
     606        }
     607
     608        len = strlen(str);
     609        header = smb_traffic_analyzer_create_header( talloc_tos(),
     610                                state_flags, len);
     611        smb_traffic_analyzer_write_data(header, str, strlen(str),
     612                                rf_sock->sock);
     613
    245614}
    246615
     
    337706}
    338707
    339 /* VFS Functions: write, read, pread, pwrite for now */
     708/* VFS Functions */
     709static int smb_traffic_analyzer_chdir(vfs_handle_struct *handle, \
     710                        const char *path)
     711{
     712        struct chdir_data s_data;
     713        s_data.result = SMB_VFS_NEXT_CHDIR(handle, path);
     714        s_data.path = path;
     715        DEBUG(10, ("smb_traffic_analyzer_chdir: CHDIR: %s\n", path));
     716        smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_chdir);
     717        return s_data.result;
     718}
     719
     720static int smb_traffic_analyzer_rename(vfs_handle_struct *handle, \
     721                const struct smb_filename *smb_fname_src,
     722                const struct smb_filename *smb_fname_dst)
     723{
     724        struct rename_data s_data;
     725        s_data.result = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, \
     726                smb_fname_dst);
     727        s_data.src = smb_fname_src->base_name;
     728        s_data.dst = smb_fname_dst->base_name;
     729        DEBUG(10, ("smb_traffic_analyzer_rename: RENAME: %s / %s\n",
     730                smb_fname_src->base_name,
     731                smb_fname_dst->base_name));
     732        smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rename);
     733        return s_data.result;
     734}
     735
     736static int smb_traffic_analyzer_rmdir(vfs_handle_struct *handle, \
     737                        const char *path)
     738{
     739        struct rmdir_data s_data;
     740        s_data.result = SMB_VFS_NEXT_RMDIR(handle, path);
     741        s_data.path = path;
     742        DEBUG(10, ("smb_traffic_analyzer_rmdir: RMDIR: %s\n", path));
     743        smb_traffic_analyzer_send_data(handle, &s_data, vfs_id_rmdir);
     744        return s_data.result;
     745}
     746
     747static int smb_traffic_analyzer_mkdir(vfs_handle_struct *handle, \
     748                        const char *path, mode_t mode)
     749{
     750        struct mkdir_data s_data;
     751        s_data.result = SMB_VFS_NEXT_MKDIR(handle, path, mode);
     752        s_data.path = path;
     753        s_data.mode = mode;
     754        DEBUG(10, ("smb_traffic_analyzer_mkdir: MKDIR: %s\n", path));
     755        smb_traffic_analyzer_send_data(handle,
     756                        &s_data,
     757                        vfs_id_mkdir);
     758        return s_data.result;
     759}
     760
     761static ssize_t smb_traffic_analyzer_sendfile(vfs_handle_struct *handle,
     762                                int tofd,
     763                                files_struct *fromfsp,
     764                                const DATA_BLOB *hdr,
     765                                SMB_OFF_T offset,
     766                                size_t n)
     767{
     768        struct rw_data s_data;
     769        s_data.len = SMB_VFS_NEXT_SENDFILE(handle,
     770                        tofd, fromfsp, hdr, offset, n);
     771        s_data.filename = fromfsp->fsp_name->base_name;
     772        DEBUG(10, ("smb_traffic_analyzer_sendfile: sendfile(r): %s\n",
     773                fsp_str_dbg(fromfsp)));
     774        smb_traffic_analyzer_send_data(handle,
     775                &s_data,
     776                vfs_id_read);
     777        return s_data.len;
     778}
     779
     780static ssize_t smb_traffic_analyzer_recvfile(vfs_handle_struct *handle,
     781                                int fromfd,
     782                                files_struct *tofsp,
     783                                SMB_OFF_T offset,
     784                                size_t n)
     785{
     786        struct rw_data s_data;
     787        s_data.len = SMB_VFS_NEXT_RECVFILE(handle,
     788                        fromfd, tofsp, offset, n);
     789        s_data.filename = tofsp->fsp_name->base_name;
     790        DEBUG(10, ("smb_traffic_analyzer_recvfile: recvfile(w): %s\n",
     791                fsp_str_dbg(tofsp)));
     792        smb_traffic_analyzer_send_data(handle,
     793                &s_data,
     794                vfs_id_write);
     795        return s_data.len;
     796}
     797
    340798
    341799static ssize_t smb_traffic_analyzer_read(vfs_handle_struct *handle, \
    342800                                files_struct *fsp, void *data, size_t n)
    343801{
    344         ssize_t result;
    345 
    346         result = SMB_VFS_NEXT_READ(handle, fsp, data, n);
     802        struct rw_data s_data;
     803
     804        s_data.len = SMB_VFS_NEXT_READ(handle, fsp, data, n);
     805        s_data.filename = fsp->fsp_name->base_name;
    347806        DEBUG(10, ("smb_traffic_analyzer_read: READ: %s\n", fsp_str_dbg(fsp)));
    348807
    349808        smb_traffic_analyzer_send_data(handle,
    350                         result,
    351                         fsp->fsp_name->base_name,
    352                         false);
    353         return result;
     809                        &s_data,
     810                        vfs_id_read);
     811        return s_data.len;
    354812}
    355813
     
    358816                files_struct *fsp, void *data, size_t n, SMB_OFF_T offset)
    359817{
    360         ssize_t result;
    361 
    362         result = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
    363 
     818        struct rw_data s_data;
     819
     820        s_data.len = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
     821        s_data.filename = fsp->fsp_name->base_name;
    364822        DEBUG(10, ("smb_traffic_analyzer_pread: PREAD: %s\n",
    365823                   fsp_str_dbg(fsp)));
    366824
    367825        smb_traffic_analyzer_send_data(handle,
    368                         result,
    369                         fsp->fsp_name->base_name,
    370                         false);
    371 
    372         return result;
     826                        &s_data,
     827                        vfs_id_pread);
     828
     829        return s_data.len;
    373830}
    374831
     
    376833                        files_struct *fsp, const void *data, size_t n)
    377834{
    378         ssize_t result;
    379 
    380         result = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
    381 
     835        struct rw_data s_data;
     836
     837        s_data.len = SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
     838        s_data.filename = fsp->fsp_name->base_name;
    382839        DEBUG(10, ("smb_traffic_analyzer_write: WRITE: %s\n",
    383840                   fsp_str_dbg(fsp)));
    384841
    385842        smb_traffic_analyzer_send_data(handle,
    386                         result,
    387                         fsp->fsp_name->base_name,
    388                         true);
    389         return result;
     843                        &s_data,
     844                        vfs_id_write);
     845        return s_data.len;
    390846}
    391847
     
    393849             files_struct *fsp, const void *data, size_t n, SMB_OFF_T offset)
    394850{
    395         ssize_t result;
    396 
    397         result = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
    398 
    399         DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", fsp_str_dbg(fsp)));
     851        struct rw_data s_data;
     852
     853        s_data.len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
     854        s_data.filename = fsp->fsp_name->base_name;
     855        DEBUG(10, ("smb_traffic_analyzer_pwrite: PWRITE: %s\n", \
     856                fsp_str_dbg(fsp)));
    400857
    401858        smb_traffic_analyzer_send_data(handle,
    402                         result,
    403                         fsp->fsp_name->base_name,
    404                         true);
    405         return result;
    406 }
    407 
     859                        &s_data,
     860                        vfs_id_pwrite);
     861        return s_data.len;
     862}
     863
     864static int smb_traffic_analyzer_open(vfs_handle_struct *handle, \
     865        struct smb_filename *smb_fname, files_struct *fsp,\
     866        int flags, mode_t mode)
     867{
     868        struct open_data s_data;
     869
     870        s_data.result = SMB_VFS_NEXT_OPEN( handle, smb_fname, fsp,
     871                        flags, mode);
     872        DEBUG(10,("smb_traffic_analyzer_open: OPEN: %s\n",
     873                fsp_str_dbg(fsp)));
     874        s_data.filename = fsp->fsp_name->base_name;
     875        s_data.mode = mode;
     876        smb_traffic_analyzer_send_data(handle,
     877                        &s_data,
     878                        vfs_id_open);
     879        return s_data.result;
     880}
     881
     882static int smb_traffic_analyzer_close(vfs_handle_struct *handle, \
     883        files_struct *fsp)
     884{
     885        struct close_data s_data;
     886        s_data.result = SMB_VFS_NEXT_CLOSE(handle, fsp);
     887        DEBUG(10,("smb_traffic_analyzer_close: CLOSE: %s\n",
     888                fsp_str_dbg(fsp)));
     889        s_data.filename = fsp->fsp_name->base_name;
     890        smb_traffic_analyzer_send_data(handle,
     891                        &s_data,
     892                        vfs_id_close);
     893        return s_data.result;
     894}
     895
     896       
    408897static struct vfs_fn_pointers vfs_smb_traffic_analyzer_fns = {
    409898        .connect_fn = smb_traffic_analyzer_connect,
     
    412901        .write = smb_traffic_analyzer_write,
    413902        .pwrite = smb_traffic_analyzer_pwrite,
     903        .mkdir = smb_traffic_analyzer_mkdir,
     904        .rename = smb_traffic_analyzer_rename,
     905        .chdir = smb_traffic_analyzer_chdir,
     906        .open_fn = smb_traffic_analyzer_open,
     907        .rmdir = smb_traffic_analyzer_rmdir,
     908        .close_fn = smb_traffic_analyzer_close,
     909        .sendfile = smb_traffic_analyzer_sendfile,
     910        .recvfile = smb_traffic_analyzer_recvfile
    414911};
    415912
    416913/* Module initialization */
    417 
    418914NTSTATUS vfs_smb_traffic_analyzer_init(void)
    419915{
  • trunk/server/source3/modules/vfs_solarisacl.c

    r414 r745  
    2020
    2121#include "includes.h"
    22 
     22#include "system/filesys.h"
     23#include "smbd/smbd.h"
     24#include "modules/vfs_solarisacl.h"
    2325
    2426/* typedef struct acl SOLARIS_ACE_T; */
  • trunk/server/source3/modules/vfs_streams_depot.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "smbd/smbd.h"
     22#include "system/filesys.h"
    2123
    2224#undef DBGC_CLASS
     
    662664        struct smb_filename *smb_fname_src_stream = NULL;
    663665        struct smb_filename *smb_fname_dst_stream = NULL;
    664         struct smb_filename *smb_fname_dst_mod = NULL;
    665666        bool src_is_stream, dst_is_stream;
    666667        NTSTATUS status;
     
    693694        }
    694695
    695         /*
    696          * Handle passing in a stream name without the base file.  This is
    697          * exercised by the NTRENAME streams rename path.
    698          */
    699         if (StrCaseCmp(smb_fname_dst->base_name, "./") == 0) {
    700                 status = create_synthetic_smb_fname(talloc_tos(),
    701                                                     smb_fname_src->base_name,
    702                                                     smb_fname_dst->stream_name,
    703                                                     NULL, &smb_fname_dst_mod);
    704                 if (!NT_STATUS_IS_OK(status)) {
    705                         errno = map_errno_from_nt_status(status);
    706                         goto done;
    707                 }
    708         }
    709 
    710         status = stream_smb_fname(handle, (smb_fname_dst_mod ?
    711                                            smb_fname_dst_mod : smb_fname_dst),
     696        status = stream_smb_fname(handle, smb_fname_dst,
    712697                                  &smb_fname_dst_stream, false);
    713698        if (!NT_STATUS_IS_OK(status)) {
     
    722707        TALLOC_FREE(smb_fname_src_stream);
    723708        TALLOC_FREE(smb_fname_dst_stream);
    724         TALLOC_FREE(smb_fname_dst_mod);
    725709        return ret;
    726710}
     
    893877static struct vfs_fn_pointers vfs_streams_depot_fns = {
    894878        .fs_capabilities = streams_depot_fs_capabilities,
    895         .open = streams_depot_open,
     879        .open_fn = streams_depot_open,
    896880        .stat = streams_depot_stat,
    897881        .lstat = streams_depot_lstat,
  • trunk/server/source3/modules/vfs_streams_xattr.c

    r480 r745  
    2323
    2424#include "includes.h"
     25#include "smbd/smbd.h"
     26#include "system/filesys.h"
     27#include "../lib/crypto/md5.h"
    2528
    2629#undef DBGC_CLASS
     
    10231026}
    10241027
     1028static int streams_xattr_fallocate(struct vfs_handle_struct *handle,
     1029                                        struct files_struct *fsp,
     1030                                        enum vfs_fallocate_mode mode,
     1031                                        SMB_OFF_T offset,
     1032                                        SMB_OFF_T len)
     1033{
     1034        struct stream_io *sio =
     1035                (struct stream_io *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
     1036
     1037        DEBUG(10, ("streams_xattr_fallocate called for file %s offset %.0f"
     1038                "len = %.0f\n",
     1039                fsp_str_dbg(fsp), (double)offset, (double)len));
     1040
     1041        if (sio == NULL) {
     1042                return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
     1043        }
     1044
     1045        if (!streams_xattr_recheck(sio)) {
     1046                return errno;
     1047        }
     1048
     1049        /* Let the pwrite code path handle it. */
     1050        return ENOSYS;
     1051}
     1052
     1053
    10251054static struct vfs_fn_pointers vfs_streams_xattr_fns = {
    10261055        .fs_capabilities = streams_xattr_fs_capabilities,
    1027         .open = streams_xattr_open,
     1056        .open_fn = streams_xattr_open,
    10281057        .stat = streams_xattr_stat,
    10291058        .fstat = streams_xattr_fstat,
     
    10341063        .rename = streams_xattr_rename,
    10351064        .ftruncate = streams_xattr_ftruncate,
     1065        .fallocate = streams_xattr_fallocate,
    10361066        .streaminfo = streams_xattr_streaminfo,
    10371067};
  • trunk/server/source3/modules/vfs_syncops.c

    r414 r745  
    33 *
    44 * Copyright (C) Andrew Tridgell     2007
     5 * Copyright (C) Christian Ambach, 2010-2011
    56 *
    67 * This program is free software; you can redistribute it and/or modify
     
    2021
    2122#include "includes.h"
     23#include "system/filesys.h"
     24#include "smbd/smbd.h"
    2225
    2326/*
     
    3235  On those filesystems this module provides a way to perform those
    3336  operations safely. 
    34  */
    35 
    36 /*
     37
    3738  most of the performance loss with this module is in fsync on close().
    38   You can disable that with syncops:onclose = no
    39  */
    40 static bool sync_onclose;
     39  You can disable that with
     40     syncops:onclose = no
     41  that can be set either globally or per share.
     42
     43  On certain filesystems that only require the last data written to be
     44  fsync()'ed, you can disable the metadata synchronization of this module with
     45     syncops:onmeta = no
     46  This option can be set either globally or per share.
     47
     48  you can also disable the module completely for a share with
     49     syncops:disable = true
     50
     51 */
     52
     53struct syncops_config_data {
     54        bool onclose;
     55        bool onmeta;
     56        bool disable;
     57};
    4158
    4259/*
     
    126143                          const struct smb_filename *smb_fname_dst)
    127144{
    128         int ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
    129         if (ret == 0) {
     145
     146        int ret;
     147        struct syncops_config_data *config;
     148
     149        SMB_VFS_HANDLE_GET_DATA(handle, config,
     150                                struct syncops_config_data,
     151                                return -1);
     152
     153        ret = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
     154        if (ret == 0 && config->onmeta && !config->disable) {
    130155                syncops_two_names(smb_fname_src->base_name,
    131156                                  smb_fname_dst->base_name);
     
    136161/* handle the rest with a macro */
    137162#define SYNCOPS_NEXT(op, fname, args) do {   \
    138         int ret = SMB_VFS_NEXT_ ## op args; \
    139         if (ret == 0 && fname) syncops_name(fname); \
     163        int ret; \
     164        struct syncops_config_data *config; \
     165        SMB_VFS_HANDLE_GET_DATA(handle, config, \
     166                                struct syncops_config_data, \
     167                                return -1); \
     168        ret = SMB_VFS_NEXT_ ## op args; \
     169        if (ret == 0 \
     170                && config->onmeta && !config->disable  \
     171                && fname) syncops_name(fname); \
    140172        return ret; \
    141173} while (0)
    142174
    143175#define SYNCOPS_NEXT_SMB_FNAME(op, fname, args) do {   \
    144         int ret = SMB_VFS_NEXT_ ## op args; \
    145         if (ret == 0 && fname) syncops_smb_fname(fname); \
     176        int ret; \
     177        struct syncops_config_data *config; \
     178        SMB_VFS_HANDLE_GET_DATA(handle, config, \
     179                                struct syncops_config_data, \
     180                                return -1); \
     181        ret = SMB_VFS_NEXT_ ## op args; \
     182        if (ret == 0 \
     183        && config->onmeta && !config->disable \
     184        && fname) syncops_smb_fname(fname); \
    146185        return ret; \
    147186} while (0)
     
    192231static int syncops_close(vfs_handle_struct *handle, files_struct *fsp)
    193232{
    194         if (fsp->can_write && sync_onclose) {
     233        struct syncops_config_data *config;
     234
     235        SMB_VFS_HANDLE_GET_DATA(handle, config,
     236                                struct syncops_config_data,
     237                                return -1);
     238
     239        if (fsp->can_write && config->onclose) {
    195240                /* ideally we'd only do this if we have written some
    196241                 data, but there is no flag for that in fsp yet. */
     
    200245}
    201246
     247static int syncops_connect(struct vfs_handle_struct *handle, const char *service,
     248                           const char *user)
     249{
     250
     251        struct syncops_config_data *config;
     252        int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
     253        if (ret < 0) {
     254                return ret;
     255        }
     256
     257        config = talloc_zero(handle->conn, struct syncops_config_data);
     258        if (!config) {
     259                SMB_VFS_NEXT_DISCONNECT(handle);
     260                DEBUG(0, ("talloc_zero() failed\n"));
     261                return -1;
     262        }
     263
     264        config->onclose = lp_parm_bool(SNUM(handle->conn), "syncops",
     265                                        "onclose", true);
     266
     267        config->onmeta = lp_parm_bool(SNUM(handle->conn), "syncops",
     268                                        "onmeta", true);
     269
     270        config->disable = lp_parm_bool(SNUM(handle->conn), "syncops",
     271                                        "disable", false);
     272
     273        SMB_VFS_HANDLE_SET_DATA(handle, config,
     274                                NULL, struct syncops_config_data,
     275                                return -1);
     276
     277        return 0;
     278
     279}
    202280
    203281static struct vfs_fn_pointers vfs_syncops_fns = {
     282        .connect_fn = syncops_connect,
    204283        .mkdir = syncops_mkdir,
    205284        .rmdir = syncops_rmdir,
    206         .open = syncops_open,
     285        .open_fn = syncops_open,
    207286        .rename = syncops_rename,
    208287        .unlink = syncops_unlink,
     
    223302                return ret;
    224303
    225         sync_onclose = lp_parm_bool(-1, "syncops", "onclose", true);
    226        
    227304        return ret;
    228305}
  • trunk/server/source3/modules/vfs_tru64acl.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
     23#include "modules/vfs_tru64acl.h"
    2124
    2225/* prototypes for private functions first - for clarity */
  • trunk/server/source3/modules/vfs_tsmsm.c

    r414 r745  
    4040
    4141#include "includes.h"
     42#include "smbd/smbd.h"
    4243
    4344#ifndef USE_DMAPI
     
    147148
    148149static bool tsmsm_is_offline(struct vfs_handle_struct *handle,
    149                             const char *path,
    150                             SMB_STRUCT_STAT *stbuf) {
     150                             const struct smb_filename *fname,
     151                             SMB_STRUCT_STAT *stbuf)
     152{
    151153        struct tsmsm_struct *tsmd = (struct tsmsm_struct *) handle->data;
    152154        const dm_sessid_t *dmsession_id;
     
    159161        char *buf = NULL;
    160162        size_t buflen;
     163        NTSTATUS status;
     164        char *path;
     165
     166        status = get_full_smb_filename(talloc_tos(), fname, &path);
     167        if (!NT_STATUS_IS_OK(status)) {
     168                errno = map_errno_from_nt_status(status);
     169                return false;
     170        }
    161171
    162172        /* if the file has more than FILE_IS_ONLINE_RATIO of blocks available,
    163173           then assume it is not offline (it may not be 100%, as it could be sparse) */
    164         if (512 * (off_t)stbuf->st_ex_blocks >=
     174        if (512 * stbuf->st_ex_blocks >=
    165175            stbuf->st_ex_size * tsmd->online_ratio) {
    166                 DEBUG(10,("%s not offline: st_blocks=%ld st_size=%ld "
     176                DEBUG(10,("%s not offline: st_blocks=%llu st_size=%llu "
    167177                          "online_ratio=%.2f\n", path,
    168                           (long)stbuf->st_ex_blocks,
    169                           (long)stbuf->st_ex_size, tsmd->online_ratio));
     178                          (unsigned long long)stbuf->st_ex_blocks,
     179                          (unsigned long long)stbuf->st_ex_size, tsmd->online_ratio));
    170180                return false;
    171181        }
     
    264274        */
    265275        if(SMB_VFS_FSTAT(fsp, &sbuf) == 0) {
    266                 DEBUG(10,("tsmsm_aio_force st_blocks=%ld st_size=%ld "
    267                           "online_ratio=%.2f\n", (long)sbuf.st_ex_blocks,
    268                           (long)sbuf.st_ex_size, tsmd->online_ratio));
    269                 return !(512 * (off_t)sbuf.st_ex_blocks >=
     276                DEBUG(10,("tsmsm_aio_force st_blocks=%llu st_size=%llu "
     277                          "online_ratio=%.2f\n", (unsigned long long)sbuf.st_ex_blocks,
     278                          (unsigned long long)sbuf.st_ex_size, tsmd->online_ratio));
     279                return !(512 * sbuf.st_ex_blocks >=
    270280                         sbuf.st_ex_size * tsmd->online_ratio);
    271281        }
     
    341351
    342352static int tsmsm_set_offline(struct vfs_handle_struct *handle,
    343                              const char *path) {
     353                             const struct smb_filename *fname)
     354{
    344355        struct tsmsm_struct *tsmd = (struct tsmsm_struct *) handle->data;
    345356        int result = 0;
    346357        char *command;
     358        NTSTATUS status;
     359        char *path;
    347360
    348361        if (tsmd->hsmscript == NULL) {
     
    351364                return 0;
    352365        }
     366
     367        status = get_full_smb_filename(talloc_tos(), fname, &path);
     368        if (!NT_STATUS_IS_OK(status)) {
     369                errno = map_errno_from_nt_status(status);
     370                return false;
     371        }
    353372
    354373        /* Now, call the script */
  • trunk/server/source3/modules/vfs_xattr_tdb.c

    r414 r745  
    1919
    2020#include "includes.h"
     21#include "system/filesys.h"
     22#include "smbd/smbd.h"
    2123#include "librpc/gen_ndr/xattr.h"
    2224#include "librpc/gen_ndr/ndr_xattr.h"
     25#include "../librpc/gen_ndr/ndr_netlogon.h"
     26#include "dbwrap.h"
     27#include "util_tdb.h"
    2328
    2429#undef DBGC_CLASS
     
    4853        blob = data_blob_const(data->dptr, data->dsize);
    4954
    50         ndr_err = ndr_pull_struct_blob(
    51                 &blob, result, NULL, result,
     55        ndr_err = ndr_pull_struct_blob(&blob, result, result,
    5256                (ndr_pull_flags_fn_t)ndr_pull_tdb_xattrs);
    5357
     
    5660                          ndr_errstr(ndr_err)));
    5761                TALLOC_FREE(result);
    58                 return ndr_map_error2ntstatus(ndr_err);;
     62                return ndr_map_error2ntstatus(ndr_err);
    5963        }
    6064
     
    7478        enum ndr_err_code ndr_err;
    7579
    76         ndr_err = ndr_push_struct_blob(
    77                 &blob, mem_ctx, NULL, attribs,
     80        ndr_err = ndr_push_struct_blob(&blob, mem_ctx, attribs,
    7881                (ndr_push_flags_fn_t)ndr_push_tdb_xattrs);
    7982
     
    8184                DEBUG(0, ("ndr_push_tdb_xattrs failed: %s\n",
    8285                          ndr_errstr(ndr_err)));
    83                 return ndr_map_error2ntstatus(ndr_err);;
     86                return ndr_map_error2ntstatus(ndr_err);
    8487        }
    8588
     
    725728                          const char *user)
    726729{
    727         fstring sname;
     730        char *sname = NULL;
    728731        int res, snum;
    729732        struct db_context *db;
     
    734737        }
    735738
    736         fstrcpy(sname, service);
    737         snum = find_service(sname);
    738         if (snum == -1) {
     739        snum = find_service(talloc_tos(), service, &sname);
     740        if (snum == -1 || sname == NULL) {
    739741                /*
    740742                 * Should not happen, but we should not fail just *here*.
  • trunk/server/source3/modules/vfs_zfsacl.c

    r414 r745  
    2424
    2525#include "includes.h"
     26#include "system/filesys.h"
     27#include "smbd/smbd.h"
    2628#include "nfs4_acls.h"
     29
     30#if HAVE_FREEBSD_SUNACL_H
     31#include "sunacl.h"
     32#endif
    2733
    2834#undef DBGC_CLASS
     
    107113        SMB4ACE_T *smbace;
    108114        TALLOC_CTX      *mem_ctx;
     115        bool have_special_id = false;
    109116
    110117        /* allocate the field of ZFS aces */
     
    124131                acebuf[i].a_flags       = aceprop->aceFlags;
    125132                acebuf[i].a_access_mask = aceprop->aceMask;
     133                /* SYNC on acls is a no-op on ZFS.
     134                   See bug #7909. */
     135                acebuf[i].a_access_mask &= ~SMB_ACE4_SYNCHRONIZE;
    126136                acebuf[i].a_who         = aceprop->who.id;
    127137                if(aceprop->flags & SMB_ACE4_ID_SPECIAL) {
     
    141151                                continue; /* don't add it !!! */
    142152                        }
     153                        have_special_id = true;
    143154                }
    144155        }
     156
     157        if (!have_special_id
     158            && lp_parm_bool(fsp->conn->params->service, "zfsacl",
     159                            "denymissingspecial", false)) {
     160                errno = EACCES;
     161                return false;
     162        }
     163
    145164        SMB_ASSERT(i == naces);
    146165
     
    209228                         files_struct *fsp,
    210229                         uint32 security_info_sent,
    211                          const SEC_DESC *psd)
     230                         const struct security_descriptor *psd)
    212231{
    213232        return zfs_set_nt_acl(handle, fsp, security_info_sent, psd);
     
    245264*/
    246265
    247 SMB_ACL_T zfsacl_fail__sys_acl_get_file(vfs_handle_struct *handle,
    248                                         const char *path_p,
    249                                         SMB_ACL_TYPE_T type)
     266static SMB_ACL_T zfsacl_fail__sys_acl_get_file(vfs_handle_struct *handle,
     267                                               const char *path_p,
     268                                               SMB_ACL_TYPE_T type)
    250269{
    251270        return (SMB_ACL_T)NULL;
    252271}
    253 SMB_ACL_T zfsacl_fail__sys_acl_get_fd(vfs_handle_struct *handle,
    254                                       files_struct *fsp,
    255                                       int fd)
     272
     273static SMB_ACL_T zfsacl_fail__sys_acl_get_fd(vfs_handle_struct *handle,
     274                                             files_struct *fsp)
    256275{
    257276        return (SMB_ACL_T)NULL;
    258277}
    259278
    260 int zfsacl_fail__sys_acl_set_file(vfs_handle_struct *handle,
    261                                   const char *name,
    262                                   SMB_ACL_TYPE_T type,
    263                                   SMB_ACL_T theacl)
     279static int zfsacl_fail__sys_acl_set_file(vfs_handle_struct *handle,
     280                                        const char *name,
     281                                        SMB_ACL_TYPE_T type,
     282                                        SMB_ACL_T theacl)
    264283{
    265284        return -1;
    266285}
    267286
    268 int zfsacl_fail__sys_acl_set_fd(vfs_handle_struct *handle,
    269                                 files_struct *fsp,
    270                                 int fd, SMB_ACL_T theacl)
     287static int zfsacl_fail__sys_acl_set_fd(vfs_handle_struct *handle,
     288                                       files_struct *fsp,
     289                                      SMB_ACL_T theacl)
    271290{
    272291        return -1;
    273292}
    274293
    275 int zfsacl_fail__sys_acl_delete_def_file(vfs_handle_struct *handle,
    276                                          const char *path)
     294static int zfsacl_fail__sys_acl_delete_def_file(vfs_handle_struct *handle,
     295                                                const char *path)
    277296{
    278297        return -1;
  • trunk/server/source3/modules/weird.c

    r414 r745  
    128128NTSTATUS charset_weird_init(void)
    129129{
    130         return smb_register_charset(&weird_functions);
     130        if (!smb_register_charset(&weird_functions)) {
     131                return NT_STATUS_INTERNAL_ERROR;
     132        }
     133        return NT_STATUS_OK;
    131134}
Note: See TracChangeset for help on using the changeset viewer.