param: Add hooks to s3 parm_struct and the parameters void * pointer
authorAndrew Bartlett <abartlet@samba.org>
Thu, 7 Jul 2011 10:33:55 +0000 (20:33 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 8 Jul 2011 09:23:23 +0000 (11:23 +0200)
This is to that the pyparam hooks can use the hooks to connect with
the s3 loadparm system.  This now also includes per-service
parameters.

Andrew Bartlett

source3/include/proto.h
source3/param/loadparm.c
source3/param/loadparm_ctx.c
source4/param/loadparm.c
source4/param/param.h
source4/param/pyparam.c
source4/script/mks3param.pl

index 6d901a07dce1f4bad1551e9016b85be6c6228973..d719bd908967258a3875630abb5e57f75b26e14f 100644 (file)
@@ -1549,6 +1549,8 @@ int lp_server_signing(void);
 int lp_client_ldap_sasl_wrapping(void);
 char *lp_parm_talloc_string(int snum, const char *type, const char *option, const char *def);
 const char *lp_parm_const_string(int snum, const char *type, const char *option, const char *def);
+struct loadparm_service;
+const char *lp_parm_const_string_service(struct loadparm_service *service, const char *type, const char *option);
 const char **lp_parm_string_list(int snum, const char *type, const char *option, const char **def);
 int lp_parm_int(int snum, const char *type, const char *option, int def);
 unsigned long lp_parm_ulong(int snum, const char *type, const char *option, unsigned long def);
@@ -1586,8 +1588,9 @@ const char *lp_ldap_machine_suffix(void);
 const char *lp_ldap_user_suffix(void);
 const char *lp_ldap_group_suffix(void);
 const char *lp_ldap_idmap_suffix(void);
-struct loadparm_service;
 struct parm_struct;
+/* Return a pointer to a service by name.  */
+struct loadparm_service *lp_service(const char *pszServiceName);
 void *lp_parm_ptr(struct loadparm_service *service, struct parm_struct *parm);
 void *lp_local_ptr_by_snum(int snum, struct parm_struct *parm);
 bool lp_do_parameter(int snum, const char *pszParmName, const char *pszParmValue);
index 045a47e1071c237f4c8553f87bf50c3533b67021..e143726f66b3f26a1bdc5b843f40f8fafc714615 100644 (file)
@@ -5571,20 +5571,18 @@ static bool is_synonym_of(int parm1, int parm2, bool *inverse);
  * pointer to parametrical option value if it exists or NULL otherwise. Actual
  * parametrical functions are quite simple
  */
-static struct param_opt_struct *get_parametrics(int snum, const char *type,
-                                               const char *option)
+static struct param_opt_struct *get_parametrics_by_service(struct loadparm_service *service, const char *type,
+                                                          const char *option)
 {
        bool global_section = false;
        char* param_key;
         struct param_opt_struct *data;
 
-       if (snum >= iNumServices) return NULL;
-
-       if (snum < 0) { 
+       if (service == NULL) {
                data = Globals.param_opt;
                global_section = true;
        } else {
-               data = ServicePtrs[snum]->param_opt;
+               data = service->param_opt;
        }
 
        if (asprintf(&param_key, "%s:%s", type, option) == -1) {
@@ -5618,6 +5616,25 @@ static struct param_opt_struct *get_parametrics(int snum, const char *type,
        return NULL;
 }
 
+/*
+ * This is a helper function for parametrical options support.  It returns a
+ * pointer to parametrical option value if it exists or NULL otherwise. Actual
+ * parametrical functions are quite simple
+ */
+static struct param_opt_struct *get_parametrics(int snum, const char *type,
+                                               const char *option)
+{
+        struct param_opt_struct *data;
+
+       if (snum >= iNumServices) return NULL;
+
+       if (snum < 0) {
+               return get_parametrics_by_service(NULL, type, option);
+       } else {
+               return get_parametrics_by_service(ServicePtrs[snum], type, option);
+       }
+}
+
 
 #define MISSING_PARAMETER(name) \
     DEBUG(0, ("%s(): value is NULL or empty!\n", #name))
@@ -5723,6 +5740,17 @@ const char *lp_parm_const_string(int snum, const char *type, const char *option,
        return data->value;
 }
 
+const char *lp_parm_const_string_service(struct loadparm_service *service, const char *type, const char *option)
+{
+       struct param_opt_struct *data = get_parametrics_by_service(service, type, option);
+
+       if (data == NULL||data->value==NULL)
+               return NULL;
+
+       return data->value;
+}
+
+
 /* Return parametric option from a given service. Type is a part of option before ':' */
 /* Parametric option has following syntax: 'Type: option = value' */
 
@@ -6525,6 +6553,17 @@ static int getservicebyname(const char *pszServiceName, struct loadparm_service
        return (iService);
 }
 
+/* Return a pointer to a service by name.  Unlike getservicebyname, it does not copy the service */
+struct loadparm_service *lp_service(const char *pszServiceName)
+{
+       int iService = getservicebyname(pszServiceName, NULL);
+       if (iService == -1 || !LP_SNUM_OK(iService)) {
+               return NULL;
+       }
+       return ServicePtrs[iService];
+}
+
+
 /***************************************************************************
  Copy a service structure to another.
  If pcopymapDest is NULL then copy all fields
index e80f6f1844442ea703a0a2c9bda81e590544cf52..0136c8bef4ee2001c7f44394c41fef197e907b6e 100644 (file)
 #include "includes.h"
 #include "../source4/param/s3_param.h"
 
-static const char *get_parametric(const char *type, const char *option)
-{
-       return lp_parm_const_string(-1, type, option, NULL);
-}
-
 /* These are in the order that they appear in the s4 loadparm file.
  * All of the s4 loadparm functions should be here eventually, once
  * they are implemented in the s3 loadparm, have the same format (enum
  * values in particular) and defaults. */
 static const struct loadparm_s3_context s3_fns = 
 {
-       .get_parametric = get_parametric,
+       .get_parametric = lp_parm_const_string_service,
+       .get_parm_struct = lp_get_parameter,
+       .get_parm_ptr = lp_parm_ptr,
+       .get_service = lp_service,
 
        .server_role = lp_server_role,
 
index eafe8333eac844b0084eb44329410dcb95d4eb3a..0a71d027710e4d2a53418943684c0aebcdc11a6a 100644 (file)
@@ -1311,14 +1311,6 @@ struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx)
        return lp_ctx->sDefault;
 }
 
-/*
-  return the parameter table
-*/
-struct parm_struct *lpcfg_parm_table(void)
-{
-       return parm_table;
-}
-
 /**
  * Convenience routine to grab string parameters into temporary memory
  * and run standard_sub_basic on them.
@@ -1597,8 +1589,7 @@ const char *lpcfg_get_parametric(struct loadparm_context *lp_ctx,
                return NULL;
 
        if (lp_ctx->s3_fns) {
-               SMB_ASSERT(service == NULL);
-               return lp_ctx->s3_fns->get_parametric(type, option);
+               return lp_ctx->s3_fns->get_parametric(service, type, option);
        }
 
        data = (service == NULL ? lp_ctx->globals->param_opt : service->param_opt);
@@ -2047,9 +2038,15 @@ static int map_parameter(const char *pszParmName)
 /**
   return the parameter structure for a parameter
 */
-struct parm_struct *lpcfg_parm_struct(const char *name)
+struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name)
 {
-       int parmnum = map_parameter(name);
+       int parmnum;
+
+       if (lp_ctx->s3_fns) {
+               return lp_ctx->s3_fns->get_parm_struct(name);
+       }
+
+       parmnum = map_parameter(name);
        if (parmnum == -1) return NULL;
        return &parm_table[parmnum];
 }
@@ -2060,6 +2057,10 @@ struct parm_struct *lpcfg_parm_struct(const char *name)
 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
                  struct loadparm_service *service, struct parm_struct *parm)
 {
+       if (lp_ctx->s3_fns) {
+               return lp_ctx->s3_fns->get_parm_ptr(service, parm);
+       }
+
        if (service == NULL) {
                if (parm->p_class == P_LOCAL)
                        return ((char *)lp_ctx->sDefault)+parm->offset;
@@ -3058,7 +3059,7 @@ bool lpcfg_dump_a_parameter(struct loadparm_context *lp_ctx,
        struct parm_struct *parm;
        void *ptr;
 
-       parm = lpcfg_parm_struct(parm_name);
+       parm = lpcfg_parm_struct(lp_ctx, parm_name);
        if (!parm) {
                return false;
        }
@@ -3580,6 +3581,10 @@ struct loadparm_service *lpcfg_service(struct loadparm_context *lp_ctx,
        int iService;
         char *serviceName;
 
+       if (lp_ctx->s3_fns) {
+               return lp_ctx->s3_fns->get_service(service_name);
+       }
+
        for (iService = lp_ctx->iNumServices - 1; iService >= 0; iService--) {
                if (lp_ctx->services[iService] &&
                    lp_ctx->services[iService]->szService) {
index ebf41f7213d4d9570925ac2db3775abaf87d54b2..02837c56d94f6aef6f86ade608b3907f4eebb620 100644 (file)
@@ -68,7 +68,6 @@ int lpcfg_server_role(struct loadparm_context *);
 void reload_charcnv(struct loadparm_context *lp_ctx);
 
 struct loadparm_service *lpcfg_default_service(struct loadparm_context *lp_ctx);
-struct parm_struct *lpcfg_parm_table(void);
 
 
 char *lpcfg_tls_keyfile(TALLOC_CTX *mem_ctx, struct loadparm_context *);
@@ -117,7 +116,7 @@ bool lpcfg_add_home(struct loadparm_context *lp_ctx,
 bool lpcfg_add_printer(struct loadparm_context *lp_ctx,
                    const char *pszPrintername,
                    struct loadparm_service *default_service);
-struct parm_struct *lpcfg_parm_struct(const char *name);
+struct parm_struct *lpcfg_parm_struct(struct loadparm_context *lp_ctx, const char *name);
 void *lpcfg_parm_ptr(struct loadparm_context *lp_ctx,
                  struct loadparm_service *service, struct parm_struct *parm);
 bool lpcfg_file_list_changed(struct loadparm_context *lp_ctx);
index cab009746dbab55405b218092b0684e2990a0795..c07892cc541626dc1f05d97e690658ff21786252 100644 (file)
@@ -73,7 +73,7 @@ static PyObject *py_lp_ctx_get_helper(struct loadparm_context *lp_ctx, const cha
                        return PyString_FromString(value);
                }
 
-               parm = lpcfg_parm_struct(param_name);
+               parm = lpcfg_parm_struct(lp_ctx, param_name);
                if (parm == NULL || parm->p_class == P_GLOBAL) {
                        return NULL;
                }
@@ -93,7 +93,7 @@ static PyObject *py_lp_ctx_get_helper(struct loadparm_context *lp_ctx, const cha
                return PyString_FromString(value);
        } else {
                /* its a global parameter */
-               parm = lpcfg_parm_struct(param_name);
+               parm = lpcfg_parm_struct(lp_ctx, param_name);
                if (parm == NULL) {
                        return NULL;
                }
index 2d99ad59a9c33d3341ae8169287e551615d4e0e4..dee3da192f0514682052759a0d0d1d3fe81ac6a1 100644 (file)
@@ -85,7 +85,10 @@ sub print_header($$)
        $file->("/* This file was automatically generated by mks3param.pl. DO NOT EDIT */\n\n");
        $file->("struct loadparm_s3_context\n");
        $file->("{\n");
-       $file->("\tconst char * (*get_parametric)(const char *type, const char *option);");
+       $file->("\tconst char * (*get_parametric)(struct loadparm_service *, const char *type, const char *option);\n");
+       $file->("\tstruct parm_struct * (*get_parm_struct)(const char *param_name);\n");
+       $file->("\tvoid * (*get_parm_ptr)(struct loadparm_service *service, struct parm_struct *parm);\n");
+       $file->("\tstruct loadparm_service * (*get_service)(const char *service_name);\n");
 }
 
 sub print_footer($$)