java.lang.Object
java.io.File
net.i2p.util.SecureDirectory
All Implemented Interfaces:
Serializable, Comparable<File>
Direct Known Subclasses:
SecureFile

public class SecureDirectoryextends File
Same as File but sets the file mode after mkdir() so it can be read and written by the owner only (i.e. 700 on linux) As of 0.8.2, just use SecureFile instead of this.
See Also:
  • Field Details

    • isNotWindows

      protected static final boolean isNotWindows
      Whether the OS is not Windows.
    • _groupPerms

      private final boolean _groupPerms
      Whether a newly created directory gets group read/write/execute (770) instead of owner-only (700). Set by the constructor overloads that take this flag; a directory is only ever widened at creation time, never after.
  • Constructor Details

    • SecureDirectory

      public SecureDirectory(String pathname)
      SecureDirectory, owner-only (700) on creation.
      Parameters:
      pathname - the directory path; perms are set when mkdir() creates it
    • SecureDirectory

      public SecureDirectory(String pathname, boolean groupPerms)
      Records whether mkdir should make this path group-accessible rather than owner-only.
      Parameters:
      pathname - the directory to create if absent and lock down
      groupPerms - true to create the directory group-accessible (770) instead of owner-only (700)
    • SecureDirectory

      public SecureDirectory(String parent, String child)
      SecureDirectory, owner-only (700) on creation.
      Parameters:
      parent - the path of the containing directory
      child - the name of the directory within parent
    • SecureDirectory

      public SecureDirectory(String parent, String child, boolean groupPerms)
      Records whether mkdir should make this child path group-accessible rather than owner-only.
      Parameters:
      parent - the parent path
      child - the child name
      groupPerms - true to create the directory group-accessible (770)
    • SecureDirectory

      public SecureDirectory(File parent, String child)
      SecureDirectory, owner-only (700) on creation.
      Parameters:
      parent - the directory that will contain the new one
      child - the name of the directory within parent
    • SecureDirectory

      public SecureDirectory(File parent, String child, boolean groupPerms)
      Records whether mkdir should make this child directory group-accessible rather than owner-only.
      Parameters:
      parent - the parent directory
      child - the child name
      groupPerms - true to create the directory group-accessible (770)
  • Method Details

    • mkdir

      public boolean mkdir()
      Sets directory mode on creation: 700 by default, or 770 when the directory was requested group-accessible.
      Overrides:
      mkdir in class File
    • mkdirs

      public boolean mkdirs()
      Sets directory mode on creation: 700 by default, or 770 when the directory was requested group-accessible. Does NOT change the mode of other created directories.
      Overrides:
      mkdirs in class File
    • setPerms

      protected void setPerms()
      Tries to set the permissions to 700 (or 770 when this directory was requested group-accessible), ignores errors.

      Uses the PosixFilePermission API rather than File.setReadable(boolean, boolean): the File setters take an ownerOnly flag, so there is no way to grant the group without also granting others — setReadable(true, false) yields 777, not 770. SecureFileOutputStream.setGroupPerms() sets file permissions the same way for the same reason.

      The execute bit matters as much as read here: a group can read a file inside a directory it cannot traverse, so a group-traversable parent is what actually makes group-readable log files reachable.