param: move special charset handlers to lib/param
authorGarming Sam <garming@catalyst.net.nz>
Thu, 20 Feb 2014 03:37:16 +0000 (16:37 +1300)
committerJeremy Allison <jra@samba.org>
Wed, 7 May 2014 17:49:16 +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 d2c9d0015f954d27665b39266cfce236bf1de4fd..5598e259f981762e5123fdaadb12038f9a405a7d 100644 (file)
@@ -77,10 +77,6 @@ static bool defaults_saved = false;
 
 #define NUMPARAMETERS (sizeof(parm_table) / sizeof(struct parm_struct))
 
-/* we don't need a special handler for "dos charset" and "unix charset" */
-#define handle_dos_charset NULL
-#define handle_charset NULL
-
 /* these are parameter handlers which are not needed in the
  * non-source3 code
  */
@@ -1198,6 +1194,73 @@ bool handle_logfile(struct loadparm_context *lp_ctx, int unused,
        return true;
 }
 
+/*
+ * These special charset handling methods only run in the source3 code.
+ */
+
+bool handle_charset(struct loadparm_context *lp_ctx, int snum,
+                       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);
+
+}
+
+bool handle_dos_charset(struct loadparm_context *lp_ctx, int snum,
+                       const char *pszParmValue, char **ptr)
+{
+       bool is_utf8 = false;
+       size_t len = strlen(pszParmValue);
+
+       if (lp_ctx->s3_fns) {
+               if (len == 4 || len == 5) {
+                       /* Don't use StrCaseCmp here as we don't want to
+                          initialize iconv. */
+                       if ((toupper_m(pszParmValue[0]) == 'U') &&
+                           (toupper_m(pszParmValue[1]) == 'T') &&
+                           (toupper_m(pszParmValue[2]) == 'F')) {
+                               if (len == 4) {
+                                       if (pszParmValue[3] == '8') {
+                                               is_utf8 = true;
+                                       }
+                               } else {
+                                       if (pszParmValue[3] == '-' &&
+                                           pszParmValue[4] == '8') {
+                                               is_utf8 = true;
+                                       }
+                               }
+                       }
+               }
+
+               if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
+                       if (is_utf8) {
+                               DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
+                                       "be UTF8, using (default value) %s instead.\n",
+                                       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);
+}
+
 /***************************************************************************
  Initialise a copymap.
 ***************************************************************************/
index 5f1470a321d39bbb4e404620f5e1d3893c656474..467dbb5792d2624ac1682a648a0ef675a50bae7e 100644 (file)
@@ -266,8 +266,6 @@ static bool handle_idmap_backend(struct loadparm_context *unused, int snum, cons
 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);
 static bool handle_netbios_aliases(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
-static bool handle_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
-static bool handle_dos_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr );
 static bool handle_printing(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
 static bool handle_ldap_debug_level(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr);
 
@@ -2460,56 +2458,6 @@ static void init_iconv(void)
                                                      true, global_iconv_handle);
 }
 
-static bool handle_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
-{
-       if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
-               string_set(Globals.ctx, ptr, pszParmValue);
-               global_iconv_handle = smb_iconv_handle_reinit(NULL, lp_dos_charset(),
-                                                     lp_unix_charset(),
-                                                     true, global_iconv_handle);
-       }
-       return true;
-}
-
-static bool handle_dos_charset(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
-{
-       bool is_utf8 = false;
-       size_t len = strlen(pszParmValue);
-
-       if (len == 4 || len == 5) {
-               /* Don't use StrCaseCmp here as we don't want to
-                  initialize iconv. */
-               if ((toupper_m(pszParmValue[0]) == 'U') &&
-                   (toupper_m(pszParmValue[1]) == 'T') &&
-                   (toupper_m(pszParmValue[2]) == 'F')) {
-                       if (len == 4) {
-                               if (pszParmValue[3] == '8') {
-                                       is_utf8 = true;
-                               }
-                       } else {
-                               if (pszParmValue[3] == '-' &&
-                                   pszParmValue[4] == '8') {
-                                       is_utf8 = true;
-                               }
-                       }
-               }
-       }
-
-       if (*ptr == NULL || strcmp(*ptr, pszParmValue) != 0) {
-               if (is_utf8) {
-                       DEBUG(0,("ERROR: invalid DOS charset: 'dos charset' must not "
-                               "be UTF8, using (default value) %s instead.\n",
-                               DEFAULT_DOS_CHARSET));
-                       pszParmValue = DEFAULT_DOS_CHARSET;
-               }
-               string_set(Globals.ctx, ptr, pszParmValue);
-               global_iconv_handle = smb_iconv_handle_reinit(NULL, lp_dos_charset(),
-                                                     lp_unix_charset(),
-                                                     true, global_iconv_handle);
-       }
-       return true;
-}
-
 static bool handle_netbios_aliases(struct loadparm_context *unused, int snum, const char *pszParmValue, char **ptr)
 {
        TALLOC_FREE(Globals.netbios_aliases);