Create the share security tdb.
********************************************************************/
-static TDB_CONTEXT *share_tdb; /* used for share security descriptors */
+static struct db_context *share_db; /* used for share security descriptors */
#define SHARE_DATABASE_VERSION_V1 1
#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
FILE_GENERIC_ALL
};
+static int delete_fn(struct db_record *rec, void *priv)
+{
+ rec->delete_rec(rec);
+ return 0;
+}
static bool share_info_db_init(void)
{
const char *vstring = "INFO/version";
int32 vers_id;
- if (share_tdb) {
+ if (share_db != NULL) {
return True;
}
- share_tdb = tdb_open_log(state_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
- if (!share_tdb) {
+ share_db = db_open_trans(NULL, state_path("share_info.tdb"), 0,
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ if (share_db == NULL) {
DEBUG(0,("Failed to open share info database %s (%s)\n",
state_path("share_info.tdb"), strerror(errno) ));
return False;
}
- /* handle a Samba upgrade */
- tdb_lock_bystring(share_tdb, vstring);
+ vers_id = dbwrap_fetch_int32(share_db, vstring);
+ if (vers_id == SHARE_DATABASE_VERSION_V2) {
+ return true;
+ }
+
+ if (share_db->transaction_start(share_db) != 0) {
+ DEBUG(0, ("transaction_start failed\n"));
+ TALLOC_FREE(share_db);
+ return false;
+ }
+
+ vers_id = dbwrap_fetch_int32(share_db, vstring);
+ if (vers_id == SHARE_DATABASE_VERSION_V2) {
+ /*
+ * Race condition
+ */
+ if (share_db->transaction_cancel(share_db)) {
+ smb_panic("transaction_cancel failed");
+ }
+ return true;
+ }
/* Cope with byte-reversed older versions of the db. */
- vers_id = tdb_fetch_int32(share_tdb, vstring);
if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
/* Written on a bigendian machine with old fetch_int code. Save as le. */
- tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
+
+ if (dbwrap_store_int32(share_db, vstring,
+ SHARE_DATABASE_VERSION_V2) != 0) {
+ DEBUG(0, ("dbwrap_store_int32 failed\n"));
+ goto cancel;
+ }
vers_id = SHARE_DATABASE_VERSION_V2;
}
if (vers_id != SHARE_DATABASE_VERSION_V2) {
- tdb_traverse(share_tdb, tdb_traverse_delete_fn, NULL);
- tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
+ if (share_db->traverse(share_db, delete_fn, NULL) != 0) {
+ DEBUG(0, ("wipe_all failed\n"));
+ goto cancel;
+ }
+ if (dbwrap_store_int32(share_db, vstring,
+ SHARE_DATABASE_VERSION_V2) != 0) {
+ DEBUG(0, ("dbwrap_store_int32 failed\n"));
+ goto cancel;
+ }
}
- tdb_unlock_bystring(share_tdb, vstring);
- return True;
+ if (share_db->transaction_commit(share_db) != 0) {
+ DEBUG(0, ("transaction_commit failed\n"));
+ goto cancel;
+ }
+
+ return true;
+
+ cancel:
+ if (share_db->transaction_cancel(share_db)) {
+ smb_panic("transaction_cancel failed");
+ }
+
+ return false;
}
/*******************************************************************
init_sec_ace(&ace, &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 1, &ace)) != NULL) {
- psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, psa, psize);
+ psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
+ SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
+ psa, psize);
}
if (!psd) {
return NULL;
}
- data = tdb_fetch_bystring(share_tdb, key);
+ data = dbwrap_fetch_bystring(share_db, talloc_tos(), key);
TALLOC_FREE(key);
status = unmarshall_sec_desc(ctx, data.dptr, data.dsize, &psd);
+ TALLOC_FREE(data.dptr);
+
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("unmarshall_sec_desc failed: %s\n",
nt_errstr(status)));
}
if (psd)
- *psize = sec_desc_size(psd);
+ *psize = ndr_size_security_descriptor(psd, 0);
return psd;
}
goto out;
}
- if (tdb_trans_store_bystring(share_tdb, key, blob,
- TDB_REPLACE) == -1) {
- DEBUG(1,("set_share_security: Failed to store secdesc for "
- "%s\n", share_name ));
+ status = dbwrap_trans_store(share_db, string_term_tdb_data(key), blob,
+ TDB_REPLACE);
+ if (!NT_STATUS_IS_OK(status)) {
+ DEBUG(1, ("set_share_security: Failed to store secdesc for "
+ "%s: %s\n", share_name, nt_errstr(status)));
goto out;
}
}
kbuf = string_term_tdb_data(key);
- if (tdb_trans_delete(share_tdb, kbuf) != 0) {
+ if (dbwrap_trans_delete(share_db, kbuf) != 0) {
DEBUG(0, ("delete_share_security: Failed to delete entry for "
"share %s\n", servicename));
return False;
{
uint32 granted;
NTSTATUS status;
- TALLOC_CTX *mem_ctx = NULL;
SEC_DESC *psd = NULL;
size_t sd_size;
bool ret = True;
- if (!(mem_ctx = talloc_init("share_access_check"))) {
- return False;
- }
-
- psd = get_share_security(mem_ctx, sharename, &sd_size);
+ psd = get_share_security(talloc_tos(), sharename, &sd_size);
if (!psd) {
- TALLOC_FREE(mem_ctx);
return True;
}
ret = se_access_check(psd, token, desired_access, &granted, &status);
- talloc_destroy(mem_ctx);
+ TALLOC_FREE(psd);
+
return ret;
}
uint32 s_access;
DOM_SID sid;
char *sidstr;
- uint8 type = SEC_ACE_TYPE_ACCESS_ALLOWED;
+ enum security_ace_type type = SEC_ACE_TYPE_ACCESS_ALLOWED;
if (!next_token_talloc(ctx, &pacl, &sidstr, ":")) {
DEBUG(0,("parse_usershare_acl: malformed usershare acl looking "
}
if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, num_aces, ace_list)) != NULL) {
- psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, psa, &sd_size);
+ psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
+ SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
+ psa, &sd_size);
}
if (!psd) {