Skip to content

Commit

Permalink
smbclient: cleanup smbclient configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
chewitt committed May 16, 2017
1 parent 71e187a commit 253152c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
27 changes: 26 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Expand Up @@ -19749,7 +19749,32 @@ 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
#: system/settings/settings.xml
msgctxt "#36621"
msgid "Maximum SMB client version"
msgstr ""

#. Description of setting with label #36621 "Maximum SMB client version"
#: system/settings/settings.xml
msgctxt "#36622"
msgid "The maximum SMB client protocol version that can be negotiated. Default is SMBv3. Maximum version can be reduced to SMBv2 for compatibility with some NAS and older Windows versions if required. SMBv1 is insecure and to be used with caution! Change NAS configuration to support SMBv2/3 before resorting to SMBv1 max client version.
msgstr ""

#. SMB client protocol labels
#: system/settings/settings.xml
msgctxt "#36623"
msgid "SMBv1"
msgstr ""

msgctxt "#36624"
msgid "SMBv2"
msgstr ""

msgctxt "#36625"
msgid "SMBv3"
msgstr ""

#empty strings from id 36626 to 36899

#: xbmc/media/MediaType.cpp
msgctxt "#36900"
Expand Down
12 changes: 12 additions & 0 deletions system/settings/settings.xml
Expand Up @@ -1923,6 +1923,18 @@
<default>WORKGROUP</default>
<control type="edit" format="string" />
</setting>
<setting id="smb.maxprotocol" type="integer" label="36621" help="36622">
<level>2</level>
<default>3</default>
<constraints>
<options>
<option label="36623">1</option>
<option label="36623">2</option>
<option label="36625">3</option>
</options>
</constraints>
<control type="list" format="integer" />
</setting>
</group>
</category>
<category id="weather" label="8" help="36316">
Expand Down
20 changes: 11 additions & 9 deletions xbmc/filesystem/SMBFile.cpp
Expand Up @@ -92,7 +92,7 @@ void CSMB::Deinit()
void CSMB::Init()
{
CSingleLock lock(*this);
if (!m_context)
if (!m_context && IsFirstInit)
{
// Create ~/.smb/smb.conf. This file is used by libsmbclient.
// http://us1.samba.org/samba/docs/man/manpages-3/libsmbclient.7.html
Expand All @@ -101,10 +101,11 @@ void CSMB::Init()
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)
int result = mkdir(smb_conf, 0755);
if (result == 0 || errno == EEXIST)
{
snprintf(smb_conf, sizeof(smb_conf), "%s/.smb/smb.conf", getenv("HOME"));
FILE* f = fopen(smb_conf, "w");
snprintf(smb_conf, sizeof(smb_conf), "%s/.smb/smb.conf", home.c_str());
FILE* f = fopen(smb_conf, "w+");
if (f != NULL)
{
fprintf(f, "[global]\n");
Expand All @@ -114,13 +115,14 @@ void CSMB::Init()
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, "\tsocket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=65536 SO_SNDBUF=65536\n");
fprintf(f, "\tlock directory = %s/.smb/\n", getenv("HOME"));

// set maximum smbclient protocol version
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.
if (CServiceBroker::GetSettings().GetString(CSettings::SETTING_SMB_WINSSERVER).length() > 0 && !StringUtils::EqualsNoCase(CServiceBroker::GetSettings().GetString(CSettings::SETTING_SMB_WINSSERVER), "0.0.0.0") )
Expand Down
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 @@ -439,7 +440,8 @@ void CNetworkServices::OnSettingChanged(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 @@ -334,6 +334,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 @@ -1161,6 +1162,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);
m_settingsManager->RegisterCallback(&CNetworkServices::GetInstance(), settingSet);

settingSet.clear();
Expand Down
1 change: 1 addition & 0 deletions xbmc/settings/Settings.h
Expand Up @@ -288,6 +288,7 @@ class CSettings : public CSettingCreator, public CSettingControlCreator
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 253152c

Please sign in to comment.