Noted by Vericode analysis. Correctly use chroot().
authorJeremy Allison <jra@samba.org>
Fri, 13 Feb 2009 23:08:57 +0000 (15:08 -0800)
committerKarolin Seeger <kseeger@samba.org>
Mon, 16 Feb 2009 08:57:04 +0000 (09:57 +0100)
Jeremy.
(cherry picked from commit 30a01422a21bd54b2b3a58729fbf25ab173845e8)

source/smbd/server.c

index 770de415a83dc14dda72280e062a6bcfe89a2249..6edef00b11aead8610197c84ba156b5e04b17793 100644 (file)
@@ -1420,8 +1420,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 */