~ubuntu-branches/ubuntu/utopic/mysql-workbench/utopic

« back to all changes in this revision

Viewing changes to backend/wbprivate/workbench/wb_tunnel.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2014-05-31 12:03:58 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140531120358-cjik5ofkmj0fxsn8
Tags: 6.1.6+dfsg-1
* New upstream release [May 2014].
* Dropped "prtcl.patch".
* "debian/clean": better clean-up.

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
  tunnel_auth_error(const std::string &err) : std::runtime_error(err) {}
51
51
};
52
52
 
 
53
class tunnel_auth_retry : public std::runtime_error
 
54
{
 
55
public:
 
56
  tunnel_auth_retry(const std::string &err) : std::runtime_error(err) {}
 
57
};
 
58
 
 
59
class tunnel_auth_cancelled : public std::runtime_error
 
60
{
 
61
public:
 
62
  tunnel_auth_cancelled(const std::string &err) : std::runtime_error(err) {}
 
63
};
 
64
 
 
65
class tunnel_auth_key_error : public std::runtime_error
 
66
{
 
67
public:
 
68
  tunnel_auth_key_error(const std::string &err) : std::runtime_error(err) {}
 
69
};
 
70
 
 
71
 
53
72
class SSHTunnel : public sql::TunnelConnection
54
73
{
55
74
  TunnelManager *_tm;
121
140
{
122
141
  std::string progpath = bec::make_path(_wb->get_grt_manager()->get_basedir(), "sshtunnel.py");
123
142
 
124
 
  grt::WillEnterPython lock;
 
143
  WillEnterPython lock;
125
144
  grt::PythonContext *py = grt::PythonContext::get();
126
145
  if (py->run_file(progpath, false) < 0)
127
146
  {
134
153
 
135
154
int TunnelManager::lookup_tunnel(const char *server, const char *username, const char *target)
136
155
{
137
 
  grt::WillEnterPython lock;
 
156
  WillEnterPython lock;
138
157
 
139
158
  // Note: without the (char*) cast gcc will complain about passing a const char* to a char*.
140
159
  //       Ideally the function signature should be changed to take a const char*.
158
177
 
159
178
void TunnelManager::shutdown()
160
179
{
161
 
  grt::WillEnterPython lock;
 
180
  WillEnterPython lock;
162
181
  if (_tunnel)
163
182
  {
164
183
    PyObject *ret = PyObject_CallMethod(_tunnel, (char*) "shutdown", NULL);
175
194
int TunnelManager::open_tunnel(const char *server, const char *username, const char *password, 
176
195
                               const char *keyfile, const char *target)
177
196
{
178
 
  grt::WillEnterPython lock;
 
197
  WillEnterPython lock;
179
198
  PyObject *ret = PyObject_CallMethod(_tunnel, (char*) "open_tunnel", (char*) "sssss",
180
199
                                      server, username, password, keyfile, target);
181
200
  if (!ret)
213
232
 
214
233
void TunnelManager::wait_tunnel(int port)
215
234
{
216
 
  grt::WillEnterPython lock;
 
235
  WillEnterPython lock;
217
236
 
218
237
  log_debug("Waiting on tunnel to connect...\n");
219
238
 
241
260
    throw tunnel_auth_error("Authentication error. Please check that your username and password are correct and try again."
242
261
            "\nDetails (Original exception message):\n" + str);
243
262
 
244
 
  if ( g_str_has_prefix(str.c_str(), "Authentication error") )
 
263
  if (g_str_has_prefix(str.c_str(), "Server key has been stored"))
 
264
  {
 
265
    log_info("TunnelManager.wait_connection server key stored, retrying: %s\n", str.c_str());
 
266
    throw tunnel_auth_retry("Retry due to fingerprint missing, user accept new fingerprint");
 
267
  }
 
268
 
 
269
  if (g_str_has_prefix(str.c_str(), "Host key for server "))
 
270
  {
 
271
    log_info("TunnelManager.wait_connection host key does not match, abandoning connection: %s\n", str.c_str());
 
272
    throw tunnel_auth_key_error(str);
 
273
  }
 
274
 
 
275
  if (g_str_has_prefix(str.c_str(), "User cancelled"))
 
276
  {
 
277
    log_info("TunnelManager.wait_connection cancelled by the user: %s\n", str.c_str());
 
278
    throw tunnel_auth_cancelled("Tunnel connection cancelled by the user");
 
279
  }
 
280
  if (g_str_has_prefix(str.c_str(), "IO Error"))
 
281
  {
 
282
    log_error("TunnelManager.wait_connection got IOError: %s\n", str.c_str());
 
283
    throw tunnel_auth_key_error(str);
 
284
  }
 
285
 
 
286
  if (g_str_has_prefix(str.c_str(), "Authentication error"))
 
287
  {
 
288
    log_info("TunnelManager.wait_connection authentication error: %s\n", str.c_str());
245
289
    throw tunnel_auth_error(str);
 
290
  }
246
291
 
247
292
  throw std::runtime_error("Error connecting SSH tunnel: "+str);
248
293
}
252
297
{
253
298
  std::list<std::pair<std::string, std::string> > messages;
254
299
 
255
 
  grt::WillEnterPython lock;
 
300
  WillEnterPython lock;
256
301
 
257
302
  PyObject *ret = PyObject_CallMethod(_tunnel, (char*) "get_message", (char*) "i", port);
258
303
  if (!ret)
290
335
 
291
336
void TunnelManager::close_tunnel(int port)
292
337
{
293
 
  grt::WillEnterPython lock;
 
338
  WillEnterPython lock;
294
339
  PyObject *ret = PyObject_CallMethod(_tunnel, (char*) "close", (char*) "i", port);
295
340
  if (!ret)
296
341
  {
407
452
        else
408
453
          throw grt::user_cancelled("Tunnel connection cancelled");
409
454
      }
 
455
      catch (tunnel_auth_retry &exc)
 
456
      {
 
457
        log_warning("Opening SSH tunnel: %s\n", exc.what());
 
458
        goto retry;
 
459
      }
 
460
      catch (tunnel_auth_cancelled &exc)
 
461
      {
 
462
        log_debug("Tunnel auth cancelled: %s\n", exc.what());
 
463
        throw grt::user_cancelled(exc.what());
 
464
      }
 
465
      catch (tunnel_auth_key_error &exc)
 
466
      {
 
467
        mforms::Utilities::show_error("Tunnel Connection Error", exc.what(), _("OK"));
 
468
        log_debug("Tunnel auth key error: %s\n", exc.what());
 
469
        throw grt::user_cancelled(exc.what());
 
470
      }
410
471
      catch (std::exception &exc)
411
472
      {
412
473
        log_error("Exception while opening SSH tunnel: %s\n", exc.what());