# =====================================================================
# grant: Web user sample authentication module.
#
# Copyright (c) 2002,2003,2004 Carlo Strozzi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or   
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License   
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# =====================================================================

# *********************************************************************
#			Local functions
# *********************************************************************

# NONE

# *********************************************************************
#			Main program
# *********************************************************************

HTTP_AUTHORIZATION = ()			# *Always* clear any old auth.

# Load GET/POST arguments, if any.
csaGetArgs

# The authCheck function is application-specific, and must be provided
# by the application programmer. The one used here is only an example,
# and uses flat ASCII tables as the user database. See the CSA
# documentation for more.

authCheck || csaExit.fault	# In case authCheck isn't defined.

# Set new auth, after the authorization check has been passed.

HTTP_AUTHORIZATION='Basic '^`{
   echo -n $CSA_AUTH_USER:$CSA_AUTH_PW | swu-encdec -e -b
}

csaPrintMsg 0014				# Log the event.

# The proper (i.e. RESTful) way of displaying the authentication
# successful page is through redirection.

csaExit.location $CSA_RPC_URL'?0='$CSA_ID'.hello-world'

# End of program.
