*/
#include "includes.h"
+#include "system/filesys.h"
#include "smb_share_modes.h"
/* Database context handle. */
memset(smb_db, '\0', sizeof(struct smbdb_ctx));
smb_db->smb_tdb = tdb_open(db_path,
- 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST,
+ 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
O_RDWR|O_CREAT,
0644);
*/
static void create_share_mode_entry(struct share_mode_entry *out,
- const struct smb_share_mode_entry *in)
+ const struct smb_share_mode_entry *in,
+ uint32_t name_hash)
{
memset(out, '\0', sizeof(struct share_mode_entry));
out->id.extid = in->extid;
out->uid = (uint32)geteuid();
out->flags = 0;
+ out->name_hash = name_hash;
}
/*
return 0;
}
- *p_delete_on_close = ld->u.s.delete_on_close;
+ *p_delete_on_close = ld->u.s.num_delete_token_entries != 0;
*pp_list = list;
free(db_data.dptr);
return list_num;
}
+static uint32_t smb_name_hash(const char *sharepath, const char *filename, int *err)
+{
+ TDB_DATA key;
+ char *fullpath = NULL;
+ size_t sharepath_size = strlen(sharepath);
+ size_t filename_size = strlen(filename);
+ uint32_t name_hash;
+
+ *err = 0;
+ fullpath = (char *)malloc(sharepath_size + filename_size + 2);
+ if (fullpath == NULL) {
+ *err = 1;
+ return 0;
+ }
+ memcpy(fullpath, sharepath, sharepath_size);
+ fullpath[sharepath_size] = '/';
+ memcpy(&fullpath[sharepath_size + 1], filename, filename_size + 1);
+
+ key.dptr = (uint8_t *)fullpath;
+ key.dsize = strlen(fullpath) + 1;
+ name_hash = tdb_jenkins_hash(&key);
+ free(fullpath);
+ return name_hash;
+}
+
/*
* Create an entry in the Samba share mode db.
*/
struct share_mode_entry *shares = NULL;
uint8 *new_data_p = NULL;
size_t new_data_size = 0;
+ int err = 0;
+ uint32_t name_hash = smb_name_hash(sharepath, filename, &err);
+
+ if (err) {
+ return -1;
+ }
db_data = tdb_fetch(db_ctx->smb_tdb, locking_key);
if (!db_data.dptr) {
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.delete_token_size = 0;
+ ld->u.s.num_delete_token_entries = 0;
shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct locking_data));
- create_share_mode_entry(shares, new_entry);
+ create_share_mode_entry(shares, new_entry, name_hash);
memcpy(db_data.dptr + sizeof(struct locking_data) + sizeof(struct share_mode_entry),
sharepath,
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);
+ create_share_mode_entry(shares, new_entry, name_hash);
ld = (struct locking_data *)new_data_p;
ld->u.s.num_share_mode_entries++;
- /* Append the original delete_token and filenames. */
+ /* Append the original delete_tokens and filenames. */
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)));
return tdb_delete(db_ctx->smb_tdb, locking_key);
}
- /* Copy any delete token plus the terminating filenames. */
+ /* Copy any delete tokens plus the terminating filenames. */
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);
}
if (share_mode_entry_equal(set_entry, share)) {
- create_share_mode_entry(share, new_entry);
+ create_share_mode_entry(share, new_entry, share->name_hash);
found_entry = 1;
break;
}