Class ServerConfig

java.lang.Object
ghidra.features.bsim.query.ServerConfig

public class ServerConfig extends Object
Class for modifying the PostgreSQL configuration files describing the main server settings (postgresql.conf) the connection settings (pg_hba.conf) the identification map (pg_ident.conf)
  • Constructor Summary

    Constructors
    Change
    Constructor
    Description
     
  • Method Summary

    Change
    Modifier and Type
    Method
    Description
    void
    addKey(String key, String value)
    Add a key/value pair directly into the configuration file
     
     
     
     
    Retrieve the value associated with a particular key from a (parsed) configuration file
    void
    patchConfig(File inFile, File outFile)
    Given a set of key/value pairs, established via restoreXml or manually entered via addKey, read in an existing configuration file, and write out an altered form, where: 1) Keys matching something in the keyValue map have their value altered to match the map 2) Keys that don't match anything in the map, are output unaltered 3) Comments, both entire line and those coming after key/value pairs, are preserved
    void
    patchConnect(File inFile, File outFile)
    Read in a connection file and write out an altered version of the file where: 1) Any entry that matches something in connectSet, has its authentication method altered 2) Any entry that does not match into connectSet is commented out in the output 3) Entire line comments are preserved
    static void
    patchIdent(File inFile, File outFile, String mapName, String systemName, String roleName, boolean addUser)
    Add/remove an identify entry to pg_ident.conf
    void
    Remove the remote (non-loopback) hostssl connection entry so that only loopback access remains.
    void
    Read a set of key/value pairs and connection entries to use for patching, from an XML file
    void
    scanConfig(File inFile)
    Parse a configuration file
    void
    scanConnect(File inFile)
    Read in all the entries of the connection file
    static Map<String, List<String>>
    scanIdent(File inFile, String mapName)
    Read the identity mappings which are registered within a specific map of pg_ident.conf.
    void
     
    void
     
    void
    writePostgresConfig(File inFile, File outFile, boolean initialize)
    Generate or update postgresql.conf using two clearly-delimited blocks appended after the pristine initdb configuration (later settings override earlier ones in postgresql.conf): a managed block (MANAGED_BEGIN..MANAGED_END) holding the BSim-controlled settings (SSL, interface binding, authentication-related, logging) which is regenerated on every reconfigure and must not be hand-edited; and a tunable block (TUNABLE_BEGIN..TUNABLE_END) holding the performance-tuning settings, written once at initialization and preserved thereafter, which an administrator may edit. At initialization the file is generated from the initdb original with both blocks appended.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ServerConfig

      public ServerConfig()
  • Method Details

    • restoreXml

      public void restoreXml(XmlPullParser parser)
      Read a set of key/value pairs and connection entries to use for patching, from an XML file
      Parameters:
      parser - the XML parser
    • patchConfig

      public void patchConfig(File inFile, File outFile) throws IOException
      Given a set of key/value pairs, established via restoreXml or manually entered via addKey, read in an existing configuration file, and write out an altered form, where: 1) Keys matching something in the keyValue map have their value altered to match the map 2) Keys that don't match anything in the map, are output unaltered 3) Comments, both entire line and those coming after key/value pairs, are preserved
      Parameters:
      inFile - the file to read
      outFile - the new file to write
      Throws:
      IOException - if the files cannot be read from or written to
    • writePostgresConfig NEW

      public void writePostgresConfig(File inFile, File outFile, boolean initialize) throws IOException
      Generate or update postgresql.conf using two clearly-delimited blocks appended after the pristine initdb configuration (later settings override earlier ones in postgresql.conf):
      • a managed block (MANAGED_BEGIN..MANAGED_END) holding the BSim-controlled settings (SSL, interface binding, authentication-related, logging) which is regenerated on every reconfigure and must not be hand-edited; and
      • a tunable block (TUNABLE_BEGIN..TUNABLE_END) holding the performance-tuning settings, written once at initialization and preserved thereafter, which an administrator may edit.
      At initialization the file is generated from the initdb original with both blocks appended. On reconfigure only the managed block is regenerated in place; the tunable block and any other edits are preserved. The entire input is read before writing, so inFile and outFile may be the same path.
      Parameters:
      inFile - the input configuration file (the initdb original at init; the current postgresql.conf at reconfigure)
      outFile - the configuration file to write (may be the same path as inFile)
      initialize - true to also (re)write the tunable block from the template defaults
      Throws:
      IOException - if the file cannot be read or written
    • patchConnect

      public void patchConnect(File inFile, File outFile) throws IOException
      Read in a connection file and write out an altered version of the file where: 1) Any entry that matches something in connectSet, has its authentication method altered 2) Any entry that does not match into connectSet is commented out in the output 3) Entire line comments are preserved
      Parameters:
      inFile - the file to read
      outFile - the new file to write
      Throws:
      IOException - if the files cannot be read from or written to
    • patchIdent

      public static void patchIdent(File inFile, File outFile, String mapName, String systemName, String roleName, boolean addUser) throws IOException
      Add/remove an identify entry to pg_ident.conf
      Parameters:
      inFile - is a copy of pg_ident.conf to modify
      outFile - becomes the modified copy of pg_ident.conf
      mapName - is the map being modified
      systemName - is the system name (map from)
      roleName - is the database role (map to)
      addUser - is true if the map entry is to be added, false if the entry should be removed
      Throws:
      IOException - if the file cannot be read from or written to
    • scanIdent NEW

      public static Map<String, List<String>> scanIdent(File inFile, String mapName) throws IOException
      Read the identity mappings which are registered within a specific map of pg_ident.conf.
      Parameters:
      inFile - is a copy of pg_ident.conf to read
      mapName - is the map whose entries are to be returned
      Returns:
      the system names (map from) registered for each database role (map to), in the order they appear within the file. PostgreSQL permits a role to be mapped from more than one system name, so each role is given all of its entries.
      Throws:
      IOException - if the file cannot be read or parsed
    • addKey

      public void addKey(String key, String value)
      Add a key/value pair directly into the configuration file
      Parameters:
      key - the key to add/update
      value - the value to insert
    • getValue

      public String getValue(String key)
      Retrieve the value associated with a particular key from a (parsed) configuration file
      Parameters:
      key - identifies the value to return
      Returns:
      the value
    • scanConfig

      public void scanConfig(File inFile) throws IOException
      Parse a configuration file
      Parameters:
      inFile - is the path to the file
      Throws:
      IOException - if the file cannot be read
    • scanConnect

      public void scanConnect(File inFile) throws IOException
      Read in all the entries of the connection file
      Parameters:
      inFile - the file to read in
      Throws:
      IOException - if the file cannot be read/parsed
    • getLocalAuthentication

      public String getLocalAuthentication()
    • getLocalAuthenticationOptions NEW

      public String getLocalAuthenticationOptions()
      Returns:
      the authentication method options of the local (loopback) connection entry whose method is returned by getLocalAuthentication(), or null if there is no such entry or it specifies no options
    • setLocalAuthentication

      public void setLocalAuthentication(String val, String options)
    • getHostAuthentication

      public String getHostAuthentication()
    • getHostAuthenticationOptions NEW

      public String getHostAuthenticationOptions()
      Returns:
      the authentication method options of the remote (non-loopback) connection entry whose method is returned by getHostAuthentication(), or null if there is no such entry (remote access disabled) or it specifies no options
    • setHostAuthentication

      public void setHostAuthentication(String val, String options)
    • removeHostAuthentication NEW

      public void removeHostAuthentication()
      Remove the remote (non-loopback) hostssl connection entry so that only loopback access remains. Used when no server certificate key store is configured.