Ignore:
Timestamp:
May 12, 2014, 8:58:38 PM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.6: updated vendor to latest version

File:
1 edited

Legend:

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

    r746 r860  
    2525
    2626#include "includes.h"
     27#include "ntioctl.h"
    2728#include "system/filesys.h"
    2829#include "version.h"
     
    329330                }
    330331
     332                if (listp->ea.value.length == 0) {
     333                        /*
     334                         * We can never return a zero length EA.
     335                         * Windows reports the EA's as corrupted.
     336                         */
     337                        TALLOC_FREE(listp);
     338                        continue;
     339                }
     340
    331341                push_ascii_fstring(dos_ea_name, listp->ea.name);
    332342
     
    412422        uint8_t *p = (uint8_t *)pdata;
    413423        uint8_t *last_start = NULL;
     424        bool store_data = (pdata != NULL);
    414425
    415426        *ret_data_size = 0;
     
    423434                fstring dos_ea_name;
    424435                size_t this_size;
    425 
    426                 if (last_start) {
     436                size_t pad = 0;
     437
     438                if (last_start && store_data) {
    427439                        SIVAL(last_start, 0, PTR_DIFF(p, last_start));
    428440                }
     
    441453
    442454                if (ea_list->next) {
    443                         size_t pad = 4 - (this_size % 4);
     455                        pad = (4 - (this_size % 4)) % 4;
    444456                        this_size += pad;
    445457                }
     
    450462
    451463                /* We know we have room. */
    452                 SIVAL(p, 0x00, 0); /* next offset */
    453                 SCVAL(p, 0x04, ea_list->ea.flags);
    454                 SCVAL(p, 0x05, dos_namelen);
    455                 SSVAL(p, 0x06, ea_list->ea.value.length);
    456                 fstrcpy((char *)(p+0x08), dos_ea_name);
    457                 memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
     464                if (store_data) {
     465                        SIVAL(p, 0x00, 0); /* next offset */
     466                        SCVAL(p, 0x04, ea_list->ea.flags);
     467                        SCVAL(p, 0x05, dos_namelen);
     468                        SSVAL(p, 0x06, ea_list->ea.value.length);
     469                        fstrcpy((char *)(p+0x08), dos_ea_name);
     470                        memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
     471                        if (pad) {
     472                                memset(p + 0x08 + dos_namelen + 1 + ea_list->ea.value.length,
     473                                        '\0',
     474                                        pad);
     475                        }
     476                }
    458477
    459478                total_data_size -= this_size;
     
    469488{
    470489        size_t total_ea_len = 0;
     490        struct ea_list *ea_list = NULL;
    471491        TALLOC_CTX *mem_ctx = NULL;
    472492
     
    475495        }
    476496        mem_ctx = talloc_tos();
    477         (void)get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
     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        }
     501        if(conn->sconn->using_smb2) {
     502                NTSTATUS status;
     503                unsigned int ret_data_size;
     504                /*
     505                 * We're going to be using fill_ea_chained_buffer() to
     506                 * marshall EA's - this size is significantly larger
     507                 * than the SMB1 buffer. Re-calculate the size without
     508                 * marshalling.
     509                 */
     510                status = fill_ea_chained_buffer(mem_ctx,
     511                                                NULL,
     512                                                65535,
     513                                                &ret_data_size,
     514                                                conn,
     515                                                ea_list);
     516                if (!NT_STATUS_IS_OK(status)) {
     517                        ret_data_size = 0;
     518                }
     519                total_ea_len = ret_data_size;
     520        }
     521
    478522        return total_ea_len;
    479523}
     
    17311775                SIVAL(p,0,mode); p += 4;
    17321776                q = p; p += 4; /* q is placeholder for name length. */
    1733                 {
     1777                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     1778                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     1779                } else {
    17341780                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    17351781                                                                smb_fname->base_name);
    17361782                        SIVAL(p,0,ea_size); /* Extended attributes */
    1737                         p += 4;
    1738                 }
     1783                }
     1784                p += 4;
    17391785                /* Clear the short name buffer. This is
    17401786                 * IMPORTANT as not doing so will trigger
     
    19081954                SIVAL(p,0,mode); p += 4;
    19091955                q = p; p += 4; /* q is placeholder for name length. */
    1910                 {
     1956                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     1957                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     1958                } else {
    19111959                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    19121960                                                                smb_fname->base_name);
    19131961                        SIVAL(p,0,ea_size); /* Extended attributes */
    1914                         p +=4;
    1915                 }
     1962                }
     1963                p +=4;
    19161964                SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
    19171965                SBVAL(p,0,file_index); p += 8;
     
    19542002                SIVAL(p,0,mode); p += 4;
    19552003                q = p; p += 4; /* q is placeholder for name length */
    1956                 {
     2004                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     2005                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     2006                } else {
    19572007                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    19582008                                                                smb_fname->base_name);
    19592009                        SIVAL(p,0,ea_size); /* Extended attributes */
    1960                         p +=4;
    1961                 }
     2010                }
     2011                p +=4;
    19622012                /* Clear the short name buffer. This is
    19632013                 * IMPORTANT as not doing so will trigger
     
    29222972                         uint16_t flags2,
    29232973                         unsigned int max_data_bytes,
     2974                         size_t *fixed_portion,
     2975                         struct smb_filename *fname,
    29242976                         char **ppdata,
    29252977                         int *ret_data_len)
     
    29302982        int snum = SNUM(conn);
    29312983        char *fstype = lp_fstype(SNUM(conn));
     2984        const char *filename = NULL;
    29322985        uint32 additional_flags = 0;
    2933         struct smb_filename smb_fname_dot;
     2986        struct smb_filename smb_fname;
    29342987        SMB_STRUCT_STAT st;
     2988        NTSTATUS status = NT_STATUS_OK;
     2989
     2990        if (fname == NULL || fname->base_name == NULL) {
     2991                filename = ".";
     2992        } else {
     2993                filename = fname->base_name;
     2994        }
    29352995
    29362996        if (IS_IPC(conn)) {
     
    29453005        DEBUG(3,("smbd_do_qfsinfo: level = %d\n", info_level));
    29463006
    2947         ZERO_STRUCT(smb_fname_dot);
    2948         smb_fname_dot.base_name = discard_const_p(char, ".");
    2949 
    2950         if(SMB_VFS_STAT(conn, &smb_fname_dot) != 0) {
     3007        ZERO_STRUCT(smb_fname);
     3008        smb_fname.base_name = discard_const_p(char, filename);
     3009
     3010        if(SMB_VFS_STAT(conn, &smb_fname) != 0) {
    29513011                DEBUG(2,("stat of . failed (%s)\n", strerror(errno)));
    29523012                return map_nt_error_from_unix(errno);
    29533013        }
    29543014
    2955         st = smb_fname_dot.st;
     3015        st = smb_fname.st;
    29563016
    29573017        *ppdata = (char *)SMB_REALLOC(
     
    29643024        memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
    29653025        end_data = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
     3026
     3027        *fixed_portion = 0;
    29663028
    29673029        switch (info_level) {
     
    29703032                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    29713033                        data_len = 18;
    2972                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3034                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    29733035                                return map_nt_error_from_unix(errno);
    29743036                        }
     
    30573119                        SIVAL(pdata,8,len);
    30583120                        data_len = 12 + len;
     3121                        if (max_data_bytes >= 16 && data_len > max_data_bytes) {
     3122                                /* the client only requested a portion of the
     3123                                   file system name */
     3124                                data_len = max_data_bytes;
     3125                                status = STATUS_BUFFER_OVERFLOW;
     3126                        }
     3127                        *fixed_portion = 16;
    30593128                        break;
    30603129
     
    30863155                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
    30873156                                (int)strlen(vname),vname, lp_servicename(snum)));
     3157                        if (max_data_bytes >= 24 && data_len > max_data_bytes) {
     3158                                /* the client only requested a portion of the
     3159                                   volume label */
     3160                                data_len = max_data_bytes;
     3161                                status = STATUS_BUFFER_OVERFLOW;
     3162                        }
     3163
    30883164                        break;
    30893165
     
    30933169                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    30943170                        data_len = 24;
    3095                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3171                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    30963172                                return map_nt_error_from_unix(errno);
    30973173                        }
     
    31183194                        SIVAL(pdata,16,sectors_per_unit);
    31193195                        SIVAL(pdata,20,bytes_per_sector);
     3196                        *fixed_portion = 24;
    31203197                        break;
    31213198                }
     
    31253202                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    31263203                        data_len = 32;
    3127                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3204                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    31283205                                return map_nt_error_from_unix(errno);
    31293206                        }
     
    31513228                        SIVAL(pdata,24,sectors_per_unit); /* Sectors per allocation unit. */
    31523229                        SIVAL(pdata,28,bytes_per_sector); /* Bytes per sector. */
     3230                        *fixed_portion = 32;
    31533231                        break;
    31543232                }
     
    31653243                        SIVAL(pdata,0,FILE_DEVICE_DISK); /* dev type */
    31663244                        SIVAL(pdata,4,characteristics);
     3245                        *fixed_portion = 8;
    31673246                        break;
    31683247                }
     
    33183397                        }
    33193398
    3320                         rc = SMB_VFS_STATVFS(conn, ".", &svfs);
     3399                        rc = SMB_VFS_STATVFS(conn, filename, &svfs);
    33213400
    33223401                        if (!rc) {
     
    33393418                                return NT_STATUS_DOS(ERRSRV, ERRerror);
    33403419                        }
     3420                        *fixed_portion = 24;
    33413421                        break;
    33423422                }
     
    34693549
    34703550        *ret_data_len = data_len;
    3471         return NT_STATUS_OK;
     3551        return status;
    34723552}
    34733553
     
    34853565        uint16_t info_level;
    34863566        int data_len = 0;
     3567        size_t fixed_portion;
    34873568        NTSTATUS status;
    34883569
     
    35113592                                 req->flags2,
    35123593                                 max_data_bytes,
     3594                                 &fixed_portion,
     3595                                 NULL,
    35133596                                 ppdata, &data_len);
    35143597        if (!NT_STATUS_IS_OK(status)) {
     
    40634146        unsigned int ofs = 0;
    40644147
    4065         for (i = 0; i < num_streams && ofs <= max_data_bytes; i++) {
     4148        if (max_data_bytes < 32) {
     4149                return NT_STATUS_INFO_LENGTH_MISMATCH;
     4150        }
     4151
     4152        for (i = 0; i < num_streams; i++) {
    40664153                unsigned int next_offset;
    40674154                size_t namelen;
     
    40824169                namelen -= 2;
    40834170
     4171                /*
     4172                 * We cannot overflow ...
     4173                 */
     4174                if ((ofs + 24 + namelen) > max_data_bytes) {
     4175                        DEBUG(10, ("refusing to overflow reply at stream %u\n",
     4176                                i));
     4177                        TALLOC_FREE(namebuf);
     4178                        return STATUS_BUFFER_OVERFLOW;
     4179                }
     4180
    40844181                SIVAL(data, ofs+4, namelen);
    40854182                SOFF_T(data, ofs+8, streams[i].size);
     
    40964193                        unsigned int align = ndr_align_size(next_offset, 8);
    40974194
     4195                        if ((next_offset + align) > max_data_bytes) {
     4196                                DEBUG(10, ("refusing to overflow align "
     4197                                        "reply at stream %u\n",
     4198                                        i));
     4199                                TALLOC_FREE(namebuf);
     4200                                return STATUS_BUFFER_OVERFLOW;
     4201                        }
     4202
    40984203                        memset(data+next_offset, 0, align);
    40994204                        next_offset += align;
     
    41054210                ofs = next_offset;
    41064211        }
     4212
     4213        DEBUG(10, ("max_data: %u, data_size: %u\n", max_data_bytes, ofs));
    41074214
    41084215        *data_size = ofs;
     
    41944301                               uint16_t flags2,
    41954302                               unsigned int max_data_bytes,
     4303                               size_t *fixed_portion,
    41964304                               char **ppdata,
    41974305                               unsigned int *pdata_size)
     
    43294437        file_index = get_FileIndex(conn, psbuf);
    43304438
     4439        *fixed_portion = 0;
     4440
    43314441        switch (info_level) {
    43324442                case SMB_INFO_STANDARD:
     
    44664576                        DEBUG(5,("change: %s ", ctime(&c_time)));
    44674577                        DEBUG(5,("mode: %x\n", mode));
     4578                        *fixed_portion = data_size;
    44684579                        break;
    44694580
     
    44794590                        SCVAL(pdata,21,(mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
    44804591                        SSVAL(pdata,22,0); /* Padding. */
     4592                        *fixed_portion = 24;
    44814593                        break;
    44824594
     
    44884600                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
    44894601                        data_size = 4;
     4602                        *fixed_portion = 4;
    44904603                        SIVAL(pdata,0,ea_size);
    44914604                        break;
     
    45094622                        data_size = 4 + len;
    45104623                        SIVAL(pdata,0,len);
     4624                        *fixed_portion = 8;
    45114625                        break;
    45124626                }
     
    45724686                        pdata += 4 + len;
    45734687                        data_size = PTR_DIFF(pdata,(*ppdata));
     4688                        *fixed_portion = 10;
    45744689                        break;
    45754690                }
     
    46094724                        pdata += 4 + len;
    46104725                        data_size = PTR_DIFF(pdata,(*ppdata));
     4726                        *fixed_portion = 104;
    46114727                        break;
    46124728                }
     
    46164732                        SBVAL(pdata, 0, file_index);
    46174733                        data_size = 8;
     4734                        *fixed_portion = 8;
    46184735                        break;
    46194736
     
    46224739                        SIVAL(pdata, 0, access_mask);
    46234740                        data_size = 4;
     4741                        *fixed_portion = 4;
    46244742                        break;
    46254743
     
    46394757                        data_size = 1;
    46404758                        SCVAL(pdata,0,delete_pending);
     4759                        *fixed_portion = 1;
    46414760                        break;
    46424761
     
    46454764                        data_size = 8;
    46464765                        SOFF_T(pdata,0,pos);
     4766                        *fixed_portion = 8;
    46474767                        break;
    46484768
     
    46514771                        SIVAL(pdata,0,mode);
    46524772                        data_size = 4;
     4773                        *fixed_portion = 4;
    46534774                        break;
    46544775
     
    46574778                        SIVAL(pdata,0,0); /* No alignment needed. */
    46584779                        data_size = 4;
     4780                        *fixed_portion = 4;
    46594781                        break;
    46604782
     
    46954817                                DEBUG(10, ("marshall_stream_info failed: %s\n",
    46964818                                           nt_errstr(status)));
     4819                                TALLOC_FREE(streams);
    46974820                                return status;
    46984821                        }
    46994822
    47004823                        TALLOC_FREE(streams);
     4824
     4825                        *fixed_portion = 32;
    47014826
    47024827                        break;
     
    47094834                        SIVAL(pdata,12,0); /* ??? */
    47104835                        data_size = 16;
     4836                        *fixed_portion = 16;
    47114837                        break;
    47124838
     
    47224848                        SIVAL(pdata,52,0); /* ??? */
    47234849                        data_size = 56;
     4850                        *fixed_portion = 56;
    47244851                        break;
    47254852
     
    47294856                        SIVAL(pdata,4,0);
    47304857                        data_size = 8;
     4858                        *fixed_portion = 8;
    47314859                        break;
    47324860
     
    49985126        int lock_data_count = 0;
    49995127        char *lock_data = NULL;
     5128        size_t fixed_portion;
    50005129        NTSTATUS status = NT_STATUS_OK;
    50015130
     
    53595488                                       lock_data_count, lock_data,
    53605489                                       req->flags2, max_data_bytes,
     5490                                       &fixed_portion,
    53615491                                       ppdata, &data_size);
    53625492        if (!NT_STATUS_IS_OK(status)) {
    53635493                reply_nterror(req, status);
     5494                return;
     5495        }
     5496        if (fixed_portion > max_data_bytes) {
     5497                reply_nterror(req, NT_STATUS_INFO_LENGTH_MISMATCH);
    53645498                return;
    53655499        }
     
    73087442                        create_disp = FILE_OPEN_IF;
    73097443                        break;
     7444                case SMB_O_EXCL:
     7445                        /* O_EXCL on its own without O_CREAT is undefined.
     7446                           We deliberately ignore it as some versions of
     7447                           Linux CIFSFS can send a bare O_EXCL on the
     7448                           wire which other filesystems in the kernel
     7449                           ignore. See bug 9519 for details. */
     7450
     7451                        /* Fallthrough. */
     7452
    73107453                case 0:
    73117454                        /* File exists open. File not exist fail. */
    73127455                        create_disp = FILE_OPEN;
    73137456                        break;
    7314                 case SMB_O_EXCL:
    7315                         /* O_EXCL on its own without O_CREAT is undefined. */
    73167457                default:
    73177458                        DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
     
    75667707                        }
    75677708                        /* Fail with sharing violation. */
     7709                        TALLOC_FREE(lck);
    75687710                        close_file(req, fsp, NORMAL_CLOSE);
    7569                         TALLOC_FREE(lck);
    75707711                        return NT_STATUS_SHARING_VIOLATION;
    75717712                }
     
    75817722                                                smb_fname);
    75827723
     7724        TALLOC_FREE(lck);
     7725
    75837726        if (!NT_STATUS_IS_OK(status)) {
    75847727                close_file(req, fsp, NORMAL_CLOSE);
    7585                 TALLOC_FREE(lck);
    75867728                return status;
    75877729        }
    7588         TALLOC_FREE(lck);
    75897730        return close_file(req, fsp, NORMAL_CLOSE);
    75907731}
Note: See TracChangeset for help on using the changeset viewer.