Ignore:
Timestamp:
May 13, 2014, 11:39:04 AM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update trunk to 3.6.23

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/smbd/trans2.c

    r792 r862  
    2525
    2626#include "includes.h"
     27#include "ntioctl.h"
    2728#include "system/filesys.h"
    2829#include "version.h"
     
    337338                }
    338339
     340                if (listp->ea.value.length == 0) {
     341                        /*
     342                         * We can never return a zero length EA.
     343                         * Windows reports the EA's as corrupted.
     344                         */
     345                        TALLOC_FREE(listp);
     346                        continue;
     347                }
     348
    339349                push_ascii_fstring(dos_ea_name, listp->ea.name);
    340350
     
    420430        uint8_t *p = (uint8_t *)pdata;
    421431        uint8_t *last_start = NULL;
     432        bool store_data = (pdata != NULL);
    422433
    423434        *ret_data_size = 0;
     
    431442                fstring dos_ea_name;
    432443                size_t this_size;
    433 
    434                 if (last_start) {
     444                size_t pad = 0;
     445
     446                if (last_start && store_data) {
    435447                        SIVAL(last_start, 0, PTR_DIFF(p, last_start));
    436448                }
     
    449461
    450462                if (ea_list->next) {
    451                         size_t pad = 4 - (this_size % 4);
     463                        pad = (4 - (this_size % 4)) % 4;
    452464                        this_size += pad;
    453465                }
     
    458470
    459471                /* We know we have room. */
    460                 SIVAL(p, 0x00, 0); /* next offset */
    461                 SCVAL(p, 0x04, ea_list->ea.flags);
    462                 SCVAL(p, 0x05, dos_namelen);
    463                 SSVAL(p, 0x06, ea_list->ea.value.length);
    464                 fstrcpy((char *)(p+0x08), dos_ea_name);
    465                 memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
     472                if (store_data) {
     473                        SIVAL(p, 0x00, 0); /* next offset */
     474                        SCVAL(p, 0x04, ea_list->ea.flags);
     475                        SCVAL(p, 0x05, dos_namelen);
     476                        SSVAL(p, 0x06, ea_list->ea.value.length);
     477                        fstrcpy((char *)(p+0x08), dos_ea_name);
     478                        memcpy(p + 0x08 + dos_namelen + 1, ea_list->ea.value.data, ea_list->ea.value.length);
     479                        if (pad) {
     480                                memset(p + 0x08 + dos_namelen + 1 + ea_list->ea.value.length,
     481                                        '\0',
     482                                        pad);
     483                        }
     484                }
    466485
    467486                total_data_size -= this_size;
     
    477496{
    478497        size_t total_ea_len = 0;
     498        struct ea_list *ea_list = NULL;
    479499        TALLOC_CTX *mem_ctx = NULL;
    480500
     
    483503        }
    484504        mem_ctx = talloc_tos();
    485         (void)get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
     505        ea_list = get_ea_list_from_file(mem_ctx, conn, fsp, fname, &total_ea_len);
     506        if (ea_list == NULL) {
     507                return 0;
     508        }
     509        if(conn->sconn->using_smb2) {
     510                NTSTATUS status;
     511                unsigned int ret_data_size;
     512                /*
     513                 * We're going to be using fill_ea_chained_buffer() to
     514                 * marshall EA's - this size is significantly larger
     515                 * than the SMB1 buffer. Re-calculate the size without
     516                 * marshalling.
     517                 */
     518                status = fill_ea_chained_buffer(mem_ctx,
     519                                                NULL,
     520                                                65535,
     521                                                &ret_data_size,
     522                                                conn,
     523                                                ea_list);
     524                if (!NT_STATUS_IS_OK(status)) {
     525                        ret_data_size = 0;
     526                }
     527                total_ea_len = ret_data_size;
     528        }
     529
    486530        return total_ea_len;
    487531}
     
    17441788                SIVAL(p,0,mode); p += 4;
    17451789                q = p; p += 4; /* q is placeholder for name length. */
    1746                 {
     1790                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     1791                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     1792                } else {
    17471793                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    17481794                                                                smb_fname->base_name);
    17491795                        SIVAL(p,0,ea_size); /* Extended attributes */
    1750                         p += 4;
    1751                 }
     1796                }
     1797                p += 4;
    17521798                /* Clear the short name buffer. This is
    17531799                 * IMPORTANT as not doing so will trigger
     
    19211967                SIVAL(p,0,mode); p += 4;
    19221968                q = p; p += 4; /* q is placeholder for name length. */
    1923                 {
     1969                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     1970                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     1971                } else {
    19241972                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    19251973                                                                smb_fname->base_name);
    19261974                        SIVAL(p,0,ea_size); /* Extended attributes */
    1927                         p +=4;
    1928                 }
     1975                }
     1976                p +=4;
    19291977                SIVAL(p,0,0); p += 4; /* Unknown - reserved ? */
    19301978                SBVAL(p,0,file_index); p += 8;
     
    19672015                SIVAL(p,0,mode); p += 4;
    19682016                q = p; p += 4; /* q is placeholder for name length */
    1969                 {
     2017                if (mode & FILE_ATTRIBUTE_REPARSE_POINT) {
     2018                        SIVAL(p, 0, IO_REPARSE_TAG_DFS);
     2019                } else {
    19702020                        unsigned int ea_size = estimate_ea_size(conn, NULL,
    19712021                                                                smb_fname->base_name);
    19722022                        SIVAL(p,0,ea_size); /* Extended attributes */
    1973                         p +=4;
    1974                 }
     2023                }
     2024                p +=4;
    19752025                /* Clear the short name buffer. This is
    19762026                 * IMPORTANT as not doing so will trigger
     
    29352985                         uint16_t flags2,
    29362986                         unsigned int max_data_bytes,
     2987                         size_t *fixed_portion,
     2988                         struct smb_filename *fname,
    29372989                         char **ppdata,
    29382990                         int *ret_data_len)
     
    29432995        int snum = SNUM(conn);
    29442996        char *fstype = lp_fstype(SNUM(conn));
     2997        const char *filename = NULL;
    29452998        uint32 additional_flags = 0;
    2946         struct smb_filename smb_fname_dot;
     2999        struct smb_filename smb_fname;
    29473000        SMB_STRUCT_STAT st;
     3001        NTSTATUS status = NT_STATUS_OK;
     3002
     3003        if (fname == NULL || fname->base_name == NULL) {
     3004                filename = ".";
     3005        } else {
     3006                filename = fname->base_name;
     3007        }
    29483008
    29493009        if (IS_IPC(conn)) {
     
    29583018        DEBUG(3,("smbd_do_qfsinfo: level = %d\n", info_level));
    29593019
    2960         ZERO_STRUCT(smb_fname_dot);
    2961         smb_fname_dot.base_name = discard_const_p(char, ".");
    2962 
    2963         if(SMB_VFS_STAT(conn, &smb_fname_dot) != 0) {
     3020        ZERO_STRUCT(smb_fname);
     3021        smb_fname.base_name = discard_const_p(char, filename);
     3022
     3023        if(SMB_VFS_STAT(conn, &smb_fname) != 0) {
    29643024                DEBUG(2,("stat of . failed (%s)\n", strerror(errno)));
    29653025                return map_nt_error_from_unix(errno);
    29663026        }
    29673027
    2968         st = smb_fname_dot.st;
     3028        st = smb_fname.st;
    29693029
    29703030        *ppdata = (char *)SMB_REALLOC(
     
    29773037        memset((char *)pdata,'\0',max_data_bytes + DIR_ENTRY_SAFETY_MARGIN);
    29783038        end_data = pdata + max_data_bytes + DIR_ENTRY_SAFETY_MARGIN - 1;
     3039
     3040        *fixed_portion = 0;
    29793041
    29803042        switch (info_level) {
     
    29833045                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    29843046                        data_len = 18;
    2985                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3047                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    29863048                                return map_nt_error_from_unix(errno);
    29873049                        }
     
    30703132                        SIVAL(pdata,8,len);
    30713133                        data_len = 12 + len;
     3134                        if (max_data_bytes >= 16 && data_len > max_data_bytes) {
     3135                                /* the client only requested a portion of the
     3136                                   file system name */
     3137                                data_len = max_data_bytes;
     3138                                status = STATUS_BUFFER_OVERFLOW;
     3139                        }
     3140                        *fixed_portion = 16;
    30723141                        break;
    30733142
     
    30993168                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol=%s serv=%s\n",
    31003169                                (int)strlen(vname),vname, lp_servicename(snum)));
     3170                        if (max_data_bytes >= 24 && data_len > max_data_bytes) {
     3171                                /* the client only requested a portion of the
     3172                                   volume label */
     3173                                data_len = max_data_bytes;
     3174                                status = STATUS_BUFFER_OVERFLOW;
     3175                        }
     3176
    31013177                        break;
    31023178
     
    31063182                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    31073183                        data_len = 24;
    3108                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3184                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    31093185                                return map_nt_error_from_unix(errno);
    31103186                        }
     
    31313207                        SIVAL(pdata,16,sectors_per_unit);
    31323208                        SIVAL(pdata,20,bytes_per_sector);
     3209                        *fixed_portion = 24;
    31333210                        break;
    31343211                }
     
    31383215                        uint64_t dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
    31393216                        data_len = 32;
    3140                         if (get_dfree_info(conn,".",False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
     3217                        if (get_dfree_info(conn,filename,False,&bsize,&dfree,&dsize) == (uint64_t)-1) {
    31413218                                return map_nt_error_from_unix(errno);
    31423219                        }
     
    31643241                        SIVAL(pdata,24,sectors_per_unit); /* Sectors per allocation unit. */
    31653242                        SIVAL(pdata,28,bytes_per_sector); /* Bytes per sector. */
     3243                        *fixed_portion = 32;
    31663244                        break;
    31673245                }
     
    31783256                        SIVAL(pdata,0,FILE_DEVICE_DISK); /* dev type */
    31793257                        SIVAL(pdata,4,characteristics);
     3258                        *fixed_portion = 8;
    31803259                        break;
    31813260                }
     
    33313410                        }
    33323411
    3333                         rc = SMB_VFS_STATVFS(conn, ".", &svfs);
     3412                        rc = SMB_VFS_STATVFS(conn, filename, &svfs);
    33343413
    33353414                        if (!rc) {
     
    33523431                                return NT_STATUS_DOS(ERRSRV, ERRerror);
    33533432                        }
     3433                        *fixed_portion = 24;
    33543434                        break;
    33553435                }
     
    34823562
    34833563        *ret_data_len = data_len;
    3484         return NT_STATUS_OK;
     3564        return status;
    34853565}
    34863566
     
    34983578        uint16_t info_level;
    34993579        int data_len = 0;
     3580        size_t fixed_portion;
    35003581        NTSTATUS status;
    35013582
     
    35243605                                 req->flags2,
    35253606                                 max_data_bytes,
     3607                                 &fixed_portion,
     3608                                 NULL,
    35263609                                 ppdata, &data_len);
    35273610        if (!NT_STATUS_IS_OK(status)) {
     
    40764159        unsigned int ofs = 0;
    40774160
    4078         for (i = 0; i < num_streams && ofs <= max_data_bytes; i++) {
     4161        if (max_data_bytes < 32) {
     4162                return NT_STATUS_INFO_LENGTH_MISMATCH;
     4163        }
     4164
     4165        for (i = 0; i < num_streams; i++) {
    40794166                unsigned int next_offset;
    40804167                size_t namelen;
     
    40954182                namelen -= 2;
    40964183
     4184                /*
     4185                 * We cannot overflow ...
     4186                 */
     4187                if ((ofs + 24 + namelen) > max_data_bytes) {
     4188                        DEBUG(10, ("refusing to overflow reply at stream %u\n",
     4189                                i));
     4190                        TALLOC_FREE(namebuf);
     4191                        return STATUS_BUFFER_OVERFLOW;
     4192                }
     4193
    40974194                SIVAL(data, ofs+4, namelen);
    40984195                SOFF_T(data, ofs+8, streams[i].size);
     
    41094206                        unsigned int align = ndr_align_size(next_offset, 8);
    41104207
     4208                        if ((next_offset + align) > max_data_bytes) {
     4209                                DEBUG(10, ("refusing to overflow align "
     4210                                        "reply at stream %u\n",
     4211                                        i));
     4212                                TALLOC_FREE(namebuf);
     4213                                return STATUS_BUFFER_OVERFLOW;
     4214                        }
     4215
    41114216                        memset(data+next_offset, 0, align);
    41124217                        next_offset += align;
     
    41184223                ofs = next_offset;
    41194224        }
     4225
     4226        DEBUG(10, ("max_data: %u, data_size: %u\n", max_data_bytes, ofs));
    41204227
    41214228        *data_size = ofs;
     
    42074314                               uint16_t flags2,
    42084315                               unsigned int max_data_bytes,
     4316                               size_t *fixed_portion,
    42094317                               char **ppdata,
    42104318                               unsigned int *pdata_size)
     
    43424450        file_index = get_FileIndex(conn, psbuf);
    43434451
     4452        *fixed_portion = 0;
     4453
    43444454        switch (info_level) {
    43454455                case SMB_INFO_STANDARD:
     
    44794589                        DEBUG(5,("change: %s ", ctime(&c_time)));
    44804590                        DEBUG(5,("mode: %x\n", mode));
     4591                        *fixed_portion = data_size;
    44814592                        break;
    44824593
     
    44924603                        SCVAL(pdata,21,(mode&FILE_ATTRIBUTE_DIRECTORY)?1:0);
    44934604                        SSVAL(pdata,22,0); /* Padding. */
     4605                        *fixed_portion = 24;
    44944606                        break;
    44954607
     
    45014613                        DEBUG(10,("smbd_do_qfilepathinfo: SMB_FILE_EA_INFORMATION\n"));
    45024614                        data_size = 4;
     4615                        *fixed_portion = 4;
    45034616                        SIVAL(pdata,0,ea_size);
    45044617                        break;
     
    45224635                        data_size = 4 + len;
    45234636                        SIVAL(pdata,0,len);
     4637                        *fixed_portion = 8;
    45244638                        break;
    45254639                }
     
    45854699                        pdata += 4 + len;
    45864700                        data_size = PTR_DIFF(pdata,(*ppdata));
     4701                        *fixed_portion = 10;
    45874702                        break;
    45884703                }
     
    46224737                        pdata += 4 + len;
    46234738                        data_size = PTR_DIFF(pdata,(*ppdata));
     4739                        *fixed_portion = 104;
    46244740                        break;
    46254741                }
     
    46294745                        SBVAL(pdata, 0, file_index);
    46304746                        data_size = 8;
     4747                        *fixed_portion = 8;
    46314748                        break;
    46324749
     
    46354752                        SIVAL(pdata, 0, access_mask);
    46364753                        data_size = 4;
     4754                        *fixed_portion = 4;
    46374755                        break;
    46384756
     
    46524770                        data_size = 1;
    46534771                        SCVAL(pdata,0,delete_pending);
     4772                        *fixed_portion = 1;
    46544773                        break;
    46554774
     
    46584777                        data_size = 8;
    46594778                        SOFF_T(pdata,0,pos);
     4779                        *fixed_portion = 8;
    46604780                        break;
    46614781
     
    46644784                        SIVAL(pdata,0,mode);
    46654785                        data_size = 4;
     4786                        *fixed_portion = 4;
    46664787                        break;
    46674788
     
    46704791                        SIVAL(pdata,0,0); /* No alignment needed. */
    46714792                        data_size = 4;
     4793                        *fixed_portion = 4;
    46724794                        break;
    46734795
     
    47084830                                DEBUG(10, ("marshall_stream_info failed: %s\n",
    47094831                                           nt_errstr(status)));
     4832                                TALLOC_FREE(streams);
    47104833                                return status;
    47114834                        }
    47124835
    47134836                        TALLOC_FREE(streams);
     4837
     4838                        *fixed_portion = 32;
    47144839
    47154840                        break;
     
    47224847                        SIVAL(pdata,12,0); /* ??? */
    47234848                        data_size = 16;
     4849                        *fixed_portion = 16;
    47244850                        break;
    47254851
     
    47354861                        SIVAL(pdata,52,0); /* ??? */
    47364862                        data_size = 56;
     4863                        *fixed_portion = 56;
    47374864                        break;
    47384865
     
    47424869                        SIVAL(pdata,4,0);
    47434870                        data_size = 8;
     4871                        *fixed_portion = 8;
    47444872                        break;
    47454873
     
    50115139        int lock_data_count = 0;
    50125140        char *lock_data = NULL;
     5141        size_t fixed_portion;
    50135142        NTSTATUS status = NT_STATUS_OK;
    50145143
     
    53725501                                       lock_data_count, lock_data,
    53735502                                       req->flags2, max_data_bytes,
     5503                                       &fixed_portion,
    53745504                                       ppdata, &data_size);
    53755505        if (!NT_STATUS_IS_OK(status)) {
    53765506                reply_nterror(req, status);
     5507                return;
     5508        }
     5509        if (fixed_portion > max_data_bytes) {
     5510                reply_nterror(req, NT_STATUS_INFO_LENGTH_MISMATCH);
    53775511                return;
    53785512        }
     
    73257459                        create_disp = FILE_OPEN_IF;
    73267460                        break;
     7461                case SMB_O_EXCL:
     7462                        /* O_EXCL on its own without O_CREAT is undefined.
     7463                           We deliberately ignore it as some versions of
     7464                           Linux CIFSFS can send a bare O_EXCL on the
     7465                           wire which other filesystems in the kernel
     7466                           ignore. See bug 9519 for details. */
     7467
     7468                        /* Fallthrough. */
     7469
    73277470                case 0:
    73287471                        /* File exists open. File not exist fail. */
    73297472                        create_disp = FILE_OPEN;
    73307473                        break;
    7331                 case SMB_O_EXCL:
    7332                         /* O_EXCL on its own without O_CREAT is undefined. */
    73337474                default:
    73347475                        DEBUG(5,("smb_posix_open: invalid create mode 0x%x\n",
     
    75837724                        }
    75847725                        /* Fail with sharing violation. */
     7726                        TALLOC_FREE(lck);
    75857727                        close_file(req, fsp, NORMAL_CLOSE);
    7586                         TALLOC_FREE(lck);
    75877728                        return NT_STATUS_SHARING_VIOLATION;
    75887729                }
     
    75987739                                                smb_fname);
    75997740
     7741        TALLOC_FREE(lck);
     7742
    76007743        if (!NT_STATUS_IS_OK(status)) {
    76017744                close_file(req, fsp, NORMAL_CLOSE);
    7602                 TALLOC_FREE(lck);
    76037745                return status;
    76047746        }
    7605         TALLOC_FREE(lck);
    76067747        return close_file(req, fsp, NORMAL_CLOSE);
    76077748}
Note: See TracChangeset for help on using the changeset viewer.