Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/trans2.c

    r860 r988  
    3333#include "../librpc/gen_ndr/xattr.h"
    3434#include "../librpc/gen_ndr/ndr_security.h"
     35#include "../librpc/gen_ndr/open_files.h"
    3536#include "libcli/security/security.h"
    3637#include "trans2.h"
     
    3839#include "smbprofile.h"
    3940#include "rpc_server/srv_pipe_hnd.h"
    40 #include "libsmb/libsmb.h"
     41#include "printing.h"
     42#include "lib/util_ea.h"
     43#include "lib/readdir_attr.h"
    4144
    4245#define DIR_ENTRY_SAFETY_MARGIN 4096
     
    5154                                files_struct *fsp,
    5255                                const SMB_STRUCT_STAT *psbuf);
     56
     57/****************************************************************************
     58 Check if an open file handle or pathname is a symlink.
     59****************************************************************************/
     60
     61static NTSTATUS refuse_symlink(connection_struct *conn,
     62                        const files_struct *fsp,
     63                        const char *name)
     64{
     65        SMB_STRUCT_STAT sbuf;
     66        const SMB_STRUCT_STAT *pst = NULL;
     67
     68        if (fsp) {
     69                pst = &fsp->fsp_name->st;
     70        } else {
     71                int ret = vfs_stat_smb_basename(conn,
     72                                name,
     73                                &sbuf);
     74                if (ret == -1) {
     75                        return map_nt_error_from_unix(errno);
     76                }
     77                pst = &sbuf;
     78        }
     79        if (S_ISLNK(pst->st_ex_mode)) {
     80                return NT_STATUS_ACCESS_DENIED;
     81        }
     82        return NT_STATUS_OK;
     83}
     84
     85NTSTATUS check_access_fsp(const struct files_struct *fsp,
     86                          uint32_t access_mask)
     87{
     88        if (!(fsp->access_mask & access_mask)) {
     89                return NT_STATUS_ACCESS_DENIED;
     90        }
     91        return NT_STATUS_OK;
     92}
     93
     94/********************************************************************
     95 The canonical "check access" based on object handle or path function.
     96********************************************************************/
     97
     98NTSTATUS check_access(connection_struct *conn,
     99                                files_struct *fsp,
     100                                const struct smb_filename *smb_fname,
     101                                uint32_t access_mask)
     102{
     103        NTSTATUS status;
     104
     105        if (fsp) {
     106                status = check_access_fsp(fsp, access_mask);
     107        } else {
     108                status = smbd_check_access_rights(conn, smb_fname,
     109                                                  false, access_mask);
     110        }
     111
     112        return status;
     113}
    53114
    54115/********************************************************************
     
    94155****************************************************************************/
    95156
    96 static bool samba_private_attr_name(const char *unix_ea_name)
     157bool samba_private_attr_name(const char *unix_ea_name)
    97158{
    98159        static const char * const prohibited_ea_names[] = {
     
    110171                        return true;
    111172        }
    112         if (StrnCaseCmp(unix_ea_name, SAMBA_XATTR_DOSSTREAM_PREFIX,
     173        if (strncasecmp_m(unix_ea_name, SAMBA_XATTR_DOSSTREAM_PREFIX,
    113174                        strlen(SAMBA_XATTR_DOSSTREAM_PREFIX)) == 0) {
    114175                return true;
     
    132193 again:
    133194
    134         val = TALLOC_REALLOC_ARRAY(mem_ctx, val, char, attr_size);
     195        val = talloc_realloc(mem_ctx, val, char, attr_size);
    135196        if (!val) {
    136197                return NT_STATUS_NO_MEMORY;
     
    153214
    154215        DEBUG(10,("get_ea_value: EA %s is of length %u\n", ea_name, (unsigned int)sizeret));
    155         dump_data(10, (uint8 *)val, sizeret);
     216        dump_data(10, (uint8_t *)val, sizeret);
    156217
    157218        pea->flags = 0;
     
    182243        size_t num_names;
    183244        ssize_t sizeret = -1;
     245        NTSTATUS status;
     246
     247        if (pnames) {
     248                *pnames = NULL;
     249        }
     250        *pnum_names = 0;
    184251
    185252        if (!lp_ea_support(SNUM(conn))) {
    186                 if (pnames) {
    187                         *pnames = NULL;
    188                 }
    189                 *pnum_names = 0;
     253                return NT_STATUS_OK;
     254        }
     255
     256        status = refuse_symlink(conn, fsp, fname);
     257        if (!NT_STATUS_IS_OK(status)) {
     258                /*
     259                 * Just return no EA's on a symlink.
     260                 */
    190261                return NT_STATUS_OK;
    191262        }
     
    195266         */
    196267
    197         names = TALLOC_ARRAY(mem_ctx, char *, 1);
     268        names = talloc_array(mem_ctx, char *, 1);
    198269        if (names == NULL) {
    199270                DEBUG(0, ("talloc failed\n"));
     
    203274        while (ea_namelist_size <= 65536) {
    204275
    205                 ea_namelist = TALLOC_REALLOC_ARRAY(
     276                ea_namelist = talloc_realloc(
    206277                        names, ea_namelist, char, ea_namelist_size);
    207278                if (ea_namelist == NULL) {
     
    232303        }
    233304
    234         DEBUG(10, ("get_ea_list_from_file: ea_namelist size = %u\n",
    235                    (unsigned int)sizeret));
     305        DEBUG(10, ("%s: ea_namelist size = %u\n",
     306                   __func__, (unsigned int)sizeret));
    236307
    237308        if (sizeret == 0) {
    238309                TALLOC_FREE(names);
    239                 if (pnames) {
    240                         *pnames = NULL;
    241                 }
    242                 *pnum_names = 0;
    243310                return NT_STATUS_OK;
    244311        }
     
    262329        }
    263330
    264         tmp = TALLOC_REALLOC_ARRAY(mem_ctx, names, char *, num_names);
     331        tmp = talloc_realloc(mem_ctx, names, char *, num_names);
    265332        if (tmp == NULL) {
    266333                DEBUG(0, ("talloc failed\n"));
     
    289356****************************************************************************/
    290357
    291 static struct ea_list *get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp,
    292                                         const char *fname, size_t *pea_total_len)
     358static NTSTATUS get_ea_list_from_file_path(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp,
     359                                      const char *fname, size_t *pea_total_len, struct ea_list **ea_list)
    293360{
    294361        /* Get a list of all xattrs. Max namesize is 64k. */
     
    299366
    300367        *pea_total_len = 0;
    301 
    302         if (!lp_ea_support(SNUM(conn))) {
    303                 return NULL;
    304         }
     368        *ea_list = NULL;
    305369
    306370        status = get_ea_names_from_file(talloc_tos(), conn, fsp, fname,
    307371                                        &names, &num_names);
    308372
    309         if (!NT_STATUS_IS_OK(status) || (num_names == 0)) {
    310                 return NULL;
     373        if (!NT_STATUS_IS_OK(status)) {
     374                return status;
     375        }
     376
     377        if (num_names == 0) {
     378                *ea_list = NULL;
     379                return NT_STATUS_OK;
    311380        }
    312381
     
    319388                        continue;
    320389
    321                 listp = TALLOC_P(mem_ctx, struct ea_list);
     390                /*
     391                 * Filter out any underlying POSIX EA names
     392                 * that a Windows client can't handle.
     393                 */
     394                if (!lp_posix_pathnames() &&
     395                                is_invalid_windows_ea_name(names[i])) {
     396                        continue;
     397                }
     398
     399                listp = talloc(mem_ctx, struct ea_list);
    322400                if (listp == NULL) {
    323                         return NULL;
    324                 }
    325 
    326                 if (!NT_STATUS_IS_OK(get_ea_value(mem_ctx, conn, fsp,
    327                                                   fname, names[i],
    328                                                   &listp->ea))) {
    329                         return NULL;
     401                        return NT_STATUS_NO_MEMORY;
     402                }
     403
     404                status = get_ea_value(listp, conn, fsp,
     405                                      fname, names[i],
     406                                      &listp->ea);
     407
     408                if (!NT_STATUS_IS_OK(status)) {
     409                        TALLOC_FREE(listp);
     410                        return status;
    330411                }
    331412
     
    348429                          (unsigned int)listp->ea.value.length));
    349430
    350                 DLIST_ADD_END(ea_list_head, listp, struct ea_list *);
     431                DLIST_ADD_END(ea_list_head, listp);
    351432
    352433        }
     
    360441                   (unsigned int)*pea_total_len));
    361442
    362         return ea_list_head;
     443        *ea_list = ea_list_head;
     444        return NT_STATUS_OK;
     445}
     446
     447static NTSTATUS get_ea_list_from_file(TALLOC_CTX *mem_ctx, connection_struct *conn, files_struct *fsp,
     448                                      const struct smb_filename *smb_fname, size_t *pea_total_len, struct ea_list **ea_list)
     449{
     450        *pea_total_len = 0;
     451        *ea_list = NULL;
     452
     453        if (!lp_ea_support(SNUM(conn))) {
     454                return NT_STATUS_OK;
     455        }
     456
     457        if (is_ntfs_stream_smb_fname(smb_fname)) {
     458                return NT_STATUS_INVALID_PARAMETER;
     459        }
     460
     461        return get_ea_list_from_file_path(mem_ctx, conn, fsp, smb_fname->base_name, pea_total_len, ea_list);
    363462}
    364463
     
    400499                SCVAL(p,1,dos_namelen);
    401500                SSVAL(p,2,ea_list->ea.value.length);
    402                 fstrcpy(p+4, dos_ea_name);
     501                strlcpy(p+4, dos_ea_name, dos_namelen+1);
    403502                memcpy( p + 4 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
    404503
     
    422521        uint8_t *p = (uint8_t *)pdata;
    423522        uint8_t *last_start = NULL;
    424         bool store_data = (pdata != NULL);
     523        bool do_store_data = (pdata != NULL);
    425524
    426525        *ret_data_size = 0;
     
    436535                size_t pad = 0;
    437536
    438                 if (last_start && store_data) {
     537                if (last_start != NULL && do_store_data) {
    439538                        SIVAL(last_start, 0, PTR_DIFF(p, last_start));
    440539                }
     
    457556                }
    458557
    459                 if (this_size > total_data_size) {
    460                         return NT_STATUS_INFO_LENGTH_MISMATCH;
    461                 }
    462 
    463                 /* We know we have room. */
    464                 if (store_data) {
     558                if (do_store_data) {
     559                        if (this_size > total_data_size) {
     560                                return NT_STATUS_INFO_LENGTH_MISMATCH;
     561                        }
     562
     563                        /* We know we have room. */
    465564                        SIVAL(p, 0x00, 0); /* next offset */
    466565                        SCVAL(p, 0x04, ea_list->ea.flags);
    467566                        SCVAL(p, 0x05, dos_namelen);
    468567                        SSVAL(p, 0x06, ea_list->ea.value.length);
    469                         fstrcpy((char *)(p+0x08), dos_ea_name);
     568                        strlcpy((char *)(p+0x08), dos_ea_name, dos_namelen+1);
    470569                        memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
    471570                        if (pad) {
     
    474573                                        pad);
    475574                        }
    476                 }
    477 
    478                 total_data_size -= this_size;
     575                        total_data_size -= this_size;
     576                }
     577
    479578                p += this_size;
    480579        }
     
    485584}
    486585
    487 static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp, const char *fname)
     586static unsigned int estimate_ea_size(connection_struct *conn, files_struct *fsp, const struct smb_filename *smb_fname)
    488587{
    489588        size_t total_ea_len = 0;
     589        TALLOC_CTX *mem_ctx;
    490590        struct ea_list *ea_list = NULL;
    491         TALLOC_CTX *mem_ctx = NULL;
    492591
    493592        if (!lp_ea_support(SNUM(conn))) {
    494593                return 0;
    495594        }
    496         mem_ctx = talloc_tos();
    497         ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
    498         if (ea_list == NULL) {
    499                 return 0;
    500         }
     595        mem_ctx = talloc_stackframe();
     596
     597        /* If this is a stream fsp, then we need to instead find the
     598         * estimated ea len from the main file, not the stream
     599         * (streams cannot have EAs), but the estimate isn't just 0 in
     600         * this case! */
     601        if (is_ntfs_stream_smb_fname(smb_fname)) {
     602                fsp = NULL;
     603        }
     604        (void)get_ea_list_from_file_path(mem_ctx, conn, fsp, smb_fname->base_name, &total_ea_len, &ea_list);
    501605        if(conn->sconn->using_smb2) {
    502606                NTSTATUS status;
     
    510614                status = fill_ea_chained_buffer(mem_ctx,
    511615                                                NULL,
    512                                                 65535,
     616                                                0,
    513617                                                &ret_data_size,
    514618                                                conn,
     
    519623                total_ea_len = ret_data_size;
    520624        }
    521 
     625        TALLOC_FREE(mem_ctx);
    522626        return total_ea_len;
    523627}
     
    531635        size_t total_ea_len;
    532636        TALLOC_CTX *mem_ctx = talloc_tos();
    533         struct ea_list *ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
     637        struct ea_list *ea_list;
     638        NTSTATUS status = get_ea_list_from_file_path(mem_ctx, conn, fsp, fname, &total_ea_len, &ea_list);
     639        if (!NT_STATUS_IS_OK(status)) {
     640                return;
     641        }
    534642
    535643        for (; ea_list; ea_list = ea_list->next) {
     
    537645                        DEBUG(10,("canonicalize_ea_name: %s -> %s\n",
    538646                                &unix_ea_name[5], ea_list->ea.name));
    539                         safe_strcpy(&unix_ea_name[5], ea_list->ea.name, sizeof(fstring)-6);
     647                        strlcpy(&unix_ea_name[5], ea_list->ea.name, sizeof(fstring)-5);
    540648                        break;
    541649                }
     
    550658                const struct smb_filename *smb_fname, struct ea_list *ea_list)
    551659{
     660        NTSTATUS status;
    552661        char *fname = NULL;
    553662
     
    556665        }
    557666
    558         if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
    559                 return NT_STATUS_ACCESS_DENIED;
    560         }
    561 
    562         /* For now setting EAs on streams isn't supported. */
     667        status = refuse_symlink(conn, fsp, smb_fname->base_name);
     668        if (!NT_STATUS_IS_OK(status)) {
     669                return status;
     670        }
     671
     672        status = check_access(conn, fsp, smb_fname, FILE_WRITE_EA);
     673        if (!NT_STATUS_IS_OK(status)) {
     674                return status;
     675        }
     676
     677        /* Setting EAs on streams isn't supported. */
     678        if (is_ntfs_stream_smb_fname(smb_fname)) {
     679                return NT_STATUS_INVALID_PARAMETER;
     680        }
     681
     682        /*
     683         * Filter out invalid Windows EA names - before
     684         * we set *any* of them.
     685         */
     686
     687        if (ea_list_has_invalid_name(ea_list)) {
     688                return STATUS_INVALID_EA_NAME;
     689        }
     690
    563691        fname = smb_fname->base_name;
    564692
     
    636764
    637765        while (offset + 2 < data_size) {
    638                 struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);
     766                struct ea_list *eal = talloc_zero(ctx, struct ea_list);
    639767                unsigned int namelen = CVAL(pdata,offset);
    640768
     
    661789
    662790                offset += (namelen + 1); /* Go past the name + terminating zero. */
    663                 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
     791                DLIST_ADD_END(ea_list_head, eal);
    664792                DEBUG(10,("read_ea_name_list: read ea name %s\n", eal->ea.name));
    665793        }
    666794
    667795        return ea_list_head;
    668 }
    669 
    670 /****************************************************************************
    671  Read one EA list entry from the buffer.
    672 ****************************************************************************/
    673 
    674 struct ea_list *read_ea_list_entry(TALLOC_CTX *ctx, const char *pdata, size_t data_size, size_t *pbytes_used)
    675 {
    676         struct ea_list *eal = TALLOC_ZERO_P(ctx, struct ea_list);
    677         uint16 val_len;
    678         unsigned int namelen;
    679         size_t converted_size;
    680 
    681         if (!eal) {
    682                 return NULL;
    683         }
    684 
    685         if (data_size < 6) {
    686                 return NULL;
    687         }
    688 
    689         eal->ea.flags = CVAL(pdata,0);
    690         namelen = CVAL(pdata,1);
    691         val_len = SVAL(pdata,2);
    692 
    693         if (4 + namelen + 1 + val_len > data_size) {
    694                 return NULL;
    695         }
    696 
    697         /* Ensure the name is null terminated. */
    698         if (pdata[namelen + 4] != '\0') {
    699                 return NULL;
    700         }
    701         if (!pull_ascii_talloc(ctx, &eal->ea.name, pdata + 4, &converted_size)) {
    702                 DEBUG(0,("read_ea_list_entry: pull_ascii_talloc failed: %s",
    703                          strerror(errno)));
    704         }
    705         if (!eal->ea.name) {
    706                 return NULL;
    707         }
    708 
    709         eal->ea.value = data_blob_talloc(eal, NULL, (size_t)val_len + 1);
    710         if (!eal->ea.value.data) {
    711                 return NULL;
    712         }
    713 
    714         memcpy(eal->ea.value.data, pdata + 4 + namelen + 1, val_len);
    715 
    716         /* Ensure we're null terminated just in case we print the value. */
    717         eal->ea.value.data[val_len] = '\0';
    718         /* But don't count the null. */
    719         eal->ea.value.length--;
    720 
    721         if (pbytes_used) {
    722                 *pbytes_used = 4 + namelen + 1 + val_len;
    723         }
    724 
    725         DEBUG(10,("read_ea_list_entry: read ea name %s\n", eal->ea.name));
    726         dump_data(10, eal->ea.value.data, eal->ea.value.length);
    727 
    728         return eal;
    729796}
    730797
     
    746813                }
    747814
    748                 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
     815                DLIST_ADD_END(ea_list_head, eal);
    749816                offset += bytes_used;
    750817        }
     
    816883void send_trans2_replies(connection_struct *conn,
    817884                        struct smb_request *req,
     885                        NTSTATUS status,
    818886                         const char *params,
    819887                         int paramsize,
     
    837905        int data_alignment_offset = 0;
    838906        bool overflow = False;
    839         struct smbd_server_connection *sconn = req->sconn;
    840         int max_send = sconn->smb1.sessions.max_send;
     907        struct smbXsrv_connection *xconn = req->xconn;
     908        int max_send = xconn->smb1.sessions.max_send;
    841909
    842910        /* Modify the data_to_send and datasize and set the error if
     
    856924        if(params_to_send == 0 && data_to_send == 0) {
    857925                reply_outbuf(req, 10, 0);
     926                if (NT_STATUS_V(status)) {
     927                        uint8_t eclass;
     928                        uint32_t ecode;
     929                        ntstatus_to_dos(status, &eclass, &ecode);
     930                        error_packet_set((char *)req->outbuf,
     931                                        eclass, ecode, status,
     932                                        __LINE__,__FILE__);
     933                }
    858934                show_msg((char *)req->outbuf);
    859                 if (!srv_send_smb(sconn,
     935                if (!srv_send_smb(xconn,
    860936                                (char *)req->outbuf,
    861937                                true, req->seqnum+1,
     
    9861062                                         STATUS_BUFFER_OVERFLOW,
    9871063                                         __LINE__,__FILE__);
     1064                } else if (NT_STATUS_V(status)) {
     1065                        uint8_t eclass;
     1066                        uint32_t ecode;
     1067                        ntstatus_to_dos(status, &eclass, &ecode);
     1068                        error_packet_set((char *)req->outbuf,
     1069                                        eclass, ecode, status,
     1070                                        __LINE__,__FILE__);
    9881071                }
    9891072
    9901073                /* Send the packet */
    9911074                show_msg((char *)req->outbuf);
    992                 if (!srv_send_smb(sconn,
     1075                if (!srv_send_smb(xconn,
    9931076                                (char *)req->outbuf,
    9941077                                true, req->seqnum+1,
     
    10301113        char *pdata = *ppdata;
    10311114        int deny_mode;
    1032         int32 open_attr;
     1115        int32_t open_attr;
    10331116        bool oplock_request;
    10341117#if 0
     
    10381121#endif
    10391122        int open_ofun;
    1040         uint32 open_size;
     1123        uint32_t open_size;
    10411124        char *pname;
    10421125        char *fname = NULL;
    1043         SMB_OFF_T size=0;
     1126        off_t size=0;
    10441127        int fattr=0,mtime=0;
    10451128        SMB_INO_T inode = 0;
     
    10471130        files_struct *fsp;
    10481131        struct ea_list *ea_list = NULL;
    1049         uint16 flags = 0;
     1132        uint16_t flags = 0;
    10501133        NTSTATUS status;
    1051         uint32 access_mask;
    1052         uint32 share_mode;
    1053         uint32 create_disposition;
    1054         uint32 create_options = 0;
     1134        uint32_t access_mask;
     1135        uint32_t share_mode;
     1136        uint32_t create_disposition;
     1137        uint32_t create_options = 0;
    10551138        uint32_t private_flags = 0;
     1139        uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
    10561140        TALLOC_CTX *ctx = talloc_tos();
    10571141
     
    10871171        }
    10881172
    1089         srvstr_get_path(ctx, params, req->flags2, &fname, pname,
    1090                         total_params - 28, STR_TERMINATE,
     1173        if (req->posix_pathnames) {
     1174                srvstr_get_path_posix(ctx,
     1175                        params,
     1176                        req->flags2,
     1177                        &fname,
     1178                        pname,
     1179                        total_params - 28,
     1180                        STR_TERMINATE,
    10911181                        &status);
     1182        } else {
     1183                srvstr_get_path(ctx,
     1184                        params,
     1185                        req->flags2,
     1186                        &fname,
     1187                        pname,
     1188                        total_params - 28,
     1189                        STR_TERMINATE,
     1190                        &status);
     1191        }
    10921192        if (!NT_STATUS_IS_OK(status)) {
    10931193                reply_nterror(req, status);
     
    11031203                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    11041204                                fname,
    1105                                 0,
     1205                                ucf_flags,
    11061206                                NULL,
    11071207                                &smb_fname);
     
    11551255                if (!lp_ea_support(SNUM(conn))) {
    11561256                        reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
     1257                        goto out;
     1258                }
     1259
     1260                if (ea_list_has_invalid_name(ea_list)) {
     1261                        int param_len = 30;
     1262                        *pparams = (char *)SMB_REALLOC(*pparams, param_len);
     1263                        if(*pparams == NULL ) {
     1264                                reply_nterror(req, NT_STATUS_NO_MEMORY);
     1265                                goto out;
     1266                        }
     1267                        params = *pparams;
     1268                        memset(params, '\0', param_len);
     1269                        send_trans2_replies(conn, req, STATUS_INVALID_EA_NAME,
     1270                                params, param_len, NULL, 0, max_data_bytes);
    11571271                        goto out;
    11581272                }
     
    11701284                open_attr,                              /* file_attributes */
    11711285                oplock_request,                         /* oplock_request */
     1286                NULL,                                   /* lease */
    11721287                open_size,                              /* allocation_size */
    11731288                private_flags,
     
    11751290                ea_list,                                /* ea_list */
    11761291                &fsp,                                   /* result */
    1177                 &smb_action);                           /* psbuf */
     1292                &smb_action,                            /* psbuf */
     1293                NULL, NULL);                            /* create context */
    11781294
    11791295        if (!NT_STATUS_IS_OK(status)) {
    1180                 if (open_was_deferred(req->mid)) {
     1296                if (open_was_deferred(req->xconn, req->mid)) {
    11811297                        /* We have re-scheduled this call. */
    11821298                        goto out;
     
    12071323        SSVAL(params,2,fattr);
    12081324        srv_put_dos_date2(params,4, mtime);
    1209         SIVAL(params,8, (uint32)size);
     1325        SIVAL(params,8, (uint32_t)size);
    12101326        SSVAL(params,12,deny_mode);
    12111327        SSVAL(params,14,0); /* open_type - file or directory. */
     
    12241340        SSVAL(params,24,0); /* Padding. */
    12251341        if (flags & 8) {
    1226                 uint32 ea_size = estimate_ea_size(conn, fsp,
    1227                                                   fsp->fsp_name->base_name);
     1342                uint32_t ea_size = estimate_ea_size(conn, fsp,
     1343                                                  smb_fname);
    12281344                SIVAL(params, 26, ea_size);
    12291345        } else {
     
    12321348
    12331349        /* Send the required number of replies */
    1234         send_trans2_replies(conn, req, params, 30, *ppdata, 0, max_data_bytes);
     1350        send_trans2_replies(conn, req, NT_STATUS_OK, params, 30, *ppdata, 0, max_data_bytes);
    12351351 out:
    12361352        TALLOC_FREE(smb_fname);
     
    12601376                return strcmp(str,mask)==0;
    12611377        } else {
    1262                 return StrCaseCmp(str,mask) == 0;
     1378                return strcasecmp_m(str,mask) == 0;
    12631379        }
    12641380}
     
    12681384****************************************************************************/
    12691385
    1270 static uint32 unix_filetype(mode_t mode)
     1386static uint32_t unix_filetype(mode_t mode)
    12711387{
    12721388        if(S_ISREG(mode))
     
    13071423static NTSTATUS unix_perms_from_wire( connection_struct *conn,
    13081424                                const SMB_STRUCT_STAT *psbuf,
    1309                                 uint32 perms,
     1425                                uint32_t perms,
    13101426                                enum perm_type ptype,
    13111427                                mode_t *ret_perms)
     
    13411457#endif
    13421458
    1343         switch (ptype) {
    1344         case PERM_NEW_FILE:
    1345                 /* Apply mode mask */
     1459        if (ptype == PERM_NEW_FILE) {
     1460                /*
     1461                 * "create mask"/"force create mode" are
     1462                 * only applied to new files, not existing ones.
     1463                 */
    13461464                ret &= lp_create_mask(SNUM(conn));
    13471465                /* Add in force bits */
    13481466                ret |= lp_force_create_mode(SNUM(conn));
    1349                 break;
    1350         case PERM_NEW_DIR:
    1351                 ret &= lp_dir_mask(SNUM(conn));
     1467        } else if (ptype == PERM_NEW_DIR) {
     1468                /*
     1469                 * "directory mask"/"force directory mode" are
     1470                 * only applied to new directories, not existing ones.
     1471                 */
     1472                ret &= lp_directory_mask(SNUM(conn));
    13521473                /* Add in force bits */
    1353                 ret |= lp_force_dir_mode(SNUM(conn));
    1354                 break;
    1355         case PERM_EXISTING_FILE:
    1356                 /* Apply mode mask */
    1357                 ret &= lp_security_mask(SNUM(conn));
    1358                 /* Add in force bits */
    1359                 ret |= lp_force_security_mode(SNUM(conn));
    1360                 break;
    1361         case PERM_EXISTING_DIR:
    1362                 /* Apply mode mask */
    1363                 ret &= lp_dir_security_mask(SNUM(conn));
    1364                 /* Add in force bits */
    1365                 ret |= lp_force_dir_security_mode(SNUM(conn));
    1366                 break;
     1474                ret |= lp_force_directory_mode(SNUM(conn));
    13671475        }
    13681476
     
    14241532        /* Mangle fname if it's an illegal name. */
    14251533        if (mangle_must_mangle(dname, state->conn->params)) {
     1534                /*
     1535                 * Slow path - ensure we can push the original name as UCS2. If
     1536                 * not, then just don't return this name.
     1537                 */
     1538                NTSTATUS status;
     1539                size_t ret_len = 0;
     1540                size_t len = (strlen(dname) + 2) * 4; /* Allow enough space. */
     1541                uint8_t *tmp = talloc_array(talloc_tos(),
     1542                                        uint8_t,
     1543                                        len);
     1544
     1545                status = srvstr_push(NULL,
     1546                        FLAGS2_UNICODE_STRINGS,
     1547                        tmp,
     1548                        dname,
     1549                        len,
     1550                        STR_TERMINATE,
     1551                        &ret_len);
     1552
     1553                TALLOC_FREE(tmp);
     1554
     1555                if (!NT_STATUS_IS_OK(status)) {
     1556                        return false;
     1557                }
     1558
    14261559                ok = name_to_8_3(dname, mangled_name,
    14271560                                 true, state->conn->params);
     
    15251658}
    15261659
    1527 static bool smbd_marshall_dir_entry(TALLOC_CTX *ctx,
     1660static NTSTATUS smbd_marshall_dir_entry(TALLOC_CTX *ctx,
    15281661                                    connection_struct *conn,
    15291662                                    uint16_t flags2,
     
    15411674                                    char **ppdata,
    15421675                                    char *end_data,
    1543                                     bool *out_of_space,
    15441676                                    uint64_t *last_entry_off)
    15451677{
     
    15491681        uint64_t allocation_size = 0;
    15501682        uint64_t file_index = 0;
    1551         uint32_t len;
    1552         struct timespec mdate_ts, adate_ts, cdate_ts, create_date_ts;
     1683        size_t len = 0;
     1684        struct timespec mdate_ts = {0};
     1685        struct timespec adate_ts = {0};
     1686        struct timespec cdate_ts = {0};
     1687        struct timespec create_date_ts = {0};
    15531688        time_t mdate = (time_t)0, adate = (time_t)0, create_date = (time_t)0;
    1554         time_t c_date = (time_t)0;
    15551689        char *nameptr;
    15561690        char *last_entry_ptr;
     
    15581692        int off;
    15591693        int pad = 0;
    1560 
    1561         *out_of_space = false;
    1562 
    1563         ZERO_STRUCT(mdate_ts);
    1564         ZERO_STRUCT(adate_ts);
    1565         ZERO_STRUCT(create_date_ts);
    1566         ZERO_STRUCT(cdate_ts);
     1694        NTSTATUS status;
     1695        struct readdir_attr_data *readdir_attr_data = NULL;
    15671696
    15681697        if (!(mode & FILE_ATTRIBUTE_DIRECTORY)) {
     
    15701699        }
    15711700        allocation_size = SMB_VFS_GET_ALLOC_SIZE(conn, NULL, &smb_fname->st);
     1701
     1702        status = SMB_VFS_READDIR_ATTR(conn, smb_fname, ctx, &readdir_attr_data);
     1703        if (!NT_STATUS_IS_OK(status)) {
     1704                if (!NT_STATUS_EQUAL(NT_STATUS_NOT_SUPPORTED, status)) {
     1705                        return status;
     1706                }
     1707        }
    15721708
    15731709        file_index = get_FileIndex(conn, &smb_fname->st);
     
    15881724        mdate = convert_timespec_to_time_t(mdate_ts);
    15891725        adate = convert_timespec_to_time_t(adate_ts);
    1590         c_date = convert_timespec_to_time_t(cdate_ts);
    15911726
    15921727        /* align the record */
     
    15981733
    15991734        if (pad && pad > space_remaining) {
    1600                 *out_of_space = true;
    16011735                DEBUG(9,("smbd_marshall_dir_entry: out of space "
    16021736                        "for padding (wanted %u, had %d)\n",
    16031737                        (unsigned int)pad,
    16041738                        space_remaining ));
    1605                 return false; /* Not finished - just out of space */
     1739                return STATUS_MORE_ENTRIES; /* Not finished - just out of space */
    16061740        }
    16071741
     
    16331767                srv_put_dos_date2(p,4,adate);
    16341768                srv_put_dos_date2(p,8,mdate);
    1635                 SIVAL(p,12,(uint32)file_size);
    1636                 SIVAL(p,16,(uint32)allocation_size);
     1769                SIVAL(p,12,(uint32_t)file_size);
     1770                SIVAL(p,16,(uint32_t)allocation_size);
    16371771                SSVAL(p,20,mode);
    16381772                p += 23;
     
    16411775                        p += ucs2_align(base_data, p, 0);
    16421776                }
    1643                 len = srvstr_push(base_data, flags2, p,
     1777                status = srvstr_push(base_data, flags2, p,
    16441778                                  fname, PTR_DIFF(end_data, p),
    1645                                   STR_TERMINATE);
     1779                                  STR_TERMINATE, &len);
     1780                if (!NT_STATUS_IS_OK(status)) {
     1781                        return status;
     1782                }
    16461783                if (flags2 & FLAGS2_UNICODE_STRINGS) {
    16471784                        if (len > 2) {
     
    16691806                srv_put_dos_date2(p,4,adate);
    16701807                srv_put_dos_date2(p,8,mdate);
    1671                 SIVAL(p,12,(uint32)file_size);
    1672                 SIVAL(p,16,(uint32)allocation_size);
     1808                SIVAL(p,12,(uint32_t)file_size);
     1809                SIVAL(p,16,(uint32_t)allocation_size);
    16731810                SSVAL(p,20,mode);
    16741811                {
    16751812                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    1676                                                                 smb_fname->base_name);
     1813                                                                smb_fname);
    16771814                        SIVAL(p,22,ea_size); /* Extended attributes */
    16781815                }
    16791816                p += 27;
    16801817                nameptr = p - 1;
    1681                 len = srvstr_push(base_data, flags2,
     1818                status = srvstr_push(base_data, flags2,
    16821819                                  p, fname, PTR_DIFF(end_data, p),
    1683                                   STR_TERMINATE | STR_NOALIGN);
     1820                                  STR_TERMINATE | STR_NOALIGN, &len);
     1821                if (!NT_STATUS_IS_OK(status)) {
     1822                        return status;
     1823                }
    16841824                if (flags2 & FLAGS2_UNICODE_STRINGS) {
    16851825                        if (len > 2) {
     
    17071847                DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_EA_LIST\n"));
    17081848                if (!name_list) {
    1709                         return false;
     1849                        return NT_STATUS_INVALID_PARAMETER;
    17101850                }
    17111851                if (requires_resume_key) {
     
    17161856                srv_put_dos_date2(p,4,adate);
    17171857                srv_put_dos_date2(p,8,mdate);
    1718                 SIVAL(p,12,(uint32)file_size);
    1719                 SIVAL(p,16,(uint32)allocation_size);
     1858                SIVAL(p,12,(uint32_t)file_size);
     1859                SIVAL(p,16,(uint32_t)allocation_size);
    17201860                SSVAL(p,20,mode);
    17211861                p += 22; /* p now points to the EA area. */
    17221862
    1723                 file_list = get_ea_list_from_file(ctx, conn, NULL,
    1724                                                   smb_fname->base_name,
    1725                                                   &ea_len);
     1863                status = get_ea_list_from_file(ctx, conn, NULL,
     1864                                               smb_fname,
     1865                                               &ea_len, &file_list);
     1866                if (!NT_STATUS_IS_OK(status)) {
     1867                        file_list = NULL;
     1868                }
    17261869                name_list = ea_list_union(name_list, file_list, &ea_len);
    17271870
     
    17291872                /* Max string size is 255 bytes. */
    17301873                if (PTR_DIFF(p + 255 + ea_len,pdata) > space_remaining) {
    1731                         *out_of_space = true;
    17321874                        DEBUG(9,("smbd_marshall_dir_entry: out of space "
    17331875                                "(wanted %u, had %d)\n",
    17341876                                (unsigned int)PTR_DIFF(p + 255 + ea_len,pdata),
    17351877                                space_remaining ));
    1736                         return False; /* Not finished - just out of space */
     1878                        return STATUS_MORE_ENTRIES; /* Not finished - just out of space */
    17371879                }
    17381880
     
    17401882                p += fill_ea_buffer(ctx, p, space_remaining, conn, name_list);
    17411883                nameptr = p;
    1742                 len = srvstr_push(base_data, flags2,
     1884                status = srvstr_push(base_data, flags2,
    17431885                                  p + 1, fname, PTR_DIFF(end_data, p+1),
    1744                                   STR_TERMINATE | STR_NOALIGN);
     1886                                  STR_TERMINATE | STR_NOALIGN, &len);
     1887                if (!NT_STATUS_IS_OK(status)) {
     1888                        return status;
     1889                }
    17451890                if (flags2 & FLAGS2_UNICODE_STRINGS) {
    17461891                        if (len > 2) {
     
    17791924                } else {
    17801925                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    1781                                                                 smb_fname->base_name);
     1926                                                                smb_fname);
    17821927                        SIVAL(p,0,ea_size); /* Extended attributes */
    17831928                }
     
    17951940                        }
    17961941                        mangled_name[12] = 0;
    1797                         len = srvstr_push(base_data, flags2,
     1942                        status = srvstr_push(base_data, flags2,
    17981943                                          p+2, mangled_name, 24,
    1799                                           STR_UPPER|STR_UNICODE);
     1944                                          STR_UPPER|STR_UNICODE, &len);
     1945                        if (!NT_STATUS_IS_OK(status)) {
     1946                                return status;
     1947                        }
    18001948                        if (len < 24) {
    18011949                                memset(p + 2 + len,'\0',24 - len);
     
    18061954                }
    18071955                p += 2 + 24;
    1808                 len = srvstr_push(base_data, flags2, p,
     1956                status = srvstr_push(base_data, flags2, p,
    18091957                                  fname, PTR_DIFF(end_data, p),
    1810                                   STR_TERMINATE_ASCII);
     1958                                  STR_TERMINATE_ASCII, &len);
     1959                if (!NT_STATUS_IS_OK(status)) {
     1960                        return status;
     1961                }
    18111962                SIVAL(q,0,len);
    18121963                p += len;
     
    18421993                SOFF_T(p,0,allocation_size); p += 8;
    18431994                SIVAL(p,0,mode); p += 4;
    1844                 len = srvstr_push(base_data, flags2,
     1995                status = srvstr_push(base_data, flags2,
    18451996                                  p + 4, fname, PTR_DIFF(end_data, p+4),
    1846                                   STR_TERMINATE_ASCII);
     1997                                  STR_TERMINATE_ASCII, &len);
     1998                if (!NT_STATUS_IS_OK(status)) {
     1999                        return status;
     2000                }
    18472001                SIVAL(p,0,len);
    18482002                p += 4 + len;
     
    18812035                {
    18822036                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    1883                                                                 smb_fname->base_name);
     2037                                                                smb_fname);
    18842038                        SIVAL(p,0,ea_size); /* Extended attributes */
    18852039                        p +=4;
    18862040                }
    1887                 len = srvstr_push(base_data, flags2, p,
     2041                status = srvstr_push(base_data, flags2, p,
    18882042                                  fname, PTR_DIFF(end_data, p),
    1889                                   STR_TERMINATE_ASCII);
     2043                                  STR_TERMINATE_ASCII, &len);
     2044                if (!NT_STATUS_IS_OK(status)) {
     2045                        return status;
     2046                }
    18902047                SIVAL(q, 0, len);
    18912048                p += len;
     
    19172074                /* this must *not* be null terminated or w2k gets in a loop trying to set an
    19182075                   acl on a dir (tridge) */
    1919                 len = srvstr_push(base_data, flags2, p,
     2076                status = srvstr_push(base_data, flags2, p,
    19202077                                  fname, PTR_DIFF(end_data, p),
    1921                                   STR_TERMINATE_ASCII);
     2078                                  STR_TERMINATE_ASCII, &len);
     2079                if (!NT_STATUS_IS_OK(status)) {
     2080                        return status;
     2081                }
    19222082                SIVAL(p, -4, len);
    19232083                p += len;
     
    19582118                } else {
    19592119                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    1960                                                                 smb_fname->base_name);
     2120                                                                smb_fname);
    19612121                        SIVAL(p,0,ea_size); /* Extended attributes */
    19622122                }
    1963                 p +=4;
     2123                p += 4;
    19642124                SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
    19652125                SBVAL(p,0,file_index); p += 8;
    1966                 len = srvstr_push(base_data, flags2, p,
     2126                status = srvstr_push(base_data, flags2, p,
    19672127                                  fname, PTR_DIFF(end_data, p),
    1968                                   STR_TERMINATE_ASCII);
     2128                                  STR_TERMINATE_ASCII, &len);
     2129                if (!NT_STATUS_IS_OK(status)) {
     2130                        return status;
     2131                }
    19692132                SIVAL(q, 0, len);
    19702133                p += len;
     
    20042167                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
    20052168                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     2169                } else if (readdir_attr_data &&
     2170                           readdir_attr_data->type == RDATTR_AAPL) {
     2171                        /*
     2172                         * OS X specific SMB2 extension negotiated via
     2173                         * AAPL create context: return max_access in
     2174                         * ea_size field.
     2175                         */
     2176                        SIVAL(p, 0, readdir_attr_data->attr_data.aapl.max_access);
    20062177                } else {
    20072178                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    2008                                                                 smb_fname->base_name);
     2179                                                                smb_fname);
    20092180                        SIVAL(p,0,ea_size); /* Extended attributes */
    20102181                }
    2011                 p +=4;
    2012                 /* Clear the short name buffer. This is
    2013                  * IMPORTANT as not doing so will trigger
    2014                  * a Win2k client bug. JRA.
    2015                  */
    2016                 if (!was_8_3 && check_mangled_names) {
     2182                p += 4;
     2183
     2184                if (readdir_attr_data &&
     2185                    readdir_attr_data->type == RDATTR_AAPL) {
     2186                        /*
     2187                         * OS X specific SMB2 extension negotiated via
     2188                         * AAPL create context: return resource fork
     2189                         * length and compressed FinderInfo in
     2190                         * shortname field.
     2191                         *
     2192                         * According to documentation short_name_len
     2193                         * should be 0, but on the wire behaviour
     2194                         * shows its set to 24 by clients.
     2195                         */
     2196                        SSVAL(p, 0, 24);
     2197
     2198                        /* Resourefork length */
     2199                        SBVAL(p, 2, readdir_attr_data->attr_data.aapl.rfork_size);
     2200
     2201                        /* Compressed FinderInfo */
     2202                        memcpy(p + 10, &readdir_attr_data->attr_data.aapl.finder_info, 16);
     2203                } else if (!was_8_3 && check_mangled_names) {
    20172204                        char mangled_name[13]; /* mangled 8.3 name. */
    20182205                        if (!name_to_8_3(fname,mangled_name,True,
     
    20222209                        }
    20232210                        mangled_name[12] = 0;
    2024                         len = srvstr_push(base_data, flags2,
     2211                        status = srvstr_push(base_data, flags2,
    20252212                                          p+2, mangled_name, 24,
    2026                                           STR_UPPER|STR_UNICODE);
     2213                                          STR_UPPER|STR_UNICODE, &len);
     2214                        if (!NT_STATUS_IS_OK(status)) {
     2215                                return status;
     2216                        }
    20272217                        SSVAL(p, 0, len);
    20282218                        if (len < 24) {
     
    20312221                        SSVAL(p, 0, len);
    20322222                } else {
     2223                        /* Clear the short name buffer. This is
     2224                         * IMPORTANT as not doing so will trigger
     2225                         * a Win2k client bug. JRA.
     2226                         */
    20332227                        memset(p,'\0',26);
    20342228                }
    20352229                p += 26;
    2036                 SSVAL(p,0,0); p += 2; /* Reserved ? */
     2230
     2231                /* Reserved ? */
     2232                if (readdir_attr_data &&
     2233                    readdir_attr_data->type == RDATTR_AAPL) {
     2234                        /*
     2235                         * OS X specific SMB2 extension negotiated via
     2236                         * AAPL create context: return UNIX mode in
     2237                         * reserved field.
     2238                         */
     2239                        uint16_t aapl_mode = (uint16_t)readdir_attr_data->attr_data.aapl.unix_mode;
     2240                        SSVAL(p, 0, aapl_mode);
     2241                } else {
     2242                        SSVAL(p, 0, 0);
     2243                }
     2244                p += 2;
     2245
    20372246                SBVAL(p,0,file_index); p += 8;
    2038                 len = srvstr_push(base_data, flags2, p,
     2247                status = srvstr_push(base_data, flags2, p,
    20392248                                  fname, PTR_DIFF(end_data, p),
    2040                                   STR_TERMINATE_ASCII);
     2249                                  STR_TERMINATE_ASCII, &len);
     2250                if (!NT_STATUS_IS_OK(status)) {
     2251                        return status;
     2252                }
    20412253                SIVAL(q,0,len);
    20422254                p += len;
     
    20742286                        p = store_file_unix_basic(conn, p,
    20752287                                                NULL, &smb_fname->st);
    2076                         len = srvstr_push(base_data, flags2, p,
     2288                        status = srvstr_push(base_data, flags2, p,
    20772289                                          fname, PTR_DIFF(end_data, p),
    2078                                           STR_TERMINATE);
     2290                                          STR_TERMINATE, &len);
     2291                        if (!NT_STATUS_IS_OK(status)) {
     2292                                return status;
     2293                        }
    20792294                } else {
    20802295                        DEBUG(10,("smbd_marshall_dir_entry: SMB_FIND_FILE_UNIX_INFO2\n"));
     
    20832298                        nameptr = p;
    20842299                        p += 4;
    2085                         len = srvstr_push(base_data, flags2, p, fname,
    2086                                           PTR_DIFF(end_data, p), 0);
     2300                        status = srvstr_push(base_data, flags2, p, fname,
     2301                                          PTR_DIFF(end_data, p), 0, &len);
     2302                        if (!NT_STATUS_IS_OK(status)) {
     2303                                return status;
     2304                        }
    20872305                        SIVAL(nameptr, 0, len);
    20882306                }
     
    21122330
    21132331        default:
    2114                 return false;
     2332                return NT_STATUS_INVALID_LEVEL;
    21152333        }
    21162334
    21172335        if (PTR_DIFF(p,pdata) > space_remaining) {
    2118                 *out_of_space = true;
    21192336                DEBUG(9,("smbd_marshall_dir_entry: out of space "
    21202337                        "(wanted %u, had %d)\n",
    21212338                        (unsigned int)PTR_DIFF(p,pdata),
    21222339                        space_remaining ));
    2123                 return false; /* Not finished - just out of space */
     2340                return STATUS_MORE_ENTRIES; /* Not finished - just out of space */
    21242341        }
    21252342
     
    21292346        *ppdata = p;
    21302347
    2131         return true;
     2348        return NT_STATUS_OK;
    21322349}
    21332350
    2134 bool smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
     2351NTSTATUS smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
    21352352                               connection_struct *conn,
    21362353                               struct dptr_struct *dirptr,
    2137                                uint16 flags2,
     2354                               uint16_t flags2,
    21382355                               const char *path_mask,
    2139                                uint32 dirtype,
     2356                               uint32_t dirtype,
    21402357                               int info_level,
    21412358                               int requires_resume_key,
     
    21482365                               char *end_data,
    21492366                               int space_remaining,
    2150                                bool *out_of_space,
    21512367                               bool *got_exact_match,
    21522368                               int *_last_entry_off,
     
    21622378        bool ok;
    21632379        uint64_t last_entry_off = 0;
     2380        NTSTATUS status;
    21642381
    21652382        ZERO_STRUCT(state);
    21662383        state.conn = conn;
    21672384        state.info_level = info_level;
    2168         state.check_mangled_names = lp_manglednames(conn->params);
     2385        state.check_mangled_names = lp_mangled_names(conn->params);
    21692386        state.has_wild = dptr_has_wild(dirptr);
    21702387        state.got_exact_match = false;
    21712388
    2172         *out_of_space = false;
    21732389        *got_exact_match = false;
    21742390
     
    21982414                                   &prev_dirpos);
    21992415        if (!ok) {
    2200                 return false;
     2416                return NT_STATUS_END_OF_FILE;
    22012417        }
    22022418
    22032419        *got_exact_match = state.got_exact_match;
    22042420
    2205         ok = smbd_marshall_dir_entry(ctx,
     2421        status = smbd_marshall_dir_entry(ctx,
    22062422                                     conn,
    22072423                                     flags2,
     
    22192435                                     ppdata,
    22202436                                     end_data,
    2221                                      out_of_space,
    22222437                                     &last_entry_off);
     2438        if (NT_STATUS_EQUAL(status, NT_STATUS_ILLEGAL_CHARACTER)) {
     2439                DEBUG(1,("Conversion error: illegal character: %s\n",
     2440                         smb_fname_str_dbg(smb_fname)));
     2441        }
    22232442        TALLOC_FREE(fname);
    22242443        TALLOC_FREE(smb_fname);
    2225         if (*out_of_space) {
     2444        if (NT_STATUS_EQUAL(status, STATUS_MORE_ENTRIES)) {
    22262445                dptr_SeekDir(dirptr, prev_dirpos);
    2227                 return false;
    2228         }
    2229         if (!ok) {
    2230                 return false;
     2446                return status;
     2447        }
     2448        if (!NT_STATUS_IS_OK(status)) {
     2449                return status;
    22312450        }
    22322451
    22332452        *_last_entry_off = last_entry_off;
    2234         return true;
     2453        return NT_STATUS_OK;
    22352454}
    22362455
    2237 static bool get_lanman2_dir_entry(TALLOC_CTX *ctx,
     2456static NTSTATUS get_lanman2_dir_entry(TALLOC_CTX *ctx,
    22382457                                connection_struct *conn,
    22392458                                struct dptr_struct *dirptr,
    2240                                 uint16 flags2,
     2459                                uint16_t flags2,
    22412460                                const char *path_mask,
    2242                                 uint32 dirtype,
     2461                                uint32_t dirtype,
    22432462                                int info_level,
    22442463                                bool requires_resume_key,
     
    22492468                                char *end_data,
    22502469                                int space_remaining,
    2251                                 bool *out_of_space,
    22522470                                bool *got_exact_match,
    22532471                                int *last_entry_off,
     
    22682486                                         ppdata, base_data, end_data,
    22692487                                         space_remaining,
    2270                                          out_of_space, got_exact_match,
     2488                                         got_exact_match,
    22712489                                         last_entry_off, name_list);
    22722490}
     
    22912509        char *pdata = *ppdata;
    22922510        char *data_end;
    2293         uint32 dirtype;
     2511        uint32_t dirtype;
    22942512        int maxentries;
    2295         uint16 findfirst_flags;
     2513        uint16_t findfirst_flags;
    22962514        bool close_after_first;
    22972515        bool close_if_end;
     
    23162534        struct dptr_struct *dirptr = NULL;
    23172535        struct smbd_server_connection *sconn = req->sconn;
    2318         uint32_t ucf_flags = (UCF_SAVE_LCOMP | UCF_ALWAYS_ALLOW_WCARD_LCOMP);
     2536        uint32_t ucf_flags = UCF_SAVE_LCOMP | UCF_ALWAYS_ALLOW_WCARD_LCOMP |
     2537                        (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
     2538        bool backup_priv = false;
     2539        bool as_root = false;
    23192540
    23202541        if (total_params < 13) {
     
    23292550        close_if_end = (findfirst_flags & FLAG_TRANS2_FIND_CLOSE_IF_END);
    23302551        requires_resume_key = (findfirst_flags & FLAG_TRANS2_FIND_REQUIRE_RESUME);
     2552        backup_priv = ((findfirst_flags & FLAG_TRANS2_FIND_BACKUP_INTENT) &&
     2553                                security_token_has_privilege(get_current_nttok(conn),
     2554                                                SEC_PRIV_BACKUP));
     2555
    23312556        info_level = SVAL(params,6);
    23322557
    23332558        DEBUG(3,("call_trans2findfirst: dirtype = %x, maxentries = %d, close_after_first=%d, \
    2334 close_if_end = %d requires_resume_key = %d level = 0x%x, max_data_bytes = %d\n",
     2559close_if_end = %d requires_resume_key = %d backup_priv = %d level = 0x%x, max_data_bytes = %d\n",
    23352560                (unsigned int)dirtype, maxentries, close_after_first, close_if_end, requires_resume_key,
     2561                (int)backup_priv,
    23362562                info_level, max_data_bytes));
    23372563
     
    23672593        }
    23682594
    2369         srvstr_get_path_wcard(ctx, params, req->flags2, &directory,
    2370                               params+12, total_params - 12,
    2371                               STR_TERMINATE, &ntstatus, &mask_contains_wcard);
     2595        if (req->posix_pathnames) {
     2596                srvstr_get_path_wcard_posix(ctx,
     2597                                params,
     2598                                req->flags2,
     2599                                &directory,
     2600                                params+12,
     2601                                total_params - 12,
     2602                                STR_TERMINATE,
     2603                                &ntstatus,
     2604                                &mask_contains_wcard);
     2605        } else {
     2606                srvstr_get_path_wcard(ctx,
     2607                                params,
     2608                                req->flags2,
     2609                                &directory,
     2610                                params+12,
     2611                                total_params - 12,
     2612                                STR_TERMINATE,
     2613                                &ntstatus,
     2614                                &mask_contains_wcard);
     2615        }
    23722616        if (!NT_STATUS_IS_OK(ntstatus)) {
    23732617                reply_nterror(req, ntstatus);
     
    23752619        }
    23762620
    2377         ntstatus = filename_convert(ctx, conn,
     2621        if (backup_priv) {
     2622                become_root();
     2623                as_root = true;
     2624                ntstatus = filename_convert_with_privilege(ctx,
     2625                                conn,
     2626                                req,
     2627                                directory,
     2628                                ucf_flags,
     2629                                &mask_contains_wcard,
     2630                                &smb_dname);
     2631        } else {
     2632                ntstatus = filename_convert(ctx, conn,
    23782633                                    req->flags2 & FLAGS2_DFS_PATHNAMES,
    23792634                                    directory,
     
    23812636                                    &mask_contains_wcard,
    23822637                                    &smb_dname);
     2638        }
     2639
    23832640        if (!NT_STATUS_IS_OK(ntstatus)) {
    23842641                if (NT_STATUS_EQUAL(ntstatus,NT_STATUS_PATH_NOT_COVERED)) {
     
    24222679
    24232680        if (info_level == SMB_FIND_EA_LIST) {
    2424                 uint32 ea_size;
     2681                uint32_t ea_size;
    24252682
    24262683                if (total_data < 4) {
     
    24502707        }
    24512708
     2709        if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) {
     2710                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     2711                goto out;
     2712        }
     2713
    24522714        *ppdata = (char *)SMB_REALLOC(
    24532715                *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
     
    24582720        pdata = *ppdata;
    24592721        data_end = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
    2460 
     2722        /*
     2723         * squash valgrind "writev(vector[...]) points to uninitialised byte(s)"
     2724         * error.
     2725         */
     2726        memset(pdata + total_data, 0, ((max_data_bytes + DIR_ENTRY_SAFETY_MARGIN) - total_data));
    24612727        /* Realloc the params space */
    24622728        *pparams = (char *)SMB_REALLOC(*pparams, 10);
     
    24712737
    24722738        ntstatus = dptr_create(conn,
     2739                                req,
    24732740                                NULL, /* fsp */
    24742741                                directory,
     
    24862753        }
    24872754
     2755        if (backup_priv) {
     2756                /* Remember this in case we have
     2757                   to do a findnext. */
     2758                dptr_set_priv(dirptr);
     2759        }
     2760
    24882761        dptr_num = dptr_dnum(dirptr);
    24892762        DEBUG(4,("dptr_num is %d, wcard = %s, attr = %d\n", dptr_num, mask, dirtype));
     
    24962769
    24972770        DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
    2498                 directory,lp_dontdescend(SNUM(conn))));
    2499         if (in_list(directory,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
     2771                 directory,lp_dont_descend(ctx, SNUM(conn))));
     2772        if (in_list(directory,lp_dont_descend(ctx, SNUM(conn)),conn->case_sensitive))
    25002773                dont_descend = True;
    25012774
     
    25132786                        finished = False;
    25142787                } else {
    2515                         finished = !get_lanman2_dir_entry(ctx,
     2788                        ntstatus = get_lanman2_dir_entry(ctx,
    25162789                                        conn,
    25172790                                        dirptr,
     
    25212794                                        ask_sharemode,
    25222795                                        &p,pdata,data_end,
    2523                                         space_remaining, &out_of_space,
     2796                                        space_remaining,
    25242797                                        &got_exact_match,
    25252798                                        &last_entry_off, ea_list);
    2526                 }
    2527 
    2528                 if (finished && out_of_space)
    2529                         finished = False;
     2799                        if (NT_STATUS_EQUAL(ntstatus,
     2800                                        NT_STATUS_ILLEGAL_CHARACTER)) {
     2801                                /*
     2802                                 * Bad character conversion on name. Ignore this
     2803                                 * entry.
     2804                                 */
     2805                                continue;
     2806                        }
     2807                        if (NT_STATUS_EQUAL(ntstatus, STATUS_MORE_ENTRIES)) {
     2808                                out_of_space = true;
     2809                        } else {
     2810                                finished = !NT_STATUS_IS_OK(ntstatus);
     2811                        }
     2812                }
    25302813
    25312814                if (!finished && !out_of_space)
     
    25852868        SSVAL(params,8,last_entry_off);
    25862869
    2587         send_trans2_replies(conn, req, params, 10, pdata, PTR_DIFF(p,pdata),
     2870        send_trans2_replies(conn, req, NT_STATUS_OK, params, 10, pdata, PTR_DIFF(p,pdata),
    25882871                            max_data_bytes);
    25892872
     
    26122895        }
    26132896 out:
     2897
     2898        if (as_root) {
     2899                unbecome_root();
     2900        }
     2901
    26142902        TALLOC_FREE(smb_dname);
    26152903        return;
     
    26362924        int dptr_num;
    26372925        int maxentries;
    2638         uint16 info_level;
    2639         uint32 resume_key;
    2640         uint16 findnext_flags;
     2926        uint16_t info_level;
     2927        uint32_t resume_key;
     2928        uint16_t findnext_flags;
    26412929        bool close_after_request;
    26422930        bool close_if_end;
     
    26482936        const char *directory = NULL;
    26492937        char *p = NULL;
    2650         uint16 dirtype;
     2938        uint16_t dirtype;
    26512939        int numentries = 0;
    26522940        int i, last_entry_off=0;
     
    26612949        struct dptr_struct *dirptr;
    26622950        struct smbd_server_connection *sconn = req->sconn;
     2951        bool backup_priv = false;
     2952        bool as_root = false;
    26632953
    26642954        if (total_params < 13) {
     
    26792969        if (!continue_bit) {
    26802970                /* We only need resume_name if continue_bit is zero. */
    2681                 srvstr_get_path_wcard(ctx, params, req->flags2, &resume_name,
    2682                               params+12,
    2683                               total_params - 12, STR_TERMINATE, &ntstatus,
    2684                               &mask_contains_wcard);
     2971                if (req->posix_pathnames) {
     2972                        srvstr_get_path_wcard_posix(ctx,
     2973                                params,
     2974                                req->flags2,
     2975                                &resume_name,
     2976                                params+12,
     2977                                total_params - 12,
     2978                                STR_TERMINATE,
     2979                                &ntstatus,
     2980                                &mask_contains_wcard);
     2981                } else {
     2982                        srvstr_get_path_wcard(ctx,
     2983                                params,
     2984                                req->flags2,
     2985                                &resume_name,
     2986                                params+12,
     2987                                total_params - 12,
     2988                                STR_TERMINATE,
     2989                                &ntstatus,
     2990                                &mask_contains_wcard);
     2991                }
    26852992                if (!NT_STATUS_IS_OK(ntstatus)) {
    26862993                        /* Win9x or OS/2 can send a resume name of ".." or ".". This will cause the parser to
     
    27383045
    27393046        if (info_level == SMB_FIND_EA_LIST) {
    2740                 uint32 ea_size;
     3047                uint32_t ea_size;
    27413048
    27423049                if (total_data < 4) {
     
    27663073        }
    27673074
     3075        if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) {
     3076                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     3077                return;
     3078        }
     3079
    27683080        *ppdata = (char *)SMB_REALLOC(
    27693081                *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
     
    27763088        data_end = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
    27773089
     3090        /*
     3091         * squash valgrind "writev(vector[...]) points to uninitialised byte(s)"
     3092         * error.
     3093         */
     3094        memset(pdata + total_data, 0, (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN) - total_data);
    27783095        /* Realloc the params space */
    27793096        *pparams = (char *)SMB_REALLOC(*pparams, 6*SIZEOFWORD);
     
    27943111
    27953112        /* Get the wildcard mask from the dptr */
    2796         if((p = dptr_wcard(sconn, dptr_num))== NULL) {
     3113        if((mask = dptr_wcard(sconn, dptr_num))== NULL) {
    27973114                DEBUG(2,("dptr_num %d has no wildcard\n", dptr_num));
    27983115                reply_nterror(req, STATUS_NO_MORE_FILES);
     
    28003117        }
    28013118
    2802         mask = p;
    2803 
    28043119        /* Get the attr mask from the dptr */
    28053120        dirtype = dptr_attr(sconn, dptr_num);
    28063121
    2807         DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld)\n",
     3122        backup_priv = dptr_get_priv(dirptr);
     3123
     3124        DEBUG(3,("dptr_num is %d, mask = %s, attr = %x, dirptr=(0x%lX,%ld) "
     3125                "backup_priv = %d\n",
    28083126                dptr_num, mask, dirtype,
    28093127                (long)dirptr,
    2810                 dptr_TellDir(dirptr)));
     3128                dptr_TellDir(dirptr),
     3129                (int)backup_priv));
    28113130
    28123131        /* Initialize per TRANS2_FIND_NEXT operation data */
     
    28173136
    28183137        DEBUG(8,("dirpath=<%s> dontdescend=<%s>\n",
    2819                  directory,lp_dontdescend(SNUM(conn))));
    2820         if (in_list(directory,lp_dontdescend(SNUM(conn)),conn->case_sensitive))
     3138                 directory,lp_dont_descend(ctx, SNUM(conn))));
     3139        if (in_list(directory,lp_dont_descend(ctx, SNUM(conn)),conn->case_sensitive))
    28213140                dont_descend = True;
    28223141
     
    28243143        space_remaining = max_data_bytes;
    28253144        out_of_space = False;
     3145
     3146        if (backup_priv) {
     3147                become_root();
     3148                as_root = true;
     3149        }
    28263150
    28273151        /*
     
    28723196                        finished = False;
    28733197                } else {
    2874                         finished = !get_lanman2_dir_entry(ctx,
     3198                        ntstatus = get_lanman2_dir_entry(ctx,
    28753199                                                conn,
    28763200                                                dirptr,
     
    28803204                                                ask_sharemode,
    28813205                                                &p,pdata,data_end,
    2882                                                 space_remaining, &out_of_space,
     3206                                                space_remaining,
    28833207                                                &got_exact_match,
    28843208                                                &last_entry_off, ea_list);
    2885                 }
    2886 
    2887                 if (finished && out_of_space)
    2888                         finished = False;
     3209                        if (NT_STATUS_EQUAL(ntstatus,
     3210                                        NT_STATUS_ILLEGAL_CHARACTER)) {
     3211                                /*
     3212                                 * Bad character conversion on name. Ignore this
     3213                                 * entry.
     3214                                 */
     3215                                continue;
     3216                        }
     3217                        if (NT_STATUS_EQUAL(ntstatus, STATUS_MORE_ENTRIES)) {
     3218                                out_of_space = true;
     3219                        } else {
     3220                                finished = !NT_STATUS_IS_OK(ntstatus);
     3221                        }
     3222                }
    28893223
    28903224                if (!finished && !out_of_space)
     
    29143248        }
    29153249
     3250        if (as_root) {
     3251                unbecome_root();
     3252        }
     3253
    29163254        /* Set up the return parameter block */
    29173255        SSVAL(params,0,numentries);
     
    29203258        SSVAL(params,6,last_entry_off);
    29213259
    2922         send_trans2_replies(conn, req, params, 8, pdata, PTR_DIFF(p,pdata),
     3260        send_trans2_replies(conn, req, NT_STATUS_OK, params, 8, pdata, PTR_DIFF(p,pdata),
    29233261                            max_data_bytes);
    29243262
     
    29283266unsigned char *create_volume_objectid(connection_struct *conn, unsigned char objid[16])
    29293267{
    2930         E_md4hash(lp_servicename(SNUM(conn)),objid);
     3268        E_md4hash(lp_servicename(talloc_tos(), SNUM(conn)),objid);
    29313269        return objid;
    29323270}
     
    29673305}
    29683306
    2969 NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
     3307NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
     3308                         connection_struct *conn,
    29703309                         TALLOC_CTX *mem_ctx,
    29713310                         uint16_t info_level,
     
    29783317{
    29793318        char *pdata, *end_data;
    2980         int data_len = 0, len;
    2981         const char *vname = volume_label(SNUM(conn));
     3319        int data_len = 0;
     3320        size_t len = 0;
     3321        const char *vname = volume_label(talloc_tos(), SNUM(conn));
    29823322        int snum = SNUM(conn);
    2983         char *fstype = lp_fstype(SNUM(conn));
     3323        const char *fstype = lp_fstype(SNUM(conn));
    29843324        const char *filename = NULL;
    2985         uint32 additional_flags = 0;
     3325        const uint64_t bytes_per_sector = 512;
     3326        uint32_t additional_flags = 0;
    29863327        struct smb_filename smb_fname;
    29873328        SMB_STRUCT_STAT st;
    29883329        NTSTATUS status = NT_STATUS_OK;
     3330        uint64_t df_ret;
    29893331
    29903332        if (fname == NULL || fname->base_name == NULL) {
     
    30153357        st = smb_fname.st;
    30163358
     3359        if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) {
     3360                return NT_STATUS_INVALID_PARAMETER;
     3361        }
     3362
    30173363        *ppdata = (char *)SMB_REALLOC(
    30183364                *ppdata, max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
     
    30303376                case SMB_INFO_ALLOCATION:
    30313377                {
    3032                         uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
     3378                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit;
    30333379                        data_len = 18;
    3034                         if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3380                        df_ret = get_dfree_info(conn, filename, &bsize, &dfree,
     3381                                                &dsize);
     3382                        if (df_ret == (uint64_t)-1) {
    30353383                                return map_nt_error_from_unix(errno);
    30363384                        }
     
    30493397                                dfree *= factor;
    30503398                        }
    3051                         bytes_per_sector = 512;
    30523399                        sectors_per_unit = bsize/bytes_per_sector;
    30533400
     
    30703417                         * the called hostname and the service name.
    30713418                         */
    3072                         SIVAL(pdata,0,str_checksum(lp_servicename(snum)) ^ (str_checksum(get_local_machine_name())<<16) );
     3419                        SIVAL(pdata,0,str_checksum(lp_servicename(talloc_tos(), snum)) ^ (str_checksum(get_local_machine_name())<<16) );
    30733420                        /*
    30743421                         * Win2k3 and previous mess this up by sending a name length
     
    30773424                         * the pushed string. The change here was adding the STR_TERMINATE. JRA.
    30783425                         */
    3079                         len = srvstr_push(
     3426                        status = srvstr_push(
    30803427                                pdata, flags2,
    30813428                                pdata+l2_vol_szVolLabel, vname,
    30823429                                PTR_DIFF(end_data, pdata+l2_vol_szVolLabel),
    3083                                 STR_NOALIGN|STR_TERMINATE);
     3430                                STR_NOALIGN|STR_TERMINATE, &len);
     3431                        if (!NT_STATUS_IS_OK(status)) {
     3432                                return status;
     3433                        }
    30843434                        SCVAL(pdata,l2_vol_cch,len);
    30853435                        data_len = l2_vol_szVolLabel + len;
    3086                         DEBUG(5,("smbd_do_qfsinfo : time = %x, namelen = %d, name = %s\n",
     3436                        DEBUG(5,("smbd_do_qfsinfo : time = %x, namelen = %u, name = %s\n",
    30873437                                 (unsigned)convert_timespec_to_time_t(st.st_ex_ctime),
    3088                                  len, vname));
     3438                                 (unsigned)len, vname));
    30893439                        break;
    30903440
     
    31143464                        /* NOTE! the fstype must *not* be null terminated or win98 won't recognise it
    31153465                                and will think we can't do long filenames */
    3116                         len = srvstr_push(pdata, flags2, pdata+12, fstype,
     3466                        status = srvstr_push(pdata, flags2, pdata+12, fstype,
    31173467                                          PTR_DIFF(end_data, pdata+12),
    3118                                           STR_UNICODE);
     3468                                          STR_UNICODE, &len);
     3469                        if (!NT_STATUS_IS_OK(status)) {
     3470                                return status;
     3471                        }
    31193472                        SIVAL(pdata,8,len);
    31203473                        data_len = 12 + len;
     
    31303483                case SMB_QUERY_FS_LABEL_INFO:
    31313484                case SMB_FS_LABEL_INFORMATION:
    3132                         len = srvstr_push(pdata, flags2, pdata+4, vname,
    3133                                           PTR_DIFF(end_data, pdata+4), 0);
     3485                        status = srvstr_push(pdata, flags2, pdata+4, vname,
     3486                                          PTR_DIFF(end_data, pdata+4), 0, &len);
     3487                        if (!NT_STATUS_IS_OK(status)) {
     3488                                return status;
     3489                        }
    31343490                        data_len = 4 + len;
    31353491                        SIVAL(pdata,0,len);
     
    31433499                         * the called hostname and the service name.
    31443500                         */
    3145                         SIVAL(pdata,8,str_checksum(lp_servicename(snum)) ^
     3501                        SIVAL(pdata,8,str_checksum(lp_servicename(talloc_tos(), snum)) ^
    31463502                                (str_checksum(get_local_machine_name())<<16));
    31473503
    31483504                        /* Max label len is 32 characters. */
    3149                         len = srvstr_push(pdata, flags2, pdata+18, vname,
     3505                        status = srvstr_push(pdata, flags2, pdata+18, vname,
    31503506                                          PTR_DIFF(end_data, pdata+18),
    3151                                           STR_UNICODE);
     3507                                          STR_UNICODE, &len);
     3508                        if (!NT_STATUS_IS_OK(status)) {
     3509                                return status;
     3510                        }
    31523511                        SIVAL(pdata,12,len);
    31533512                        data_len = 18+len;
    31543513
    31553514                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
    3156                                 (int)strlen(vname),vname, lp_servicename(snum)));
     3515                                (int)strlen(vname),vname,
     3516                                lp_servicename(talloc_tos(), snum)));
    31573517                        if (max_data_bytes >= 24 && data_len > max_data_bytes) {
    31583518                                /* the client only requested a portion of the
     
    31613521                                status = STATUS_BUFFER_OVERFLOW;
    31623522                        }
    3163 
     3523                        *fixed_portion = 24;
    31643524                        break;
    31653525
     
    31673527                case SMB_FS_SIZE_INFORMATION:
    31683528                {
    3169                         uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
     3529                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit;
    31703530                        data_len = 24;
    3171                         if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3531                        df_ret = get_dfree_info(conn, filename, &bsize, &dfree,
     3532                                                &dsize);
     3533                        if (df_ret == (uint64_t)-1) {
    31723534                                return map_nt_error_from_unix(errno);
    31733535                        }
     
    31853547                                dfree *= factor;
    31863548                        }
    3187                         bytes_per_sector = 512;
    31883549                        sectors_per_unit = bsize/bytes_per_sector;
    31893550                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_SIZE_INFO bsize=%u, cSectorUnit=%u, \
     
    32003561                case SMB_FS_FULL_SIZE_INFORMATION:
    32013562                {
    3202                         uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
     3563                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit;
    32033564                        data_len = 32;
    3204                         if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3565                        df_ret = get_dfree_info(conn, filename, &bsize, &dfree,
     3566                                                &dsize);
     3567                        if (df_ret == (uint64_t)-1) {
    32053568                                return map_nt_error_from_unix(errno);
    32063569                        }
     
    32183581                                dfree *= factor;
    32193582                        }
    3220                         bytes_per_sector = 512;
    32213583                        sectors_per_unit = bsize/bytes_per_sector;
    32223584                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_FULL_SIZE_INFO bsize=%u, cSectorUnit=%u, \
     
    32793641
    32803642                        fsp.conn = conn;
    3281                         fsp.fnum = -1;
     3643                        fsp.fnum = FNUM_FIELD_INVALID;
    32823644
    32833645                        /* access check */
    32843646                        if (get_current_uid(conn) != 0) {
    3285                                 DEBUG(0,("set_user_quota: access_denied "
     3647                                DEBUG(0,("get_user_quota: access_denied "
    32863648                                         "service [%s] user [%s]\n",
    3287                                          lp_servicename(SNUM(conn)),
    3288                                          conn->session_info->unix_name));
     3649                                         lp_servicename(talloc_tos(), SNUM(conn)),
     3650                                         conn->session_info->unix_info->unix_name));
    32893651                                return NT_STATUS_ACCESS_DENIED;
    32903652                        }
    32913653
    32923654                        if (vfs_get_ntquota(&fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
    3293                                 DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
     3655                                DEBUG(0,("vfs_get_ntquota() failed for service [%s]\n",lp_servicename(talloc_tos(), SNUM(conn))));
    32943656                                return map_nt_error_from_unix(errno);
    32953657                        }
     
    32983660
    32993661                        DEBUG(10,("SMB_FS_QUOTA_INFORMATION: for service [%s]\n",
    3300                                   lp_servicename(SNUM(conn))));
     3662                                  lp_servicename(talloc_tos(), SNUM(conn))));
    33013663
    33023664                        /* Unknown1 24 NULL bytes*/
     
    33363698                }
    33373699
     3700                case SMB_FS_SECTOR_SIZE_INFORMATION:
     3701                {
     3702                        data_len = 28;
     3703                        /*
     3704                         * These values match a physical Windows Server 2012
     3705                         * share backed by NTFS atop spinning rust.
     3706                         */
     3707                        DEBUG(5, ("SMB_FS_SECTOR_SIZE_INFORMATION:"));
     3708                        /* logical_bytes_per_sector */
     3709                        SIVAL(pdata, 0, bytes_per_sector);
     3710                        /* phys_bytes_per_sector_atomic */
     3711                        SIVAL(pdata, 4, bytes_per_sector);
     3712                        /* phys_bytes_per_sector_perf */
     3713                        SIVAL(pdata, 8, bytes_per_sector);
     3714                        /* fs_effective_phys_bytes_per_sector_atomic */
     3715                        SIVAL(pdata, 12, bytes_per_sector);
     3716                        /* flags */
     3717                        SIVAL(pdata, 16, SSINFO_FLAGS_ALIGNED_DEVICE
     3718                                | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE);
     3719                        /* byte_off_sector_align */
     3720                        SIVAL(pdata, 20, 0);
     3721                        /* byte_off_partition_align */
     3722                        SIVAL(pdata, 24, 0);
     3723                        *fixed_portion = 28;
     3724                        break;
     3725                }
     3726
     3727
    33383728                /*
    33393729                 * Query the version and capabilities of the CIFS UNIX extensions
     
    33443734                {
    33453735                        bool large_write = lp_min_receive_file_size() &&
    3346                                         !srv_is_signing_active(conn->sconn);
    3347                         bool large_read = !srv_is_signing_active(conn->sconn);
     3736                                        !srv_is_signing_active(xconn);
     3737                        bool large_read = !srv_is_signing_active(xconn);
    33483738                        int encrypt_caps = 0;
    33493739
     
    33533743
    33543744                        switch (conn->encrypt_level) {
    3355                         case 0:
     3745                        case SMB_SIGNING_OFF:
    33563746                                encrypt_caps = 0;
    33573747                                break;
    3358                         case 1:
    3359                         case Auto:
     3748                        case SMB_SIGNING_DESIRED:
     3749                        case SMB_SIGNING_IF_REQUIRED:
     3750                        case SMB_SIGNING_DEFAULT:
    33603751                                encrypt_caps = CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP;
    33613752                                break;
    3362                         case Required:
     3753                        case SMB_SIGNING_REQUIRED:
    33633754                                encrypt_caps = CIFS_UNIX_TRANSPORT_ENCRYPTION_CAP|
    33643755                                                CIFS_UNIX_TRANSPORT_ENCRYPTION_MANDATORY_CAP;
     
    34153806#endif /* EOPNOTSUPP */
    34163807                        } else {
    3417                                 DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(SNUM(conn))));
     3808                                DEBUG(0,("vfs_statvfs() failed for service [%s]\n",lp_servicename(talloc_tos(), SNUM(conn))));
    34183809                                return NT_STATUS_DOS(ERRSRV, ERRerror);
    34193810                        }
    3420                         *fixed_portion = 24;
    34213811                        break;
    34223812                }
     
    34363826                        }
    34373827
    3438                         /* We ARE guest if global_sid_Builtin_Guests is
    3439                          * in our list of SIDs.
    3440                          */
    3441                         if (nt_token_check_sid(&global_sid_Builtin_Guests,
    3442                                                conn->session_info->security_token)) {
     3828                        if (security_session_user_level(conn->session_info, NULL) < SECURITY_USER) {
    34433829                                flags |= SMB_WHOAMI_GUEST;
    3444                         }
    3445 
    3446                         /* We are NOT guest if global_sid_Authenticated_Users
    3447                          * is in our list of SIDs.
    3448                          */
    3449                         if (nt_token_check_sid(&global_sid_Authenticated_Users,
    3450                                                conn->session_info->security_token)) {
    3451                                 flags &= ~SMB_WHOAMI_GUEST;
    34523830                        }
    34533831
     
    34643842                            + 4 /* SID bytes */
    34653843                            + 4 /* pad/reserved */
    3466                             + (conn->session_info->utok.ngroups * 8)
     3844                            + (conn->session_info->unix_token->ngroups * 8)
    34673845                                /* groups list */
    34683846                            + (conn->session_info->security_token->num_sids *
     
    34733851                        SIVAL(pdata, 4, SMB_WHOAMI_MASK);
    34743852                        SBIG_UINT(pdata, 8,
    3475                                   (uint64_t)conn->session_info->utok.uid);
     3853                                  (uint64_t)conn->session_info->unix_token->uid);
    34763854                        SBIG_UINT(pdata, 16,
    3477                                   (uint64_t)conn->session_info->utok.gid);
     3855                                  (uint64_t)conn->session_info->unix_token->gid);
    34783856
    34793857
     
    34903868                        }
    34913869
    3492                         SIVAL(pdata, 24, conn->session_info->utok.ngroups);
     3870                        SIVAL(pdata, 24, conn->session_info->unix_token->ngroups);
    34933871                        SIVAL(pdata, 28, conn->session_info->security_token->num_sids);
    34943872
     
    35123890
    35133891                        /* GID list */
    3514                         for (i = 0; i < conn->session_info->utok.ngroups; ++i) {
     3892                        for (i = 0; i < conn->session_info->unix_token->ngroups; ++i) {
    35153893                                SBIG_UINT(pdata, data_len,
    3516                                           (uint64_t)conn->session_info->utok.groups[i]);
     3894                                          (uint64_t)conn->session_info->unix_token->groups[i]);
    35173895                                data_len += 8;
    35183896                        }
     
    35253903                                        0);
    35263904
    3527                                 sid_linearize(pdata + data_len, sid_len,
     3905                                sid_linearize((uint8_t *)(pdata + data_len),
     3906                                              sid_len,
    35283907                                    &conn->session_info->security_token->sids[i]);
    35293908                                data_len += sid_len;
     
    35503929        *ret_data_len = data_len;
    35513930        return status;
     3931}
     3932
     3933static NTSTATUS smb_set_fsquota(connection_struct *conn,
     3934                        struct smb_request *req,
     3935                        files_struct *fsp,
     3936                        const DATA_BLOB *qdata)
     3937{
     3938        NTSTATUS status;
     3939        SMB_NTQUOTA_STRUCT quotas;
     3940
     3941        ZERO_STRUCT(quotas);
     3942
     3943        /* access check */
     3944        if ((get_current_uid(conn) != 0) || !CAN_WRITE(conn)) {
     3945                DEBUG(3, ("set_fsquota: access_denied service [%s] user [%s]\n",
     3946                          lp_servicename(talloc_tos(), SNUM(conn)),
     3947                          conn->session_info->unix_info->unix_name));
     3948                return NT_STATUS_ACCESS_DENIED;
     3949        }
     3950
     3951        if (!check_fsp_ntquota_handle(conn, req,
     3952                                      fsp)) {
     3953                DEBUG(1, ("set_fsquota: no valid QUOTA HANDLE\n"));
     3954                return NT_STATUS_INVALID_HANDLE;
     3955        }
     3956
     3957        /* note: normally there're 48 bytes,
     3958         * but we didn't use the last 6 bytes for now
     3959         * --metze
     3960         */
     3961        if (qdata->length < 42) {
     3962                DEBUG(0,("set_fsquota: requires total_data(%u) >= 42 bytes!\n",
     3963                        (unsigned int)qdata->length));
     3964                return NT_STATUS_INVALID_PARAMETER;
     3965        }
     3966
     3967        /* unknown_1 24 NULL bytes in pdata*/
     3968
     3969        /* the soft quotas 8 bytes (uint64_t)*/
     3970        quotas.softlim = BVAL(qdata->data,24);
     3971
     3972        /* the hard quotas 8 bytes (uint64_t)*/
     3973        quotas.hardlim = BVAL(qdata->data,32);
     3974
     3975        /* quota_flags 2 bytes **/
     3976        quotas.qflags = SVAL(qdata->data,40);
     3977
     3978        /* unknown_2 6 NULL bytes follow*/
     3979
     3980        /* now set the quotas */
     3981        if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
     3982                DEBUG(1, ("vfs_set_ntquota() failed for service [%s]\n",
     3983                          lp_servicename(talloc_tos(), SNUM(conn))));
     3984                status =  map_nt_error_from_unix(errno);
     3985        } else {
     3986                status = NT_STATUS_OK;
     3987        }
     3988        return status;
     3989}
     3990
     3991NTSTATUS smbd_do_setfsinfo(connection_struct *conn,
     3992                                struct smb_request *req,
     3993                                TALLOC_CTX *mem_ctx,
     3994                                uint16_t info_level,
     3995                                files_struct *fsp,
     3996                                const DATA_BLOB *pdata)
     3997{
     3998        switch (info_level) {
     3999                case SMB_FS_QUOTA_INFORMATION:
     4000                {
     4001                        return smb_set_fsquota(conn,
     4002                                                req,
     4003                                                fsp,
     4004                                                pdata);
     4005                }
     4006
     4007                default:
     4008                        break;
     4009        }
     4010        return NT_STATUS_INVALID_LEVEL;
    35524011}
    35534012
     
    35804039                                "and info level 0x%x sent.\n",
    35814040                                (unsigned int)info_level));
    3582                         exit_server_cleanly("encryption required "
    3583                                 "on connection");
     4041                        reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    35844042                        return;
    35854043                }
     
    35884046        DEBUG(3,("call_trans2qfsinfo: level = %d\n", info_level));
    35894047
    3590         status = smbd_do_qfsinfo(conn, req,
     4048        status = smbd_do_qfsinfo(req->xconn, conn, req,
    35914049                                 info_level,
    35924050                                 req->flags2,
     
    36004058        }
    36014059
    3602         send_trans2_replies(conn, req, params, 0, *ppdata, data_len,
     4060        send_trans2_replies(conn, req, NT_STATUS_OK, params, 0, *ppdata, data_len,
    36034061                            max_data_bytes);
    36044062
     
    36194077                                 unsigned int max_data_bytes)
    36204078{
     4079        struct smbXsrv_connection *xconn = req->xconn;
    36214080        char *pdata = *ppdata;
    36224081        char *params = *pparams;
    3623         uint16 info_level;
    3624 
    3625         DEBUG(10,("call_trans2setfsinfo: for service [%s]\n",lp_servicename(SNUM(conn))));
     4082        uint16_t info_level;
     4083
     4084        DEBUG(10,("call_trans2setfsinfo: for service [%s]\n",
     4085                  lp_servicename(talloc_tos(), SNUM(conn))));
    36264086
    36274087        /*  */
     
    36514111                                "and info level 0x%x sent.\n",
    36524112                                (unsigned int)info_level));
    3653                         exit_server_cleanly("encryption required "
    3654                                 "on connection");
     4113                        reply_nterror(req, NT_STATUS_ACCESS_DENIED);
    36554114                        return;
    36564115                }
     
    36594118        switch(info_level) {
    36604119                case SMB_SET_CIFS_UNIX_INFO:
    3661                         {
    3662                                 uint16 client_unix_major;
    3663                                 uint16 client_unix_minor;
    3664                                 uint32 client_unix_cap_low;
    3665                                 uint32 client_unix_cap_high;
    3666 
    3667                                 if (!lp_unix_extensions()) {
    3668                                         reply_nterror(req,
    3669                                                       NT_STATUS_INVALID_LEVEL);
    3670                                         return;
    3671                                 }
    3672 
    3673                                 /* There should be 12 bytes of capabilities set. */
    3674                                 if (total_data < 8) {
    3675                                         reply_nterror(
    3676                                                 req,
    3677                                                 NT_STATUS_INVALID_PARAMETER);
    3678                                         return;
    3679                                 }
    3680                                 client_unix_major = SVAL(pdata,0);
    3681                                 client_unix_minor = SVAL(pdata,2);
    3682                                 client_unix_cap_low = IVAL(pdata,4);
    3683                                 client_unix_cap_high = IVAL(pdata,8);
    3684                                 /* Just print these values for now. */
    3685                                 DEBUG(10,("call_trans2setfsinfo: set unix info. major = %u, minor = %u \
    3686 cap_low = 0x%x, cap_high = 0x%x\n",
    3687                                         (unsigned int)client_unix_major,
    3688                                         (unsigned int)client_unix_minor,
    3689                                         (unsigned int)client_unix_cap_low,
    3690                                         (unsigned int)client_unix_cap_high ));
    3691 
    3692                                 /* Here is where we must switch to posix pathname processing... */
    3693                                 if (client_unix_cap_low & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
    3694                                         lp_set_posix_pathnames();
    3695                                         mangle_change_to_posix();
    3696                                 }
    3697 
    3698                                 if ((client_unix_cap_low & CIFS_UNIX_FCNTL_LOCKS_CAP) &&
    3699                                     !(client_unix_cap_low & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP)) {
    3700                                         /* Client that knows how to do posix locks,
    3701                                          * but not posix open/mkdir operations. Set a
    3702                                          * default type for read/write checks. */
    3703 
    3704                                         lp_set_posix_default_cifsx_readwrite_locktype(POSIX_LOCK);
    3705 
    3706                                 }
    3707                                 break;
    3708                         }
     4120                        if (!lp_unix_extensions()) {
     4121                                DEBUG(2,("call_trans2setfsinfo: "
     4122                                        "SMB_SET_CIFS_UNIX_INFO is invalid with "
     4123                                        "unix extensions off\n"));
     4124                                reply_nterror(req,
     4125                                              NT_STATUS_INVALID_LEVEL);
     4126                                return;
     4127                        }
     4128
     4129                        /* There should be 12 bytes of capabilities set. */
     4130                        if (total_data < 12) {
     4131                                reply_nterror(
     4132                                        req,
     4133                                        NT_STATUS_INVALID_PARAMETER);
     4134                                return;
     4135                        }
     4136                        xconn->smb1.unix_info.client_major = SVAL(pdata,0);
     4137                        xconn->smb1.unix_info.client_minor = SVAL(pdata,2);
     4138                        xconn->smb1.unix_info.client_cap_low = IVAL(pdata,4);
     4139                        xconn->smb1.unix_info.client_cap_high = IVAL(pdata,8);
     4140                        /* Just print these values for now. */
     4141                        DEBUG(10, ("call_trans2setfsinfo: set unix_info info. "
     4142                                   "major = %u, minor = %u cap_low = 0x%x, "
     4143                                   "cap_high = 0x%xn",
     4144                                   (unsigned int)xconn->
     4145                                   smb1.unix_info.client_major,
     4146                                   (unsigned int)xconn->
     4147                                   smb1.unix_info.client_minor,
     4148                                   (unsigned int)xconn->
     4149                                   smb1.unix_info.client_cap_low,
     4150                                   (unsigned int)xconn->
     4151                                   smb1.unix_info.client_cap_high));
     4152
     4153                        /* Here is where we must switch to posix pathname processing... */
     4154                        if (xconn->smb1.unix_info.client_cap_low & CIFS_UNIX_POSIX_PATHNAMES_CAP) {
     4155                                lp_set_posix_pathnames();
     4156                                mangle_change_to_posix();
     4157                        }
     4158
     4159                        if ((xconn->smb1.unix_info.client_cap_low & CIFS_UNIX_FCNTL_LOCKS_CAP) &&
     4160                            !(xconn->smb1.unix_info.client_cap_low & CIFS_UNIX_POSIX_PATH_OPERATIONS_CAP)) {
     4161                                /* Client that knows how to do posix locks,
     4162                                 * but not posix open/mkdir operations. Set a
     4163                                 * default type for read/write checks. */
     4164
     4165                                lp_set_posix_default_cifsx_readwrite_locktype(POSIX_LOCK);
     4166
     4167                        }
     4168                        break;
    37094169
    37104170                case SMB_REQUEST_TRANSPORT_ENCRYPTION:
     
    37214181                                }
    37224182
    3723                                 if (lp_smb_encrypt(SNUM(conn)) == false) {
     4183                                if (lp_smb_encrypt(SNUM(conn)) == SMB_SIGNING_OFF) {
    37244184                                        reply_nterror(
    37254185                                                req,
     
    37284188                                }
    37294189
    3730                                 if (req->sconn->smb1.echo_handler.trusted_fde) {
     4190                                if (xconn->smb1.echo_handler.trusted_fde) {
    37314191                                        DEBUG( 2,("call_trans2setfsinfo: "
    37324192                                                "request transport encryption disabled"
     
    37544214
    37554215                                send_trans2_replies(conn, req,
     4216                                                NT_STATUS_OK,
    37564217                                                *pparams,
    37574218                                                param_len,
     
    37654226                                        status = srv_encryption_start(conn);
    37664227                                        if (!NT_STATUS_IS_OK(status)) {
    3767                                                 exit_server_cleanly(
    3768                                                         "Failure in setting "
    3769                                                         "up encrypted transport");
     4228                                                char *reason = talloc_asprintf(talloc_tos(),
     4229                                                                               "Failure in setting "
     4230                                                                               "up encrypted transport: %s",
     4231                                                                               nt_errstr(status));
     4232                                                exit_server_cleanly(reason);
    37704233                                        }
    37714234                                }
     
    37754238                case SMB_FS_QUOTA_INFORMATION:
    37764239                        {
     4240                                NTSTATUS status;
     4241                                DATA_BLOB qdata = {
     4242                                                .data = (uint8_t *)pdata,
     4243                                                .length = total_data
     4244                                };
    37774245                                files_struct *fsp = NULL;
    3778                                 SMB_NTQUOTA_STRUCT quotas;
    3779 
    3780                                 ZERO_STRUCT(quotas);
    3781 
    3782                                 /* access check */
    3783                                 if ((get_current_uid(conn) != 0) || !CAN_WRITE(conn)) {
    3784                                         DEBUG(0,("set_user_quota: access_denied service [%s] user [%s]\n",
    3785                                                  lp_servicename(SNUM(conn)),
    3786                                                  conn->session_info->unix_name));
    3787                                         reply_nterror(req, NT_STATUS_ACCESS_DENIED);
     4246                                fsp = file_fsp(req, SVAL(params,0));
     4247
     4248                                status = smb_set_fsquota(conn,
     4249                                                        req,
     4250                                                        fsp,
     4251                                                        &qdata);
     4252                                if (!NT_STATUS_IS_OK(status)) {
     4253                                        reply_nterror(req, status);
    37884254                                        return;
    37894255                                }
    3790 
    3791                                 /* note: normaly there're 48 bytes,
    3792                                  * but we didn't use the last 6 bytes for now
    3793                                  * --metze
    3794                                  */
    3795                                 fsp = file_fsp(req, SVAL(params,0));
    3796 
    3797                                 if (!check_fsp_ntquota_handle(conn, req,
    3798                                                               fsp)) {
    3799                                         DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
    3800                                         reply_nterror(
    3801                                                 req, NT_STATUS_INVALID_HANDLE);
    3802                                         return;
    3803                                 }
    3804 
    3805                                 if (total_data < 42) {
    3806                                         DEBUG(0,("call_trans2setfsinfo: SET_FS_QUOTA: requires total_data(%d) >= 42 bytes!\n",
    3807                                                 total_data));
    3808                                         reply_nterror(
    3809                                                 req,
    3810                                                 NT_STATUS_INVALID_PARAMETER);
    3811                                         return;
    3812                                 }
    3813 
    3814                                 /* unknown_1 24 NULL bytes in pdata*/
    3815 
    3816                                 /* the soft quotas 8 bytes (uint64_t)*/
    3817                                 quotas.softlim = BVAL(pdata,24);
    3818 
    3819                                 /* the hard quotas 8 bytes (uint64_t)*/
    3820                                 quotas.hardlim = BVAL(pdata,32);
    3821 
    3822                                 /* quota_flags 2 bytes **/
    3823                                 quotas.qflags = SVAL(pdata,40);
    3824 
    3825                                 /* unknown_2 6 NULL bytes follow*/
    3826 
    3827                                 /* now set the quotas */
    3828                                 if (vfs_set_ntquota(fsp, SMB_USER_FS_QUOTA_TYPE, NULL, &quotas)!=0) {
    3829                                         DEBUG(0,("vfs_set_ntquota() failed for service [%s]\n",lp_servicename(SNUM(conn))));
    3830                                         reply_nterror(req, map_nt_error_from_unix(errno));
    3831                                         return;
    3832                                 }
    3833 
    38344256                                break;
    38354257                        }
     
    38624284        SMB_ACL_ENTRY_T entry;
    38634285
    3864         while ( posix_acl && (SMB_VFS_SYS_ACL_GET_ENTRY(conn, posix_acl, entry_id, &entry) == 1)) {
     4286        while ( posix_acl && (sys_acl_get_entry(posix_acl, entry_id, &entry) == 1)) {
    38654287                /* get_next... */
    38664288                if (entry_id == SMB_ACL_FIRST_ENTRY) {
     
    38814303        SMB_ACL_ENTRY_T entry;
    38824304
    3883         while ( posix_acl && (SMB_VFS_SYS_ACL_GET_ENTRY(conn, posix_acl, entry_id, &entry) == 1)) {
     4305        while ( posix_acl && (sys_acl_get_entry(posix_acl, entry_id, &entry) == 1)) {
    38844306                SMB_ACL_TAG_T tagtype;
    38854307                SMB_ACL_PERMSET_T permset;
     
    38924314                }
    38934315
    3894                 if (SMB_VFS_SYS_ACL_GET_TAG_TYPE(conn, entry, &tagtype) == -1) {
     4316                if (sys_acl_get_tag_type(entry, &tagtype) == -1) {
    38954317                        DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_TAG_TYPE failed.\n"));
    38964318                        return False;
    38974319                }
    38984320
    3899                 if (SMB_VFS_SYS_ACL_GET_PERMSET(conn, entry, &permset) == -1) {
     4321                if (sys_acl_get_permset(entry, &permset) == -1) {
    39004322                        DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_PERMSET failed.\n"));
    39014323                        return False;
    39024324                }
    39034325
    3904                 perms |= (SMB_VFS_SYS_ACL_GET_PERM(conn, permset, SMB_ACL_READ) ? SMB_POSIX_ACL_READ : 0);
    3905                 perms |= (SMB_VFS_SYS_ACL_GET_PERM(conn, permset, SMB_ACL_WRITE) ? SMB_POSIX_ACL_WRITE : 0);
    3906                 perms |= (SMB_VFS_SYS_ACL_GET_PERM(conn, permset, SMB_ACL_EXECUTE) ? SMB_POSIX_ACL_EXECUTE : 0);
     4326                perms |= (sys_acl_get_perm(permset, SMB_ACL_READ) ? SMB_POSIX_ACL_READ : 0);
     4327                perms |= (sys_acl_get_perm(permset, SMB_ACL_WRITE) ? SMB_POSIX_ACL_WRITE : 0);
     4328                perms |= (sys_acl_get_perm(permset, SMB_ACL_EXECUTE) ? SMB_POSIX_ACL_EXECUTE : 0);
    39074329
    39084330                SCVAL(pdata,1,perms);
     
    39174339                        case SMB_ACL_USER:
    39184340                                {
    3919                                         uid_t *puid = (uid_t *)SMB_VFS_SYS_ACL_GET_QUALIFIER(conn, entry);
     4341                                        uid_t *puid = (uid_t *)sys_acl_get_qualifier(entry);
    39204342                                        if (!puid) {
    39214343                                                DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n"));
     
    39234345                                        }
    39244346                                        own_grp = (unsigned int)*puid;
    3925                                         SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn, (void *)puid,tagtype);
    39264347                                        SCVAL(pdata,0,SMB_POSIX_ACL_USER);
    39274348                                        SIVAL(pdata,2,own_grp);
     
    39374358                        case SMB_ACL_GROUP:
    39384359                                {
    3939                                         gid_t *pgid= (gid_t *)SMB_VFS_SYS_ACL_GET_QUALIFIER(conn, entry);
     4360                                        gid_t *pgid= (gid_t *)sys_acl_get_qualifier(entry);
    39404361                                        if (!pgid) {
    39414362                                                DEBUG(0,("marshall_posix_acl: SMB_VFS_SYS_ACL_GET_QUALIFIER failed.\n"));
     
    39434364                                        }
    39444365                                        own_grp = (unsigned int)*pgid;
    3945                                         SMB_VFS_SYS_ACL_FREE_QUALIFIER(conn, (void *)pgid,tagtype);
    39464366                                        SCVAL(pdata,0,SMB_POSIX_ACL_GROUP);
    39474367                                        SIVAL(pdata,2,own_grp);
     
    39804400{
    39814401        uint64_t file_index = get_FileIndex(conn, psbuf);
     4402        dev_t devno;
    39824403
    39834404        DEBUG(10,("store_file_unix_basic: SMB_QUERY_FILE_UNIX_BASIC\n"));
     
    40064427        pdata += 4;
    40074428
    4008         SIVAL(pdata,0,unix_dev_major(psbuf->st_ex_rdev));   /* Major device number if type is device */
     4429        if (S_ISBLK(psbuf->st_ex_mode) || S_ISCHR(psbuf->st_ex_mode)) {
     4430                devno = psbuf->st_ex_rdev;
     4431        } else {
     4432                devno = psbuf->st_ex_dev;
     4433        }
     4434
     4435        SIVAL(pdata,0,unix_dev_major(devno));   /* Major device number if type is device */
    40094436        SIVAL(pdata,4,0);
    40104437        pdata += 8;
    40114438
    4012         SIVAL(pdata,0,unix_dev_minor(psbuf->st_ex_rdev));   /* Minor device number if type is device */
     4439        SIVAL(pdata,0,unix_dev_minor(devno));   /* Minor device number if type is device */
    40134440        SIVAL(pdata,4,0);
    40144441        pdata += 8;
     
    40634490
    40644491static void map_info2_flags_from_sbuf(const SMB_STRUCT_STAT *psbuf,
    4065                                 uint32 *smb_fflags, uint32 *smb_fmask)
     4492                                uint32_t *smb_fflags, uint32_t *smb_fmask)
    40664493{
    40674494        int i;
     
    40764503
    40774504static bool map_info2_flags_to_sbuf(const SMB_STRUCT_STAT *psbuf,
    4078                                 const uint32 smb_fflags,
    4079                                 const uint32 smb_fmask,
     4505                                const uint32_t smb_fflags,
     4506                                const uint32_t smb_fmask,
    40804507                                int *stat_fflags)
    40814508{
    4082         uint32 max_fmask = 0;
     4509        uint32_t max_fmask = 0;
    40834510        int i;
    40844511
     
    41204547                                const SMB_STRUCT_STAT *psbuf)
    41214548{
    4122         uint32 file_flags = 0;
    4123         uint32 flags_mask = 0;
     4549        uint32_t file_flags = 0;
     4550        uint32_t flags_mask = 0;
    41244551
    41254552        pdata = store_file_unix_basic(conn, pdata, fsp, psbuf);
     
    42334660        unsigned int data_size = 0;
    42344661        unsigned int param_size = 2;
    4235         uint16 info_level;
     4662        uint16_t info_level;
    42364663        files_struct *fsp;
    42374664
     
    42614688        params = *pparams;
    42624689        SSVAL(params,0,0);
     4690        if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) {
     4691                reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
     4692                return;
     4693        }
    42634694        data_size = max_data_bytes + DIR_ENTRY_SAFETY_MARGIN;
    42644695        *ppdata = (char *)SMB_REALLOC(*ppdata, data_size);
     
    42834714        }
    42844715
    4285         send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,
     4716        send_trans2_replies(conn, req, NT_STATUS_OK, params, param_size, *ppdata, data_size,
    42864717                            max_data_bytes);
    42874718
     
    43224753        uint64_t file_index = 0;
    43234754        uint32_t access_mask = 0;
     4755        size_t len = 0;
    43244756
    43254757        if (INFO_LEVEL_IS_UNIX(info_level) && !lp_unix_extensions()) {
     
    43274759        }
    43284760
    4329         DEBUG(5,("smbd_do_qfilepathinfo: %s (fnum = %d) level=%d max_data=%u\n",
    4330                  smb_fname_str_dbg(smb_fname), fsp ? fsp->fnum : -1,
     4761        DEBUG(5,("smbd_do_qfilepathinfo: %s (%s) level=%d max_data=%u\n",
     4762                 smb_fname_str_dbg(smb_fname),
     4763                 fsp_fnum_dbg(fsp),
    43314764                 info_level, max_data_bytes));
    43324765
     
    43404773        if ((nlink > 0) && delete_pending) {
    43414774                nlink -= 1;
     4775        }
     4776
     4777        if (max_data_bytes + DIR_ENTRY_SAFETY_MARGIN < max_data_bytes) {
     4778                return NT_STATUS_INVALID_PARAMETER;
    43424779        }
    43434780
     
    44464883                        srv_put_dos_date2(pdata,l1_fdateLastAccess,atime);
    44474884                        srv_put_dos_date2(pdata,l1_fdateLastWrite,mtime); /* write time */
    4448                         SIVAL(pdata,l1_cbFile,(uint32)file_size);
    4449                         SIVAL(pdata,l1_cbFileAlloc,(uint32)allocation_size);
     4885                        SIVAL(pdata,l1_cbFile,(uint32_t)file_size);
     4886                        SIVAL(pdata,l1_cbFileAlloc,(uint32_t)allocation_size);
    44504887                        SSVAL(pdata,l1_attrFile,mode);
    44514888                        break;
     
    44554892                        unsigned int ea_size =
    44564893                            estimate_ea_size(conn, fsp,
    4457                                              smb_fname->base_name);
     4894                                             smb_fname);
    44584895                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EA_SIZE\n"));
    44594896                        data_size = 26;
     
    44614898                        srv_put_dos_date2(pdata,4,atime);
    44624899                        srv_put_dos_date2(pdata,8,mtime); /* write time */
    4463                         SIVAL(pdata,12,(uint32)file_size);
    4464                         SIVAL(pdata,16,(uint32)allocation_size);
     4900                        SIVAL(pdata,12,(uint32_t)file_size);
     4901                        SIVAL(pdata,16,(uint32_t)allocation_size);
    44654902                        SSVAL(pdata,20,mode);
    44664903                        SIVAL(pdata,22,ea_size);
     
    44824919                        size_t total_ea_len = 0;
    44834920                        struct ea_list *ea_file_list = NULL;
    4484 
    44854921                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_EAS_FROM_LIST\n"));
    44864922
    4487                         ea_file_list =
     4923                        status =
    44884924                            get_ea_list_from_file(mem_ctx, conn, fsp,
    4489                                                   smb_fname->base_name,
    4490                                                   &total_ea_len);
     4925                                                  smb_fname,
     4926                                                  &total_ea_len, &ea_file_list);
     4927                        if (!NT_STATUS_IS_OK(status)) {
     4928                                return status;
     4929                        }
     4930
    44914931                        ea_list = ea_list_union(ea_list, ea_file_list, &total_ea_len);
    44924932
     
    45054945                        /* We have data_size bytes to put EA's into. */
    45064946                        size_t total_ea_len = 0;
    4507 
    45084947                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_INFO_QUERY_ALL_EAS\n"));
    45094948
    4510                         ea_list = get_ea_list_from_file(mem_ctx, conn, fsp,
    4511                                                         smb_fname->base_name,
    4512                                                         &total_ea_len);
     4949                        status = get_ea_list_from_file(mem_ctx, conn, fsp,
     4950                                                        smb_fname,
     4951                                                        &total_ea_len, &ea_list);
     4952                        if (!NT_STATUS_IS_OK(status)) {
     4953                                return status;
     4954                        }
     4955
    45134956                        if (!ea_list || (total_ea_len > data_size)) {
    45144957                                data_size = 4;
     
    45344977                        /*TODO: add filtering and index handling */
    45354978
    4536                         ea_file_list =
    4537                             get_ea_list_from_file(mem_ctx, conn, fsp,
    4538                                                   smb_fname->base_name,
    4539                                                   &total_ea_len);
     4979                        status  =
     4980                                get_ea_list_from_file(mem_ctx, conn, fsp,
     4981                                                  smb_fname,
     4982                                                  &total_ea_len, &ea_file_list);
     4983                        if (!NT_STATUS_IS_OK(status)) {
     4984                                return status;
     4985                        }
    45404986                        if (!ea_file_list) {
    45414987                                return NT_STATUS_NO_EAS_ON_FILE;
     
    45975043                {
    45985044                        unsigned int ea_size =
    4599                             estimate_ea_size(conn, fsp, smb_fname->base_name);
     5045                            estimate_ea_size(conn, fsp, smb_fname);
    46005046                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
    46015047                        data_size = 4;
     
    46095055                case SMB_FILE_ALTERNATE_NAME_INFORMATION:
    46105056                {
    4611                         int len;
    46125057                        char mangled_name[13];
    46135058                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALTERNATE_NAME_INFORMATION\n"));
     
    46165061                                return NT_STATUS_NO_MEMORY;
    46175062                        }
    4618                         len = srvstr_push(dstart, flags2,
     5063                        status = srvstr_push(dstart, flags2,
    46195064                                          pdata+4, mangled_name,
    46205065                                          PTR_DIFF(dend, pdata+4),
    4621                                           STR_UNICODE);
     5066                                          STR_UNICODE, &len);
     5067                        if (!NT_STATUS_IS_OK(status)) {
     5068                                return status;
     5069                        }
    46225070                        data_size = 4 + len;
    46235071                        SIVAL(pdata,0,len);
     
    46285076                case SMB_QUERY_FILE_NAME_INFO:
    46295077                {
    4630                         int len;
    46315078                        /*
    46325079                          this must be *exactly* right for ACLs on mapped drives to work
    46335080                         */
    4634                         len = srvstr_push(dstart, flags2,
     5081                        status = srvstr_push(dstart, flags2,
    46355082                                          pdata+4, dos_fname,
    46365083                                          PTR_DIFF(dend, pdata+4),
    4637                                           STR_UNICODE);
     5084                                          STR_UNICODE, &len);
     5085                        if (!NT_STATUS_IS_OK(status)) {
     5086                                return status;
     5087                        }
    46385088                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_QUERY_FILE_NAME_INFO\n"));
    46395089                        data_size = 4 + len;
     
    46595109                case SMB_FILE_ALL_INFORMATION:
    46605110                {
    4661                         int len;
    46625111                        unsigned int ea_size =
    4663                             estimate_ea_size(conn, fsp, smb_fname->base_name);
     5112                            estimate_ea_size(conn, fsp, smb_fname);
    46645113                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_ALL_INFORMATION\n"));
    46655114                        put_long_date_timespec(conn->ts_res,pdata,create_time_ts);
     
    46795128                        SIVAL(pdata,0,ea_size);
    46805129                        pdata += 4; /* EA info */
    4681                         len = srvstr_push(dstart, flags2,
     5130                        status = srvstr_push(dstart, flags2,
    46825131                                          pdata+4, dos_fname,
    46835132                                          PTR_DIFF(dend, pdata+4),
    4684                                           STR_UNICODE);
     5133                                          STR_UNICODE, &len);
     5134                        if (!NT_STATUS_IS_OK(status)) {
     5135                                return status;
     5136                        }
    46855137                        SIVAL(pdata,0,len);
    46865138                        pdata += 4 + len;
     
    46925144                case 0xFF12:/*SMB2_FILE_ALL_INFORMATION*/
    46935145                {
    4694                         int len;
    46955146                        unsigned int ea_size =
    4696                             estimate_ea_size(conn, fsp, smb_fname->base_name);
     5147                            estimate_ea_size(conn, fsp, smb_fname);
    46975148                        DEBUG(10,("smbd_do_qfilepathinfo: SMB2_FILE_ALL_INFORMATION\n"));
    46985149                        put_long_date_timespec(conn->ts_res,pdata+0x00,create_time_ts);
     
    47175168                        pdata += 0x60;
    47185169
    4719                         len = srvstr_push(dstart, flags2,
     5170                        status = srvstr_push(dstart, flags2,
    47205171                                          pdata+4, dos_fname,
    47215172                                          PTR_DIFF(dend, pdata+4),
    4722                                           STR_UNICODE);
     5173                                          STR_UNICODE, &len);
     5174                        if (!NT_STATUS_IS_OK(status)) {
     5175                                return status;
     5176                        }
    47235177                        SIVAL(pdata,0,len);
    47245178                        pdata += 4 + len;
     
    48925346                case SMB_QUERY_FILE_UNIX_LINK:
    48935347                        {
    4894                                 int len;
    4895                                 char *buffer = TALLOC_ARRAY(mem_ctx, char, PATH_MAX+1);
     5348                                int link_len = 0;
     5349                                char *buffer = talloc_array(mem_ctx, char, PATH_MAX+1);
    48965350
    48975351                                if (!buffer) {
     
    49075361                                return NT_STATUS_DOS(ERRDOS, ERRbadlink);
    49085362#endif
    4909                                 len = SMB_VFS_READLINK(conn,
     5363                                link_len = SMB_VFS_READLINK(conn,
    49105364                                                       smb_fname->base_name,
    49115365                                                       buffer, PATH_MAX);
    4912                                 if (len == -1) {
     5366                                if (link_len == -1) {
    49135367                                        return map_nt_error_from_unix(errno);
    49145368                                }
    4915                                 buffer[len] = 0;
    4916                                 len = srvstr_push(dstart, flags2,
     5369                                buffer[link_len] = 0;
     5370                                status = srvstr_push(dstart, flags2,
    49175371                                                  pdata, buffer,
    49185372                                                  PTR_DIFF(dend, pdata),
    4919                                                   STR_TERMINATE);
     5373                                                  STR_TERMINATE, &len);
     5374                                if (!NT_STATUS_IS_OK(status)) {
     5375                                        return status;
     5376                                }
    49205377                                pdata += len;
    49215378                                data_size = PTR_DIFF(pdata,(*ppdata));
     
    49295386                                SMB_ACL_T file_acl = NULL;
    49305387                                SMB_ACL_T def_acl = NULL;
    4931                                 uint16 num_file_acls = 0;
    4932                                 uint16 num_def_acls = 0;
     5388                                uint16_t num_file_acls = 0;
     5389                                uint16_t num_def_acls = 0;
     5390
     5391                                status = refuse_symlink(conn,
     5392                                                fsp,
     5393                                                smb_fname->base_name);
     5394                                if (!NT_STATUS_IS_OK(status)) {
     5395                                        return status;
     5396                                }
    49335397
    49345398                                if (fsp && fsp->fh->fd != -1) {
    4935                                         file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp);
     5399                                        file_acl = SMB_VFS_SYS_ACL_GET_FD(fsp,
     5400                                                talloc_tos());
    49365401                                } else {
    49375402                                        file_acl =
    49385403                                            SMB_VFS_SYS_ACL_GET_FILE(conn,
    49395404                                                smb_fname->base_name,
    4940                                                 SMB_ACL_TYPE_ACCESS);
     5405                                                SMB_ACL_TYPE_ACCESS,
     5406                                                talloc_tos());
    49415407                                }
    49425408
     
    49555421                                                            conn,
    49565422                                                            fsp->fsp_name->base_name,
    4957                                                             SMB_ACL_TYPE_DEFAULT);
     5423                                                            SMB_ACL_TYPE_DEFAULT,
     5424                                                            talloc_tos());
    49585425                                        } else {
    49595426                                                def_acl =
     
    49615428                                                            conn,
    49625429                                                            smb_fname->base_name,
    4963                                                             SMB_ACL_TYPE_DEFAULT);
     5430                                                            SMB_ACL_TYPE_DEFAULT,
     5431                                                            talloc_tos());
    49645432                                        }
    49655433                                        def_acl = free_empty_sys_acl(conn, def_acl);
     
    49755443                                                        SMB_POSIX_ACL_HEADER_SIZE) ));
    49765444                                        if (file_acl) {
    4977                                                 SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
     5445                                                TALLOC_FREE(file_acl);
    49785446                                        }
    49795447                                        if (def_acl) {
    4980                                                 SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
     5448                                                TALLOC_FREE(def_acl);
    49815449                                        }
    49825450                                        return NT_STATUS_BUFFER_TOO_SMALL;
     
    49885456                                if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE, psbuf, file_acl)) {
    49895457                                        if (file_acl) {
    4990                                                 SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
     5458                                                TALLOC_FREE(file_acl);
    49915459                                        }
    49925460                                        if (def_acl) {
    4993                                                 SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
     5461                                                TALLOC_FREE(def_acl);
    49945462                                        }
    49955463                                        return NT_STATUS_INTERNAL_ERROR;
     
    49975465                                if (!marshall_posix_acl(conn, pdata + SMB_POSIX_ACL_HEADER_SIZE + (num_file_acls*SMB_POSIX_ACL_ENTRY_SIZE), psbuf, def_acl)) {
    49985466                                        if (file_acl) {
    4999                                                 SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
     5467                                                TALLOC_FREE(file_acl);
    50005468                                        }
    50015469                                        if (def_acl) {
    5002                                                 SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
     5470                                                TALLOC_FREE(def_acl);
    50035471                                        }
    50045472                                        return NT_STATUS_INTERNAL_ERROR;
     
    50065474
    50075475                                if (file_acl) {
    5008                                         SMB_VFS_SYS_ACL_FREE_ACL(conn, file_acl);
     5476                                        TALLOC_FREE(file_acl);
    50095477                                }
    50105478                                if (def_acl) {
    5011                                         SMB_VFS_SYS_ACL_FREE_ACL(conn, def_acl);
     5479                                        TALLOC_FREE(def_acl);
    50125480                                }
    50135481                                data_size = (num_file_acls + num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE + SMB_POSIX_ACL_HEADER_SIZE;
     
    50475515
    50485516                        smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET);
    5049 #if defined(HAVE_LONGLONG)
    5050                         offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
    5051                                         ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
    5052                         count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
    5053                                         ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
    5054 #else /* HAVE_LONGLONG */
    5055                         offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET);
    5056                         count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
    5057 #endif /* HAVE_LONGLONG */
     5517                        offset = BVAL(pdata,POSIX_LOCK_START_OFFSET);
     5518                        count = BVAL(pdata,POSIX_LOCK_LEN_OFFSET);
    50585519
    50595520                        status = query_lock(fsp,
     
    50715532                                SSVAL(pdata, POSIX_LOCK_FLAGS_OFFSET, 0);
    50725533                                SIVAL(pdata, POSIX_LOCK_PID_OFFSET, (uint32_t)smblctx);
    5073 #if defined(HAVE_LONGLONG)
    5074                                 SIVAL(pdata, POSIX_LOCK_START_OFFSET, (uint32)(offset & 0xFFFFFFFF));
    5075                                 SIVAL(pdata, POSIX_LOCK_START_OFFSET + 4, (uint32)((offset >> 32) & 0xFFFFFFFF));
    5076                                 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, (uint32)(count & 0xFFFFFFFF));
    5077                                 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET + 4, (uint32)((count >> 32) & 0xFFFFFFFF));
    5078 #else /* HAVE_LONGLONG */
    5079                                 SIVAL(pdata, POSIX_LOCK_START_OFFSET, offset);
    5080                                 SIVAL(pdata, POSIX_LOCK_LEN_OFFSET, count);
    5081 #endif /* HAVE_LONGLONG */
     5534                                SBVAL(pdata, POSIX_LOCK_START_OFFSET, offset);
     5535                                SBVAL(pdata, POSIX_LOCK_LEN_OFFSET, count);
    50825536
    50835537                        } else if (NT_STATUS_IS_OK(status)) {
     
    51155569        char *params = *pparams;
    51165570        char *pdata = *ppdata;
    5117         uint16 info_level;
     5571        uint16_t info_level;
    51185572        unsigned int data_size = 0;
    51195573        unsigned int param_size = 2;
     
    51655619                }
    51665620
    5167                 status = copy_smb_filename(talloc_tos(), fsp->fsp_name,
    5168                                            &smb_fname);
    5169                 if (!NT_STATUS_IS_OK(status)) {
    5170                         reply_nterror(req, status);
     5621                smb_fname = cp_smb_filename(talloc_tos(), fsp->fsp_name);
     5622                if (smb_fname == NULL) {
     5623                        reply_nterror(req, NT_STATUS_NO_MEMORY);
    51715624                        return;
    51725625                }
     
    52155668                         */
    52165669                        if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
    5217                                 DEBUG(3, ("fstat of fnum %d failed (%s)\n",
    5218                                           fsp->fnum, strerror(errno)));
     5670                                DEBUG(3, ("fstat of %s failed (%s)\n",
     5671                                          fsp_fnum_dbg(fsp), strerror(errno)));
    52195672                                reply_nterror(req,
    52205673                                        map_nt_error_from_unix(errno));
     
    52285681                uint32_t name_hash;
    52295682                char *fname = NULL;
    5230                 uint32_t ucf_flags = 0;
     5683                uint32_t ucf_flags = (req->posix_pathnames ?
     5684                                UCF_POSIX_PATHNAMES : 0);
    52315685
    52325686                /* qpathinfo */
     
    52525706                }
    52535707
    5254                 srvstr_get_path(req, params, req->flags2, &fname, &params[6],
     5708                if (req->posix_pathnames) {
     5709                        srvstr_get_path_posix(req,
     5710                                params,
     5711                                req->flags2,
     5712                                &fname,
     5713                                &params[6],
    52555714                                total_params - 6,
    5256                                 STR_TERMINATE, &status);
     5715                                STR_TERMINATE,
     5716                                &status);
     5717                } else {
     5718                        srvstr_get_path(req,
     5719                                params,
     5720                                req->flags2,
     5721                                &fname,
     5722                                &params[6],
     5723                                total_params - 6,
     5724                                STR_TERMINATE,
     5725                                &status);
     5726                }
    52575727                if (!NT_STATUS_IS_OK(status)) {
    52585728                        reply_nterror(req, status);
     
    52815751                if ((conn->fs_capabilities & FILE_NAMED_STREAMS)
    52825752                    && is_ntfs_stream_smb_fname(smb_fname)) {
    5283                         struct smb_filename *smb_fname_base = NULL;
     5753                        struct smb_filename *smb_fname_base;
    52845754
    52855755                        /* Create an smb_filename with stream_name == NULL. */
    5286                         status =
    5287                             create_synthetic_smb_fname(talloc_tos(),
    5288                                                        smb_fname->base_name,
    5289                                                        NULL, NULL,
    5290                                                        &smb_fname_base);
    5291                         if (!NT_STATUS_IS_OK(status)) {
    5292                                 reply_nterror(req, status);
     5756                        smb_fname_base = synthetic_smb_fname(
     5757                                talloc_tos(), smb_fname->base_name,
     5758                                NULL, NULL);
     5759                        if (smb_fname_base == NULL) {
     5760                                reply_nterror(req, NT_STATUS_NO_MEMORY);
    52935761                                return;
    52945762                        }
     
    53805848        }
    53815849
    5382         DEBUG(3,("call_trans2qfilepathinfo %s (fnum = %d) level=%d call=%d "
     5850        DEBUG(3,("call_trans2qfilepathinfo %s (%s) level=%d call=%d "
    53835851                 "total_data=%d\n", smb_fname_str_dbg(smb_fname),
    5384                  fsp ? fsp->fnum : -1, info_level,tran_call,total_data));
     5852                 fsp_fnum_dbg(fsp),
     5853                 info_level,tran_call,total_data));
    53855854
    53865855        /* Pull out any data sent here before we realloc. */
     
    53895858                {
    53905859                        /* Pull any EA list from the data portion. */
    5391                         uint32 ea_size;
     5860                        uint32_t ea_size;
    53925861
    53935862                        if (total_data < 4) {
     
    54355904
    54365905                        /* Copy the lock range data. */
    5437                         lock_data = (char *)TALLOC_MEMDUP(
     5906                        lock_data = (char *)talloc_memdup(
    54385907                                req, pdata, total_data);
    54395908                        if (!lock_data) {
     
    54995968        }
    55005969
    5501         send_trans2_replies(conn, req, params, param_size, *ppdata, data_size,
     5970        send_trans2_replies(conn, req, NT_STATUS_OK, params, param_size, *ppdata, data_size,
    55025971                            max_data_bytes);
    55035972
     
    55696038/****************************************************************************
    55706039 Deal with setting the time from any of the setfilepathinfo functions.
     6040 NOTE !!!! The check for FILE_WRITE_ATTRIBUTES access must be done *before*
     6041 calling this function.
    55716042****************************************************************************/
    55726043
     
    55786049{
    55796050        struct smb_filename smb_fname_base;
    5580         uint32 action =
     6051        uint32_t action =
    55816052                FILE_NOTIFY_CHANGE_LAST_ACCESS
    55826053                |FILE_NOTIFY_CHANGE_LAST_WRITE
     
    55856056        if (!VALID_STAT(smb_fname->st)) {
    55866057                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
    5587         }
    5588 
    5589         if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
    5590                 return NT_STATUS_ACCESS_DENIED;
    55916058        }
    55926059
     
    56716138/****************************************************************************
    56726139 Deal with setting the dosmode from any of the setfilepathinfo functions.
     6140 NB. The check for FILE_WRITE_ATTRIBUTES access on this path must have been
     6141 done before calling this function.
    56736142****************************************************************************/
    56746143
    56756144static NTSTATUS smb_set_file_dosmode(connection_struct *conn,
    56766145                                     const struct smb_filename *smb_fname,
    5677                                      uint32 dosmode)
     6146                                     uint32_t dosmode)
    56786147{
    5679         struct smb_filename *smb_fname_base = NULL;
     6148        struct smb_filename *smb_fname_base;
    56806149        NTSTATUS status;
    56816150
     
    56856154
    56866155        /* Always operate on the base_name, even if a stream was passed in. */
    5687         status = create_synthetic_smb_fname(talloc_tos(), smb_fname->base_name,
    5688                                             NULL, &smb_fname->st,
    5689                                             &smb_fname_base);
    5690         if (!NT_STATUS_IS_OK(status)) {
    5691                 return status;
     6156        smb_fname_base = synthetic_smb_fname(
     6157                talloc_tos(), smb_fname->base_name, NULL, &smb_fname->st);
     6158        if (smb_fname_base == NULL) {
     6159                return NT_STATUS_NO_MEMORY;
    56926160        }
    56936161
     
    57336201                                  const struct smb_filename *smb_fname,
    57346202                                  const SMB_STRUCT_STAT *psbuf,
    5735                                   SMB_OFF_T size,
     6203                                  off_t size,
    57366204                                  bool fail_after_createfile)
    57376205{
     
    57446212        }
    57456213
    5746         if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
    5747                 return NT_STATUS_ACCESS_DENIED;
    5748         }
    5749 
    57506214        DEBUG(6,("smb_set_file_size: size: %.0f ", (double)size));
    57516215
     
    57596223        if (fsp && fsp->fh->fd != -1) {
    57606224                /* Handle based call. */
     6225                if (!(fsp->access_mask & FILE_WRITE_DATA)) {
     6226                        return NT_STATUS_ACCESS_DENIED;
     6227                }
     6228
    57616229                if (vfs_set_filelen(fsp, size) == -1) {
    57626230                        return map_nt_error_from_unix(errno);
     
    57666234        }
    57676235
    5768         status = copy_smb_filename(talloc_tos(), smb_fname, &smb_fname_tmp);
    5769         if (!NT_STATUS_IS_OK(status)) {
    5770                 return status;
     6236        smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
     6237        if (smb_fname_tmp == NULL) {
     6238                return NT_STATUS_NO_MEMORY;
    57716239        }
    57726240
     
    57846252                0,                                      /* create_options */
    57856253                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
    5786                 FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
     6254                0,                                      /* oplock_request */
     6255                NULL,                                   /* lease */
    57876256                0,                                      /* allocation_size */
    57886257                0,                                      /* private_flags */
     
    57906259                NULL,                                   /* ea_list */
    57916260                &new_fsp,                               /* result */
    5792                 NULL);                                  /* pinfo */
     6261                NULL,                                   /* pinfo */
     6262                NULL, NULL);                            /* create context */
    57936263
    57946264        TALLOC_FREE(smb_fname_tmp);
     
    58556325        }
    58566326
    5857         if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
    5858                 return NT_STATUS_ACCESS_DENIED;
    5859         }
    5860 
    58616327        status = set_ea(conn, fsp, smb_fname, ea_list);
    58626328
     
    59006366        if (!ea_list) {
    59016367                return NT_STATUS_INVALID_PARAMETER;
    5902         }
    5903 
    5904         if (fsp && !(fsp->access_mask & FILE_WRITE_EA)) {
    5905                 return NT_STATUS_ACCESS_DENIED;
    59066368        }
    59076369
     
    59286390        NTSTATUS status = NT_STATUS_OK;
    59296391        bool delete_on_close;
    5930         uint32 dosmode = 0;
     6392        uint32_t dosmode = 0;
    59316393
    59326394        if (total_data < 1) {
     
    59576419        if (!set_delete_on_close(fsp, delete_on_close,
    59586420                                 conn->session_info->security_token,
    5959                                  &conn->session_info->utok)) {
     6421                                 conn->session_info->unix_token)) {
    59606422                return NT_STATUS_ACCESS_DENIED;
    59616423        }
     
    59846446
    59856447        position_information = (uint64_t)IVAL(pdata,0);
    5986 #ifdef LARGE_SMB_OFF_T
    59876448        position_information |= (((uint64_t)IVAL(pdata,4)) << 32);
    5988 #else /* LARGE_SMB_OFF_T */
    5989         if (IVAL(pdata,4) != 0) {
    5990                 /* more than 32 bits? */
    5991                 return NT_STATUS_INVALID_PARAMETER;
    5992         }
    5993 #endif /* LARGE_SMB_OFF_T */
    59946449
    59956450        DEBUG(10,("smb_file_position_information: Set file position "
     
    60086463                                int total_data)
    60096464{
    6010         uint32 mode;
     6465        uint32_t mode;
    60116466
    60126467        if (total_data < 4) {
     
    60416496        }
    60426497
    6043         if (!lp_symlinks(SNUM(conn))) {
     6498        if (!lp_follow_symlinks(SNUM(conn))) {
    60446499                return NT_STATUS_ACCESS_DENIED;
    60456500        }
     
    60736528        char *oldname = NULL;
    60746529        struct smb_filename *smb_fname_old = NULL;
     6530        uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
    60756531        TALLOC_CTX *ctx = talloc_tos();
    60766532        NTSTATUS status = NT_STATUS_OK;
     
    60816537        }
    60826538
    6083         srvstr_get_path(ctx, pdata, req->flags2, &oldname, pdata,
    6084                         total_data, STR_TERMINATE, &status);
     6539        if (req->posix_pathnames) {
     6540                srvstr_get_path_posix(ctx,
     6541                        pdata,
     6542                        req->flags2,
     6543                        &oldname,
     6544                        pdata,
     6545                        total_data,
     6546                        STR_TERMINATE,
     6547                        &status);
     6548        } else {
     6549                srvstr_get_path(ctx,
     6550                        pdata,
     6551                        req->flags2,
     6552                        &oldname,
     6553                        pdata,
     6554                        total_data,
     6555                        STR_TERMINATE,
     6556                        &status);
     6557        }
    60856558        if (!NT_STATUS_IS_OK(status)) {
    60866559                return status;
     
    60946567                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    60956568                                oldname,
    6096                                 0,
     6569                                ucf_flags,
    60976570                                NULL,
    60986571                                &smb_fname_old);
     
    61206593        char *newname = NULL;
    61216594        struct smb_filename *smb_fname_dst = NULL;
     6595        uint32_t ucf_flags = UCF_SAVE_LCOMP |
     6596                (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
    61226597        NTSTATUS status = NT_STATUS_OK;
    61236598        TALLOC_CTX *ctx = talloc_tos();
     
    61386613        }
    61396614
    6140         srvstr_get_path(ctx, pdata, req->flags2, &newname,
    6141                                 &pdata[20], len, STR_TERMINATE,
     6615        if (req->posix_pathnames) {
     6616                srvstr_get_path_posix(ctx,
     6617                                pdata,
     6618                                req->flags2,
     6619                                &newname,
     6620                                &pdata[20],
     6621                                len,
     6622                                STR_TERMINATE,
    61426623                                &status);
     6624        } else {
     6625                srvstr_get_path(ctx,
     6626                                pdata,
     6627                                req->flags2,
     6628                                &newname,
     6629                                &pdata[20],
     6630                                len,
     6631                                STR_TERMINATE,
     6632                                &status);
     6633        }
    61436634        if (!NT_STATUS_IS_OK(status)) {
    61446635                return status;
     
    61526643                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    61536644                                newname,
    6154                                 UCF_SAVE_LCOMP,
     6645                                ucf_flags,
    61556646                                NULL,
    61566647                                &smb_fname_dst);
     
    61666657
    61676658                /* Create an smb_fname to call rename_internals_fsp() with. */
    6168                 status = create_synthetic_smb_fname(talloc_tos(),
    6169                     fsp->base_fsp->fsp_name->base_name, newname, NULL,
    6170                     &smb_fname_dst);
    6171                 if (!NT_STATUS_IS_OK(status)) {
     6659                smb_fname_dst = synthetic_smb_fname(
     6660                        talloc_tos(), fsp->base_fsp->fsp_name->base_name,
     6661                        newname, NULL);
     6662                if (smb_fname_dst == NULL) {
     6663                        status = NT_STATUS_NO_MEMORY;
    61726664                        goto out;
    61736665                }
     
    61876679
    61886680        DEBUG(10,("smb2_file_rename_information: "
    6189                   "SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
    6190                   fsp->fnum, fsp_str_dbg(fsp),
     6681                  "SMB_FILE_RENAME_INFORMATION (%s) %s -> %s\n",
     6682                  fsp_fnum_dbg(fsp), fsp_str_dbg(fsp),
    61916683                  smb_fname_str_dbg(smb_fname_dst)));
    61926684        status = rename_internals_fsp(conn, fsp, smb_fname_dst,
     
    62116703        struct smb_filename *smb_fname_dst = NULL;
    62126704        NTSTATUS status = NT_STATUS_OK;
     6705        uint32_t ucf_flags = UCF_SAVE_LCOMP |
     6706                (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
    62136707        TALLOC_CTX *ctx = talloc_tos();
    62146708
     
    62286722        }
    62296723
    6230         srvstr_get_path(ctx, pdata, req->flags2, &newname,
    6231                                 &pdata[20], len, STR_TERMINATE,
     6724        if (req->posix_pathnames) {
     6725                srvstr_get_path_posix(ctx,
     6726                                pdata,
     6727                                req->flags2,
     6728                                &newname,
     6729                                &pdata[20],
     6730                                len,
     6731                                STR_TERMINATE,
    62326732                                &status);
     6733        } else {
     6734                srvstr_get_path(ctx,
     6735                                pdata,
     6736                                req->flags2,
     6737                                &newname,
     6738                                &pdata[20],
     6739                                len,
     6740                                STR_TERMINATE,
     6741                                &status);
     6742        }
    62336743        if (!NT_STATUS_IS_OK(status)) {
    62346744                return status;
     
    62426752                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    62436753                                newname,
    6244                                 UCF_SAVE_LCOMP,
     6754                                ucf_flags,
    62456755                                NULL,
    62466756                                &smb_fname_dst);
     
    62556765
    62566766        DEBUG(10,("smb_file_link_information: "
    6257                   "SMB_FILE_LINK_INFORMATION (fnum %d) %s -> %s\n",
    6258                   fsp->fnum, fsp_str_dbg(fsp),
     6767                  "SMB_FILE_LINK_INFORMATION (%s) %s -> %s\n",
     6768                  fsp_fnum_dbg(fsp), fsp_str_dbg(fsp),
    62596769                  smb_fname_str_dbg(smb_fname_dst)));
    62606770        status = hardlink_internals(ctx,
     
    62816791{
    62826792        bool overwrite;
    6283         uint32 root_fid;
    6284         uint32 len;
     6793        uint32_t root_fid;
     6794        uint32_t len;
    62856795        char *newname = NULL;
    62866796        struct smb_filename *smb_fname_dst = NULL;
     
    63026812        }
    63036813
    6304         srvstr_get_path_wcard(ctx, pdata, req->flags2, &newname, &pdata[12],
    6305                               len, 0, &status,
    6306                               &dest_has_wcard);
     6814        if (req->posix_pathnames) {
     6815                srvstr_get_path_wcard_posix(ctx,
     6816                                pdata,
     6817                                req->flags2,
     6818                                &newname,
     6819                                &pdata[12],
     6820                                len,
     6821                                0,
     6822                                &status,
     6823                                &dest_has_wcard);
     6824        } else {
     6825                srvstr_get_path_wcard(ctx,
     6826                                pdata,
     6827                                req->flags2,
     6828                                &newname,
     6829                                &pdata[12],
     6830                                len,
     6831                                0,
     6832                                &status,
     6833                                &dest_has_wcard);
     6834        }
    63076835        if (!NT_STATUS_IS_OK(status)) {
    63086836                return status;
     
    63166844                                       newname,
    63176845                                       true,
     6846                                       !conn->sconn->using_smb2,
    63186847                                       &newname,
    63196848                                       &dest_has_wcard);
     
    63346863
    63356864                /* Create an smb_fname to call rename_internals_fsp() with. */
    6336                 status = create_synthetic_smb_fname(talloc_tos(),
    6337                     fsp->base_fsp->fsp_name->base_name, newname, NULL,
    6338                     &smb_fname_dst);
    6339                 if (!NT_STATUS_IS_OK(status)) {
     6865                smb_fname_dst = synthetic_smb_fname(
     6866                        talloc_tos(), fsp->base_fsp->fsp_name->base_name,
     6867                        newname, NULL);
     6868                if (smb_fname_dst == NULL) {
     6869                        status = NT_STATUS_NO_MEMORY;
    63406870                        goto out;
    63416871                }
     
    64056935                        }
    64066936                        /* Create an smb_fname to call rename_internals_fsp() */
    6407                         status = create_synthetic_smb_fname(ctx,
    6408                                                             base_name, NULL,
    6409                                                             NULL,
    6410                                                             &smb_fname_dst);
    6411                         if (!NT_STATUS_IS_OK(status)) {
     6937                        smb_fname_dst = synthetic_smb_fname(
     6938                                ctx, base_name, NULL, NULL);
     6939                        if (smb_fname_dst == NULL) {
     6940                                status = NT_STATUS_NO_MEMORY;
    64126941                                goto out;
    64136942                        }
     
    64176946        if (fsp) {
    64186947                DEBUG(10,("smb_file_rename_information: "
    6419                           "SMB_FILE_RENAME_INFORMATION (fnum %d) %s -> %s\n",
    6420                           fsp->fnum, fsp_str_dbg(fsp),
     6948                          "SMB_FILE_RENAME_INFORMATION (%s) %s -> %s\n",
     6949                          fsp_fnum_dbg(fsp), fsp_str_dbg(fsp),
    64216950                          smb_fname_str_dbg(smb_fname_dst)));
    64226951                status = rename_internals_fsp(conn, fsp, smb_fname_dst, 0,
     
    64486977                                const struct smb_filename *smb_fname)
    64496978{
    6450         uint16 posix_acl_version;
    6451         uint16 num_file_acls;
    6452         uint16 num_def_acls;
     6979        uint16_t posix_acl_version;
     6980        uint16_t num_file_acls;
     6981        uint16_t num_def_acls;
    64536982        bool valid_file_acls = True;
    64546983        bool valid_def_acls = True;
     6984        NTSTATUS status;
    64556985
    64566986        if (total_data < SMB_POSIX_ACL_HEADER_SIZE) {
     
    64787008                        (num_file_acls+num_def_acls)*SMB_POSIX_ACL_ENTRY_SIZE) {
    64797009                return NT_STATUS_INVALID_PARAMETER;
     7010        }
     7011
     7012        status = refuse_symlink(conn, fsp, smb_fname->base_name);
     7013        if (!NT_STATUS_IS_OK(status)) {
     7014                return status;
    64807015        }
    64817016
     
    65587093
    65597094        smblctx = (uint64_t)IVAL(pdata, POSIX_LOCK_PID_OFFSET);
    6560 #if defined(HAVE_LONGLONG)
    65617095        offset = (((uint64_t) IVAL(pdata,(POSIX_LOCK_START_OFFSET+4))) << 32) |
    65627096                        ((uint64_t) IVAL(pdata,POSIX_LOCK_START_OFFSET));
    65637097        count = (((uint64_t) IVAL(pdata,(POSIX_LOCK_LEN_OFFSET+4))) << 32) |
    65647098                        ((uint64_t) IVAL(pdata,POSIX_LOCK_LEN_OFFSET));
    6565 #else /* HAVE_LONGLONG */
    6566         offset = (uint64_t)IVAL(pdata,POSIX_LOCK_START_OFFSET);
    6567         count = (uint64_t)IVAL(pdata,POSIX_LOCK_LEN_OFFSET);
    6568 #endif /* HAVE_LONGLONG */
    65697099
    65707100        DEBUG(10,("smb_set_posix_lock: file %s, lock_type = %u,"
     
    65957125                                                        blocking_lock,
    65967126                                                        &status,
    6597                                                         &block_smblctx,
    6598                                                         NULL);
     7127                                                        &block_smblctx);
    65997128
    66007129                if (br_lck && blocking_lock && ERROR_WAS_LOCK_DENIED(status)) {
     
    66377166        /* Patch to do this correctly from Paul Eggert <eggert@twinsun.com>. */
    66387167        struct smb_file_time ft;
    6639         uint32 dosmode = 0;
     7168        uint32_t dosmode = 0;
    66407169        NTSTATUS status = NT_STATUS_OK;
    66417170
     
    66467175        }
    66477176
    6648         if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
    6649                 return NT_STATUS_ACCESS_DENIED;
     7177        status = check_access(conn, fsp, smb_fname, FILE_WRITE_ATTRIBUTES);
     7178        if (!NT_STATUS_IS_OK(status)) {
     7179                return status;
    66507180        }
    66517181
     
    66867216                                        const struct smb_filename *smb_fname)
    66877217{
     7218        NTSTATUS status;
    66887219        struct smb_file_time ft;
    66897220
     
    66927223        if (total_data < 12) {
    66937224                return NT_STATUS_INVALID_PARAMETER;
    6694         }
    6695 
    6696         if (fsp && !(fsp->access_mask & FILE_WRITE_ATTRIBUTES)) {
    6697                 return NT_STATUS_ACCESS_DENIED;
    66987225        }
    66997226
     
    67077234        DEBUG(10,("smb_set_info_standard: file %s\n",
    67087235                smb_fname_str_dbg(smb_fname)));
     7236
     7237        status = check_access(conn, fsp, smb_fname, FILE_WRITE_ATTRIBUTES);
     7238        if (!NT_STATUS_IS_OK(status)) {
     7239                return status;
     7240        }
    67097241
    67107242        return smb_set_file_time(conn,
     
    67397271
    67407272        allocation_size = (uint64_t)IVAL(pdata,0);
    6741 #ifdef LARGE_SMB_OFF_T
    67427273        allocation_size |= (((uint64_t)IVAL(pdata,4)) << 32);
    6743 #else /* LARGE_SMB_OFF_T */
    6744         if (IVAL(pdata,4) != 0) {
    6745                 /* more than 32 bits? */
    6746                 return NT_STATUS_INVALID_PARAMETER;
    6747         }
    6748 #endif /* LARGE_SMB_OFF_T */
    6749 
    67507274        DEBUG(10,("smb_set_file_allocation_info: Set file allocation info for "
    67517275                  "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
     
    67567280        }
    67577281
    6758         if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
    6759                 return NT_STATUS_ACCESS_DENIED;
    6760         }
    6761 
    67627282        DEBUG(10,("smb_set_file_allocation_info: file %s : setting new "
    67637283                  "allocation size to %.0f\n", smb_fname_str_dbg(smb_fname),
     
    67667286        if (fsp && fsp->fh->fd != -1) {
    67677287                /* Open file handle. */
     7288                if (!(fsp->access_mask & FILE_WRITE_DATA)) {
     7289                        return NT_STATUS_ACCESS_DENIED;
     7290                }
     7291
    67687292                /* Only change if needed. */
    67697293                if (allocation_size != get_file_size_stat(&smb_fname->st)) {
     
    67937317                0,                                      /* create_options */
    67947318                FILE_ATTRIBUTE_NORMAL,                  /* file_attributes */
    6795                 FORCE_OPLOCK_BREAK_TO_NONE,             /* oplock_request */
     7319                0,                                      /* oplock_request */
     7320                NULL,                                   /* lease */
    67967321                0,                                      /* allocation_size */
    67977322                0,                                      /* private_flags */
     
    67997324                NULL,                                   /* ea_list */
    68007325                &new_fsp,                               /* result */
    6801                 NULL);                                  /* pinfo */
     7326                NULL,                                   /* pinfo */
     7327                NULL, NULL);                            /* create context */
    68027328
    68037329        if (!NT_STATUS_IS_OK(status)) {
     
    68217347         */
    68227348        trigger_write_time_update_immediate(new_fsp);
    6823 
    68247349        close_file(req, new_fsp, NORMAL_CLOSE);
    68257350        return NT_STATUS_OK;
     
    68387363                                        bool fail_after_createfile)
    68397364{
    6840         SMB_OFF_T size;
     7365        off_t size;
    68417366
    68427367        if (total_data < 8) {
     
    68457370
    68467371        size = IVAL(pdata,0);
    6847 #ifdef LARGE_SMB_OFF_T
    6848         size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
    6849 #else /* LARGE_SMB_OFF_T */
    6850         if (IVAL(pdata,4) != 0) {
    6851                 /* more than 32 bits? */
    6852                 return NT_STATUS_INVALID_PARAMETER;
    6853         }
    6854 #endif /* LARGE_SMB_OFF_T */
     7372        size |= (((off_t)IVAL(pdata,4)) << 32);
    68557373        DEBUG(10,("smb_set_file_end_of_file_info: Set end of file info for "
    68567374                  "file %s to %.0f\n", smb_fname_str_dbg(smb_fname),
    68577375                  (double)size));
    6858 
    6859         if (fsp && !(fsp->access_mask & FILE_WRITE_DATA)) {
    6860                 return NT_STATUS_ACCESS_DENIED;
    6861         }
    68627376
    68637377        return smb_set_file_size(conn, req,
     
    68787392                                        const struct smb_filename *smb_fname)
    68797393{
    6880         uint32 file_type = IVAL(pdata,56);
     7394        uint32_t file_type = IVAL(pdata,56);
    68817395#if defined(HAVE_MAKEDEV)
    6882         uint32 dev_major = IVAL(pdata,60);
    6883         uint32 dev_minor = IVAL(pdata,68);
     7396        uint32_t dev_major = IVAL(pdata,60);
     7397        uint32_t dev_minor = IVAL(pdata,68);
    68847398#endif
    68857399        SMB_DEV_T dev = (SMB_DEV_T)0;
    6886         uint32 raw_unixmode = IVAL(pdata,84);
     7400        uint32_t raw_unixmode = IVAL(pdata,84);
    68877401        NTSTATUS status;
    68887402        mode_t unixmode;
     
    69407454         */
    69417455
    6942         if (lp_inherit_perms(SNUM(conn))) {
     7456        if (lp_inherit_permissions(SNUM(conn))) {
    69437457                char *parent;
    69447458                if (!parent_dirname(talloc_tos(), smb_fname->base_name,
     
    69667480{
    69677481        struct smb_file_time ft;
    6968         uint32 raw_unixmode;
     7482        uint32_t raw_unixmode;
    69697483        mode_t unixmode;
    6970         SMB_OFF_T size = 0;
     7484        off_t size = 0;
    69717485        uid_t set_owner = (uid_t)SMB_UID_NO_CHANGE;
    69727486        gid_t set_grp = (uid_t)SMB_GID_NO_CHANGE;
     
    69897503           IVAL(pdata, 4) != SMB_SIZE_NO_CHANGE_HI) {
    69907504                size=IVAL(pdata,0); /* first 8 Bytes are size */
    6991 #ifdef LARGE_SMB_OFF_T
    6992                 size |= (((SMB_OFF_T)IVAL(pdata,4)) << 32);
    6993 #else /* LARGE_SMB_OFF_T */
    6994                 if (IVAL(pdata,4) != 0) {
    6995                         /* more than 32 bits? */
    6996                         return NT_STATUS_INVALID_PARAMETER;
    6997                 }
    6998 #endif /* LARGE_SMB_OFF_T */
     7505                size |= (((off_t)IVAL(pdata,4)) << 32);
    69997506        }
    70007507
     
    70447551                }
    70457552
    7046                 status = copy_smb_filename(talloc_tos(), smb_fname,
    7047                                            &smb_fname_tmp);
    7048                 if (!NT_STATUS_IS_OK(status)) {
    7049                         return status;
     7553                smb_fname_tmp = cp_smb_filename(talloc_tos(), smb_fname);
     7554                if (smb_fname_tmp == NULL) {
     7555                        return NT_STATUS_NO_MEMORY;
    70507556                }
    70517557
     
    70877593
    70887594        if (raw_unixmode != SMB_MODE_NO_CHANGE) {
     7595                int ret;
     7596
    70897597                DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
    70907598                          "setting mode 0%o for file %s\n",
    70917599                          (unsigned int)unixmode,
    70927600                          smb_fname_str_dbg(smb_fname)));
    7093                 if (SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode) != 0) {
     7601                if (fsp && fsp->fh->fd != -1) {
     7602                        ret = SMB_VFS_FCHMOD(fsp, unixmode);
     7603                } else {
     7604                        ret = SMB_VFS_CHMOD(conn, smb_fname->base_name, unixmode);
     7605                }
     7606                if (ret != 0) {
    70947607                        return map_nt_error_from_unix(errno);
    70957608                }
     
    71097622                          smb_fname_str_dbg(smb_fname)));
    71107623
    7111                 if (S_ISLNK(sbuf.st_ex_mode)) {
     7624                if (fsp && fsp->fh->fd != -1) {
     7625                        ret = SMB_VFS_FCHOWN(fsp, set_owner, (gid_t)-1);
     7626                } else {
     7627                        /*
     7628                         * UNIX extensions calls must always operate
     7629                         * on symlinks.
     7630                         */
    71127631                        ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name,
    71137632                                             set_owner, (gid_t)-1);
    7114                 } else {
    7115                         ret = SMB_VFS_CHOWN(conn, smb_fname->base_name,
    7116                                             set_owner, (gid_t)-1);
    71177633                }
    71187634
     
    71327648        if ((set_grp != (uid_t)SMB_GID_NO_CHANGE) &&
    71337649            (sbuf.st_ex_gid != set_grp)) {
     7650                int ret;
     7651
    71347652                DEBUG(10,("smb_set_file_unix_basic: SMB_SET_FILE_UNIX_BASIC "
    71357653                          "changing group %u for file %s\n",
    71367654                          (unsigned int)set_owner,
    71377655                          smb_fname_str_dbg(smb_fname)));
    7138                 if (SMB_VFS_CHOWN(conn, smb_fname->base_name, (uid_t)-1,
    7139                                   set_grp) != 0) {
     7656                if (fsp && fsp->fh->fd != -1) {
     7657                        ret = SMB_VFS_FCHOWN(fsp, set_owner, (gid_t)-1);
     7658                } else {
     7659                        /*
     7660                         * UNIX extensions calls must always operate
     7661                         * on symlinks.
     7662                         */
     7663                        ret = SMB_VFS_LCHOWN(conn, smb_fname->base_name, (uid_t)-1,
     7664                                  set_grp);
     7665                }
     7666                if (ret != 0) {
    71407667                        status = map_nt_error_from_unix(errno);
    71417668                        if (delete_on_fail) {
     
    72097736{
    72107737        NTSTATUS status;
    7211         uint32 smb_fflags;
    7212         uint32 smb_fmask;
     7738        uint32_t smb_fflags;
     7739        uint32_t smb_fmask;
    72137740
    72147741        if (total_data < 116) {
     
    72717798{
    72727799        NTSTATUS status = NT_STATUS_OK;
    7273         uint32 raw_unixmode = 0;
    7274         uint32 mod_unixmode = 0;
     7800        uint32_t raw_unixmode = 0;
     7801        uint32_t mod_unixmode = 0;
    72757802        mode_t unixmode = (mode_t)0;
    72767803        files_struct *fsp = NULL;
    7277         uint16 info_level_return = 0;
     7804        uint16_t info_level_return = 0;
    72787805        int info;
    72797806        char *pdata = *ppdata;
     
    72927819        }
    72937820
    7294         mod_unixmode = (uint32)unixmode | FILE_FLAG_POSIX_SEMANTICS;
     7821        mod_unixmode = (uint32_t)unixmode | FILE_FLAG_POSIX_SEMANTICS;
    72957822
    72967823        DEBUG(10,("smb_posix_mkdir: file %s, mode 0%o\n",
     
    73087835                mod_unixmode,                           /* file_attributes */
    73097836                0,                                      /* oplock_request */
     7837                NULL,                                   /* lease */
    73107838                0,                                      /* allocation_size */
    73117839                0,                                      /* private_flags */
     
    73137841                NULL,                                   /* ea_list */
    73147842                &fsp,                                   /* result */
    7315                 &info);                                 /* pinfo */
     7843                &info,                                  /* pinfo */
     7844                NULL, NULL);                            /* create context */
    73167845
    73177846        if (NT_STATUS_IS_OK(status)) {
     
    73797908        bool extended_oplock_granted = False;
    73807909        char *pdata = *ppdata;
    7381         uint32 flags = 0;
    7382         uint32 wire_open_mode = 0;
    7383         uint32 raw_unixmode = 0;
    7384         uint32 mod_unixmode = 0;
    7385         uint32 create_disp = 0;
    7386         uint32 access_mask = 0;
    7387         uint32 create_options = FILE_NON_DIRECTORY_FILE;
     7910        uint32_t flags = 0;
     7911        uint32_t wire_open_mode = 0;
     7912        uint32_t raw_unixmode = 0;
     7913        uint32_t mod_unixmode = 0;
     7914        uint32_t create_disp = 0;
     7915        uint32_t access_mask = 0;
     7916        uint32_t create_options = FILE_NON_DIRECTORY_FILE;
    73887917        NTSTATUS status = NT_STATUS_OK;
    73897918        mode_t unixmode = (mode_t)0;
     
    73917920        int oplock_request = 0;
    73927921        int info = 0;
    7393         uint16 info_level_return = 0;
     7922        uint16_t info_level_return = 0;
    73947923
    73957924        if (total_data < 18) {
     
    75028031        }
    75038032
    7504         mod_unixmode = (uint32)unixmode | FILE_FLAG_POSIX_SEMANTICS;
     8033        mod_unixmode = (uint32_t)unixmode | FILE_FLAG_POSIX_SEMANTICS;
    75058034
    75068035        if (wire_open_mode & SMB_O_SYNC) {
     
    75408069                mod_unixmode,                           /* file_attributes */
    75418070                oplock_request,                         /* oplock_request */
     8071                NULL,                                   /* lease */
    75428072                0,                                      /* allocation_size */
    75438073                0,                                      /* private_flags */
     
    75458075                NULL,                                   /* ea_list */
    75468076                &fsp,                                   /* result */
    7547                 &info);                                 /* pinfo */
     8077                &info,                                  /* pinfo */
     8078                NULL, NULL);                            /* create context */
    75488079
    75498080        if (!NT_STATUS_IS_OK(status)) {
     
    76288159        NTSTATUS status = NT_STATUS_OK;
    76298160        files_struct *fsp = NULL;
    7630         uint16 flags = 0;
     8161        uint16_t flags = 0;
    76318162        char del = 1;
    76328163        int info = 0;
     
    76708201                FILE_FLAG_POSIX_SEMANTICS|0777,         /* file_attributes */
    76718202                0,                                      /* oplock_request */
     8203                NULL,                                   /* lease */
    76728204                0,                                      /* allocation_size */
    76738205                0,                                      /* private_flags */
     
    76758207                NULL,                                   /* ea_list */
    76768208                &fsp,                                   /* result */
    7677                 &info);                                 /* pinfo */
     8209                &info,                                  /* pinfo */
     8210                NULL, NULL);                            /* create context */
    76788211
    76798212        if (!NT_STATUS_IS_OK(status)) {
     
    76868219         */
    76878220
    7688         lck = get_share_mode_lock(talloc_tos(), fsp->file_id, NULL, NULL,
    7689                                   NULL);
     8221        lck = get_existing_share_mode_lock(talloc_tos(), fsp->file_id);
    76908222        if (lck == NULL) {
    76918223                DEBUG(0, ("smb_posix_unlink: Could not get share mode "
     
    77008232         * on close disposition.
    77018233         */
    7702         for (i=0; i<lck->num_share_modes; i++) {
    7703                 struct share_mode_entry *e = &lck->share_modes[i];
     8234        for (i=0; i<lck->data->num_share_modes; i++) {
     8235                struct share_mode_entry *e = &lck->data->share_modes[i];
    77048236                if (is_valid_share_mode_entry(e)) {
    77058237                        if (e->flags & SHARE_MODE_FLAG_POSIX_OPEN) {
     8238                                continue;
     8239                        }
     8240                        if (share_mode_stale_pid(lck->data, i)) {
    77068241                                continue;
    77078242                        }
     
    77588293        }
    77598294
    7760         DEBUG(3,("smbd_do_setfilepathinfo: %s (fnum %d) info_level=%d "
     8295        DEBUG(3,("smbd_do_setfilepathinfo: %s (%s) info_level=%d "
    77618296                 "totdata=%d\n", smb_fname_str_dbg(smb_fname),
    7762                  fsp ? fsp->fnum : -1, info_level, total_data));
     8297                 fsp_fnum_dbg(fsp),
     8298                 info_level, total_data));
    77638299
    77648300        switch (info_level) {
     
    80288564        char *params = *pparams;
    80298565        char *pdata = *ppdata;
    8030         uint16 info_level;
     8566        uint16_t info_level;
    80318567        struct smb_filename *smb_fname = NULL;
    80328568        files_struct *fsp = NULL;
     
    80528588                info_level = SVAL(params,2);
    80538589
    8054                 status = copy_smb_filename(talloc_tos(), fsp->fsp_name,
    8055                                            &smb_fname);
    8056                 if (!NT_STATUS_IS_OK(status)) {
    8057                         reply_nterror(req, status);
     8590                smb_fname = cp_smb_filename(talloc_tos(), fsp->fsp_name);
     8591                if (smb_fname == NULL) {
     8592                        reply_nterror(req, NT_STATUS_NO_MEMORY);
    80588593                        return;
    80598594                }
     
    80988633
    80998634                                SSVAL(params,0,0);
    8100                                 send_trans2_replies(conn, req, params, 2,
     8635                                send_trans2_replies(conn, req, NT_STATUS_OK, params, 2,
    81018636                                                    *ppdata, 0,
    81028637                                                    max_data_bytes);
     
    81138648                        if (SMB_VFS_FSTAT(fsp, &smb_fname->st) != 0) {
    81148649                                DEBUG(3,("call_trans2setfilepathinfo: fstat "
    8115                                          "of fnum %d failed (%s)\n", fsp->fnum,
     8650                                         "of %s failed (%s)\n", fsp_fnum_dbg(fsp),
    81168651                                         strerror(errno)));
    81178652                                reply_nterror(req, map_nt_error_from_unix(errno));
     
    81218656        } else {
    81228657                char *fname = NULL;
    8123                 uint32_t ucf_flags = 0;
     8658                uint32_t ucf_flags = (req->posix_pathnames ?
     8659                        UCF_POSIX_PATHNAMES : 0);
    81248660
    81258661                /* set path info */
     
    81308666
    81318667                info_level = SVAL(params,0);
    8132                 srvstr_get_path(req, params, req->flags2, &fname, &params[6],
    8133                                 total_params - 6, STR_TERMINATE,
     8668                if (req->posix_pathnames) {
     8669                        srvstr_get_path_posix(req,
     8670                                params,
     8671                                req->flags2,
     8672                                &fname,
     8673                                &params[6],
     8674                                total_params - 6,
     8675                                STR_TERMINATE,
    81348676                                &status);
     8677                } else {
     8678                        srvstr_get_path(req,
     8679                                params,
     8680                                req->flags2,
     8681                                &fname,
     8682                                &params[6],
     8683                                total_params - 6,
     8684                                STR_TERMINATE,
     8685                                &status);
     8686                }
    81358687                if (!NT_STATUS_IS_OK(status)) {
    81368688                        reply_nterror(req, status);
     
    81818733        }
    81828734
    8183         DEBUG(3,("call_trans2setfilepathinfo(%d) %s (fnum %d) info_level=%d "
     8735        DEBUG(3,("call_trans2setfilepathinfo(%d) %s (%s) info_level=%d "
    81848736                 "totdata=%d\n", tran_call, smb_fname_str_dbg(smb_fname),
    8185                  fsp ? fsp->fnum : -1, info_level,total_data));
     8737                 fsp_fnum_dbg(fsp),
     8738                 info_level,total_data));
    81868739
    81878740        /* Realloc the parameter size */
     
    82028755                                         &data_return_size);
    82038756        if (!NT_STATUS_IS_OK(status)) {
    8204                 if (open_was_deferred(req->mid)) {
     8757                if (open_was_deferred(req->xconn, req->mid)) {
    82058758                        /* We have re-scheduled this call. */
    82068759                        return;
     
    82208773                }
    82218774
    8222                 reply_nterror(req, status);
     8775                /*
     8776                 * Invalid EA name needs to return 2 param bytes,
     8777                 * not a zero-length error packet.
     8778                 */
     8779                if (NT_STATUS_EQUAL(status, STATUS_INVALID_EA_NAME)) {
     8780                        send_trans2_replies(conn, req, status, params, 2, NULL, 0,
     8781                                        max_data_bytes);
     8782                } else {
     8783                        reply_nterror(req, status);
     8784                }
    82238785                return;
    82248786        }
    82258787
    8226         send_trans2_replies(conn, req, params, 2, *ppdata, data_return_size,
     8788        send_trans2_replies(conn, req, NT_STATUS_OK, params, 2, *ppdata, data_return_size,
    82278789                            max_data_bytes);
    82288790
     
    82458807        NTSTATUS status = NT_STATUS_OK;
    82468808        struct ea_list *ea_list = NULL;
     8809        uint32_t ucf_flags = (req->posix_pathnames ? UCF_POSIX_PATHNAMES : 0);
    82478810        TALLOC_CTX *ctx = talloc_tos();
    82488811
     
    82578820        }
    82588821
    8259         srvstr_get_path(ctx, params, req->flags2, &directory, &params[4],
    8260                         total_params - 4, STR_TERMINATE,
     8822        if (req->posix_pathnames) {
     8823                srvstr_get_path_posix(ctx,
     8824                        params,
     8825                        req->flags2,
     8826                        &directory,
     8827                        &params[4],
     8828                        total_params - 4,
     8829                        STR_TERMINATE,
    82618830                        &status);
     8831        } else {
     8832                srvstr_get_path(ctx,
     8833                        params,
     8834                        req->flags2,
     8835                        &directory,
     8836                        &params[4],
     8837                        total_params - 4,
     8838                        STR_TERMINATE,
     8839                        &status);
     8840        }
    82628841        if (!NT_STATUS_IS_OK(status)) {
    82638842                reply_nterror(req, status);
     
    82718850                                req->flags2 & FLAGS2_DFS_PATHNAMES,
    82728851                                directory,
    8273                                 0,
     8852                                ucf_flags,
    82748853                                NULL,
    82758854                                &smb_dname);
     
    83498928        SSVAL(params,0,0);
    83508929
    8351         send_trans2_replies(conn, req, params, 2, *ppdata, 0, max_data_bytes);
     8930        send_trans2_replies(conn, req, NT_STATUS_OK, params, 2, *ppdata, 0, max_data_bytes);
    83528931
    83538932 out:
     
    83688947{
    83698948        char *params = *pparams;
    8370         uint16 info_level;
     8949        uint16_t info_level;
    83718950
    83728951        if (total_params < 6) {
     
    84048983                fnf_handle = 257;
    84058984
    8406         send_trans2_replies(conn, req, params, 6, *ppdata, 0, max_data_bytes);
     8985        send_trans2_replies(conn, req, NT_STATUS_OK, params, 6, *ppdata, 0, max_data_bytes);
    84078986
    84088987        return;
     
    84359014        SSVAL(params,2,0); /* No EA errors */
    84369015
    8437         send_trans2_replies(conn, req, params, 4, *ppdata, 0, max_data_bytes);
     9016        send_trans2_replies(conn, req, NT_STATUS_OK, params, 4, *ppdata, 0, max_data_bytes);
    84389017
    84399018        return;
     
    84839062        }
    84849063
    8485         SSVAL(req->inbuf, smb_flg2,
     9064        SSVAL((discard_const_p(uint8_t, req->inbuf)), smb_flg2,
    84869065              SVAL(req->inbuf,smb_flg2) | FLAGS2_DFS_PATHNAMES);
    8487         send_trans2_replies(conn, req,0,0,*ppdata,reply_size, max_data_bytes);
     9066        send_trans2_replies(conn, req, NT_STATUS_OK, 0,0,*ppdata,reply_size, max_data_bytes);
    84889067
    84899068        return;
     
    85059084        char *pdata = *ppdata;
    85069085        files_struct *fsp = file_fsp(req, SVAL(req->vwv+15, 0));
     9086        NTSTATUS status;
     9087        size_t len = 0;
    85079088
    85089089        /* check for an invalid fid before proceeding */
     
    85269107
    85279108                /* Job number */
    8528                 if (fsp->print_file) {
    8529                         SSVAL(pdata, 0, fsp->print_file->rap_jobid);
    8530                 } else {
    8531                         SSVAL(pdata, 0, 0);
    8532                 }
    8533                 srvstr_push(pdata, req->flags2, pdata + 2,
    8534                             global_myname(), 15,
    8535                             STR_ASCII|STR_TERMINATE); /* Our NetBIOS name */
    8536                 srvstr_push(pdata, req->flags2, pdata+18,
    8537                             lp_servicename(SNUM(conn)), 13,
    8538                             STR_ASCII|STR_TERMINATE); /* Service name */
    8539                 send_trans2_replies(conn, req, *pparams, 0, *ppdata, 32,
     9109                SSVAL(pdata, 0, print_spool_rap_jobid(fsp->print_file));
     9110
     9111                status = srvstr_push(pdata, req->flags2, pdata + 2,
     9112                            lp_netbios_name(), 15,
     9113                            STR_ASCII|STR_TERMINATE, &len); /* Our NetBIOS name */
     9114                if (!NT_STATUS_IS_OK(status)) {
     9115                        reply_nterror(req, status);
     9116                        return;
     9117                }
     9118                status = srvstr_push(pdata, req->flags2, pdata+18,
     9119                            lp_servicename(talloc_tos(), SNUM(conn)), 13,
     9120                            STR_ASCII|STR_TERMINATE, &len); /* Service name */
     9121                if (!NT_STATUS_IS_OK(status)) {
     9122                        reply_nterror(req, status);
     9123                        return;
     9124                }
     9125                send_trans2_replies(conn, req, NT_STATUS_OK, *pparams, 0, *ppdata, 32,
    85409126                                    max_data_bytes);
    85419127                return;
     
    86149200        if (get_Protocol() >= PROTOCOL_NT1) {
    86159201                req->flags2 |= 0x40; /* IS_LONG_NAME */
    8616                 SSVAL(req->inbuf,smb_flg2,req->flags2);
    8617         }
    8618 
    8619         if (conn->encrypt_level == Required && !req->encrypted) {
     9202                SSVAL((discard_const_p(uint8_t, req->inbuf)),smb_flg2,req->flags2);
     9203        }
     9204
     9205        if (ENCRYPTION_REQUIRED(conn) && !req->encrypted) {
    86209206                if (state->call != TRANSACT2_QFSINFO &&
    8621                                 state->call != TRANSACT2_SETFSINFO) {
     9207                    state->call != TRANSACT2_SETFSINFO) {
    86229208                        DEBUG(0,("handle_trans2: encryption required "
    86239209                                "with call 0x%x\n",
     
    88279413        }
    88289414
    8829         if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
     9415        if ((state = talloc(conn, struct trans_state)) == NULL) {
    88309416                DEBUG(0, ("talloc failed\n"));
    88319417                reply_nterror(req, NT_STATUS_NO_MEMORY);
     
    89739559        START_PROFILE(SMBtranss2);
    89749560
    8975         show_msg((char *)req->inbuf);
     9561        show_msg((const char *)req->inbuf);
    89769562
    89779563        /* Windows clients expect all replies to
Note: See TracChangeset for help on using the changeset viewer.