~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_connect.cc

  • Committer: Stewart Smith
  • Author(s): Marko Mäkelä
  • Date: 2010-12-20 03:21:44 UTC
  • mto: (2021.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2022.
  • Revision ID: stewart@flamingspork.com-20101220032144-7aqh2z403u7d7bdp
Merge Revision revid:marko.makela@oracle.com-20101104131215-pfxnpidlrzd4krg0 from MySQL InnoDB

Original revid:marko.makela@oracle.com-20101104131215-pfxnpidlrzd4krg0

Original Authors: Marko Mäkelä <marko.makela@oracle.com>
Original commit message:
row_ins_index_entry(): Note that only CREATE INDEX sets foreign=FALSE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
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 General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
 
21
 
/*
22
 
  Functions to autenticate and handle reqests for a connection
23
 
*/
24
 
#include <drizzled/server_includes.h>
25
 
#include <netdb.h>
26
 
 
27
 
#include <drizzled/authentication.h>
28
 
#include <drizzled/db.h>
29
 
#include <drizzled/error.h>
30
 
#include <drizzled/sql_parse.h>
31
 
#include <drizzled/scheduler.h>
32
 
#include <drizzled/session.h>
33
 
 
34
 
extern scheduler_functions thread_scheduler;
35
 
 
36
 
#define MIN_HANDSHAKE_SIZE      6
37
 
 
38
 
/*
39
 
  Get structure for logging connection data for the current user
40
 
*/
41
 
 
42
 
char *ip_to_hostname(struct sockaddr_storage *in, int addrLen)
43
 
{
44
 
  char *name;
45
 
 
46
 
  int gxi_error;
47
 
  char hostname_buff[NI_MAXHOST];
48
 
 
49
 
  /* Historical comparison for 127.0.0.1 */
50
 
  gxi_error= getnameinfo((struct sockaddr *)in, addrLen,
51
 
                         hostname_buff, NI_MAXHOST,
52
 
                         NULL, 0, NI_NUMERICHOST);
53
 
  if (gxi_error)
54
 
  {
55
 
    return NULL;
56
 
  }
57
 
 
58
 
  if (!(name= my_strdup(hostname_buff, MYF(0))))
59
 
  {
60
 
    return NULL;
61
 
  }
62
 
 
63
 
  return NULL;
64
 
}
65
 
 
66
 
/**
67
 
  Check if user exist and password supplied is correct.
68
 
 
69
 
  @param  session         thread handle, session->security_ctx->{host,user,ip} are used
70
 
  @param  command     originator of the check: now check_user is called
71
 
                      during connect and change user procedures; used for
72
 
                      logging.
73
 
  @param  passwd      scrambled password received from client
74
 
  @param  passwd_len  length of scrambled password
75
 
  @param  db          database name to connect to, may be NULL
76
 
  @param  check_count true if establishing a new connection. In this case
77
 
                      check that we have not exceeded the global
78
 
                      max_connections limist
79
 
 
80
 
  @note Host, user and passwd may point to communication buffer.
81
 
  Current implementation does not depend on that, but future changes
82
 
  should be done with this in mind; 'session' is INOUT, all other params
83
 
  are 'IN'.
84
 
 
85
 
  @retval  0  OK
86
 
  @retval  1  error, e.g. access denied or handshake error, not sent to
87
 
              the client. A message is pushed into the error stack.
88
 
*/
89
 
 
90
 
int
91
 
check_user(Session *session, const char *passwd,
92
 
           uint32_t passwd_len, const char *db,
93
 
           bool check_count)
94
 
{
95
 
  LEX_STRING db_str= { (char *) db, db ? strlen(db) : 0 };
96
 
  bool is_authenticated;
97
 
 
98
 
  /*
99
 
    Clear session->db as it points to something, that will be freed when
100
 
    connection is closed. We don't want to accidentally free a wrong
101
 
    pointer if connect failed. Also in case of 'CHANGE USER' failure,
102
 
    current database will be switched to 'no database selected'.
103
 
  */
104
 
  session->reset_db(NULL, 0);
105
 
 
106
 
  if (passwd_len != 0 && passwd_len != SCRAMBLE_LENGTH)
107
 
  {
108
 
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->main_security_ctx.ip);
109
 
    return(1);
110
 
  }
111
 
 
112
 
  is_authenticated= authenticate_user(session, passwd);
113
 
 
114
 
  if (is_authenticated != true)
115
 
  {
116
 
    my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
117
 
             session->main_security_ctx.user,
118
 
             session->main_security_ctx.ip,
119
 
             passwd_len ? ER(ER_YES) : ER(ER_NO));
120
 
 
121
 
    return 1;
122
 
  }
123
 
 
124
 
 
125
 
  USER_RESOURCES ur;
126
 
  session->security_ctx->skip_grants();
127
 
  memset(&ur, 0, sizeof(USER_RESOURCES));
128
 
 
129
 
  if (check_count)
130
 
  {
131
 
    pthread_mutex_lock(&LOCK_connection_count);
132
 
    bool count_ok= connection_count <= max_connections;
133
 
    pthread_mutex_unlock(&LOCK_connection_count);
134
 
 
135
 
    if (!count_ok)
136
 
    {                                         // too many connections
137
 
      my_error(ER_CON_COUNT_ERROR, MYF(0));
138
 
      return(1);
139
 
    }
140
 
  }
141
 
 
142
 
  /* Change database if necessary */
143
 
  if (db && db[0])
144
 
  {
145
 
    if (mysql_change_db(session, &db_str, false))
146
 
    {
147
 
      /* mysql_change_db() has pushed the error message. */
148
 
      return(1);
149
 
    }
150
 
  }
151
 
  my_ok(session);
152
 
  session->password= test(passwd_len);          // remember for error messages 
153
 
  /* Ready to handle queries */
154
 
  return(0);
155
 
}
156
 
 
157
 
 
158
 
/*
159
 
  Check for maximum allowable user connections, if the mysqld server is
160
 
  started with corresponding variable that is greater then 0.
161
 
*/
162
 
 
163
 
extern "C" unsigned char *get_key_conn(user_conn *buff, size_t *length,
164
 
                               bool not_used __attribute__((unused)))
165
 
{
166
 
  *length= buff->len;
167
 
  return (unsigned char*) buff->user;
168
 
}
169
 
 
170
 
 
171
 
extern "C" void free_user(struct user_conn *uc)
172
 
{
173
 
  free((char*) uc);
174
 
}
175
 
 
176
 
void session_init_client_charset(Session *session, uint32_t cs_number)
177
 
{
178
 
  /*
179
 
   Use server character set and collation if
180
 
   - opt_character_set_client_handshake is not set
181
 
   - client has not specified a character set
182
 
   - client character set is the same as the servers
183
 
   - client character set doesn't exists in server
184
 
  */
185
 
  if (!opt_character_set_client_handshake ||
186
 
      !(session->variables.character_set_client= get_charset(cs_number, MYF(0))) ||
187
 
      !my_strcasecmp(&my_charset_utf8_general_ci,
188
 
                     global_system_variables.character_set_client->name,
189
 
                     session->variables.character_set_client->name))
190
 
  {
191
 
    session->variables.character_set_client=
192
 
      global_system_variables.character_set_client;
193
 
    session->variables.collation_connection=
194
 
      global_system_variables.collation_connection;
195
 
    session->variables.character_set_results=
196
 
      global_system_variables.character_set_results;
197
 
  }
198
 
  else
199
 
  {
200
 
    session->variables.character_set_results=
201
 
      session->variables.collation_connection= 
202
 
      session->variables.character_set_client;
203
 
  }
204
 
}
205
 
 
206
 
 
207
 
/*
208
 
  Initialize connection threads
209
 
*/
210
 
 
211
 
bool init_new_connection_handler_thread()
212
 
{
213
 
  pthread_detach_this_thread();
214
 
  /* Win32 calls this in pthread_create */
215
 
  if (my_thread_init())
216
 
    return 1;
217
 
  return 0;
218
 
}
219
 
 
220
 
/*
221
 
  Perform handshake, authorize client and update session ACL variables.
222
 
 
223
 
  SYNOPSIS
224
 
    check_connection()
225
 
    session  thread handle
226
 
 
227
 
  RETURN
228
 
     0  success, OK is sent to user, session is updated.
229
 
    -1  error, which is sent to user
230
 
   > 0  error code (not sent to user)
231
 
*/
232
 
 
233
 
static int check_connection(Session *session)
234
 
{
235
 
  NET *net= &session->net;
236
 
  uint32_t pkt_len= 0;
237
 
  char *end;
238
 
 
239
 
  // TCP/IP connection
240
 
  {
241
 
    char ip[NI_MAXHOST];
242
 
 
243
 
    if (net_peer_addr(net, ip, &session->peer_port, NI_MAXHOST))
244
 
    {
245
 
      my_error(ER_BAD_HOST_ERROR, MYF(0), session->main_security_ctx.ip);
246
 
      return 1;
247
 
    }
248
 
    if (!(session->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME))))
249
 
      return 1; /* The error is set by my_strdup(). */
250
 
  }
251
 
  net_keepalive(net, true);
252
 
  
253
 
  uint32_t server_capabilites;
254
 
  {
255
 
    /* buff[] needs to big enough to hold the server_version variable */
256
 
    char buff[SERVER_VERSION_LENGTH + SCRAMBLE_LENGTH + 64];
257
 
    server_capabilites= CLIENT_BASIC_FLAGS;
258
 
 
259
 
    if (opt_using_transactions)
260
 
      server_capabilites|= CLIENT_TRANSACTIONS;
261
 
#ifdef HAVE_COMPRESS
262
 
    server_capabilites|= CLIENT_COMPRESS;
263
 
#endif /* HAVE_COMPRESS */
264
 
 
265
 
    end= my_stpncpy(buff, server_version, SERVER_VERSION_LENGTH) + 1;
266
 
    int4store((unsigned char*) end, session->thread_id);
267
 
    end+= 4;
268
 
    /*
269
 
      So as check_connection is the only entry point to authorization
270
 
      procedure, scramble is set here. This gives us new scramble for
271
 
      each handshake.
272
 
    */
273
 
    create_random_string(session->scramble, SCRAMBLE_LENGTH, &session->rand);
274
 
    /*
275
 
      Old clients does not understand long scrambles, but can ignore packet
276
 
      tail: that's why first part of the scramble is placed here, and second
277
 
      part at the end of packet.
278
 
    */
279
 
    end= strmake(end, session->scramble, SCRAMBLE_LENGTH_323) + 1;
280
 
   
281
 
    int2store(end, server_capabilites);
282
 
    /* write server characteristics: up to 16 bytes allowed */
283
 
    end[2]=(char) default_charset_info->number;
284
 
    int2store(end+3, session->server_status);
285
 
    memset(end+5, 0, 13);
286
 
    end+= 18;
287
 
    /* write scramble tail */
288
 
    end= strmake(end, session->scramble + SCRAMBLE_LENGTH_323, 
289
 
                 SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323) + 1;
290
 
 
291
 
    /* At this point we write connection message and read reply */
292
 
    if (net_write_command(net, (unsigned char) protocol_version, (unsigned char*) "", 0,
293
 
                          (unsigned char*) buff, (size_t) (end-buff)) ||
294
 
        (pkt_len= my_net_read(net)) == packet_error ||
295
 
        pkt_len < MIN_HANDSHAKE_SIZE)
296
 
    {
297
 
      my_error(ER_HANDSHAKE_ERROR, MYF(0),
298
 
               session->main_security_ctx.ip);
299
 
      return 1;
300
 
    }
301
 
  }
302
 
  if (session->packet.alloc(session->variables.net_buffer_length))
303
 
    return 1; /* The error is set by alloc(). */
304
 
 
305
 
  session->client_capabilities= uint2korr(net->read_pos);
306
 
 
307
 
 
308
 
  session->client_capabilities|= ((uint32_t) uint2korr(net->read_pos+2)) << 16;
309
 
  session->max_client_packet_length= uint4korr(net->read_pos+4);
310
 
  session_init_client_charset(session, (uint) net->read_pos[8]);
311
 
  session->update_charset();
312
 
  end= (char*) net->read_pos+32;
313
 
 
314
 
  /*
315
 
    Disable those bits which are not supported by the server.
316
 
    This is a precautionary measure, if the client lies. See Bug#27944.
317
 
  */
318
 
  session->client_capabilities&= server_capabilites;
319
 
 
320
 
  if (end >= (char*) net->read_pos+ pkt_len +2)
321
 
  {
322
 
 
323
 
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->main_security_ctx.ip);
324
 
    return 1;
325
 
  }
326
 
 
327
 
  if (session->client_capabilities & CLIENT_INTERACTIVE)
328
 
    session->variables.net_wait_timeout= session->variables.net_interactive_timeout;
329
 
  if ((session->client_capabilities & CLIENT_TRANSACTIONS) &&
330
 
      opt_using_transactions)
331
 
    net->return_status= &session->server_status;
332
 
 
333
 
  char *user= end;
334
 
  char *passwd= strchr(user, '\0')+1;
335
 
  uint32_t user_len= passwd - user - 1;
336
 
  char *db= passwd;
337
 
  char db_buff[NAME_LEN + 1];           // buffer to store db in utf8
338
 
  char user_buff[USERNAME_LENGTH + 1];  // buffer to store user in utf8
339
 
  uint32_t dummy_errors;
340
 
 
341
 
  /*
342
 
    Old clients send null-terminated string as password; new clients send
343
 
    the size (1 byte) + string (not null-terminated). Hence in case of empty
344
 
    password both send '\0'.
345
 
 
346
 
    This strlen() can't be easily deleted without changing protocol.
347
 
 
348
 
    Cast *passwd to an unsigned char, so that it doesn't extend the sign for
349
 
    *passwd > 127 and become 2**32-127+ after casting to uint.
350
 
  */
351
 
  uint32_t passwd_len= session->client_capabilities & CLIENT_SECURE_CONNECTION ?
352
 
    (unsigned char)(*passwd++) : strlen(passwd);
353
 
  db= session->client_capabilities & CLIENT_CONNECT_WITH_DB ?
354
 
    db + passwd_len + 1 : 0;
355
 
  /* strlen() can't be easily deleted without changing protocol */
356
 
  uint32_t db_len= db ? strlen(db) : 0;
357
 
 
358
 
  if (passwd + passwd_len + db_len > (char *)net->read_pos + pkt_len)
359
 
  {
360
 
    my_error(ER_HANDSHAKE_ERROR, MYF(0), session->main_security_ctx.ip);
361
 
    return 1;
362
 
  }
363
 
 
364
 
  /* Since 4.1 all database names are stored in utf8 */
365
 
  if (db)
366
 
  {
367
 
    db_buff[copy_and_convert(db_buff, sizeof(db_buff)-1,
368
 
                             system_charset_info,
369
 
                             db, db_len,
370
 
                             session->charset(), &dummy_errors)]= 0;
371
 
    db= db_buff;
372
 
  }
373
 
 
374
 
  user_buff[user_len= copy_and_convert(user_buff, sizeof(user_buff)-1,
375
 
                                       system_charset_info, user, user_len,
376
 
                                       session->charset(), &dummy_errors)]= '\0';
377
 
  user= user_buff;
378
 
 
379
 
  /* If username starts and ends in "'", chop them off */
380
 
  if (user_len > 1 && user[0] == '\'' && user[user_len - 1] == '\'')
381
 
  {
382
 
    user[user_len-1]= 0;
383
 
    user++;
384
 
    user_len-= 2;
385
 
  }
386
 
 
387
 
  if (session->main_security_ctx.user)
388
 
    if (session->main_security_ctx.user)
389
 
      free(session->main_security_ctx.user);
390
 
  if (!(session->main_security_ctx.user= my_strdup(user, MYF(MY_WME))))
391
 
    return 1; /* The error is set by my_strdup(). */
392
 
  return check_user(session, passwd, passwd_len, db, true);
393
 
}
394
 
 
395
 
 
396
 
/*
397
 
  Setup thread to be used with the current thread
398
 
 
399
 
  SYNOPSIS
400
 
    bool setup_connection_thread_globals()
401
 
    session    Thread/connection handler
402
 
 
403
 
  RETURN
404
 
    0   ok
405
 
    1   Error (out of memory)
406
 
        In this case we will close the connection and increment status
407
 
*/
408
 
 
409
 
bool setup_connection_thread_globals(Session *session)
410
 
{
411
 
  if (session->store_globals())
412
 
  {
413
 
    close_connection(session, ER_OUT_OF_RESOURCES, 1);
414
 
    statistic_increment(aborted_connects,&LOCK_status);
415
 
    thread_scheduler.end_thread(session, 0);
416
 
    return 1;                                   // Error
417
 
  }
418
 
  return 0;
419
 
}
420
 
 
421
 
 
422
 
/*
423
 
  Autenticate user, with error reporting
424
 
 
425
 
  SYNOPSIS
426
 
   login_connection()
427
 
   session        Thread handler
428
 
 
429
 
  NOTES
430
 
    Connection is not closed in case of errors
431
 
 
432
 
  RETURN
433
 
    0    ok
434
 
    1    error
435
 
*/
436
 
 
437
 
 
438
 
bool login_connection(Session *session)
439
 
{
440
 
  NET *net= &session->net;
441
 
  int error;
442
 
 
443
 
  /* Use "connect_timeout" value during connection phase */
444
 
  my_net_set_read_timeout(net, connect_timeout);
445
 
  my_net_set_write_timeout(net, connect_timeout);
446
 
  
447
 
  lex_start(session);
448
 
 
449
 
  error= check_connection(session);
450
 
  net_end_statement(session);
451
 
 
452
 
  if (error)
453
 
  {                                             // Wrong permissions
454
 
    statistic_increment(aborted_connects,&LOCK_status);
455
 
    return(1);
456
 
  }
457
 
  /* Connect completed, set read/write timeouts back to default */
458
 
  my_net_set_read_timeout(net, session->variables.net_read_timeout);
459
 
  my_net_set_write_timeout(net, session->variables.net_write_timeout);
460
 
  return(0);
461
 
}
462
 
 
463
 
 
464
 
/*
465
 
  Close an established connection
466
 
 
467
 
  NOTES
468
 
    This mainly updates status variables
469
 
*/
470
 
 
471
 
void end_connection(Session *session)
472
 
{
473
 
  NET *net= &session->net;
474
 
  plugin_sessionvar_cleanup(session);
475
 
 
476
 
  if (session->killed || (net->error && net->vio != 0))
477
 
  {
478
 
    statistic_increment(aborted_threads,&LOCK_status);
479
 
  }
480
 
 
481
 
  if (net->error && net->vio != 0)
482
 
  {
483
 
    if (!session->killed && session->variables.log_warnings > 1)
484
 
    {
485
 
      Security_context *sctx= session->security_ctx;
486
 
 
487
 
      sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION),
488
 
                        session->thread_id,(session->db ? session->db : "unconnected"),
489
 
                        sctx->user ? sctx->user : "unauthenticated",
490
 
                        sctx->ip,
491
 
                        (session->main_da.is_error() ? session->main_da.message() :
492
 
                         ER(ER_UNKNOWN_ERROR)));
493
 
    }
494
 
  }
495
 
}
496
 
 
497
 
 
498
 
/*
499
 
  Initialize Session to handle queries
500
 
*/
501
 
 
502
 
void prepare_new_connection_state(Session* session)
503
 
{
504
 
  Security_context *sctx= session->security_ctx;
505
 
 
506
 
  if (session->variables.max_join_size == HA_POS_ERROR)
507
 
    session->options |= OPTION_BIG_SELECTS;
508
 
  if (session->client_capabilities & CLIENT_COMPRESS)
509
 
    session->net.compress=1;                            // Use compression
510
 
 
511
 
  /*
512
 
    Much of this is duplicated in create_embedded_session() for the
513
 
    embedded server library.
514
 
    TODO: refactor this to avoid code duplication there
515
 
  */
516
 
  session->version= refresh_version;
517
 
  session->set_proc_info(0);
518
 
  session->command= COM_SLEEP;
519
 
  session->set_time();
520
 
  session->init_for_queries();
521
 
 
522
 
  /* In the past this would only run of the user did not have SUPER_ACL */
523
 
  if (sys_init_connect.value_length)
524
 
  {
525
 
    execute_init_command(session, &sys_init_connect, &LOCK_sys_init_connect);
526
 
    if (session->is_error())
527
 
    {
528
 
      session->killed= Session::KILL_CONNECTION;
529
 
      sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION),
530
 
                        session->thread_id,(session->db ? session->db : "unconnected"),
531
 
                        sctx->user ? sctx->user : "unauthenticated",
532
 
                        sctx->ip, "init_connect command failed");
533
 
      sql_print_warning("%s", session->main_da.message());
534
 
    }
535
 
    session->set_proc_info(0);
536
 
    session->set_time();
537
 
    session->init_for_queries();
538
 
  }
539
 
}
540
 
 
541
 
 
542
 
/*
543
 
  Thread handler for a connection
544
 
 
545
 
  SYNOPSIS
546
 
    handle_one_connection()
547
 
    arg         Connection object (Session)
548
 
 
549
 
  IMPLEMENTATION
550
 
    This function (normally) does the following:
551
 
    - Initialize thread
552
 
    - Initialize Session to be used with this thread
553
 
    - Authenticate user
554
 
    - Execute all queries sent on the connection
555
 
    - Take connection down
556
 
    - End thread  / Handle next connection using thread from thread cache
557
 
*/
558
 
 
559
 
pthread_handler_t handle_one_connection(void *arg)
560
 
{
561
 
  Session *session= (Session*) arg;
562
 
  uint32_t launch_time= (uint32_t) ((session->thr_create_utime= my_micro_time()) -
563
 
                              session->connect_utime);
564
 
 
565
 
  if (thread_scheduler.init_new_connection_thread())
566
 
  {
567
 
    close_connection(session, ER_OUT_OF_RESOURCES, 1);
568
 
    statistic_increment(aborted_connects,&LOCK_status);
569
 
    thread_scheduler.end_thread(session,0);
570
 
    return 0;
571
 
  }
572
 
  if (launch_time >= slow_launch_time*1000000L)
573
 
    statistic_increment(slow_launch_threads,&LOCK_status);
574
 
 
575
 
  /*
576
 
    handle_one_connection() is normally the only way a thread would
577
 
    start and would always be on the very high end of the stack ,
578
 
    therefore, the thread stack always starts at the address of the
579
 
    first local variable of handle_one_connection, which is session. We
580
 
    need to know the start of the stack so that we could check for
581
 
    stack overruns.
582
 
  */
583
 
  session->thread_stack= (char*) &session;
584
 
  if (setup_connection_thread_globals(session))
585
 
    return 0;
586
 
 
587
 
  for (;;)
588
 
  {
589
 
    NET *net= &session->net;
590
 
 
591
 
    if (login_connection(session))
592
 
      goto end_thread;
593
 
 
594
 
    prepare_new_connection_state(session);
595
 
 
596
 
    while (!net->error && net->vio != 0 &&
597
 
           !(session->killed == Session::KILL_CONNECTION))
598
 
    {
599
 
      if (do_command(session))
600
 
        break;
601
 
    }
602
 
    end_connection(session);
603
 
   
604
 
end_thread:
605
 
    close_connection(session, 0, 1);
606
 
    if (thread_scheduler.end_thread(session,1))
607
 
      return 0;                                 // Probably no-threads
608
 
 
609
 
    /*
610
 
      If end_thread() returns, we are either running with
611
 
      thread-handler=no-threads or this thread has been schedule to
612
 
      handle the next connection.
613
 
    */
614
 
    session= current_session;
615
 
    session->thread_stack= (char*) &session;
616
 
  }
617
 
}