r4423: give lp_parm_int() and lp_parm_ulong() default values
[samba.git] / source4 / param / loadparm.c
index 397d131d7506485605ff018709cb612da7a3278d..eabf70b6d092eb4dd6e0c46ea91bc2e19bd05eca 100644 (file)
  */
 
 #include "includes.h"
+#include "dynconfig.h"
+#include "system/time.h"
+#include "system/iconv.h"
+#include "system/network.h"
+#include "system/printing.h"
+#include "librpc/gen_ndr/ndr_svcctl.h"
+#include "dlinklist.h"
 
 BOOL in_client = False;                /* Not in the client by default */
 static BOOL bLoaded = False;
@@ -78,6 +85,56 @@ static BOOL do_parameter_var(const char *pszParmName, const char *fmt, ...);
 
 static BOOL defaults_saved = False;
 
+
+#define FLAG_BASIC     0x0001 /* fundamental options */
+#define FLAG_SHARE     0x0002 /* file sharing options */
+#define FLAG_PRINT     0x0004 /* printing options */
+#define FLAG_GLOBAL    0x0008 /* local options that should be globally settable in SWAT */
+#define FLAG_WIZARD    0x0010 /* Parameters that the wizard will operate on */
+#define FLAG_ADVANCED  0x0020 /* Parameters that the wizard will operate on */
+#define FLAG_DEVELOPER         0x0040 /* Parameters that the wizard will operate on */
+#define FLAG_DEPRECATED 0x1000 /* options that should no longer be used */
+#define FLAG_HIDE      0x2000 /* options that should be hidden in SWAT */
+#define FLAG_DOS_STRING 0x4000 /* convert from UNIX to DOS codepage when reading this string. */
+#define FLAG_CMDLINE    0x8000 /* this option was set from the command line */
+
+
+/* the following are used by loadparm for option lists */
+typedef enum
+{
+  P_BOOL,P_BOOLREV,P_CHAR,P_INTEGER,P_OCTAL,P_LIST,
+  P_STRING,P_USTRING,P_ENUM,P_SEP
+} parm_type;
+
+typedef enum
+{
+  P_LOCAL,P_GLOBAL,P_SEPARATOR,P_NONE
+} parm_class;
+
+struct enum_list {
+       int value;
+       const char *name;
+};
+
+struct parm_struct
+{
+       const char *label;
+       parm_type type;
+       parm_class class;
+       void *ptr;
+       BOOL (*special)(const char *, char **);
+       const struct enum_list *enum_list;
+       uint_t flags;
+       union {
+               BOOL bvalue;
+               int ivalue;
+               char *svalue;
+               char cvalue;
+               char **lvalue;
+       } def;
+};
+
+
 struct param_opt {
        struct param_opt *prev, *next;
        char *key;
@@ -93,6 +150,7 @@ typedef struct
        char **smb_ports;
        char *dos_charset;
        char *unix_charset;
+       char *ncalrpc_dir;
        char *display_charset;
        char *szPrintcapname;
        char *szLockDir;
@@ -197,8 +255,8 @@ typedef struct
        BOOL bLanmanAuth;
        BOOL bNTLMAuth;
        BOOL bUseSpnego;
-       BOOL server_signing;
-       BOOL client_signing;
+       int  server_signing;
+       int  client_signing;
        BOOL bClientLanManAuth;
        BOOL bClientNTLMv2Auth;
        BOOL bHostMSDfs;
@@ -271,6 +329,7 @@ typedef struct
        BOOL bMSDfsRoot;
        BOOL bShareModes;
        BOOL bStrictSync;
+       BOOL bCIFileSystem;
        struct param_opt *param_opt;
 
        char dummy[3];          /* for alignment */
@@ -329,6 +388,7 @@ static service sDefault = {
        False,                  /* bMSDfsRoot */
        True,                   /* bShareModes */
        False,                  /* bStrictSync */
+       False,                  /* bCIFileSystem */
        NULL,                   /* Parametric options */
 
        ""                      /* dummy */
@@ -410,12 +470,6 @@ static const struct enum_list enum_announce_as[] = {
        {-1, NULL}
 };
 
-static const struct enum_list enum_case[] = {
-       {CASE_LOWER, "lower"},
-       {CASE_UPPER, "upper"},
-       {-1, NULL}
-};
-
 static const struct enum_list enum_bool_auto[] = {
        {False, "No"},
        {False, "False"},
@@ -453,42 +507,15 @@ static const struct enum_list enum_smb_signing_vals[] = {
        {SMB_SIGNING_SUPPORTED, "1"},
        {SMB_SIGNING_SUPPORTED, "On"},
        {SMB_SIGNING_SUPPORTED, "enabled"},
-       {SMB_SIGNING_SUPPORTED, "auto"},
        {SMB_SIGNING_REQUIRED, "required"},
        {SMB_SIGNING_REQUIRED, "mandatory"},
        {SMB_SIGNING_REQUIRED, "force"},
        {SMB_SIGNING_REQUIRED, "forced"},
        {SMB_SIGNING_REQUIRED, "enforced"},
+       {SMB_SIGNING_AUTO, "auto"},
        {-1, NULL}
 };
 
-/* 
-   Do you want session setups at user level security with a invalid
-   password to be rejected or allowed in as guest? WinNT rejects them
-   but it can be a pain as it means "net view" needs to use a password
-
-   You have 3 choices in the setting of map_to_guest:
-
-   "Never" means session setups with an invalid password
-   are rejected. This is the default.
-
-   "Bad User" means session setups with an invalid password
-   are rejected, unless the username does not exist, in which case it
-   is treated as a guest login
-
-   "Bad Password" means session setups with an invalid password
-   are treated as a guest login
-
-   Note that map_to_guest only has an effect in user or server
-   level security.
-*/
-
-static const struct enum_list enum_map_to_guest[] = {
-       {NEVER_MAP_TO_GUEST, "Never"},
-       {MAP_TO_GUEST_ON_BAD_USER, "Bad User"},
-       {MAP_TO_GUEST_ON_BAD_PASSWORD, "Bad Password"},
-       {-1, NULL}
-};
 
 /* Note: We do not initialise the defaults union - it is not allowed in ANSI C
  *
@@ -505,6 +532,7 @@ static struct parm_struct parm_table[] = {
 
        {"dos charset", P_STRING, P_GLOBAL, &Globals.dos_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"unix charset", P_STRING, P_GLOBAL, &Globals.unix_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
+       {"ncalrpc dir", P_STRING, P_GLOBAL, &Globals.ncalrpc_dir, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"display charset", P_STRING, P_GLOBAL, &Globals.display_charset, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"comment", P_STRING, P_LOCAL, &sDefault.comment, NULL, NULL, FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT | FLAG_DEVELOPER},
        {"path", P_STRING, P_LOCAL, &sDefault.szPath, NULL, NULL, FLAG_BASIC | FLAG_ADVANCED | FLAG_SHARE | FLAG_PRINT | FLAG_DEVELOPER},
@@ -621,6 +649,7 @@ static struct parm_struct parm_table[] = {
 
        {"name cache timeout", P_INTEGER, P_GLOBAL, &Globals.name_cache_timeout, NULL, NULL, FLAG_ADVANCED | FLAG_DEVELOPER},
        {"strict sync", P_BOOL, P_LOCAL, &sDefault.bStrictSync, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE}, 
+       {"case insensitive filesystem", P_BOOL, P_LOCAL, &sDefault.bCIFileSystem, NULL, NULL, FLAG_ADVANCED | FLAG_SHARE}, 
 
        {"Printing Options", P_SEP, P_SEPARATOR},
        
@@ -866,6 +895,7 @@ static void init_printer_values(void)
 static void init_globals(void)
 {
        int i;
+       char *myname;
 
        DEBUG(3, ("Initialising global parameters\n"));
 
@@ -880,9 +910,13 @@ static void init_globals(void)
 
        /* options that can be set on the command line must be initialised via
           the slower do_parameter() to ensure that FLAG_CMDLINE is obeyed */
-       do_parameter("socket options", DEFAULT_SOCKET_OPTIONS);
+#ifdef TCP_NODELAY
+       do_parameter("socket options", "TCP_NODELAY");
+#endif
        do_parameter("workgroup", DEFAULT_WORKGROUP);
-       do_parameter("netbios name", get_myname());
+       myname = get_myname();
+       do_parameter("netbios name", myname);
+       SAFE_FREE(myname);
        do_parameter("max protocol", "NT1");
        do_parameter("name resolve order", "lmhosts wins host bcast");
 
@@ -891,9 +925,9 @@ static void init_globals(void)
        do_parameter("fstype", FSTYPE_STRING);
        do_parameter("ntvfs handler", "unixuid default");
 
-       do_parameter("dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi");
+       do_parameter("dcerpc endpoint servers", "epmapper srvsvc wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi winreg IOXIDResolver IRemoteActivation");
        do_parameter("server services", "smb rpc");
-       do_parameter("auth methods", "guest sam_ignoredomain");
+       do_parameter("auth methods", "anonymous sam_ignoredomain");
        do_parameter("smb passwd file", dyn_SMB_PASSWD_FILE);
        do_parameter("private dir", dyn_PRIVATE_DIR);
        do_parameter_var("sam database", "tdb://%s/sam.ldb", dyn_PRIVATE_DIR);
@@ -916,6 +950,8 @@ static void init_globals(void)
        
        do_parameter("pid directory", dyn_PIDDIR);
        do_parameter("lock dir", dyn_LOCKDIR);
+       do_parameter("ncalrpc dir", dyn_NCALRPCDIR);
+
        do_parameter("socket address", "0.0.0.0");
        do_parameter_var("server string", "Samba %s", SAMBA_VERSION_STRING);
 
@@ -932,7 +968,7 @@ static void init_globals(void)
        do_parameter("load printers", "True");
 
        do_parameter("max mux", "50");
-       do_parameter("max xmit", "4356");
+       do_parameter("max xmit", "12288");
        do_parameter("lpqcachetime", "10");
        do_parameter("DisableSpoolss", "False");
        do_parameter("password level", "0");
@@ -999,7 +1035,7 @@ static void init_globals(void)
        do_parameter("name cache timeout", "660"); /* In seconds */
 
        do_parameter("client signing", "Yes");
-       do_parameter("server signing", "Yes");
+       do_parameter("server signing", "auto");
 
        do_parameter("use spnego", "True");
 
@@ -1113,6 +1149,7 @@ FN_GLOBAL_STRING(lp_private_dir, &Globals.szPrivateDir)
 FN_GLOBAL_STRING(lp_serverstring, &Globals.szServerString)
 FN_GLOBAL_STRING(lp_printcapname, &Globals.szPrintcapname)
 FN_GLOBAL_STRING(lp_lockdir, &Globals.szLockDir)
+FN_GLOBAL_STRING(lp_ncalrpc_dir, &Globals.ncalrpc_dir)
 FN_GLOBAL_STRING(lp_piddir, &Globals.szPidDir)
 FN_GLOBAL_LIST(lp_dcerpc_endpoint_servers, &Globals.dcerpc_ep_servers)
 FN_GLOBAL_LIST(lp_server_services, &Globals.server_services)
@@ -1139,7 +1176,6 @@ FN_GLOBAL_STRING(lp_remote_browse_sync, &Globals.szRemoteBrowseSync)
 FN_GLOBAL_LIST(lp_wins_server_list, &Globals.szWINSservers)
 FN_GLOBAL_LIST(lp_interfaces, &Globals.szInterfaces)
 FN_GLOBAL_STRING(lp_socket_address, &Globals.szSocketAddress)
-static FN_GLOBAL_STRING(lp_announce_version, &Globals.szAnnounceVersion)
 FN_GLOBAL_LIST(lp_netbios_aliases, &Globals.szNetbiosAliases)
 FN_GLOBAL_LIST(lp_preload_modules, &Globals.szPreloadModules)
 FN_GLOBAL_STRING(lp_panic_action, &Globals.szPanicAction)
@@ -1248,6 +1284,7 @@ FN_LOCAL_BOOL(lp_locking, bLocking)
 FN_LOCAL_BOOL(lp_strict_locking, bStrictLocking)
 FN_LOCAL_BOOL(lp_posix_locking, bPosixLocking)
 FN_LOCAL_BOOL(lp_strict_sync, bStrictSync)
+FN_LOCAL_BOOL(lp_ci_filesystem, bCIFileSystem)
 FN_LOCAL_BOOL(lp_share_modes, bShareModes)
 FN_LOCAL_BOOL(lp_oplocks, bOpLocks)
 FN_LOCAL_BOOL(lp_level2_oplocks, bLevel2OpLocks)
@@ -1366,26 +1403,6 @@ static BOOL lp_bool(const char *s)
        return ret;
 }
 
-/*******************************************************************
-convenience routine to return enum parameters.
-********************************************************************/
-static int lp_enum(const char *s,const struct enum_list *_enum)
-{
-       int i;
-
-       if (!s || !_enum) {
-               DEBUG(0,("lp_enum(%s,enum): is called with NULL!\n",s));
-               return False;
-       }
-       
-       for (i=0; _enum[i].name; i++) {
-               if (strcasecmp(_enum[i].name,s)==0)
-                       return _enum[i].value;
-       }
-
-       DEBUG(0,("lp_enum(%s,enum): value is not in enum_list!\n",s));
-       return (-1);
-}
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
@@ -1419,27 +1436,27 @@ char **lp_parm_string_list(int lookup_service, const char *type, const char *opt
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-int lp_parm_int(int lookup_service, const char *type, const char *option)
+int lp_parm_int(int lookup_service, const char *type, const char *option, int default_v)
 {
        const char *value = get_parametrics(lookup_service, type, option);
        
        if (value)
                return lp_int(value);
 
-       return (-1);
+       return default_v;
 }
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
-unsigned long lp_parm_ulong(int lookup_service, const char *type, const char *option)
+unsigned long lp_parm_ulong(int lookup_service, const char *type, const char *option, unsigned long default_v)
 {
        const char *value = get_parametrics(lookup_service, type, option);
        
        if (value)
                return lp_ulong(value);
 
-       return (0);
+       return default_v;
 }
 
 /* Return parametric option from a given service. Type is a part of option before ':' */
@@ -1455,20 +1472,6 @@ BOOL lp_parm_bool(int lookup_service, const char *type, const char *option, BOOL
        return default_v;
 }
 
-/* Return parametric option from a given service. Type is a part of option before ':' */
-/* Parametric option has following syntax: 'Type: option = value' */
-
-int lp_parm_enum(int lookup_service, const char *type, const char *option,
-                const struct enum_list *_enum)
-{
-       const char *value = get_parametrics(lookup_service, type, option);
-       
-       if (value)
-               return lp_enum(value, _enum);
-
-       return (-1);
-}
-
 
 /***************************************************************************
  Initialise a service to the defaults.
@@ -1568,9 +1571,7 @@ static int add_a_service(const service *pservice, const char *name)
        if (i == iNumServices) {
                service **tsp;
                
-               tsp = (service **) Realloc(ServicePtrs,
-                                          sizeof(service *) *
-                                          num_to_alloc);
+               tsp = realloc_p(ServicePtrs, service *, num_to_alloc);
                                           
                if (!tsp) {
                        DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
@@ -1578,8 +1579,7 @@ static int add_a_service(const service *pservice, const char *name)
                }
                else {
                        ServicePtrs = tsp;
-                       ServicePtrs[iNumServices] =
-                               (service *) malloc(sizeof(service));
+                       ServicePtrs[iNumServices] = malloc_p(service);
                }
                if (!ServicePtrs[iNumServices]) {
                        DEBUG(0,("add_a_service: out of memory!\n"));
@@ -1676,6 +1676,8 @@ static BOOL lp_add_ipc(const char *ipc_name, BOOL guest_ok)
        ServicePtrs[i]->bPrint_ok = False;
        ServicePtrs[i]->bBrowseable = sDefault.bBrowseable;
 
+       lp_do_parameter(i, "ntvfs handler", "default");
+
        DEBUG(3, ("adding IPC service\n"));
 
        return (True);
@@ -1871,7 +1873,7 @@ static void copy_service(service * pserviceDest, service * pserviceSource, BOOL
                        pdata = pdata->next;
                }
                if (not_added) {
-                       paramo = smb_xmalloc(sizeof(*paramo));
+                       paramo = smb_xmalloc_p(struct param_opt);
                        paramo->key = strdup(data->key);
                        paramo->value = strdup(data->value);
                        DLIST_ADD(pserviceDest->param_opt, paramo);
@@ -1940,7 +1942,7 @@ static void add_to_file_list(const char *fname, const char *subfname)
        }
 
        if (!f) {
-               f = (struct file_lists *)malloc(sizeof(file_lists[0]));
+               f = malloc_p(struct file_lists);
                if (!f)
                        return;
                f->next = file_lists;
@@ -2185,7 +2187,7 @@ static void init_copymap(service * pservice)
 {
        int i;
        SAFE_FREE(pservice->copymap);
-       pservice->copymap = (BOOL *)malloc(sizeof(BOOL) * NUMPARAMETERS);
+       pservice->copymap = malloc_array_p(BOOL, NUMPARAMETERS);
        if (!pservice->copymap)
                DEBUG(0,
                      ("Couldn't allocate copymap!! (size %d)\n",
@@ -2247,7 +2249,7 @@ static BOOL lp_do_parameter_parametric(int snum, const char *pszParmName, const
                }
        }
 
-       paramo = smb_xmalloc(sizeof(*paramo));
+       paramo = smb_xmalloc_p(struct param_opt);
        paramo->key = strdup(name);
        paramo->value = strdup(pszParmValue);
        paramo->flags = flags;
@@ -2439,6 +2441,11 @@ BOOL lp_set_cmdline(const char *pszParmName, const char *pszParmValue)
                return lp_do_parameter_parametric(-1, pszParmName, pszParmValue, FLAG_CMDLINE);
        }
 
+       if (parmnum < 0) {
+               DEBUG(0,("Unknown option '%s'\n", pszParmName));
+               return False;
+       }
+
        /* reset the CMDLINE flag in case this has been called before */
        parm_table[parmnum].flags &= ~FLAG_CMDLINE;
 
@@ -2701,19 +2708,6 @@ static void dump_globals(FILE *f)
 
 }
 
-/***************************************************************************
- Return True if a local parameter is currently set to the global default.
-***************************************************************************/
-
-BOOL lp_is_default(int snum, struct parm_struct *parm)
-{
-       int pdiff = PTR_DIFF(parm->ptr, &sDefault);
-
-       return equal_parameter(parm->type,
-                              ((char *)ServicePtrs[snum]) + pdiff,
-                              ((char *)&sDefault) + pdiff);
-}
-
 /***************************************************************************
  Display the contents of a single services record.
 ***************************************************************************/
@@ -2819,28 +2813,6 @@ struct parm_struct *lp_next_parameter(int snum, int *i, int allparameters)
 }
 
 
-#if 0
-/***************************************************************************
- Display the contents of a single copy structure.
-***************************************************************************/
-static void dump_copy_map(BOOL *pcopymap)
-{
-       int i;
-       if (!pcopymap)
-               return;
-
-       printf("\n\tNon-Copied parameters:\n");
-
-       for (i = 0; parm_table[i].label; i++)
-               if (parm_table[i].class == P_LOCAL &&
-                   parm_table[i].ptr && !pcopymap[i] &&
-                   (i == 0 || (parm_table[i].ptr != parm_table[i - 1].ptr)))
-               {
-                       printf("\t\t%s\n", parm_table[i].label);
-               }
-}
-#endif
-
 /***************************************************************************
  Return TRUE if the passed service number is within range.
 ***************************************************************************/
@@ -3099,6 +3071,9 @@ BOOL lp_load(const char *pszFname, BOOL global_only, BOOL save_defaults,
                lp_do_parameter(-1, "wins server", "127.0.0.1");
        }
 
+       lp_do_parameter(-1, "gensec:krb5", "False");
+       lp_do_parameter(-1, "gensec:ms_krb5", "False");
+
        init_iconv();
 
        return (bRetval);
@@ -3308,60 +3283,11 @@ void lp_copy_service(int snum, const char *new_name)
 /*******************************************************************
  Get the default server type we will announce as via nmbd.
 ********************************************************************/
-
 int lp_default_server_announce(void)
 {
        return default_server_announce;
 }
 
-/*******************************************************************
- Split the announce version into major and minor numbers.
-********************************************************************/
-
-int lp_major_announce_version(void)
-{
-       static BOOL got_major = False;
-       static int major_version = DEFAULT_MAJOR_VERSION;
-       const char *vers;
-       char *p;
-
-       if (got_major)
-               return major_version;
-
-       got_major = True;
-       if ((vers = lp_announce_version()) == NULL)
-               return major_version;
-
-       if ((p = strchr_m(vers, '.')) == 0)
-               return major_version;
-
-       *p = '\0';
-       major_version = atoi(vers);
-       return major_version;
-}
-
-int lp_minor_announce_version(void)
-{
-       static BOOL got_minor = False;
-       static int minor_version = DEFAULT_MINOR_VERSION;
-       const char *vers;
-       char *p;
-
-       if (got_minor)
-               return minor_version;
-
-       got_minor = True;
-       if ((vers = lp_announce_version()) == NULL)
-               return minor_version;
-
-       if ((p = strchr_m(vers, '.')) == 0)
-               return minor_version;
-
-       p++;
-       minor_version = atoi(p);
-       return minor_version;
-}
-
 const char *lp_printername(int snum)
 {
        const char *ret = _lp_printername(snum);