2

I am a user on a Solaris 10 system and I wish to maintain my own version of /etc/hosts. This file will function like a normal /etc/hosts, except it will only resolve hosts from processes that I run.

Since I do not have the ability to write to /etc/hosts and I do not wish to have to ask the adminstrator to reconfigure it for me. (please don't go into this more)

I am open to other alternatives that will allow a non-privileged user the ability to add custom host names. The solution must not involve the superuser doing anything.

JdeBP
  • 3,970
  • 17
  • 17
David
  • 557
  • 2
  • 6
  • 13
  • Is this for specific applications? Can you just build a configuration file and store the ip address in the configuration? – Zoredache Jul 01 '10 at 23:40
  • it's an application that won't let me store hostnames in its config – David Jul 01 '10 at 23:41
  • Can you put the desired IP address into the App? Can you get the administrator to help with initial setup of whatever solution is suggested? – DrStalker Jul 02 '10 at 04:24

2 Answers2

4

Override gethostbyname. You'll need to control the library path, but that can be done by a user. See here for some neat info:

http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Slartibartfast
  • 3,265
  • 17
  • 16
  • You will need to override more functions than gethostbyname, like gethostent. Depending on the Solaris release, these functions might also differ, like gethostbyname_r and gethostent_r. Also, beware that the link you posted is more directed to Gnu/Linux than Solaris and some information doesn't apply to the latter, like ld.so.preload. LD_PRELOAD is however the way to go with both Gnu/Linux and Solaris. – jlliagre Jul 02 '10 at 09:21
  • This is the Right Answer but sadly not a simple one. Here's one that someone else prepared earlier: http://fy.chalmers.se/~appro/LD_*-gallery/libhost.c – Zanchey Jan 24 '12 at 01:07
2

A chrooted environment or even a dedicated non global zone might be a solution for you. Otherwise, an interposition library or a dtrace script might also do the job.

jlliagre
  • 8,691
  • 16
  • 36
  • 1
    don't you need to be root for all those things? – David Jul 01 '10 at 23:41
  • For setting up them yes, outside the interposition library suggestion which requires no privileges but programming skills. I doubt you'd easily find existing code that does precisely that. – jlliagre Jul 01 '10 at 23:49