Find default smb.conf path correctly, when it was not specified on the
authorJelmer Vernooij <jelmer@samba.org>
Fri, 16 Jan 2009 14:05:15 +0000 (15:05 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 16 Jan 2009 14:05:15 +0000 (15:05 +0100)
command-line.

source4/param/loadparm.c
source4/param/param.h
source4/param/pyparam.c
source4/scripting/python/samba/provision.py

index 2d9af333259d1b61218e232064e476af073d69ea..c1a012474b53f87f2b36395b32f84811eefad635 100644 (file)
@@ -2427,13 +2427,19 @@ const char *lp_configfile(struct loadparm_context *lp_ctx)
        return lp_ctx->szConfigFile;
 }
 
        return lp_ctx->szConfigFile;
 }
 
-bool lp_load_default(struct loadparm_context *lp_ctx)
+const char *lp_default_path(void)
 {
 {
-    const char *path;
     if (getenv("SMB_CONF_PATH"))
     if (getenv("SMB_CONF_PATH"))
-        path = getenv("SMB_CONF_PATH");
+        return getenv("SMB_CONF_PATH");
     else
     else
-        path = dyn_CONFIGFILE;
+        return dyn_CONFIGFILE;
+}
+
+bool lp_load_default(struct loadparm_context *lp_ctx)
+{
+    const char *path;
+
+    path = lp_default_path();
 
     if (!file_exist(path)) {
            /* We allow the default smb.conf file to not exist, 
 
     if (!file_exist(path)) {
            /* We allow the default smb.conf file to not exist, 
index ba0dbfd0fa3c6cfb2d9e0e3ee4093fad9836fb2c..3d257be062815a5079a27a81adfdf77eb1ae7e37 100644 (file)
@@ -279,6 +279,7 @@ void lp_killunused(struct loadparm_context *lp_ctx,
 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx);
 const char *lp_configfile(struct loadparm_context *lp_ctx);
 bool lp_load_default(struct loadparm_context *lp_ctx);
 struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx);
 const char *lp_configfile(struct loadparm_context *lp_ctx);
 bool lp_load_default(struct loadparm_context *lp_ctx);
+const char *lp_default_path(void);
 
 /**
  * Load the services array from the services file.
 
 /**
  * Load the services array from the services file.
index 0061eadc54e0c98f85aa1122de87accad499fe6a..42775908eac2c86524d978ff0b4d99dbd44dac3d 100644 (file)
@@ -358,6 +358,17 @@ struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx)
     return ret;
 }
 
     return ret;
 }
 
+static PyObject *py_default_path(PyObject *self)
+{
+    return PyString_FromString(lp_default_path());
+}
+
+static PyMethodDef pyparam_methods[] = {
+    { "default_path", (PyCFunction)py_default_path, METH_NOARGS, 
+        "Returns the default smb.conf path." },
+    { NULL }
+};
+
 void initparam(void)
 {
        PyObject *m;
 void initparam(void)
 {
        PyObject *m;
@@ -365,7 +376,7 @@ void initparam(void)
        if (PyType_Ready(&PyLoadparmContext) < 0)
                return;
 
        if (PyType_Ready(&PyLoadparmContext) < 0)
                return;
 
-       m = Py_InitModule3("param", NULL, "Parsing and writing Samba configuration files.");
+       m = Py_InitModule3("param", pyparam_methods, "Parsing and writing Samba configuration files.");
        if (m == NULL)
                return;
 
        if (m == NULL)
                return;
 
index 6becc78dc729061fe8ed6aaa74a59ae6cde1c210..70bd8ac7f60063f6ac9c093057197818a80c348c 100644 (file)
@@ -344,6 +344,9 @@ def guess_names(lp=None, hostname=None, domain=None, dnsdomain=None, serverrole=
 
 def make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, 
                  targetdir):
 
 def make_smbconf(smbconf, setup_path, hostname, domain, realm, serverrole, 
                  targetdir):
+    """Create a new smb.conf file based on a couple of basic settings.
+    """
+    assert smbconf is not None
     if hostname is None:
         hostname = socket.gethostname().split(".")[0].lower()
 
     if hostname is None:
         hostname = socket.gethostname().split(".")[0].lower()
 
@@ -947,6 +950,8 @@ def provision(setup_dir, message, session_info,
         if (not os.path.exists(os.path.join(targetdir, "etc"))):
             os.makedirs(os.path.join(targetdir, "etc"))
         smbconf = os.path.join(targetdir, "etc", "smb.conf")
         if (not os.path.exists(os.path.join(targetdir, "etc"))):
             os.makedirs(os.path.join(targetdir, "etc"))
         smbconf = os.path.join(targetdir, "etc", "smb.conf")
+    elif smbconf is None:
+        smbconf = param.default_path()
 
     # only install a new smb.conf if there isn't one there already
     if not os.path.exists(smbconf):
 
     # only install a new smb.conf if there isn't one there already
     if not os.path.exists(smbconf):
@@ -1178,6 +1183,9 @@ def provision_backend(setup_dir=None, message=None,
         if (not os.path.exists(os.path.join(targetdir, "etc"))):
             os.makedirs(os.path.join(targetdir, "etc"))
         smbconf = os.path.join(targetdir, "etc", "smb.conf")
         if (not os.path.exists(os.path.join(targetdir, "etc"))):
             os.makedirs(os.path.join(targetdir, "etc"))
         smbconf = os.path.join(targetdir, "etc", "smb.conf")
+    elif smbconf is None:
+        smbconf = param.default_path()
+        assert smbconf is not None
 
     # only install a new smb.conf if there isn't one there already
     if not os.path.exists(smbconf):
 
     # only install a new smb.conf if there isn't one there already
     if not os.path.exists(smbconf):