param: make server role list common and include auto (for the new default)
[ira/wip.git] / source3 / param / loadparm.c
index 255bc7459479e8ec3f19177d07a89e00f2d81834..11da2a968751d62c05c7a157a0e32254069a2529 100644 (file)
@@ -64,8 +64,9 @@
 #include "ads.h"
 #include "../librpc/gen_ndr/svcctl.h"
 #include "intl.h"
-#include "smb_signing.h"
+#include "../libcli/smb/smb_signing.h"
 #include "dbwrap/dbwrap.h"
+#include "dbwrap/dbwrap_rbt.h"
 #include "smbldap.h"
 #include "../lib/util/bitmap.h"
 
@@ -434,22 +435,24 @@ static const struct enum_list enum_csc_policy[] = {
 
 /* SMB signing types. */
 static const struct enum_list enum_smb_signing_vals[] = {
-       {false, "No"},
-       {false, "False"},
-       {false, "0"},
-       {false, "Off"},
-       {false, "disabled"},
-       {true, "Yes"},
-       {true, "True"},
-       {true, "1"},
-       {true, "On"},
-       {true, "enabled"},
-       {Auto, "auto"},
-       {Required, "required"},
-       {Required, "mandatory"},
-       {Required, "force"},
-       {Required, "forced"},
-       {Required, "enforced"},
+       {SMB_SIGNING_DEFAULT, "default"},
+       {SMB_SIGNING_OFF, "No"},
+       {SMB_SIGNING_OFF, "False"},
+       {SMB_SIGNING_OFF, "0"},
+       {SMB_SIGNING_OFF, "Off"},
+       {SMB_SIGNING_OFF, "disabled"},
+       {SMB_SIGNING_IF_REQUIRED, "if_required"},
+       {SMB_SIGNING_IF_REQUIRED, "Yes"},
+       {SMB_SIGNING_IF_REQUIRED, "True"},
+       {SMB_SIGNING_IF_REQUIRED, "1"},
+       {SMB_SIGNING_IF_REQUIRED, "On"},
+       {SMB_SIGNING_IF_REQUIRED, "enabled"},
+       {SMB_SIGNING_IF_REQUIRED, "auto"},
+       {SMB_SIGNING_REQUIRED, "required"},
+       {SMB_SIGNING_REQUIRED, "mandatory"},
+       {SMB_SIGNING_REQUIRED, "force"},
+       {SMB_SIGNING_REQUIRED, "forced"},
+       {SMB_SIGNING_REQUIRED, "enforced"},
        {-1, NULL}
 };
 
@@ -509,6 +512,23 @@ static const struct enum_list enum_kerberos_method[] = {
        {-1, NULL}
 };
 
+/* Server role options */
+static const struct enum_list enum_server_role[] = {
+       {ROLE_AUTO, "auto"},
+       {ROLE_STANDALONE, "standalone"},
+       {ROLE_DOMAIN_MEMBER, "member server"},
+       {ROLE_DOMAIN_MEMBER, "member"},
+       /* note that currently
+          ROLE_DOMAIN_CONTROLLER == ROLE_DOMAIN_BDC */
+       {ROLE_DOMAIN_CONTROLLER, "domain controller"},
+       {ROLE_DOMAIN_BDC, "backup domain controller"},
+       {ROLE_DOMAIN_BDC, "bdc"},
+       {ROLE_DOMAIN_BDC, "dc"},
+       {ROLE_DOMAIN_PDC, "primary domain controller"},
+       {ROLE_DOMAIN_PDC, "pdc"},
+       {-1, NULL}
+};
+
 /* Note: We do not initialise the defaults union - it is not allowed in ANSI C
  *
  * The FLAG_HIDE is explicit. Parameters set this way do NOT appear in any edit
@@ -659,6 +679,15 @@ static struct parm_struct parm_table[] = {
                .enum_list      = enum_config_backend,
                .flags          = FLAG_HIDE|FLAG_ADVANCED|FLAG_META,
        },
+       {
+               .label          = "server role",
+               .type           = P_ENUM,
+               .p_class        = P_GLOBAL,
+               .offset         = GLOBAL_VAR(ServerRole),
+               .special        = NULL,
+               .enum_list      = enum_server_role,
+               .flags          = FLAG_BASIC | FLAG_ADVANCED,
+       },
 
        {N_("Security Options"), P_SEP, P_SEPARATOR},
 
@@ -1147,7 +1176,7 @@ static struct parm_struct parm_table[] = {
                .offset         = LOCAL_VAR(bAclCheckPermissions),
                .special        = NULL,
                .enum_list      = NULL,
-               .flags          = FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE,
+               .flags          = FLAG_ADVANCED | FLAG_GLOBAL | FLAG_SHARE | FLAG_DEPRECATED,
        },
        {
                .label          = "acl group control",
@@ -4793,6 +4822,7 @@ static void init_globals(bool reinit_globals)
        Globals.PrintcapCacheTime = 750;        /* 12.5 minutes */
 
        Globals.ConfigBackend = config_backend;
+       Globals.ServerRole = ROLE_STANDALONE;
 
        /* Was 65535 (0xFFFF). 0x4101 matches W2K and causes major speed improvements... */
        /* Discovered by 2 days of pain by Don McCall @ HP :-). */
@@ -4977,8 +5007,8 @@ static void init_globals(bool reinit_globals)
        Globals.bUseSpnego = true;
        Globals.bClientUseSpnego = true;
 
-       Globals.client_signing = Auto;
-       Globals.server_signing = false;
+       Globals.client_signing = SMB_SIGNING_DEFAULT;
+       Globals.server_signing = SMB_SIGNING_DEFAULT;
 
        Globals.bDeferSharingViolations = true;
        string_set(&Globals.smb_ports, SMB_PORTS);
@@ -5360,6 +5390,7 @@ FN_GLOBAL_INTEGER(lp_lock_spin_time, iLockSpinTime)
 FN_GLOBAL_INTEGER(lp_usershare_max_shares, iUsershareMaxShares)
 FN_GLOBAL_CONST_STRING(lp_socket_options, szSocketOptions)
 FN_GLOBAL_INTEGER(lp_config_backend, ConfigBackend)
+FN_GLOBAL_INTEGER(lp_server_role, ServerRole)
 FN_GLOBAL_INTEGER(lp_smb2_max_read, ismb2_max_read)
 FN_GLOBAL_INTEGER(lp_smb2_max_write, ismb2_max_write)
 FN_GLOBAL_INTEGER(lp_smb2_max_trans, ismb2_max_trans)
@@ -5924,7 +5955,7 @@ bool lp_add_home(const char *pszHomename, int iDefaultService,
        i = add_a_service(ServicePtrs[iDefaultService], pszHomename);
 
        if (i < 0)
-               return (false);
+               return false;
 
        if (!(*(ServicePtrs[iDefaultService]->szPath))
            || strequal(ServicePtrs[iDefaultService]->szPath, lp_pathname(GLOBAL_SECTION_SNUM))) {
@@ -5950,7 +5981,7 @@ bool lp_add_home(const char *pszHomename, int iDefaultService,
        DEBUG(3, ("adding home's share [%s] for user '%s' at '%s'\n", pszHomename, 
               user, ServicePtrs[i]->szPath ));
 
-       return (true);
+       return true;
 }
 
 /***************************************************************************
@@ -5976,11 +6007,11 @@ static bool lp_add_ipc(const char *ipc_name, bool guest_ok)
        int i = add_a_service(&sDefault, ipc_name);
 
        if (i < 0)
-               return (false);
+               return false;
 
        if (asprintf(&comment, "IPC Service (%s)",
                                Globals.szServerString) < 0) {
-               return (false);
+               return false;
        }
 
        string_set(&ServicePtrs[i]->szPath, tmpdir());
@@ -5999,7 +6030,7 @@ static bool lp_add_ipc(const char *ipc_name, bool guest_ok)
        DEBUG(3, ("adding IPC service\n"));
 
        SAFE_FREE(comment);
-       return (true);
+       return true;
 }
 
 /***************************************************************************
@@ -6012,7 +6043,7 @@ bool lp_add_printer(const char *pszPrintername, int iDefaultService)
        int i = add_a_service(ServicePtrs[iDefaultService], pszPrintername);
 
        if (i < 0)
-               return (false);
+               return false;
 
        /* note that we do NOT default the availability flag to true - */
        /* we take it from the default service passed. This allows all */
@@ -6037,7 +6068,7 @@ bool lp_add_printer(const char *pszPrintername, int iDefaultService)
 
        DEBUG(3, ("adding printer service %s\n", pszPrintername));
 
-       return (true);
+       return true;
 }
 
 
@@ -6398,6 +6429,7 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
        int iService = -1;
        char *canon_name;
        TDB_DATA data;
+       NTSTATUS status;
 
        if (ServiceHash == NULL) {
                return -1;
@@ -6405,9 +6437,13 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
 
        canon_name = canonicalize_servicename(talloc_tos(), pszServiceName);
 
-       data = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name);
+       status = dbwrap_fetch_bystring(ServiceHash, canon_name, canon_name,
+                                      &data);
 
-       if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
+       if (NT_STATUS_IS_OK(status) &&
+           (data.dptr != NULL) &&
+           (data.dsize == sizeof(iService)))
+       {
                iService = *(int *)data.dptr;
        }
 
@@ -6929,7 +6965,7 @@ bool lp_file_list_changed(void)
                }
                f = f->next;
        }
-       return (false);
+       return false;
 }
 
 
@@ -7348,7 +7384,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                if (strchr(pszParmName, ':') == NULL) {
                        DEBUG(0, ("Ignoring unknown parameter \"%s\"\n",
                                  pszParmName));
-                       return (true);
+                       return true;
                }
 
                /*
@@ -7359,7 +7395,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        ? &Globals.param_opt : &ServicePtrs[snum]->param_opt;
                set_param_opt(opt_list, pszParmName, pszParmValue, 0);
 
-               return (true);
+               return true;
        }
 
        /* if it's already been set by the command line, then we don't
@@ -7381,7 +7417,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        DEBUG(0,
                              ("Global parameter %s found in service section!\n",
                               pszParmName));
-                       return (true);
+                       return true;
                }
                parm_ptr = lp_local_ptr_by_snum(snum, &parm_table[parmnum]);
        }
@@ -7473,7 +7509,7 @@ bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue
                        break;
        }
 
-       return (true);
+       return true;
 }
 
 /***************************************************************************
@@ -7538,7 +7574,7 @@ static bool do_parameter(const char *pszParmName, const char *pszParmValue,
                         void *userdata)
 {
        if (!bInGlobalSection && bGlobalOnly)
-               return (true);
+               return true;
 
        DEBUGADD(4, ("doing parameter %s = %s\n", pszParmName, pszParmValue));
 
@@ -7694,7 +7730,7 @@ static bool equal_parameter(parm_type type, void *ptr1, void *ptr2)
                case P_SEP:
                        break;
        }
-       return (false);
+       return false;
 }
 
 /***************************************************************************
@@ -7729,11 +7765,11 @@ static bool do_section(const char *pszSectionName, void *userdata)
        /* check for multiple global sections */
        if (bInGlobalSection) {
                DEBUG(3, ("Processing section \"[%s]\"\n", pszSectionName));
-               return (true);
+               return true;
        }
 
        if (!bInGlobalSection && bGlobalOnly)
-               return (true);
+               return true;
 
        /* if we have a current service, tidy it up before moving on */
        bRetval = true;
@@ -7750,14 +7786,14 @@ static bool do_section(const char *pszSectionName, void *userdata)
                iServiceIndex = add_a_service(&sDefault, pszSectionName);
                if (iServiceIndex < 0) {
                        DEBUG(0, ("Failed to add a new service\n"));
-                       return (false);
+                       return false;
                }
                /* Clean all parametric options for service */
                /* They will be added during parsing again */
                free_param_opts(&ServicePtrs[iServiceIndex]->param_opt);
        }
 
-       return (bRetval);
+       return bRetval;
 }
 
 
@@ -8540,12 +8576,18 @@ static int process_usershare_file(const char *dir_name, const char *file_name, i
        }
 
        {
-               TDB_DATA data = dbwrap_fetch_bystring(
-                       ServiceHash, canon_name, canon_name);
+               TDB_DATA data;
+               NTSTATUS status;
+
+               status = dbwrap_fetch_bystring(ServiceHash, canon_name,
+                                              canon_name, &data);
 
                iService = -1;
 
-               if ((data.dptr != NULL) && (data.dsize == sizeof(iService))) {
+               if (NT_STATUS_IS_OK(status) &&
+                   (data.dptr != NULL) &&
+                   (data.dsize == sizeof(iService)))
+               {
                        iService = *(int *)data.dptr;
                }
        }
@@ -9693,3 +9735,8 @@ bool lp_readraw(void)
        }
        return _lp_readraw();
 }
+
+void _lp_set_server_role(int server_role)
+{
+       Globals.ServerRole = server_role;
+}