Changeset: 38dbdaf29b6f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/38dbdaf29b6f
Modified Files:
        tools/merovingian/daemon/forkmserver.c
        tools/merovingian/daemon/merovingian.c
        tools/mserver/mserver5.c
Branch: Dec2025
Log Message:

Disallow running mserver5 and monetdbd as root.
Unless started with --accept-the-risks-running-as-root.


diffs (90 lines):

diff --git a/tools/merovingian/daemon/forkmserver.c 
b/tools/merovingian/daemon/forkmserver.c
--- a/tools/merovingian/daemon/forkmserver.c
+++ b/tools/merovingian/daemon/forkmserver.c
@@ -514,6 +514,8 @@ forkMserver(const char *database, sabdb*
                         "--set=merovingian_uri=mapi:monetdb://%s:%u/%s",
                         _mero_hostname, mport, database);
        argv[c++] = _mero_mserver;
+       if (getuid() == 0)
+               argv[c++] = "--accept-the-risks-running-as-root";
        argv[c++] = dbpath;
        argv[c++] = muri;
        if (dbextra != NULL) {
diff --git a/tools/merovingian/daemon/merovingian.c 
b/tools/merovingian/daemon/merovingian.c
--- a/tools/merovingian/daemon/merovingian.c
+++ b/tools/merovingian/daemon/merovingian.c
@@ -483,6 +483,18 @@ main(int argc, char *argv[])
        int retfd = -1;
        int dup_err;
 
+       if (getuid() == 0) {
+               if (argc > 1 && strcmp(argv[1], 
"--accept-the-risks-running-as-root") == 0) {
+                       Mlevelfprintf(WARNING, stderr, "running as root is not 
recommended\n");
+                       argv[1] = argv[0];
+                       argv++;
+                       argc--;
+               } else {
+                       Mlevelfprintf(ERROR, stderr, "fatal: running as root is 
not allowed\n");
+                       exit(1);
+               }
+       }
+
        /* seed the randomiser for when we create a database, send responses
         * to HELO, etc */
        srand(time(NULL));
diff --git a/tools/mserver/mserver5.c b/tools/mserver/mserver5.c
--- a/tools/mserver/mserver5.c
+++ b/tools/mserver/mserver5.c
@@ -360,6 +360,10 @@ main(int argc, char **av)
                {"process-wal-and-exit", no_argument, NULL, 0},
                {"clean-BBP", no_argument, NULL, 0},
 
+#ifdef HAVE_GETUID
+               {"accept-the-risks-running-as-root", no_argument, NULL, 0},
+#endif
+
                {NULL, 0, NULL, 0}
        };
 
@@ -425,6 +429,10 @@ main(int argc, char **av)
        if (!(setlen = mo_builtin_settings(&set)))
                usage(prog, -1);
 
+#ifdef HAVE_GETUID
+       bool allow_root = false;
+#endif
+
        for (;;) {
                int option_index = 0;
 
@@ -436,6 +444,12 @@ main(int argc, char **av)
 
                switch (c) {
                case 0:
+#ifdef HAVE_GETUID
+                       if (strcmp(long_options[option_index].name, 
"accept-the-risks-running-as-root") == 0) {
+                               allow_root = true;
+                               break;
+                       }
+#endif
                        if (strcmp(long_options[option_index].name, 
"in-memory") == 0) {
                                inmemory = true;
                                break;
@@ -654,6 +668,17 @@ main(int argc, char **av)
                }
        }
 
+#ifdef HAVE_GETUID
+       if (getuid() == 0) {
+               if (allow_root) {
+                       fprintf(stderr, "WARNING: running as root is not 
recommended\n");
+               } else {
+                       fprintf(stderr, "ERROR: running as root is not 
allowed\n");
+                       exit(1);
+               }
+       }
+#endif
+
        if (optind < argc)
                usage(prog, -1);
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to