Prev: IGMP snooping
Next: Forging IPv6 addresses?
From: Barry Margolin on 16 Feb 2010 12:40 In article <d55d4e2b-c24a-47cd-ad6a-32afba02299c(a)c34g2000pri.googlegroups.com>, David Schwartz <davids(a)webmaster.com> wrote: > On Feb 16, 8:45�am, Poster Matt <postermatt(a)no_spam_for_me.org> wrote: > > > > Depends on what you mean by "relied upon". > > > All I meant was if I could rely on using getenv("HOME") to reliably get the > > home > > directory of a user, in all normal situations. > > That doesn't answer the question. Do you mean "what the user wants me > to use as his home directory" or "securely get what the system > administrator set as the user's home directory"? Do you want the user > to be able to override this if he needs to or not? I think he's asking if this is a portable way to get the home directory, i.e. is there a standard that says that $HOME is the variable that's used for this purpose? The answer is yes. SUS Section 8.3 says: "The system shall initialize this variable at the time of login to be a pathname of the user's home directory. See <pwd.h>." > > > I suppose I was just checking in case there were differences between > > flavours of > > UNIX/Linux in where the home directory environment variable was stored. For > > example if HOME_DIR was used sometimes or if HOME is often left unset. > > If it's unset, use 'getpwuid(getuid());' Some situations where this may occur: * A daemon process. * A program running from /etc/rc (I haven't checked whether $HOME is set to root's home directory) * The user has unset he environment variable for some reason. Actually, I just wondered something. If a daemon crashes, and a sysadmin restarts it, could it potentially inherit his $HOME environment variable? It's probably not a good idea to depend on $HOME in daemon programs. -- Barry Margolin, barmar(a)alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group ***
From: Casper H.S. Dik on 16 Feb 2010 13:27 Barry Margolin <barmar(a)alum.mit.edu> writes: >Actually, I just wondered something. If a daemon crashes, and a >sysadmin restarts it, could it potentially inherit his $HOME environment >variable? It's probably not a good idea to depend on $HOME in daemon >programs. Indeed; in older Solaris releases and you restarted (kill -TERM/KILL) inetd will just pass the administrators environment and some daemon were confused (particularly telnetd). Modern Solaris doesn't have that issue as all daemons are started through an intermediate process. Casper -- Expressed in this posting are my opinions. They are in no way related to opinions held by my employer, Sun Microsystems. Statements on Sun products included here are not gospel and may be fiction rather than truth.
From: Poster Matt on 17 Feb 2010 07:56
Barry Margolin wrote: > In article > <d55d4e2b-c24a-47cd-ad6a-32afba02299c(a)c34g2000pri.googlegroups.com>, > David Schwartz <davids(a)webmaster.com> wrote: > >> That doesn't answer the question. Do you mean "what the user wants me >> to use as his home directory" or "securely get what the system >> administrator set as the user's home directory"? Do you want the user >> to be able to override this if he needs to or not? > > I think he's asking if this is a portable way to get the home directory, > i.e. is there a standard that says that $HOME is the variable that's > used for this purpose? Yes, that's exactly what I wanted to know. All that's wanted is whatever the user is using as their home directory, so that a hidden config file can be placed where it can consistently be found should a user choose to use the config file options. > The answer is yes. SUS Section 8.3 says: "The system shall initialize > this variable at the time of login to be a pathname of the user's home > directory. See <pwd.h>." Great, that's me sorted. :) >> If it's unset, use 'getpwuid(getuid());' Okay, I'll use that as a backup in the unlikely event of getenv("HOME") not bearing fruit. Thanks again everyone. |