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 17, 2017
1 parent 71e187a commit 2fdca9f
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 12 deletions.
40 changes: 39 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -19749,7 +19749,45 @@ 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 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 ""

#. Label of a setting, allow overwrite of user smb.conf
#: system/settings/settings.xml
msgctxt "#36626"
msgid "Overwrite smb.conf"
msgstr ""

#. Description of setting with label #36626 "Overwrite smb.conf"
#: system/settings/settings.xml
msgctxt "#36627"
msgid "Overwrite ~/.smb/smb.conf on next restart. Use with caution! if smb.conf is shared by other system functions. The setting is automatically disabled after restarting"
msgstr ""

#empty strings from id 36628 to 36899

#: xbmc/media/MediaType.cpp
msgctxt "#36900"
Expand Down
33 changes: 30 additions & 3 deletions system/settings/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1913,15 +1913,42 @@
<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>
<setting id="smb.overwriteconf" type="boolean" label="36626" help="36627">
<level>2</level>
<default>false</default>
<control type="toggle" />
</setting>
<setting id="smb.winsserver" type="string" label="1207" help="36347">
<level>2</level>
<default>0.0.0.0</default>
<dependencies>
<dependency type="enable">
<condition setting="smb.overwriteconf" operator="is">true</condition>
</dependency>
<dependencies>
<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>
<dependencies>
<dependency type="enable">
<condition setting="smb.overwriteconf" operator="is">true</condition>
</dependency>
<dependencies>
<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>
Expand Down
19 changes: 12 additions & 7 deletions xbmc/filesystem/SMBFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ 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 && CServiceBroker::GetSettings().GetBool(CSettings::SETTING_SMB_OVERWRITECONF)))
{
snprintf(smb_conf, sizeof(smb_conf), "%s/.smb/smb.conf", getenv("HOME"));
snprintf(smb_conf, sizeof(smb_conf), "%s/.smb/smb.conf", home.c_str());
FILE* f = fopen(smb_conf, "w");
if (f != NULL)
{
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 All @@ -137,6 +139,9 @@ void CSMB::Init()
fprintf(f, "\tdos charset = %s\n", g_advancedSettings.m_sambadoscodepage.c_str());

fclose(f);

// disable overwrite setting
CServiceBroker::GetSettings().SetBool(CSettings::SETTING_SMB_OVERWRITECONF, false);
}
}

Expand Down
4 changes: 3 additions & 1 deletion xbmc/network/NetworkServices.cpp
Original file line number Diff line number Diff line change
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
4 changes: 4 additions & 0 deletions xbmc/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ 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_SMB_OVERWRITECONF = "smb.overwriteconf";
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 +1163,8 @@ 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);
settingSet.insert(CSettings::SETTING_SMB_OVERWRITECONF);
m_settingsManager->RegisterCallback(&CNetworkServices::GetInstance(), settingSet);

settingSet.clear();
Expand Down
2 changes: 2 additions & 0 deletions xbmc/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ 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_SMB_OVERWRITECONF;
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 2fdca9f

Please sign in to comment.