There's no need to call getpwuid/getpwnam_r 5 times. Do it once before chroot, once...