I'm writing a Ruby module that uses libsmbclient to connect to SMB/CIFS services. For this module, I want to use the own smb.conf path instead of the default smb.conf path, $HOME/.smb/smb.conf and $HOME/.smb/smb.conf.append, but there is no method to do it.
The way I wrote that code, a number of years ago, $HOME/.smb/smb.conf and $HOME/.smb/smb.conf.append take precedence over the global file (in some defined order). You don't need to call anything for that to happen. I believe that if there is a $HOME/.smb/smb.conf it overwrite completely the global configuration, and if there is a $HOME/.smb/smb.conf.append, the settings contained in there are added to the global settings. There is a precedence of files which I don't recall (and don't have quick access to the code at the moment). I think maybe the .append file is checked first, and if it doesn't exist, then the $HOME/.smb/smb.conf is looked for. It may be the other way around. (It is conceivable that something has changed in the past few years regarding how those files are read.) Derrell
(In reply to comment #1) > The way I wrote that code, a number of years ago, $HOME/.smb/smb.conf and > $HOME/.smb/smb.conf.append take precedence over the global file (in some > defined order). You don't need to call anything for that to happen. I believe > that if there is a $HOME/.smb/smb.conf it overwrite completely the global > configuration, and if there is a $HOME/.smb/smb.conf.append, the settings > contained in there are added to the global settings. This has a problem that if $HOME/.smb/smb.conf exists, there is a no way to ignore it without an ugly hack (see below) when we want to use default the smb.conf. SMBCCTX *smbcctx; char *home = getenv("HOME"); if (home) { unsetenv("HOME"); } smbcctx = smbc_new_context(); if (home) { setenv("HOME", home, 1); }
(In reply to comment #2) > This has a problem that if $HOME/.smb/smb.conf exists, there is a no way > to ignore it without an ugly hack The intention was that the user knows a lot better than the application developer what configuration to use. If the user has provided an overriding configuration file, it feels unreasonable for the application to say, "No, you must use the global one as is, not the one you created to override the global one." I'm curious... What is your use case that you would want the application to override the user's desire?
(In reply to comment #3) > I'm curious... What is your use case that you would want the application to > override the user's desire? Case 1: ------- I have the $HOME/.smb/smb.conf for some libsmbclient applications. On the other hand, I'm writing a libsmbclient application and test programs for it. I want to use a specific smb.conf file (to avoid /etc/samba/smb.conf and $HOME/.smb/smb.conf) for the application when I run the test program. Case 2: ------- Someone uses a libsmbclient application to connect to server A and B. He want to use /etc/samba/smb.conf for A, but $HOME/.smb/smb.conf for B. Case 3: ------- Someone uses libsmbclient applications, application X and Y. He want to use $HOME/etc/smb.A.conf for X, but $HOME/etc/smb.B.conf for Y.
Created attachment 7106 [details] Patch to use SMB_CONF environment entry as first choice Here's a likely patch to accommodate this request reasonably. It looks first for an environment variable SMB_CONF, and if found, uses that as the path to the configuration file to use. If not found, then the previous precedence is used.
(In reply to comment #5) > Created attachment 7106 [details] > Patch to use SMB_CONF environment entry as first choice You should s/SMB_CONF/SMB_CONF_PATH/ as same as other Samba commands (smbd and others) that see SMB_CONF_PATH.
(In reply to comment #6) > You should s/SMB_CONF/SMB_CONF_PATH/ as same as other Samba commands > (smbd and others) that see SMB_CONF_PATH. ... and how about SMB_CONF_APPEND_PATH?
Hmmm... libsmbclient uses LIBSMBCLIENT_NO_CCACHE environment variable, thus LIBSMBCLIENT_SMB_CONF_PATH is more reasonable?
Are you there?
Derrell isn't working on this code anymore, I'll take over. Jeremy.