+/*
+ * Internal structure of locking.tdb share mode db.
+ * Used by locking.c and libsmbsharemodes.c
+ */
+
+struct locking_data {
+ union {
+ struct {
+ int num_share_mode_entries;
+ BOOL delete_on_close;
+ BOOL initial_delete_on_close; /* Only set at NTCreateX if file was created. */
+ uint32 delete_token_size; /* Only valid if either of
+ the two previous fields
+ are True. */
+ } s;
+ struct share_mode_entry dummy; /* Needed for alignment. */
+ } u;
+ /* The following four entries are implicit
+ struct share_mode_entry modes[num_share_mode_entries];
+ char unix_token[delete_token_size] (divisible by 4).
+ char share_name[];
+ char file_name[];
+ */
+};
+
#define NT_HASH_LEN 16
#define LM_HASH_LEN 16
#define NT_HASH_LEN 16
#define LM_HASH_LEN 16
Samba share mode database library external interface library.
Used by non-Samba products needing access to the Samba share mode db.
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
sharemodes_procid functions (C) Copyright (C) Volker Lendecke 2005
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
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"
#include "includes.h"
#include "smb_share_modes.h"
return tdb_chainunlock(db_ctx->smb_tdb, get_locking_key(dev, 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 {
struct locking_data {
union {
struct {
/*
* Check if an external smb_share_mode_entry and an internal share_mode entry match.
*/
/*
* 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 &&
{
return (sharemodes_procid_equal(&e_entry->pid, &entry->pid) &&
e_entry->file_id == (uint32_t)entry->share_file_id &&
* Create an internal Samba share_mode entry from an external smb_share_mode_entry.
*/
* 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));
{
memset(out, '\0', sizeof(struct share_mode_entry));
return -1;
}
ld = (struct locking_data *)db_data.dptr;
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.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);
shares = (struct share_mode_entry *)(db_data.dptr + sizeof(struct share_mode_entry));
create_share_mode_entry(shares, new_entry);
ld = (struct locking_data *)new_data_p;
ld->u.s.num_share_mode_entries++;
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)));
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)));
struct locking_data *ld = NULL; /* internal samba db state. */
struct share_mode_entry *shares = NULL;
char *new_data_p = NULL;
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;
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) {
db_data = tdb_fetch(db_ctx->smb_tdb, locking_key);
if (!db_data.dptr) {
return tdb_delete(db_ctx->smb_tdb, locking_key);
}
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)),
memcpy(new_data_p + ((num_share_modes+1)*sizeof(struct share_mode_entry)),
- fname_ptr,
- filename_size);
+ remaining_ptr,
+ remaining_size);
ld = (struct locking_data *)db_data.dptr;
ld->u.s.num_share_mode_entries = num_share_modes;
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);
if (tdb_store(db_ctx->smb_tdb, locking_key, db_data, TDB_REPLACE) == -1) {
free(db_data.dptr);
/* the locking database handle */
static TDB_CONTEXT *tdb;
/* the locking database handle */
static TDB_CONTEXT *tdb;
-struct locking_data {
- union {
- struct {
- int num_share_mode_entries;
- BOOL delete_on_close;
- BOOL initial_delete_on_close; /* Only set at NTCreateX if file was created. */
- uint32 delete_token_size; /* Only valid if either of
- the two previous fields
- are True. */
- } 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[];
- */
-};
-
/****************************************************************************
Debugging aid :-).
****************************************************************************/
/****************************************************************************
Debugging aid :-).
****************************************************************************/