1
/**************************************************************************
3
* Copyright 2015 Canonical Ltd.
4
* Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; version 3.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
* File: smblocationauthentication.cpp
22
#include "smblocationauthentication.h"
25
#define GOOD_INDEX() (m_infoIndex >= 0 && m_infoIndex < MAX_AUTH_INSTANCES)
27
#if defined(REGRESSION_TEST_FOLDERLISTMODEL) && defined(SIMPLE_UI)
28
# define DEBUG_AUTHENTICATION() qDebug() << Q_FUNC_INFO << "user:" << user << "passwd:" << passwd << "server:" << server << "share:" << share
30
# define DEBUG_AUTHENTICATION() /**/
36
QByteArray m_AuthUser[MAX_AUTH_INSTANCES];
37
QByteArray m_AuthPass[MAX_AUTH_INSTANCES];
38
void * m_instances[MAX_AUTH_INSTANCES];
42
SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
44
for(int counter = 0; counter < MAX_AUTH_INSTANCES; ++counter)
46
if (m_instances[counter] == 0)
48
m_infoIndex = counter;
49
m_instances[m_infoIndex] = this;
55
//============================================================================
57
* \brief SmbLocationAuthentication::~SmbLocationAuthentication
59
SmbLocationAuthentication::~SmbLocationAuthentication()
63
m_instances[m_infoIndex] = 0;
67
qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
71
//============================================================================
73
* \brief SmbLocationAuthentication::setInfo
77
void SmbLocationAuthentication::setInfo(const QString &user, const QString &password)
81
m_AuthUser[m_infoIndex] = user.toLocal8Bit();
82
m_AuthPass[m_infoIndex] = password.toLocal8Bit();
86
qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
90
//============================================================================
92
* \brief SmbLocationAuthentication::suitableAuthenticationFunction
95
Smb::AuthenticationFunction
96
SmbLocationAuthentication::suitableAuthenticationFunction() const
100
case 0: return &SmbLocationAuthentication::authenticateCallBack0;
101
case 1: return &SmbLocationAuthentication::authenticateCallBack1;
102
case 2: return &SmbLocationAuthentication::authenticateCallBack2;
103
case 3: return &SmbLocationAuthentication::authenticateCallBack3;
108
//============================================================================
110
* \brief SmbLocationAuthentication::authenticateCallBack0
120
void SmbLocationAuthentication::authenticateCallBack0(const char *server,
134
::strncpy(user, m_AuthUser[0].constData(), --userlen);
135
::strncpy(passwd, m_AuthPass[0].constData(), --passwdlen);
136
DEBUG_AUTHENTICATION();
139
//============================================================================
141
* \brief SmbLocationAuthentication::authenticateCallBack1
151
void SmbLocationAuthentication::authenticateCallBack1(const char *server,
165
::strncpy(user, m_AuthUser[1].constData(), --userlen);
166
::strncpy(passwd, m_AuthPass[1].constData(), --passwdlen);
167
DEBUG_AUTHENTICATION();
170
//============================================================================
172
* \brief SmbLocationAuthentication::authenticateCallBack2
182
void SmbLocationAuthentication::authenticateCallBack2(const char *server,
196
::strncpy(user, m_AuthUser[2].constData(), --userlen);
197
::strncpy(passwd, m_AuthPass[2].constData(), --passwdlen);
198
DEBUG_AUTHENTICATION();
201
//============================================================================
203
* \brief SmbLocationAuthentication::authenticateCallBack3
213
void SmbLocationAuthentication::authenticateCallBack3(const char *server,
227
::strncpy(user, m_AuthUser[3].constData(), --userlen);
228
::strncpy(passwd, m_AuthPass[3].constData(), --passwdlen);
229
DEBUG_AUTHENTICATION();
233
QString SmbLocationAuthentication::currentAuthUser() const
238
ret = m_AuthUser[m_infoIndex];
245
QString SmbLocationAuthentication::currentAuthPassword() const
250
ret = m_AuthPass[m_infoIndex];