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
1=== modified file 'client/drizzle.cc'
2--- client/drizzle.cc 2011-03-14 11:43:13 +0000
3+++ client/drizzle.cc 2011-04-19 18:13:25 +0000
4@@ -154,6 +154,8 @@
5 #include <boost/scoped_ptr.hpp>
6 #include <drizzled/program_options/config_file.h>
7
8+#include "user_detect.h"
9+
10 using namespace std;
11 namespace po=boost::program_options;
12 namespace dpo=drizzled::program_options;
13@@ -1474,7 +1476,8 @@
14 _("Automatic limit for rows in a join when using --safe-updates"))
15 ;
16 #ifndef DRIZZLE_ADMIN_TOOL
17- const char* unix_user= getlogin();
18+ UserDetect *detected_user= new UserDetect();
19+ const char* shell_user= detected_user->getUser();
20 #endif
21 po::options_description client_options(_("Options specific to the client"));
22 client_options.add_options()
23@@ -1487,7 +1490,7 @@
24 #ifdef DRIZZLE_ADMIN_TOOL
25 ("user,u", po::value<string>(&current_user)->default_value("root"),
26 #else
27- ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),
28+ ("user,u", po::value<string>(&current_user)->default_value(shell_user ? shell_user : ""),
29 #endif
30 _("User for login if not current user."))
31 ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
32
33=== modified file 'client/drizzledump.cc'
34--- client/drizzledump.cc 2011-03-04 23:41:25 +0000
35+++ client/drizzledump.cc 2011-04-19 18:13:25 +0000
36@@ -48,6 +48,8 @@
37 #include "drizzledump_mysql.h"
38 #include "drizzledump_drizzle.h"
39
40+#include "user_detect.h"
41+
42 using namespace std;
43 using namespace drizzled;
44 namespace po= boost::program_options;
45@@ -533,7 +535,8 @@
46 _("Do not make a UTF8 connection to MySQL, use if you have UTF8 data in a non-UTF8 table"))
47 ;
48
49- const char* unix_user= getlogin();
50+ UserDetect *detected_user= new UserDetect();
51+ const char* shell_user= detected_user->getUser();
52
53 po::options_description client_options(_("Options specific to the client"));
54 client_options.add_options()
55@@ -543,7 +546,7 @@
56 _("Password to use when connecting to server. If password is not given it's solicited on the tty."))
57 ("port,p", po::value<uint32_t>(&opt_drizzle_port)->default_value(0),
58 _("Port number to use for connection."))
59- ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),
60+ ("user,u", po::value<string>(&current_user)->default_value((shell_user ? shell_user : "")),
61 _("User for login if not current user."))
62 ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
63 _("The protocol of connection (mysql or drizzle)."))
64
65=== modified file 'client/drizzleimport.cc'
66--- client/drizzleimport.cc 2011-03-03 22:12:08 +0000
67+++ client/drizzleimport.cc 2011-04-19 18:13:25 +0000
68@@ -31,6 +31,8 @@
69 #include <drizzled/gettext.h>
70 #include <drizzled/configmake.h>
71
72+#include "user_detect.h"
73+
74 namespace po= boost::program_options;
75 using namespace std;
76 using namespace drizzled;
77@@ -397,7 +399,8 @@
78 "Load files in parallel. The argument is the number of threads to use for loading data (default is 4.")
79 ;
80
81- const char* unix_user= getlogin();
82+ UserDetect *detected_user= new UserDetect();
83+ const char* shell_user= detected_user->getUser();
84
85 po::options_description client_options("Options specific to the client");
86 client_options.add_options()
87@@ -409,7 +412,7 @@
88 "Port number to use for connection")
89 ("protocol", po::value<string>(&opt_protocol)->default_value("mysql"),
90 "The protocol of connection (mysql or drizzle).")
91- ("user,u", po::value<string>(&current_user)->default_value((unix_user ? unix_user : "")),
92+ ("user,u", po::value<string>(&current_user)->default_value((shell_user ? shell_user : "")),
93 "User for login if not current user.")
94 ;
95
96
97=== modified file 'client/include.am'
98--- client/include.am 2011-02-21 13:59:06 +0000
99+++ client/include.am 2011-04-19 18:13:25 +0000
100@@ -58,6 +58,7 @@
101 client/statement.h \
102 client/stats.h \
103 client/thread_context.h \
104+ client/user_detect.h \
105 client/wakeup.h
106
107 client_drizzle_SOURCES= client/drizzle.cc client/linebuffer.cc
108
109=== added file 'client/user_detect.h'
110--- client/user_detect.h 1970-01-01 00:00:00 +0000
111+++ client/user_detect.h 2011-04-19 18:13:25 +0000
112@@ -0,0 +1,62 @@
113+/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
114+ * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
115+ *
116+ * Copyright (C) 2011 Andrew Hutchings
117+ *
118+ * This program is free software; you can redistribute it and/or modify
119+ * it under the terms of the GNU General Public License as published by
120+ * the Free Software Foundation; version 2 of the License.
121+ *
122+ * This program is distributed in the hope that it will be useful,
123+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
124+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
125+ * GNU General Public License for more details.
126+ *
127+ * You should have received a copy of the GNU General Public License
128+ * along with this program; if not, write to the Free Software
129+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
130+ */
131+
132+#ifndef CLIENT_USER_DETECT_H
133+#define CLIENT_USER_DETECT_H
134+
135+#include <unistd.h>
136+#include <pwd.h>
137+#include <cstring>
138+
139+class UserDetect
140+{
141+ public:
142+ const char* getUser() { return user; }
143+
144+ UserDetect() :
145+ user(NULL)
146+ {
147+ long pw_len= sysconf(_SC_GETPW_R_SIZE_MAX);
148+ struct passwd pw_struct;
149+ struct passwd* pw_tmp_struct;
150+ char *pw_buffer= new char[pw_len];
151+
152+ if (getpwuid_r(geteuid(), &pw_struct, pw_buffer, pw_len, &pw_tmp_struct) != 0)
153+ {
154+ user= NULL;
155+ }
156+ else
157+ {
158+ user= new char[strlen(pw_struct.pw_name)];
159+ strcpy(user, pw_struct.pw_name);
160+ }
161+
162+ delete[] pw_buffer;
163+ }
164+
165+ ~UserDetect()
166+ {
167+ delete[] user;
168+ }
169+
170+ private:
171+ char* user;
172+};
173+
174+#endif /* CLIENT_USER_DETECT_H */
175
176=== modified file 'plugin/console/console.cc'
177--- plugin/console/console.cc 2011-03-14 15:00:51 +0000
178+++ plugin/console/console.cc 2011-04-19 18:13:25 +0000
179@@ -27,6 +27,8 @@
180
181 #include <boost/program_options.hpp>
182
183+#include <client/user_detect.h>
184+
185 using namespace std;
186 using namespace drizzled;
187
188@@ -386,8 +388,10 @@
189 context("debug",
190 po::value<bool>(&debug_enabled)->default_value(false)->zero_tokens(),
191 N_("Turn on extra debugging."));
192+ UserDetect *detected_user= new UserDetect();
193+ const char* shell_user= detected_user->getUser();
194 context("username",
195- po::value<string>(),
196+ po::value<string>()->default_value(shell_user ? shell_user : ""),
197 N_("User to use for auth."));
198 context("password",
199 po::value<string>(),

Subscribers

People subscribed via source and target branches