From e8e98c9ea0690e3acf1126b50882e59e1056c7b3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Aug 2001 08:19:43 +0000 Subject: converted smbd to use NTSTATUS by default major changes include: - added NSTATUS type - added automatic mapping between dos and nt error codes - changed all ERROR() calls to ERROR_DOS() and many to ERROR_NT() these calls auto-translate to the client error code system - got rid of the cached error code and the writebmpx code We eventually will need to also: - get rid of BOOL, so we don't lose error info - replace all ERROR_DOS() calls with ERROR_NT() calls but that is too much for one night (This used to be commit 83d9896c1ea8be796192b51a4678c2a3b87f7518) --- source3/locking/brlock.c | 71 +++++++++++++++++++++++++++++++++++++++-------- source3/locking/locking.c | 35 +++++++++-------------- 2 files changed, 73 insertions(+), 33 deletions(-) (limited to 'source3/locking') diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c index dc2f39e7d9..e21effe6eb 100644 --- a/source3/locking/brlock.c +++ b/source3/locking/brlock.c @@ -30,6 +30,8 @@ extern int DEBUGLEVEL; +#define ZERO_ZERO 0 + /* This contains elements that differentiate locks. The smbpid is a client supplied pid, and is essentially the locking context for this client */ @@ -116,6 +118,32 @@ static BOOL brl_conflict(struct lock_struct *lck1, return True; } +#if ZERO_ZERO +static BOOL brl_conflict1(struct lock_struct *lck1, + struct lock_struct *lck2) +{ + if (lck1->lock_type == READ_LOCK && lck2->lock_type == READ_LOCK) { + return False; + } + + if (brl_same_context(&lck1->context, &lck2->context) && + lck2->lock_type == READ_LOCK && lck1->fnum == lck2->fnum) { + return False; + } + + if (lck2->start == 0 && lck2->size == 0 && lck1->size != 0) { + return True; + } + + if (lck1->start >= (lck2->start + lck2->size) || + lck2->start >= (lck1->start + lck1->size)) { + return False; + } + + return True; +} +#endif + /**************************************************************************** Check to see if this lock conflicts, but ignore our own locks on the same fnum only. @@ -231,6 +259,21 @@ void brl_shutdown(int read_only) tdb_close(tdb); } +#if ZERO_ZERO +/**************************************************************************** +compare two locks for sorting +****************************************************************************/ +static int lock_compare(struct lock_struct *lck1, + struct lock_struct *lck2) +{ + if (lck1->start != lck2->start) return (lck1->start - lck2->start); + if (lck2->size != lck1->size) { + return ((int)lck1->size - (int)lck2->size); + } + return 0; +} +#endif + /**************************************************************************** Lock a range of bytes. ****************************************************************************/ @@ -249,10 +292,10 @@ BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, dbuf.dptr = NULL; -#if 0 +#if !ZERO_ZERO if (start == 0 && size == 0) { - tdb_delete(tdb, kbuf); - return True; + DEBUG(0,("client sent 0/0 lock - please report this\n")); + return False; } #endif @@ -275,23 +318,27 @@ BOOL brl_lock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, if (brl_conflict(&locks[i], &lock)) { goto fail; } +#if ZERO_ZERO + if (lock.start == 0 && lock.size == 0 && + locks[i].size == 0) { + break; + } +#endif } } -#if 0 - if (start == 0 && size == 0) { - if (dbuf.dptr) free(dbuf.dptr); - tdb_chainunlock(tdb, kbuf); - return True; - } -#endif - /* no conflicts - add it to the list of locks */ tp = Realloc(dbuf.dptr, dbuf.dsize + sizeof(*locks)); if (!tp) goto fail; else dbuf.dptr = tp; memcpy(dbuf.dptr + dbuf.dsize, &lock, sizeof(lock)); dbuf.dsize += sizeof(lock); + +#if ZERO_ZERO + /* sort the lock list */ + qsort(dbuf.dptr, dbuf.dsize/sizeof(lock), sizeof(lock), lock_compare); +#endif + tdb_store(tdb, kbuf, dbuf, TDB_REPLACE); free(dbuf.dptr); @@ -337,6 +384,7 @@ BOOL brl_unlock(SMB_DEV_T dev, SMB_INO_T ino, int fnum, locks = (struct lock_struct *)dbuf.dptr; count = dbuf.dsize / sizeof(*locks); +#if ZERO_ZERO for (i=0; ican_lock || (fsp->conn != conn)) { - *eclass = ERRDOS; - *ecode = ERRbadfid; - return False; + return NT_STATUS_INVALID_HANDLE; } DEBUG(10,("do_unlock: unlock start=%.0f len=%.0f requested for file %s\n", @@ -183,17 +176,15 @@ BOOL do_unlock(files_struct *fsp,connection_struct *conn, uint16 lock_pid, if (!ok) { DEBUG(10,("do_unlock: returning ERRlock.\n" )); - *eclass = ERRDOS; - *ecode = ERRnotlocked; - return False; + return NT_STATUS_LOCK_NOT_GRANTED; } if (!lp_posix_locking(SNUM(conn))) - return True; + return NT_STATUS_NOPROBLEMO; (void)release_posix_lock(fsp, offset, count); - return True; /* Did unlock */ + return NT_STATUS_NOPROBLEMO; /* Did unlock */ } /**************************************************************************** -- cgit