summaryrefslogtreecommitdiff
path: root/source3/winbindd/idmap_tdb.c
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2010-06-17 08:43:11 +0200
committerMichael Adam <obnox@samba.org>2010-08-14 02:10:51 +0200
commit47387b3ebb0d4d04403d0d65312d29af6bccc95a (patch)
treeb9838f61ccf9c2f22688c6fe6a8a43114f09e713 /source3/winbindd/idmap_tdb.c
parent2b2a8f9b3b283a39f391548775628e1aeb6fb811 (diff)
downloadsamba-47387b3ebb0d4d04403d0d65312d29af6bccc95a.tar.gz
samba-47387b3ebb0d4d04403d0d65312d29af6bccc95a.tar.bz2
samba-47387b3ebb0d4d04403d0d65312d29af6bccc95a.zip
s3:idmap_tdb: move the set_mapping code up
Diffstat (limited to 'source3/winbindd/idmap_tdb.c')
-rw-r--r--source3/winbindd/idmap_tdb.c207
1 files changed, 104 insertions, 103 deletions
diff --git a/source3/winbindd/idmap_tdb.c b/source3/winbindd/idmap_tdb.c
index fb56ffd451..b155bde81d 100644
--- a/source3/winbindd/idmap_tdb.c
+++ b/source3/winbindd/idmap_tdb.c
@@ -506,6 +506,110 @@ failed:
return ret;
}
+
+/**
+ * store a mapping in the database
+ */
+
+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;
+ char *ksidstr, *kidstr;
+ struct idmap_tdb_set_mapping_context state;
+
+ if (!map || !map->sid) {
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ ksidstr = kidstr = NULL;
+
+ /* TODO: should we filter a set_mapping using low/high filters ? */
+
+ ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
+
+ switch (map->xid.type) {
+
+ case ID_TYPE_UID:
+ kidstr = talloc_asprintf(ctx, "UID %lu",
+ (unsigned long)map->xid.id);
+ break;
+
+ case ID_TYPE_GID:
+ kidstr = talloc_asprintf(ctx, "GID %lu",
+ (unsigned long)map->xid.id);
+ break;
+
+ default:
+ DEBUG(2, ("INVALID unix ID type: 0x02%x\n", map->xid.type));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ if (kidstr == NULL) {
+ DEBUG(0, ("ERROR: Out of memory!\n"));
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ ksidstr = sid_string_talloc(ctx, map->sid);
+ if (ksidstr == NULL) {
+ DEBUG(0, ("Out of memory!\n"));
+ ret = NT_STATUS_NO_MEMORY;
+ goto done;
+ }
+
+ state.ksidstr = ksidstr;
+ state.kidstr = kidstr;
+
+ ret = dbwrap_trans_do(ctx->db, idmap_tdb_set_mapping_action, &state);
+
+done:
+ talloc_free(ksidstr);
+ talloc_free(kidstr);
+ return ret;
+}
+
/**********************************
Single id to sid lookup function.
**********************************/
@@ -731,109 +835,6 @@ 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;
- char *ksidstr, *kidstr;
- struct idmap_tdb_set_mapping_context state;
-
- if (!map || !map->sid) {
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- ksidstr = kidstr = NULL;
-
- /* TODO: should we filter a set_mapping using low/high filters ? */
-
- ctx = talloc_get_type(dom->private_data, struct idmap_tdb_context);
-
- switch (map->xid.type) {
-
- case ID_TYPE_UID:
- kidstr = talloc_asprintf(ctx, "UID %lu",
- (unsigned long)map->xid.id);
- break;
-
- case ID_TYPE_GID:
- kidstr = talloc_asprintf(ctx, "GID %lu",
- (unsigned long)map->xid.id);
- break;
-
- default:
- DEBUG(2, ("INVALID unix ID type: 0x02%x\n", map->xid.type));
- return NT_STATUS_INVALID_PARAMETER;
- }
-
- if (kidstr == NULL) {
- DEBUG(0, ("ERROR: Out of memory!\n"));
- ret = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- ksidstr = sid_string_talloc(ctx, map->sid);
- if (ksidstr == NULL) {
- DEBUG(0, ("Out of memory!\n"));
- ret = NT_STATUS_NO_MEMORY;
- goto done;
- }
-
- state.ksidstr = ksidstr;
- state.kidstr = kidstr;
-
- ret = dbwrap_trans_do(ctx->db, idmap_tdb_set_mapping_action, &state);
-
-done:
- talloc_free(ksidstr);
- talloc_free(kidstr);
- return ret;
-}
-
-/**********************************
Close the idmap tdb instance
**********************************/