r26095: Add function for import a generic configuration file in a loadparm context.
authorJelmer Vernooij <jelmer@samba.org>
Wed, 21 Nov 2007 13:49:27 +0000 (14:49 +0100)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 04:46:00 +0000 (05:46 +0100)
(This used to be commit d74018d05542582515a4d3cc995820667200b301)

source4/param/generic.c
source4/param/loadparm.c
source4/param/param.h

index d65502c02d22321d5ded892e604f683232c19b80..f706dd6407a6d5b6d5a43adc78807a1fefbb9476 100644 (file)
@@ -64,6 +64,9 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se
        struct param_section *section;
        struct param_opt *p;
 
+       SMB_ASSERT(section_name != NULL);
+       SMB_ASSERT(name != NULL);
+
        section = param_get_section(ctx, section_name);
 
        if (section == NULL) {
@@ -72,7 +75,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se
                        return NULL;
 
                section->name = talloc_strdup(section, section_name);
-               DLIST_ADD(ctx->sections, section);
+               DLIST_ADD_END(ctx->sections, section, struct param_section *);
        }
 
        p = param_section_get(section, name);
@@ -82,7 +85,7 @@ static struct param_opt *param_get_add(struct param_context *ctx, const char *se
                        return NULL;
 
                p->key = talloc_strdup(p, name);
-               DLIST_ADD(section->parameters, p);
+               DLIST_ADD_END(section->parameters, p, struct param_opt *);
        }
        
        return p;
@@ -185,7 +188,7 @@ static bool param_sfunc (const char *name, void *_ctx)
 
                section->name = talloc_strdup(section, name);
 
-               DLIST_ADD(ctx->sections, section);
+               DLIST_ADD_END(ctx->sections, section, struct param_section *);
        }
 
        /* Make sure this section is on top of the list for param_pfunc */
@@ -235,6 +238,32 @@ int param_read(struct param_context *ctx, const char *fn)
        return 0;
 }
 
+int param_use(struct loadparm_context *lp_ctx, struct param_context *ctx)
+{
+       struct param_section *section;
+
+       for (section = ctx->sections; section; section = section->next) {
+               struct param_opt *param;
+               bool isglobal = strcmp(section->name, "global") == 0;
+               for (param = section->parameters; param; param = param->next) {
+                       if (isglobal)
+                               lp_do_global_parameter(lp_ctx, param->key,
+                                                      param->value);
+                       else {
+                               struct loadparm_service *service = 
+                                                       lp_service(lp_ctx, section->name);
+                               if (service == NULL)
+                                       service = lp_add_service(lp_ctx, &sDefault, section->name);
+                               lp_do_service_parameter(lp_ctx, 
+                                                       service,
+                                                       param->key,
+                                                       param->value);
+                       }
+               }
+       }
+       return 0;
+}
+
 int param_write(struct param_context *ctx, const char *fn)
 {
        int file;
index c54932aa47306d5c73b17a37576d683f3daab95c..8e2b8b555c2dac51602260541b0afa0c9631af2f 100644 (file)
@@ -222,7 +222,7 @@ struct loadparm_service
 
 
 /* This is a default service used to prime a services structure */
-static struct loadparm_service sDefault = {
+struct loadparm_service sDefault = {
        .szService = NULL,
        .szPath = NULL,
        .szCopy = NULL,
@@ -1031,7 +1031,7 @@ static bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src)
  service. 
 ***************************************************************************/
 
-static struct loadparm_service *add_a_service(struct loadparm_context *lp_ctx, 
+struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx, 
                                     const struct loadparm_service *pservice, 
                                     const char *name)
 {
@@ -1073,7 +1073,7 @@ static struct loadparm_service *add_a_service(struct loadparm_context *lp_ctx,
                                num_to_alloc);
                                           
                if (!tsp) {
-                       DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n"));
+                       DEBUG(0,("lp_add_service: failed to enlarge ServicePtrs!\n"));
                        return NULL;
                }
                else {
@@ -1086,7 +1086,7 @@ static struct loadparm_service *add_a_service(struct loadparm_context *lp_ctx,
 
        lp_ctx->ServicePtrs[i] = init_service(talloc_autofree_context());
        if (lp_ctx->ServicePtrs[i] == NULL) {
-               DEBUG(0,("add_a_service: out of memory!\n"));
+               DEBUG(0,("lp_add_service: out of memory!\n"));
                return NULL;
        }
        copy_service(lp_ctx->ServicePtrs[i], &tservice, NULL);
@@ -1107,7 +1107,7 @@ bool lp_add_home(struct loadparm_context *lp_ctx,
 {
        struct loadparm_service *service;
 
-       service = add_a_service(lp_ctx, default_service, pszHomename);
+       service = lp_add_service(lp_ctx, default_service, pszHomename);
 
        if (service == NULL)
                return false;
@@ -1131,17 +1131,6 @@ bool lp_add_home(struct loadparm_context *lp_ctx,
        return true;
 }
 
-/***************************************************************************
- Add a new service, based on an old one.
-***************************************************************************/
-
-struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx, 
-                              const char *pszService, 
-                              struct loadparm_service *default_service)
-{
-       return add_a_service(lp_ctx, default_service, pszService);
-}
-
 /***************************************************************************
  Add the IPC service.
 ***************************************************************************/
@@ -1149,7 +1138,7 @@ struct loadparm_service *lp_add_service(struct loadparm_context *lp_ctx,
 static bool lp_add_hidden(struct loadparm_context *lp_ctx, const char *name, 
                          const char *fstype)
 {
-       struct loadparm_service *service = add_a_service(lp_ctx, &sDefault, name);
+       struct loadparm_service *service = lp_add_service(lp_ctx, &sDefault, name);
 
        if (service == NULL)
                return false;
@@ -1185,7 +1174,7 @@ bool lp_add_printer(struct loadparm_context *lp_ctx,
 {
        const char *comment = "From Printcap";
        struct loadparm_service *service;
-       service = add_a_service(lp_ctx, default_service, pszPrintername);
+       service = lp_add_service(lp_ctx, default_service, pszPrintername);
 
        if (service == NULL)
                return false;
@@ -2024,7 +2013,7 @@ static bool do_section(const char *pszSectionName, void *userdata)
                /* issued by the post-processing of a previous section. */
                DEBUG(2, ("Processing section \"[%s]\"\n", pszSectionName));
 
-               if ((lp_ctx->currentService = add_a_service(lp_ctx, &sDefault, 
+               if ((lp_ctx->currentService = lp_add_service(lp_ctx, &sDefault, 
                                                             pszSectionName))
                    == NULL) {
                        DEBUG(0, ("Failed to add a new service\n"));
index 1dd5950e31210dc707058ab106b766eeb0d267ff..210b21d9a003c41ead72df7760e5552afc144cdc 100644 (file)
@@ -63,5 +63,6 @@ struct loadparm_service;
 #include "param/proto.h"
 
 extern struct loadparm_context *global_loadparm;
+extern struct loadparm_service sDefault;
 
 #endif /* _PARAM_H */