2.7. Creating Access to the Configuration Data

We have already set the UI up but we don't have any real configuration data. We will have some SCR Agent for reading and writing the /etc/ssh/sshd_config configuration file.

2.7.1. SCR Agent

This section contains the general definition of any SCR Agent, way of looking for already written SCR Agent, technique how to create your own one and also the very important part about testing the SCR Agent.

2.7.1.1. SCR Agents in General

SCR is and abstraction layer. YaST never touches the system directly even if the functionality is written in Perl and such functionality exists.

Every SCR Agent is a small program which transforms any service configuration, file attribute or whatever you can imagine into the YaST data-structure. They can be written in several languages such as C, Bash, Perl or Greenlandic.

The most important functions of SCR Agent are Read() and Write() but not every SCR Agent needs to provide these functions. Additionaly, some SCR Agents have also the Execute() or Dir() function.

2.7.1.2. Looking for a SCR Agent

The first thing, we should do, is to run through all already created SCR Agents whether there is any agent we could use instead of creating a new one. After some time spent on browsing that documentation we could run across the universal .target agent which can also read and return a textual file as one string and might be also used in case when every other tries failed. Unfortunately this is not suitable for such yast-hacker you want to be. That's why we have to create our own SCR Agent.

2.7.1.3. Creating Your Own SCR Agent

Fortunately YaST has a configurable so-called IniAgent which is quite easy to use and sufficiently fulfills our needs. You can find its documentation here: /usr/share/doc/packages/yast2-core/agent-ini/ini.html (you need yast2-core-devel package installed).

Our new SCR Agent should be able to:

  • Handle repeating options such as the Port definition

  • Handle comments starting with the # string

This is the full definition of a .sshd SCR Agent which has the Read(), Write() and Dir() functions. It should be saved into the agents/sshd.scr file:

/**
 * File:
 *   sshd.scr
 * Summary:
 *   SCR Agent for reading/writing /etc/ssh/sshd_config
 *   using the ini-agent
 * Access:
 *   read/write
 * Authors:
 *   John The Fish <john@thesmallfish.net>
 * Example:
 *   Dir(.sshd)
 *   (["Port", "X11Forwarding", "Compression", "MaxAuthTries", "PermitRootLogin"])
 *
 *   Read(.sshd.Compression)
 *   (["yes"])
 *
 *   Write(.sshd.Compression, "no")
 *   (true)
 *
 * $Id: sshd.scr 11113 2005-10-20 14:15:16Z jtf $
 *
 * Fore more information about possible keys and values
 * consult with the sshd_config man pages `man sshd_config`.
 */

.sshd

`ag_ini(
    `IniAgent( "/etc/ssh/sshd_config",
        $[
            "options"   : [ "global_values", "repeat_names", "flat" ],
            "comments"  : [ "^[ \t]*#.*$", "^[ \t]*$" ],
            "params"    : [
                // Options with one value ('yes' / 'no')
                $[ "match" : [ "^[ \t]*([^ \t]+)[ \t]+([^ \t]+)[ \t]+$", "%s %s" ]],
                // Options with more possible values
                $[ "match" : [ "^[ \t]*([^ \t]+)[ \t]+(.+)[ \t]*$", "%s %s" ]],
            ],
            "subindent" : " ",
        ]
    )
)

The file agents/Makefile.am should be modified to have the sshd.scr added into the scrconf_DATA variable. This is the new version of agents/Makefile.am:

# Makefile.am for sshd/agents

agent_SCRIPTS =

scrconf_DATA = sshd.scr

EXTRA_DIST = $(agent_SCRIPTS) $(scrconf_DATA)

Run command sudo make install in the agents directory to get it installed into the /usr/share/YaST2/scrconf/ directory. Make sure, that the file has been copied there.

Every SCR Agent should have documented its functionality in the file header. Examples for every function are also very important. See the agent configuration.

For more information consult these agent's settings with the ini-agent documentation, please. This tutorial is not supposed to provide so complex information already described somewhere else.

2.7.1.4. Testing the SCR Agent

You can directly test the SCR Agent by running the y2base binary in the terminal with this command: /usr/lib/YaST2/bin/y2base stdio scr. Don't forget to watch your /var/log/YaST2/y2log file while testing.

  1. Start the y2base binary /usr/lib/YaST2/bin/y2base stdio scr returns:

    ([])
  2. Getting already configured options with command `Dir(.sshd) returns:

    (["Port", "PasswordAuthentication", "UsePAM", "X11Forwarding", "AcceptEnv", "AcceptEnv"])
  3. Reading the UsePAM option with command `Read(.sshd.UsePAM) returns:

    (["yes"])
  4. Reading all the Port options with command `Read(.sshd.Port) returns:

    (["22","33"])

Because this SCR Agent communicates using the standard I/O, you can replace the interactive call method with with the single command call using the pipe echo '`Read(.sshd.UsePAM)' | /usr/lib/YaST2/bin/y2base stdio scr which would return:

([])
(["yes"])