Skip to content

Commit

Permalink
Merge pull request #12110 from chewitt/smbclient_leia
Browse files Browse the repository at this point in the history
smbclient: cleanup smbclient configuration
  • Loading branch information
MartijnKaijser committed Aug 3, 2017
2 parents c4f8dca + 2b1402b commit 2c41c63
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 20 deletions.
44 changes: 43 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Expand Up @@ -19865,7 +19865,49 @@ msgctxt "#36620"
msgid "Enable high quality downscaling of pictures (uses more memory and has moderate performance impact)."
msgstr ""

#empty strings from id 36621 to 36899
#. Label of a setting, allow the maximum smbclient protocol to be configured
#: system/settings/settings.xml
msgctxt "#36621"
msgid "Maximum protocol version"
msgstr ""

#. Description of setting with label #36621 "Maximum protocol version"
#: system/settings/settings.xml
msgctxt "#36622"
msgid "Set the maximum SMB protocol version to negotiate when making connections. Forcing SMBv2 or SMBv1 compatibility may be required with older NAS and Windows shares."
msgstr ""

#. Values for setting with label #36621 "Maximum protocol version" - none means "no protocol version is forced"
#: system/settings/settings.xml
msgctxt "#36623"
msgid "None"
msgstr ""

#. Values for setting with label #36621 "Maximum protocol version"
#: system/settings/settings.xml
msgctxt "#36624"
msgid "SMBv1"
msgstr ""

#. Values for setting with label #36621 "Maximum protocol version"
#: system/settings/settings.xml
msgctxt "#36625"
msgid "SMBv2"
msgstr ""

#. Values for setting with label #36621 "Maximum protocol version"
#: system/settings/settings.xml
msgctxt "#36626"
msgid "SMBv3"
msgstr ""

#. Label of a group, that allows configuration of the system SMB client
#: system/settings/settings.xml
msgctxt "#36627"
msgid "Client"
msgstr ""

#empty strings from id 36628 to 36899

#: xbmc/media/MediaType.cpp
msgctxt "#36900"
Expand Down
21 changes: 18 additions & 3 deletions system/settings/settings.xml
Expand Up @@ -1921,15 +1921,30 @@
<category id="smb" label="1200" help="36346">
<requirement>HAS_FILESYSTEM_SMB</requirement>
<group id="1" label="16000">
<setting id="smb.workgroup" type="string" label="1202" help="36348">
<level>2</level>
<default>WORKGROUP</default>
<control type="edit" format="string" />
</setting>
</group>
<group id="2" label="36627">
<setting id="smb.winsserver" type="string" label="1207" help="36347">
<level>2</level>
<default>0.0.0.0</default>
<control type="edit" format="ip" />
</setting>
<setting id="smb.workgroup" type="string" label="1202" help="36348">
<setting id="smb.maxprotocol" type="integer" label="36621" help="36622">
<level>2</level>
<default>WORKGROUP</default>
<control type="edit" format="string" />
<default>3</default>
<constraints>
<options>
<option label="36623">0</option>
<option label="36624">1</option>
<option label="36625">2</option>
<option label="36626">3</option>
</options>
</constraints>
<control type="list" format="integer" />
</setting>
</group>
</category>
Expand Down
45 changes: 30 additions & 15 deletions xbmc/filesystem/SMBFile.cpp
Expand Up @@ -28,6 +28,7 @@
#include "ServiceBroker.h"
#include "SMBDirectory.h"
#include <libsmbclient.h>
#include "filesystem/SpecialProtocol.h"
#include "settings/AdvancedSettings.h"
#include "settings/Settings.h"
#include "threads/SingleLock.h"
Expand Down Expand Up @@ -92,33 +93,39 @@ void CSMB::Deinit()
void CSMB::Init()
{
CSingleLock lock(*this);

if (!m_context)
{
// Create ~/.smb/smb.conf. This file is used by libsmbclient.
// force libsmbclient to use our own smb.conf by overriding HOME
std::string truehome(getenv("HOME"));
setenv("HOME", CSpecialProtocol::TranslatePath("special://home").c_str(), 1);

// Create ~/.kodi/.smb/smb.conf. This file is used by libsmbclient.
// http://us1.samba.org/samba/docs/man/manpages-3/libsmbclient.7.html
// http://us1.samba.org/samba/docs/man/manpages-3/smb.conf.5.html
char smb_conf[MAX_PATH];
std::string smb_conf;
std::string home(getenv("HOME"));
URIUtils::RemoveSlashAtEnd(home);
snprintf(smb_conf, sizeof(smb_conf), "%s/.smb", home.c_str());
if (mkdir(smb_conf, 0755) == 0)
smb_conf = home + "/.smb";
int result = mkdir(smb_conf.c_str(), 0755);
if (result == 0 || (errno == EEXIST && IsFirstInit))
{
snprintf(smb_conf, sizeof(smb_conf), "%s/.smb/smb.conf", getenv("HOME"));
FILE* f = fopen(smb_conf, "w");
smb_conf += "/smb.conf";
FILE* f = fopen(smb_conf.c_str(), "w");
if (f != NULL)
{
fprintf(f, "[global]\n");

// make sure we're not acting like a server
fprintf(f, "\tpreferred master = no\n");
fprintf(f, "\tlocal master = no\n");
fprintf(f, "\tdomain master = no\n");

// use the weaker LANMAN password hash in order to be compatible with older servers
fprintf(f, "\tclient lanman auth = yes\n");
fprintf(f, "\tlanman auth = yes\n");
fprintf(f, "\tlock directory = %s/.smb/\n", home.c_str());

fprintf(f, "\tlock directory = %s/.smb/\n", getenv("HOME"));
// set maximum smbclient protocol version
if (CServiceBroker::GetSettings().GetInt(CSettings::SETTING_SMB_MAXPROTOCOL) > 0)
{
if (CServiceBroker::GetSettings().GetInt(CSettings::SETTING_SMB_MAXPROTOCOL) == 1)
fprintf(f, "\tclient max protocol = NT1\n");
else
fprintf(f, "\tclient max protocol = SMB%d\n", CServiceBroker::GetSettings().GetInt(CSettings::SETTING_SMB_MAXPROTOCOL));
}

// set wins server if there's one. name resolve order defaults to 'lmhosts host wins bcast'.
// if no WINS server has been specified the wins method will be ignored.
Expand All @@ -135,6 +142,9 @@ void CSMB::Init()
if (g_advancedSettings.m_sambadoscodepage.length() > 0)
fprintf(f, "\tdos charset = %s\n", g_advancedSettings.m_sambadoscodepage.c_str());

// include users configuration if available
fprintf(f, "\tinclude = %s/.smb/user.conf\n", home.c_str());

fclose(f);
}
}
Expand All @@ -151,6 +161,10 @@ void CSMB::Init()

// setup our context
m_context = smbc_new_context();

// restore HOME
setenv("HOME", truehome.c_str(), 1);

#ifdef DEPRECATED_SMBC_INTERFACE
smbc_setDebug(m_context, g_advancedSettings.CanLogComponent(LOGSAMBA) ? 10 : 0);
smbc_setFunctionAuthData(m_context, xb_smbc_auth);
Expand Down Expand Up @@ -647,3 +661,4 @@ int CSMBFile::IoControl(EIoControl request, void* param)

return -1;
}

4 changes: 3 additions & 1 deletion xbmc/network/NetworkServices.cpp
Expand Up @@ -118,6 +118,7 @@ CNetworkServices::CNetworkServices()
, m_httpWebinterfaceAddonsHandler(*new CHTTPWebinterfaceAddonsHandler)
#endif // HAS_WEB_INTERFACE
#endif // HAS_WEB_SERVER

{
#ifdef HAS_WEB_SERVER
m_webserver.RegisterRequestHandler(&m_httpImageHandler);
Expand Down Expand Up @@ -456,7 +457,8 @@ void CNetworkServices::OnSettingChanged(std::shared_ptr<const CSetting> setting)
else
#endif // HAS_WEB_SERVER
if (settingId == CSettings::SETTING_SMB_WINSSERVER ||
settingId == CSettings::SETTING_SMB_WORKGROUP)
settingId == CSettings::SETTING_SMB_WORKGROUP ||
settingId == CSettings::SETTING_SMB_MAXPROTOCOL)
{
// okey we really don't need to restart, only deinit samba, but that could be damn hard if something is playing
//! @todo - General way of handling setting changes that require restart
Expand Down
2 changes: 2 additions & 0 deletions xbmc/settings/Settings.cpp
Expand Up @@ -332,6 +332,7 @@ const std::string CSettings::SETTING_SERVICES_AIRPLAYPASSWORD = "services.airpla
const std::string CSettings::SETTING_SERVICES_AIRPLAYVIDEOSUPPORT = "services.airplayvideosupport";
const std::string CSettings::SETTING_SMB_WINSSERVER = "smb.winsserver";
const std::string CSettings::SETTING_SMB_WORKGROUP = "smb.workgroup";
const std::string CSettings::SETTING_SMB_MAXPROTOCOL = "smb.maxprotocol";
const std::string CSettings::SETTING_VIDEOSCREEN_MONITOR = "videoscreen.monitor";
const std::string CSettings::SETTING_VIDEOSCREEN_SCREEN = "videoscreen.screen";
const std::string CSettings::SETTING_VIDEOSCREEN_RESOLUTION = "videoscreen.resolution";
Expand Down Expand Up @@ -990,6 +991,7 @@ void CSettings::InitializeISettingCallbacks()
settingSet.insert(CSettings::SETTING_SERVICES_ESCONTINUOUSDELAY);
settingSet.insert(CSettings::SETTING_SMB_WINSSERVER);
settingSet.insert(CSettings::SETTING_SMB_WORKGROUP);
settingSet.insert(CSettings::SETTING_SMB_MAXPROTOCOL);
GetSettingsManager()->RegisterCallback(&CNetworkServices::GetInstance(), settingSet);

settingSet.clear();
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/Settings.h
Expand Up @@ -278,6 +278,7 @@ class CSettings : public CSettingsBase, public CSettingCreator, public CSettingC
static const std::string SETTING_SERVICES_AIRPLAYVIDEOSUPPORT;
static const std::string SETTING_SMB_WINSSERVER;
static const std::string SETTING_SMB_WORKGROUP;
static const std::string SETTING_SMB_MAXPROTOCOL;
static const std::string SETTING_VIDEOSCREEN_MONITOR;
static const std::string SETTING_VIDEOSCREEN_SCREEN;
static const std::string SETTING_VIDEOSCREEN_RESOLUTION;
Expand Down

0 comments on commit 2c41c63

Please sign in to comment.