Thanks for the tip on strlcpy.
My solution was to ensure that my credentials file does not terminate with a new-line character. I used a hex editor to delete the final new-line character that vi sticks in there, and I was able to use my credentials file at that point.
However, it looks like the same thing is happening in the domain parameter, so if you include both a domain and a password, you need to have a new-line character to separate them, and I am not sure how to workaround that.
Here are a couple of alternative workarounds if you need to supply both domain and username in the credentials file. The trick is to help strlcpy to terminate the string, by explicitly inserting a NULL character.
1) If using a hex-editor insert a NULL character (00) just before the newline on each row.
2) or wash/fix an existing credentials file like this:
cat credentials_file | tr -d ' t' | awk -- '{printf "%sn", $0}' > new_credetials_file
This also take care of the space problem, since any spaces (or tabs) are deleted.
3) or create a brand new credentials file like this:
echo -en "domain=xxxnusername=xxxnpassword=xxxn" > credentials_file
Cheers /S-G