lib: Give lib/util/util_file.c its own header file
[samba.git] / source3 / param / loadparm.c
index 56a8bc2d28b5806357bcea4008a865ecb1546674..414d19d7439799c0e8a3246e7356b008baa9d825 100644 (file)
@@ -55,6 +55,7 @@
 
 #define LOADPARM_SUBSTITUTION_INTERNALS 1
 #include "includes.h"
+#include "lib/util/util_file.h"
 #include "system/filesys.h"
 #include "util_tdb.h"
 #include "lib/param/loadparm.h"
 #include "auth/credentials/credentials.h"
 #include "source3/lib/substitute.h"
 #include "source3/librpc/gen_ndr/ads.h"
+#include "lib/util/time_basic.h"
+#include "libds/common/flags.h"
 
 #ifdef HAVE_SYS_SYSCTL_H
 #include <sys/sysctl.h>
 #endif
 
-bool bLoaded = false;
+bool b_loaded = false;
 
 /* the special value for the include parameter
  * to be interpreted not as a file name but to
@@ -245,7 +248,6 @@ static const struct loadparm_service _sDefault =
        .aio_read_size = 1,
        .aio_write_size = 1,
        .map_readonly = MAP_READONLY_NO,
-       .directory_name_cache_size = 100,
        .server_smb_encrypt = SMB_ENCRYPTION_DEFAULT,
        .kernel_share_modes = false,
        .durable_handles = true,
@@ -503,7 +505,8 @@ static bool apply_lp_set_cmdline(void)
  Initialise the global parameter structure.
 ***************************************************************************/
 
-static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
+void loadparm_s3_init_globals(struct loadparm_context *lp_ctx,
+                             bool reinit_globals)
 {
        static bool done_init = false;
        char *s = NULL;
@@ -607,7 +610,7 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
         */
        Globals.nmbd_bind_explicit_broadcast = true;
 
-       s = talloc_asprintf(talloc_tos(), "Samba %s", samba_version_string());
+       s = talloc_asprintf(Globals.ctx, "Samba %s", samba_version_string());
        if (s == NULL) {
                smb_panic("init_globals: ENOMEM");
        }
@@ -755,7 +758,7 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
        Globals.ldap_debug_level = 0;
        Globals.ldap_debug_threshold = 10;
 
-       Globals.client_ldap_sasl_wrapping = ADS_AUTH_SASL_SIGN;
+       Globals.client_ldap_sasl_wrapping = ADS_AUTH_SASL_SEAL;
 
        Globals.ldap_server_require_strong_auth =
                LDAP_SERVER_REQUIRE_STRONG_AUTH_YES;
@@ -882,7 +885,7 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
 
        Globals.server_services = str_list_make_v3_const(NULL, "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns", NULL);
 
-       Globals.dcerpc_endpoint_servers = str_list_make_v3_const(NULL, "epmapper wkssvc rpcecho samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver", NULL);
+       Globals.dcerpc_endpoint_servers = str_list_make_v3_const(NULL, "epmapper wkssvc samr netlogon lsarpc drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver", NULL);
 
        Globals.tls_enabled = true;
        Globals.tls_verify_peer = TLS_VERIFY_PEER_AS_STRICT_AS_POSSIBLE;
@@ -950,6 +953,8 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
 
        Globals.kdc_enable_fast = true;
 
+       Globals.winbind_debug_traceid = true;
+
        Globals.aio_max_threads = 100;
 
        lpcfg_string_set(Globals.ctx,
@@ -994,6 +999,10 @@ static void init_globals(struct loadparm_context *lp_ctx, bool reinit_globals)
         */
        Globals.rpc_start_on_demand_helpers = true;
 
+       Globals.ad_dc_functional_level = DS_DOMAIN_FUNCTION_2008_R2,
+
+       Globals.acl_claims_evaluation = ACL_CLAIMS_EVALUATION_AD_DC_ONLY;
+
        /* Now put back the settings that were set with lp_set_cmdline() */
        apply_lp_set_cmdline();
 }
@@ -1705,7 +1714,7 @@ bool lp_add_printer(const char *pszPrintername, int iDefaultService)
                         pszPrintername);
        lpcfg_string_set(ServicePtrs[i], &ServicePtrs[i]->comment, comment);
 
-       /* set the browseable flag from the gloabl default */
+       /* set the browseable flag from the global default */
        ServicePtrs[i]->browseable = sDefault.browseable;
 
        /* Printers cannot be read_only. */
@@ -1781,7 +1790,7 @@ bool lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
 /**************************************************************************
  Determine the canonical name for a parameter.
  Turn the value given into the inverse boolean expression when
- the synonym is an invers boolean synonym.
+ the synonym is an inverse boolean synonym.
 
  Return true if
  - parm_name is a valid parameter name and
@@ -1842,7 +1851,7 @@ static int map_parameter_canonical(const char *pszParmName, bool *inverse)
 
        parm_num = lpcfg_map_parameter(pszParmName);
        if ((parm_num < 0) || !(parm_table[parm_num].flags & FLAG_SYNONYM)) {
-               /* invalid, parametric or no canidate for synonyms ... */
+               /* invalid, parametric or no candidate for synonyms ... */
                goto done;
        }
 
@@ -2408,8 +2417,15 @@ bool lp_file_list_changed(void)
                                return true;
                        }
                } else {
-                       time_t mod_time;
+                       struct timespec mod_time = {
+                               .tv_sec = 0,
+                       };
+                       struct timeval_buf tbuf = {
+                               .buf = {0},
+                       };
                        char *n2 = NULL;
+                       struct stat sb = {0};
+                       int rc;
 
                        n2 = talloc_sub_basic(talloc_tos(),
                                              get_current_username(),
@@ -2419,19 +2435,29 @@ bool lp_file_list_changed(void)
                                return false;
                        }
                        DEBUGADD(6, ("file %s -> %s  last mod_time: %s\n",
-                                    f->name, n2, ctime(&f->modtime)));
-
-                       mod_time = file_modtime(n2);
+                                    f->name, n2,
+                                    timespec_string_buf(&f->modtime,
+                                                        true,
+                                                        &tbuf)));
+
+                       rc = stat(n2, &sb);
+                       if (rc == 0) {
+                               mod_time = get_mtimespec(&sb);
+                       }
 
-                       if (mod_time &&
-                           ((f->modtime != mod_time) ||
+                       if (mod_time.tv_sec > 0 &&
+                           ((timespec_compare(&mod_time, &f->modtime) != 0) ||
                             (f->subfname == NULL) ||
                             (strcmp(n2, f->subfname) != 0)))
                        {
+                               f->modtime = mod_time;
+
                                DEBUGADD(6,
                                         ("file %s modified: %s\n", n2,
-                                         ctime(&mod_time)));
-                               f->modtime = mod_time;
+                                         timespec_string_buf(&f->modtime,
+                                                             true,
+                                                             &tbuf)));
+
                                TALLOC_FREE(f->subfname);
                                f->subfname = talloc_strdup(f, n2);
                                if (f->subfname == NULL) {
@@ -2741,24 +2767,6 @@ static bool lp_set_cmdline_helper(const char *pszParmName, const char *pszParmVa
        return false;
 }
 
-bool lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
-{
-       bool ret;
-       TALLOC_CTX *frame = talloc_stackframe();
-       struct loadparm_context *lp_ctx;
-
-       lp_ctx = setup_lp_context(frame);
-       if (lp_ctx == NULL) {
-               TALLOC_FREE(frame);
-               return false;
-       }
-
-       ret = lpcfg_set_cmdline(lp_ctx, pszParmName, pszParmValue);
-
-       TALLOC_FREE(frame);
-       return ret;
-}
-
 /***************************************************************************
  Process a parameter.
 ***************************************************************************/
@@ -3027,7 +3035,7 @@ void lp_add_one_printer(const char *name, const char *comment,
 
 bool lp_loaded(void)
 {
-       return (bLoaded);
+       return (b_loaded);
 }
 
 /***************************************************************************
@@ -3074,7 +3082,7 @@ void lp_killservice(int iServiceIn)
 }
 
 /***************************************************************************
- Save the curent values of all global and sDefault parameters into the
+ Save the current values of all global and sDefault parameters into the
  defaults union. This allows testparm to show only the
  changed (ie. non-default) parameters.
 ***************************************************************************/
@@ -3143,7 +3151,7 @@ static void lp_save_defaults(void)
 }
 
 /***********************************************************
- If we should send plaintext/LANMAN passwords in the clinet
+ If we should send plaintext/LANMAN passwords in the client
 ************************************************************/
 
 static void set_allowed_client_auth(void)
@@ -3983,7 +3991,7 @@ static bool lp_load_ex(const char *pszFname,
 
        lp_ctx = setup_lp_context(talloc_tos());
 
-       init_globals(lp_ctx, reinit_globals);
+       loadparm_s3_init_globals(lp_ctx, reinit_globals);
 
        free_file_list();
 
@@ -4037,7 +4045,7 @@ static bool lp_load_ex(const char *pszFname,
                        /* start over */
                        DEBUG(1, ("lp_load_ex: changing to config backend "
                                  "registry\n"));
-                       init_globals(lp_ctx, true);
+                       loadparm_s3_init_globals(lp_ctx, true);
 
                        TALLOC_FREE(lp_ctx);
 
@@ -4089,7 +4097,7 @@ static bool lp_load_ex(const char *pszFname,
                          lp_password_server()));
        }
 
-       bLoaded = true;
+       b_loaded = true;
 
        /* Now we check we_are_a_wins_server and set szWINSserver to 127.0.0.1 */
        /* if we_are_a_wins_server is true and we are in the client            */
@@ -4404,7 +4412,7 @@ const char *volume_label(TALLOC_CTX *ctx, int snum)
                }
        }
 
-       /* This returns a max of 33 byte guarenteed null terminated string. */
+       /* This returns a max of 33 byte guaranteed null terminated string. */
        ret = talloc_strndup(ctx, label, end);
        if (!ret) {
                return "";
@@ -4675,12 +4683,12 @@ void widelinks_warning(int snum)
                        "These parameters are incompatible. "
                        "Wide links will be disabled for this share.\n",
                         lp_const_servicename(snum));
-               } else if (lp_smb3_unix_extensions()) {
-                       DBG_ERR("Share '%s' has wide links and SMB3 unix "
-                       "extensions enabled. "
-                       "These parameters are incompatible. "
-                       "Wide links will be disabled for this share.\n",
-                        lp_const_servicename(snum));
+               } else if (lp_smb3_unix_extensions(snum)) {
+                       DBG_ERR("Share '%s' has wide links and SMB3 Unix "
+                               "extensions enabled. "
+                               "These parameters are incompatible. "
+                               "Wide links will be disabled for this share.\n",
+                               lp_const_servicename(snum));
                }
        }
 }
@@ -4688,7 +4696,7 @@ void widelinks_warning(int snum)
 bool lp_widelinks(int snum)
 {
        /* wide links is always incompatible with unix extensions */
-       if (lp_smb1_unix_extensions() || lp_smb3_unix_extensions()) {
+       if (lp_smb1_unix_extensions() || lp_smb3_unix_extensions(snum)) {
                /*
                 * Unless we have "allow insecure widelinks"
                 * turned on.
@@ -4828,12 +4836,3 @@ uint32_t lp_get_async_dns_timeout(void)
         */
        return MAX(Globals.async_dns_timeout, 1);
 }
-
-bool lp_smb3_unix_extensions(void)
-{
-#if defined(DEVELOPER)
-       return lp__smb3_unix_extensions();
-#else
-       return false;
-#endif
-}