Exemple #1
0
NTSTATUS query_lock(files_struct *fsp,
			uint16 *psmbpid,
			SMB_BIG_UINT *pcount,
			SMB_BIG_UINT *poffset,
			enum brl_type *plock_type,
			enum brl_flavour lock_flav)
{
	struct byte_range_lock *br_lck = NULL;
	NTSTATUS status = NT_STATUS_LOCK_NOT_GRANTED;

	if (!OPEN_FSP(fsp) || !fsp->can_lock) {
		return NT_STATUS_INVALID_HANDLE;
	}

	if (!lp_locking(SNUM(fsp->conn))) {
		return NT_STATUS_OK;
	}

	br_lck = brl_get_locks(fsp);
	if (!br_lck) {
		return NT_STATUS_NO_MEMORY;
	}

	status = brl_lockquery(br_lck,
			psmbpid,
			procid_self(),
			poffset,
			pcount,
			plock_type,
			lock_flav);

	byte_range_lock_destructor(br_lck);
	return status;
}
Exemple #2
0
BOOL do_unlock(uint16 smbpid,
		files_struct * fsp, struct vfs_connection_struct *conn,
	       SMB_BIG_UINT count, SMB_BIG_UINT offset, uint32 *err)
{
	BOOL ok = False;

	if (!lp_locking(conn->snum))
		return (True);

	if (!OPEN_FSP(fsp) || !fsp->can_lock || (fsp->conn != conn))
	{
		*err = NT_STATUS_NOT_LOCKED;
		return False;
	}

	DEBUG(10,
	      ("do_unlock: unlock start=%.0f len=%.0f requested for file %s\n",
	       (double)offset, (double)count, smbstrA(fsp->fsp_name)));

	/*
	 * Remove the existing lock record from the tdb lockdb
	 * before looking at POSIX locks. If this record doesn't
	 * match then don't bother looking to remove POSIX locks.
	 */

	ok = brl_unlock(fsp->sbuf.st_dev, fsp->sbuf.st_ino, fsp->fnum,
			smbpid, sys_getpid(), conn->snum, offset,
			count);

	if (!ok)
	{
		DEBUG(10, ("do_unlock: returning ERRlock.\n"));
		*err = NT_STATUS_RANGE_NOT_LOCKED;
		return False;
	}

	if (!lp_posix_locking(conn->snum))
		return True;

	(void)release_posix_lock(fsp, offset, count);

	return True;		/* Did unlock */
}
Exemple #3
0
static NTSTATUS do_lock(files_struct *fsp,connection_struct *conn, uint16 lock_pid,
		 SMB_BIG_UINT count,SMB_BIG_UINT offset,enum brl_type lock_type)
{
	NTSTATUS status;

	if (!lp_locking(SNUM(conn)))
		return NT_STATUS_OK;

	/* NOTE! 0 byte long ranges ARE allowed and should be stored  */


	DEBUG(10,("do_lock: lock type %s start=%.0f len=%.0f requested for file %s\n",
		  lock_type_name(lock_type), (double)offset, (double)count, fsp->fsp_name ));

	if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn)) {
		status = brl_lock(fsp->dev, fsp->inode, fsp->fnum,
				  lock_pid, sys_getpid(), conn->cnum,
				  offset, count,
				  lock_type);

		if (NT_STATUS_IS_OK(status) && lp_posix_locking(SNUM(conn))) {

			/*
			 * Try and get a POSIX lock on this range.
			 * Note that this is ok if it is a read lock
			 * overlapping on a different fd. JRA.
			 */

			if (!set_posix_lock(fsp, offset, count, lock_type)) {
				status = NT_STATUS_LOCK_NOT_GRANTED;
				/*
				 * We failed to map - we must now remove the brl
				 * lock entry.
				 */
				(void)brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
								lock_pid, sys_getpid(), conn->cnum,
								offset, count, False);
			}
		}
	}

	return status;
}
Exemple #4
0
NTSTATUS do_lock(files_struct *fsp,
			uint16 lock_pid,
			SMB_BIG_UINT count,
			SMB_BIG_UINT offset,
			enum brl_type lock_type,
			enum brl_flavour lock_flav,
			BOOL *my_lock_ctx)
{
	struct byte_range_lock *br_lck = NULL;
	NTSTATUS status = NT_STATUS_LOCK_NOT_GRANTED;

	if (!OPEN_FSP(fsp) || !fsp->can_lock) {
		return NT_STATUS_INVALID_HANDLE;
	}

	if (!lp_locking(SNUM(fsp->conn))) {
		return NT_STATUS_OK;
	}

	/* NOTE! 0 byte long ranges ARE allowed and should be stored  */

	DEBUG(10,("do_lock: lock flavour %s lock type %s start=%.0f len=%.0f requested for fnum %d file %s\n",
		lock_flav_name(lock_flav), lock_type_name(lock_type),
		(double)offset, (double)count, fsp->fnum, fsp->fsp_name ));

	br_lck = brl_get_locks(fsp);
	if (!br_lck) {
		return NT_STATUS_NO_MEMORY;
	}

	status = brl_lock(br_lck,
			lock_pid,
			procid_self(),
			offset,
			count, 
			lock_type,
			lock_flav,
			my_lock_ctx);

	byte_range_lock_destructor(br_lck);
	return status;
}
Exemple #5
0
NTSTATUS do_unlock(files_struct *fsp,
			uint16 lock_pid,
			SMB_BIG_UINT count,
			SMB_BIG_UINT offset,
			enum brl_flavour lock_flav)
{
	BOOL ok = False;
	struct byte_range_lock *br_lck = NULL;
	
	if (!lp_locking(SNUM(fsp->conn))) {
		return NT_STATUS_OK;
	}
	
	if (!OPEN_FSP(fsp) || !fsp->can_lock) {
		return NT_STATUS_INVALID_HANDLE;
	}
	
	DEBUG(10,("do_unlock: unlock start=%.0f len=%.0f requested for fnum %d file %s\n",
		  (double)offset, (double)count, fsp->fnum, fsp->fsp_name ));

	br_lck = brl_get_locks(fsp);
	if (!br_lck) {
		return NT_STATUS_NO_MEMORY;
	}

	ok = brl_unlock(br_lck,
			lock_pid,
			procid_self(),
			offset,
			count,
			lock_flav);
   
	byte_range_lock_destructor(br_lck);

	if (!ok) {
		DEBUG(10,("do_unlock: returning ERRlock.\n" ));
		return NT_STATUS_RANGE_NOT_LOCKED;
	}

	return NT_STATUS_OK;
}
Exemple #6
0
NTSTATUS do_unlock(files_struct *fsp,connection_struct *conn, uint16 lock_pid,
		   SMB_BIG_UINT count,SMB_BIG_UINT offset)
{
	BOOL ok = False;

	if (!lp_locking(SNUM(conn)))
		return NT_STATUS_OK;

	if (!OPEN_FSP(fsp) || !fsp->can_lock || (fsp->conn != conn)) {
		return NT_STATUS_INVALID_HANDLE;
	}

	DEBUG(10,("do_unlock: unlock start=%.0f len=%.0f requested for file %s\n",
		  (double)offset, (double)count, fsp->fsp_name ));

	/*
	 * Remove the existing lock record from the tdb lockdb
	 * before looking at POSIX locks. If this record doesn't
	 * match then don't bother looking to remove POSIX locks.
	 */

	ok = brl_unlock(fsp->dev, fsp->inode, fsp->fnum,
			lock_pid, sys_getpid(), conn->cnum, offset, count, False);

	if (!ok) {
		DEBUG(10,("do_unlock: returning ERRlock.\n" ));
		return NT_STATUS_RANGE_NOT_LOCKED;
	}

	if (!lp_posix_locking(SNUM(conn)))
		return NT_STATUS_OK;

	(void)release_posix_lock(fsp, offset, count);

	return NT_STATUS_OK;
}
Exemple #7
0
BOOL do_lock(uint16 smbpid,
		files_struct * fsp, struct vfs_connection_struct *conn,
	     SMB_BIG_UINT count, SMB_BIG_UINT offset, enum brl_type lock_type,
	     uint32 *err)
{
	BOOL ok = False;

	if (!lp_locking(conn->snum))
		return (True);

	if (count == 0)
	{
		*err = NT_STATUS_ACCESS_DENIED;
		return False;
	}

	DEBUG(10,
	      ("do_lock: lock type %s start=%.0f len=%.0f requested for file %s\n",
	       lock_type_name(lock_type), (double)offset, (double)count,
	       smbstrA(fsp->fsp_name)));

	if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn))
	{
		ok = brl_lock(fsp->sbuf.st_dev, fsp->sbuf.st_ino, fsp->fnum,
			      smbpid, sys_getpid(), conn->snum,
			      offset, count, lock_type);

		if (ok && lp_posix_locking(conn->snum))
		{

			/*
			 * Try and get a POSIX lock on this range.
			 * Note that this is ok if it is a read lock
			 * overlapping on a different fd. JRA.
			 */

			ok = set_posix_lock(fsp, offset, count, lock_type);

			if (!ok)
			{
				/*
				 * We failed to map - we must now remove the brl
				 * lock entry.
				 */
				
					(void)brl_unlock(fsp->sbuf.st_dev,
							 fsp->sbuf.st_ino,
							 fsp->fnum,
							 smbpid,
							 sys_getpid(),
							 conn->snum, offset,
							 count);
			}
		}
	}

	if (!ok)
	{
		*err = NT_STATUS_LOCK_NOT_GRANTED;
		return False;
	}
	return True;		/* Got lock */
}