john icon indicating copy to clipboard operation
john copied to clipboard

Add environment variable to control John’s home directory (XDG Base Directory support)

Open misterhackerman opened this issue 3 months ago • 2 comments

Summary

John the Ripper currently hardcodes ~/.john as the per-user “home” (JOHN_PRIVATE_HOME in params.h), with $JOHN as a partial override. This setup does not comply with the XDG Base Directory Specification and gives users little flexibility in where files are stored.

The problem is not whether to default to ~/.john or to XDG — it’s that the path is compiled in and not fully user-configurable.


Proposal

Introduce a new environment variable (e.g. JOHN_HOME) that defines the base directory for all user-specific files (config, pot, session, recovery, etc).

This would allow:

  • JOHN_HOME=$XDG_DATA_HOME/john
  • JOHN_HOME=$HOME/.local/state/john
  • JOHN_HOME=$HOME/.john (legacy)

In other words, users control the layout without recompiling or symlink hacks.

Additionally:

  • Preserve the current behavior if JOHN_HOME is unset (fall back to ~/.john).

Benefits

  • User Choice: Users who want strict XDG compliance can set it in their shell profile. Those who prefer the legacy layout don’t need to change anything.

  • Distribution-friendly: Packagers (Arch, Debian, etc.) can enable XDG layouts without patching params.h.

  • No breakage: Existing scripts and installs continue to work unchanged.

  • Simple to implement: Replace the constant JOHN_PRIVATE_HOME with a getenv() check, e.g.:

    const char *john_home = getenv("JOHN_HOME");
    if (!john_home)
        john_home = "~/.john";
    

misterhackerman avatar Sep 02 '25 01:09 misterhackerman

Related issue: #4552

solardiz avatar Sep 02 '25 13:09 solardiz

Thank you for linking that issue. But let me clarify:

This isn't about implementing XDG - it's about adding one environment variable (JOHN_HOME) that lets users decide for themselves. Default behavior stays exactly the same (~/.john), but now packagers and advanced users can configure their own paths without needing patches. Zero breaking changes, minimal code.

misterhackerman avatar Sep 03 '25 20:09 misterhackerman