Commit 233f30dc authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

smb: fix horrendous indentation in auth.cpp

it was all over the place.
also reduce nesting in auth_initialize_smbc by returning early if already
init'd. also happens to reduce the debug spam on noop calls
parent 101c8781
......@@ -75,7 +75,7 @@ void SMBSlave::auth_smbc_get_data(const char *server,const char *share,
return;
}
qCDebug(KIO_SMB_LOG) << "auth_smbc_get_dat: set user=" << username << ", workgroup=" << workgroup
<< " server=" << server << ", share=" << share;
<< " server=" << server << ", share=" << share;
QString s_server = QString::fromUtf8(server);
QString s_share = QString::fromUtf8(share);
......@@ -156,15 +156,15 @@ int SMBSlave::checkPassword(SMBUrl &url)
if ( share.isEmpty() )
info.prompt = i18n(
"<qt>Please enter authentication information for <b>%1</b></qt>" ,
url.host() );
"<qt>Please enter authentication information for <b>%1</b></qt>" ,
url.host() );
else
info.prompt = i18n(
"Please enter authentication information for:\n"
"Server = %1\n"
"Share = %2" ,
url.host() ,
share );
"Please enter authentication information for:\n"
"Server = %1\n"
"Share = %2" ,
url.host() ,
share );
info.username = url.userName();
qCDebug(KIO_SMB_LOG) << "call openPasswordDialog for " << info.url;
......@@ -176,7 +176,7 @@ int SMBSlave::checkPassword(SMBUrl &url)
if (info.keepPassword) {
qCDebug(KIO_SMB_LOG) << "Caching info.username = " << info.username
<< ", info.url = " << info.url.toDisplayString();
<< ", info.url = " << info.url.toDisplayString();
cacheAuthentication(info);
}
......@@ -192,50 +192,49 @@ int SMBSlave::checkPassword(SMBUrl &url)
// Returns: 0 on success -1 with errno set on error
bool SMBSlave::auth_initialize_smbc()
{
SMBCCTX *smb_context = nullptr;
if (m_initialized_smbc) {
return true;
}
qCDebug(KIO_SMB_LOG) << "auth_initialize_smbc ";
if(m_initialized_smbc == false)
{
qCDebug(KIO_SMB_LOG) << "smbc_init call";
KConfig cfg( "kioslaverc", KConfig::SimpleConfig);
int debug_level = cfg.group( "SMB" ).readEntry( "DebugLevel", 0 );
qCDebug(KIO_SMB_LOG) << "auth_initialize_smbc";
KConfig cfg("kioslaverc", KConfig::SimpleConfig);
int debug_level = cfg.group("SMB").readEntry("DebugLevel", 0);
smb_context = smbc_new_context();
if (smb_context == nullptr) {
SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to create context"));
return false;
}
qCDebug(KIO_SMB_LOG) << "smbc_new_context call";
SMBCCTX *smb_context = smbc_new_context();
if (!smb_context) {
SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to create context"));
return false;
}
#ifdef DEPRECATED_SMBC_INTERFACE // defined by libsmbclient.h of Samba 3.2
/* New libsmbclient interface of Samba 3.2 */
smbc_setDebug(smb_context, debug_level);
smbc_setFunctionAuthDataWithContext(smb_context, ::auth_smbc_get_data);
smbc_setOptionUserData(smb_context, this);
/* Enable Kerberos support */
smbc_setOptionUseKerberos(smb_context, 1);
smbc_setOptionFallbackAfterKerberos(smb_context, 1);
/* New libsmbclient interface of Samba 3.2 */
smbc_setDebug(smb_context, debug_level);
smbc_setFunctionAuthDataWithContext(smb_context, ::auth_smbc_get_data);
smbc_setOptionUserData(smb_context, this);
/* Enable Kerberos support */
smbc_setOptionUseKerberos(smb_context, 1);
smbc_setOptionFallbackAfterKerberos(smb_context, 1);
#else
smb_context->debug = debug_level;
smb_context->callbacks.auth_fn = NULL;
smbc_option_set(smb_context, "auth_function", (void*)::auth_smbc_get_data);
smbc_option_set(smb_context, "user_data", this);
#if defined(SMB_CTX_FLAG_USE_KERBEROS) && defined(SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS)
smb_context->flags |= SMB_CTX_FLAG_USE_KERBEROS | SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS;
#endif
smb_context->debug = debug_level;
smb_context->callbacks.auth_fn = NULL;
smbc_option_set(smb_context, "auth_function", (void*)::auth_smbc_get_data);
smbc_option_set(smb_context, "user_data", this);
#if defined(SMB_CTX_FLAG_USE_KERBEROS) && defined(SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS)
smb_context->flags |= SMB_CTX_FLAG_USE_KERBEROS | SMB_CTX_FLAG_FALLBACK_AFTER_KERBEROS;
#endif
#endif /* DEPRECATED_SMBC_INTERFACE */
if (!smbc_init_context(smb_context)) {
smbc_free_context(smb_context, 0);
smb_context = nullptr;
SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to initialize context"));
return false;
}
if (!smbc_init_context(smb_context)) {
smbc_free_context(smb_context, 0);
smb_context = nullptr;
SlaveBase::error(ERR_INTERNAL, i18n("libsmbclient failed to initialize context"));
return false;
}
smbc_set_context(smb_context);
smbc_set_context(smb_context);
// TODO: refactor; checkPassword should query this on
// demand to not run into situations where we may have cached
......@@ -244,9 +243,7 @@ bool SMBSlave::auth_initialize_smbc()
// problems should checkPassword be called without init first.
m_default_workgroup = smbc_getWorkgroup(smb_context);
m_initialized_smbc = true;
}
m_initialized_smbc = true;
return true;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment