summaryrefslogtreecommitdiff
path: root/source3/locking
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-08-14 17:38:29 +0000
committerAndrew Tridgell <tridge@samba.org>1998-08-14 17:38:29 +0000
commitb9623ab59e813131b1ed3f51616a46e719d59c21 (patch)
treea1ba04e55e67ca102b05dd22b024bab9e9d51d57 /source3/locking
parent58fb3c31c03601042fdba71501068fcaea8a821c (diff)
downloadsamba-b9623ab59e813131b1ed3f51616a46e719d59c21.tar.gz
samba-b9623ab59e813131b1ed3f51616a46e719d59c21.tar.bz2
samba-b9623ab59e813131b1ed3f51616a46e719d59c21.zip
this is the bug change to using connection_struct* instead of cnum.
Connections[] is now a local array in server.c I might have broken something with this change. In particular the oplock code is suspect and some .dll files aren't being oplocked when I expected them to be. I'll look at it after I've got some sleep. (This used to be commit c7ee025ead4a85b6fa44a832047b878451845fb6)
Diffstat (limited to 'source3/locking')
-rw-r--r--source3/locking/locking.c87
-rw-r--r--source3/locking/locking_shm.c20
-rw-r--r--source3/locking/locking_slow.c78
-rw-r--r--source3/locking/shmem.c2
4 files changed, 91 insertions, 96 deletions
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index c1c0659496..bb852b07d6 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -33,7 +33,6 @@
#include "includes.h"
extern int DEBUGLEVEL;
-extern connection_struct Connections[];
extern files_struct Files[];
extern int Client;
@@ -147,13 +146,10 @@ static void blocking_lock_reply_error(blocking_lock_record *blr, int eclass, int
uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
uint16 num_locks = SVAL(inbuf,smb_vwv7);
uint32 count, offset;
- int cnum;
int lock_num = blr->lock_num;
char *data;
int i;
- cnum = SVAL(inbuf,smb_tid);
-
data = smb_buf(inbuf) + 10*num_ulocks;
/*
@@ -164,7 +160,7 @@ static void blocking_lock_reply_error(blocking_lock_record *blr, int eclass, int
for(i = blr->lock_num; i >= 0; i--) {
count = IVAL(data,SMB_LKLEN_OFFSET(i));
offset = IVAL(data,SMB_LKOFF_OFFSET(i));
- do_unlock(fnum,cnum,count,offset,&dummy1,&dummy2);
+ do_unlock(fnum,conn,count,offset,&dummy1,&dummy2);
}
construct_reply_common(inbuf, outbuf);
@@ -185,14 +181,11 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr)
uint16 num_ulocks = SVAL(inbuf,smb_vwv6);
uint16 num_locks = SVAL(inbuf,smb_vwv7);
uint32 count, offset;
- int cnum;
int lock_num = blr->lock_num;
char *data;
int eclass=0;
uint32 ecode=0;
- cnum = SVAL(inbuf,smb_tid);
-
data = smb_buf(inbuf) + 10*num_ulocks;
/*
@@ -203,7 +196,7 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr)
for(; blr->lock_num < num_locks; blr->lock_num++) {
count = IVAL(data,SMB_LKLEN_OFFSET(blr->lock_num));
offset = IVAL(data,SMB_LKOFF_OFFSET(blr->lock_num));
- if(!do_lock(fnum,cnum,count,offset, ((locktype & 1) ? F_RDLCK : F_WRLCK),
+ if(!do_lock(fnum,conn,count,offset, ((locktype & 1) ? F_RDLCK : F_WRLCK),
&eclass, &ecode))
break;
}
@@ -214,8 +207,8 @@ static BOOL blocking_lock_record_process(blocking_lock_record *blr)
* Success - we got all the locks.
*/
- DEBUG(3,("blocking_lock_record_process fnum=%d cnum=%d type=%d num_locks=%d\n",
- fnum, cnum, (unsigned int)locktype, num_locks) );
+ DEBUG(3,("blocking_lock_record_process fnum=%d type=%d num_locks=%d\n",
+ fnum, (unsigned int)locktype, num_locks) );
blocking_lock_reply_success(blr);
return True;
@@ -260,7 +253,6 @@ void process_blocking_lock_queue(time_t t)
while(blr != NULL) {
int fnum = GETFNUM(blr->inbuf,smb_vwv2);
- int cnum = SVAL(blr->inbuf,smb_tid);
files_struct *fsp = &Files[fnum];
uint16 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID :
SVAL(blr->inbuf,smb_uid);
@@ -282,7 +274,7 @@ void process_blocking_lock_queue(time_t t)
continue;
}
- if(!become_user(&Connections[cnum],cnum,vuid)) {
+ if(!become_user(conn,vuid)) {
DEBUG(0,("process_blocking_lock_queue: Unable to become user vuid=%d.\n",
vuid ));
/*
@@ -294,9 +286,8 @@ void process_blocking_lock_queue(time_t t)
continue;
}
- if(!become_service(cnum,True)) {
- DEBUG(0,("process_blocking_lock_queue: Unable to become service cnum=%d. \
-Error was %s.\n", cnum, strerror(errno) ));
+ if(!become_service(conn,True)) {
+ DEBUG(0,("process_blocking_lock_queue: Unable to become service Error was %s.\n", strerror(errno) ));
/*
* Remove the entry and return an error to the client.
*/
@@ -365,39 +356,39 @@ static int map_lock_type( files_struct *fsp, int lock_type)
/****************************************************************************
Utility function called to see if a file region is locked.
****************************************************************************/
-
-BOOL is_locked(int fnum,int cnum,uint32 count,uint32 offset, int lock_type)
+BOOL is_locked(int fnum,connection_struct *conn,
+ uint32 count,uint32 offset, int lock_type)
{
- int snum = SNUM(cnum);
- files_struct *fsp = &Files[fnum];
+ int snum = SNUM(conn);
+ files_struct *fsp = &Files[fnum];
- if (count == 0)
- return(False);
+ if (count == 0)
+ return(False);
- if (!lp_locking(snum) || !lp_strict_locking(snum))
- return(False);
-
- /*
- * Note that most UNIX's can *test* for a write lock on
- * a read-only fd, just not *set* a write lock on a read-only
- * fd. So we don't need to use map_lock_type here.
- */
+ if (!lp_locking(snum) || !lp_strict_locking(snum))
+ return(False);
- return(fcntl_lock(fsp->fd_ptr->fd,F_GETLK,offset,count,lock_type));
+ /*
+ * Note that most UNIX's can *test* for a write lock on
+ * a read-only fd, just not *set* a write lock on a read-only
+ * fd. So we don't need to use map_lock_type here.
+ */
+
+ return(fcntl_lock(fsp->fd_ptr->fd,F_GETLK,offset,count,lock_type));
}
/****************************************************************************
Utility function called by locking requests.
****************************************************************************/
-
-BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int lock_type,
+BOOL do_lock(int fnum,connection_struct *conn,
+ uint32 count,uint32 offset,int lock_type,
int *eclass,uint32 *ecode)
{
BOOL ok = False;
files_struct *fsp = &Files[fnum];
- if (!lp_locking(SNUM(cnum)))
+ if (!lp_locking(SNUM(conn)))
return(True);
if (count == 0) {
@@ -406,7 +397,7 @@ BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int lock_type,
return False;
}
- if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->cnum == cnum))
+ if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->conn == conn))
ok = fcntl_lock(fsp->fd_ptr->fd,F_SETLK,offset,count,
map_lock_type(fsp,lock_type));
@@ -422,16 +413,16 @@ BOOL do_lock(int fnum,int cnum,uint32 count,uint32 offset,int lock_type,
/****************************************************************************
Utility function called by unlocking requests.
****************************************************************************/
-
-BOOL do_unlock(int fnum,int cnum,uint32 count,uint32 offset,int *eclass,uint32 *ecode)
+BOOL do_unlock(int fnum,connection_struct *conn,
+ uint32 count,uint32 offset,int *eclass,uint32 *ecode)
{
BOOL ok = False;
files_struct *fsp = &Files[fnum];
- if (!lp_locking(SNUM(cnum)))
+ if (!lp_locking(SNUM(conn)))
return(True);
- if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->cnum == cnum))
+ if (OPEN_FNUM(fnum) && fsp->can_lock && (fsp->conn == conn))
ok = fcntl_lock(fsp->fd_ptr->fd,F_SETLK,offset,count,F_UNLCK);
if (!ok) {
@@ -481,29 +472,29 @@ BOOL locking_end(void)
/*******************************************************************
Lock a hash bucket entry.
******************************************************************/
-
-BOOL lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok)
+BOOL lock_share_entry(connection_struct *conn,
+ uint32 dev, uint32 inode, int *ptok)
{
- return share_ops->lock_entry(cnum, dev, inode, ptok);
+ return share_ops->lock_entry(conn, dev, inode, ptok);
}
/*******************************************************************
Unlock a hash bucket entry.
******************************************************************/
-
-BOOL unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token)
+BOOL unlock_share_entry(connection_struct *conn,
+ uint32 dev, uint32 inode, int token)
{
- return share_ops->unlock_entry(cnum, dev, inode, token);
+ return share_ops->unlock_entry(conn, dev, inode, token);
}
/*******************************************************************
Get all share mode entries for a dev/inode pair.
********************************************************************/
-
-int get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
+int get_share_modes(connection_struct *conn,
+ int token, uint32 dev, uint32 inode,
share_mode_entry **shares)
{
- return share_ops->get_entries(cnum, token, dev, inode, shares);
+ return share_ops->get_entries(conn, token, dev, inode, shares);
}
/*******************************************************************
diff --git a/source3/locking/locking_shm.c b/source3/locking/locking_shm.c
index 43a927e14c..84310d3a33 100644
--- a/source3/locking/locking_shm.c
+++ b/source3/locking/locking_shm.c
@@ -37,7 +37,6 @@
#ifdef FAST_SHARE_MODES
extern int DEBUGLEVEL;
-extern connection_struct Connections[];
extern files_struct Files[];
static struct shmem_ops *shmops;
@@ -79,15 +78,17 @@ static BOOL shm_stop_share_mode_mgmt(void)
/*******************************************************************
lock a hash bucket entry in shared memory for share_mode management
******************************************************************/
-static BOOL shm_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok)
+static BOOL shm_lock_share_entry(connection_struct *conn,
+ uint32 dev, uint32 inode, int *ptok)
{
- return shmops->lock_hash_entry(HASH_ENTRY(dev, inode));
+ return shmops->lock_hash_entry(HASH_ENTRY(dev, inode));
}
/*******************************************************************
unlock a hash bucket entry in shared memory for share_mode management
******************************************************************/
-static BOOL shm_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token)
+static BOOL shm_unlock_share_entry(connection_struct *conn,
+ uint32 dev, uint32 inode, int token)
{
return shmops->unlock_hash_entry(HASH_ENTRY(dev, inode));
}
@@ -95,7 +96,8 @@ static BOOL shm_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token
/*******************************************************************
get all share mode entries in shared memory for a dev/inode pair.
********************************************************************/
-static int shm_get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
+static int shm_get_share_modes(connection_struct *conn,
+ int token, uint32 dev, uint32 inode,
share_mode_entry **old_shares)
{
int *mode_array;
@@ -426,7 +428,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
/* We must create a share_mode_record */
share_mode_record *new_mode_p = NULL;
int new_offset = shmops->shm_alloc(sizeof(share_mode_record) +
- strlen(fs_p->name) + 1);
+ strlen(fs_p->fsp_name) + 1);
if(new_offset == 0) {
DEBUG(0,("ERROR:set_share_mode shmops->shm_alloc fail!\n"));
return False;
@@ -437,7 +439,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
new_mode_p->st_ino = inode;
new_mode_p->num_share_mode_entries = 0;
new_mode_p->share_mode_entries = 0;
- pstrcpy(new_mode_p->file_name, fs_p->name);
+ pstrcpy(new_mode_p->file_name, fs_p->fsp_name);
/* Chain onto the start of the hash chain (in the hope we will be used first). */
new_mode_p->next_offset = mode_array[hash_entry];
@@ -446,7 +448,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
file_scanner_p = new_mode_p;
DEBUG(3,("set_share_mode: Created share record for %s (dev %d inode %d)\n",
- fs_p->name, dev, inode));
+ fs_p->fsp_name, dev, inode));
}
/* Now create the share mode entry */
@@ -485,7 +487,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
file_scanner_p->num_share_mode_entries += 1;
DEBUG(3,("set_share_mode: Created share entry for %s with mode 0x%X pid=%d\n",
- fs_p->name, fs_p->share_mode, new_entry_p->e.pid));
+ fs_p->fsp_name, fs_p->share_mode, new_entry_p->e.pid));
return(True);
}
diff --git a/source3/locking/locking_slow.c b/source3/locking/locking_slow.c
index 1f8f962ac9..9135ae29d2 100644
--- a/source3/locking/locking_slow.c
+++ b/source3/locking/locking_slow.c
@@ -37,7 +37,6 @@
#ifndef FAST_SHARE_MODES
extern int DEBUGLEVEL;
-extern connection_struct Connections[];
extern files_struct Files[];
/*
@@ -82,23 +81,24 @@ static BOOL slow_stop_share_mode_mgmt(void)
/*******************************************************************
name a share file
******************************************************************/
-static BOOL share_name(int cnum, uint32 dev, uint32 inode, char *name)
+static BOOL share_name(connection_struct *conn,
+ uint32 dev, uint32 inode, char *name)
{
- int len;
- pstrcpy(name,lp_lockdir());
- trim_string(name,"","/");
- if (!*name) return(False);
- len = strlen(name);
- name += len;
-
- slprintf(name, sizeof(pstring) - len - 1, "/share.%u.%u",dev,inode);
- return(True);
+ int len;
+ pstrcpy(name,lp_lockdir());
+ trim_string(name,"","/");
+ if (!*name) return(False);
+ len = strlen(name);
+ name += len;
+
+ slprintf(name, sizeof(pstring) - len - 1, "/share.%u.%u",dev,inode);
+ return(True);
}
/*******************************************************************
Force a share file to be deleted.
********************************************************************/
-static int delete_share_file( int cnum, char *fname )
+static int delete_share_file(connection_struct *conn, char *fname )
{
if (read_only) return -1;
@@ -124,7 +124,8 @@ static int delete_share_file( int cnum, char *fname )
/*******************************************************************
lock a share mode file.
******************************************************************/
-static BOOL slow_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok)
+static BOOL slow_lock_share_entry(connection_struct *conn,
+ uint32 dev, uint32 inode, int *ptok)
{
pstring fname;
int fd;
@@ -132,7 +133,7 @@ static BOOL slow_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok)
*ptok = (int)-1;
- if(!share_name(cnum, dev, inode, fname))
+ if(!share_name(conn, dev, inode, fname))
return False;
if (read_only) return True;
@@ -216,7 +217,8 @@ static BOOL slow_lock_share_entry(int cnum, uint32 dev, uint32 inode, int *ptok)
/*******************************************************************
unlock a share mode file.
******************************************************************/
-static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int token)
+static BOOL slow_unlock_share_entry(connection_struct *conn,
+ uint32 dev, uint32 inode, int token)
{
int fd = (int)token;
int ret = True;
@@ -228,7 +230,7 @@ static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int toke
/* Fix for zero length share files from
Gerald Werner <wernerg@mfldclin.edu> */
- share_name(cnum, dev, inode, fname);
+ share_name(conn, dev, inode, fname);
/* get the share mode file size */
if(fstat((int)token, &sb) != 0)
@@ -246,7 +248,7 @@ static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int toke
/* remove the share file if zero length */
if(sb.st_size == 0)
- delete_share_file(cnum, fname);
+ delete_share_file(conn, fname);
/* token is the fd of the open share mode file. */
/* Unlock the first byte. */
@@ -264,7 +266,7 @@ static BOOL slow_unlock_share_entry(int cnum, uint32 dev, uint32 inode, int toke
/*******************************************************************
Read a share file into a buffer.
********************************************************************/
-static int read_share_file(int cnum, int fd, char *fname, char **out, BOOL *p_new_file)
+static int read_share_file(connection_struct *conn, int fd, char *fname, char **out, BOOL *p_new_file)
{
struct stat sb;
char *buf;
@@ -317,7 +319,7 @@ locking version (was %d, should be %d).\n",fname,
IVAL(buf,SMF_VERSION_OFFSET), LOCKING_VERSION));
if(buf)
free(buf);
- delete_share_file(cnum, fname);
+ delete_share_file(conn, fname);
return -1;
}
@@ -335,7 +337,7 @@ locking version (was %d, should be %d).\n",fname,
deleting it.\n", fname));
if(buf)
free(buf);
- delete_share_file(cnum, fname);
+ delete_share_file(conn, fname);
return -1;
}
@@ -346,7 +348,7 @@ deleting it.\n", fname));
/*******************************************************************
get all share mode entries in a share file for a dev/inode pair.
********************************************************************/
-static int slow_get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
+static int slow_get_share_modes(connection_struct *conn, int token, uint32 dev, uint32 inode,
share_mode_entry **old_shares)
{
int fd = (int)token;
@@ -377,9 +379,9 @@ static int slow_get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
16 - oplock port (if oplocks in use) - 2 bytes.
*/
- share_name(cnum, dev, inode, fname);
+ share_name(conn, dev, inode, fname);
- if(read_share_file( cnum, fd, fname, &buf, &new_file) != 0)
+ if(read_share_file( conn, fd, fname, &buf, &new_file) != 0)
{
DEBUG(0,("ERROR: get_share_modes: Failed to read share file %s\n",
fname));
@@ -419,7 +421,7 @@ for share file %d\n", num_entries, fname));
fname));
if(buf)
free(buf);
- delete_share_file(cnum, fname);
+ delete_share_file(conn, fname);
return 0;
}
@@ -460,7 +462,7 @@ it left a share mode entry with mode 0x%X in share file %s\n",
*old_shares = 0;
if(buf)
free(buf);
- delete_share_file(cnum, fname);
+ delete_share_file(conn, fname);
return 0;
}
@@ -546,10 +548,10 @@ static void slow_del_share_mode(int token, int fnum)
BOOL deleted = False;
BOOL new_file;
- share_name(fs_p->cnum, fs_p->fd_ptr->dev,
+ share_name(fs_p->conn, fs_p->fd_ptr->dev,
fs_p->fd_ptr->inode, fname);
- if(read_share_file( fs_p->cnum, fd, fname, &buf, &new_file) != 0)
+ if(read_share_file( fs_p->conn, fd, fname, &buf, &new_file) != 0)
{
DEBUG(0,("ERROR: del_share_mode: Failed to read share file %s\n",
fname));
@@ -560,7 +562,7 @@ static void slow_del_share_mode(int token, int fnum)
{
DEBUG(0,("ERROR:del_share_mode: share file %s is new (size zero), deleting it.\n",
fname));
- delete_share_file(fs_p->cnum, fname);
+ delete_share_file(fs_p->conn, fname);
return;
}
@@ -584,7 +586,7 @@ for share file %d\n", num_entries, fname));
fname));
if(buf)
free(buf);
- delete_share_file(fs_p->cnum, fname);
+ delete_share_file(fs_p->conn, fname);
return;
}
@@ -635,7 +637,7 @@ for share file %d\n", num_entries, fname));
fname));
if(buf)
free(buf);
- delete_share_file(fs_p->cnum,fname);
+ delete_share_file(fs_p->conn,fname);
return;
}
@@ -685,7 +687,7 @@ static BOOL slow_set_share_mode(int token,int fnum, uint16 port, uint16 op_type)
int header_size;
char *p;
- share_name(fs_p->cnum, fs_p->fd_ptr->dev,
+ share_name(fs_p->conn, fs_p->fd_ptr->dev,
fs_p->fd_ptr->inode, fname);
if(fstat(fd, &sb) != 0)
@@ -733,7 +735,7 @@ locking version (was %d, should be %d).\n",fname, IVAL(buf,SMF_VERSION_OFFSET),
LOCKING_VERSION));
if(buf)
free(buf);
- delete_share_file(fs_p->cnum, fname);
+ delete_share_file(fs_p->conn, fname);
return False;
}
@@ -746,7 +748,7 @@ locking version (was %d, should be %d).\n",fname, IVAL(buf,SMF_VERSION_OFFSET),
deleting it.\n", fname));
if(buf)
free(buf);
- delete_share_file(fs_p->cnum, fname);
+ delete_share_file(fs_p->conn, fname);
return False;
}
@@ -794,7 +796,7 @@ deleting it.\n", fname));
{
DEBUG(2,("ERROR: set_share_mode: Failed to write share file %s - \
deleting it (%s).\n",fname, strerror(errno)));
- delete_share_file(fs_p->cnum, fname);
+ delete_share_file(fs_p->conn, fname);
if(buf)
free(buf);
return False;
@@ -838,10 +840,10 @@ static BOOL slow_remove_share_oplock(int fnum, int token)
BOOL found = False;
BOOL new_file;
- share_name(fs_p->cnum, fs_p->fd_ptr->dev,
+ share_name(fs_p->conn, fs_p->fd_ptr->dev,
fs_p->fd_ptr->inode, fname);
- if(read_share_file( fs_p->cnum, fd, fname, &buf, &new_file) != 0)
+ if(read_share_file( fs_p->conn, fd, fname, &buf, &new_file) != 0)
{
DEBUG(0,("ERROR: remove_share_oplock: Failed to read share file %s\n",
fname));
@@ -852,7 +854,7 @@ static BOOL slow_remove_share_oplock(int fnum, int token)
{
DEBUG(0,("ERROR: remove_share_oplock: share file %s is new (size zero), \
deleting it.\n", fname));
- delete_share_file(fs_p->cnum, fname);
+ delete_share_file(fs_p->conn, fname);
return False;
}
@@ -876,7 +878,7 @@ for share file %d\n", num_entries, fname));
fname));
if(buf)
free(buf);
- delete_share_file(fs_p->cnum, fname);
+ delete_share_file(fs_p->conn, fname);
return False;
}
diff --git a/source3/locking/shmem.c b/source3/locking/shmem.c
index 48f78d2a5b..dd97d5c76c 100644
--- a/source3/locking/shmem.c
+++ b/source3/locking/shmem.c
@@ -128,7 +128,7 @@ static BOOL smb_shm_global_unlock(void)
if(smb_shm_times_locked == 0)
{
- DEBUG(0,("ERROR smb_shm_global_unlock : shmem not locked\n",smb_shm_fd));
+ DEBUG(0,("ERROR smb_shm_global_unlock : shmem not locked\n"));
return False;
}