[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Tue Oct 8 17:59:03 MDT 2013


The branch, master has been updated
       via  0239315 smbd: Fix an error path in open_directory
       via  0cc2123 smbd: Simplify set_share_mode
       via  b8b7e85 smbd: Simplify find_share_mode_entry callers
       via  e0e5f67 smbd: Convert set_share_mode to return bool for success
       via  ad2ba58 smbd: Make add_share_mode return bool
       via  f9554a9 smbd: Change parameter from unsigned to uint32_t
      from  2ad37cb lib/util: remove unused (and not even compiled) lib/util/capability.c.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 02393156de280748d4e87f231d477fa70437a8a0
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Oct 7 20:13:28 2013 +0000

    smbd: Fix an error path in open_directory
    
    In open_file_ntcreate we do the del_share_mode on error. We should do
    it here as well.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed Oct  9 01:58:55 CEST 2013 on sn-devel-104

commit 0cc212385c4b622bb1fa5055cde87ab43de36e45
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 14:02:48 2013 -0700

    smbd: Simplify set_share_mode
    
    With the find_share_mode simplification we don't need fill_share_mode anymore.
    So this coalesces add_share_mode as well.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b8b7e855ce1fd4bfdd06addcb824396418025dc8
Author: Volker Lendecke <vl at samba.org>
Date:   Mon Sep 16 13:58:54 2013 -0700

    smbd: Simplify find_share_mode_entry callers
    
    All callers used fill_share_mode_entry before calling
    find_share_mode_entry. Remove that requirement.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e0e5f67da522521a37622a5833b8699ae63e8c27
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Sep 14 13:49:14 2013 +0200

    smbd: Convert set_share_mode to return bool for success
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ad2ba58f53a7fb6b87511288cb450f1327f1ccbf
Author: Volker Lendecke <vl at samba.org>
Date:   Sat Sep 14 13:48:03 2013 +0200

    smbd: Make add_share_mode return bool
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f9554a993ecb345b8773a911a6e98a7f2329422b
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Sep 25 18:39:27 2013 -0700

    smbd: Change parameter from unsigned to uint32_t
    
    share_mode_stale_pid internally only has to deal with uint32_t. Make
    the parameter match this.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/locking/locking.c |  111 +++++++++++++++++----------------------------
 source3/locking/proto.h   |    4 +-
 source3/smbd/open.c       |   20 ++++++--
 3 files changed, 59 insertions(+), 76 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/locking/locking.c b/source3/locking/locking.c
index d0b6eaf..b9db27c 100644
--- a/source3/locking/locking.c
+++ b/source3/locking/locking.c
@@ -636,7 +636,7 @@ bool is_valid_share_mode_entry(const struct share_mode_entry *e)
  * being used, we need to make sure the corresponding process still
  * exists.
  */
-bool share_mode_stale_pid(struct share_mode_data *d, unsigned idx)
+bool share_mode_stale_pid(struct share_mode_data *d, uint32_t idx)
 {
 	struct share_mode_entry *e;
 
@@ -693,14 +693,22 @@ bool share_mode_stale_pid(struct share_mode_data *d, unsigned idx)
 	return true;
 }
 
-/*******************************************************************
- Fill a share mode entry.
-********************************************************************/
-
-static void fill_share_mode_entry(struct share_mode_entry *e,
-				  files_struct *fsp,
-				  uid_t uid, uint64_t mid, uint16 op_type)
+bool set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
+		    uid_t uid, uint64_t mid, uint16 op_type)
 {
+	struct share_mode_data *d = lck->data;
+	struct share_mode_entry *tmp, *e;
+
+	tmp = talloc_realloc(d, d->share_modes, struct share_mode_entry,
+			     d->num_share_modes+1);
+	if (tmp == NULL) {
+		return false;
+	}
+	d->share_modes = tmp;
+	e = &d->share_modes[d->num_share_modes];
+	d->num_share_modes += 1;
+	d->modified = true;
+
 	ZERO_STRUCTP(e);
 	e->pid = messaging_server_id(fsp->conn->sconn->msg_ctx);
 	e->share_access = fsp->share_access;
@@ -715,58 +723,35 @@ static void fill_share_mode_entry(struct share_mode_entry *e,
 	e->uid = (uint32)uid;
 	e->flags = fsp->posix_open ? SHARE_MODE_FLAG_POSIX_OPEN : 0;
 	e->name_hash = fsp->name_hash;
-}
-
-static void add_share_mode_entry(struct share_mode_data *d,
-				 const struct share_mode_entry *entry)
-{
-	ADD_TO_ARRAY(d, struct share_mode_entry, *entry,
-		     &d->share_modes, &d->num_share_modes);
-	d->modified = True;
-}
-
-void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
-		    uid_t uid, uint64_t mid, uint16 op_type)
-{
-	struct share_mode_entry entry;
-	fill_share_mode_entry(&entry, fsp, uid, mid, op_type);
-	add_share_mode_entry(lck->data, &entry);
-}
-
-/*******************************************************************
- Check if two share mode entries are identical, ignoring oplock 
- and mid info and desired_access. (Removed paranoia test - it's
- not automatically a logic error if they are identical. JRA.)
-********************************************************************/
 
-static bool share_modes_identical(const struct share_mode_entry *e1,
-				  const struct share_mode_entry *e2)
-{
-	/* We used to check for e1->share_access == e2->share_access here
-	   as well as the other fields but 2 different DOS or FCB opens
-	   sharing the same share mode entry may validly differ in
-	   fsp->share_access field. */
-
-	return (serverid_equal(&e1->pid, &e2->pid) &&
-		file_id_equal(&e1->id, &e2->id) &&
-		e1->share_file_id == e2->share_file_id );
+	return true;
 }
 
 static struct share_mode_entry *find_share_mode_entry(
-	struct share_mode_data *d, const struct share_mode_entry *entry)
+	struct share_mode_lock *lck, files_struct *fsp)
 {
+	struct share_mode_data *d = lck->data;
+	struct server_id pid;
 	int i;
 
-	if (!is_valid_share_mode_entry(entry)) {
-		return NULL;
-	}
+	pid = messaging_server_id(fsp->conn->sconn->msg_ctx);
 
 	for (i=0; i<d->num_share_modes; i++) {
 		struct share_mode_entry *e = &d->share_modes[i];
-		if (is_valid_share_mode_entry(e) &&
-		    share_modes_identical(e, entry)) {
-			return e;
+
+		if (!is_valid_share_mode_entry(e)) {
+			continue;
+		}
+		if (!serverid_equal(&pid, &e->pid)) {
+			continue;
+		}
+		if (!file_id_equal(&fsp->file_id, &e->id)) {
+			continue;
+		}
+		if (fsp->fh->gen_id != e->share_file_id) {
+			continue;
 		}
+		return e;
 	}
 	return NULL;
 }
@@ -778,12 +763,9 @@ static struct share_mode_entry *find_share_mode_entry(
 
 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
 {
-	struct share_mode_entry entry, *e;
-
-	/* Don't care about the pid owner being correct here - just a search. */
-	fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
+	struct share_mode_entry *e;
 
-	e = find_share_mode_entry(lck->data, &entry);
+	e = find_share_mode_entry(lck, fsp);
 	if (e == NULL) {
 		return False;
 	}
@@ -796,7 +778,7 @@ bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp)
 bool mark_share_mode_disconnected(struct share_mode_lock *lck,
 				  struct files_struct *fsp)
 {
-	struct share_mode_entry entry, *e;
+	struct share_mode_entry *e;
 
 	if (lck->data->num_share_modes != 1) {
 		return false;
@@ -809,10 +791,7 @@ bool mark_share_mode_disconnected(struct share_mode_lock *lck,
 		return false;
 	}
 
-	/* Don't care about the pid owner being correct here - just a search. */
-	fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
-
-	e = find_share_mode_entry(lck->data, &entry);
+	e = find_share_mode_entry(lck, fsp);
 	if (e == NULL) {
 		return false;
 	}
@@ -837,12 +816,9 @@ bool mark_share_mode_disconnected(struct share_mode_lock *lck,
 
 bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp)
 {
-	struct share_mode_entry entry, *e;
-
-	/* Don't care about the pid owner being correct here - just a search. */
-	fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
+	struct share_mode_entry *e;
 
-	e = find_share_mode_entry(lck->data, &entry);
+	e = find_share_mode_entry(lck, fsp);
 	if (e == NULL) {
 		return False;
 	}
@@ -870,12 +846,9 @@ bool remove_share_oplock(struct share_mode_lock *lck, files_struct *fsp)
 
 bool downgrade_share_oplock(struct share_mode_lock *lck, files_struct *fsp)
 {
-	struct share_mode_entry entry, *e;
-
-	/* Don't care about the pid owner being correct here - just a search. */
-	fill_share_mode_entry(&entry, fsp, (uid_t)-1, 0, NO_OPLOCK);
+	struct share_mode_entry *e;
 
-	e = find_share_mode_entry(lck->data, &entry);
+	e = find_share_mode_entry(lck, fsp);
 	if (e == NULL) {
 		return False;
 	}
diff --git a/source3/locking/proto.h b/source3/locking/proto.h
index 1573f6b..02e2bf5 100644
--- a/source3/locking/proto.h
+++ b/source3/locking/proto.h
@@ -170,8 +170,8 @@ void get_file_infos(struct file_id id,
 		    bool *delete_on_close,
 		    struct timespec *write_time);
 bool is_valid_share_mode_entry(const struct share_mode_entry *e);
-bool share_mode_stale_pid(struct share_mode_data *d, unsigned idx);
-void set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
+bool share_mode_stale_pid(struct share_mode_data *d, uint32_t idx);
+bool set_share_mode(struct share_mode_lock *lck, files_struct *fsp,
 		    uid_t uid, uint64_t mid, uint16 op_type);
 bool del_share_mode(struct share_mode_lock *lck, files_struct *fsp);
 bool mark_share_mode_disconnected(struct share_mode_lock *lck,
diff --git a/source3/smbd/open.c b/source3/smbd/open.c
index 858d2be..5024c90 100644
--- a/source3/smbd/open.c
+++ b/source3/smbd/open.c
@@ -2681,9 +2681,13 @@ static NTSTATUS open_file_ntcreate(connection_struct *conn,
 		fsp->oplock_type = NO_OPLOCK;
 	}
 
-	set_share_mode(lck, fsp, get_current_uid(conn),
-			req ? req->mid : 0,
-		       fsp->oplock_type);
+	if (!set_share_mode(lck, fsp, get_current_uid(conn),
+			    req ? req->mid : 0,
+			    fsp->oplock_type)) {
+		TALLOC_FREE(lck);
+		fd_close(fsp);
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	/* Handle strange delete on close create semantics. */
 	if (create_options & FILE_DELETE_ON_CLOSE) {
@@ -3173,14 +3177,20 @@ static NTSTATUS open_directory(connection_struct *conn,
 		return status;
 	}
 
-	set_share_mode(lck, fsp, get_current_uid(conn),
-			req ? req->mid : 0, NO_OPLOCK);
+	if (!set_share_mode(lck, fsp, get_current_uid(conn),
+			    req ? req->mid : 0, NO_OPLOCK)) {
+		TALLOC_FREE(lck);
+		fd_close(fsp);
+		file_free(req, fsp);
+		return NT_STATUS_NO_MEMORY;
+	}
 
 	/* For directories the delete on close bit at open time seems
 	   always to be honored on close... See test 19 in Samba4 BASE-DELETE. */
 	if (create_options & FILE_DELETE_ON_CLOSE) {
 		status = can_set_delete_on_close(fsp, 0);
 		if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_DIRECTORY_NOT_EMPTY)) {
+			del_share_mode(lck, fsp);
 			TALLOC_FREE(lck);
 			fd_close(fsp);
 			file_free(req, fsp);


-- 
Samba Shared Repository


More information about the samba-cvs mailing list