proposal: libsmbclient functionality addition

Andrew Bartlett abartlet at
Wed Jun 19 05:44:04 GMT 2002

Tom Jansen wrote:
> > > o Will all smbc_* functions get the handle when called ?
> >
> > Yes, they have to be given the file handle.
> >
> > The major issue here is that this will break all existing programs. I
> > have spent some time trying to think of a way to avoid this breakage, but
> > fear that I cannot do it easily.
> Ehm... I've given it some thought too and came up with the following:
> smbc_set_client(struct smbc_handle * handle)
> {
>   current_handle = handle;
> }
> and make all the functions use current_handle as the handle.


Please NO.  I *really* would like to see this move in the opposite
direction - with all function taking a context and using it.  It
*really* isn't that hard to change and it eliminates all sorts of bugs.

The problem is that libraries should not maintain 'magic state'.  'magic
state' causes bugs - and nasty bugs too.  By ensureing that all state is
maintined on a context pointer, we *know* that shutting down one context
can't affect another etc.

Yes, I can see why you might like this approch, but I am strongly
opposed do it.  Furthermore I think constructs like this:

> /* open using client 1 */
> smbc_set_client(handle1);
> fd1 = smbc_open("smb://puter/share/file1.txt",mode);
> /* open using client 1 */
> smbc_set_client(handle2);
> fd2 = smbc_open("smb://puter/share/file2.txt",mode);

are just *asking* for bugs.

The original design was flawed.  Posix is flawed (and the idea was to
emulate posix, and I can understand that), but *please* don't use that
as an excuse to for substandard interfaces a second time around.

If you want to know the kind of code I like, see the passdb subsystem. 
It is complex, but I really like code that has only one entrypoint
(think namespace pollution), and puts the rest of the functions on a
struct, as function pointers.  Each funciton takes the struct as an arg,
(becouse C doesn't have 'Current').

Andrew Bartlett

Andrew Bartlett                                 abartlet at
Manager, Authentication Subsystems, Samba Team  abartlet at
Student Network Administrator, Hawker College   abartlet at

More information about the samba-technical mailing list