Skip to content

Commit b0ef3ee

Browse files
committed
monet-explorer
1 parent 4074d59 commit b0ef3ee

File tree

5 files changed

+55
-40
lines changed

5 files changed

+55
-40
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
monet-explorer
22
monet-explorer-dbg
3+
core
4+
vgcore.*

protocol_doc/monet-explorer/Client.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,13 @@ namespace MonetExplorer {
151151
Connect to the server
152152
*/
153153
if (args.IsOptionSet("unix-domain-socket")) {
154-
std::cout << "\033[32mConnecting through Unix domain socket.\033[0m\n";
154+
std::string socketFilePath("/tmp/.s.monetdb." + std::to_string(args.GetIntValue("port")));
155+
std::cout << "\033[32mConnecting through Unix domain socket to " << socketFilePath << ".\033[0m\n";
155156

156-
this->connection.ConnectUnix(
157-
args.GetIntValue("port")
158-
);
157+
this->connection.ConnectUnix(socketFilePath);
158+
159+
std::cout << "\033[32mSending the init byte 0x30 ('0') to the server.\033[0m\n";
160+
this->connection.SendUnixDomainSocketInitByte();
159161
} else {
160162
std::cout << "\033[32mConnecting through TCP/IP to: " << args.GetStringValue("host") << ':'
161163
<< args.GetIntValue("port") << "\033[0m\n";

protocol_doc/monet-explorer/Connection.hpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,20 @@ namespace MonetExplorer {
139139
return;
140140
}
141141

142-
// Close the outgoing channel
143-
shutdown(this->clientSocket, SHUT_WR);
142+
if (clientSocket > -1) {
143+
// Close the outgoing channel
144+
shutdown(this->clientSocket, SHUT_WR);
144145

145-
/*
146-
After the server noticed that the client
147-
closed its outgoing channel, it will also
148-
do so. Read until that is detected.
149-
*/
150-
while(this->ReadExact(BUFFER_SIZE, false) > 0);
151-
close(this->clientSocket);
146+
/*
147+
After the server noticed that the client
148+
closed its outgoing channel, it will also
149+
do so. Read until that is detected.
150+
*/
151+
while(this->ReadExact(BUFFER_SIZE, false) > 0);
152+
close(this->clientSocket);
153+
}
152154

155+
this->clientSocket = -1;
153156
this->connected = false;
154157
}
155158

@@ -193,11 +196,11 @@ namespace MonetExplorer {
193196
* @brief Connect to the server though Unix
194197
* domain socket.
195198
*
196-
* @param port The port of the server is part of the
197-
* name of the files which represent these sockets.
198-
* Therefore it's required for finding the files.
199+
* @param socketFilePath The path to the socket file.
200+
* It ends with the port of the server. Typical value
201+
* is: "/tmp/.s.monetdb.50000"
199202
*/
200-
void ConnectUnix(int port) {
203+
void ConnectUnix(std::string socketFilePath) {
201204
if (this->connected) {
202205
throw std::runtime_error("Connection::ConnectUnix(): Already connected to the server. "
203206
"(Method is called twice.)");
@@ -209,31 +212,31 @@ namespace MonetExplorer {
209212
+ "' (" + std::to_string(errno) + ")");
210213
}
211214

212-
std::vector<std::string> paths ({
213-
"/tmp/.s.monetdb." + std::to_string(port)
214-
});
215-
216-
for(const std::string &path : paths) {
217-
std::cout << "\033[32mTrying: " << path << "\033[0m\n";
218-
219-
struct sockaddr_un serverAddress;
220-
bzero(&serverAddress, sizeof(serverAddress));
221-
serverAddress.sun_family = AF_UNIX;
222-
std::memcpy(serverAddress.sun_path, path.c_str(), path.length() + 1);
215+
struct sockaddr_un serverAddress;
216+
bzero(&serverAddress, sizeof(serverAddress));
217+
serverAddress.sun_family = AF_UNIX;
218+
std::memcpy(serverAddress.sun_path, socketFilePath.c_str(), socketFilePath.length() + 1);
223219

224-
if (connect(this->clientSocket, (sockaddr*)&serverAddress, sizeof(serverAddress)) == 0) {
225-
// See: https://github.com/MonetDB/MonetDB/blob/1f1bbdbd3340fdb74345723e8c98c120dcaf2ead/clients/mapilib/mapi.c#L2416
226-
this->buffer[0] = '0';
227-
this->WriteExact(1);
228-
this->connected = true;
229-
return;
230-
}
220+
if (connect(this->clientSocket, (sockaddr*)&serverAddress, sizeof(serverAddress)) == 0) {
221+
this->connected = true;
222+
return;
231223
}
232224

233225
throw std::runtime_error("Failed to connect to the server. Error: '"
234226
+ std::string(strerror(errno)) + "' (" + std::to_string(errno) + ")");
235227
}
236228

229+
/**
230+
* @brief The unix domain socket connection requires
231+
* that the client sends a single byte (without packet frame)
232+
* first with content 0x30 or '0'.
233+
* See: https://github.com/MonetDB/MonetDB/blob/1f1bbdbd3340fdb74345723e8c98c120dcaf2ead/clients/mapilib/mapi.c#L2416
234+
*/
235+
void SendUnixDomainSocketInitByte() {
236+
this->buffer[0] = '0';
237+
this->WriteExact(1);
238+
}
239+
237240
/**
238241
* @brief Returns true if the client is connected
239242
* to the MonetDB server, false otherwise.

protocol_doc/monet-explorer/ServerChallenge.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ namespace MonetExplorer {
154154
const char *endPos = pos + msg.length() - 1;
155155
int field = 0;
156156

157-
for(; pos < endPos; pos++) {
158-
if (*pos == ':' || pos == endPos - 1 || *pos == '\n' || *pos == ',') {
157+
for(; pos <= endPos; pos++) {
158+
if (*pos == ':' || pos == endPos || *pos == '\n' || *pos == ',') {
159159
switch (field) {
160160
case 0: {
161161
this->salt = std::string(start, pos - start);
@@ -263,6 +263,13 @@ namespace MonetExplorer {
263263
throw std::runtime_error("The protocol '" + proto + "' chosen from the command line "
264264
"is not supported by the server. (Please check if it's upper-case.)");
265265
}
266+
267+
if (this->passwordHashAlgo != "SHA512") {
268+
throw std::runtime_error("The server offered '" + this->passwordHashAlgo + "' "
269+
"for password hashing. This client supports only SHA512 for password hashing "
270+
"and the following for 'salted hashing': SHA1, SHA256, SHA512, RIPEMD160, "
271+
"SHA224, SHA384.");
272+
}
266273

267274
std::stringstream buff;
268275
std::string pwHash = this->Sha512(password) + this->salt;

protocol_doc/monet-explorer/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ int main(int argc, char *argv[]) {
2727

2828
cmd.Argument.String("host", 'h', "127.0.0.1", "host_name", "The host name or IP add|ress "
2929
"of the \033[1mMonetDB server\033[0m.");
30-
cmd.Argument.Int("port", 'p', 50000, "port", "The port of the \033[1mMonetDB server\033[0m.");
30+
cmd.Argument.Int("port", 'p', 50000, "port", "The port of the \033[1mMonetDB server\033[0m."
31+
"The de-fault value is 50000.");
3132
cmd.Argument.String("user", 'u', "monetdb", "user_name", "User name for the database login.");
3233
cmd.Argument.String("password", 'P', "monetdb", "password", "User password for the database login. "
3334
"The de|fault value is 'monetdb'.");
@@ -39,9 +40,9 @@ int main(int argc, char *argv[]) {
3940
cmd.Option("file-transfer", 't', "Enable the file trans|fer pro|to|col for the con|nec|tion.");
4041
cmd.Argument.String("auth-algo", 'a', "SHA1", "algo", "The hash al|go|rithm to be used "
4142
"for the 'salted hashing'. The \033[1mMonetDB server\033[0m has to support it. This is "
42-
"typi|cally a weaker hash al|go|rithm, which is used to|gether with a "
43+
"typi|cally a weaker hash al|go|rithm, which is used to|gether with the "
4344
"stron|ger 'pass|word hash' that is now SHA512. The cur|rent|ly sup|port|ed values are: "
44-
"SHA1, SHA256, SHA512.");
45+
"SHA1, SHA256, SHA512, RIPEMD160, SHA224, SHA384. De|fault is SHA1.");
4546
cmd.Option("help", '?', "Display the usage instructions.");
4647
cmd.RestrictOperands();
4748

0 commit comments

Comments
 (0)