Noted by Vericode analysis. Correctly use chroot().
[samba.git] / source / smbd / server.c
index 2ed6792c4a956376539173531543ef0f854843c8..9f13c32b78eeae004f78e70f64a9018ba3ad0aa3 100644 (file)
@@ -1101,8 +1101,15 @@ extern void build_options(BOOL screen);
        }
 
        if (*lp_rootdir()) {
-               if (sys_chroot(lp_rootdir()) == 0)
-                       DEBUG(2,("Changed root to %s\n", lp_rootdir()));
+               if (sys_chroot(lp_rootdir()) != 0) {
+                       DEBUG(0,("Failed to change root to %s\n", lp_rootdir()));
+                       exit(1);
+               }
+               if (chdir("/") == -1) {
+                       DEBUG(0,("Failed to chdir to / on chroot to %s\n", lp_rootdir()));
+                       exit(1);
+               }
+               DEBUG(0,("Changed root to %s\n", lp_rootdir()));
        }
 
        /* Setup oplocks */