static void reply_lockingX_error(struct blocking_lock_record *blr, NTSTATUS status) { files_struct *fsp = blr->fsp; uint16 num_ulocks = SVAL(blr->req->vwv+6, 0); uint64_t count = (uint64_t)0, offset = (uint64_t) 0; uint32 lock_pid; unsigned char locktype = CVAL(blr->req->vwv+3, 0); bool large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES); uint8_t *data; int i; data = (uint8_t *)blr->req->buf + ((large_file_format ? 20 : 10)*num_ulocks); /* * Data now points at the beginning of the list * of smb_lkrng structs. */ /* * Ensure we don't do a remove on the lock that just failed, * as under POSIX rules, if we have a lock already there, we * will delete it (and we shouldn't) ..... */ for(i = blr->lock_num - 1; i >= 0; i--) { bool err; lock_pid = get_lock_pid( data, i, large_file_format); count = get_lock_count( data, i, large_file_format); offset = get_lock_offset( data, i, large_file_format, &err); /* * We know err cannot be set as if it was the lock * request would never have been queued. JRA. */ do_unlock(smbd_messaging_context(), fsp, lock_pid, count, offset, WINDOWS_LOCK); } generic_blocking_lock_error(blr, status); }
static void undo_locks_obtained(struct blocking_lock_record *blr) { files_struct *fsp = blr->fsp; uint16 num_ulocks = SVAL(blr->req->vwv+6, 0); uint64_t count = (uint64_t)0, offset = (uint64_t) 0; uint64_t smblctx; unsigned char locktype = CVAL(blr->req->vwv+3, 0); bool large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES); uint8_t *data; int i; data = discard_const_p(uint8_t, blr->req->buf) + ((large_file_format ? 20 : 10)*num_ulocks); /* * Data now points at the beginning of the list * of smb_lkrng structs. */ /* * Ensure we don't do a remove on the lock that just failed, * as under POSIX rules, if we have a lock already there, we * will delete it (and we shouldn't) ..... */ for(i = blr->lock_num - 1; i >= 0; i--) { bool err; smblctx = get_lock_pid( data, i, large_file_format); count = get_lock_count( data, i, large_file_format); offset = get_lock_offset( data, i, large_file_format, &err); /* * We know err cannot be set as if it was the lock * request would never have been queued. JRA. */ do_unlock(fsp->conn->sconn->msg_ctx, fsp, smblctx, count, offset, WINDOWS_LOCK); } }
static void reply_lockingX_error(blocking_lock_record *blr, NTSTATUS status) { char *inbuf = blr->inbuf; files_struct *fsp = blr->fsp; connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); uint16 num_ulocks = SVAL(inbuf,smb_vwv6); SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT) 0; uint16 lock_pid; unsigned char locktype = CVAL(inbuf,smb_vwv3); BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES); char *data; int i; data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks); /* * Data now points at the beginning of the list * of smb_lkrng structs. */ /* * Ensure we don't do a remove on the lock that just failed, * as under POSIX rules, if we have a lock already there, we * will delete it (and we shouldn't) ..... */ for(i = blr->lock_num - 1; i >= 0; i--) { BOOL err; lock_pid = get_lock_pid( data, i, large_file_format); count = get_lock_count( data, i, large_file_format); offset = get_lock_offset( data, i, large_file_format, &err); /* * We know err cannot be set as if it was the lock * request would never have been queued. JRA. */ do_unlock(fsp,conn,lock_pid,count,offset); } generic_blocking_lock_error(blr, status); }
static bool process_lockingX(struct blocking_lock_record *blr) { unsigned char locktype = CVAL(blr->req->vwv+3, 0); files_struct *fsp = blr->fsp; uint16 num_ulocks = SVAL(blr->req->vwv+6, 0); uint16 num_locks = SVAL(blr->req->vwv+7, 0); uint64_t count = (uint64_t)0, offset = (uint64_t)0; uint32 lock_pid; bool large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES); uint8_t *data; NTSTATUS status = NT_STATUS_OK; data = (uint8_t *)blr->req->buf + ((large_file_format ? 20 : 10)*num_ulocks); /* * Data now points at the beginning of the list * of smb_lkrng structs. */ for(; blr->lock_num < num_locks; blr->lock_num++) { struct byte_range_lock *br_lck = NULL; bool err; lock_pid = get_lock_pid( data, blr->lock_num, large_file_format); count = get_lock_count( data, blr->lock_num, large_file_format); offset = get_lock_offset( data, blr->lock_num, large_file_format, &err); /* * We know err cannot be set as if it was the lock * request would never have been queued. JRA. */ errno = 0; br_lck = do_lock(smbd_messaging_context(), fsp, lock_pid, count, offset, ((locktype & LOCKING_ANDX_SHARED_LOCK) ? READ_LOCK : WRITE_LOCK), WINDOWS_LOCK, True, &status, &blr->blocking_pid, blr); TALLOC_FREE(br_lck); if (NT_STATUS_IS_ERR(status)) { break; } } if(blr->lock_num == num_locks) { /* * Success - we got all the locks. */ DEBUG(3,("process_lockingX file = %s, fnum=%d type=%d num_locks=%d\n", fsp->fsp_name, fsp->fnum, (unsigned int)locktype, num_locks) ); reply_lockingX_success(blr); return True; } if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) && !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) { /* * We have other than a "can't get lock" * error. Free any locks we had and return an error. * Return True so we get dequeued. */ blocking_lock_reply_error(blr, status); return True; } /* * Still can't get all the locks - keep waiting. */ DEBUG(10,("process_lockingX: only got %d locks of %d needed for file %s, fnum = %d. \ Waiting....\n", blr->lock_num, num_locks, fsp->fsp_name, fsp->fnum)); return False; }
static BOOL process_lockingX(blocking_lock_record *blr) { char *inbuf = blr->inbuf; unsigned char locktype = CVAL(inbuf,smb_vwv3); files_struct *fsp = blr->fsp; connection_struct *conn = conn_find(SVAL(inbuf,smb_tid)); uint16 num_ulocks = SVAL(inbuf,smb_vwv6); uint16 num_locks = SVAL(inbuf,smb_vwv7); SMB_BIG_UINT count = (SMB_BIG_UINT)0, offset = (SMB_BIG_UINT)0; uint16 lock_pid; BOOL large_file_format = (locktype & LOCKING_ANDX_LARGE_FILES); char *data; BOOL my_lock_ctx = False; NTSTATUS status = NT_STATUS_OK; data = smb_buf(inbuf) + ((large_file_format ? 20 : 10)*num_ulocks); /* * Data now points at the beginning of the list * of smb_lkrng structs. */ for(; blr->lock_num < num_locks; blr->lock_num++) { BOOL err; lock_pid = get_lock_pid( data, blr->lock_num, large_file_format); count = get_lock_count( data, blr->lock_num, large_file_format); offset = get_lock_offset( data, blr->lock_num, large_file_format, &err); /* * We know err cannot be set as if it was the lock * request would never have been queued. JRA. */ errno = 0; status = do_lock_spin(fsp,conn,lock_pid,count,offset, ((locktype & 1) ? READ_LOCK : WRITE_LOCK), &my_lock_ctx); if (NT_STATUS_IS_ERR(status)) break; } if(blr->lock_num == num_locks) { /* * Success - we got all the locks. */ DEBUG(3,("process_lockingX file = %s, fnum=%d type=%d num_locks=%d\n", fsp->fsp_name, fsp->fnum, (unsigned int)locktype, num_locks) ); reply_lockingX_success(blr); return True; } else if (!NT_STATUS_EQUAL(status,NT_STATUS_LOCK_NOT_GRANTED) && !NT_STATUS_EQUAL(status,NT_STATUS_FILE_LOCK_CONFLICT)) { /* * We have other than a "can't get lock" * error. Free any locks we had and return an error. * Return True so we get dequeued. */ blocking_lock_reply_error(blr, status); return True; } /* * Still can't get all the locks - keep waiting. */ DEBUG(10,("process_lockingX: only got %d locks of %d needed for file %s, fnum = %d. \ Waiting....\n", blr->lock_num, num_locks, fsp->fsp_name, fsp->fnum)); return False; }