mirror of
https://github.com/samba-team/samba.git
synced 2025-03-27 22:50:26 +03:00
s3:dbwrap: convert dbwrap_fetch(), dbwrap_fetch_bystring() and dbwrap_fetch_bystring_upper() to NTSTATUS
This commit is contained in:
parent
25a9978c2c
commit
0e28448a78
@ -173,6 +173,7 @@ static bool get_group_map_from_sid(struct dom_sid sid, GROUP_MAP *map)
|
||||
TDB_DATA dbuf;
|
||||
char *key;
|
||||
int ret = 0;
|
||||
NTSTATUS status;
|
||||
|
||||
/* the key is the SID, retrieving is direct */
|
||||
|
||||
@ -181,8 +182,8 @@ static bool get_group_map_from_sid(struct dom_sid sid, GROUP_MAP *map)
|
||||
return false;
|
||||
}
|
||||
|
||||
dbuf = dbwrap_fetch_bystring(db, key, key);
|
||||
if (dbuf.dptr == NULL) {
|
||||
status = dbwrap_fetch_bystring(db, key, key, &dbuf);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
TALLOC_FREE(key);
|
||||
return false;
|
||||
}
|
||||
@ -404,8 +405,8 @@ static NTSTATUS one_alias_membership(const struct dom_sid *member,
|
||||
slprintf(key, sizeof(key), "%s%s", MEMBEROF_PREFIX,
|
||||
sid_to_fstring(tmp, member));
|
||||
|
||||
dbuf = dbwrap_fetch_bystring(db, frame, key);
|
||||
if (dbuf.dptr == NULL) {
|
||||
status = dbwrap_fetch_bystring(db, frame, key, &dbuf);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
TALLOC_FREE(frame);
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
@ -130,16 +130,18 @@ struct db_record *dbwrap_fetch_locked(struct db_context *db,
|
||||
return db->fetch_locked(db, mem_ctx, key);
|
||||
}
|
||||
|
||||
TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
TDB_DATA key)
|
||||
NTSTATUS dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
TDB_DATA key, TDB_DATA *value)
|
||||
{
|
||||
TDB_DATA result;
|
||||
|
||||
if (db->fetch(db, mem_ctx, key, &result) != 0) {
|
||||
return make_tdb_data(NULL, 0);
|
||||
if (value == NULL) {
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return result;
|
||||
if (db->fetch(db, mem_ctx, key, value) != 0) {
|
||||
return NT_STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
bool dbwrap_exists(struct db_context *db, TDB_DATA key)
|
||||
|
@ -72,8 +72,8 @@ struct db_record *dbwrap_fetch_locked(struct db_context *db,
|
||||
NTSTATUS dbwrap_delete(struct db_context *db, TDB_DATA key);
|
||||
NTSTATUS dbwrap_store(struct db_context *db, TDB_DATA key,
|
||||
TDB_DATA data, int flags);
|
||||
TDB_DATA dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
TDB_DATA key);
|
||||
NTSTATUS dbwrap_fetch(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
TDB_DATA key, TDB_DATA *value);
|
||||
bool dbwrap_exists(struct db_context *db, TDB_DATA key);
|
||||
NTSTATUS dbwrap_traverse(struct db_context *db,
|
||||
int (*f)(struct db_record*, void*),
|
||||
@ -100,8 +100,8 @@ int dbwrap_transaction_cancel(struct db_context *db);
|
||||
NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
|
||||
NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
|
||||
TDB_DATA data, int flags);
|
||||
TDB_DATA dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key);
|
||||
NTSTATUS dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key, TDB_DATA *value);
|
||||
|
||||
int32_t dbwrap_fetch_int32(struct db_context *db, const char *keystr);
|
||||
int dbwrap_store_int32(struct db_context *db, const char *keystr, int32_t v);
|
||||
@ -140,7 +140,7 @@ NTSTATUS dbwrap_trans_traverse(struct db_context *db,
|
||||
NTSTATUS dbwrap_delete_bystring_upper(struct db_context *db, const char *key);
|
||||
NTSTATUS dbwrap_store_bystring_upper(struct db_context *db, const char *key,
|
||||
TDB_DATA data, int flags);
|
||||
TDB_DATA dbwrap_fetch_bystring_upper(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key);
|
||||
NTSTATUS dbwrap_fetch_bystring_upper(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key, TDB_DATA *value);
|
||||
|
||||
#endif /* __DBWRAP_H__ */
|
||||
|
@ -458,10 +458,10 @@ NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
|
||||
return dbwrap_store(db, string_term_tdb_data(key), data, flags);
|
||||
}
|
||||
|
||||
TDB_DATA dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key)
|
||||
NTSTATUS dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key, TDB_DATA *value)
|
||||
{
|
||||
return dbwrap_fetch(db, mem_ctx, string_term_tdb_data(key));
|
||||
return dbwrap_fetch(db, mem_ctx, string_term_tdb_data(key), value);
|
||||
}
|
||||
|
||||
|
||||
@ -499,19 +499,19 @@ NTSTATUS dbwrap_store_bystring_upper(struct db_context *db, const char *key,
|
||||
return status;
|
||||
}
|
||||
|
||||
TDB_DATA dbwrap_fetch_bystring_upper(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key)
|
||||
NTSTATUS dbwrap_fetch_bystring_upper(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key, TDB_DATA *value)
|
||||
{
|
||||
char *key_upper;
|
||||
TDB_DATA result;
|
||||
NTSTATUS status;
|
||||
|
||||
key_upper = talloc_strdup_upper(talloc_tos(), key);
|
||||
if (key_upper == NULL) {
|
||||
return make_tdb_data(NULL, 0);
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
result = dbwrap_fetch_bystring(db, mem_ctx, key_upper);
|
||||
status = dbwrap_fetch_bystring(db, mem_ctx, key_upper, value);
|
||||
|
||||
talloc_free(key_upper);
|
||||
return result;
|
||||
return status;
|
||||
}
|
||||
|
@ -76,6 +76,7 @@ static bool get_privileges( const struct dom_sid *sid, uint64_t *mask )
|
||||
struct db_context *db = get_account_pol_db();
|
||||
fstring tmp, keystr;
|
||||
TDB_DATA data;
|
||||
NTSTATUS status;
|
||||
|
||||
/* Fail if the admin has not enable privileges */
|
||||
|
||||
@ -90,9 +91,9 @@ static bool get_privileges( const struct dom_sid *sid, uint64_t *mask )
|
||||
|
||||
fstr_sprintf(keystr, "%s%s", PRIVPREFIX, sid_to_fstring(tmp, sid));
|
||||
|
||||
data = dbwrap_fetch_bystring( db, talloc_tos(), keystr );
|
||||
status = dbwrap_fetch_bystring(db, talloc_tos(), keystr, &data);
|
||||
|
||||
if ( !data.dptr ) {
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(4, ("get_privileges: No privileges assigned to SID "
|
||||
"[%s]\n", sid_string_dbg(sid)));
|
||||
return False;
|
||||
|
@ -288,11 +288,11 @@ struct security_descriptor *get_share_security( TALLOC_CTX *ctx, const char *ser
|
||||
|
||||
TALLOC_FREE(c_servicename);
|
||||
|
||||
data = dbwrap_fetch_bystring(share_db, talloc_tos(), key);
|
||||
status = dbwrap_fetch_bystring(share_db, talloc_tos(), key, &data);
|
||||
|
||||
TALLOC_FREE(key);
|
||||
|
||||
if (data.dptr == NULL) {
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
return get_share_security_default(ctx, psize,
|
||||
SEC_RIGHTS_DIR_ALL);
|
||||
}
|
||||
|
@ -6399,6 +6399,7 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
|
||||
int iService = -1;
|
||||
char *canon_name;
|
||||
TDB_DATA data;
|
||||
NTSTATUS status;
|
||||
|
||||
if (ServiceHash == NULL) {
|
||||
return -1;
|
||||
@ -6406,9 +6407,13 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
|
||||
|
||||
canon_name = canonicalize_servicename(talloc_tos(), pszServiceName);
|
||||
|
||||
data = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name);
|
||||
status = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name,
|
||||
&data);
|
||||
|
||||
if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
|
||||
if (NT_STATUS_IS_OK(status) &&
|
||||
(data.dptr != NULL) &&
|
||||
(data.dsize == sizeof(iService)))
|
||||
{
|
||||
iService = *(int *)data.dptr;
|
||||
}
|
||||
|
||||
@ -8541,12 +8546,18 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
|
||||
}
|
||||
|
||||
{
|
||||
TDB_DATA data = dbwrap_fetch_bystring(
|
||||
ServiceHash, canon_name, canon_name);
|
||||
TDB_DATA data;
|
||||
NTSTATUS status;
|
||||
|
||||
status = dbwrap_fetch_bystring(ServiceHash, canon_name,
|
||||
canon_name, &data);
|
||||
|
||||
iService = -1;
|
||||
|
||||
if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
|
||||
if (NT_STATUS_IS_OK(status) &&
|
||||
(data.dptr != NULL) &&
|
||||
(data.dsize == sizeof(iService)))
|
||||
{
|
||||
iService = *(int *)data.dptr;
|
||||
}
|
||||
}
|
||||
|
@ -537,6 +537,7 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods,
|
||||
TDB_DATA data;
|
||||
fstring keystr;
|
||||
fstring name;
|
||||
NTSTATUS status;
|
||||
|
||||
if ( !user ) {
|
||||
DEBUG(0,("pdb_getsampwnam: struct samu is NULL.\n"));
|
||||
@ -559,8 +560,8 @@ static NTSTATUS tdbsam_getsampwnam (struct pdb_methods *my_methods,
|
||||
|
||||
/* get the record */
|
||||
|
||||
data = dbwrap_fetch_bystring(db_sam, talloc_tos(), keystr);
|
||||
if (!data.dptr) {
|
||||
status = dbwrap_fetch_bystring(db_sam, talloc_tos(), keystr, &data);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(5,("pdb_getsampwnam (TDB): error fetching database.\n"));
|
||||
DEBUGADD(5, (" Key: %s\n", keystr));
|
||||
return NT_STATUS_NO_SUCH_USER;
|
||||
@ -611,10 +612,10 @@ static NTSTATUS tdbsam_getsampwrid (struct pdb_methods *my_methods,
|
||||
|
||||
/* get the record */
|
||||
|
||||
data = dbwrap_fetch_bystring(db_sam, talloc_tos(), keystr);
|
||||
if (!data.dptr) {
|
||||
nt_status = dbwrap_fetch_bystring(db_sam, talloc_tos(), keystr, &data);
|
||||
if (!NT_STATUS_IS_OK(nt_status)) {
|
||||
DEBUG(5,("pdb_getsampwrid (TDB): error looking up RID %d by key %s.\n", rid, keystr));
|
||||
return NT_STATUS_UNSUCCESSFUL;
|
||||
return nt_status;
|
||||
}
|
||||
|
||||
fstrcpy(name, (const char *)data.dptr);
|
||||
|
@ -90,10 +90,9 @@ NTSTATUS printer_list_get_printer(TALLOC_CTX *mem_ctx,
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
data = dbwrap_fetch_bystring_upper(db, key, key);
|
||||
if (data.dptr == NULL) {
|
||||
status = dbwrap_fetch_bystring_upper(db, key, key, &data);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(1, ("Failed to fetch record!\n"));
|
||||
status = NT_STATUS_NOT_FOUND;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -216,10 +215,9 @@ NTSTATUS printer_list_get_last_refresh(time_t *last_refresh)
|
||||
|
||||
ZERO_STRUCT(data);
|
||||
|
||||
data = dbwrap_fetch_bystring(db, talloc_tos(), PL_TIMESTAMP_KEY);
|
||||
if (data.dptr == NULL) {
|
||||
status = dbwrap_fetch_bystring(db, talloc_tos(), PL_TIMESTAMP_KEY, &data);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(1, ("Failed to fetch record!\n"));
|
||||
status = NT_STATUS_NOT_FOUND;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
@ -1431,13 +1431,17 @@ static TDB_DATA regdb_fetch_key_internal(struct db_context *db,
|
||||
{
|
||||
char *path = NULL;
|
||||
TDB_DATA data;
|
||||
NTSTATUS status;
|
||||
|
||||
path = normalize_reg_path(mem_ctx, key);
|
||||
if (!path) {
|
||||
return make_tdb_data(NULL, 0);
|
||||
}
|
||||
|
||||
data = dbwrap_fetch_bystring(db, mem_ctx, path);
|
||||
status = dbwrap_fetch_bystring(db, mem_ctx, path, &data);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
data = tdb_null;
|
||||
}
|
||||
|
||||
TALLOC_FREE(path);
|
||||
return data;
|
||||
@ -1796,9 +1800,10 @@ static NTSTATUS regdb_store_values_internal(struct db_context *db,
|
||||
goto done;
|
||||
}
|
||||
|
||||
old_data = dbwrap_fetch_bystring(db, ctx, keystr);
|
||||
status = dbwrap_fetch_bystring(db, ctx, keystr, &old_data);
|
||||
|
||||
if ((old_data.dptr != NULL)
|
||||
if (NT_STATUS_IS_OK(status)
|
||||
&& (old_data.dptr != NULL)
|
||||
&& (old_data.dsize == data.dsize)
|
||||
&& (memcmp(old_data.dptr, data.dptr, data.dsize) == 0))
|
||||
{
|
||||
@ -1871,8 +1876,8 @@ static WERROR regdb_get_secdesc(TALLOC_CTX *mem_ctx, const char *key,
|
||||
goto done;
|
||||
}
|
||||
|
||||
data = dbwrap_fetch_bystring(regdb, tmp_ctx, tdbkey);
|
||||
if (data.dptr == NULL) {
|
||||
status = dbwrap_fetch_bystring(regdb, tmp_ctx, tdbkey, &data);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
err = WERR_BADFILE;
|
||||
goto done;
|
||||
}
|
||||
|
@ -170,13 +170,15 @@ static WERROR regsubkey_ctr_index_for_keyname(struct regsubkey_ctr *ctr,
|
||||
uint32_t *idx)
|
||||
{
|
||||
TDB_DATA data;
|
||||
NTSTATUS status;
|
||||
|
||||
if ((ctr == NULL) || (keyname == NULL)) {
|
||||
return WERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
data = dbwrap_fetch_bystring_upper(ctr->subkeys_hash, ctr, keyname);
|
||||
if (data.dptr == NULL) {
|
||||
status = dbwrap_fetch_bystring_upper(ctr->subkeys_hash, ctr, keyname,
|
||||
&data);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
return WERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
|
@ -318,7 +318,10 @@ static int add_record(struct check_ctx* ctx, TDB_DATA key, TDB_DATA value)
|
||||
return -1;
|
||||
};
|
||||
if (rec->value.dptr == 0) { /* first entry */
|
||||
diff.oval = dbwrap_fetch(ctx->db, ctx->diff, key);
|
||||
status = dbwrap_fetch(ctx->db, ctx->diff, key, &diff.oval);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
diff.oval = tdb_null;
|
||||
}
|
||||
} else {
|
||||
diff = unpack_diff(rec->value);
|
||||
talloc_free(diff.nval.dptr);
|
||||
|
@ -136,6 +136,7 @@ static NTSTATUS idmap_autorid_id_to_sid(struct autorid_global_config *cfg,
|
||||
TDB_DATA data;
|
||||
char *keystr;
|
||||
struct dom_sid sid;
|
||||
NTSTATUS status;
|
||||
|
||||
/* can this be one of our ids? */
|
||||
if (map->xid.id < cfg->minvalue) {
|
||||
@ -160,10 +161,10 @@ static NTSTATUS idmap_autorid_id_to_sid(struct autorid_global_config *cfg,
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
data = dbwrap_fetch_bystring(autorid_db, talloc_tos(), keystr);
|
||||
status = dbwrap_fetch_bystring(autorid_db, talloc_tos(), keystr, &data);
|
||||
TALLOC_FREE(keystr);
|
||||
|
||||
if (!data.dptr) {
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(4, ("id %d belongs to range %d which does not have "
|
||||
"domain mapping, ignoring mapping request\n",
|
||||
map->xid.id, range));
|
||||
@ -383,10 +384,11 @@ static struct autorid_global_config *idmap_autorid_loadconfig(TALLOC_CTX * ctx)
|
||||
TDB_DATA data;
|
||||
struct autorid_global_config *cfg;
|
||||
unsigned long minvalue, rangesize, maxranges;
|
||||
NTSTATUS status;
|
||||
|
||||
data = dbwrap_fetch_bystring(autorid_db, ctx, CONFIGKEY);
|
||||
status = dbwrap_fetch_bystring(autorid_db, ctx, CONFIGKEY, &data);
|
||||
|
||||
if (!data.dptr) {
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
DEBUG(10, ("No saved config found\n"));
|
||||
return NULL;
|
||||
}
|
||||
|
@ -723,9 +723,9 @@ static NTSTATUS idmap_tdb_id_to_sid(struct idmap_domain *dom, struct id_map *map
|
||||
DEBUG(10,("Fetching record %s\n", keystr));
|
||||
|
||||
/* Check if the mapping exists */
|
||||
data = dbwrap_fetch_bystring(ctx->db, NULL, keystr);
|
||||
ret = dbwrap_fetch_bystring(ctx->db, NULL, keystr, &data);
|
||||
|
||||
if (!data.dptr) {
|
||||
if (!NT_STATUS_IS_OK(ret)) {
|
||||
DEBUG(10,("Record %s not found\n", keystr));
|
||||
ret = NT_STATUS_NONE_MAPPED;
|
||||
goto done;
|
||||
@ -772,8 +772,8 @@ static NTSTATUS idmap_tdb_sid_to_id(struct idmap_domain *dom, struct id_map *map
|
||||
DEBUG(10,("Fetching record %s\n", keystr));
|
||||
|
||||
/* Check if sid is present in database */
|
||||
data = dbwrap_fetch_bystring(ctx->db, tmp_ctx, keystr);
|
||||
if (!data.dptr) {
|
||||
ret = dbwrap_fetch_bystring(ctx->db, tmp_ctx, keystr, &data);
|
||||
if (!NT_STATUS_IS_OK(ret)) {
|
||||
DEBUG(10,("Record %s not found\n", keystr));
|
||||
ret = NT_STATUS_NONE_MAPPED;
|
||||
goto done;
|
||||
|
@ -355,8 +355,8 @@ static NTSTATUS idmap_tdb2_set_mapping_action(struct db_context *db,
|
||||
DEBUG(10, ("Storing %s <-> %s map\n", state->ksidstr, state->kidstr));
|
||||
|
||||
/* check wheter sid mapping is already present in db */
|
||||
data = dbwrap_fetch_bystring(db, tmp_ctx, state->ksidstr);
|
||||
if (data.dptr) {
|
||||
ret = dbwrap_fetch_bystring(db, tmp_ctx, state->ksidstr, &data);
|
||||
if (!NT_STATUS_IS_OK(ret)) {
|
||||
ret = NT_STATUS_OBJECT_NAME_COLLISION;
|
||||
goto done;
|
||||
}
|
||||
@ -585,9 +585,9 @@ static NTSTATUS idmap_tdb2_id_to_sid(struct idmap_domain *dom, struct id_map *ma
|
||||
DEBUG(10,("Fetching record %s\n", keystr));
|
||||
|
||||
/* Check if the mapping exists */
|
||||
data = dbwrap_fetch_bystring(ctx->db, keystr, keystr);
|
||||
status = dbwrap_fetch_bystring(ctx->db, keystr, keystr, &data);
|
||||
|
||||
if (!data.dptr) {
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
char *sidstr;
|
||||
struct idmap_tdb2_set_mapping_context store_state;
|
||||
|
||||
@ -659,8 +659,8 @@ static NTSTATUS idmap_tdb2_sid_to_id(struct idmap_domain *dom, struct id_map *ma
|
||||
DEBUG(10,("Fetching record %s\n", keystr));
|
||||
|
||||
/* Check if sid is present in database */
|
||||
data = dbwrap_fetch_bystring(ctx->db, tmp_ctx, keystr);
|
||||
if (!data.dptr) {
|
||||
ret = dbwrap_fetch_bystring(ctx->db, tmp_ctx, keystr, &data);
|
||||
if (!NT_STATUS_IS_OK(ret)) {
|
||||
char *idstr;
|
||||
struct idmap_tdb2_set_mapping_context store_state;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user