summaryrefslogtreecommitdiff
path: root/source/locking
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1999-12-13 13:27:58 +0000
committerAndrew Tridgell <tridge@samba.org>1999-12-13 13:27:58 +0000
commit453a822a76780063dff23526c35408866d0c0154 (patch)
tree804feffcd5e60153e27d3ca2b007021e66e5bd0a /source/locking
parent054195df9b6187c663ede5cf4489499abbdc29fc (diff)
downloadsamba-453a822a76780063dff23526c35408866d0c0154.tar.gz
first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
Diffstat (limited to 'source/locking')
-rw-r--r--source/locking/locking.c84
-rw-r--r--source/locking/locking_shm.c25
-rw-r--r--source/locking/locking_slow.c102
-rw-r--r--source/locking/shmem.c2
-rw-r--r--source/locking/shmem_sysv.c28
5 files changed, 169 insertions, 72 deletions
diff --git a/source/locking/locking.c b/source/locking/locking.c
index fdc39d00407..012d954e501 100644
--- a/source/locking/locking.c
+++ b/source/locking/locking.c
@@ -87,8 +87,7 @@ BOOL is_locked(files_struct *fsp,connection_struct *conn,
* fd. So we don't need to use map_lock_type here.
*/
- return(conn->vfs_ops.lock(fsp->fd_ptr->fd,SMB_F_GETLK,offset,count,
- lock_type));
+ return(fcntl_lock(fsp->fd_ptr->fd,SMB_F_GETLK,offset,count,lock_type));
}
@@ -114,8 +113,8 @@ BOOL do_lock(files_struct *fsp,connection_struct *conn,
lock_type, (double)offset, (double)count, fsp->fsp_name ));
if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn))
- ok = conn->vfs_ops.lock(fsp->fd_ptr->fd,SMB_F_SETLK,offset,count,
- map_lock_type(fsp,lock_type));
+ ok = fcntl_lock(fsp->fd_ptr->fd,SMB_F_SETLK,offset,count,
+ map_lock_type(fsp,lock_type));
if (!ok) {
*eclass = ERRDOS;
@@ -141,7 +140,7 @@ BOOL do_unlock(files_struct *fsp,connection_struct *conn,
(double)offset, (double)count, fsp->fsp_name ));
if (OPEN_FSP(fsp) && fsp->can_lock && (fsp->conn == conn))
- ok = conn->vfs_ops.lock(fsp->fd_ptr->fd,SMB_F_SETLK,offset,count,F_UNLCK);
+ ok = fcntl_lock(fsp->fd_ptr->fd,SMB_F_SETLK,offset,count,F_UNLCK);
if (!ok) {
*eclass = ERRDOS;
@@ -157,21 +156,26 @@ BOOL do_unlock(files_struct *fsp,connection_struct *conn,
BOOL locking_init(int read_only)
{
- if (share_ops)
- return True;
+ if (share_ops)
+ return True;
#ifdef FAST_SHARE_MODES
- share_ops = locking_shm_init(read_only);
+ share_ops = locking_shm_init(read_only);
+ if (!share_ops && read_only && (getuid() == 0)) {
+ /* this may be the first time the share modes code has
+ been run. Initialise it now by running it read-write */
+ share_ops = locking_shm_init(0);
+ }
#else
- share_ops = locking_slow_init(read_only);
+ share_ops = locking_slow_init(read_only);
#endif
- if (!share_ops) {
- DEBUG(0,("ERROR: Failed to initialise share modes!\n"));
- return False;
- }
+ if (!share_ops) {
+ DEBUG(0,("ERROR: Failed to initialise share modes\n"));
+ return False;
+ }
- return True;
+ return True;
}
/*******************************************************************
@@ -242,7 +246,7 @@ static void remove_share_oplock_fn(share_mode_entry *entry, SMB_DEV_T dev, SMB_I
(unsigned int)dev, (double)inode ));
/* Delete the oplock info. */
entry->op_port = 0;
- entry->op_type = 0;
+ entry->op_type = NO_OPLOCK;
}
/*******************************************************************
@@ -259,14 +263,45 @@ BOOL remove_share_oplock(int token, files_struct *fsp)
below.
********************************************************************/
+static void downgrade_share_oplock_fn(share_mode_entry *entry, SMB_DEV_T dev, SMB_INO_T inode,
+ void *param)
+{
+ DEBUG(10,("downgrade_share_oplock_fn: downgrading oplock info for entry dev=%x ino=%.0f\n",
+ (unsigned int)dev, (double)inode ));
+ entry->op_type = LEVEL_II_OPLOCK;
+}
+
+/*******************************************************************
+ Downgrade a oplock type from exclusive to level II.
+********************************************************************/
+
+BOOL downgrade_share_oplock(int token, files_struct *fsp)
+{
+ return share_ops->mod_entry(token, fsp, downgrade_share_oplock_fn, NULL);
+}
+
+/*******************************************************************
+ Static function that actually does the work for the generic function
+ below.
+********************************************************************/
+
+struct mod_val {
+ int new_share_mode;
+ uint16 new_oplock;
+};
+
static void modify_share_mode_fn(share_mode_entry *entry, SMB_DEV_T dev, SMB_INO_T inode,
void *param)
{
- int new_share_mode = *(int *)param;
- DEBUG(10,("modify_share_mode_fn: changing share mode info from %x to %x for entry dev=%x ino=%.0f\n",
- entry->share_mode, new_share_mode, (unsigned int)dev, (double)inode ));
- /* Change the share mode info. */
- entry->share_mode = new_share_mode;
+ struct mod_val *mvp = (struct mod_val *)param;
+
+ DEBUG(10,("modify_share_mode_fn: changing share mode info from %x to %x for entry dev=%x ino=%.0f\n",
+ entry->share_mode, mvp->new_share_mode, (unsigned int)dev, (double)inode ));
+ DEBUG(10,("modify_share_mode_fn: changing oplock state from %x to %x for entry dev=%x ino=%.0f\n",
+ entry->op_type, (int)mvp->new_oplock, (unsigned int)dev, (double)inode ));
+ /* Change the share mode info. */
+ entry->share_mode = mvp->new_share_mode;
+ entry->op_type = mvp->new_oplock;
}
/*******************************************************************
@@ -274,9 +309,14 @@ static void modify_share_mode_fn(share_mode_entry *entry, SMB_DEV_T dev, SMB_INO
Return False on fail, True on success.
********************************************************************/
-BOOL modify_share_mode(int token, files_struct *fsp, int new_mode)
+BOOL modify_share_mode(int token, files_struct *fsp, int new_mode, uint16 new_oplock)
{
- return share_ops->mod_entry(token, fsp, modify_share_mode_fn, (void *)&new_mode);
+ struct mod_val mv;
+
+ mv.new_share_mode = new_mode;
+ mv.new_oplock = new_oplock;
+
+ return share_ops->mod_entry(token, fsp, modify_share_mode_fn, (void *)&mv);
}
/*******************************************************************
diff --git a/source/locking/locking_shm.c b/source/locking/locking_shm.c
index 375a8b7f109..174ad73e977 100644
--- a/source/locking/locking_shm.c
+++ b/source/locking/locking_shm.c
@@ -80,6 +80,7 @@ static BOOL shm_stop_share_mode_mgmt(void)
static BOOL shm_lock_share_entry(connection_struct *conn,
SMB_DEV_T dev, SMB_INO_T inode, int *ptok)
{
+ *ptok = 0; /* For purify... */
return shmops->lock_hash_entry(HASH_ENTRY(dev, inode));
}
@@ -165,7 +166,7 @@ static int shm_get_share_modes(connection_struct *conn,
malloc(num_entries * sizeof(share_mode_entry));
if(*old_shares == 0)
{
- DEBUG(0,("get_share_modes: malloc fail!\n"));
+ DEBUG(0,("get_share_modes: malloc fail for size 0x%x!\n", (unsigned int)(num_entries * sizeof(share_mode_entry))));
return 0;
}
}
@@ -177,7 +178,7 @@ static int shm_get_share_modes(connection_struct *conn,
entry_prev_p = entry_scanner_p;
while(entry_scanner_p)
{
- int pid = entry_scanner_p->e.pid;
+ pid_t pid = entry_scanner_p->e.pid;
if (pid && !process_exists(pid))
{
@@ -209,7 +210,7 @@ static int shm_get_share_modes(connection_struct *conn,
return 0;
}
- DEBUG(0,("get_share_modes: process %d no longer exists\n", pid));
+ DEBUG(0,("get_share_modes: process %d no longer exists\n", (int)pid));
shmops->shm_free(shmops->addr2offset(delete_entry_p));
}
@@ -226,7 +227,7 @@ static int shm_get_share_modes(connection_struct *conn,
sizeof(struct timeval));
num_entries_copied++;
DEBUG(5,("get_share_modes Read share mode 0x%X pid=%d\n",
- entry_scanner_p->e.share_mode, entry_scanner_p->e.pid));
+ entry_scanner_p->e.share_mode, (int)entry_scanner_p->e.pid));
entry_prev_p = entry_scanner_p;
entry_scanner_p = (shm_share_mode_entry *)
shmops->offset2addr(entry_scanner_p->next_share_mode_entry);
@@ -270,7 +271,7 @@ static void shm_del_share_mode(int token, files_struct *fsp)
shm_share_mode_entry *entry_scanner_p;
shm_share_mode_entry *entry_prev_p;
BOOL found = False;
- int pid = getpid();
+ pid_t pid = getpid();
dev = fsp->fd_ptr->dev;
inode = fsp->fd_ptr->inode;
@@ -430,7 +431,7 @@ static BOOL shm_set_share_mode(int token, files_struct *fsp, uint16 port, uint16
/* 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(fsp->fsp_name) + 1);
+ strlen(fsp->fsp_name) + strlen(fsp->conn->connectpath) + 2);
if(new_offset == 0) {
DEBUG(0,("ERROR:set_share_mode shmops->shm_alloc fail!\n"));
return False;
@@ -441,7 +442,9 @@ static BOOL shm_set_share_mode(int token, files_struct *fsp, uint16 port, uint16
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, fsp->fsp_name);
+ pstrcpy(new_mode_p->file_name, fsp->conn->connectpath);
+ pstrcat(new_mode_p->file_name, "/");
+ pstrcat(new_mode_p->file_name, fsp->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];
@@ -489,7 +492,7 @@ static BOOL shm_set_share_mode(int token, files_struct *fsp, uint16 port, uint16
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",
- fsp->fsp_name, fsp->share_mode, new_entry_p->e.pid));
+ fsp->fsp_name, fsp->share_mode, (int)new_entry_p->e.pid));
return(True);
}
@@ -510,7 +513,7 @@ static BOOL shm_mod_share_entry(int token, files_struct *fsp,
share_mode_record *file_prev_p;
shm_share_mode_entry *entry_scanner_p;
BOOL found = False;
- int pid = getpid();
+ pid_t pid = getpid();
dev = fsp->fd_ptr->dev;
inode = fsp->fd_ptr->inode;
@@ -689,12 +692,12 @@ struct share_ops *locking_shm_init(int ronly)
{
read_only = ronly;
-#ifdef HAVE_SYSV_IPC
+#ifdef USE_SYSV_IPC
shmops = sysv_shm_open(read_only);
if (shmops) return &share_ops;
#endif
-#ifdef HAVE_SHARED_MMAP
+#ifdef USE_SHARED_MMAP
shmops = smb_shm_open(read_only);
if (shmops) return &share_ops;
#endif
diff --git a/source/locking/locking_slow.c b/source/locking/locking_slow.c
index 64bedca4ad2..58673d27079 100644
--- a/source/locking/locking_slow.c
+++ b/source/locking/locking_slow.c
@@ -118,7 +118,7 @@ static int delete_share_file(connection_struct *conn, char *fname )
DEBUG(5,("delete_share_file: Deleted share file %s\n", fname));
}
- /* return to our previous privilage level */
+ /* return to our previous privilege level */
unbecome_root(False);
return 0;
@@ -177,7 +177,7 @@ static BOOL slow_lock_share_entry(connection_struct *conn,
/* At this point we have an open fd to the share mode file.
Lock the first byte exclusively to signify a lock. */
- if(conn->vfs_ops.lock(fd, SMB_F_SETLKW, 0, 1, F_WRLCK) == False)
+ if(fcntl_lock(fd, SMB_F_SETLKW, 0, 1, F_WRLCK) == False)
{
DEBUG(0,("ERROR lock_share_entry: fcntl_lock on file %s failed with %s\n",
fname, strerror(errno)));
@@ -210,7 +210,7 @@ static BOOL slow_lock_share_entry(connection_struct *conn,
*ptok = (int)fd;
- /* return to our previous privilage level */
+ /* return to our previous privilege level */
unbecome_root(False);
return ret;
@@ -254,7 +254,7 @@ static BOOL slow_unlock_share_entry(connection_struct *conn,
/* token is the fd of the open share mode file. */
/* Unlock the first byte. */
- if(conn->vfs_ops.lock(fd, SMB_F_SETLKW, 0, 1, F_UNLCK) == False)
+ if(fcntl_lock(fd, SMB_F_SETLKW, 0, 1, F_UNLCK) == False)
{
DEBUG(0,("ERROR unlock_share_entry: fcntl_lock failed with %s\n",
strerror(errno)));
@@ -434,16 +434,16 @@ for share file %s\n", num_entries, fname));
for( i = 0; i < num_entries; i++)
{
- int pid;
+ pid_t pid;
char *p = base + (i*SMF_ENTRY_LENGTH);
- pid = IVAL(p,SME_PID_OFFSET);
+ pid = (pid_t)IVAL(p,SME_PID_OFFSET);
if(!process_exists(pid))
{
DEBUG(0,("get_share_modes: process %d no longer exists and \
it left a share mode entry with mode 0x%X in share file %s\n",
- pid, IVAL(p,SME_SHAREMODE_OFFSET), fname));
+ (int)pid, IVAL(p,SME_SHAREMODE_OFFSET), fname));
continue;
}
share_array[num_entries_copied].time.tv_sec = IVAL(p,SME_SEC_OFFSET);
@@ -492,7 +492,7 @@ position 0 for share mode file %s (%s)\n", fname, strerror(errno)));
{
char *p = base + (i*SMF_ENTRY_LENGTH);
- SIVAL(p,SME_PID_OFFSET,share_array[i].pid);
+ SIVAL(p,SME_PID_OFFSET,(uint32)share_array[i].pid);
SIVAL(p,SME_SHAREMODE_OFFSET,share_array[i].share_mode);
SIVAL(p,SME_SEC_OFFSET,share_array[i].time.tv_sec);
SIVAL(p,SME_USEC_OFFSET,share_array[i].time.tv_usec);
@@ -513,8 +513,18 @@ mode file %s (%s)\n", fname, strerror(errno)));
return 0;
}
/* Now truncate the file at this point. */
+#ifdef FTRUNCATE_NEEDS_ROOT
+ become_root(False);
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
if(sys_ftruncate(fd, (SMB_OFF_T)newsize)!= 0)
{
+#ifdef FTRUNCATE_NEEDS_ROOT
+ int saved_errno = errno;
+ unbecome_root(False);
+ errno = saved_errno;
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
DEBUG(0,("ERROR: get_share_modes: failed to ftruncate share \
mode file %s to size %d (%s)\n", fname, newsize, strerror(errno)));
if(*old_shares)
@@ -526,6 +536,10 @@ mode file %s to size %d (%s)\n", fname, newsize, strerror(errno)));
}
}
+#ifdef FTRUNCATE_NEEDS_ROOT
+ unbecome_root(False);
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
if(buf)
free(buf);
@@ -547,7 +561,7 @@ static void slow_del_share_mode(int token, files_struct *fsp)
int num_entries;
int newsize;
int i;
- int pid;
+ pid_t pid;
BOOL deleted = False;
BOOL new_file;
@@ -608,7 +622,7 @@ for share file %s\n", num_entries, fname));
if((IVAL(p,SME_SEC_OFFSET) != fsp->open_time.tv_sec) ||
(IVAL(p,SME_USEC_OFFSET) != fsp->open_time.tv_usec) ||
(IVAL(p,SME_SHAREMODE_OFFSET) != fsp->share_mode) ||
- (IVAL(p,SME_PID_OFFSET) != pid))
+ (((pid_t)IVAL(p,SME_PID_OFFSET)) != pid))
continue;
DEBUG(5,("del_share_mode: deleting entry number %d (of %d) from the share file %s\n",
@@ -665,14 +679,30 @@ mode file %s (%s)\n", fname, strerror(errno)));
}
/* Now truncate the file at this point. */
+#ifdef FTRUNCATE_NEEDS_ROOT
+ become_root(False);
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
if(sys_ftruncate(fd, (SMB_OFF_T)newsize) != 0)
{
+#ifdef FTRUNCATE_NEEDS_ROOT
+ int saved_errno = errno;
+ unbecome_root(False);
+ errno = saved_errno;
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
+
DEBUG(0,("ERROR: del_share_mode: failed to ftruncate share \
mode file %s to size %d (%s)\n", fname, newsize, strerror(errno)));
if(buf)
free(buf);
return;
}
+
+#ifdef FTRUNCATE_NEEDS_ROOT
+ unbecome_root(False);
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
}
/*******************************************************************
@@ -682,7 +712,7 @@ static BOOL slow_set_share_mode(int token,files_struct *fsp, uint16 port, uint16
{
pstring fname;
int fd = (int)token;
- int pid = (int)getpid();
+ pid_t pid = getpid();
SMB_STRUCT_STAT sb;
char *buf;
int num_entries;
@@ -692,7 +722,7 @@ static BOOL slow_set_share_mode(int token,files_struct *fsp, uint16 port, uint16
share_name(fsp->conn, fsp->fd_ptr->dev,
fsp->fd_ptr->inode, fname);
- if(fsp->conn->vfs_ops.fstat_file(fd, &sb) != 0)
+ if(sys_fstat(fd, &sb) != 0)
{
DEBUG(0,("ERROR: set_share_mode: Failed to do stat on share file %s\n",
fname));
@@ -759,15 +789,17 @@ deleting it.\n", fname));
{
/* New file - just use a single_entry. */
if((buf = (char *)malloc(SMF_HEADER_LENGTH +
- strlen(fsp->fsp_name) + 1 + SMF_ENTRY_LENGTH)) == NULL)
+ strlen(fsp->fsp_name) + strlen(fsp->conn->connectpath) + 2 + SMF_ENTRY_LENGTH)) == NULL)
{
DEBUG(0,("ERROR: set_share_mode: malloc failed for single entry.\n"));
return False;
}
SIVAL(buf,SMF_VERSION_OFFSET,LOCKING_VERSION);
SIVAL(buf,SMF_NUM_ENTRIES_OFFSET,0);
- SSVAL(buf,SMF_FILENAME_LEN_OFFSET,strlen(fsp->fsp_name) + 1);
- pstrcpy(buf + SMF_HEADER_LENGTH, fsp->fsp_name);
+ SSVAL(buf,SMF_FILENAME_LEN_OFFSET,strlen(fsp->fsp_name) + strlen(fsp->conn->connectpath) + 2);
+ pstrcpy(buf + SMF_HEADER_LENGTH, fsp->conn->connectpath);
+ pstrcat(buf + SMF_HEADER_LENGTH, "/");
+ pstrcat(buf + SMF_HEADER_LENGTH, fsp->fsp_name);
}
num_entries = IVAL(buf,SMF_NUM_ENTRIES_OFFSET);
@@ -776,7 +808,7 @@ deleting it.\n", fname));
SIVAL(p,SME_SEC_OFFSET,fsp->open_time.tv_sec);
SIVAL(p,SME_USEC_OFFSET,fsp->open_time.tv_usec);
SIVAL(p,SME_SHAREMODE_OFFSET,fsp->share_mode);
- SIVAL(p,SME_PID_OFFSET,pid);
+ SIVAL(p,SME_PID_OFFSET,(uint32)pid);
SSVAL(p,SME_PORT_OFFSET,port);
SSVAL(p,SME_OPLOCK_TYPE_OFFSET,op_type);
@@ -806,8 +838,19 @@ deleting it (%s).\n",fname, strerror(errno)));
/* Now truncate the file at this point - just for safety. */
+#ifdef FTRUNCATE_NEEDS_ROOT
+ become_root(False);
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
if(sys_ftruncate(fd, (SMB_OFF_T)(header_size + (SMF_ENTRY_LENGTH*num_entries)))!= 0)
{
+
+#ifdef FTRUNCATE_NEEDS_ROOT
+ int saved_errno = errno;
+ unbecome_root(False);
+ errno = saved_errno;
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
DEBUG(0,("ERROR: set_share_mode: failed to ftruncate share \
mode file %s to size %d (%s)\n", fname, header_size + (SMF_ENTRY_LENGTH*num_entries),
strerror(errno)));
@@ -816,11 +859,15 @@ mode file %s to size %d (%s)\n", fname, header_size + (SMF_ENTRY_LENGTH*num_entr
return False;
}
+#ifdef FTRUNCATE_NEEDS_ROOT
+ unbecome_root(False);
+#endif /* FTRUNCATE_NEEDS_ROOT */
+
if(buf)
free(buf);
DEBUG(3,("set_share_mode: Created share file %s with \
-mode 0x%X pid=%d\n",fname,fsp->share_mode,pid));
+mode 0x%X pid=%d\n",fname,fsp->share_mode,(int)pid));
return True;
}
@@ -840,7 +887,7 @@ static BOOL slow_mod_share_entry(int token, files_struct *fsp,
int num_entries;
int fsize;
int i;
- int pid;
+ pid_t pid;
BOOL found = False;
BOOL new_file;
share_mode_entry entry;
@@ -898,7 +945,7 @@ for share file %s\n", num_entries, fname));
if((IVAL(p,SME_SEC_OFFSET) != fsp->open_time.tv_sec) ||
(IVAL(p,SME_USEC_OFFSET) != fsp->open_time.tv_usec) ||
(IVAL(p,SME_SHAREMODE_OFFSET) != fsp->share_mode) ||
- (IVAL(p,SME_PID_OFFSET) != pid))
+ (((pid_t)IVAL(p,SME_PID_OFFSET)) != pid))
continue;
DEBUG(5,("slow_mod_share_entry: Calling generic function to modify entry number %d (of %d) \
@@ -909,12 +956,12 @@ from the share file %s\n", i, num_entries, fname));
* the generic function with the given parameter.
*/
- entry.pid = IVAL(p,SME_PID_OFFSET);
+ entry.pid = (pid_t)IVAL(p,SME_PID_OFFSET);
entry.op_port = SVAL(p,SME_PORT_OFFSET);
entry.op_type = SVAL(p,SME_OPLOCK_TYPE_OFFSET);
entry.share_mode = IVAL(p,SME_SHAREMODE_OFFSET);
- entry.time.tv_sec = IVAL(p,SME_SEC_OFFSET)
- entry.time.tv_sec = IVAL(p,SME_USEC_OFFSET);
+ entry.time.tv_sec = IVAL(p,SME_SEC_OFFSET);
+ entry.time.tv_usec = IVAL(p,SME_USEC_OFFSET);
(*mod_fn)( &entry, fsp->fd_ptr->dev, fsp->fd_ptr->inode, param);
@@ -922,12 +969,12 @@ from the share file %s\n", i, num_entries, fname));
* Now copy any changes the function made back into the buffer.
*/
- SIVAL(p,SME_PID_OFFSET, entry.pid)
+ SIVAL(p,SME_PID_OFFSET, (uint32)entry.pid);
SSVAL(p,SME_PORT_OFFSET,entry.op_port);
SSVAL(p,SME_OPLOCK_TYPE_OFFSET,entry.op_type);
SIVAL(p,SME_SHAREMODE_OFFSET,entry.share_mode);
- SIVAL(p,SME_SEC_OFFSET,entry.time.tv_sec)
- SIVAL(p,SME_USEC_OFFSET,entry.time.tv_sec);
+ SIVAL(p,SME_SEC_OFFSET,entry.time.tv_sec);
+ SIVAL(p,SME_USEC_OFFSET,entry.time.tv_usec);
found = True;
break;
@@ -968,7 +1015,7 @@ mode file %s (%s)\n", fname, strerror(errno)));
/*******************************************************************
call the specified function on each entry under management by the
-share ode system
+share mode system
********************************************************************/
static int slow_share_forall(void (*fn)(share_mode_entry *, char *))
{
@@ -1030,12 +1077,11 @@ static int slow_share_forall(void (*fn)(share_mode_entry *, char *))
SVAL(buf,SMF_FILENAME_LEN_OFFSET);
for( i = 0; i < IVAL(buf, SMF_NUM_ENTRIES_OFFSET); i++) {
char *p = base + (i*SMF_ENTRY_LENGTH);
- e.pid = IVAL(p,SME_PID_OFFSET);
+ e.pid = (pid_t)IVAL(p,SME_PID_OFFSET);
e.share_mode = IVAL(p,SME_SHAREMODE_OFFSET);
e.time.tv_sec = IVAL(p,SME_SEC_OFFSET);
e.time.tv_usec = IVAL(p,SME_USEC_OFFSET);
e.op_port = SVAL(p,SME_PORT_OFFSET);
- e.pid = SVAL(p,SME_PID_OFFSET);
e.op_type = SVAL(p,SME_OPLOCK_TYPE_OFFSET);
if (process_exists(e.pid)) {
diff --git a/source/locking/shmem.c b/source/locking/shmem.c
index 435c0d4c789..bf2802c9ec5 100644
--- a/source/locking/shmem.c
+++ b/source/locking/shmem.c
@@ -23,7 +23,7 @@
#include "includes.h"
-#ifdef HAVE_SHARED_MMAP
+#ifdef USE_SHARED_MMAP
extern int DEBUGLEVEL;
diff --git a/source/locking/shmem_sysv.c b/source/locking/shmem_sysv.c
index d4e814d26fb..04a2e744608 100644
--- a/source/locking/shmem_sysv.c
+++ b/source/locking/shmem_sysv.c
@@ -23,7 +23,7 @@
#include "includes.h"
-#ifdef HAVE_SYSV_IPC
+#ifdef USE_SYSV_IPC
extern int DEBUGLEVEL;
@@ -33,7 +33,11 @@ extern int DEBUGLEVEL;
#define SHM_MAGIC 0x53484100
#define SHM_VERSION 2
+#ifdef SHM_R
#define IPC_PERMS ((SHM_R | SHM_W) | (SHM_R>>3) | (SHM_R>>6))
+#else
+#define IPC_PERMS 0644
+#endif
#ifdef SECURE_SEMAPHORES
@@ -320,7 +324,7 @@ static BOOL shm_free(int offset)
shm_header_p->consistent = False;
DEBUG(6,("shm_free : freeing %d bytes at offset %d\n",
- header_p->size*CellSize,offset));
+ (int)(header_p->size*CellSize),(int)offset));
/* zero the area being freed - this allows us to find bugs faster */
memset(shm_offset2addr(offset), 0, header_p->size*CellSize);
@@ -524,6 +528,7 @@ static struct shmem_ops shmops = {
/*******************************************************************
open the shared memory
******************************************************************/
+
struct shmem_ops *sysv_shm_open(int ronly)
{
BOOL other_processes;
@@ -531,7 +536,9 @@ struct shmem_ops *sysv_shm_open(int ronly)
struct semid_ds sem_ds;
union semun su;
int i;
- int pid;
+ pid_t pid;
+ struct passwd *root_pwd = sys_getpwuid((uid_t)0);
+ gid_t root_gid = root_pwd ? root_pwd->pw_gid : (gid_t)0;
read_only = ronly;
@@ -589,15 +596,16 @@ struct shmem_ops *sysv_shm_open(int ronly)
hash_size = sem_ds.sem_nsems-1;
if (!read_only) {
- if (sem_ds.sem_perm.cuid != 0 || sem_ds.sem_perm.cgid != 0) {
- DEBUG(0,("ERROR: root did not create the semaphore\n"));
+ if (sem_ds.sem_perm.cuid != 0 || ((sem_ds.sem_perm.cgid != root_gid) && (sem_ds.sem_perm.cgid != 0))) {
+ DEBUG(0,("ERROR: root did not create the semaphore: semgid=%u, rootgid=%u\n",
+ (unsigned int)sem_ds.sem_perm.cgid, (unsigned int)root_gid));
return NULL;
}
if (semctl(sem_id, 0, GETVAL, su) == 0 &&
- !process_exists((pid=semctl(sem_id, 0, GETPID, su)))) {
+ !process_exists((pid=(pid_t)semctl(sem_id, 0, GETPID, su)))) {
DEBUG(0,("WARNING: clearing global IPC lock set by dead process %d\n",
- pid));
+ (int)pid));
su.val = 1;
if (semctl(sem_id, 0, SETVAL, su) != 0) {
DEBUG(0,("ERROR: Failed to clear global lock. Error was %s\n",
@@ -620,9 +628,9 @@ struct shmem_ops *sysv_shm_open(int ronly)
for (i=1;i<hash_size+1;i++) {
if (semctl(sem_id, i, GETVAL, su) == 0 &&
- !process_exists((pid=semctl(sem_id, i, GETPID, su)))) {
+ !process_exists((pid=(pid_t)semctl(sem_id, i, GETPID, su)))) {
DEBUG(1,("WARNING: clearing IPC lock %d set by dead process %d\n",
- i, pid));
+ i, (int)pid));
su.val = 1;
if (semctl(sem_id, i, SETVAL, su) != 0) {
DEBUG(0,("ERROR: Failed to clear IPC lock %d. Error was %s\n",
@@ -680,7 +688,7 @@ struct shmem_ops *sysv_shm_open(int ronly)
}
if (!read_only) {
- if (shm_ds.shm_perm.cuid != 0 || shm_ds.shm_perm.cgid != 0) {
+ if (shm_ds.shm_perm.cuid != 0 || ((shm_ds.shm_perm.cgid != root_gid) && (shm_ds.shm_perm.cgid != 0))) {
DEBUG(0,("ERROR: root did not create the shmem\n"));
global_unlock();
return NULL;