param: get rid of unnecessary get_default_loadparm_service pointer
[sfrench/samba-autobuild/.git] / lib / param / loadparm.c
index bf0cbc0e9d919b7f64238404ff00f439a3738dd3..2b73d40f6c3f35c794599abcf60eea3bd6e7caf5 100644 (file)
 
 #define standard_sub_basic talloc_strdup
 
-static bool do_parameter(const char *, const char *, void *);
-
 #include "lib/param/param_global.h"
 
 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
 {
-       if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->get_default_loadparm_service();
-       }
        return lp_ctx->sDefault;
 }
 
@@ -231,8 +226,13 @@ FN_GLOBAL_CONST_STRING(dnsdomain, dnsdomain)
 /* local prototypes */
 static struct loadparm_service *lpcfg_getservicebyname(struct loadparm_context *lp_ctx,
                                        const char *pszServiceName);
-static bool lpcfg_service_ok(struct loadparm_service *service);
 static bool do_section(const char *pszSectionName, void *);
+static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
+                               const char *pszParmName, const char *pszParmValue);
+static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
+                                      struct loadparm_service *service,
+                                      const char *pszParmName,
+                                      const char *pszParmValue, int flags);
 
 /* The following are helper functions for parametrical options support. */
 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
@@ -543,7 +543,7 @@ bool lpcfg_string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
  * Set a string value, deallocating any existing space, and allocing the space
  * for the string
  */
-static bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
+bool lpcfg_string_set_upper(TALLOC_CTX *mem_ctx, char **dest, const char *src)
 {
        talloc_free(*dest);
 
@@ -727,15 +727,13 @@ int lpcfg_map_parameter(const char *pszParmName)
 */
 struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
 {
-       int parmnum;
+       int num = lpcfg_map_parameter(name);
 
-       if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->get_parm_struct(name);
+       if (num < 0) {
+               return NULL;
        }
 
-       parmnum = lpcfg_map_parameter(name);
-       if (parmnum == -1) return NULL;
-       return &parm_table[parmnum];
+       return &parm_table[num];
 }
 
 /**
@@ -766,14 +764,6 @@ bool lpcfg_parm_is_cmdline(struct loadparm_context *lp_ctx, const char *name)
 {
        int parmnum;
 
-       if (lp_ctx->s3_fns) {
-               struct parm_struct *parm = lp_ctx->s3_fns->get_parm_struct(name);
-               if (parm) {
-                       return parm->flags & FLAG_CMDLINE;
-               }
-               return false;
-       }
-
        parmnum = lpcfg_map_parameter(name);
        if (parmnum == -1) return false;
 
@@ -936,7 +926,7 @@ void copy_service(struct loadparm_service *pserviceDest,
  * Check a service for consistency. Return False if the service is in any way
  * incomplete or faulty, else True.
  */
-static bool lpcfg_service_ok(struct loadparm_service *service)
+bool lpcfg_service_ok(struct loadparm_service *service)
 {
        bool bRetval;
 
@@ -960,6 +950,15 @@ static bool lpcfg_service_ok(struct loadparm_service *service)
                        service->browseable = false;
        }
 
+       if (service->path[0] == '\0' &&
+           strwicmp(service->szService, HOMES_NAME) != 0 &&
+           service->msdfs_proxy[0] == '\0')
+       {
+               DEBUG(0, ("WARNING: No path in service %s - making it unavailable!\n",
+                       service->szService));
+               service->bAvailable = false;
+       }
+
        /* If a service is flagged unavailable, log the fact at level 0. */
        if (!service->bAvailable)
                DEBUG(1, ("NOTE: Service %s is flagged unavailable.\n",
@@ -1039,8 +1038,10 @@ bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx)
                        f->modtime = mod_time;
                        talloc_free(f->subfname);
                        f->subfname = talloc_strdup(f, n2);
+                       TALLOC_FREE(n2);
                        return true;
                }
+               TALLOC_FREE(n2);
        }
        return false;
 }
@@ -1069,7 +1070,7 @@ bool lp_set_enum_parm( struct parm_struct *parm, const char *pszParmValue,
  Handle the "realm" parameter
 ***************************************************************************/
 
-bool handle_realm(struct loadparm_context *lp_ctx, int unused,
+bool handle_realm(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                  const char *pszParmValue, char **ptr)
 {
        char *upper;
@@ -1086,15 +1087,9 @@ bool handle_realm(struct loadparm_context *lp_ctx, int unused,
                return false;
        }
 
-       if (lp_ctx->s3_fns != NULL) {
-               lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
-               lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->realm, upper);
-               lp_ctx->s3_fns->lp_string_set(&lp_ctx->globals->dnsdomain, lower);
-       } else {
-               lpcfg_string_set(lp_ctx, ptr, pszParmValue);
-               lpcfg_string_set(lp_ctx, &lp_ctx->globals->realm, upper);
-               lpcfg_string_set(lp_ctx, &lp_ctx->globals->dnsdomain, lower);
-       }
+       lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
+       lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->realm, upper);
+       lpcfg_string_set(lp_ctx->globals->ctx, &lp_ctx->globals->dnsdomain, lower);
 
        return true;
 }
@@ -1103,13 +1098,13 @@ bool handle_realm(struct loadparm_context *lp_ctx, int unused,
  Handle the include operation.
 ***************************************************************************/
 
-bool handle_include(struct loadparm_context *lp_ctx, int unused,
+bool handle_include(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                           const char *pszParmValue, char **ptr)
 {
        char *fname;
 
        if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->lp_include(lp_ctx, unused, pszParmValue, ptr);
+               return lp_ctx->s3_fns->lp_include(lp_ctx, service, pszParmValue, ptr);
        }
 
        fname = standard_sub_basic(lp_ctx, pszParmValue);
@@ -1119,7 +1114,7 @@ bool handle_include(struct loadparm_context *lp_ctx, int unused,
        lpcfg_string_set(lp_ctx, ptr, fname);
 
        if (file_exist(fname))
-               return pm_process(fname, do_section, do_parameter, lp_ctx);
+               return pm_process(fname, do_section, lpcfg_do_parameter, lp_ctx);
 
        DEBUG(2, ("Can't find include file %s\n", fname));
 
@@ -1130,37 +1125,31 @@ bool handle_include(struct loadparm_context *lp_ctx, int unused,
  Handle the interpretation of the copy parameter.
 ***************************************************************************/
 
-bool handle_copy(struct loadparm_context *lp_ctx, int snum,
+bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                        const char *pszParmValue, char **ptr)
 {
        bool bRetval;
        struct loadparm_service *serviceTemp = NULL;
-       struct loadparm_service *current = NULL;
 
        bRetval = false;
 
        DEBUG(3, ("Copying service from service %s\n", pszParmValue));
 
        serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
-       if (lp_ctx->s3_fns != NULL) {
-               current = lp_ctx->s3_fns->get_servicebynum(snum);
-       } else {
-               current = lp_ctx->currentService;
-       }
 
-       if (current == NULL) {
-               DEBUG(0, ("Unable to copy service - invalid service destination"));
+       if (service == NULL) {
+               DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
                return false;
        }
 
        if (serviceTemp != NULL) {
-               if (serviceTemp == current) {
+               if (serviceTemp == service) {
                        DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
                } else {
-                       copy_service(current,
+                       copy_service(service,
                                     serviceTemp,
-                                    current->copymap);
-                       lpcfg_string_set(current, ptr, pszParmValue);
+                                    service->copymap);
+                       lpcfg_string_set(service, ptr, pszParmValue);
 
                        bRetval = true;
                }
@@ -1173,28 +1162,23 @@ bool handle_copy(struct loadparm_context *lp_ctx, int snum,
        return bRetval;
 }
 
-bool handle_debug_list(struct loadparm_context *lp_ctx, int unused,
+bool handle_debug_list(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                        const char *pszParmValue, char **ptr)
 {
-       if (lp_ctx->s3_fns != NULL) {
-               lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
-       } else {
-               lpcfg_string_set(lp_ctx, ptr, pszParmValue);
-       }
+       lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
 
        return debug_parse_levels(pszParmValue);
 }
 
-bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
+bool handle_logfile(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                    const char *pszParmValue, char **ptr)
 {
-       if (lp_ctx->s3_fns != NULL) {
-               lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
-       } else {
+       if (lp_ctx->s3_fns == NULL) {
                debug_set_logfile(pszParmValue);
-               lpcfg_string_set(lp_ctx, ptr, pszParmValue);
        }
 
+       lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
+
        return true;
 }
 
@@ -1202,25 +1186,23 @@ bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
  * These special charset handling methods only run in the source3 code.
  */
 
-bool handle_charset(struct loadparm_context *lp_ctx, int snum,
+bool handle_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                        const char *pszParmValue, char **ptr)
 {
        if (lp_ctx->s3_fns) {
                if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
-                       lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
                        global_iconv_handle = smb_iconv_handle_reinit(NULL,
                                                        lpcfg_dos_charset(lp_ctx),
                                                        lpcfg_unix_charset(lp_ctx),
                                                        true, global_iconv_handle);
                }
 
-               return true;
        }
-       return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
+       return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
 
 }
 
-bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
+bool handle_dos_charset(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                        const char *pszParmValue, char **ptr)
 {
        bool is_utf8 = false;
@@ -1253,23 +1235,20 @@ bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
                                        DEFAULT_DOS_CHARSET));
                                pszParmValue = DEFAULT_DOS_CHARSET;
                        }
-                       lp_ctx->s3_fns->lp_string_set(ptr, pszParmValue);
                        global_iconv_handle = smb_iconv_handle_reinit(NULL,
                                                        lpcfg_dos_charset(lp_ctx),
                                                        lpcfg_unix_charset(lp_ctx),
                                                        true, global_iconv_handle);
                }
-               return true;
        }
 
-       return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
+       return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
 }
 
-bool handle_printing(struct loadparm_context *lp_ctx, int snum,
+bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *service,
                            const char *pszParmValue, char **ptr)
 {
        static int parm_num = -1;
-       struct loadparm_service *s;
 
        if (parm_num == -1) {
                parm_num = lpcfg_map_parameter("printing");
@@ -1280,19 +1259,18 @@ bool handle_printing(struct loadparm_context *lp_ctx, int snum,
        }
 
        if (lp_ctx->s3_fns) {
-               if ( snum < 0 ) {
-                       s = lp_ctx->sDefault;
-                       lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
+               if (service == NULL) {
+                       init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
                } else {
-                       s = lp_ctx->services[snum];
-                       lp_ctx->s3_fns->init_printer_values(s, s);
+                       init_printer_values(lp_ctx, service, service);
                }
        }
 
        return true;
 }
 
-bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
+bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, struct loadparm_service *service,
+                            const char *pszParmValue, char **ptr)
 {
        lp_ctx->globals->ldap_debug_level = lp_int(pszParmValue);
 
@@ -1302,7 +1280,8 @@ bool handle_ldap_debug_level(struct loadparm_context *lp_ctx, int snum, const ch
        return true;
 }
 
-bool handle_netbios_aliases(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
+bool handle_netbios_aliases(struct loadparm_context *lp_ctx, struct loadparm_service *service,
+                           const char *pszParmValue, char **ptr)
 {
        TALLOC_FREE(lp_ctx->globals->netbios_aliases);
        lp_ctx->globals->netbios_aliases = (const char **)str_list_make_v3(lp_ctx->globals->ctx,
@@ -1318,31 +1297,76 @@ bool handle_netbios_aliases(struct loadparm_context *lp_ctx, int snum, const cha
  * idmap related parameters
  */
 
-bool handle_idmap_backend(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
+bool handle_idmap_backend(struct loadparm_context *lp_ctx, struct loadparm_service *service,
+                         const char *pszParmValue, char **ptr)
 {
        if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : backend", pszParmValue);
+               lp_do_parameter_parametric(lp_ctx, service, "idmap config * : backend",
+                                          pszParmValue, 0);
        }
 
-       return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
+       return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
 }
 
-bool handle_idmap_uid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
+bool handle_idmap_uid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
+                     const char *pszParmValue, char **ptr)
 {
        if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
+               lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
+                                          pszParmValue, 0);
        }
 
-       return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
+       return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
 }
 
-bool handle_idmap_gid(struct loadparm_context *lp_ctx, int snum, const char *pszParmValue, char **ptr)
+bool handle_idmap_gid(struct loadparm_context *lp_ctx, struct loadparm_service *service,
+                     const char *pszParmValue, char **ptr)
 {
        if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->lp_do_parameter(snum, "idmap config * : range", pszParmValue);
+               lp_do_parameter_parametric(lp_ctx, service, "idmap config * : range",
+                                          pszParmValue, 0);
+       }
+
+       return lpcfg_string_set(lp_ctx->globals->ctx, ptr, pszParmValue);
+}
+
+bool handle_smb_ports(struct loadparm_context *lp_ctx, struct loadparm_service *service,
+                     const char *pszParmValue, char **ptr)
+{
+       static int parm_num = -1;
+       int i;
+       const char **list;
+
+       if (!pszParmValue || !*pszParmValue) {
+               return false;
+       }
+
+       if (parm_num == -1) {
+               parm_num = lpcfg_map_parameter("smb ports");
+       }
+
+       if(!set_variable_helper(lp_ctx->globals->ctx, parm_num, ptr, "smb ports",
+                               pszParmValue)) {
+               return false;
        }
 
-       return lpcfg_string_set(lp_ctx, ptr, pszParmValue);
+       list = lp_ctx->globals->smb_ports;
+       if (list == NULL) {
+               return false;
+       }
+
+       /* Check that each port is a valid integer and within range */
+       for (i = 0; list[i] != NULL; i++) {
+               char *end = NULL;
+               int port = 0;
+               port = strtol(list[i], &end, 10);
+               if (*end != '\0' || port <= 0 || port > 65535) {
+                       TALLOC_FREE(list);
+                       return false;
+               }
+       }
+
+       return true;
 }
 
 /***************************************************************************
@@ -1386,7 +1410,14 @@ static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
 
        if (service == NULL) {
                data = &lp_ctx->globals->param_opt;
-               mem_ctx = lp_ctx->globals;
+               /**
+                * s3 code cannot deal with parametric options stored on the globals ctx.
+                */
+               if (lp_ctx->s3_fns != NULL) {
+                       mem_ctx = NULL;
+               } else {
+                       mem_ctx = lp_ctx->globals->ctx;
+               }
        } else {
                data = &service->param_opt;
                mem_ctx = service;
@@ -1399,29 +1430,18 @@ static bool lp_do_parameter_parametric(struct loadparm_context *lp_ctx,
        return true;
 }
 
-static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
-                        const char *pszParmName, const char *pszParmValue,
-                        struct loadparm_context *lp_ctx, bool on_globals)
+static bool set_variable_helper(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
+                        const char *pszParmName, const char *pszParmValue)
 {
        int i;
-       /* if it is a special case then go ahead */
-       if (parm_table[parmnum].special) {
-               bool ret;
-               ret = parm_table[parmnum].special(lp_ctx, -1, pszParmValue,
-                                                 (char **)parm_ptr);
-               if (!ret) {
-                       return false;
-               }
-               goto mark_non_default;
-       }
 
-       /* now switch on the type of variable it is */
+       /* switch on the type of variable it is */
        switch (parm_table[parmnum].type)
        {
                case P_BOOL: {
                        bool b;
                        if (!set_boolean(pszParmValue, &b)) {
-                               DEBUG(0, ("set_variable(%s): value is not "
+                               DEBUG(0, ("set_variable_helper(%s): value is not "
                                          "boolean!\n", pszParmValue));
                                return false;
                        }
@@ -1432,7 +1452,7 @@ static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
                case P_BOOLREV: {
                        bool b;
                        if (!set_boolean(pszParmValue, &b)) {
-                               DEBUG(0, ("set_variable(%s): value is not "
+                               DEBUG(0, ("set_variable_helper(%s): value is not "
                                          "boolean!\n", pszParmValue));
                                return false;
                        }
@@ -1466,7 +1486,7 @@ static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
                                }
                        }
 
-                       DEBUG(0, ("set_variable(%s): value is not "
+                       DEBUG(0, ("set_variable_helper(%s): value is not "
                                  "a valid size specifier!\n", pszParmValue));
                        return false;
                }
@@ -1474,13 +1494,18 @@ static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
                case P_CMDLIST:
                        TALLOC_FREE(*(char ***)parm_ptr);
                        *(const char * const **)parm_ptr
-                               = (const char * const *)str_list_make(mem_ctx,
-                                                                     pszParmValue, NULL);
+                               = (const char * const *)str_list_make_v3(mem_ctx,
+                                                                        pszParmValue, NULL);
                        break;
+
                case P_LIST:
                {
-                       char **new_list = str_list_make(mem_ctx,
+                       char **new_list = str_list_make_v3(mem_ctx,
                                                        pszParmValue, NULL);
+                       if (new_list == NULL) {
+                               break;
+                       }
+
                        for (i=0; new_list[i]; i++) {
                                if (*(const char ***)parm_ptr != NULL &&
                                    new_list[i][0] == '+' &&
@@ -1509,6 +1534,7 @@ static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
                        }
                        break;
                }
+
                case P_STRING:
                        lpcfg_string_set(mem_ctx, (char **)parm_ptr, pszParmValue);
                        break;
@@ -1527,6 +1553,33 @@ static bool set_variable(TALLOC_CTX *mem_ctx, int parmnum, void *parm_ptr,
                        break;
        }
 
+       return true;
+
+}
+
+bool set_variable(TALLOC_CTX *mem_ctx, struct loadparm_service *service, int parmnum, void *parm_ptr,
+                        const char *pszParmName, const char *pszParmValue,
+                        struct loadparm_context *lp_ctx, bool on_globals)
+{
+       int i;
+       bool ok;
+
+       /* if it is a special case then go ahead */
+       if (parm_table[parmnum].special) {
+               ok = parm_table[parmnum].special(lp_ctx, service, pszParmValue,
+                                                 (char **)parm_ptr);
+               if (!ok) {
+                       return false;
+               }
+               goto mark_non_default;
+       }
+
+       ok = set_variable_helper(mem_ctx, parmnum, parm_ptr, pszParmName, pszParmValue);
+
+       if (!ok) {
+               return false;
+       }
+
 mark_non_default:
        if (on_globals && (lp_ctx->flags[parmnum] & FLAG_DEFAULT)) {
                lp_ctx->flags[parmnum] &= ~FLAG_DEFAULT;
@@ -1562,9 +1615,14 @@ bool lpcfg_do_global_parameter(struct loadparm_context *lp_ctx,
                return true;
        }
 
+       if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
+               DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
+                         pszParmName));
+       }
+
        parm_ptr = lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[parmnum]);
 
-       return set_variable(lp_ctx->globals, parmnum, parm_ptr,
+       return set_variable(lp_ctx->globals->ctx, NULL, parmnum, parm_ptr,
                            pszParmName, pszParmValue, lp_ctx, true);
 }
 
@@ -1590,6 +1648,11 @@ bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
                return true;
        }
 
+       if (parm_table[parmnum].flags & FLAG_DEPRECATED) {
+               DEBUG(1, ("WARNING: The \"%s\" option is deprecated\n",
+                         pszParmName));
+       }
+
        if (parm_table[parmnum].p_class == P_GLOBAL) {
                DEBUG(0,
                      ("Global parameter %s found in service section!\n",
@@ -1608,7 +1671,7 @@ bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
                    parm_table[i].p_class == parm_table[parmnum].p_class)
                        bitmap_clear(service->copymap, i);
 
-       return set_variable(service, parmnum, parm_ptr, pszParmName,
+       return set_variable(service, service, parmnum, parm_ptr, pszParmName,
                            pszParmValue, lp_ctx, false);
 }
 
@@ -1616,7 +1679,7 @@ bool lpcfg_do_service_parameter(struct loadparm_context *lp_ctx,
  * Process a parameter.
  */
 
-static bool do_parameter(const char *pszParmName, const char *pszParmValue,
+bool lpcfg_do_parameter(const char *pszParmName, const char *pszParmValue,
                         void *userdata)
 {
        struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
@@ -1662,16 +1725,19 @@ bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
 
        while (isspace((unsigned char)*pszParmValue)) pszParmValue++;
 
-       if (lp_ctx->s3_fns) {
-               return lp_ctx->s3_fns->set_cmdline(pszParmName, pszParmValue);
-       }
-
        parmnum = lpcfg_map_parameter(pszParmName);
 
        if (parmnum < 0 && strchr(pszParmName, ':')) {
                /* set a parametric option */
-               return lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
-                                                 pszParmValue, FLAG_CMDLINE);
+               bool ok;
+               ok = lp_do_parameter_parametric(lp_ctx, NULL, pszParmName,
+                                               pszParmValue, FLAG_CMDLINE);
+               if (lp_ctx->s3_fns != NULL) {
+                       if (ok) {
+                               lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
+                       }
+               }
+               return ok;
        }
 
        if (parmnum < 0) {
@@ -1703,6 +1769,10 @@ bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
                lp_ctx->flags[i] |= FLAG_CMDLINE;
        }
 
+       if (lp_ctx->s3_fns != NULL) {
+               lp_ctx->s3_fns->store_cmdline(pszParmName, pszParmValue);
+       }
+
        return true;
 }
 
@@ -1867,8 +1937,15 @@ static bool do_section(const char *pszSectionName, void *userdata)
 {
        struct loadparm_context *lp_ctx = (struct loadparm_context *)userdata;
        bool bRetval;
-       bool isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
+       bool isglobal;
+
+       if (lp_ctx->s3_fns != NULL) {
+               return lp_ctx->s3_fns->do_section(pszSectionName, lp_ctx);
+       }
+
+       isglobal = ((strwicmp(pszSectionName, GLOBAL_NAME) == 0) ||
                         (strwicmp(pszSectionName, GLOBAL_NAME2) == 0));
+
        bRetval = false;
 
        /* if we've just struck a global section, note the fact. */
@@ -1908,9 +1985,9 @@ static bool do_section(const char *pszSectionName, void *userdata)
  * Determine if a particular base parameter is currently set to the default value.
  */
 
-static bool is_default(struct loadparm_service *sDefault, int i)
+static bool is_default(void *base_structure, int i)
 {
-       void *def_ptr = ((char *)sDefault) + parm_table[i].offset;
+       void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
        switch (parm_table[i].type) {
                case P_CMDLIST:
                case P_LIST:
@@ -1941,7 +2018,7 @@ static bool is_default(struct loadparm_service *sDefault, int i)
  *Display the contents of the global structure.
  */
 
-static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
+void lpcfg_dump_globals(struct loadparm_context *lp_ctx, FILE *f,
                         bool show_defaults)
 {
        int i;
@@ -1952,8 +2029,16 @@ static void dump_globals(struct loadparm_context *lp_ctx, FILE *f,
        for (i = 0; parm_table[i].label; i++)
                if (parm_table[i].p_class == P_GLOBAL &&
                    (i == 0 || (parm_table[i].offset != parm_table[i - 1].offset))) {
-                       if (!show_defaults && (lp_ctx->flags[i] & FLAG_DEFAULT))
-                               continue;
+                       if (!show_defaults) {
+                               if (lp_ctx->flags && (lp_ctx->flags[i] & FLAG_DEFAULT)) {
+                                       continue;
+                               }
+
+                               if (is_default(lp_ctx->globals, i)) {
+                                       continue;
+                               }
+                       }
+
                        fprintf(f, "\t%s = ", parm_table[i].label);
                        lpcfg_print_parameter(&parm_table[i], lpcfg_parm_ptr(lp_ctx, NULL, &parm_table[i]), f);
                        fprintf(f, "\n");
@@ -2014,6 +2099,9 @@ void lpcfg_dump_a_service(struct loadparm_service * pService, struct loadparm_se
        }
        if (pService->param_opt != NULL) {
                for (data = pService->param_opt; data; data = data->next) {
+                       if (!show_defaults && (data->priority & FLAG_DEFAULT)) {
+                               continue;
+                       }
                        fprintf(f, "\t%s = %s\n", data->key, data->value);
                }
         }
@@ -2077,6 +2165,127 @@ static void lpcfg_add_auto_services(struct loadparm_context *lp_ctx,
        return;
 }
 
+/***************************************************************************
+ Initialise the sDefault parameter structure for the printer values.
+***************************************************************************/
+
+void init_printer_values(struct loadparm_context *lp_ctx, TALLOC_CTX *ctx,
+                        struct loadparm_service *pService)
+{
+       /* choose defaults depending on the type of printing */
+       switch (pService->printing) {
+               case PRINT_BSD:
+               case PRINT_AIX:
+               case PRINT_LPRNT:
+               case PRINT_LPROS2:
+                       lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
+                       lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
+                       lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
+                       break;
+
+               case PRINT_LPRNG:
+               case PRINT_PLP:
+                       lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P'%p'");
+                       lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P'%p' %j");
+                       lpcfg_string_set(ctx, &pService->print_command, "lpr -r -P'%p' %s");
+                       lpcfg_string_set(ctx, &pService->queuepause_command, "lpc stop '%p'");
+                       lpcfg_string_set(ctx, &pService->queueresume_command, "lpc start '%p'");
+                       lpcfg_string_set(ctx, &pService->lppause_command, "lpc hold '%p' %j");
+                       lpcfg_string_set(ctx, &pService->lpresume_command, "lpc release '%p' %j");
+                       break;
+
+               case PRINT_CUPS:
+               case PRINT_IPRINT:
+                       /* set the lpq command to contain the destination printer
+                          name only.  This is used by cups_queue_get() */
+                       lpcfg_string_set(ctx, &pService->lpq_command, "%p");
+                       lpcfg_string_set(ctx, &pService->lprm_command, "");
+                       lpcfg_string_set(ctx, &pService->print_command, "");
+                       lpcfg_string_set(ctx, &pService->lppause_command, "");
+                       lpcfg_string_set(ctx, &pService->lpresume_command, "");
+                       lpcfg_string_set(ctx, &pService->queuepause_command, "");
+                       lpcfg_string_set(ctx, &pService->queueresume_command, "");
+                       break;
+
+               case PRINT_SYSV:
+               case PRINT_HPUX:
+                       lpcfg_string_set(ctx, &pService->lpq_command, "lpstat -o%p");
+                       lpcfg_string_set(ctx, &pService->lprm_command, "cancel %p-%j");
+                       lpcfg_string_set(ctx, &pService->print_command, "lp -c -d%p %s; rm %s");
+                       lpcfg_string_set(ctx, &pService->queuepause_command, "disable %p");
+                       lpcfg_string_set(ctx, &pService->queueresume_command, "enable %p");
+#ifndef HPUX
+                       lpcfg_string_set(ctx, &pService->lppause_command, "lp -i %p-%j -H hold");
+                       lpcfg_string_set(ctx, &pService->lpresume_command, "lp -i %p-%j -H resume");
+#endif /* HPUX */
+                       break;
+
+               case PRINT_QNX:
+                       lpcfg_string_set(ctx, &pService->lpq_command, "lpq -P%p");
+                       lpcfg_string_set(ctx, &pService->lprm_command, "lprm -P%p %j");
+                       lpcfg_string_set(ctx, &pService->print_command, "lp -r -P%p %s");
+                       break;
+
+#if defined(DEVELOPER) || defined(ENABLE_SELFTEST)
+
+       case PRINT_TEST:
+       case PRINT_VLP: {
+               const char *tdbfile;
+               TALLOC_CTX *tmp_ctx = talloc_new(ctx);
+               const char *tmp;
+
+               tmp = lpcfg_parm_string(lp_ctx, NULL, "vlp", "tdbfile");
+               if (tmp == NULL) {
+                       tmp = "/tmp/vlp.tdb";
+               }
+
+               tdbfile = talloc_asprintf(tmp_ctx, "tdbfile=%s", tmp);
+               if (tdbfile == NULL) {
+                       tdbfile="tdbfile=/tmp/vlp.tdb";
+               }
+
+               tmp = talloc_asprintf(tmp_ctx, "vlp %s print %%p %%s",
+                                     tdbfile);
+               lpcfg_string_set(ctx, &pService->print_command,
+                          tmp ? tmp : "vlp print %p %s");
+
+               tmp = talloc_asprintf(tmp_ctx, "vlp %s lpq %%p",
+                                     tdbfile);
+               lpcfg_string_set(ctx, &pService->lpq_command,
+                          tmp ? tmp : "vlp lpq %p");
+
+               tmp = talloc_asprintf(tmp_ctx, "vlp %s lprm %%p %%j",
+                                     tdbfile);
+               lpcfg_string_set(ctx, &pService->lprm_command,
+                          tmp ? tmp : "vlp lprm %p %j");
+
+               tmp = talloc_asprintf(tmp_ctx, "vlp %s lppause %%p %%j",
+                                     tdbfile);
+               lpcfg_string_set(ctx, &pService->lppause_command,
+                          tmp ? tmp : "vlp lppause %p %j");
+
+               tmp = talloc_asprintf(tmp_ctx, "vlp %s lpresume %%p %%j",
+                                     tdbfile);
+               lpcfg_string_set(ctx, &pService->lpresume_command,
+                          tmp ? tmp : "vlp lpresume %p %j");
+
+               tmp = talloc_asprintf(tmp_ctx, "vlp %s queuepause %%p",
+                                     tdbfile);
+               lpcfg_string_set(ctx, &pService->queuepause_command,
+                          tmp ? tmp : "vlp queuepause %p");
+
+               tmp = talloc_asprintf(tmp_ctx, "vlp %s queueresume %%p",
+                                     tdbfile);
+               lpcfg_string_set(ctx, &pService->queueresume_command,
+                          tmp ? tmp : "vlp queueresume %p");
+               TALLOC_FREE(tmp_ctx);
+
+               break;
+       }
+#endif /* DEVELOPER */
+
+       }
+}
 
 /**
  * Unload unused services.
@@ -2214,7 +2423,7 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
        lpcfg_do_global_parameter(lp_ctx, "max connections", "0");
 
        lpcfg_do_global_parameter(lp_ctx, "dcerpc endpoint servers", "epmapper wkssvc rpcecho samr netlogon lsarpc spoolss drsuapi dssetup unixinfo browser eventlog6 backupkey dnsserver");
-       lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbind ntp_signd kcc dnsupdate dns");
+       lpcfg_do_global_parameter(lp_ctx, "server services", "s3fs rpc nbt wrepl ldap cldap kdc drepl winbindd ntp_signd kcc dnsupdate dns");
        lpcfg_do_global_parameter(lp_ctx, "kccsrv:samba_kcc", "true");
        /* the winbind method for domain controllers is for both RODC
           auth forwarding and for trusted domains */
@@ -2294,7 +2503,7 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
        lpcfg_do_global_parameter_var(lp_ctx, "samba kcc command",
                                        "%s/samba_kcc", dyn_SCRIPTSBINDIR);
        lpcfg_do_global_parameter(lp_ctx, "template shell", "/bin/false");
-       lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%WORKGROUP%/%ACCOUNTNAME%");
+       lpcfg_do_global_parameter(lp_ctx, "template homedir", "/home/%D/%U");
 
        lpcfg_do_global_parameter(lp_ctx, "client signing", "default");
        lpcfg_do_global_parameter(lp_ctx, "server signing", "default");
@@ -2402,6 +2611,8 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
 
        lpcfg_do_global_parameter(lp_ctx, "winbind reconnect delay", "30");
 
+       lpcfg_do_global_parameter(lp_ctx, "winbind request timeout", "60");
+
        lpcfg_do_global_parameter(lp_ctx, "nt acl support", "yes");
 
        lpcfg_do_global_parameter(lp_ctx, "acl check permissions", "yes");
@@ -2536,6 +2747,13 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
                }
        }
 
+       for (parm=lp_ctx->sDefault->param_opt; parm; parm=parm->next) {
+               if (!(parm->priority & FLAG_CMDLINE)) {
+                       parm->priority |= FLAG_DEFAULT;
+               }
+       }
+
+
        return lp_ctx;
 }
 
@@ -2570,6 +2788,8 @@ struct loadparm_context *loadparm_init_s3(TALLOC_CTX *mem_ctx,
        }
        loadparm_context->s3_fns = s3_fns;
        loadparm_context->globals = s3_fns->globals;
+       loadparm_context->flags = s3_fns->flags;
+
        return loadparm_context;
 }
 
@@ -2681,7 +2901,7 @@ bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
 
        /* We get sections first, so have to start 'behind' to make up */
        lp_ctx->currentService = NULL;
-       bRetval = pm_process(n2, do_section, do_parameter, lp_ctx);
+       bRetval = pm_process(n2, do_section, lpcfg_do_parameter, lp_ctx);
 
        /* finish up the last section */
        DEBUG(4, ("pm_process() returned %s\n", BOOLSTR(bRetval)));
@@ -2736,7 +2956,7 @@ void lpcfg_dump(struct loadparm_context *lp_ctx, FILE *f, bool show_defaults,
                return;
        }
 
-       dump_globals(lp_ctx, f, show_defaults);
+       lpcfg_dump_globals(lp_ctx, f, show_defaults);
 
        lpcfg_dump_a_service(lp_ctx->sDefault, lp_ctx->sDefault, f, lp_ctx->flags, show_defaults);