summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2006-01-12 22:17:54 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 11:06:05 -0500
commit33174847994128387a36a8103f147fe5a96c15fd (patch)
tree72ef01910bac6df965a9e0554c235bab145fa209
parent80f2848260d5c9be70f4a037ca3ea5c5b6a76166 (diff)
downloadsamba-33174847994128387a36a8103f147fe5a96c15fd.tar.gz
samba-33174847994128387a36a8103f147fe5a96c15fd.tar.bz2
samba-33174847994128387a36a8103f147fe5a96c15fd.zip
r12877: Stop passing structs around in smb messages, instead
always linearize into little-endian. Should fix all Solaris issues with this, plus provide a cleaner base moving forward for cluster-aware Samba where smbd's can communicate across different compilers/architectures (eventually these message will have to go cross-machine). Jeremy. (This used to be commit d01824b78576a034428e1cef73868d1169057991)
-rw-r--r--source3/configure.in19
-rw-r--r--source3/include/includes.h20
-rw-r--r--source3/include/smb.h44
-rw-r--r--source3/locking/locking.c17
-rw-r--r--source3/smbd/close.c6
-rw-r--r--source3/smbd/open.c22
-rw-r--r--source3/smbd/oplock.c188
-rw-r--r--source3/smbd/trans2.c4
8 files changed, 245 insertions, 75 deletions
diff --git a/source3/configure.in b/source3/configure.in
index 89891cf412..22dfa67154 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -1639,7 +1639,11 @@ if test x"$samba_cv_HAVE_OFF64_T" = x"yes"; then
fi
AC_CACHE_CHECK([for 64 bit ino_t],samba_cv_SIZEOF_INO_T,[
-AC_TRY_RUN([#include <stdio.h>
+AC_TRY_RUN([
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#include <stdio.h>
#include <sys/stat.h>
main() { exit((sizeof(ino_t) == 8) ? 0 : 1); }],
samba_cv_SIZEOF_INO_T=yes,samba_cv_SIZEOF_INO_T=no,samba_cv_SIZEOF_INO_T=cross)])
@@ -1660,6 +1664,19 @@ if test x"$samba_cv_HAVE_INO64_T" = x"yes"; then
AC_DEFINE(HAVE_INO64_T,1,[Whether the 'ino64_t' type is available])
fi
+AC_CACHE_CHECK([for 64 bit dev_t],samba_cv_SIZEOF_DEV_T,[
+AC_TRY_RUN([
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
+#include <stdio.h>
+#include <sys/stat.h>
+main() { exit((sizeof(dev_t) == 8) ? 0 : 1); }],
+samba_cv_SIZEOF_DEV_T=yes,samba_cv_SIZEOF_DEV_T=no,samba_cv_SIZEOF_DEV_T=cross)])
+if test x"$samba_cv_SIZEOF_DEV_T" = x"yes"; then
+ AC_DEFINE(SIZEOF_DEV_T,8,[The size of the 'dev_t' type])
+fi
+
AC_CACHE_CHECK([for dev64_t],samba_cv_HAVE_DEV64_T,[
AC_TRY_RUN([
#if defined(HAVE_UNISTD_H)
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 44b5ea1bd7..a9b792d5f6 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -657,6 +657,20 @@ typedef int socklen_t;
# endif
#endif
+#ifndef LARGE_SMB_DEV_T
+# if (defined(HAVE_EXPLICIT_LARGEFILE_SUPPORT) && defined(HAVE_DEV64_T)) || (defined(SIZEOF_DEV_T) && (SIZEOF_DEV_T == 8))
+# define LARGE_SMB_DEV_T 1
+# endif
+#endif
+
+#ifdef LARGE_SMB_DEV_T
+#define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
+#define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(((SMB_BIG_UINT)(IVAL((p),(ofs))))| (((SMB_BIG_UINT)(IVAL((p),(ofs)+4))) << 32)))
+#else
+#define SDEV_T_VAL(p, ofs, v) (SIVAL((p),(ofs),v),SIVAL((p),(ofs)+4,0))
+#define DEV_T_VAL(p, ofs) ((SMB_DEV_T)(IVAL((p),(ofs))))
+#endif
+
/*
* Setup the correctly sized inode type.
*/
@@ -676,9 +690,11 @@ typedef int socklen_t;
#endif
#ifdef LARGE_SMB_INO_T
-#define SINO_T(p, ofs, v) (SIVAL(p,ofs,(v)&0xFFFFFFFF), SIVAL(p,(ofs)+4,(v)>>32))
+#define SINO_T_VAL(p, ofs, v) (SIVAL((p),(ofs),(v)&0xFFFFFFFF), SIVAL((p),(ofs)+4,(v)>>32))
+#define INO_T_VAL(p, ofs) ((SMB_INO_T)(((SMB_BIG_UINT)(IVAL(p,ofs)))| (((SMB_BIG_UINT)(IVAL(p,(ofs)+4))) << 32)))
#else
-#define SINO_T(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
+#define SINO_T_VAL(p, ofs, v) (SIVAL(p,ofs,v),SIVAL(p,(ofs)+4,0))
+#define INO_T_VAL(p, ofs) ((SMB_INO_T)(IVAL((p),(ofs))))
#endif
#ifndef SMB_OFF_T
diff --git a/source3/include/smb.h b/source3/include/smb.h
index d2eb5644e0..6ceb4ec1cd 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -631,6 +631,25 @@ struct share_mode_entry {
unsigned long share_file_id;
};
+/* oplock break message definition - linearization of share_mode_entry.
+
+Offset Data length.
+0 struct process_id pid 4
+4 uint16 op_mid 2
+6 uint16 op_type 2
+8 uint32 access_mask 4
+12 uint32 share_access 4
+16 uint32 private_options 4
+20 uint32 time sec 4
+24 uint32 time usec 4
+28 SMB_DEV_T dev 8 bytes.
+36 SMB_INO_T inode 8 bytes
+44 unsigned long file_id 4 bytes
+48
+
+*/
+#define MSG_SMB_SHARE_MODE_ENTRY_SIZE 48
+
struct share_mode_lock {
const char *servicepath; /* canonicalized. */
const char *filename;
@@ -1456,18 +1475,41 @@ struct inform_level2_message {
unsigned long source_file_id;
};
+/* kernel_oplock_message definition.
+
struct kernel_oplock_message {
SMB_DEV_T dev;
SMB_INO_T inode;
unsigned long file_id;
};
+Offset Data length.
+0 SMB_DEV_T dev 8 bytes.
+8 SMB_INO_T inode 8 bytes
+16 unsigned long file_id 4 bytes
+20
+
+*/
+#define MSG_SMB_KERNEL_BREAK_SIZE 20
+
+/* file_renamed_message definition.
+
struct file_renamed_message {
SMB_DEV_T dev;
SMB_INO_T inode;
- char names[1]; /* A variable area containing sharepath and filename. */
+ char names[1]; A variable area containing sharepath and filename.
};
+Offset Data length.
+0 SMB_DEV_T dev 8 bytes.
+8 SMB_INO_T inode 8 bytes
+16 char [] name zero terminated namelen bytes
+minimum length == 18.
+
+*/
+
+#define MSG_FILE_RENAMED_MIN_SIZE 16
+
/*
* On the wire return values for oplock types.
*/
diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index 07377831b4..d9737895ba 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -662,10 +662,10 @@ BOOL rename_share_filename(struct share_mode_lock *lck,
const char *servicepath,
const char *newname)
{
- struct file_renamed_message *frm = NULL;
size_t sp_len;
size_t fn_len;
size_t msg_len;
+ char *frm = NULL;
int i;
if (!lck) {
@@ -694,20 +694,21 @@ BOOL rename_share_filename(struct share_mode_lock *lck,
sp_len = strlen(lck->servicepath);
fn_len = strlen(lck->filename);
- msg_len = sizeof(*frm) + sp_len + 1 + fn_len + 1;
+ msg_len = MSG_FILE_RENAMED_MIN_SIZE + sp_len + 1 + fn_len + 1;
/* Set up the name changed message. */
frm = TALLOC(lck, msg_len);
if (!frm) {
return False;
}
- frm->dev = lck->dev;
- frm->inode = lck->ino;
+
+ SDEV_T_VAL(frm,0,lck->dev);
+ SINO_T_VAL(frm,8,lck->ino);
DEBUG(10,("rename_share_filename: msg_len = %d\n", msg_len ));
- safe_strcpy(&frm->names[0], lck->servicepath, sp_len);
- safe_strcpy(&frm->names[sp_len + 1], lck->filename, fn_len);
+ safe_strcpy(&frm[16], lck->servicepath, sp_len);
+ safe_strcpy(&frm[16 + sp_len + 1], lck->filename, fn_len);
/* Send the messages. */
for (i=0; i<lck->num_share_modes; i++) {
@@ -723,11 +724,13 @@ BOOL rename_share_filename(struct share_mode_lock *lck,
DEBUG(10,("rename_share_filename: sending rename message to pid %u "
"dev %x, inode %.0f sharepath %s newname %s\n",
(unsigned int)procid_to_pid(&se->pid),
- (unsigned int)frm->dev, (double)frm->inode,
+ (unsigned int)lck->dev, (double)lck->ino,
lck->servicepath, lck->filename ));
+ become_root();
message_send_pid(se->pid, MSG_SMB_FILE_RENAME,
frm, msg_len, True);
+ unbecome_root();
}
return True;
diff --git a/source3/smbd/close.c b/source3/smbd/close.c
index f834869935..c0d87b1b21 100644
--- a/source3/smbd/close.c
+++ b/source3/smbd/close.c
@@ -130,9 +130,13 @@ static void notify_deferred_opens(struct share_mode_lock *lck)
*/
schedule_deferred_open_smb_message(e->op_mid);
} else {
+ char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
+
+ share_mode_entry_to_message(msg, e);
+
become_root();
message_send_pid(e->pid, MSG_SMB_OPEN_RETRY,
- e, sizeof(*e), True);
+ msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
unbecome_root();
}
}
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index e6c749fab9..0ccac592d6 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -683,12 +683,17 @@ static BOOL delay_for_oplocks(struct share_mode_lock *lck, files_struct *fsp)
if (delay_it) {
BOOL ret;
+ char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
+
DEBUG(10, ("Sending break request to PID %s\n",
procid_str_static(&exclusive->pid)));
exclusive->op_mid = get_current_mid();
+
+ share_mode_entry_to_message(msg, exclusive);
+
become_root();
ret = message_send_pid(exclusive->pid, MSG_SMB_BREAK_REQUEST,
- exclusive, sizeof(*exclusive), True);
+ msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
unbecome_root();
if (!ret) {
DEBUG(3, ("Could not send oplock break message\n"));
@@ -2055,25 +2060,30 @@ files_struct *open_file_stat(connection_struct *conn, char *fname,
void msg_file_was_renamed(int msg_type, struct process_id src, void *buf, size_t len)
{
files_struct *fsp;
- struct file_renamed_message *frm = (struct file_renamed_message *)buf;
+ char *frm = (char *)buf;
+ SMB_DEV_T dev;
+ SMB_INO_T inode;
const char *sharepath;
const char *newname;
size_t sp_len;
- if (buf == NULL || len < sizeof(*frm)) {
+ if (buf == NULL || len < MSG_FILE_RENAMED_MIN_SIZE + 2) {
DEBUG(0, ("msg_file_was_renamed: Got invalid msg len %d\n", (int)len));
return;
}
- sharepath = &frm->names[0];
+ /* Unpack the message. */
+ dev = DEV_T_VAL(frm,0);
+ inode = INO_T_VAL(frm,8);
+ sharepath = &frm[16];
newname = sharepath + strlen(sharepath) + 1;
sp_len = strlen(sharepath);
DEBUG(10,("msg_file_was_renamed: Got rename message for sharepath %s, new name %s, "
"dev %x, inode %.0f\n",
- sharepath, newname, (unsigned int)frm->dev, (double)frm->inode ));
+ sharepath, newname, (unsigned int)dev, (double)inode ));
- for(fsp = file_find_di_first(frm->dev, frm->inode); fsp; fsp = file_find_di_next(fsp)) {
+ for(fsp = file_find_di_first(dev, inode); fsp; fsp = file_find_di_next(fsp)) {
if (memcmp(fsp->conn->connectpath, sharepath, sp_len) == 0) {
DEBUG(10,("msg_file_was_renamed: renaming file fnum %d from %s -> %s\n",
fsp->fnum, fsp->fsp_name, newname ));
diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c
index f788fc9e2e..6739d29470 100644
--- a/source3/smbd/oplock.c
+++ b/source3/smbd/oplock.c
@@ -48,8 +48,9 @@ int32 get_number_of_exclusive_open_oplocks(void)
BOOL oplock_message_waiting(fd_set *fds)
{
- if (koplocks && koplocks->msg_waiting(fds))
+ if (koplocks && koplocks->msg_waiting(fds)) {
return True;
+ }
return False;
}
@@ -84,7 +85,7 @@ void process_kernel_oplocks(void)
while (koplocks->msg_waiting(&fds)) {
files_struct *fsp;
- struct kernel_oplock_message msg;
+ char msg[MSG_SMB_KERNEL_BREAK_SIZE];
fsp = koplocks->receive_message(&fds);
@@ -94,12 +95,17 @@ void process_kernel_oplocks(void)
return;
}
- msg.dev = fsp->dev;
- msg.inode = fsp->inode;
- msg.file_id = fsp->file_id;
+ /* Put the kernel break info into the message. */
+ SDEV_T_VAL(msg,0,fsp->dev);
+ SINO_T_VAL(msg,8,fsp->inode);
+ SIVAL(msg,16,fsp->file_id);
+
+ /* Don't need to be root here as we're only ever
+ sending to ourselves. */
+
message_send_pid(pid_to_procid(sys_getpid()),
MSG_SMB_KERNEL_BREAK,
- &msg, sizeof(msg), True);
+ &msg, MSG_SMB_KERNEL_BREAK_SIZE, True);
}
}
@@ -110,15 +116,17 @@ void process_kernel_oplocks(void)
BOOL set_file_oplock(files_struct *fsp, int oplock_type)
{
- if (koplocks && !koplocks->set_oplock(fsp, oplock_type))
+ if (koplocks && !koplocks->set_oplock(fsp, oplock_type)) {
return False;
+ }
fsp->oplock_type = oplock_type;
fsp->sent_oplock_break = NO_BREAK_SENT;
- if (oplock_type == LEVEL_II_OPLOCK)
+ if (oplock_type == LEVEL_II_OPLOCK) {
level_II_oplocks_open++;
- else
+ } else {
exclusive_oplocks_open++;
+ }
DEBUG(5,("set_file_oplock: granted oplock on file %s, dev = %x, inode = %.0f, file_id = %lu, \
tv_sec = %x, tv_usec = %x\n",
@@ -140,10 +148,11 @@ void release_file_oplock(files_struct *fsp)
koplocks->release_oplock(fsp);
}
- if (fsp->oplock_type == LEVEL_II_OPLOCK)
+ if (fsp->oplock_type == LEVEL_II_OPLOCK) {
level_II_oplocks_open--;
- else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
+ } else if (EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
exclusive_oplocks_open--;
+ }
SMB_ASSERT(exclusive_oplocks_open>=0);
SMB_ASSERT(level_II_oplocks_open>=0);
@@ -160,8 +169,9 @@ void release_file_oplock(files_struct *fsp)
static void downgrade_file_oplock(files_struct *fsp)
{
- if (koplocks)
+ if (koplocks) {
koplocks->release_oplock(fsp);
+ }
fsp->oplock_type = LEVEL_II_OPLOCK;
exclusive_oplocks_open--;
level_II_oplocks_open++;
@@ -223,7 +233,7 @@ BOOL downgrade_oplock(files_struct *fsp)
fsp->fsp_name, fsp->fnum, (unsigned int)dev,
(double)inode));
}
-
+
downgrade_file_oplock(fsp);
talloc_free(lck);
return ret;
@@ -284,8 +294,9 @@ static void wait_before_sending_break(void)
struct timeval cur_tv;
long wait_left = (long)lp_oplock_break_wait_time();
- if (wait_left == 0)
+ if (wait_left == 0) {
return;
+ }
GetTimeOfDay(&cur_tv);
@@ -307,7 +318,7 @@ static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, un
files_struct *fsp = NULL;
if( DEBUGLVL( 3 ) ) {
- dbgtext( "initial_break_processing: called for dev = %x, inode = %.0f file_id = %lu\n",
+ dbgtext( "initial_break_processing: called for dev = 0x%x, inode = %.0f file_id = %lu\n",
(unsigned int)dev, (double)inode, file_id);
dbgtext( "Current oplocks_open (exclusive = %d, levelII = %d)\n",
exclusive_oplocks_open, level_II_oplocks_open );
@@ -325,7 +336,7 @@ static files_struct *initial_break_processing(SMB_DEV_T dev, SMB_INO_T inode, un
/* The file could have been closed in the meantime - return success. */
if( DEBUGLVL( 3 ) ) {
dbgtext( "initial_break_processing: cannot find open file with " );
- dbgtext( "dev = %x, inode = %.0f file_id = %lu", (unsigned int)dev,
+ dbgtext( "dev = 0x%x, inode = %.0f file_id = %lu", (unsigned int)dev,
(double)inode, file_id);
dbgtext( "allowing break to succeed.\n" );
}
@@ -370,7 +381,7 @@ static void oplock_timeout_handler(struct timed_event *te,
static void process_oplock_break_message(int msg_type, struct process_id src,
void *buf, size_t len)
{
- struct share_mode_entry *msg = buf;
+ struct share_mode_entry msg;
files_struct *fsp;
char *break_msg;
BOOL break_to_level2 = False;
@@ -381,17 +392,20 @@ static void process_oplock_break_message(int msg_type, struct process_id src,
return;
}
- if (len != sizeof(*msg)) {
+ if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
DEBUG(0, ("Got invalid msg len %d\n", (int)len));
return;
}
- DEBUG(10, ("Got oplock break message from pid %d: %d/%d/%d\n",
- (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
- (int)msg->share_file_id));
+ /* De-linearize incoming message. */
+ message_to_share_mode_entry(&msg, buf);
+
+ DEBUG(10, ("Got oplock break message from pid %d: 0x%x/%.0f/%d\n",
+ (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
+ (int)msg.share_file_id));
- fsp = initial_break_processing(msg->dev, msg->inode,
- msg->share_file_id);
+ fsp = initial_break_processing(msg.dev, msg.inode,
+ msg.share_file_id);
if (fsp == NULL) {
/* We hit race here. Break messages are sent, and before we
@@ -399,8 +413,11 @@ static void process_oplock_break_message(int msg_type, struct process_id src,
* with 'ok, oplock broken' */
DEBUG(3, ("Did not find fsp\n"));
become_root();
+
+ /* We just send the same message back. */
message_send_pid(src, MSG_SMB_BREAK_RESPONSE,
- msg, sizeof(*msg), True);
+ buf, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
+
unbecome_root();
return;
}
@@ -408,21 +425,24 @@ static void process_oplock_break_message(int msg_type, struct process_id src,
if (fsp->sent_oplock_break != NO_BREAK_SENT) {
/* Remember we have to inform the requesting PID when the
* client replies */
- msg->pid = src;
- ADD_TO_ARRAY(NULL, struct share_mode_entry, *msg,
+ msg.pid = src;
+ ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
&fsp->pending_break_messages,
&fsp->num_pending_break_messages);
return;
}
- if (EXCLUSIVE_OPLOCK_TYPE(msg->op_type) &&
+ if (EXCLUSIVE_OPLOCK_TYPE(msg.op_type) &&
!EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
- DEBUG(3, ("Already downgraded oplock on %.0f/%.0f: %s\n",
- (double)fsp->dev, (double)fsp->inode,
+ DEBUG(3, ("Already downgraded oplock on 0x%x/%.0f: %s\n",
+ (unsigned int)fsp->dev, (double)fsp->inode,
fsp->fsp_name));
become_root();
+
+ /* We just send the same message back. */
message_send_pid(src, MSG_SMB_BREAK_RESPONSE,
- msg, sizeof(*msg), True);
+ buf, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
+
unbecome_root();
return;
}
@@ -466,8 +486,8 @@ static void process_oplock_break_message(int msg_type, struct process_id src,
/* Async level2 request, don't send a reply */
fsp->sent_oplock_break = ASYNC_LEVEL_II_BREAK_SENT;
}
- msg->pid = src;
- ADD_TO_ARRAY(NULL, struct share_mode_entry, *msg,
+ msg.pid = src;
+ ADD_TO_ARRAY(NULL, struct share_mode_entry, msg,
&fsp->pending_break_messages,
&fsp->num_pending_break_messages);
@@ -490,7 +510,9 @@ static void process_oplock_break_message(int msg_type, struct process_id src,
static void process_kernel_oplock_break(int msg_type, struct process_id src,
void *buf, size_t len)
{
- struct kernel_oplock_message *msg = buf;
+ SMB_DEV_T dev;
+ SMB_INO_T inode;
+ unsigned long file_id;
files_struct *fsp;
char *break_msg;
BOOL sign_state;
@@ -500,16 +522,21 @@ static void process_kernel_oplock_break(int msg_type, struct process_id src,
return;
}
- if (len != sizeof(*msg)) {
+ if (len != MSG_SMB_KERNEL_BREAK_SIZE) {
DEBUG(0, ("Got invalid msg len %d\n", (int)len));
return;
}
- DEBUG(10, ("Got kernel oplock break message from pid %d: %d/%d/%d\n",
- (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
- (int)msg->file_id));
+ /* Pull the data from the message. */
+ dev = DEV_T_VAL(buf, 0);
+ inode = INO_T_VAL(buf, 8);
+ file_id = (unsigned long)IVAL(buf, 16);
- fsp = initial_break_processing(msg->dev, msg->inode, msg->file_id);
+ DEBUG(10, ("Got kernel oplock break message from pid %d: 0x%x/%.0f/%u\n",
+ (int)procid_to_pid(&src), (unsigned int)dev, (double)inode,
+ (unsigned int)file_id));
+
+ fsp = initial_break_processing(dev, inode, file_id);
if (fsp == NULL) {
DEBUG(3, ("Got a kernel oplock break message for a file "
@@ -551,9 +578,13 @@ void reply_to_oplock_break_requests(files_struct *fsp)
become_root();
for (i=0; i<fsp->num_pending_break_messages; i++) {
- struct share_mode_entry *msg = &fsp->pending_break_messages[i];
- message_send_pid(msg->pid, MSG_SMB_BREAK_RESPONSE,
- msg, sizeof(*msg), True);
+ struct share_mode_entry *e = &fsp->pending_break_messages[i];
+ char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
+
+ share_mode_entry_to_message(msg, e);
+
+ message_send_pid(e->pid, MSG_SMB_BREAK_RESPONSE,
+ msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
}
unbecome_root();
@@ -569,46 +600,52 @@ void reply_to_oplock_break_requests(files_struct *fsp)
static void process_oplock_break_response(int msg_type, struct process_id src,
void *buf, size_t len)
{
- struct share_mode_entry *msg = buf;
+ struct share_mode_entry msg;
if (buf == NULL) {
DEBUG(0, ("Got NULL buffer\n"));
return;
}
- if (len != sizeof(*msg)) {
- DEBUG(0, ("Got invalid msg len %d\n", (int)len));
+ if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
+ DEBUG(0, ("Got invalid msg len %u\n", (unsigned int)len));
return;
}
- DEBUG(10, ("Got oplock break response from pid %d: %d/%d/%d mid %d\n",
- (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
- (int)msg->share_file_id, (int)msg->op_mid));
+ /* De-linearize incoming message. */
+ message_to_share_mode_entry(&msg, buf);
+
+ DEBUG(10, ("Got oplock break response from pid %d: 0x%x/%.0f/%u mid %u\n",
+ (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
+ (unsigned int)msg.share_file_id, (unsigned int)msg.op_mid));
/* Here's the hack from open.c, store the mid in the 'port' field */
- schedule_deferred_open_smb_message(msg->op_mid);
+ schedule_deferred_open_smb_message(msg.op_mid);
}
static void process_open_retry_message(int msg_type, struct process_id src,
void *buf, size_t len)
{
- struct share_mode_entry *msg = buf;
+ struct share_mode_entry msg;
if (buf == NULL) {
DEBUG(0, ("Got NULL buffer\n"));
return;
}
- if (len != sizeof(*msg)) {
+ if (len != MSG_SMB_SHARE_MODE_ENTRY_SIZE) {
DEBUG(0, ("Got invalid msg len %d\n", (int)len));
return;
}
- DEBUG(10, ("Got open retry msg from pid %d: %d/%d mid %d\n",
- (int)procid_to_pid(&src), (int)msg->dev, (int)msg->inode,
- (int)msg->op_mid));
+ /* De-linearize incoming message. */
+ message_to_share_mode_entry(&msg, buf);
- schedule_deferred_open_smb_message(msg->op_mid);
+ DEBUG(10, ("Got open retry msg from pid %d: 0x%x/%.0f mid %u\n",
+ (int)procid_to_pid(&src), (unsigned int)msg.dev, (double)msg.inode,
+ (unsigned int)msg.op_mid));
+
+ schedule_deferred_open_smb_message(msg.op_mid);
}
/****************************************************************************
@@ -662,6 +699,7 @@ void release_level_2_oplocks_on_change(files_struct *fsp)
for(i = 0; i < lck->num_share_modes; i++) {
struct share_mode_entry *share_entry = &lck->share_modes[i];
+ char msg[MSG_SMB_SHARE_MODE_ENTRY_SIZE];
/*
* As there could have been multiple writes waiting at the
@@ -692,9 +730,11 @@ void release_level_2_oplocks_on_change(files_struct *fsp)
abort();
}
+ share_mode_entry_to_message(msg, share_entry);
+
become_root();
message_send_pid(share_entry->pid, MSG_SMB_ASYNC_LEVEL2_BREAK,
- share_entry, sizeof(*share_entry), True);
+ msg, MSG_SMB_SHARE_MODE_ENTRY_SIZE, True);
unbecome_root();
}
@@ -703,6 +743,44 @@ void release_level_2_oplocks_on_change(files_struct *fsp)
}
/****************************************************************************
+ Linearize a share mode entry struct to an internal oplock break message.
+****************************************************************************/
+
+void share_mode_entry_to_message(char *msg, struct share_mode_entry *e)
+{
+ SIVAL(msg,0,(uint32)e->pid.pid);
+ SSVAL(msg,4,e->op_mid);
+ SSVAL(msg,6,e->op_type);
+ SIVAL(msg,8,e->access_mask);
+ SIVAL(msg,12,e->share_access);
+ SIVAL(msg,16,e->private_options);
+ SIVAL(msg,20,(uint32)e->time.tv_sec);
+ SIVAL(msg,24,(uint32)e->time.tv_usec);
+ SDEV_T_VAL(msg,28,e->dev);
+ SINO_T_VAL(msg,36,e->inode);
+ SIVAL(msg,44,e->share_file_id);
+}
+
+/****************************************************************************
+ De-linearize an internal oplock break message to a share mode entry struct.
+****************************************************************************/
+
+void message_to_share_mode_entry(struct share_mode_entry *e, char *msg)
+{
+ e->pid.pid = (pid_t)IVAL(msg,0);
+ e->op_mid = SVAL(msg,4);
+ e->op_type = SVAL(msg,6);
+ e->access_mask = IVAL(msg,8);
+ e->share_access = IVAL(msg,12);
+ e->private_options = IVAL(msg,16);
+ e->time.tv_sec = (time_t)IVAL(msg,20);
+ e->time.tv_usec = (int)IVAL(msg,24);
+ e->dev = DEV_T_VAL(msg,28);
+ e->inode = INO_T_VAL(msg,36);
+ e->share_file_id = (unsigned long)IVAL(msg,44);
+}
+
+/****************************************************************************
Setup oplocks for this process.
****************************************************************************/
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index 191ccdcf8b..8ff219b468 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -1536,7 +1536,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
SIVAL(p,4,0);
p+= 8;
- SINO_T(p,0,(SMB_INO_T)sbuf.st_ino); /* inode number */
+ SINO_T_VAL(p,0,(SMB_INO_T)sbuf.st_ino); /* inode number */
p+= 8;
SIVAL(p,0, unix_perms_to_wire(sbuf.st_mode)); /* Standard UNIX file permissions */
@@ -3353,7 +3353,7 @@ total_data=%u (should be %u)\n", (unsigned int)total_data, (unsigned int)IVAL(pd
SIVAL(pdata,4,0);
pdata += 8;
- SINO_T(pdata,0,(SMB_INO_T)sbuf.st_ino); /* inode number */
+ SINO_T_VAL(pdata,0,(SMB_INO_T)sbuf.st_ino); /* inode number */
pdata += 8;
SIVAL(pdata,0, unix_perms_to_wire(sbuf.st_mode)); /* Standard UNIX file permissions */