Skip to content

Override passwd->pw_dir for the current user's password database entry with $HOME.

Notifications You must be signed in to change notification settings

ericpruitt/homeishome

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

$HOME is Home

Some applications query the password database without checking "HOME" to determine where to save data, and if these paths are not configurable within the application itself, it becomes impossible to control where the data is stored. This library can be used with dynamically linked binaries on Linux via "LD_PRELOAD" to ensure that the value of the environment variable "HOME" is always used as the current user's home directory even if the password database contains something else. This is achieved by replacing GNU libc's default implementations of getpwent(3), getpwent_r(3), getpwnam(3), getpwnam_r(3), getpwuid(3) and getpwuid_r(3) with thin wrappers that change passwd->pw_dir to getenv("HOME") when passwd->pw_uid is the same as the effective UID. For example:

# Normal behavior:
$ HOME="EXAMPLE" getent passwd ericpruitt
ericpruitt:x:1000:1000:Eric Pruitt,,,:/home/ericpruitt:/bin/bash

# Modified behavior:
$ LD_PRELOAD="$PWD/homeishome.so" HOME="EXAMPLE" getent passwd ericpruitt
ericpruitt:x:1000:1000:Eric Pruitt,,,:EXAMPLE:/bin/bash

The library can also be compiled as an executable that will insert itself into "LD_PRELOAD" before executing another command with execvp(3):

$ env | grep LD_PRELOAD
$ ./homeishome env | grep LD_PRELOAD
LD_PRELOAD=/home/ericpruitt/projects/homeishome/homeishome
$ HOME="EXAMPLE" ./homeishome getent passwd ericpruitt
ericpruitt:x:1000:1000:Eric Pruitt,,,:EXAMPLE:/bin/bash

This project is licensed under the 2-clause BSD license.

Compilation

Dependencies

  • Debian-based Systems: apt-get install build-essential
  • RHEL/CentOS-based Systems: yum install gcc make

Build Targets

  • homeishome: Build the executable version of the library that can be loaded using "LD_PRELOAD" or by executing the library. This is the default target.
  • homeishome.so: Build a non-executable shared object that must be loaded by explicitly configuring "LD_PRELOAD".
  • all: Build both "homeishome" and "homeishome.so".
  • test: Run behavior verification test suite. If neither "homeishome" nor "homeishome.so" has been compiled, this target will fail.
  • install: Copy the shared object "homeishome.so" to $(LIB) ("/usr/local/lib" by default), and copy the "homeishome" executable binary to $(BIN) ("/usr/local/bin" by default). If neither of the two files exists, this target will fail.
  • uninstall: Delete "homeishome" from $(BIN) and "homeishome.so" from $(LIB) if present.
  • clean: Delete files generated by the build system.

About

Override passwd->pw_dir for the current user's password database entry with $HOME.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published