param: get rid of unnecessary get_default_loadparm_service pointer
[sfrench/samba-autobuild/.git] / lib / param / loadparm.c
index 6f8eedb660f4ad99442c8a9ce77eccf2499fc5b5..2b73d40f6c3f35c794599abcf60eea3bd6e7caf5 100644 (file)
@@ -74,9 +74,6 @@
 
 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;
 }
 
@@ -730,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];
 }
 
 /**
@@ -1043,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;
 }
@@ -1141,7 +1138,7 @@ bool handle_copy(struct loadparm_context *lp_ctx, struct loadparm_service *servi
        serviceTemp = lpcfg_getservicebyname(lp_ctx, pszParmValue);
 
        if (service == NULL) {
-               DEBUG(0, ("Unable to copy service - invalid service destination"));
+               DEBUG(0, ("Unable to copy service - invalid service destination.\n"));
                return false;
        }
 
@@ -1252,7 +1249,6 @@ bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *s
                            const char *pszParmValue, char **ptr)
 {
        static int parm_num = -1;
-       struct loadparm_service *s;
 
        if (parm_num == -1) {
                parm_num = lpcfg_map_parameter("printing");
@@ -1264,11 +1260,9 @@ bool handle_printing(struct loadparm_context *lp_ctx, struct loadparm_service *s
 
        if (lp_ctx->s3_fns) {
                if (service == NULL) {
-                       s = lp_ctx->sDefault;
-                       lp_ctx->s3_fns->init_printer_values(lp_ctx->globals->ctx, s);
+                       init_printer_values(lp_ctx, lp_ctx->globals->ctx, lp_ctx->sDefault);
                } else {
-                       s = service;
-                       lp_ctx->s3_fns->init_printer_values(s, s);
+                       init_printer_values(lp_ctx, service, service);
                }
        }
 
@@ -1754,14 +1748,8 @@ bool lpcfg_set_cmdline(struct loadparm_context *lp_ctx, const char *pszParmName,
        /* reset the CMDLINE flag in case this has been called before */
        lp_ctx->flags[parmnum] &= ~FLAG_CMDLINE;
 
-       if (lp_ctx->s3_fns != NULL) {
-               if (!lp_ctx->s3_fns->lp_do_parameter(-1, pszParmName, pszParmValue)) {
-                       return false;
-               }
-       } else {
-               if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
-                       return false;
-               }
+       if (!lpcfg_do_global_parameter(lp_ctx, pszParmName, pszParmValue)) {
+               return false;
        }
 
        lp_ctx->flags[parmnum] |= FLAG_CMDLINE;
@@ -1997,7 +1985,7 @@ static bool do_section(const char *pszSectionName, void *userdata)
  * Determine if a particular base parameter is currently set to the default value.
  */
 
-bool is_default(void *base_structure, int i)
+static bool is_default(void *base_structure, int i)
 {
        void *def_ptr = ((char *)base_structure) + parm_table[i].offset;
        switch (parm_table[i].type) {
@@ -2030,7 +2018,7 @@ bool is_default(void *base_structure, int i)
  *Display the contents of the global structure.
  */
 
-static void lpcfg_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;
@@ -2177,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.