Changeset 751 for trunk/server/source3/smbd/files.c
- Timestamp:
- Nov 29, 2012, 1:59:04 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/source3/smbd/files.c
r745 r751 29 29 30 30 /**************************************************************************** 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. 32 34 ****************************************************************************/ 33 35 34 36 static unsigned long get_gen_count(struct smbd_server_connection *sconn) 35 37 { 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 } 36 47 sconn->file_gen_counter += 1; 48 if (sconn->file_gen_counter >= UINT32_MAX) { 49 sconn->file_gen_counter = 0; 50 } 37 51 if (sconn->file_gen_counter == 0) { 38 52 sconn->file_gen_counter += 1; … … 284 298 int count=0; 285 299 files_struct *fsp; 300 301 if (gen_id == 0) { 302 return NULL; 303 } 286 304 287 305 for (fsp=sconn->files; fsp; fsp=fsp->next,count++) { … … 549 567 } 550 568 569 uint64_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 593 struct 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 551 638 /**************************************************************************** 552 639 Duplicate the file handle part for a DOS or FCB open.
Note:
See TracChangeset
for help on using the changeset viewer.