~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/sql_connect.cc

  • Committer: Brian Aker
  • Date: 2008-07-10 19:37:55 UTC
  • mfrom: (51.1.67 remove-dbug)
  • Revision ID: brian@tangent.org-20080710193755-f5g761uieqa3wxmt
Merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
                         NULL, 0, NI_NUMERICHOST);
40
40
  if (gxi_error)
41
41
  {
42
 
    DBUG_PRINT("error",("getnameinfo returned %d", gxi_error));
43
42
    return NULL;
44
43
  }
45
 
  DBUG_PRINT("info",("resolved: %s", hostname_buff));
46
44
 
47
45
  if (!(name= my_strdup(hostname_buff, MYF(0))))
48
46
  {
49
 
    DBUG_PRINT("error",("out of memory"));
50
47
    return NULL;
51
48
  }
52
49
 
63
60
  @param  passwd      scrambled password received from client
64
61
  @param  passwd_len  length of scrambled password
65
62
  @param  db          database name to connect to, may be NULL
66
 
  @param  check_count TRUE if establishing a new connection. In this case
 
63
  @param  check_count true if establishing a new connection. In this case
67
64
                      check that we have not exceeded the global
68
65
                      max_connections limist
69
66
 
84
81
           uint passwd_len, const char *db,
85
82
           bool check_count)
86
83
{
87
 
  DBUG_ENTER("check_user");
88
84
  LEX_STRING db_str= { (char *) db, db ? strlen(db) : 0 };
89
85
 
90
86
  /*
108
104
  {
109
105
    my_error(ER_NOT_SUPPORTED_AUTH_MODE, MYF(0));
110
106
    general_log_print(thd, COM_CONNECT, ER(ER_NOT_SUPPORTED_AUTH_MODE));
111
 
    DBUG_RETURN(1);
 
107
    return(1);
112
108
  }
113
109
  if (passwd_len != 0 &&
114
110
      passwd_len != SCRAMBLE_LENGTH &&
115
111
      passwd_len != SCRAMBLE_LENGTH_323)
116
112
  {
117
113
    my_error(ER_HANDSHAKE_ERROR, MYF(0), thd->main_security_ctx.host_or_ip);
118
 
    DBUG_RETURN(1);
 
114
    return(1);
119
115
  }
120
116
 
121
117
  USER_RESOURCES ur;
122
118
  thd->security_ctx->skip_grants();
123
119
  memset(&ur, 0, sizeof(USER_RESOURCES));
124
120
 
125
 
  DBUG_PRINT("info",
126
 
             ("Capabilities: %lu  packet_length: %ld  Host: '%s'  "
127
 
              "Login user: '%s' Priv_user: '%s'  Using password: %s "
128
 
              "db: '%s'",
129
 
              thd->client_capabilities,
130
 
              thd->max_client_packet_length,
131
 
              thd->main_security_ctx.host_or_ip,
132
 
              thd->main_security_ctx.user,
133
 
              thd->main_security_ctx.priv_user,
134
 
              passwd_len ? "yes": "no",
135
 
              (thd->db ? thd->db : "*none*")));
136
 
 
137
121
  if (check_count)
138
122
  {
139
123
    pthread_mutex_lock(&LOCK_connection_count);
143
127
    if (!count_ok)
144
128
    {                                         // too many connections
145
129
      my_error(ER_CON_COUNT_ERROR, MYF(0));
146
 
      DBUG_RETURN(1);
 
130
      return(1);
147
131
    }
148
132
  }
149
133
 
171
155
  /* Change database if necessary */
172
156
  if (db && db[0])
173
157
  {
174
 
    if (mysql_change_db(thd, &db_str, FALSE))
 
158
    if (mysql_change_db(thd, &db_str, false))
175
159
    {
176
160
      /* mysql_change_db() has pushed the error message. */
177
 
      DBUG_RETURN(1);
 
161
      return(1);
178
162
    }
179
163
  }
180
164
  my_ok(thd);
181
165
  thd->password= test(passwd_len);          // remember for error messages 
182
166
  /* Ready to handle queries */
183
 
  DBUG_RETURN(0);
 
167
  return(0);
184
168
}
185
169
 
186
170
 
265
249
  ulong pkt_len= 0;
266
250
  char *end;
267
251
 
268
 
  DBUG_PRINT("info",
269
 
             ("New connection received on %s", vio_description(net->vio)));
270
252
#ifdef SIGNAL_WITH_VIO_CLOSE
271
253
  thd->set_active_vio(net->vio);
272
254
#endif
286
268
    thd->main_security_ctx.host= ip_to_hostname(&net->vio->remote, 
287
269
                                                net->vio->addrLen);
288
270
    thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
289
 
    DBUG_PRINT("info",("Host: %s  ip: %s",
290
 
                       (thd->main_security_ctx.host ?
291
 
                        thd->main_security_ctx.host : "unknown host"),
292
 
                       (thd->main_security_ctx.ip ?
293
 
                        thd->main_security_ctx.ip : "unknown ip")));
294
271
  }
295
272
  else /* Hostname given means that the connection was on a socket */
296
273
  {
297
 
    DBUG_PRINT("info",("Host: %s", thd->main_security_ctx.host));
298
274
    thd->main_security_ctx.host_or_ip= thd->main_security_ctx.host;
299
275
    thd->main_security_ctx.ip= 0;
300
276
    /* Reset sin_addr */
301
277
    bzero((char*) &net->vio->remote, sizeof(net->vio->remote));
302
278
  }
303
 
  vio_keepalive(net->vio, TRUE);
 
279
  vio_keepalive(net->vio, true);
304
280
  
305
281
  ulong server_capabilites;
306
282
  {
362
338
  {
363
339
    thd->client_capabilities|= ((ulong) uint2korr(net->read_pos+2)) << 16;
364
340
    thd->max_client_packet_length= uint4korr(net->read_pos+4);
365
 
    DBUG_PRINT("info", ("client_character_set: %d", (uint) net->read_pos[8]));
366
341
    thd_init_client_charset(thd, (uint) net->read_pos[8]);
367
342
    thd->update_charset();
368
343
    end= (char*) net->read_pos+32;
452
427
    x_free(thd->main_security_ctx.user);
453
428
  if (!(thd->main_security_ctx.user= my_strdup(user, MYF(MY_WME))))
454
429
    return 1; /* The error is set by my_strdup(). */
455
 
  return check_user(thd, COM_CONNECT, passwd, passwd_len, db, TRUE);
 
430
  return check_user(thd, COM_CONNECT, passwd, passwd_len, db, true);
456
431
}
457
432
 
458
433
 
502
477
{
503
478
  NET *net= &thd->net;
504
479
  int error;
505
 
  DBUG_ENTER("login_connection");
506
 
  DBUG_PRINT("info", ("login_connection called by thread %lu",
507
 
                      thd->thread_id));
508
480
 
509
481
  /* Use "connect_timeout" value during connection phase */
510
482
  my_net_set_read_timeout(net, connect_timeout);
518
490
  if (error)
519
491
  {                                             // Wrong permissions
520
492
    statistic_increment(aborted_connects,&LOCK_status);
521
 
    DBUG_RETURN(1);
 
493
    return(1);
522
494
  }
523
495
  /* Connect completed, set read/write timeouts back to default */
524
496
  my_net_set_read_timeout(net, thd->variables.net_read_timeout);
525
497
  my_net_set_write_timeout(net, thd->variables.net_write_timeout);
526
 
  DBUG_RETURN(0);
 
498
  return(0);
527
499
}
528
500
 
529
501