DNS Resolve in php chroot

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I created a script which creates a chroot and sets up s://forum.tuteehub.com/tag/php">php-fpm and apache2 to make the site work. In my script I'm copying all required lib(s) to my chroot lib(s) dir(s) using this:

fileArray=$(ldd /usr/bin/s://forum.tuteehub.com/tag/php">php* 2>/dev/null | awk 'NF == 4 {print $3}; NF == 2 {print $1}' | s://forum.tuteehub.com/tag/sort">sort -u)

for file in $fileArray
do
  dirName="$(dirname $file)"
  [ ! -d "$serverDir$dirName" ] && mkdir -p "$serverDir$dirName" || :
  cp $file "$serverDir$dirName"
done

but I saw that if I use a little script like this:

s://forum.tuteehub.com/tag/php">php 
  print_r(gethostbynamel("google.com")); 
?>

It doesn't resolve unless there is libnss_dns.so.1 in libs. Now my question is: what is the file I need to 'ldd' to copy libnss_dns to my chroot?

PS: I don't want to copy it manually because I want my script to be cross architecture.

profilepic.png
manpreet 2 years ago

 

There is no option you can supply to ldd and no ldd feature you can call upon to cause it to include libnss_dns.so.1 in the list of libraries to copy. That library is loaded dynamically at run time because of the contents of configuration files that have nothing to do with the dynamic linker (namely /etc/nsswitch.conf) and ldd simply cannot know what libraries the program might or might not load dynamically in this way.

You will find that there is probably going to be a whole assortment of other files that you need to copy in manually to make a working chroot: everything from /dev/null to locale configuration, depending on what you're using.

PS: I don't want to copy it manually because I want my script to be cross architecture.

Unfortunately, getting a chroot just right is an inherently non-portable thing. That is, there are no standard APIs you can use to set one up.

(I think you don't mean "cross architecture" here: assuming you have a working procedure to set up a chroot on, say, SPARC, the exact same procedure should work just fine on, say, x86_64, given the same operating system.)

You might try to use something like debootstrap to set up a new chroot. At least it's tied to a package manager so it ensures that all the dependencies are present. Even then, debootstrap does leave several system files (like /etc/fstab) in a kind of TODO state.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.