Moved the creation of the data directory.
authorArt Cancro <ajc@citadel.org>
Fri, 1 Sep 2023 03:10:28 +0000 (23:10 -0400)
committerArt Cancro <ajc@citadel.org>
Fri, 1 Sep 2023 03:10:28 +0000 (23:10 -0400)
It was happening too late in the new code and failing on some new installations.

citadel/server/backends/common/database.c
citadel/server/server_main.c

index 934d5553e8456c41ffdf2542eb4519903d7b1bc0..e3024f4d1919573ecf080a3f0b568733efaaa467 100644 (file)
@@ -17,6 +17,8 @@
 #include "../../citserver.h"
 #include "../../config.h"
 
+void cdb_chmod_data(void);
+
 // Header files for all available backends must be included here.
 #include "../berkeley_db/berkeley_db.h"
 
@@ -41,6 +43,7 @@ void                  (*cdb_tick)(void)                                       = NULL;
 
 // This function is responsible for choosing and initializing a back end.
 void cdb_init_backends(void) {
+       cdb_chmod_data();
        bdb_init_backend();             // for now, this is the only one, so we select it always.
 }
 
index cd757a1403e3c4ce7c2f3daed7af2c21f7a92e4f..349213d6f6bf496724b3d5704e26a1abc6f94ee8 100644 (file)
@@ -261,18 +261,17 @@ int main(int argc, char **argv) {
        }
 
        // Now that we've bound the sockets, change to the Citadel user id and its corresponding group ids
-       if (drop_root_perms) {
-               cdb_chmod_data();       // make sure we own our data files
-               getpwuid_r(ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
-               if (pwp == NULL) {
-                       syslog(LOG_ERR, "main: WARNING, getpwuid(%ld): %m Group IDs will be incorrect.", (long)ctdluid);
-               }
-               else {
-                       initgroups(pw.pw_name, pw.pw_gid);
-                       if (setgid(pw.pw_gid)) {
-                               syslog(LOG_ERR, "main: setgid(%ld): %m", (long)pw.pw_gid);
-                       }
+       getpwuid_r(ctdluid, &pw, pwbuf, sizeof(pwbuf), &pwp);
+       if (pwp == NULL) {
+               syslog(LOG_ERR, "main: WARNING, getpwuid(%ld): %m Group IDs will be incorrect.", (long)ctdluid);
+       }
+       else {
+               initgroups(pw.pw_name, pw.pw_gid);
+               if (setgid(pw.pw_gid)) {
+                       syslog(LOG_ERR, "main: setgid(%ld): %m", (long)pw.pw_gid);
                }
+       }
+       if (drop_root_perms) {
                syslog(LOG_INFO, "main: changing uid to %ld", (long)ctdluid);
                if (setuid(ctdluid) != 0) {
                        syslog(LOG_ERR, "main: setuid() failed: %m");