From 34721ad233227300d9c2e8b5483ba2c6c798a7da Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Sep 2005 20:36:07 +0000 Subject: r10042: Add in external LGPL library for accessing the share mode db. Allow others to examine & test. May not end up here eventually... Jeremy. (This used to be commit 7cc70ae63399eacd55bd0bf51ac2c7b004d761bf) --- source3/libsmb/smb_share_modes.c | 452 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 452 insertions(+) create mode 100644 source3/libsmb/smb_share_modes.c (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c new file mode 100644 index 0000000000..0ba68aed06 --- /dev/null +++ b/source3/libsmb/smb_share_modes.c @@ -0,0 +1,452 @@ +/* + Samba share mode database library external interface library. + Used by non-Samba products needing access to the Samba share mode db. + + Copyright (C) Jeremy Allison 2005. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "includes.h" +#include "smb_share_modes.h" + +/* + * open/close sharemode database. + */ + +struct smbdb_ctx *smb_share_mode_db_open(const char *db_path) +{ + struct smbdb_ctx *smb_db = SMB_MALLOC_P(struct smbdb_ctx); + + if (!smb_db) { + return NULL; + } + + memset(smb_db, '\0', sizeof(struct smbdb_ctx)); + + smb_db->smb_tdb = tdb_open_log(lock_path("locking.tdb"), + 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, + O_RDWR|O_CREAT, + 0644); + + if (!smb_db->smb_tdb) { + free(smb_db); + return NULL; + } + + /* Should check that this is the correct version.... */ + return smb_db; +} + +int smb_share_mode_db_close(struct smbdb_ctx *db_ctx) +{ + int ret = tdb_close(db_ctx->smb_tdb); + free(db_ctx); + return ret; +} + +/* Create locking key. */ + +struct samba_locking_key { + SMB_DEV_T dev; + SMB_INO_T ino; +}; + +static TDB_DATA get_locking_key(uint64_t dev, uint64_t ino) +{ + static struct samba_locking_key lk; + TDB_DATA ld; + + memset(&lk, '\0', sizeof(struct samba_locking_key)); + lk.dev = (SMB_DEV_T)dev; + lk.ino = (SMB_INO_T)ino; + ld.dptr = (char *)&lk; + ld.dsize = sizeof(lk); + return ld; +} + +/* + * lock/unlock entry in sharemode database. + */ + +int smb_lock_share_mode_entry(struct smbdb_ctx *db_ctx, + uint64_t dev, + uint64_t ino) +{ + return tdb_chainlock(db_ctx->smb_tdb, get_locking_key(dev, ino)); +} + +int smb_unlock_share_mode_entry(struct smbdb_ctx *db_ctx, + dev_t dev, + ino_t ino) +{ + return tdb_chainunlock(db_ctx->smb_tdb, get_locking_key(dev, ino)); +} + +/* Internal structure of Samba share mode db. */ +/* FIXME ! This should be moved into a Samba include file. */ + +struct locking_data { + union { + struct { + int num_share_mode_entries; + BOOL delete_on_close; + } s; + share_mode_entry dummy; /* Needed for alignment. */ + } u; + /* the following two entries are implicit + share_mode_entry modes[num_share_mode_entries]; + char file_name[]; + */ +}; + +/* + * Check if an external smb_share_mode_entry and an internal share_mode entry match. + */ + +static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, const share_mode_entry *entry) +{ + return (e_entry->pid == entry->pid && + e_entry->file_id == (uint32_t)entry->share_file_id && + e_entry->open_time.tv_sec == entry->time.tv_sec && + e_entry->open_time.tv_usec == entry->time.tv_usec && + e_entry->share_access == (uint32_t)entry->share_access && + e_entry->access_mask == (uint32_t)entry->access_mask && + e_entry->dev == (uint64_t)entry->dev && + e_entry->ino == (uint64_t)entry->inode); +} + +/* + * Create an internal Samba share_mode entry from an external smb_share_mode_entry. + */ + +static void create_share_mode_entry(share_mode_entry *out, const struct smb_share_mode_entry *in) +{ + memset(out, '\0', sizeof(share_mode_entry)); + + out->pid = in->pid; + out->share_file_id = (unsigned long)in->file_id; + out->time.tv_sec = in->open_time.tv_sec; + out->time.tv_usec = in->open_time.tv_usec; + out->share_access = in->share_access; + out->access_mask = in->access_mask; + out->dev = (SMB_DEV_T)in->dev; + out->inode = (SMB_INO_T)in->ino; +} + +/* + * Return the current share mode list for an open file. + * This uses similar (but simplified) logic to locking/locking.c + */ + +int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, + uint64_t dev, + uint64_t ino, + struct smb_share_mode_entry **pp_list, + unsigned char *p_delete_on_close) +{ + TDB_DATA db_data; + struct smb_share_mode_entry *list = NULL; + int num_share_modes = 0; + struct locking_data *ld = NULL; /* internal samba db state. */ + share_mode_entry *shares = NULL; + size_t i; + + *pp_list = NULL; + *p_delete_on_close = 0; + + db_data = tdb_fetch(db_ctx->smb_tdb, get_locking_key(dev, ino)); + if (!db_data.dptr) { + return 0; + } + + ld = (struct locking_data *)db_data.dptr; + num_share_modes = ld->u.s.num_share_mode_entries; + + if (!num_share_modes) { + free(db_data.dptr); + return 0; + } + + list = SMB_MALLOC_ARRAY(struct smb_share_mode_entry, num_share_modes); + if (!list) { + free(db_data.dptr); + return -1; + } + + memset(list, '\0', num_share_modes * sizeof(struct smb_share_mode_entry)); + + shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); + + for (i = 0; i < num_share_modes; i++) { + share_mode_entry *share = &shares[i]; + struct smb_share_mode_entry *sme = &list[i]; + pid_t pid = share->pid; + + /* Check this process really exists. */ + if (kill(pid, 0) == -1 && (errno == ESRCH)) { + continue; /* No longer exists. */ + } + + /* Copy into the external list. */ + sme->dev = (uint64_t)share->dev; + sme->ino = (uint64_t)share->inode; + sme->share_access = (uint32_t)share->share_access; + sme->access_mask = (uint32_t)share->access_mask; + sme->open_time.tv_sec = share->time.tv_sec; + sme->open_time.tv_usec = share->time.tv_usec; + sme->file_id = (uint32_t)share->share_file_id; + sme->pid = share->pid; + } + + if (i == 0) { + free(db_data.dptr); + free(list); + return 0; + } + + *p_delete_on_close = ld->u.s.delete_on_close; + *pp_list = list; + return i; +} + +/* + * Create an entry in the Samba share mode db. + */ + +int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, + uint64_t dev, + uint64_t ino, + const struct smb_share_mode_entry *new_entry, + const char *filename) /* Must be abolute utf8 path. */ +{ + TDB_DATA db_data; + TDB_DATA locking_key = get_locking_key(dev, ino); + int orig_num_share_modes = 0; + struct locking_data *ld = NULL; /* internal samba db state. */ + share_mode_entry *shares = NULL; + char *new_data_p = NULL; + size_t new_data_size = 0; + + db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); + if (!db_data.dptr) { + /* We must create the entry. */ + db_data.dptr = SMB_MALLOC(sizeof(struct locking_data) + sizeof(share_mode_entry) + strlen(filename) + 1); + if (!db_data.dptr) { + return -1; + } + ld = (struct locking_data *)db_data.dptr; + ld->u.s.num_share_mode_entries = 1; + ld->u.s.delete_on_close = 0; + shares = (share_mode_entry *)db_data.dptr + sizeof(struct locking_data); + create_share_mode_entry(shares, new_entry); + memcpy(db_data.dptr + sizeof(struct locking_data) + sizeof(share_mode_entry), + filename, + strlen(filename) + 1); + + db_data.dsize = sizeof(struct locking_data) + sizeof(share_mode_entry) + strlen(filename) + 1; + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) == -1) { + free(db_data.dptr); + return -1; + } + free(db_data.dptr); + return 0; + } + + /* Entry exists, we must add a new entry. */ + new_data_p = SMB_MALLOC(db_data.dsize + sizeof(share_mode_entry)); + if (!new_data_p) { + free(db_data.dptr); + return -1; + } + + ld = (struct locking_data *)db_data.dptr; + orig_num_share_modes = ld->u.s.num_share_mode_entries; + + /* Copy the original data. */ + memcpy(new_data_p, db_data.dptr, sizeof(struct locking_data) + (orig_num_share_modes*sizeof(share_mode_entry))); + + /* Add in the new share mode */ + shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes*sizeof(share_mode_entry))); + create_share_mode_entry(shares, new_entry); + + ld = (struct locking_data *)new_data_p; + ld->u.s.num_share_mode_entries++; + + /* Append the original filename */ + memcpy(new_data_p + sizeof(struct locking_data) + (ld->u.s.num_share_mode_entries * sizeof(share_mode_entry)), + db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry)), + db_data.dsize - (sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry)))); + + new_data_size = db_data.dsize + sizeof(share_mode_entry); + + free(db_data.dptr); + + db_data.dptr = new_data_p; + db_data.dsize = new_data_size; + + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { + free(db_data.dptr); + return -1; + } + free(db_data.dptr); + return 0; +} + +int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, + uint64_t dev, + uint64_t ino, + const struct smb_share_mode_entry *del_entry) +{ + TDB_DATA db_data; + TDB_DATA locking_key = get_locking_key(dev, ino); + int orig_num_share_modes = 0; + struct locking_data *ld = NULL; /* internal samba db state. */ + share_mode_entry *shares = NULL; + char *new_data_p = NULL; + size_t filename_size = 0; + size_t i; + + db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); + if (!db_data.dptr) { + return -1; /* Error - missing entry ! */ + } + + ld = (struct locking_data *)db_data.dptr; + orig_num_share_modes = ld->u.s.num_share_mode_entries; + shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); + + if (orig_num_share_modes == 1) { + /* Only one entry - better be ours... */ + if (!share_mode_entry_equal(del_entry, shares)) { + /* Error ! We can't delete someone else's entry ! */ + free(db_data.dptr); + return -1; + } + /* It's ours - just remove the entire record. */ + free(db_data.dptr); + return tdb_delete(db_ctx->smb_tdb, locking_key); + } + + /* More than one - allocate a new record minus the one we'll delete. */ + new_data_p = SMB_MALLOC(db_data.dsize - sizeof(share_mode_entry)); + if (!new_data_p) { + free(db_data.dptr); + return -1; + } + + /* Copy the header. */ + memcpy(new_data_p, db_data.dptr, sizeof(struct locking_data)); + + for (i = 0; i < orig_num_share_modes; i++) { + share_mode_entry *share = &shares[i]; + pid_t pid = share->pid; + + /* Check this process really exists. */ + if (kill(pid, 0) == -1 && (errno == ESRCH)) { + continue; /* No longer exists. */ + } + + if (share_mode_entry_equal(del_entry, share)) { + continue; /* This is our delete taget. */ + } + + memcpy(new_data_p + sizeof(struct locking_data) + (i*sizeof(share_mode_entry)), + share, sizeof(share_mode_entry) ); + } + + if (i == 0) { + /* None left after pruning. Delete record. */ + free(db_data.dptr); + free(new_data_p); + return tdb_delete(db_ctx->smb_tdb, locking_key); + } + + /* Copy the terminating filename. */ + filename_size = db_data.dsize - ( sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry))); + + memcpy(new_data_p + sizeof(struct locking_data) + (i*sizeof(share_mode_entry)), + db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry)), + filename_size); + + free(db_data.dptr); + + db_data.dptr = new_data_p; + + /* Re-save smaller record. */ + ld = (struct locking_data *)db_data.dptr; + ld->u.s.num_share_mode_entries = i; + + db_data.dsize = sizeof(struct locking_data) + (i*sizeof(share_mode_entry)) + filename_size; + + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { + free(db_data.dptr); + return -1; + } + free(db_data.dptr); + return 0; +} + +int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx, + uint64_t dev, + uint64_t ino, + const struct smb_share_mode_entry *set_entry, + const struct smb_share_mode_entry *new_entry) +{ + TDB_DATA db_data; + TDB_DATA locking_key = get_locking_key(dev, ino); + int num_share_modes = 0; + struct locking_data *ld = NULL; /* internal samba db state. */ + share_mode_entry *shares = NULL; + size_t i; + int found_entry = 0; + + db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); + if (!db_data.dptr) { + return -1; /* Error - missing entry ! */ + } + + ld = (struct locking_data *)db_data.dptr; + num_share_modes = ld->u.s.num_share_mode_entries; + shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); + + for (i = 0; i < num_share_modes; i++) { + share_mode_entry *share = &shares[i]; + pid_t pid = share->pid; + + /* Check this process really exists. */ + if (kill(pid, 0) == -1 && (errno == ESRCH)) { + continue; /* No longer exists. */ + } + + if (share_mode_entry_equal(set_entry, share)) { + create_share_mode_entry(share, new_entry); + break; + } + } + + if (!found_entry) { + free(db_data.dptr); + return -1; + } + + /* Save modified data. */ + if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { + free(db_data.dptr); + return -1; + } + free(db_data.dptr); + return 0; +} -- cgit From dcf4bc5e7fd8af2b9e5d8f53b3d65004cb4974ed Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Sep 2005 16:52:25 +0000 Subject: r10054: Actually use the given db path (:-) Jeremy. (This used to be commit ac7cf320dfa2fd980188e72c9b8baa726c5cdaa1) --- source3/libsmb/smb_share_modes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 0ba68aed06..180b5b4bfd 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -36,7 +36,11 @@ struct smbdb_ctx *smb_share_mode_db_open(const char *db_path) memset(smb_db, '\0', sizeof(struct smbdb_ctx)); - smb_db->smb_tdb = tdb_open_log(lock_path("locking.tdb"), + if (!db_path) { + db_path = lock_path("locking.tdb"); + } + + smb_db->smb_tdb = tdb_open_log(db_path, 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0644); -- cgit From 1ff0de8b6d3de21325d92e7ebffbc74602a13c49 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 9 Sep 2005 21:49:49 +0000 Subject: r10135: Remove external dependencies for libsmbsharemodes.so Jeremy. (This used to be commit 2521ae826f1a0344c882090832646d56f248488f) --- source3/libsmb/smb_share_modes.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 180b5b4bfd..1c95fe1a30 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -22,13 +22,18 @@ #include "includes.h" #include "smb_share_modes.h" +/* Remove the paranoid malloc checker. */ +#ifdef malloc +#undef malloc +#endif + /* * open/close sharemode database. */ struct smbdb_ctx *smb_share_mode_db_open(const char *db_path) { - struct smbdb_ctx *smb_db = SMB_MALLOC_P(struct smbdb_ctx); + struct smbdb_ctx *smb_db = (struct smbdb_ctx *)malloc(sizeof(struct smbdb_ctx)); if (!smb_db) { return NULL; @@ -36,11 +41,7 @@ struct smbdb_ctx *smb_share_mode_db_open(const char *db_path) memset(smb_db, '\0', sizeof(struct smbdb_ctx)); - if (!db_path) { - db_path = lock_path("locking.tdb"); - } - - smb_db->smb_tdb = tdb_open_log(db_path, + smb_db->smb_tdb = tdb_open(db_path, 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_RDWR|O_CREAT, 0644); @@ -184,7 +185,7 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, return 0; } - list = SMB_MALLOC_ARRAY(struct smb_share_mode_entry, num_share_modes); + list = (struct smb_share_mode_entry *)malloc(sizeof(struct smb_share_mode_entry)*num_share_modes); if (!list) { free(db_data.dptr); return -1; @@ -247,7 +248,7 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ - db_data.dptr = SMB_MALLOC(sizeof(struct locking_data) + sizeof(share_mode_entry) + strlen(filename) + 1); + db_data.dptr = malloc(sizeof(struct locking_data) + sizeof(share_mode_entry) + strlen(filename) + 1); if (!db_data.dptr) { return -1; } @@ -270,7 +271,7 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, } /* Entry exists, we must add a new entry. */ - new_data_p = SMB_MALLOC(db_data.dsize + sizeof(share_mode_entry)); + new_data_p = malloc(db_data.dsize + sizeof(share_mode_entry)); if (!new_data_p) { free(db_data.dptr); return -1; @@ -345,7 +346,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* More than one - allocate a new record minus the one we'll delete. */ - new_data_p = SMB_MALLOC(db_data.dsize - sizeof(share_mode_entry)); + new_data_p = malloc(db_data.dsize - sizeof(share_mode_entry)); if (!new_data_p) { free(db_data.dptr); return -1; -- cgit From b03137d568f598eb0b506c6c4871a1311bc682e7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Sep 2005 05:16:54 +0000 Subject: r10150: Fix from Steve Williams to make the args consistent (uint64_t). Jeremy. (This used to be commit 08de7261720f7bfd72396ea7c9777dc0734c4593) --- source3/libsmb/smb_share_modes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 1c95fe1a30..9e7f196b82 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -94,8 +94,8 @@ int smb_lock_share_mode_entry(struct smbdb_ctx *db_ctx, } int smb_unlock_share_mode_entry(struct smbdb_ctx *db_ctx, - dev_t dev, - ino_t ino) + uint64_t dev, + uint64_t ino) { return tdb_chainunlock(db_ctx->smb_tdb, get_locking_key(dev, ino)); } -- cgit From c2f9fdcb46c81415aefd7852ad1bd45e1762c90d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Sep 2005 16:54:59 +0000 Subject: r10204: I love valgrind :-). Found stupid missing parantheses :-). Jeremy. (This used to be commit b406a202128c1ba9800784ab8c571584b37c746b) --- source3/libsmb/smb_share_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 9e7f196b82..e0c2387793 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -255,7 +255,7 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, ld = (struct locking_data *)db_data.dptr; ld->u.s.num_share_mode_entries = 1; ld->u.s.delete_on_close = 0; - shares = (share_mode_entry *)db_data.dptr + sizeof(struct locking_data); + shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); create_share_mode_entry(shares, new_entry); memcpy(db_data.dptr + sizeof(struct locking_data) + sizeof(share_mode_entry), filename, -- cgit From 6a8ce7487b9282a6a6025c7b18bbe3bc1fc75178 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Sep 2005 22:23:59 +0000 Subject: r10215: Fix several memory corruption bugs now we're testing this. Jeremy. (This used to be commit 3d1207aaf66bafd84935b21dbe1a0fd8efeb661d) --- source3/libsmb/smb_share_modes.c | 70 +++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 33 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index e0c2387793..ddc4e13ff6 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -62,21 +62,14 @@ int smb_share_mode_db_close(struct smbdb_ctx *db_ctx) return ret; } -/* Create locking key. */ - -struct samba_locking_key { - SMB_DEV_T dev; - SMB_INO_T ino; -}; - static TDB_DATA get_locking_key(uint64_t dev, uint64_t ino) { - static struct samba_locking_key lk; + static struct locking_key lk; TDB_DATA ld; - memset(&lk, '\0', sizeof(struct samba_locking_key)); + memset(&lk, '\0', sizeof(struct locking_key)); lk.dev = (SMB_DEV_T)dev; - lk.ino = (SMB_INO_T)ino; + lk.inode = (SMB_INO_T)ino; ld.dptr = (char *)&lk; ld.dsize = sizeof(lk); return ld; @@ -168,6 +161,7 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, struct locking_data *ld = NULL; /* internal samba db state. */ share_mode_entry *shares = NULL; size_t i; + int list_num; *pp_list = NULL; *p_delete_on_close = 0; @@ -193,11 +187,12 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, memset(list, '\0', num_share_modes * sizeof(struct smb_share_mode_entry)); - shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); + shares = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); + list_num = 0; for (i = 0; i < num_share_modes; i++) { share_mode_entry *share = &shares[i]; - struct smb_share_mode_entry *sme = &list[i]; + struct smb_share_mode_entry *sme = &list[list_num]; pid_t pid = share->pid; /* Check this process really exists. */ @@ -214,9 +209,10 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, sme->open_time.tv_usec = share->time.tv_usec; sme->file_id = (uint32_t)share->share_file_id; sme->pid = share->pid; + list_num++; } - if (i == 0) { + if (list_num == 0) { free(db_data.dptr); free(list); return 0; @@ -224,7 +220,8 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, *p_delete_on_close = ld->u.s.delete_on_close; *pp_list = list; - return i; + free(db_data.dptr); + return list_num; } /* @@ -248,20 +245,20 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ - db_data.dptr = malloc(sizeof(struct locking_data) + sizeof(share_mode_entry) + strlen(filename) + 1); + db_data.dptr = malloc((2*sizeof(share_mode_entry)) + strlen(filename) + 1); if (!db_data.dptr) { return -1; } ld = (struct locking_data *)db_data.dptr; ld->u.s.num_share_mode_entries = 1; ld->u.s.delete_on_close = 0; - shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); + shares = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); create_share_mode_entry(shares, new_entry); - memcpy(db_data.dptr + sizeof(struct locking_data) + sizeof(share_mode_entry), + memcpy(db_data.dptr + 2*sizeof(share_mode_entry), filename, strlen(filename) + 1); - db_data.dsize = sizeof(struct locking_data) + sizeof(share_mode_entry) + strlen(filename) + 1; + db_data.dsize = 2*sizeof(share_mode_entry) + strlen(filename) + 1; if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) == -1) { free(db_data.dptr); return -1; @@ -281,19 +278,21 @@ int smb_create_share_mode_entry(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, sizeof(struct locking_data) + (orig_num_share_modes*sizeof(share_mode_entry))); + memcpy(new_data_p, db_data.dptr, (orig_num_share_modes+1)*sizeof(share_mode_entry)); /* Add in the new share mode */ - shares = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes*sizeof(share_mode_entry))); + shares = (share_mode_entry *)(new_data_p + + ((orig_num_share_modes+1)*sizeof(share_mode_entry))); + create_share_mode_entry(shares, new_entry); ld = (struct locking_data *)new_data_p; ld->u.s.num_share_mode_entries++; /* Append the original filename */ - memcpy(new_data_p + sizeof(struct locking_data) + (ld->u.s.num_share_mode_entries * sizeof(share_mode_entry)), - db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry)), - db_data.dsize - (sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry)))); + memcpy(new_data_p + ((ld->u.s.num_share_mode_entries+1)*sizeof(share_mode_entry)), + db_data.dptr + ((orig_num_share_modes+1)*sizeof(share_mode_entry)), + db_data.dsize - ((orig_num_share_modes+1) * sizeof(share_mode_entry))); new_data_size = db_data.dsize + sizeof(share_mode_entry); @@ -322,7 +321,8 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, share_mode_entry *shares = NULL; char *new_data_p = NULL; size_t filename_size = 0; - size_t i; + size_t i, num_share_modes; + const char *fname_ptr = NULL; db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { @@ -331,7 +331,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 = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); + shares = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); if (orig_num_share_modes == 1) { /* Only one entry - better be ours... */ @@ -353,8 +353,9 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* Copy the header. */ - memcpy(new_data_p, db_data.dptr, sizeof(struct locking_data)); + memcpy(new_data_p, db_data.dptr, sizeof(share_mode_entry)); + num_share_modes = 0; for (i = 0; i < orig_num_share_modes; i++) { share_mode_entry *share = &shares[i]; pid_t pid = share->pid; @@ -368,11 +369,13 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, continue; /* This is our delete taget. */ } - memcpy(new_data_p + sizeof(struct locking_data) + (i*sizeof(share_mode_entry)), + memcpy(new_data_p + ((num_share_modes+1)*sizeof(share_mode_entry)), share, sizeof(share_mode_entry) ); + + num_share_modes++; } - if (i == 0) { + if (num_share_modes == 0) { /* None left after pruning. Delete record. */ free(db_data.dptr); free(new_data_p); @@ -380,10 +383,11 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* Copy the terminating filename. */ - filename_size = db_data.dsize - ( sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry))); + fname_ptr = db_data.dptr + ((orig_num_share_modes+1) * sizeof(share_mode_entry)); + filename_size = db_data.dsize - (fname_ptr - db_data.dptr); - memcpy(new_data_p + sizeof(struct locking_data) + (i*sizeof(share_mode_entry)), - db_data.dptr + sizeof(struct locking_data) + (orig_num_share_modes * sizeof(share_mode_entry)), + memcpy(new_data_p + ((num_share_modes+1)*sizeof(share_mode_entry)), + fname_ptr, filename_size); free(db_data.dptr); @@ -392,9 +396,9 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, /* Re-save smaller record. */ ld = (struct locking_data *)db_data.dptr; - ld->u.s.num_share_mode_entries = i; + ld->u.s.num_share_mode_entries = num_share_modes; - db_data.dsize = sizeof(struct locking_data) + (i*sizeof(share_mode_entry)) + filename_size; + db_data.dsize = ((num_share_modes+1)*sizeof(share_mode_entry)) + filename_size; if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { free(db_data.dptr); -- cgit From f94d9826465b391faa4a4697e03459104065c115 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Sep 2005 23:11:23 +0000 Subject: r10217: Remember to exit correctly when we find a matching entry to change. Jeremy. (This used to be commit 142c84eb31a4f2577d5f4bb0f541440d84eb607f) --- source3/libsmb/smb_share_modes.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index ddc4e13ff6..87a386307c 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -429,7 +429,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 = (share_mode_entry *)(db_data.dptr + sizeof(struct locking_data)); + shares = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); for (i = 0; i < num_share_modes; i++) { share_mode_entry *share = &shares[i]; @@ -442,6 +442,7 @@ int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx, if (share_mode_entry_equal(set_entry, share)) { create_share_mode_entry(share, new_entry); + found_entry = 1; break; } } -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/libsmb/smb_share_modes.c | 93 ++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 41 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 87a386307c..7659d1cd6e 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -55,6 +55,12 @@ struct smbdb_ctx *smb_share_mode_db_open(const char *db_path) return smb_db; } +/* key and data records in the tdb locking database */ +struct locking_key { + SMB_DEV_T dev; + SMB_INO_T inode; +}; + int smb_share_mode_db_close(struct smbdb_ctx *db_ctx) { int ret = tdb_close(db_ctx->smb_tdb); @@ -102,10 +108,10 @@ struct locking_data { int num_share_mode_entries; BOOL delete_on_close; } s; - share_mode_entry dummy; /* Needed for alignment. */ + struct share_mode_entry dummy; /* Needed for alignment. */ } u; /* the following two entries are implicit - share_mode_entry modes[num_share_mode_entries]; + struct share_mode_entry modes[num_share_mode_entries]; char file_name[]; */ }; @@ -114,9 +120,9 @@ struct locking_data { * Check if an external smb_share_mode_entry and an internal share_mode entry match. */ -static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, const share_mode_entry *entry) +static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, const struct share_mode_entry *entry) { - return (e_entry->pid == entry->pid && + return (procid_equal(&e_entry->pid, &entry->pid) && e_entry->file_id == (uint32_t)entry->share_file_id && e_entry->open_time.tv_sec == entry->time.tv_sec && e_entry->open_time.tv_usec == entry->time.tv_usec && @@ -130,9 +136,9 @@ static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, co * Create an internal Samba share_mode entry from an external smb_share_mode_entry. */ -static void create_share_mode_entry(share_mode_entry *out, const struct smb_share_mode_entry *in) +static void create_share_mode_entry(struct share_mode_entry *out, const struct smb_share_mode_entry *in) { - memset(out, '\0', sizeof(share_mode_entry)); + memset(out, '\0', sizeof(struct share_mode_entry)); out->pid = in->pid; out->share_file_id = (unsigned long)in->file_id; @@ -159,7 +165,7 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, struct smb_share_mode_entry *list = NULL; int num_share_modes = 0; struct locking_data *ld = NULL; /* internal samba db state. */ - share_mode_entry *shares = NULL; + struct share_mode_entry *shares = NULL; size_t i; int list_num; @@ -187,19 +193,24 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, memset(list, '\0', num_share_modes * sizeof(struct smb_share_mode_entry)); - shares = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); + shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); list_num = 0; for (i = 0; i < num_share_modes; i++) { - share_mode_entry *share = &shares[i]; + struct share_mode_entry *share = &shares[i]; struct smb_share_mode_entry *sme = &list[list_num]; - pid_t pid = share->pid; + struct process_id pid = share->pid; /* Check this process really exists. */ - if (kill(pid, 0) == -1 && (errno == ESRCH)) { + if (kill(procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { continue; /* No longer exists. */ } + /* Ignore deferred open entries. */ + if (share->op_type == DEFERRED_OPEN_ENTRY) { + continue; + } + /* Copy into the external list. */ sme->dev = (uint64_t)share->dev; sme->ino = (uint64_t)share->inode; @@ -238,27 +249,27 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, TDB_DATA locking_key = get_locking_key(dev, ino); int orig_num_share_modes = 0; struct locking_data *ld = NULL; /* internal samba db state. */ - share_mode_entry *shares = NULL; + struct share_mode_entry *shares = NULL; char *new_data_p = NULL; size_t new_data_size = 0; db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ - db_data.dptr = malloc((2*sizeof(share_mode_entry)) + strlen(filename) + 1); + db_data.dptr = malloc((2*sizeof(struct share_mode_entry)) + strlen(filename) + 1); if (!db_data.dptr) { return -1; } ld = (struct locking_data *)db_data.dptr; ld->u.s.num_share_mode_entries = 1; ld->u.s.delete_on_close = 0; - shares = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); + shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); create_share_mode_entry(shares, new_entry); - memcpy(db_data.dptr + 2*sizeof(share_mode_entry), + memcpy(db_data.dptr + 2*sizeof(struct share_mode_entry), filename, strlen(filename) + 1); - db_data.dsize = 2*sizeof(share_mode_entry) + strlen(filename) + 1; + db_data.dsize = 2*sizeof(struct share_mode_entry) + strlen(filename) + 1; if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_INSERT) == -1) { free(db_data.dptr); return -1; @@ -268,7 +279,7 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, } /* Entry exists, we must add a new entry. */ - new_data_p = malloc(db_data.dsize + sizeof(share_mode_entry)); + new_data_p = malloc(db_data.dsize + sizeof(struct share_mode_entry)); if (!new_data_p) { free(db_data.dptr); return -1; @@ -278,11 +289,11 @@ int smb_create_share_mode_entry(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(share_mode_entry)); + memcpy(new_data_p, db_data.dptr, (orig_num_share_modes+1)*sizeof(struct share_mode_entry)); /* Add in the new share mode */ - shares = (share_mode_entry *)(new_data_p + - ((orig_num_share_modes+1)*sizeof(share_mode_entry))); + shares = (struct share_mode_entry *)(new_data_p + + ((orig_num_share_modes+1)*sizeof(struct share_mode_entry))); create_share_mode_entry(shares, new_entry); @@ -290,11 +301,11 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, ld->u.s.num_share_mode_entries++; /* Append the original filename */ - memcpy(new_data_p + ((ld->u.s.num_share_mode_entries+1)*sizeof(share_mode_entry)), - db_data.dptr + ((orig_num_share_modes+1)*sizeof(share_mode_entry)), - db_data.dsize - ((orig_num_share_modes+1) * sizeof(share_mode_entry))); + 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))); - new_data_size = db_data.dsize + sizeof(share_mode_entry); + new_data_size = db_data.dsize + sizeof(struct share_mode_entry); free(db_data.dptr); @@ -318,7 +329,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, TDB_DATA locking_key = get_locking_key(dev, ino); int orig_num_share_modes = 0; struct locking_data *ld = NULL; /* internal samba db state. */ - share_mode_entry *shares = NULL; + struct share_mode_entry *shares = NULL; char *new_data_p = NULL; size_t filename_size = 0; size_t i, num_share_modes; @@ -331,7 +342,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 = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); + shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); if (orig_num_share_modes == 1) { /* Only one entry - better be ours... */ @@ -346,22 +357,22 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* More than one - allocate a new record minus the one we'll delete. */ - new_data_p = malloc(db_data.dsize - sizeof(share_mode_entry)); + new_data_p = malloc(db_data.dsize - sizeof(struct share_mode_entry)); if (!new_data_p) { free(db_data.dptr); return -1; } /* Copy the header. */ - memcpy(new_data_p, db_data.dptr, sizeof(share_mode_entry)); + memcpy(new_data_p, db_data.dptr, sizeof(struct share_mode_entry)); num_share_modes = 0; for (i = 0; i < orig_num_share_modes; i++) { - share_mode_entry *share = &shares[i]; - pid_t pid = share->pid; + struct share_mode_entry *share = &shares[i]; + struct process_id pid = share->pid; /* Check this process really exists. */ - if (kill(pid, 0) == -1 && (errno == ESRCH)) { + if (kill(procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { continue; /* No longer exists. */ } @@ -369,8 +380,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(share_mode_entry)), - share, sizeof(share_mode_entry) ); + memcpy(new_data_p + ((num_share_modes+1)*sizeof(struct share_mode_entry)), + share, sizeof(struct share_mode_entry) ); num_share_modes++; } @@ -383,10 +394,10 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* Copy the terminating filename. */ - fname_ptr = db_data.dptr + ((orig_num_share_modes+1) * sizeof(share_mode_entry)); + fname_ptr = db_data.dptr + ((orig_num_share_modes+1) * sizeof(struct share_mode_entry)); filename_size = db_data.dsize - (fname_ptr - db_data.dptr); - memcpy(new_data_p + ((num_share_modes+1)*sizeof(share_mode_entry)), + memcpy(new_data_p + ((num_share_modes+1)*sizeof(struct share_mode_entry)), fname_ptr, filename_size); @@ -398,7 +409,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(share_mode_entry)) + filename_size; + db_data.dsize = ((num_share_modes+1)*sizeof(struct share_mode_entry)) + filename_size; if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) { free(db_data.dptr); @@ -418,7 +429,7 @@ int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx, TDB_DATA locking_key = get_locking_key(dev, ino); int num_share_modes = 0; struct locking_data *ld = NULL; /* internal samba db state. */ - share_mode_entry *shares = NULL; + struct share_mode_entry *shares = NULL; size_t i; int found_entry = 0; @@ -429,14 +440,14 @@ 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 = (share_mode_entry *)(db_data.dptr + sizeof(share_mode_entry)); + shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); for (i = 0; i < num_share_modes; i++) { - share_mode_entry *share = &shares[i]; - pid_t pid = share->pid; + struct share_mode_entry *share = &shares[i]; + struct process_id pid = share->pid; /* Check this process really exists. */ - if (kill(pid, 0) == -1 && (errno == ESRCH)) { + if (kill(procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { continue; /* No longer exists. */ } -- cgit From a04dd5f4ad14b58664060411dcaeef8a935d3bd8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Oct 2005 20:36:21 +0000 Subject: r11379: Remove external dependencies from sharemodes library. Jeremy. (This used to be commit 7fb05872612c9e1816ac24d25a020073e3b41950) --- source3/libsmb/smb_share_modes.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 7659d1cd6e..40ccf15f94 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -3,6 +3,12 @@ Used by non-Samba products needing access to the Samba share mode db. Copyright (C) Jeremy Allison 2005. + + sharemodes_procid functions (C) Copyright (C) Volker Lendecke 2005 + + ** NOTE! The following LGPL license applies to this module only. + ** This does NOT imply that all of Samba is released + ** under the LGPL This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -27,6 +33,16 @@ #undef malloc #endif +static BOOL sharemodes_procid_equal(const struct process_id *p1, const struct process_id *p2) +{ + return (p1->pid == p2->pid); +} + +static pid_t sharemodes_procid_to_pid(const struct process_id *proc) +{ + return proc->pid; +} + /* * open/close sharemode database. */ @@ -122,7 +138,7 @@ struct locking_data { static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, const struct share_mode_entry *entry) { - return (procid_equal(&e_entry->pid, &entry->pid) && + return (sharemodes_procid_equal(&e_entry->pid, &entry->pid) && e_entry->file_id == (uint32_t)entry->share_file_id && e_entry->open_time.tv_sec == entry->time.tv_sec && e_entry->open_time.tv_usec == entry->time.tv_usec && @@ -202,7 +218,7 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, struct process_id pid = share->pid; /* Check this process really exists. */ - if (kill(procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { + if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { continue; /* No longer exists. */ } @@ -372,7 +388,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, struct process_id pid = share->pid; /* Check this process really exists. */ - if (kill(procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { + if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { continue; /* No longer exists. */ } @@ -447,7 +463,7 @@ int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx, struct process_id pid = share->pid; /* Check this process really exists. */ - if (kill(procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { + if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { continue; /* No longer exists. */ } -- cgit From 7d2771e758d4e8ef0adb45e55775b524de4dba9a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Dec 2005 22:07:36 +0000 Subject: r12203: Add the share path into the sharemode db. This involves revving the minor version number for libsmbsharemodes (we now have a new _ex interface that takes the share path as well as the filename). Needed for #3303. Some code written by SATOH Fumiyasu included in the changes to locking/locking.c. The smbstatus output is a bit of a mess and needs overhauling... Jeremy. (This used to be commit 9d93af713f8520ca506730dd32aa2b994937eaba) --- source3/libsmb/smb_share_modes.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 40ccf15f94..43f25cd378 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -255,11 +255,12 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, * Create an entry in the Samba share mode db. */ -int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, +int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, const struct smb_share_mode_entry *new_entry, - const char *filename) /* Must be abolute utf8 path. */ + const char *sharepath, /* Must be absolute utf8 path. */ + const char *filename) /* Must be relative utf8 path. */ { TDB_DATA db_data; TDB_DATA locking_key = get_locking_key(dev, ino); @@ -272,7 +273,9 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ - db_data.dptr = malloc((2*sizeof(struct share_mode_entry)) + strlen(filename) + 1); + db_data.dptr = malloc((2*sizeof(struct share_mode_entry)) + + strlen(sharepath) + 1 + + strlen(filename) + 1); if (!db_data.dptr) { return -1; } @@ -281,11 +284,18 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, ld->u.s.delete_on_close = 0; shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); create_share_mode_entry(shares, new_entry); + memcpy(db_data.dptr + 2*sizeof(struct share_mode_entry), + sharepath, + strlen(sharepath) + 1); + memcpy(db_data.dptr + 2*sizeof(struct share_mode_entry) + + strlen(sharepath) + 1, filename, strlen(filename) + 1); - db_data.dsize = 2*sizeof(struct share_mode_entry) + strlen(filename) + 1; + db_data.dsize = 2*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) { free(db_data.dptr); return -1; @@ -336,6 +346,25 @@ int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, return 0; } +/* + * Create an entry in the Samba share mode db. Original interface - doesn't + * Distinguish between share path and filename. Fudge this by using a + * sharepath of / and a relative filename of (filename+1). + */ + +int smb_create_share_mode_entry(struct smbdb_ctx *db_ctx, + uint64_t dev, + uint64_t ino, + const struct smb_share_mode_entry *new_entry, + const char *filename) /* Must be absolute utf8 path. */ +{ + if (*filename != '/') { + abort(); + } + return smb_create_share_mode_entry_ex(db_ctx, dev, ino, new_entry, + "/", &filename[1]); +} + int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, -- cgit From 86c9bac4c31df1606e3758ec42672506dde26cc6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 1 Feb 2006 04:14:07 +0000 Subject: r13274: Fix for bug #3467. Not a show stopper. jason qian was a *fantastic* help in tracking this down. Jeremy. (This used to be commit 9f4a9c70fa232047868e5d8a3f132a2dd6bfee82) --- source3/libsmb/smb_share_modes.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 43f25cd378..86071ee2e9 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -123,6 +123,7 @@ struct locking_data { struct { int num_share_mode_entries; BOOL delete_on_close; + BOOL initial_delete_on_close; } s; struct share_mode_entry dummy; /* Needed for alignment. */ } u; @@ -282,6 +283,7 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, ld = (struct locking_data *)db_data.dptr; ld->u.s.num_share_mode_entries = 1; ld->u.s.delete_on_close = 0; + ld->u.s.initial_delete_on_close = 0; shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); create_share_mode_entry(shares, new_entry); -- cgit From 40d3c7ebb22bae6f486e8c60c3bb0494d2d397d9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 4 Feb 2006 06:31:04 +0000 Subject: r13329: Fix libsmbsharemodes.so to work with the stored delete token. Less trouble than I thought plus it didn't need an interface change (thank goodness !). Jeremy. (This used to be commit dbe2572d1c713f46b0d1d0c405f88456c9336297) --- source3/libsmb/smb_share_modes.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 86071ee2e9..f7e7baf445 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -2,7 +2,7 @@ Samba share mode database library external interface library. Used by non-Samba products needing access to the Samba share mode db. - Copyright (C) Jeremy Allison 2005. + Copyright (C) Jeremy Allison 2005 - 2006 sharemodes_procid functions (C) Copyright (C) Volker Lendecke 2005 @@ -25,6 +25,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + * Version 2 - interface changed to handle the token added for correct + * delete on close semantics. + */ + #include "includes.h" #include "smb_share_modes.h" @@ -115,9 +120,7 @@ int smb_unlock_share_mode_entry(struct smbdb_ctx *db_ctx, return tdb_chainunlock(db_ctx->smb_tdb, get_locking_key(dev, ino)); } -/* Internal structure of Samba share mode db. */ -/* FIXME ! This should be moved into a Samba include file. */ - +#if 0 struct locking_data { union { struct { @@ -132,12 +135,14 @@ struct locking_data { char file_name[]; */ }; +#endif /* * Check if an external smb_share_mode_entry and an internal share_mode entry match. */ -static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, const struct share_mode_entry *entry) +static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, + const struct share_mode_entry *entry) { return (sharemodes_procid_equal(&e_entry->pid, &entry->pid) && e_entry->file_id == (uint32_t)entry->share_file_id && @@ -153,7 +158,8 @@ static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, co * Create an internal Samba share_mode entry from an external smb_share_mode_entry. */ -static void create_share_mode_entry(struct share_mode_entry *out, const struct smb_share_mode_entry *in) +static void create_share_mode_entry(struct share_mode_entry *out, + const struct smb_share_mode_entry *in) { memset(out, '\0', sizeof(struct share_mode_entry)); @@ -281,9 +287,11 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, return -1; } ld = (struct locking_data *)db_data.dptr; + memset(ld, '\0', sizeof(struct locking_data)); ld->u.s.num_share_mode_entries = 1; ld->u.s.delete_on_close = 0; ld->u.s.initial_delete_on_close = 0; + ld->u.s.delete_token_size = 0; shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); create_share_mode_entry(shares, new_entry); @@ -328,7 +336,7 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, ld = (struct locking_data *)new_data_p; ld->u.s.num_share_mode_entries++; - /* Append the original filename */ + /* 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))); @@ -378,9 +386,9 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, struct locking_data *ld = NULL; /* internal samba db state. */ struct share_mode_entry *shares = NULL; char *new_data_p = NULL; - size_t filename_size = 0; + size_t remaining_size = 0; size_t i, num_share_modes; - const char *fname_ptr = NULL; + const char *remaining_ptr = NULL; db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { @@ -440,13 +448,13 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, return tdb_delete(db_ctx->smb_tdb, locking_key); } - /* Copy the terminating filename. */ - fname_ptr = db_data.dptr + ((orig_num_share_modes+1) * sizeof(struct share_mode_entry)); - filename_size = db_data.dsize - (fname_ptr - db_data.dptr); + /* Copy any delete token plus the terminating filenames. */ + remaining_ptr = db_data.dptr + ((orig_num_share_modes+1) * 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)), - fname_ptr, - filename_size); + remaining_ptr, + remaining_size); free(db_data.dptr); @@ -456,7 +464,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)) + filename_size; + db_data.dsize = ((num_share_modes+1)*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); -- cgit From 7f5e36df8d3fcee507325c97aeea41cbbd870e0d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 4 Feb 2006 06:36:02 +0000 Subject: r13331: No I didn't have to change the interface version... Jeremy. (This used to be commit 2aed5b36409e05ac25b4492669f47d50be988f2c) --- source3/libsmb/smb_share_modes.c | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index f7e7baf445..090571b810 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -25,11 +25,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* - * Version 2 - interface changed to handle the token added for correct - * delete on close semantics. - */ - #include "includes.h" #include "smb_share_modes.h" @@ -120,23 +115,6 @@ int smb_unlock_share_mode_entry(struct smbdb_ctx *db_ctx, return tdb_chainunlock(db_ctx->smb_tdb, get_locking_key(dev, ino)); } -#if 0 -struct locking_data { - union { - struct { - int num_share_mode_entries; - BOOL delete_on_close; - BOOL initial_delete_on_close; - } s; - struct share_mode_entry dummy; /* Needed for alignment. */ - } u; - /* the following two entries are implicit - struct share_mode_entry modes[num_share_mode_entries]; - char file_name[]; - */ -}; -#endif - /* * Check if an external smb_share_mode_entry and an internal share_mode entry match. */ -- cgit From 54ea3c23e3bfd25008198e85fdcc1f48b0325eab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 21 Jun 2006 02:31:12 +0000 Subject: r16435: Add in the uid info that Jerry needs into the share_mode struct. Allows us to know the unix uid of the opener of the file/directory. Needed for info level queries on open files. Jeremy. (This used to be commit d929323d6f513902381369d77bcd7b714346d713) --- source3/libsmb/smb_share_modes.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 090571b810..34ede9df29 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -149,6 +149,7 @@ static void create_share_mode_entry(struct share_mode_entry *out, out->access_mask = in->access_mask; out->dev = (SMB_DEV_T)in->dev; out->inode = (SMB_INO_T)in->ino; + out->uid = (uint32)geteuid(); } /* -- cgit From 467ec2a32bac08468855a5a28a7d6e25b26904d5 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 1 Aug 2006 12:45:12 +0000 Subject: r17363: Some C++ warnings (This used to be commit fd82f185a2e0f94bfb75f4eee072556ad94bf27d) --- source3/libsmb/smb_share_modes.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 34ede9df29..54477c4524 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -259,9 +259,10 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ - db_data.dptr = malloc((2*sizeof(struct share_mode_entry)) + - strlen(sharepath) + 1 + - strlen(filename) + 1); + db_data.dptr = (char *)malloc( + (2*sizeof(struct share_mode_entry)) + + strlen(sharepath) + 1 + + strlen(filename) + 1); if (!db_data.dptr) { return -1; } @@ -294,7 +295,8 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, } /* Entry exists, we must add a new entry. */ - new_data_p = malloc(db_data.dsize + sizeof(struct share_mode_entry)); + new_data_p = (char *)malloc( + db_data.dsize + sizeof(struct share_mode_entry)); if (!new_data_p) { free(db_data.dptr); return -1; @@ -391,7 +393,8 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* More than one - allocate a new record minus the one we'll delete. */ - new_data_p = malloc(db_data.dsize - sizeof(struct share_mode_entry)); + new_data_p = (char *)malloc( + db_data.dsize - sizeof(struct share_mode_entry)); if (!new_data_p) { free(db_data.dptr); return -1; -- cgit From e59e787b4868acffad49b6264e319d585643d5ab Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 20 Dec 2006 01:10:04 +0000 Subject: r20269: merge -r20264:20267 from SAMBA_3_0_24 more no previous prototype warnings (This used to be commit 41be182f78762372ae13759ede5d2bd40a71d7f5) --- source3/libsmb/smb_share_modes.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 54477c4524..b62240ce50 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -33,6 +33,10 @@ #undef malloc #endif +int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, uint64_t dev, + uint64_t ino, const struct smb_share_mode_entry *new_entry, + const char *sharepath, const char *filename); + static BOOL sharemodes_procid_equal(const struct process_id *p1, const struct process_id *p2) { return (p1->pid == p2->pid); -- cgit From c9a14ea19f812d86266bfa9e6ce8b32f7b4ff19f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Jan 2007 21:51:52 +0000 Subject: r20883: W00t! I now understand how "delete on close" really works - even with the strange "initial delete on close" semantics. The "initial delete on close" flag isn't committed to the share mode db until the handle is closed, and is discarded if any real "delete on close" was set. This allows me to remove the "initial_delete_on_close" flag from the share db, and move it into a BOOL in files_struct. Warning ! You must do a make clean after this. Cope with the wrinkle in directory delete on close which is done differently from files. We now pass all Samba4 smbtortute BASE-DELETE tests except for the one checking that files can't be created in a directory which has the delete on close set (possibly expensive to fix). Jeremy. (This used to be commit f2df77a1497958c1ea791f1d2f4446b5fc3389b3) --- source3/libsmb/smb_share_modes.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index b62240ce50..b8c7a7e66b 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -274,7 +274,6 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, memset(ld, '\0', sizeof(struct locking_data)); ld->u.s.num_share_mode_entries = 1; ld->u.s.delete_on_close = 0; - ld->u.s.initial_delete_on_close = 0; ld->u.s.delete_token_size = 0; shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry)); create_share_mode_entry(shares, new_entry); -- cgit From 7a5fa7f12ec439ef5a4af29aa86498f799b6b9a5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Feb 2007 21:05:34 +0000 Subject: r21191: Add in the POSIX open/mkdir/unlink calls. Move more error code returns to NTSTATUS. Client test code to follow... See if this passes the build-farm before I add it into 3.0.25. Jeremy. (This used to be commit 83dbbdff345fa9e427c9579183f4380004bf3dd7) --- source3/libsmb/smb_share_modes.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index b8c7a7e66b..4c49ecb7bd 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -154,6 +154,7 @@ static void create_share_mode_entry(struct share_mode_entry *out, out->dev = (SMB_DEV_T)in->dev; out->inode = (SMB_INO_T)in->ino; out->uid = (uint32)geteuid(); + out->flags = 0; } /* -- cgit From bc2b6436d0f5f3e9ffdfaeb7f1b32996a83d5478 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Mar 2007 09:35:51 +0000 Subject: r22009: change TDB_DATA from char * to unsigned char * and fix all compiler warnings in the users metze (This used to be commit 3a28443079c141a6ce8182c65b56ca210e34f37f) --- source3/libsmb/smb_share_modes.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 4c49ecb7bd..e98de5e264 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -96,7 +96,7 @@ static TDB_DATA get_locking_key(uint64_t dev, uint64_t ino) memset(&lk, '\0', sizeof(struct locking_key)); lk.dev = (SMB_DEV_T)dev; lk.inode = (SMB_INO_T)ino; - ld.dptr = (char *)&lk; + ld.dptr = (uint8 *)&lk; ld.dsize = sizeof(lk); return ld; } @@ -258,13 +258,13 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, int orig_num_share_modes = 0; struct locking_data *ld = NULL; /* internal samba db state. */ struct share_mode_entry *shares = NULL; - char *new_data_p = NULL; + uint8 *new_data_p = NULL; size_t new_data_size = 0; db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { /* We must create the entry. */ - db_data.dptr = (char *)malloc( + db_data.dptr = (uint8 *)malloc( (2*sizeof(struct share_mode_entry)) + strlen(sharepath) + 1 + strlen(filename) + 1); @@ -299,7 +299,7 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, } /* Entry exists, we must add a new entry. */ - new_data_p = (char *)malloc( + new_data_p = (uint8 *)malloc( db_data.dsize + sizeof(struct share_mode_entry)); if (!new_data_p) { free(db_data.dptr); @@ -370,10 +370,10 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, int orig_num_share_modes = 0; struct locking_data *ld = NULL; /* internal samba db state. */ struct share_mode_entry *shares = NULL; - char *new_data_p = NULL; + uint8 *new_data_p = NULL; size_t remaining_size = 0; size_t i, num_share_modes; - const char *remaining_ptr = NULL; + const uint8 *remaining_ptr = NULL; db_data = tdb_fetch(db_ctx->smb_tdb, locking_key); if (!db_data.dptr) { @@ -397,7 +397,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, } /* More than one - allocate a new record minus the one we'll delete. */ - new_data_p = (char *)malloc( + new_data_p = (uint8 *)malloc( db_data.dsize - sizeof(struct share_mode_entry)); if (!new_data_p) { free(db_data.dptr); -- cgit From 1ff60ed7bc75991449900670bc3e6b5b91c9003d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Mar 2007 22:12:28 +0000 Subject: r22012: Ensure we use the same technique to pull the share mode data out that locking/locking.c does. Jeremy. (This used to be commit 1fec4da6d6267289bf93f930de4cb5e21c450e15) --- source3/libsmb/smb_share_modes.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index e98de5e264..f78eaf8ca5 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -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]; -- cgit From 4e0a6bd9a7a66989dc53d2682c06451afb32199e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Apr 2007 18:12:25 +0000 Subject: r22154: Make struct smbdb_ctx an opaque pointer so users of the API don't need to have tdb.h. Jeremy. (This used to be commit 512542c90a78006bda3470eed7fb6d3f6e708eed) --- source3/libsmb/smb_share_modes.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index f78eaf8ca5..53f99d0f50 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -28,6 +28,11 @@ #include "includes.h" #include "smb_share_modes.h" +/* Database context handle. */ +struct smbdb_ctx { + TDB_CONTEXT *smb_tdb; +}; + /* Remove the paranoid malloc checker. */ #ifdef malloc #undef malloc -- cgit From e6383f47629368d9dd4e803f17566a24e9d7359e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 7 May 2007 09:35:35 +0000 Subject: r22736: Start to merge the low-hanging fruit from the now 7000-line cluster patch. This changes "struct process_id" to "struct server_id", keeping both is just too much hassle. No functional change (I hope ;-)) Volker (This used to be commit 0ad4b1226c9d91b72136310d3bbb640d2c5d67b8) --- source3/libsmb/smb_share_modes.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 53f99d0f50..da8d9e1fdc 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -42,12 +42,12 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, const struct smb_share_mode_entry *new_entry, const char *sharepath, const char *filename); -static BOOL sharemodes_procid_equal(const struct process_id *p1, const struct process_id *p2) +static BOOL sharemodes_procid_equal(const struct server_id *p1, const struct server_id *p2) { return (p1->pid == p2->pid); } -static pid_t sharemodes_procid_to_pid(const struct process_id *proc) +static pid_t sharemodes_procid_to_pid(const struct server_id *proc) { return proc->pid; } @@ -211,7 +211,7 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, for (i = 0; i < num_share_modes; i++) { struct share_mode_entry *share = &shares[i]; struct smb_share_mode_entry *sme = &list[list_num]; - struct process_id pid = share->pid; + struct server_id pid = share->pid; /* Check this process really exists. */ if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { @@ -416,7 +416,7 @@ int smb_delete_share_mode_entry(struct smbdb_ctx *db_ctx, num_share_modes = 0; for (i = 0; i < orig_num_share_modes; i++) { struct share_mode_entry *share = &shares[i]; - struct process_id pid = share->pid; + struct server_id pid = share->pid; /* Check this process really exists. */ if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { @@ -492,7 +492,7 @@ int smb_change_share_mode_entry(struct smbdb_ctx *db_ctx, for (i = 0; i < num_share_modes; i++) { struct share_mode_entry *share = &shares[i]; - struct process_id pid = share->pid; + struct server_id pid = share->pid; /* Check this process really exists. */ if (kill(sharemodes_procid_to_pid(&pid), 0) == -1 && (errno == ESRCH)) { -- cgit From e8156439f24137b5418baad20a7f00f6949cfe29 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 29 May 2007 09:30:34 +0000 Subject: r23183: Check in a change made by Tridge: This replaces the internal explicit dev/ino file id representation by a "struct file_id". This is necessary as cluster file systems and NFS don't necessarily assign the same device number to the shared file system. With this structure in place we can now easily add different schemes to map a file to a unique 64-bit device node. Jeremy, you might note that I did not change the external interface of smb_share_modes.c. Volker (This used to be commit 9b10dbbd5de8813fc15ebbb6be9b18010ffe8139) --- source3/libsmb/smb_share_modes.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index da8d9e1fdc..89395fe373 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -137,8 +137,8 @@ static int share_mode_entry_equal(const struct smb_share_mode_entry *e_entry, e_entry->open_time.tv_usec == entry->time.tv_usec && e_entry->share_access == (uint32_t)entry->share_access && e_entry->access_mask == (uint32_t)entry->access_mask && - e_entry->dev == (uint64_t)entry->dev && - e_entry->ino == (uint64_t)entry->inode); + e_entry->dev == entry->id.devid && + e_entry->ino == entry->id.inode); } /* @@ -156,8 +156,8 @@ static void create_share_mode_entry(struct share_mode_entry *out, out->time.tv_usec = in->open_time.tv_usec; out->share_access = in->share_access; out->access_mask = in->access_mask; - out->dev = (SMB_DEV_T)in->dev; - out->inode = (SMB_INO_T)in->ino; + out->id.devid = in->dev; + out->id.inode = in->ino; out->uid = (uint32)geteuid(); out->flags = 0; } @@ -224,8 +224,8 @@ int smb_get_share_mode_entries(struct smbdb_ctx *db_ctx, } /* Copy into the external list. */ - sme->dev = (uint64_t)share->dev; - sme->ino = (uint64_t)share->inode; + sme->dev = share->id.devid; + sme->ino = share->id.inode; sme->share_access = (uint32_t)share->share_access; sme->access_mask = (uint32_t)share->access_mask; sme->open_time.tv_sec = share->time.tv_sec; -- cgit From 2c09988e46d4e917b1c53c9bda3f81a48bba4952 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 01:44:42 +0000 Subject: r23790: LGPLv3+ conversion for our LGPLv2+ library code (This used to be commit 1b78cace504f60c0f525765fbf59d9cc6506cd4d) --- source3/libsmb/smb_share_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 89395fe373..77368de23f 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -13,7 +13,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 9fa1c63578733077c0aaaeeb2fc97c3b191089cc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit c676a971142d7176fd5dbf21405fca14515a0a76) --- source3/libsmb/smb_share_modes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index 77368de23f..b0cfc765d1 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -21,8 +21,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/libsmb/smb_share_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/smb_share_modes.c') diff --git a/source3/libsmb/smb_share_modes.c b/source3/libsmb/smb_share_modes.c index b0cfc765d1..16b3b10925 100644 --- a/source3/libsmb/smb_share_modes.c +++ b/source3/libsmb/smb_share_modes.c @@ -41,7 +41,7 @@ int smb_create_share_mode_entry_ex(struct smbdb_ctx *db_ctx, uint64_t dev, uint64_t ino, const struct smb_share_mode_entry *new_entry, const char *sharepath, const char *filename); -static BOOL sharemodes_procid_equal(const struct server_id *p1, const struct server_id *p2) +static bool sharemodes_procid_equal(const struct server_id *p1, const struct server_id *p2) { return (p1->pid == p2->pid); } -- cgit