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 53f1960 commit 3edead1
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 17 deletions.
50 changes: 49 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Expand Up @@ -19750,7 +19750,55 @@ 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 that can be negotiated (default SMBv3). Reduce to SMBv2 or SMBv1 for compatibility with older NAS and Windows shares if required."
msgstr ""

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

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

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

#. Label of a setting, allow overwrite of user smb.conf used with smbclient
#: system/settings/settings.xml
msgctxt "#36626"
msgid "Configure SMB client"
msgstr ""

#. Description of setting with label #36626 "Configure SMB client"
#: system/settings/settings.xml
msgctxt "#36627"
msgid "Configuring overwrites ~/.smb/smb.conf on next restart. The setting is automatically disabled after restarting"
msgstr ""

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

#empty strings from id 36629 to 36899

#: xbmc/media/MediaType.cpp
msgctxt "#36900"
Expand Down
35 changes: 32 additions & 3 deletions system/settings/settings.xml
Expand Up @@ -1913,15 +1913,44 @@
<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="36628">
<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="36624">2</option>
<option label="36625">3</option>
</options>
</constraints>
<control type="list" format="integer" />
</setting>
</group>
</category>
Expand Down
24 changes: 12 additions & 12 deletions xbmc/filesystem/SMBFile.cpp
Expand Up @@ -101,26 +101,23 @@ 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)
{
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, "\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 +134,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
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
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
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 3edead1

Please sign in to comment.