SUMMARY: When using libsmbclient with multiple threads, sometimes the fname (path) gets mixed up and incorrect results are returned. I.e. files that should exist cannot be accessed. PROBABLE CAUSE: smbc_parse_path uses a static buffer that occasionally gets overwritten by another thread. SYMPTOMS: I saw the following output from my program: 2008-04-06 12:17:53: proto_smb: In authentication function for smb://som/likaan. 2008-04-06 12:17:53: proto_smb: Stat/open failed for `smb://som/share/music/some_random_file.mp3' This happened while I was iterating over the files of two shares simultaneously: smb://som/share and smb://depelikaan/share. As you can see, smb://som/likaan is a mix of both the share paths. TESTS: I replaced the "static pstring s" in libsmbclient.c with "pstring s" and I could not reproduce the bug. PATCH: --- samba-3.0.28a/source/libsmb/libsmbclient.c.orig 2008-04-06 14:34:14.822198288 +0200 +++ samba-3.0.28a/source/libsmb/libsmbclient.c 2008-04-06 14:37:51.378276760 +0200 @@ -281,7 +281,7 @@ char *password, int password_len, char *options, int options_len) { - static pstring s; + pstring s; pstring userinfo; const char *p; char *q, *r;
Samba 3.2, the current version, has no pstrings, and more importantly, no staticly-declared buffers in libsmbclient. The Samba3 core is getting closer to being thread-safe, but AFAIK, still is not. libsmbclient has a few potential issues with thread safety (particularly with tracking initialization state) which must be looked at when the core of Samba3 is deemed thread safe. Until then, however, you should not assume that libsmbclient is thread safe. Derrell