lib/param: lpcfg_private_db_path()
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 11 Apr 2013 07:42:10 +0000 (17:12 +0930)
committerJeremy Allison <jra@samba.org>
Fri, 12 Apr 2013 21:59:23 +0000 (14:59 -0700)
This wrapper avoids testing lpcfg_use_ntdb() everywhere.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/param/param.h
lib/param/util.c

index 18d4b29ea05aeeb1f8d2bc1044079d3946acbe4c..7e73dd0f23403d67fd240acd085b3116b442a075 100644 (file)
@@ -283,6 +283,21 @@ char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
                            struct loadparm_context *lp_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 
index f488540b7fafcfe62c9e3fb6bf523a553939e079..29266c493d041c8b88f3926784b2d5bce535907a 100644 (file)
@@ -189,6 +189,33 @@ char *lpcfg_private_path(TALLOC_CTX* mem_ctx,
        return fname;
 }
 
+/**
+ * @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 = ".tdb";
+
+#ifndef DISABLE_NTDB
+       if (lpcfg_use_ntdb(lp_ctx)) {
+               extension = ".ntdb";
+       }
+#endif
+
+       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