[PATCH 2/7] lib/param: lpcfg_private_db_path()

Rusty Russell rusty at rustcorp.com.au
Tue Mar 26 19:37:19 MDT 2013


This wrapper avoids testing lpcfg_use_ntdb() everywhere.

Signed-off-by: Rusty Russell <rusty at rustcorp.com.au>
---
 lib/param/param.h |   15 +++++++++++++++
 lib/param/util.c  |   26 ++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/lib/param/param.h b/lib/param/param.h
index 18d4b29..7e73dd0 100644
--- a/lib/param/param.h
+++ b/lib/param/param.h
@@ -284,6 +284,21 @@ char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
 			    const char *name);
 
 /**
+ * @brief Returns an absolute path to a NTDB or TDB file in the Samba
+ * private directory.
+ *
+ * @param name File to find, relative to PRIVATEDIR, without .(n)tdb extension.
+ * Only provide fixed-string names which are supposed to change with "use ntdb"
+ * option.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path, for
+ * use with dbwrap_local_open().
+ **/
+char *lpcfg_private_db_path(TALLOC_CTX *mem_ctx,
+			    struct loadparm_context *lp_ctx,
+			    const char *name);
+
+/**
   return a path in the smbd.tmp directory, where all temporary file
   for smbd go. If NULL is passed for name then return the directory 
   path itself
diff --git a/lib/param/util.c b/lib/param/util.c
index f488540..c853678 100644
--- a/lib/param/util.c
+++ b/lib/param/util.c
@@ -190,6 +190,32 @@ char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
 }
 
 /**
+ * @brief Returns an absolute path to a NTDB or TDB file in the Samba
+ * private directory.
+ *
+ * @param name File to find, relative to PRIVATEDIR, without .(n)tdb extension.
+ * Only provide fixed-string names which are supposed to change with "use ntdb"
+ * option.
+ *
+ * @retval Pointer to a talloc'ed string containing the full path, for
+ * use with dbwrap_local_open().
+ **/
+char *lpcfg_private_db_path(TALLOC_CTX *mem_ctx,
+			    struct loadparm_context *lp_ctx,
+			    const char *name)
+{
+	const char *extension;
+
+	if (lpcfg_use_ntdb(lp_ctx))
+		extension = ".ntdb";
+	else
+		extension = ".tdb";
+
+	return talloc_asprintf(mem_ctx, "%s/%s%s",
+			       lpcfg_private_dir(lp_ctx), name, extension);
+}
+
+/**
   return a path in the smbd.tmp directory, where all temporary file
   for smbd go. If NULL is passed for name then return the directory 
   path itself
-- 
1.7.10.4



More information about the samba-technical mailing list