~ubuntu-filemanager-dev/ubuntu-filemanager-app/trunk

« back to all changes in this revision

Viewing changes to src/plugin/folderlistmodel/smb/smblocationauthentication.cpp

  • Committer: Bileto Bot
  • Date: 2017-04-04 17:06:41 UTC
  • mfrom: (588.1.19 fix-desktop-file)
  • Revision ID: ci-train-bot@canonical.com-20170404170641-1p15lmx8wodlx2ut
* Rename binary file to ubuntu-filemanager-app
* Join plugin packages into the main package 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 *
 
3
 * Copyright 2015 Canonical Ltd.
 
4
 * Copyright 2015 Carlos J Mazieri <carlos.mazieri@gmail.com>
 
5
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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/>.
 
17
 *
 
18
 * File: smblocationauthentication.cpp
 
19
 * Date: 17/01/2015
 
20
 */
 
21
 
 
22
#include "smblocationauthentication.h"
 
23
#include <QDebug>
 
24
 
 
25
#define  GOOD_INDEX()  (m_infoIndex >= 0 && m_infoIndex < MAX_AUTH_INSTANCES)
 
26
 
 
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
 
29
#else
 
30
# define DEBUG_AUTHENTICATION() /**/
 
31
#endif
 
32
 
 
33
 
 
34
namespace
 
35
{
 
36
   QByteArray  m_AuthUser[MAX_AUTH_INSTANCES];
 
37
   QByteArray  m_AuthPass[MAX_AUTH_INSTANCES];
 
38
   void *      m_instances[MAX_AUTH_INSTANCES];
 
39
}
 
40
 
 
41
 
 
42
SmbLocationAuthentication::SmbLocationAuthentication() : m_infoIndex(-1)
 
43
{
 
44
    for(int counter = 0; counter < MAX_AUTH_INSTANCES; ++counter)
 
45
    {
 
46
        if (m_instances[counter] == 0)
 
47
        {
 
48
            m_infoIndex = counter;
 
49
            m_instances[m_infoIndex] = this;
 
50
            break;
 
51
        }
 
52
    }
 
53
}
 
54
 
 
55
//============================================================================
 
56
/*!
 
57
 * \brief SmbLocationAuthentication::~SmbLocationAuthentication
 
58
 */
 
59
SmbLocationAuthentication::~SmbLocationAuthentication()
 
60
{
 
61
    if (GOOD_INDEX())
 
62
    {
 
63
        m_instances[m_infoIndex] = 0;
 
64
    }
 
65
    else
 
66
    {
 
67
        qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
 
68
    }
 
69
}
 
70
 
 
71
//============================================================================
 
72
/*!
 
73
 * \brief SmbLocationAuthentication::setInfo
 
74
 * \param user
 
75
 * \param password
 
76
 */
 
77
void SmbLocationAuthentication::setInfo(const QString &user, const QString &password)
 
78
{
 
79
    if (GOOD_INDEX())
 
80
    {
 
81
        m_AuthUser[m_infoIndex] = user.toLocal8Bit();
 
82
        m_AuthPass[m_infoIndex] = password.toLocal8Bit();
 
83
    }
 
84
    else
 
85
    {
 
86
        qDebug() << Q_FUNC_INFO << "ERROR no m_instances[] index";
 
87
    }
 
88
}
 
89
 
 
90
//============================================================================
 
91
/*!
 
92
 * \brief SmbLocationAuthentication::suitableAuthenticationFunction
 
93
 * \return
 
94
 */
 
95
Smb::AuthenticationFunction
 
96
SmbLocationAuthentication::suitableAuthenticationFunction() const
 
97
{
 
98
    switch(m_infoIndex)
 
99
    {
 
100
       case 0:  return  &SmbLocationAuthentication::authenticateCallBack0;
 
101
       case 1:  return  &SmbLocationAuthentication::authenticateCallBack1;
 
102
       case 2:  return  &SmbLocationAuthentication::authenticateCallBack2;
 
103
       case 3:  return  &SmbLocationAuthentication::authenticateCallBack3;
 
104
       default: return  0;
 
105
    }
 
106
}
 
107
 
 
108
//============================================================================
 
109
/*!
 
110
 * \brief SmbLocationAuthentication::authenticateCallBack0
 
111
 * \param server
 
112
 * \param share
 
113
 * \param wrkgrp
 
114
 * \param wrkgrplen
 
115
 * \param user
 
116
 * \param userlen
 
117
 * \param passwd
 
118
 * \param passwdlen
 
119
 */
 
120
void SmbLocationAuthentication::authenticateCallBack0(const char *server,
 
121
                                                      const char *share,
 
122
                                                      char *wrkgrp,
 
123
                                                      int wrkgrplen,
 
124
                                                      char *user,
 
125
                                                      int userlen,
 
126
                                                      char *passwd,
 
127
                                                      int passwdlen)
 
128
{
 
129
    Q_UNUSED(server);
 
130
    Q_UNUSED(share);
 
131
    Q_UNUSED(wrkgrp);
 
132
    Q_UNUSED(wrkgrplen);
 
133
 
 
134
    ::strncpy(user,   m_AuthUser[0].constData(),  --userlen);
 
135
    ::strncpy(passwd, m_AuthPass[0].constData(),  --passwdlen);
 
136
    DEBUG_AUTHENTICATION();
 
137
}
 
138
 
 
139
//============================================================================
 
140
/*!
 
141
 * \brief SmbLocationAuthentication::authenticateCallBack1
 
142
 * \param server
 
143
 * \param share
 
144
 * \param wrkgrp
 
145
 * \param wrkgrplen
 
146
 * \param user
 
147
 * \param userlen
 
148
 * \param passwd
 
149
 * \param passwdlen
 
150
 */
 
151
void SmbLocationAuthentication::authenticateCallBack1(const char *server,
 
152
                                                      const char *share,
 
153
                                                      char *wrkgrp,
 
154
                                                      int wrkgrplen,
 
155
                                                      char *user,
 
156
                                                      int userlen,
 
157
                                                      char *passwd,
 
158
                                                      int passwdlen)
 
159
{
 
160
    Q_UNUSED(server);
 
161
    Q_UNUSED(share);
 
162
    Q_UNUSED(wrkgrp);
 
163
    Q_UNUSED(wrkgrplen);
 
164
 
 
165
    ::strncpy(user,   m_AuthUser[1].constData(),  --userlen);
 
166
    ::strncpy(passwd, m_AuthPass[1].constData(),  --passwdlen);
 
167
    DEBUG_AUTHENTICATION();
 
168
}
 
169
 
 
170
//============================================================================
 
171
/*!
 
172
 * \brief SmbLocationAuthentication::authenticateCallBack2
 
173
 * \param server
 
174
 * \param share
 
175
 * \param wrkgrp
 
176
 * \param wrkgrplen
 
177
 * \param user
 
178
 * \param userlen
 
179
 * \param passwd
 
180
 * \param passwdlen
 
181
 */
 
182
void SmbLocationAuthentication::authenticateCallBack2(const char *server,
 
183
                                                      const char *share,
 
184
                                                      char *wrkgrp,
 
185
                                                      int wrkgrplen,
 
186
                                                      char *user,
 
187
                                                      int userlen,
 
188
                                                      char *passwd,
 
189
                                                      int passwdlen)
 
190
{
 
191
    Q_UNUSED(server);
 
192
    Q_UNUSED(share);
 
193
    Q_UNUSED(wrkgrp);
 
194
    Q_UNUSED(wrkgrplen);
 
195
 
 
196
    ::strncpy(user,   m_AuthUser[2].constData(),  --userlen);
 
197
    ::strncpy(passwd, m_AuthPass[2].constData(),  --passwdlen);
 
198
    DEBUG_AUTHENTICATION();
 
199
}
 
200
 
 
201
//============================================================================
 
202
/*!
 
203
 * \brief SmbLocationAuthentication::authenticateCallBack3
 
204
 * \param server
 
205
 * \param share
 
206
 * \param wrkgrp
 
207
 * \param wrkgrplen
 
208
 * \param user
 
209
 * \param userlen
 
210
 * \param passwd
 
211
 * \param passwdlen
 
212
 */
 
213
void SmbLocationAuthentication::authenticateCallBack3(const char *server,
 
214
                                                      const char *share,
 
215
                                                      char *wrkgrp,
 
216
                                                      int wrkgrplen,
 
217
                                                      char *user,
 
218
                                                      int userlen,
 
219
                                                      char *passwd,
 
220
                                                      int passwdlen)
 
221
{
 
222
    Q_UNUSED(server);
 
223
    Q_UNUSED(share);
 
224
    Q_UNUSED(wrkgrp);
 
225
    Q_UNUSED(wrkgrplen);
 
226
 
 
227
    ::strncpy(user,   m_AuthUser[3].constData(),  --userlen);
 
228
    ::strncpy(passwd, m_AuthPass[3].constData(),  --passwdlen);
 
229
    DEBUG_AUTHENTICATION();
 
230
}
 
231
 
 
232
 
 
233
QString SmbLocationAuthentication::currentAuthUser() const
 
234
{
 
235
    QString ret;
 
236
    if (GOOD_INDEX())
 
237
    {
 
238
       ret = m_AuthUser[m_infoIndex];
 
239
    }
 
240
    return ret;
 
241
}
 
242
 
 
243
 
 
244
 
 
245
QString SmbLocationAuthentication::currentAuthPassword() const
 
246
{
 
247
    QString ret;
 
248
    if (GOOD_INDEX())
 
249
    {
 
250
       ret = m_AuthPass[m_infoIndex];
 
251
    }
 
252
    return ret;
 
253
}