If the path returned for HOMEDIR doesn't exist even root or mail
won't
be able to change to it, never mind the permissions.
Of course the correct HOMEDIR value was returned from the LDAP server,
so that was not a problem.
When testing with IMAP it gave the same error: "chdir([path])
failed!!"
Without any more evidence I suggest the following:
Grep the sources for the error message. You might even want to change
it slightly (add dash, dot or something), recompile and verify that
you found the right spot in the source. Then scroll backwards in the
source code and see what was tested. Most probably there is a quite
clear "if(some system call(supplied path))" a few lines before the
error message. Then you need to figure out why it is returning
something that causes the error message. You may want to add a log
line that prints the supllied homedir and the effective uid to the
logs to verify that they indeed are what you expect.
This is the way I have debugged some mysterious error messages in
open source code. Usually I have found out that my own stupidity
outsmarts me by large. I am not a C-genius, there are ample examples
of logging in the code. Just cut, paste and edit a bit. Be careful
with the parenthesis and semicolons, they can cause even more
mysterious output from the compiler.
You might even try to create your own "Hello world" type of program
that calls the same system call with a fixed string and prints the
output. The only challenge is to find which header files and
libraries to include, but man pages are your friend.