lib/util/charset Add back setlocale(), but only when called from binaries
authorAndrew Bartlett <abartlet@samba.org>
Fri, 18 Feb 2011 02:59:05 +0000 (13:59 +1100)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 18 Feb 2011 08:29:35 +0000 (09:29 +0100)
When called from a library, we don't want to call this, as we may
overwrite some of our calling program's context.

Andrew Bartlett

Autobuild-User: Andrew Bartlett <abartlet@samba.org>
Autobuild-Date: Fri Feb 18 09:29:35 CET 2011 on sn-devel-104

lib/util/charset/charset.h
lib/util/charset/codepoints.c
nsswitch/wins.c
source3/lib/charcnv.c
source3/lib/netapi/netapi.c
source3/libsmb/libsmb_context.c
source3/pam_smbpass/pam_smb_acct.c
source3/pam_smbpass/pam_smb_auth.c
source3/pam_smbpass/pam_smb_passwd.c

index b4a5a5546106733bc7a74172a5327ac660a18da6..474d77e54e7ddb437b353e4233f115c58234afc1 100644 (file)
@@ -223,6 +223,7 @@ smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode,
                              const char *fromcode, bool native_iconv);
 
 void load_case_tables(void);
+void load_case_tables_library(void);
 bool smb_register_charset(const struct charset_functions *funcs_in);
 
 /*
index 01183e4ad448df929a23c99ccba0ee015ba7f05b..5ee95a8af56cf6691b1757ce6c2f556fb8c32719 100644 (file)
@@ -42,8 +42,10 @@ static void *lowcase_table;
 
 /*******************************************************************
 load the case handling tables
+
+This is the function that should be called from library code.
 ********************************************************************/
-void load_case_tables(void)
+void load_case_tables_library(void)
 {
        TALLOC_CTX *mem_ctx;
 
@@ -64,6 +66,24 @@ void load_case_tables(void)
        }
 }
 
+/*******************************************************************
+load the case handling tables
+
+This MUST only be called from main() in application code, never from a
+library.  We don't know if the calling program has already done
+setlocale() to another value, and can't tell if they have.
+********************************************************************/
+void load_case_tables(void)
+{
+       /* This is a useful global hook where we can ensure that the
+        * locale is set from the environment.  This is needed so that
+        * we can use LOCALE as a codepage */
+#ifdef HAVE_SETLOCALE
+       setlocale(LC_ALL, "");
+#endif
+       load_case_tables_library();
+}
+
 /**
  Convert a codepoint_t to upper case.
 **/
@@ -73,7 +93,7 @@ _PUBLIC_ codepoint_t toupper_m(codepoint_t val)
                return toupper(val);
        }
        if (upcase_table == NULL) {
-               load_case_tables();
+               load_case_tables_library();
        }
        if (upcase_table == (void *)-1) {
                return val;
@@ -93,7 +113,7 @@ _PUBLIC_ codepoint_t tolower_m(codepoint_t val)
                return tolower(val);
        }
        if (lowcase_table == NULL) {
-               load_case_tables();
+               load_case_tables_library();
        }
        if (lowcase_table == (void *)-1) {
                return val;
index eba27bc287777cbe388fd51e6b6a78fe8beca9ee..5136c94c76e6e395e150bc73f290242bb4b8d7a9 100644 (file)
@@ -48,7 +48,7 @@ NSS_STATUS _nss_wins_gethostbyname2_r(const char *name, int af, struct hostent *
 static void nss_wins_init(void)
 {
        initialised = 1;
-       load_case_tables();
+       load_case_tables_library();
        lp_set_cmdline("log level", "0");
 
        TimeInit();
index 27235995993c4869da118b4cc29e00efee352c9d..6f1ced69d03630b8665ba99e9b6074e6df925c3c 100644 (file)
@@ -51,7 +51,7 @@ static bool initialized;
 void lazy_initialize_conv(void)
 {
        if (!initialized) {
-               load_case_tables();
+               load_case_tables_library();
                init_iconv();
                initialized = true;
        }
index 9d76017a01aed13c417495e05b3ae3db865a1bc5..c04ca70249371c06e47372d3de8fb89188dbe3fb 100644 (file)
@@ -68,7 +68,7 @@ NET_API_STATUS libnetapi_init(struct libnetapi_ctx **context)
        frame = talloc_stackframe();
 
        /* Case tables must be loaded before any string comparisons occour */
-       load_case_tables();
+       load_case_tables_library();
 
        /* When libnetapi is invoked from an application, it does not
         * want to be swamped with level 10 debug messages, even if
index ab2db9d3e9b2b5c6a7cc6d4d38769e8f4ee69046..9c8429aab477f2f103f83ed53b8894ad8f0c64b7 100644 (file)
@@ -45,7 +45,7 @@ SMBC_module_init(void * punused)
     char *home = NULL;
     TALLOC_CTX *frame = talloc_stackframe();
 
-    load_case_tables();
+    load_case_tables_library();
 
     setup_logging("libsmbclient", DEBUG_STDOUT);
 
index 650d322b356a6e866f5a6d71b68d46baa1d23333..63323d8d8fca0c3a4031814832551f9abf395042 100644 (file)
@@ -57,7 +57,7 @@ int pam_sm_acct_mgmt( pam_handle_t *pamh, int flags,
        void (*oldsig_handler)(int);
 
        /* Samba initialization. */
-       load_case_tables();
+       load_case_tables_library();
         lp_set_in_client(True);
 
        ctrl = set_ctrl(pamh, flags, argc, argv );
index feb469792d3756e264a150f6d2567e3972561601..24702131b4ba55e205cf0236449db8c1eadbd290 100644 (file)
@@ -80,7 +80,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags,
        char *p = NULL;
 
        /* Samba initialization. */
-       load_case_tables();
+       load_case_tables_library();
         lp_set_in_client(True);
 
        ctrl = set_ctrl(pamh, flags, argc, argv);
index 8fc2cf3e14d003380e4054fe967ac95e3bb2cc81..54d9db7f312a022e42521ce7784b961f4906c982 100644 (file)
@@ -105,7 +105,7 @@ int pam_sm_chauthtok(pam_handle_t *pamh, int flags,
     char *pass_new;
 
     /* Samba initialization. */
-    load_case_tables();
+    load_case_tables_library();
     lp_set_in_client(True);
 
     ctrl = set_ctrl(pamh, flags, argc, argv);