Bug 2100 - Wrong way of loading VFS modules via dlopen/dlsym
Summary: Wrong way of loading VFS modules via dlopen/dlsym
Status: CLOSED FIXED
Alias: None
Product: Samba 3.0
Classification: Unclassified
Component: File Services (show other bugs)
Version: 3.0.9
Hardware: All FreeBSD
: P3 major
Target Milestone: none
Assignee: Samba Bugzilla Account
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-29 16:38 UTC by Timur Bakeyev
Modified: 2005-08-24 10:19 UTC (History)
0 users

See Also:


Attachments
Fix to the dlopen/dlsym sequence (501 bytes, patch)
2004-11-29 16:39 UTC, Timur Bakeyev
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Timur Bakeyev 2004-11-29 16:38:30 UTC
For last half a year VFS modules were unable to get loaded in FreeBSD 5.x. The
error message was quite misleading:

Nov 20 13:21:52 wader smbd[87549]: [2004/11/20 13:21:52, 0]
lib/module.c:do_smb_load_module(57)
Nov 20 13:21:52 wader kernel: Nov 20 13:21:52 wader smbd[87549]: [2004/11/20
13:21:52, 0] lib/module.c:do_smb_load_module(57)
Nov 20 13:21:52 wader smbd[87549]:   Error trying to resolve symbol
'init_module' in /usr/local/lib/samba/vfs/recycle.so
: Shared object "nss_files.so.1" not found, required by "smbd"
Nov 20 13:21:52 wader kernel: Nov 20 13:21:52 wader smbd[87549]:   Error trying
to resolve symbol 'init_module' in /usr/local/lib/samba/vfs/recycle.so: Shared
object "nss_files.so.1" not found, required by "smbd"
Nov 20 13:21:52 wader smbd[87549]: [2004/11/20 13:21:52, 0]
smbd/vfs.c:vfs_init_custom(256)
Nov 20 13:21:52 wader kernel: Nov 20 13:21:52 wader smbd[87549]: [2004/11/20
13:21:52, 0] smbd/vfs.c:vfs_init_custom(256)
Nov 20 13:21:52 wader smbd[87549]:   Can't find a vfs module [recycle]
Nov 20 13:21:52 wader kernel: Nov 20 13:21:52 wader smbd[87549]:   Can't find a
vfs module [recycle]
Nov 20 13:21:52 wader smbd[87549]: [2004/11/20 13:21:52, 0]
smbd/vfs.c:smbd_vfs_init(319)
Nov 20 13:21:52 wader kernel: Nov 20 13:21:52 wader smbd[87549]: [2004/11/20
13:21:52, 0] smbd/vfs.c:smbd_vfs_init(319)
Nov 20 13:21:52 wader smbd[87549]:   smbd_vfs_init: vfs_init_custom failed for
recycle

The funny thing is that nss_files.so not meant to exist at all in FreeBSD. So,
after sevire digging into the changes in the OS code the real cause was found.
To make long thing short, the problem lays in the way how dlopen/dlsym is used
in Samba.

It's technically possible, that dlopen() get non-fatal error(s) during
execution(or, better call them warnings)that dlerror() will happily return
later. Unfortunatelly, if you'll make call to dlsym() after such dlopen() with
warning, and then check failure of dlsym() via call to dlopen() - you'll get an
error from a previous stage, dlopen().

As Samba uses that error as the only indication of dlsym() failure, any VFS
module can't be loaded...

The cure is amasingly simple - just call dlerror() explicitly before the call to
dlsym().

At least on Debian Linux man pages especially stress that way of dealing with
dynamic loading.

With regards,
Timur Bakeyev.
Comment 1 Timur Bakeyev 2004-11-29 16:40:03 UTC
Created attachment 812 [details]
Fix to the dlopen/dlsym sequence

Here is the propossed patch to fix the problem. Works fine with FreeBSD, should
work on any other system too.
Comment 2 Jeremy Allison 2004-11-29 18:01:27 UTC
Good patch - applied.
Thanks.
Jeremy.
Comment 3 Gerald (Jerry) Carter (dead mail address) 2005-08-24 10:19:07 UTC
sorry for the same, cleaning up the database to prevent unecessary reopens of bugs.