]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
r22012: Ensure we use the same technique to pull the share mode
authorJeremy Allison <jra@samba.org>
Thu, 29 Mar 2007 22:12:28 +0000 (22:12 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:19:01 +0000 (12:19 -0500)
data out that locking/locking.c does.
Jeremy.

source/libsmb/smb_share_modes.c

index e98de5e264405e36989482d1dd501d6cd372227c..f78eaf8ca537cff25d9510f336abdaf797d22bff 100644 (file)
@@ -200,7 +200,7 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx,
 
        memset(list, '\0', num_share_modes * sizeof(struct smb_share_mode_entry));
 
-       shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry));
+       shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
 
        list_num = 0;
        for (i = 0; i < num_share_modes; i++) {
@@ -265,7 +265,8 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx,
        if (!db_data.dptr) {
                /* We must create the entry. */
                db_data.dptr = (uint8 *)malloc(
-                       (2*sizeof(struct share_mode_entry)) +
+                       sizeof(struct locking_data) +
+                       sizeof(struct share_mode_entry) +
                        strlen(sharepath) + 1 +
                        strlen(filename) + 1);
                if (!db_data.dptr) {
@@ -276,18 +277,18 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx,
                ld->u.s.num_share_mode_entries = 1;
                ld->u.s.delete_on_close = 0;
                ld->u.s.delete_token_size = 0;
-               shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry));
+               shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
                create_share_mode_entry(shares, new_entry);
 
-               memcpy(db_data.dptr + 2*sizeof(struct share_mode_entry),
+               memcpy(db_data.dptr + sizeof(struct locking_data) + sizeof(struct share_mode_entry),
                        sharepath,
                        strlen(sharepath) + 1);
-               memcpy(db_data.dptr + 2*sizeof(struct share_mode_entry) +
+               memcpy(db_data.dptr + sizeof(struct locking_data) + sizeof(struct share_mode_entry) +
                        strlen(sharepath) + 1,
                        filename,
                        strlen(filename) + 1);
 
-               db_data.dsize = 2*sizeof(struct share_mode_entry) +
+               db_data.dsize = sizeof(struct locking_data) + sizeof(struct share_mode_entry) +
                                        strlen(sharepath) + 1 +
                                        strlen(filename) + 1;
                if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) == -1) {
@@ -310,11 +311,11 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx,
        orig_num_share_modes = ld->u.s.num_share_mode_entries;
 
        /* Copy the original data. */
-       memcpy(new_data_p, db_data.dptr, (orig_num_share_modes+1)*sizeof(struct share_mode_entry));
+       memcpy(new_data_p, db_data.dptr, sizeof(struct locking_data) + (orig_num_share_modes * sizeof(struct share_mode_entry)));
 
        /* Add in the new share mode */
-       shares = (struct share_mode_entry *)(new_data_p +
-                       ((orig_num_share_modes+1)*sizeof(struct share_mode_entry)));
+       shares = (struct share_mode_entry *)(new_data_p + sizeof(struct locking_data) +
+                       (orig_num_share_modes * sizeof(struct share_mode_entry)));
 
        create_share_mode_entry(shares, new_entry);
 
@@ -322,9 +323,9 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx,
        ld->u.s.num_share_mode_entries++;
 
        /* Append the original delete_token and filenames. */
-       memcpy(new_data_p + ((ld->u.s.num_share_mode_entries+1)*sizeof(struct share_mode_entry)),
-               db_data.dptr + ((orig_num_share_modes+1)*sizeof(struct share_mode_entry)),
-               db_data.dsize - ((orig_num_share_modes+1) * sizeof(struct share_mode_entry)));
+       memcpy(new_data_p + sizeof(struct locking_data) + (ld->u.s.num_share_mode_entries * sizeof(struct share_mode_entry)),
+               db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(struct share_mode_entry)),
+               db_data.dsize - sizeof(struct locking_data) - (orig_num_share_modes * sizeof(struct share_mode_entry)));
 
        new_data_size = db_data.dsize + sizeof(struct share_mode_entry);
 
@@ -382,7 +383,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx,
 
        ld = (struct locking_data *)db_data.dptr;
        orig_num_share_modes = ld->u.s.num_share_mode_entries;
-       shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry));
+       shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
 
        if (orig_num_share_modes == 1) {
                /* Only one entry - better be ours... */
@@ -405,7 +406,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx,
        }
 
        /* Copy the header. */
-       memcpy(new_data_p, db_data.dptr, sizeof(struct share_mode_entry));
+       memcpy(new_data_p, db_data.dptr, sizeof(struct locking_data));
 
        num_share_modes = 0;
        for (i = 0; i < orig_num_share_modes; i++) {
@@ -421,7 +422,8 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx,
                        continue; /* This is our delete taget. */
                }
 
-               memcpy(new_data_p + ((num_share_modes+1)*sizeof(struct share_mode_entry)),
+               memcpy(new_data_p + sizeof(struct locking_data) +
+                               (num_share_modes * sizeof(struct share_mode_entry)),
                        share, sizeof(struct share_mode_entry) );
 
                num_share_modes++;
@@ -435,10 +437,10 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx,
        }
 
        /* Copy any delete token plus the terminating filenames. */
-       remaining_ptr = db_data.dptr + ((orig_num_share_modes+1) * sizeof(struct share_mode_entry));
+       remaining_ptr = db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(struct share_mode_entry));
        remaining_size = db_data.dsize - (remaining_ptr - db_data.dptr);
 
-       memcpy(new_data_p + ((num_share_modes+1)*sizeof(struct share_mode_entry)),
+       memcpy(new_data_p + sizeof(struct locking_data) + (num_share_modes * sizeof(struct share_mode_entry)),
                remaining_ptr,
                remaining_size);
 
@@ -450,7 +452,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx,
        ld = (struct locking_data *)db_data.dptr;
        ld->u.s.num_share_mode_entries = num_share_modes;
 
-       db_data.dsize = ((num_share_modes+1)*sizeof(struct share_mode_entry)) + remaining_size;
+       db_data.dsize = sizeof(struct locking_data) + (num_share_modes * sizeof(struct share_mode_entry)) + remaining_size;
 
        if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) {
                free(db_data.dptr);
@@ -481,7 +483,7 @@ int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx,
 
        ld = (struct locking_data *)db_data.dptr;
        num_share_modes = ld->u.s.num_share_mode_entries;
-       shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry));
+       shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
 
        for (i = 0; i < num_share_modes; i++) {
                struct share_mode_entry *share = &shares[i];