summaryrefslogtreecommitdiff
path: root/source3/locking/locking_slow.c
diff options
context:
space:
mode:
Diffstat (limited to 'source3/locking/locking_slow.c')
-rw-r--r--source3/locking/locking_slow.c102
1 files changed, 74 insertions, 28 deletions
diff --git a/source3/locking/locking_slow.c b/source3/locking/locking_slow.c
index 64bedca4ad..58673d2707 100644
--- a/source3/locking/locking_slow.c
+++ b/source3/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)) {