idmap_autorid_tdb: add idmap_autorid_getconfigstr()
authorMichael Adam <obnox@samba.org>
Wed, 28 Aug 2013 12:20:13 +0000 (14:20 +0200)
committerVolker Lendecke <vl@samba.org>
Tue, 1 Oct 2013 11:59:29 +0000 (11:59 +0000)
Pair-Programmed-With: Atul Kulkarni <atul.kulkarni@in.ibm.com>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Atul Kulkarni <atul.kulkarni@in.ibm.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/include/idmap_autorid_tdb.h
source3/winbindd/idmap_autorid_tdb.c

index 12151289cbe145098e5bc3e993628e265c8a502b..21e4ddbdc3748510ab046a01e1795c5b6b5e70ca 100644 (file)
@@ -69,4 +69,10 @@ struct autorid_global_config *idmap_autorid_loadconfig(struct db_context *db,
 NTSTATUS idmap_autorid_saveconfig(struct db_context *db,
                                  struct autorid_global_config *cfg);
 
+/**
+ * get the range config string stored in the database
+ */
+NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx,
+                                   char **result);
+
 #endif /* _IDMAP_AUTORID_H_ */
index fbb8a7cff60ea7e94a2dc2483a739f1baf321bb9..6933c9e31e717ed6378162fee06d95016634e580 100644 (file)
@@ -207,6 +207,60 @@ NTSTATUS idmap_autorid_db_init(const char *path,
        return status;
 }
 
+struct idmap_autorid_fetch_config_state {
+       TALLOC_CTX *mem_ctx;
+       char *configstr;
+};
+
+static void idmap_autorid_config_parser(TDB_DATA key, TDB_DATA value,
+                                       void *private_data)
+{
+       struct idmap_autorid_fetch_config_state *state;
+
+       state = (struct idmap_autorid_fetch_config_state *)private_data;
+
+       /*
+        * strndup because we have non-nullterminated strings in the db
+        */
+       state->configstr = talloc_strndup(
+               state->mem_ctx, (const char *)value.dptr, value.dsize);
+}
+
+NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx,
+                                   char **result)
+{
+       TDB_DATA key;
+       NTSTATUS status;
+       struct idmap_autorid_fetch_config_state state;
+
+       if (result == NULL) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       key = string_term_tdb_data(CONFIGKEY);
+
+       state.mem_ctx = mem_ctx;
+       state.configstr = NULL;
+
+       status = dbwrap_parse_record(db, key, idmap_autorid_config_parser,
+                                    &state);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("Error while retrieving config: %s\n",
+                         nt_errstr(status)));
+               return status;
+       }
+
+       if (state.configstr == NULL) {
+               DEBUG(1, ("Error while retrieving config\n"));
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       DEBUG(5, ("found CONFIG: %s\n", state.configstr));
+
+       *result = state.configstr;
+       return NT_STATUS_OK;
+}
+
 struct autorid_global_config *idmap_autorid_loadconfig(struct db_context *db,
                                                       TALLOC_CTX *ctx)
 {