diff options
| author | Russ Allbery <rra@stanford.edu> | 2007-11-14 20:38:07 +0000 | 
|---|---|---|
| committer | Russ Allbery <rra@stanford.edu> | 2007-11-14 20:38:07 +0000 | 
| commit | dd7eea9a59493dc3e0664229d1ada10488aa78ed (patch) | |
| tree | f9dfc3f69fa9c66c21b97fd9a4adf1df1eddf21d /server | |
| parent | 16890a8c0ee6af63b6a54a8209bae4f2a095e644 (diff) | |
Add tests for the syslog logging in keytab-backend.
Diffstat (limited to 'server')
| -rwxr-xr-x | server/keytab-backend | 33 | 
1 files changed, 28 insertions, 5 deletions
| diff --git a/server/keytab-backend b/server/keytab-backend index 87868d5..a06c717 100755 --- a/server/keytab-backend +++ b/server/keytab-backend @@ -41,21 +41,45 @@ $KADMIN = '/usr/sbin/kadmin.local';  # A temporary area into which keytabs should be written.  $TMP = '/var/lib/keytabs'; -# Set to zero to suppress syslog logging, which is used only for testing. +# Set to zero to suppress syslog logging, which is used only for testing.  Set +# to a reference to a string to append messages to that string instead.  $SYSLOG = 1 unless defined $SYSLOG;  ##############################################################################  # Logging  ############################################################################## +# Initialize logging. +sub log_init { +    if (ref $SYSLOG) { +        $$SYSLOG = ''; +    } elsif ($SYSLOG) { +        openlog ('keytab-backend', 'pid', 'auth'); +    } +} +  # Log a failure message to both syslog and to stderr and exit with a non-zero  # status.  sub error {      my $message = join ('', @_); -    syslog ('err', '%s', $message) if $SYSLOG; +    if (ref $SYSLOG) { +        $$SYSLOG .= $message . "\n"; +    } elsif ($SYSLOG) { +        syslog ('err', '%s', $message); +    }      die "keytab-backend: $message\n";  } +# Log a regular message, generally for success. +sub info { +    my $message = join ('', @_); +    if (ref $SYSLOG) { +        $$SYSLOG .= $message . "\n"; +    } elsif ($SYSLOG) { +        syslog ('info', '%s', $message); +    } +} +  ##############################################################################  # Implementation  ############################################################################## @@ -66,7 +90,7 @@ sub error {  # not.  sub download {      my (@args) = @_; -    openlog ('keytab-backend', 'pid', 'auth') if $SYSLOG; +    log_init;      # Set up a default identity if run from the command line.      $ENV{REMOTE_USER} = getpwnam ($<) || 'UNKNOWN' unless $ENV{REMOTE_USER}; @@ -124,8 +148,7 @@ sub download {      print while <KEYTAB>;      close KEYTAB;      unlink $filename; -    syslog ('info', '%s', "keytab $principal retrieved by $ENV{REMOTE_USER}") -        if $SYSLOG; +    info ("keytab $principal retrieved by $ENV{REMOTE_USER}");  }  download (@ARGV);  __END__ | 
