#! /usr/bin/perl
# fixscript will replace this line with require innshellvars.pl

# Example wrapper nnrpd_auth.pl for support of old perl authentication
# scripts, by Erik Klavon.

# This file contains a sample perl script which can be used to
# duplicate the behavior of the old nnrpperlauth functionality. This
# script only supports authentication.

# How to use this wrapper:
# - append your old script to this file with two changes:
# - rename the old "auth_init" sub to "old_auth_init"
# - rename the old "authenticate" sub to "old_authenticate"


# auth_init
# This sub simply calls old_auth_init
# Comment this out if you don't need auth_init

sub auth_init {
    old_auth_init();
}


# authenticate
# This sub modifies the global hash attributes so that it has all the
# entries required in the old way of doing things, calls
# old_authenticate, and transforms the return array into the new
# format.

sub authenticate {
    $attributes{type} = "authenticate";
    my @auth_array = old_authenticate();
    my @return_array;

    # copy return code
    $return_array[0] = $auth_array[0];

    # simple error report
    if ($auth_array[0] != 281) {
        $return_array[1] = "Perl authentication error!";
        return @return_array;
    } else {
        $return_array[1] = "";
    }

    return @return_array;
}
