[Samba] libsmbclient - detect own workgroup

derrell at samba.org derrell at samba.org
Thu Oct 13 15:32:10 GMT 2005


"Gerald (Jerry) Carter" <jerry at samba.org> writes:

> Gerd Fleischer wrote:
> | Hi,
> |
> | I would like to know if there's a way to detect the
> | workgroup of my own server with libsmbclient.
> |
> | With earlier versions than 3.0.20 it was possible
> | to use smbctx->workgroup after the context was
> | initialized. Since 3.0.15pre2 or so its always "WORKGROUP".
> | Am I missing something?
>
> My guess would that it would be the fix for BUG 1133.

The fix for bug 1133 added reading a new configuration file but "should" not
have affected previous operation.

The value of smbctx->workgroup is set from within smbc_init_context() which is
occasionally called explicitly (and it sounds like you're doing that), or is
called by smbc_init().

The value of smbctx->workgroup should come from one of the following files:

  ${HOME}/.smb/smb.conf
  /etc/smb.conf (or wherever your global configuration file is)
  ${HOME}/.smb/smb.conf.append

${HOME} is the setting of the environment variable HOME.

If you have a ${HOME}/.smb/smb.conf file then the other two files are not
read.  Therefore, if you have ${HOME}/.smb/smb.conf and it does not specify a
workgroup, your workgroup will default to WORKGROUP.

If you do not have ${HOME}/.smb/smb.conf then the global configuration file is
read.  It may define the workgroup.  If not, then at this point, the workgroup
has defaulted to WORKGROUP.

If AND ONLY IF the global configuration was read, then per-user settings can
be overridden in ${HOME}/.smb/smb.conf.append and this file may modify the
workgroup.

When the above configuration files have been read, smbctx->workgroup will
contain whatever value was specified, or WORKGROUP if the workgroup was not
specified in any of the files that were read.

If you find that this description does not match reality, please let me know.

Cheers,

Derrell

ps. There's the possibility that if HOME is not set in the environment, then
/.smb/smb.conf might be read.  I'll have to look into that.  On Linux, this
file shouldn't exist since even root's home directory is not in "/"; it's in
/root.  Furthermore, on Linux, snprintf() which is used to generate the
configuration file name, inserts the string "(null)" when a null pointer is
passed to a %s parameter (which is what will occur if HOME was not found in
the environment), so the configuration file with HOME not set would be the
string "(null)/.smb/smb.conf".

On other Unixes, if root's home directory is "/" then /.smb/smb.conf may
reasonably exist.  If it is readable by the user running the client
application and if snprintf() inserts an empty string if a null pointer is
passed to a %s parameter and if HOME is not set in the environment (that's a
lot of if's), /.smb/smb.conf file will be read by the client app.

We shouldn't be passing a possibly null pointer to snprintf().  I think, also,
that if HOME is not set in the environment, I need to treat it just as if
${HOME}/.smb/smb.conf* do not exist.  I'll fix those when I get a chance.
I've added bug #3166 so I don't forget about it.



More information about the samba mailing list