Merge lp:~linuxjedi/drizzle/elliott-bug-743902 into lp:drizzle/7.0

Proposed by Andrew Hutchings
Status: Merged
Merged at revision: 2245
Proposed branch: lp:~linuxjedi/drizzle/elliott-bug-743902
Merge into: lp:drizzle/7.0
Diff against target: 199 lines (+83/-7)
6 files modified
client/drizzle.cc (+5/-2)
client/drizzledump.cc (+5/-2)
client/drizzleimport.cc (+5/-2)
client/include.am (+1/-0)
client/user_detect.h (+62/-0)
plugin/console/console.cc (+5/-1)
To merge this branch: bzr merge lp:~linuxjedi/drizzle/elliott-bug-743902
Reviewer Review Type Date Requested Status
Stewart Smith (community) Approve
Review via email: mp+58367@code.launchpad.net

Description of the change

Backport bug fix from trunk

To post a comment you must log in.
Revision history for this message
Stewart Smith (stewart) wrote :

looks good

review: Approve
Revision history for this message
Andrew Hutchings (linuxjedi) wrote :

Valgrind warnings need fixing here too

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'client/drizzle.cc'
--- client/drizzle.cc 2011-03-14 11:43:13 +0000
+++ client/drizzle.cc 2011-04-19 18:13:25 +0000
@@ -154,6 +154,8 @@
154#include <boost/scoped_ptr.hpp>154#include <boost/scoped_ptr.hpp>
155#include <drizzled/program_options/config_file.h>155#include <drizzled/program_options/config_file.h>
156156
157#include "user_detect.h"
158
157using namespace std;159using namespace std;
158namespace po=boost::program_options;160namespace po=boost::program_options;
159namespace dpo=drizzled::program_options;161namespace dpo=drizzled::program_options;
@@ -1474,7 +1476,8 @@
1474 _("Automatic limit for rows in a join when using --safe-updates"))1476 _("Automatic limit for rows in a join when using --safe-updates"))
1475 ;1477 ;
1476#ifndef DRIZZLE_ADMIN_TOOL1478#ifndef DRIZZLE_ADMIN_TOOL
1477 const char* unix_user= getlogin();1479 UserDetect *detected_user= new UserDetect();
1480 const char* shell_user= detected_user->getUser();
1478#endif1481#endif
1479 po::options_description client_options(_("Options specific to the client"));1482 po::options_description client_options(_("Options specific to the client"));
1480 client_options.add_options()1483 client_options.add_options()
@@ -1487,7 +1490,7 @@
1487#ifdef DRIZZLE_ADMIN_TOOL1490#ifdef DRIZZLE_ADMIN_TOOL
1488 ("user,u", po::value<string>(&current_user)->default_value("root"),1491 ("user,u", po::value<string>(&current_user)->default_value("root"),
1489#else1492#else
1490 ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),1493 ("user,u", po::value<string>(&current_user)->default_value(shell_user ? shell_user : ""),
1491#endif1494#endif
1492 _("User for login if not current user."))1495 _("User for login if not current user."))
1493 ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),1496 ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
14941497
=== modified file 'client/drizzledump.cc'
--- client/drizzledump.cc 2011-03-04 23:41:25 +0000
+++ client/drizzledump.cc 2011-04-19 18:13:25 +0000
@@ -48,6 +48,8 @@
48#include "drizzledump_mysql.h"48#include "drizzledump_mysql.h"
49#include "drizzledump_drizzle.h"49#include "drizzledump_drizzle.h"
5050
51#include "user_detect.h"
52
51using namespace std;53using namespace std;
52using namespace drizzled;54using namespace drizzled;
53namespace po= boost::program_options;55namespace po= boost::program_options;
@@ -533,7 +535,8 @@
533 _("Do not make a UTF8 connection to MySQL, use if you have UTF8 data in a non-UTF8 table"))535 _("Do not make a UTF8 connection to MySQL, use if you have UTF8 data in a non-UTF8 table"))
534 ;536 ;
535537
536 const char* unix_user= getlogin();538 UserDetect *detected_user= new UserDetect();
539 const char* shell_user= detected_user->getUser();
537540
538 po::options_description client_options(_("Options specific to the client"));541 po::options_description client_options(_("Options specific to the client"));
539 client_options.add_options()542 client_options.add_options()
@@ -543,7 +546,7 @@
543 _("Password to use when connecting to server. If password is not given it's solicited on the tty."))546 _("Password to use when connecting to server. If password is not given it's solicited on the tty."))
544 ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),547 ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
545 _("Port number to use for connection."))548 _("Port number to use for connection."))
546 ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),549 ("user,u", po::value<string>(&current_user)->default_value((shell_user ? shell_user : "")),
547 _("User for login if not current user."))550 _("User for login if not current user."))
548 ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),551 ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
549 _("The protocol of connection (mysql or drizzle)."))552 _("The protocol of connection (mysql or drizzle)."))
550553
=== modified file 'client/drizzleimport.cc'
--- client/drizzleimport.cc 2011-03-03 22:12:08 +0000
+++ client/drizzleimport.cc 2011-04-19 18:13:25 +0000
@@ -31,6 +31,8 @@
31#include <drizzled/gettext.h>31#include <drizzled/gettext.h>
32#include <drizzled/configmake.h>32#include <drizzled/configmake.h>
3333
34#include "user_detect.h"
35
34namespace po= boost::program_options;36namespace po= boost::program_options;
35using namespace std;37using namespace std;
36using namespace drizzled;38using namespace drizzled;
@@ -397,7 +399,8 @@
397 "Load files in parallel. The argument is the number of threads to use for loading data (default is 4.")399 "Load files in parallel. The argument is the number of threads to use for loading data (default is 4.")
398 ;400 ;
399401
400 const char* unix_user= getlogin();402 UserDetect *detected_user= new UserDetect();
403 const char* shell_user= detected_user->getUser();
401404
402 po::options_description client_options("Options specific to the client");405 po::options_description client_options("Options specific to the client");
403 client_options.add_options()406 client_options.add_options()
@@ -409,7 +412,7 @@
409 "Port number to use for connection") 412 "Port number to use for connection")
410 ("protocol", po::value<string>(&opt_protocol)->default_value("mysql"),413 ("protocol", po::value<string>(&opt_protocol)->default_value("mysql"),
411 "The protocol of connection (mysql or drizzle).")414 "The protocol of connection (mysql or drizzle).")
412 ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),415 ("user,u", po::value<string>(&current_user)->default_value((shell_user ? shell_user : "")),
413 "User for login if not current user.")416 "User for login if not current user.")
414 ;417 ;
415418
416419
=== modified file 'client/include.am'
--- client/include.am 2011-02-21 13:59:06 +0000
+++ client/include.am 2011-04-19 18:13:25 +0000
@@ -58,6 +58,7 @@
58 client/statement.h \58 client/statement.h \
59 client/stats.h \59 client/stats.h \
60 client/thread_context.h \60 client/thread_context.h \
61 client/user_detect.h \
61 client/wakeup.h62 client/wakeup.h
6263
63client_drizzle_SOURCES= client/drizzle.cc client/linebuffer.cc64client_drizzle_SOURCES= client/drizzle.cc client/linebuffer.cc
6465
=== added file 'client/user_detect.h'
--- client/user_detect.h 1970-01-01 00:00:00 +0000
+++ client/user_detect.h 2011-04-19 18:13:25 +0000
@@ -0,0 +1,62 @@
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2011 Andrew Hutchings
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#ifndef CLIENT_USER_DETECT_H
21#define CLIENT_USER_DETECT_H
22
23#include <unistd.h>
24#include <pwd.h>
25#include <cstring>
26
27class UserDetect
28{
29 public:
30 const char* getUser() { return user; }
31
32 UserDetect() :
33 user(NULL)
34 {
35 long pw_len= sysconf(_SC_GETPW_R_SIZE_MAX);
36 struct passwd pw_struct;
37 struct passwd* pw_tmp_struct;
38 char *pw_buffer= new char[pw_len];
39
40 if (getpwuid_r(geteuid(), &pw_struct, pw_buffer, pw_len, &pw_tmp_struct) != 0)
41 {
42 user= NULL;
43 }
44 else
45 {
46 user= new char[strlen(pw_struct.pw_name)];
47 strcpy(user, pw_struct.pw_name);
48 }
49
50 delete[] pw_buffer;
51 }
52
53 ~UserDetect()
54 {
55 delete[] user;
56 }
57
58 private:
59 char* user;
60};
61
62#endif /* CLIENT_USER_DETECT_H */
063
=== modified file 'plugin/console/console.cc'
--- plugin/console/console.cc 2011-03-14 15:00:51 +0000
+++ plugin/console/console.cc 2011-04-19 18:13:25 +0000
@@ -27,6 +27,8 @@
2727
28#include <boost/program_options.hpp>28#include <boost/program_options.hpp>
2929
30#include <client/user_detect.h>
31
30using namespace std;32using namespace std;
31using namespace drizzled;33using namespace drizzled;
3234
@@ -386,8 +388,10 @@
386 context("debug",388 context("debug",
387 po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),389 po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
388 N_("Turn on extra debugging."));390 N_("Turn on extra debugging."));
391 UserDetect *detected_user= new UserDetect();
392 const char* shell_user= detected_user->getUser();
389 context("username",393 context("username",
390 po::value<string>(),394 po::value<string>()->default_value(shell_user ? shell_user : ""),
391 N_("User to use for auth."));395 N_("User to use for auth."));
392 context("password",396 context("password",
393 po::value<string>(),397 po::value<string>(),

Subscribers

People subscribed via source and target branches