Bug 2926 - smbc_init() resets locale (seems to require Jeremy's attention)
smbc_init() resets locale (seems to require Jeremy's attention)
Status: RESOLVED FIXED
Product: Samba 3.0
Classification: Unclassified
Component: libsmbclient
3.0.9
All Linux
: P3 normal
: none
Assigned To: Jeremy Allison
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-07-28 02:39 UTC by Bernhard Walle
Modified: 2006-03-22 18:25 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Walle 2005-07-28 02:39:32 UTC
Hello,

following test code:

#include <libsmbclient.h>
#include <locale.h>
#include <stdio.h>

void smb_auth(const char *srv, const char *shr, char *wg, int wglen, char *un,
int unlen, char *pw, int pwlen)
{
	wglen = unlen = pwlen = 0;
}

int main(void)
{
        setlocale(LC_ALL, "");
        printf("locale = %s\n", setlocale(LC_MESSAGES, NULL));
        smbc_init(smb_auth,0);
        //smbc_open("", O_RDONLY,0);
        printf("locale = %s\n", setlocale(LC_MESSAGES, NULL));
}

In my system (SuSE 9.3), the output is:

locale = de_DE.UTF-8
locale = C

That can be problematic in locale-aware applications (for example it leads to a
problem in libxine, if the smb-input-plugin is installed, etc.).

I use version 3.0.13 shipped with SuSE 9.3. I even confirmed the bug on other
systems running the same version.
Comment 1 Derrell Lipman 2005-08-26 06:48:06 UTC
Jeremy is the expert on locale issues.
We discussed this at the CIFS conference.  Apparently, some locale code was
added a while back for something that vorlon required (some lower case letters
don't match to their upper case equivalent in some European language, or
something) and that code is suspect here.
Comment 2 Derrell Lipman 2005-12-19 07:30:42 UTC
Jeremy, this bug has been pending for a long time.  We discussed it at the CIFS conference.  When you get a chance, do you think you could look at it?

Thanks.

Derrell 
Comment 3 Bastien Nocera 2005-12-22 05:05:38 UTC
This bug causes a no-ending pain for anyone using libsmbclient based libraries.
For example, this would break all the xine front-ends when the smb input plugin is present, all the applications using gnome-vfs if smb is browsed, and most likely KDE apps that browse smb as well.
Comment 4 Christian Neumair 2005-12-23 11:47:37 UTC
Yeah, I'm sure that this was the cause for Nautilus and GnomeVFS sometimes not being localized. It's really important for many clients - maybe you could raise the severity and milestone it?
Comment 5 Christian Neumair 2005-12-23 12:12:22 UTC
source/lib/charcnv.c:charset_name seems to be the culprit. You should either use the method described under [1] to strdup and re-set the locale variable in your second setlocale call instead of using "C", or remove the setlocale calls altogether. I don't know why these were added, and the ChangeLog isn't verbose either.

[1] http://www.delorie.com/gnu/docs/glibc/libc_112.html
Comment 6 Jeremy Allison 2005-12-27 10:32:52 UTC
Ok, I took a look at this. The problem is that smbd uses toupper/tolower expecting that these *must* be "C" locale conversions. Note this comment :

/* We set back the locale to C to get ASCII-compatible toupper/lower functions.
   For now we do not need any other POSIX localisations anyway. When we should
   really need localized string functions one day we need to write our own
   ascii_tolower etc.
*/

The time has now come to write ascii_tolower/ascii_toupper and replace all calls to tolower()/toupper() with them - if you notice they are usually only called when we *know* the character being examined is in the ASCII char set. This will have to be done for 3.0.22. Please mark this as a show-stopper for 3.0.22. Once this is done we can replace the setlocale(LC_ALL, "C") call but not before.

I'm assigning this one to me as I know the effect this will have on all the code code.

Jeremy.
Comment 7 Jeremy Allison 2005-12-27 13:54:16 UTC
Check out SVN revision 12522 in SAMBA_3_0 or revision 12521 in HEAD to check out the fix I've added for this bug.
Should be fixed as I've removed the setlocale call in lib/charcnv.c and modified all the toupper/tolower/isupper/islower calls to be _ascii versions.
Please let me know if this fixes the problem.
Jeremy.
Comment 8 Derrell Lipman 2006-03-22 18:24:10 UTC
Jeremy, there's been no response to this in a few months.  Can we close it?
Comment 9 Jeremy Allison 2006-03-22 18:25:04 UTC
Yeah, this should be fixed in svn now. Closing.
Jeremy.