Ignore:
Timestamp:
Nov 29, 2012, 1:59:04 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.9

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/source3/smbd/files.c

    r745 r751  
    2929
    3030/****************************************************************************
    31  Return a unique number identifying this fsp over the life of this pid.
     31 Return a unique number identifying this fsp over the life of this pid,
     32 and try to make it as globally unique as possible.
     33 See bug #8995 for the details.
    3234****************************************************************************/
    3335
    3436static unsigned long get_gen_count(struct smbd_server_connection *sconn)
    3537{
     38        /*
     39         * While fsp->fh->gen_id is 'unsigned long' currently
     40         * (which might by 8 bytes),
     41         * there's some oplock code which truncates it to
     42         * uint32_t(using IVAL()).
     43         */
     44        if (sconn->file_gen_counter == 0) {
     45                sconn->file_gen_counter = generate_random();
     46        }
    3647        sconn->file_gen_counter += 1;
     48        if (sconn->file_gen_counter >= UINT32_MAX) {
     49                sconn->file_gen_counter = 0;
     50        }
    3751        if (sconn->file_gen_counter == 0) {
    3852                sconn->file_gen_counter += 1;
     
    284298        int count=0;
    285299        files_struct *fsp;
     300
     301        if (gen_id == 0) {
     302                return NULL;
     303        }
    286304
    287305        for (fsp=sconn->files; fsp; fsp=fsp->next,count++) {
     
    549567}
    550568
     569uint64_t fsp_persistent_id(const struct files_struct *fsp)
     570{
     571        uint64_t persistent_id;
     572
     573        /*
     574         * This calculates a number that is most likely
     575         * globally unique. In future we will have a database
     576         * to make it completely unique.
     577         *
     578         * 32-bit random gen_id
     579         * 16-bit truncated open_time
     580         * 16-bit fnum (valatile_id)
     581         */
     582        persistent_id = fsp->fh->gen_id & UINT32_MAX;
     583        persistent_id <<= 16;
     584        persistent_id &= 0x0000FFFFFFFF0000LLU;
     585        persistent_id |= fsp->open_time.tv_usec & UINT16_MAX;
     586        persistent_id <<= 16;
     587        persistent_id &= 0xFFFFFFFFFFFF0000LLU;
     588        persistent_id |= fsp->fnum & UINT16_MAX;
     589
     590        return persistent_id;
     591}
     592
     593struct files_struct *file_fsp_smb2(struct smbd_smb2_request *smb2req,
     594                                   uint64_t persistent_id,
     595                                   uint64_t volatile_id)
     596{
     597        struct files_struct *fsp;
     598        uint64_t fsp_persistent;
     599
     600        if (smb2req->compat_chain_fsp != NULL) {
     601                return smb2req->compat_chain_fsp;
     602        }
     603
     604        if (volatile_id > UINT16_MAX) {
     605                return NULL;
     606        }
     607
     608        fsp = file_fnum(smb2req->sconn, (uint16_t)volatile_id);
     609        if (fsp == NULL) {
     610                return NULL;
     611        }
     612        fsp_persistent = fsp_persistent_id(fsp);
     613
     614        if (persistent_id != fsp_persistent) {
     615                return NULL;
     616        }
     617
     618        if (smb2req->tcon == NULL) {
     619                return NULL;
     620        }
     621
     622        if (smb2req->tcon->compat_conn != fsp->conn) {
     623                return NULL;
     624        }
     625
     626        if (smb2req->session == NULL) {
     627                return NULL;
     628        }
     629
     630        if (smb2req->session->vuid != fsp->vuid) {
     631                return NULL;
     632        }
     633
     634        smb2req->compat_chain_fsp = fsp;
     635        return fsp;
     636}
     637
    551638/****************************************************************************
    552639 Duplicate the file handle part for a DOS or FCB open.
Note: See TracChangeset for help on using the changeset viewer.