param: consolidate handle_copy method between the two loadparms
authorGarming Sam <garming@catalyst.net.nz>
Wed, 19 Feb 2014 21:24:00 +0000 (10:24 +1300)
committerJeremy Allison <jra@samba.org>
Wed, 7 May 2014 17:49:15 +0000 (19:49 +0200)
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/param/loadparm.c
source3/param/loadparm.c

index fc5829379ee8ca4a9d98c11bf65339f03020581f..aaf905d8f464b7b3e6316a669dd7ac49ba664733 100644 (file)
@@ -98,8 +98,6 @@ static bool defaults_saved = false;
 /* prototypes for the special type handlers */
 static bool handle_include(struct loadparm_context *lp_ctx, int unused,
                           const char *pszParmValue, char **ptr);
-static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
-                       const char *pszParmValue, char **ptr);
 
 #include "lib/param/param_table.c"
 
@@ -1133,27 +1131,38 @@ static bool handle_include(struct loadparm_context *lp_ctx, int unused,
  Handle the interpretation of the copy parameter.
 ***************************************************************************/
 
-static bool handle_copy(struct loadparm_context *lp_ctx, int unused,
+bool handle_copy(struct loadparm_context *lp_ctx, int snum,
                        const char *pszParmValue, char **ptr)
 {
        bool bRetval;
-       struct loadparm_service *serviceTemp;
-
-       lpcfg_string_set(lp_ctx, ptr, pszParmValue);
+       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"));
+               return false;
+       }
 
        if (serviceTemp != NULL) {
-               if (serviceTemp == lp_ctx->currentService) {
+               if (serviceTemp == current) {
                        DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
                } else {
-                       copy_service(lp_ctx->currentService,
+                       copy_service(current,
                                     serviceTemp,
-                                    lp_ctx->currentService->copymap);
+                                    current->copymap);
+                       lpcfg_string_set(current, ptr, pszParmValue);
+
                        bRetval = true;
                }
        } else {
index 11b148625243902f83e92b15e9225bb376a3c0f2..2964544ce4df572b6ba68f37bd0d6f93e0aff352 100644 (file)
@@ -261,7 +261,6 @@ static bool bGlobalOnly = false;
 
 /* prototypes for the special type handlers */
 static bool handle_include(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
-static bool handle_copy(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
 static bool handle_idmap_backend(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
 static bool handle_idmap_uid(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
 static bool handle_idmap_gid(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
@@ -2627,37 +2626,6 @@ static bool handle_include(struct loadparm_context *unused, int snum, const char
        return true;
 }
 
-/***************************************************************************
- Handle the interpretation of the copy parameter.
-***************************************************************************/
-
-static bool handle_copy(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
-{
-       bool bRetval;
-       int iTemp;
-
-       bRetval = false;
-
-       DEBUG(3, ("Copying service from service %s\n", pszParmValue));
-
-       if ((iTemp = getservicebyname(pszParmValue, NULL)) >= 0) {
-               if (iTemp == snum) {
-                       DEBUG(0, ("Can't copy service %s - unable to copy self!\n", pszParmValue));
-               } else {
-                       copy_service(ServicePtrs[snum],
-                                    serviceTemp,
-                                    ServicePtrs[snum]->copymap);
-                       string_set(ServicePtrs[snum], ptr, pszParmValue);
-                       bRetval = true;
-               }
-       } else {
-               DEBUG(0, ("Unable to copy service - source not found: %s\n", pszParmValue));
-               bRetval = false;
-       }
-
-       return (bRetval);
-}
-
 static bool handle_ldap_debug_level(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
 {
        Globals.ldap_debug_level = lp_int(pszParmValue);