IBM Books

Administration Guide


Developing a Sysctl application

Creating a Sysctl application consists of the following basic steps:

  1. Examine what you are trying to do and divide it among client-server lines. The server side runs as root. The client side typically does not require root authority, but might require that the user has logged in as appropriate for the authentication method that is in use.
  2. Define the client-server interface. This consists of Sysctl command names and their arguments, return values, and authorizations.
  3. Code the server commands. This consists of Tcl code that performs your task, as well as callback authorizations if you do not use one of the supplied ones. The Tcl code may be simple (such as a wrapper around an AIX command or script) or elaborate (a detailed Tcl program).
    Note:
    The stdout and stderr output of scripts called from a Tcl procedure might not automatically be routed back to the client user's terminal. For an example of how to ensure that stdout and stderr are returned to the client, see how /etc/root_script is used in the procedure adminscript.
  4. Code the client side. This typically gathers any necessary information and then issues the sysctl command to cause the servers to perform the desired action. This can be a GUI, Perl or shell script. Note that client side code may not always be necessary. In some cases, issuing the sysctl command directly from the command line is sufficient.
  5. If the authorization scheme requires changes to existing ACL files or new ACL files, these changes must be made, and the changed files distributed.
  6. Register the new server command with each node's sysctld daemon by restarting the daemons with updated configuration files.

Here is an example of how to write a Sysctl application that allows a user to execute a script including some commands requiring root execution privileges on all the nodes in an SP system in parallel. The user is not required to know any of the root passwords, but must be listed in an ACL specifically set up to authorize use of the script. A copy of this ACL resides on each node. The script containing the commands executable only by root is called /etc/root_script. Assume that /etc/root_script accepts a single argument, and that this script resides on each node.

The server side of the application does the root part of the job, which is to issue the /etc/root_script command with the correct arguments on behalf of authorized users. It first needs to determine if the client is authorized based on an authorization policy. As mentioned above, authorization is based on an access control list. There are no return values, but an error message is displayed when the user is not authorized to run the command. stdout and stderr are returned to the client.

The server command resides in /etc/sysctl/apps/adminscript and is coded as follows:

create proc adminscript {argument} AUTH {
        global SCPRINCIPAL
        if [aclcheck -f /etc/sysctl.adminscript.acl $SCPRINCIPAL] {
                puts "[exec /etc/root_script $argument]"
                return
        }
        puts "Not authorized to run adminscript"
}

The first line creates a new Sysctl procedure called adminscript. One argument is accepted, which will be passed unchanged to /etc/root_script. This procedure uses the provided AUTH authorization callback, which means that only authenticated clients can execute the command.

The second line issues the Tcl global command to provide the content of the SCPRINCIPAL variable to other Sysctl commands. (This is needed because SCPRINCIPAL is passed as an argument to aclcheck later.) The SCPRINCIPAL variable is the authenticated identity of the command issuer and is one of the variables set by the server and available to procedures and callbacks. See the Sysctld daemon information in the book PSSP: Command and Technical Reference for a list of all the variables.

The third line is Tcl code that uses the built-in aclcheck command to see if the user is in the ACL (/etc/sysctl.adminscript.acl) set up for this command. If the user is authorized, the program issues the /etc/root_script command with the supplied argument and then returns. If the user is not authorized, the program issues an error message. The program returns any output (information from /etc/root_script command or the error message) to the client user's terminal.

Note that in this example, further authorization checking is done in the body of the procedure after the authorization callback has completed. This is to demonstrate the use of the SCUSER variable provided by the server to procedures. Alternatively, this check could have been made part of the authorization callback itself.

The client side of the application needs to find out the necessary information to provide to the servers. It does not require root authority to be issued. The information in this case includes the single argument to be passed through to /etc/root_script. The client also needs to determine the hostnames of all the nodes in the SP System, so that the command can be sent to and run in parallel on all the nodes.

The client side is coded as follows in /usr/bin/doadminscript:

#!/usr/lpp/ssp/perl/bin/perl
 
# Run /etc/root_script on all the SP nodes in parallel by invoking
# the adminscript sysctl command on all the nodes. Invoke via:
# doadminscript arg_to_root_script
 
$#ARGV > 1 && die "too many arguments";
 
exec "/usr/lpp/ssp/bin/hostlist -av |
      /usr/bin/sysctl -c - adminscript $ARGV[0]";

The first line checks for extraneous arguments. The exec statement uses the SP hostlist command to write all the currently responding hostnames in the SP System to stdout. The single argument to adminscript is passed along to the Sysctl adminscript server command.

A new ACL file needs to be put on each node in the system. The file /etc/sysctl.adminscript.acl looks like this:

#acl#
# These are the users that can issue the adminscript command on this
# node:
_principal root@HPSSL.KGN.IBM.COM
_principal newbie@HPSSL.KGN.IBM.COM
_principal guru@HPSSL.KGN.IBM.COM

Note that each node can authorize different users to run the new command. In this case, assume that the ACL will be the same on all nodes. To distribute the ACL file to all the responding nodes, an authorized user enters the following (see the pcp man page for details):

pcp "-av" /etc/sysctl.adminscript.acl

In addition, the /etc/sysctl.conf file needs to be updated to include the new command. If the server code is to reside in /etc/sysctl/apps directory, the following lines can be added to /etc/sysctl.conf:

# Add the adminscript application
include /etc/sysctl/apps/adminscript

The updated sysctl.conf file and the actual server code need to be distributed:

pcp "-av" /etc/sysctl.conf
pcp "-av" /etc/sysctl/apps/adminscript

Now the servers need to be restarted to include the updated sysctl.conf file. Note that the following command requires ACL authorization:

hostlist -av | sysctl -c - svcrestart

Now, any of the users in /etc/sysctl.adminscript.acl (root, newbie, or guru) can run /etc/root_script with the argument mikef on all the nodes simultaneously by entering the following command:

doadminscript mikef

Authorization variables

Variables are set by the server based on information on the client provided by SP security services. Authorization callbacks and Tcl scripts have access to these variables. See "Sysctld (daemon)" in the book PSSP: Command and Technical Reference for a list of all the authorization variables.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]