summaryrefslogtreecommitdiff
path: root/source3/locking/share_mode_lock.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2013-08-30 12:49:43 +0000
committerMichael Adam <obnox@samba.org>2013-09-03 17:13:53 +0200
commit7d91ffc6fdc3b371564e14f09822a96264ea372a (patch)
tree7c2534a2c851707e26b66010dfee9b9fc7590d29 /source3/locking/share_mode_lock.c
parent5006db98aaf1efe119f1da8be091587a9bc2b952 (diff)
downloadsamba-7d91ffc6fdc3b371564e14f09822a96264ea372a.tar.gz
samba-7d91ffc6fdc3b371564e14f09822a96264ea372a.tar.bz2
samba-7d91ffc6fdc3b371564e14f09822a96264ea372a.zip
smbd: Fix flawed share_mode_stale_pid API
The comment for this routine said: > Modifies d->num_share_modes, watch out in routines iterating over > that array. Well, it turns out that *every* caller of this API got it wrong. So I think it's better to change the routine. This leaves the array untouched while iterating but filters out the deleted ones while saving them back to disk. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'source3/locking/share_mode_lock.c')
-rw-r--r--source3/locking/share_mode_lock.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index 0693cf5408..342f9108d6 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -121,6 +121,7 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
{
struct share_mode_data *d;
enum ndr_err_code ndr_err;
+ uint32_t i;
DATA_BLOB blob;
d = talloc(mem_ctx, struct share_mode_data);
@@ -140,6 +141,14 @@ static struct share_mode_data *parse_share_modes(TALLOC_CTX *mem_ctx,
goto fail;
}
+ /*
+ * Initialize the values that are [skip] in the idl. The NDR code does
+ * not initialize them.
+ */
+
+ for (i=0; i<d->num_share_modes; i++) {
+ d->share_modes[i].stale = false;
+ }
d->modified = false;
d->fresh = false;
@@ -162,12 +171,27 @@ static TDB_DATA unparse_share_modes(struct share_mode_data *d)
{
DATA_BLOB blob;
enum ndr_err_code ndr_err;
+ uint32_t i;
if (DEBUGLEVEL >= 10) {
DEBUG(10, ("unparse_share_modes:\n"));
NDR_PRINT_DEBUG(share_mode_data, d);
}
+ i = 0;
+ while (i < d->num_share_modes) {
+ if (d->share_modes[i].stale) {
+ /*
+ * Remove the stale entries before storing
+ */
+ struct share_mode_entry *m = d->share_modes;
+ m[i] = m[d->num_share_modes-1];
+ d->num_share_modes -= 1;
+ } else {
+ i += 1;
+ }
+ }
+
if (d->num_share_modes == 0) {
DEBUG(10, ("No used share mode found\n"));
return make_tdb_data(NULL, 0);