Changeset: 311fe7824f18 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=311fe7824f18
Branch: Oct2020
Log Message:

merged


diffs (277 lines):

diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -9559,7 +9559,7 @@ optimize_rel(mvc *sql, sql_rel *rel, int
                        rel = rel_visitor_bottomup(&v, rel, 
&rewrite_reset_used); /* reset used flag, used by rel_merge_select_rse */
                }
 
-       if (gp.cnt[op_project] && /* DISABLES CODE */ (0))
+       if (gp.cnt[op_project])
                rel = rel_exp_visitor_bottomup(&v, rel, &rel_merge_project_rse, 
false);
 
        if (gp.cnt[op_join])
diff --git a/sql/test/SQLancer/Tests/sqlancer07.sql 
b/sql/test/SQLancer/Tests/sqlancer07.sql
--- a/sql/test/SQLancer/Tests/sqlancer07.sql
+++ b/sql/test/SQLancer/Tests/sqlancer07.sql
@@ -113,3 +113,12 @@ select t0.c1 from t0 where (-5) in (case
 select t0.c1 from t0 where (-5) in (case when t0.c1 then 1 else -2 end, 
(select -3 from t0, t2 where false));
        -- empty
 ROLLBACK;
+
+START TRANSACTION;
+CREATE TABLE t1 (c0 DOUBLE PRECISION NOT NULL);
+INSERT INTO t1(c0) 
VALUES((0.6548429615298178*0.3050008736497528)/(0.5061323979270875));
+INSERT INTO t1(c0) VALUES(((((COALESCE(0.6548429615298178, 
0.20317629894456002))*(COALESCE(0.3050008736497528, 
0.2277902039419617))))/(0.5061323979270875)));
+SELECT t1.c0 FROM t1;
+       -- 0.3946154725285108
+       -- 0.3946154725285108
+ROLLBACK;
diff --git a/tools/merovingian/daemon/CMakeLists.txt 
b/tools/merovingian/daemon/CMakeLists.txt
--- a/tools/merovingian/daemon/CMakeLists.txt
+++ b/tools/merovingian/daemon/CMakeLists.txt
@@ -36,9 +36,7 @@ target_link_libraries(monetdbd
   mcrypt
   stream
   mapi
-  bat
   msabaoth
-  mal
   ${CMAKE_DL_LIBS}
   Threads::Threads)
 
diff --git a/tools/merovingian/daemon/controlrunner.c 
b/tools/merovingian/daemon/controlrunner.c
--- a/tools/merovingian/daemon/controlrunner.c
+++ b/tools/merovingian/daemon/controlrunner.c
@@ -34,9 +34,6 @@
 #include "utils/database.h"
 #include "utils/control.h"
 
-#include "gdk.h"  /* these three for creation of dbs with password */
-#include "mal_authorize.h"
-
 #include "merovingian.h"
 #include "discoveryrunner.h" /* broadcast, remotedb */
 #include "forkmserver.h"
@@ -442,78 +439,60 @@ static void ctl_handle_client(
                                } else {
                                        if (*p != '\0') {
                                                pid_t child;
-                                               if ((child = fork()) == 0) {
-                                                       FILE *secretf;
-                                                       size_t len;
+                                               int pipes[2];
+                                               if (pipe(pipes) == -1) {
+                                                       Mfprintf(_mero_ctlerr, 
"%s: creating pipe failed\n",
+                                                                        
origin);
+                                               } else if ((child = fork()) == 
0) {
+                                                       /* this is the child 
process; exit non-zero
+                                                        * on failure */
                                                        char *err;
-                                                       char *vaultkey;
-                                                       opt *set = 
malloc(sizeof(opt) * 2);
-                                                       int setlen = 0;
                                                        char *sadbfarm;
+                                                       char buf3[8092];
+
+                                                       close(pipes[1]);
+                                                       dup2(pipes[0], 0);
+                                                       close(pipes[0]);
 
                                                        if ((err = 
msab_getDBfarm(&sadbfarm)) != NULL) {
-                                                               
Mfprintf(_mero_ctlerr, "%s: internal error: %s\n",
+                                                               
Mfprintf(_mero_ctlerr,
+                                                                               
 "%s: internal error: %s\n",
                                                                                
 origin, err);
-                                                               exit(0);
-                                                       }
-                                                       snprintf(buf2, 
sizeof(buf2), "%s/%s", sadbfarm, q);
-                                                       free(sadbfarm);
-                                                       setlen = 
mo_add_option(&set, setlen, opt_cmdline, "gdk_dbpath", buf2);
-                                                       setlen = 
mo_system_config(&set, setlen);
-                                                       if (BBPaddfarm(buf2, (1 
<< PERSISTENT) | (1 << TRANSIENT), true) != GDK_SUCCEED) {
-                                                               
Mfprintf(_mero_ctlerr, "%s: could not add farm to "
-                                                                       "'%s': 
%d: %s\n", origin, q, errno, strerror(errno));
-                                                               exit(0);
-                                                       }
-                                                       /* the child, pollute 
scope by loading BBP */
-                                                       if (chdir(q) < 0) {
-                                                               /* Fabian says 
"Ignore the output.
-                                                                * The idea is 
that the stuff below
-                                                                * will also 
fail, and therefore emit
-                                                                * some error, 
but if that happens,
-                                                                * the world 
already is in such a bad
-                                                                * shape that 
that most likely isn't
-                                                                * your biggest 
problem.
-                                                                * Hence a 
(void) probably does.
-                                                                * If not, a 
fake if.
-                                                                * (exit(0) 
should be fine)."
-                                                                * 
(https://www.monetdb.org/pipermail/developers-list/2014-February/004238.html)
-                                                                */
-                                                               
Mfprintf(_mero_ctlerr, "%s: could not chdir to "
-                                                                       "'%s': 
%d: %s\n", origin, q, errno, strerror(errno));
-                                                               exit(0);
+                                                               
exit(EXIT_FAILURE);
                                                        }
-
-                                                       buf2[0] = '\0';
-                                                       if ((secretf = 
fopen(".vaultkey", "r")) != NULL) {
-                                                               len = 
fread(buf2, 1, sizeof(buf2), secretf);
-                                                               buf2[len] = 
'\0';
-                                                               len = 
strlen(buf2); /* secret can contain null-bytes */
-                                                               fclose(secretf);
-                                                       }
-                                                       if (GDKinit(set, 
setlen, 0) != GDK_SUCCEED) {
-                                                               
Mfprintf(_mero_ctlerr, "%s: could not "
-                                                                               
 "initialize database '%s'\n",
+                                                       snprintf(buf2, 
sizeof(buf2),
+                                                                        
"monet_vault_key=%s/%s/.vaultkey",
+                                                                        
sadbfarm, q);
+                                                       snprintf(buf3, 
sizeof(buf3), "--dbpath=%s/%s",
+                                                                        
sadbfarm, q);
+                                                       free(sadbfarm);
+                                                       execl(_mero_mserver,
+                                                                 _mero_mserver,
+                                                                 "--set",
+                                                                 buf2,
+                                                                 buf3,
+                                                                 
"--read-password-initialize-and-exit",
+                                                                 NULL);
+                                                       Mfprintf(_mero_ctlerr,
+                                                                        "%s: 
cannot start mserver5\n", origin);
+                                                       exit(EXIT_FAILURE);
+                                               } else if (child > 0) {
+                                                       /* this is the parent 
process */
+                                                       int status;
+                                                       close(pipes[0]);
+                                                       write(pipes[1], p, 
strlen(p));
+                                                       write(pipes[1], "\n", 
1);
+                                                       close(pipes[1]);
+                                                       /* wait for the child 
to finish */
+                                                       waitpid(child, &status, 
0);
+                                                       if (!WIFEXITED(status) 
|| WEXITSTATUS(status) != 0)
+                                                               
Mfprintf(_mero_ctlerr,
+                                                                               
 "%s: initialization of database '%s' failed\n",
                                                                                
 origin, q);
-                                                               exit(0);
-                                                       }
-                                                       vaultkey = buf2;
-                                                       if ((err = 
AUTHunlockVault(vaultkey)) != NULL ||
-                                                               (err = 
AUTHinitTables(p)) != NULL) {
-                                                               
Mfprintf(_mero_ctlerr, "%s: could not setup "
-                                                                               
"database '%s': %s\n", origin, q, err);
-                                                               
freeException(err);
-                                                       } else {
-                                                               /* don't start 
locked */
-                                                               
remove(".maintenance");
-                                                       }
-
-                                                       exit(0); /* return to 
the parent */
-                                               } else if (child > 0) {
-                                                       /* wait for the child 
to finish */
-                                                       waitpid(child, NULL, 0);
                                                } else {
-                                                       Mfprintf(_mero_ctlout, 
"%s: forking failed\n",
+                                                       close(pipes[0]);
+                                                       close(pipes[1]);
+                                                       Mfprintf(_mero_ctlerr, 
"%s: forking failed\n",
                                                                         
origin);
                                                }
                                        }
diff --git a/tools/mserver/mserver5.1.in b/tools/mserver/mserver5.1.in
--- a/tools/mserver/mserver5.1.in
+++ b/tools/mserver/mserver5.1.in
@@ -202,6 +202,18 @@ Equivalent to \fB\-\-debug=\fP\fI(THRDMA
 .TP
 .B \-\-transactions
 Equivalent to \fB\-\-debug=\fP\fI(TMMASK | DELTAMASK | TEMMASK)\fP.
+.TP
+.B \-\-read\-password\-initialize\-and\-exit
+Read an unencrypted password from standard input and use it to set the
+password for the
+.B monetdb
+administrator user, initialize the database, and exit.
+If the database was already initialized, the administrator password is
+not changed.
+This option is used by
+.IR monetdbd (1)
+when creating a new database with an administrator password and should
+not be used otherwise.
 .SH MSERVER5 PARAMETERS
 .I Mserver5
 instructs the GDK kernel through the MAL (MonetDB Assembler Language)
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -270,6 +270,7 @@ main(int argc, char **av)
        char *dbextra = NULL;
        char *dbtrace = NULL;
        bool inmemory = false;
+       bool readpwdxit = false;
        static struct option long_options[] = {
                { "config", required_argument, NULL, 'c' },
                { "dbextra", required_argument, NULL, 0 },
@@ -294,6 +295,8 @@ main(int argc, char **av)
                { "threads", no_argument, NULL, 0 },
                { "transactions", no_argument, NULL, 0 },
 
+               { "read-password-initialize-and-exit", no_argument, NULL, 0 },
+
                { NULL, 0, NULL, 0 }
        };
 
@@ -428,6 +431,10 @@ main(int argc, char **av)
                                grpdebug |= GRPtransactions;
                                break;
                        }
+                       if (strcmp(long_options[option_index].name, 
"read-password-initialize-and-exit") == 0) {
+                               readpwdxit = true;
+                               break;
+                       }
                        usage(prog, -1);
                        /* not reached */
                case 'c':
@@ -489,6 +496,11 @@ main(int argc, char **av)
                exit(1);
        }
 
+       if (inmemory && readpwdxit) {
+               fprintf(stderr, "!ERROR: cannot have both in-memory and 
read-password-initialize-and-exit\n");
+               exit(1);
+       }
+
        if (!dbpath) {
                dbpath = absolute_path(mo_find_option(set, setlen, 
"gdk_dbpath"));
                if (!dbpath) {
@@ -689,7 +701,7 @@ main(int argc, char **av)
                        }
                        fclose(secretf);
                }
-               if ((err = AUTHunlockVault(secretp)) != MAL_SUCCEED) {
+               if ((err = AUTHunlockVault(secret)) != MAL_SUCCEED) {
                        /* don't show this as a crash */
                        if (!GDKinmemory())
                                msab_registerStop();
@@ -697,6 +709,23 @@ main(int argc, char **av)
                        freeException(err);
                        exit(1);
                }
+               if (readpwdxit) {
+                       if (fgets(secret, (int) sizeof(secret), stdin) == NULL) 
{
+                               fprintf(stderr, "!ERROR: no password read\n");
+                               exit(1);
+                       }
+                       if ((secretp = strchr(secret, '\n')) == NULL) {
+                               fprintf(stderr, "!ERROR: password too long\n");
+                               exit(1);
+                       }
+                       *secretp = '\0';
+                       if ((err = AUTHinitTables(secret)) != MAL_SUCCEED) {
+                               fprintf(stderr, "%s\n", err);
+                               freeException(err);
+                               exit(1);
+                       }
+                       exit(0);
+               }
        }
 
        char *modules[16];
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to