diff options
author | Michael Adam <obnox@samba.org> | 2010-06-17 08:35:28 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2010-08-14 02:10:51 +0200 |
commit | 2b2a8f9b3b283a39f391548775628e1aeb6fb811 (patch) | |
tree | f8fa5f264b1a7520b0ea9c25008b281af389a6ac /source3 | |
parent | b0615e475786faba1146949d5414518a0c2d05cf (diff) | |
download | samba-2b2a8f9b3b283a39f391548775628e1aeb6fb811.tar.gz samba-2b2a8f9b3b283a39f391548775628e1aeb6fb811.tar.bz2 samba-2b2a8f9b3b283a39f391548775628e1aeb6fb811.zip |
s3:idmap_tdb: use transaction wrapper for idmap_tdb_set_mapping().
Diffstat (limited to 'source3')
-rw-r--r-- | source3/winbindd/idmap_tdb.c | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c index 5b040542d9..fb56ffd451 100644 --- a/source3/winbindd/idmap_tdb.c +++ b/source3/winbindd/idmap_tdb.c @@ -734,14 +734,53 @@ done: set a mapping. **********************************/ +struct idmap_tdb_set_mapping_context { + const char *ksidstr; + const char *kidstr; +}; + +static NTSTATUS idmap_tdb_set_mapping_action(struct db_context *db, + void *private_data) +{ + NTSTATUS ret; + struct idmap_tdb_set_mapping_context *state; + + state = (struct idmap_tdb_set_mapping_context *)private_data; + + DEBUG(10, ("Storing %s <-> %s map\n", state->ksidstr, state->kidstr)); + + ret = dbwrap_store_bystring(db, state->ksidstr, + string_term_tdb_data(state->kidstr), + TDB_REPLACE); + if (!NT_STATUS_IS_OK(ret)) { + DEBUG(0, ("Error storing SID -> ID (%s -> %s): %s\n", + state->ksidstr, state->kidstr, nt_errstr(ret))); + goto done; + } + + ret = dbwrap_store_bystring(db, state->kidstr, + string_term_tdb_data(state->ksidstr), + TDB_REPLACE); + if (!NT_STATUS_IS_OK(ret)) { + DEBUG(0, ("Error storing ID -> SID (%s -> %s): %s\n", + state->kidstr, state->ksidstr, nt_errstr(ret))); + goto done; + } + + DEBUG(10,("Stored %s <-> %s\n", state->ksidstr, state->kidstr)); + ret = NT_STATUS_OK; + +done: + return ret; +} + static NTSTATUS idmap_tdb_set_mapping(struct idmap_domain *dom, const struct id_map *map) { struct idmap_tdb_context *ctx; NTSTATUS ret; - TDB_DATA ksid, kid; char *ksidstr, *kidstr; - fstring tmp; + struct idmap_tdb_set_mapping_context state; if (!map || !map->sid) { return NT_STATUS_INVALID_PARAMETER; @@ -776,48 +815,17 @@ static NTSTATUS idmap_tdb_set_mapping(struct idmap_domain *dom, goto done; } - if ((ksidstr = talloc_asprintf( - ctx, "%s", sid_to_fstring(tmp, map->sid))) == NULL) { + ksidstr = sid_string_talloc(ctx, map->sid); + if (ksidstr == NULL) { DEBUG(0, ("Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; goto done; } - DEBUG(10, ("Storing %s <-> %s map\n", ksidstr, kidstr)); - kid = string_term_tdb_data(kidstr); - ksid = string_term_tdb_data(ksidstr); - - if (ctx->db->transaction_start(ctx->db) != 0) { - DEBUG(0, ("Failed to start transaction for %s\n", - ksidstr)); - ret = NT_STATUS_INTERNAL_DB_ERROR; - goto done; - } - - ret = dbwrap_store(ctx->db, ksid, kid, TDB_REPLACE); - if (!NT_STATUS_IS_OK(ret)) { - ctx->db->transaction_cancel(ctx->db); - DEBUG(0, ("Error storing SID -> ID (%s -> %s): %s\n", - ksidstr, kidstr, nt_errstr(ret))); - goto done; - } - ret = dbwrap_store(ctx->db, kid, ksid, TDB_REPLACE); - if (!NT_STATUS_IS_OK(ret)) { - ctx->db->transaction_cancel(ctx->db); - DEBUG(0, ("Error storing ID -> SID (%s -> %s): %s\n", - kidstr, ksidstr, nt_errstr(ret))); - goto done; - } - - if (ctx->db->transaction_commit(ctx->db) != 0) { - DEBUG(0, ("Failed to commit transaction for (%s -> %s)\n", - ksidstr, kidstr)); - ret = NT_STATUS_INTERNAL_DB_ERROR; - goto done; - } + state.ksidstr = ksidstr; + state.kidstr = kidstr; - DEBUG(10,("Stored %s <-> %s\n", ksidstr, kidstr)); - ret = NT_STATUS_OK; + ret = dbwrap_trans_do(ctx->db, idmap_tdb_set_mapping_action, &state); done: talloc_free(ksidstr); |