File:  [Public] / libwww / Library / src / HTAABrow.html
Revision 2.18: download - view: text, annotated - select for diffs
Tue Sep 12 23:37:51 1995 UTC (28 years, 8 months ago) by frystyk
Branches: MAIN
CVS tags: v4/0pre5, v4/0pre4, v4/0pre3, HEAD
Most of new version

<HEAD>
<TITLE>Browser side Access Auth</TITLE>
<!-- Changed by: Henrik Frystyk Nielsen,  5-Sep-1995 -->
</HEAD>
<BODY>

<H1>Browser Side Access Authorization Module</H1>

<PRE>
/*
**	(c) COPYRIGHT MIT 1995.
**	Please first read the full copyright statement in the file COPYRIGH.
*/
</PRE>

This module is the browser side interface to Access Authorization (AA)
package.  It contains code only for browser.<P>

<B>Important</B> to know about memory allocation:<P>

Routines in this module use dynamic allocation, but free automatically
all the memory reserved by them.<P>

Therefore the caller never has to (and never should)
<CODE>free()</CODE> any object returned by these functions.<P>

Therefore also all the strings returned by this package are only valid
until the next call to the same function is made. This approach is
selected, because of the nature of access authorization: no string
returned by the package needs to be valid longer than until the next
call.<P>

This also makes it easy to plug the AA package in: you don't have to
ponder whether to <CODE>free()</CODE> something here or is it done
somewhere else (because it is always done somewhere else).<P>

The strings that the package needs to store are copied
so the original strings given as parameters to AA
functions may be freed or modified with no side effects.<P>

<B>Also note:</B> The AA package does not <CODE>free()</CODE> anything
else than what it has itself allocated.  <P>

This module is implemented by <A HREF="HTAABrow.c">HTAABrow.c</A>, and
it is a part of the <A
HREF="http://www.w3.org/pub/WWW/Library/">
W3C Reference Library</A>.

<PRE>
#ifndef HTAABROW_H
#define HTAABROW_H
#include "HTAAUtil.h"
#include "HTList.h"
#include "HTAssoc.h"
#include "HTReq.h"

/*
** Local datatype definitions
**
** HTAAServer contains all the information about one server.
*/
typedef struct _HTAAServer {

    char *	hostname;	/* Host's name			*/
    int		portnumber;	/* Port number			*/
    HTList *	setups;		/* List of protection setups	*/
                                /* on this server; i.e. valid	*/
                                /* authentication schemes and	*/
                                /* templates when to use them.	*/
                                /* This is actually a list of	*/
                                /* HTAASetup objects.		*/
    HTList *	realms;		/* Information about passwords	*/
} HTAAServer;


/*
** HTAASetup contains information about one server's one
** protected tree of documents.
*/
typedef struct _HTAASetup {
    HTAAServer *server;		/* Which server serves this tree	     */
    char *	tmplate;	/* Template for this tree		     */
    HTList *	valid_schemes;	/* Valid authentic.schemes   		     */
    HTAssocList**scheme_specifics;/* Scheme specific params		     */
    BOOL	reprompt;	/* Failed last time -- reprompt (or whatever)*/
} HTAASetup;


/*
** Information about usernames and passwords in
** Basic and Pubkey authentication schemes;
*/
typedef struct _HTAARealm {
    char *	realmname;	/* Password domain name		*/
    char *	username;	/* Username in that domain	*/
    char *	password;	/* Corresponding password	*/
} HTAARealm;
</PRE>

<H2>Routines for Browser Side Recording of AA Info</H2>

Most of the browser-side AA is done by the following two functions
(which are called from file <CODE>HTTP.c</CODE> so the browsers using
<CODE>libwww</CODE> only need to be linked with the new library and not
be changed at all):
<UL>

<LI><CODE>HTAA_composeAuth()</CODE> composes the
<CODE>Authorization:</CODE> line contents, if the AA package thinks
that the given document is protected. Otherwise this function returns
NULL.  This function also calls the functions <CODE>HTPrompt(),</CODE>
<CODE>HTPromptPassword()</CODE> and <CODE>HTConfirm()</CODE> to get
the username, password and some confirmation from the user.

<LI><CODE>HTAA_shouldRetryWithAuth()</CODE> determines whether to
retry the request with AA or with a new AA (in case username or
password was misspelled).

</UL>
<PRE>
/* BROWSER PUBLIC					HTAA_composeAuth()
**
**	COMPOSE Authorization: HEADER LINE CONTENTS
**	IF WE ALREADY KNOW THAT THE HOST REQUIRES AUTHENTICATION
**
** ON ENTRY:
**	req		request, which contains
**	req->argument	document, that we're trying to access.
**	req->setup	protection setup info on browser.
**	req->scheme	selected authentication scheme.
**	req->realm	for Basic scheme the username and password.
**
** ON EXIT:
**	returns	NO, if no authorization seems to be needed, and
**		req->authorization is NULL.
**		YES, if it has composed Authorization field,
**		in which case the result is in req->authorization,
**		e.g.
**
**		   "Basic AkRDIhEF8sdEgs72F73bfaS=="
*/
extern BOOL HTAA_composeAuth PARAMS((HTRequest * req));


/* BROWSER PUBLIC					HTAA_retryWithAuth()
**
**		RETRY THE SERVER WITH AUTHORIZATION (OR IF
**		ALREADY RETRIED, WITH A DIFFERENT USERNAME
**		AND/OR PASSWORD (IF MISSPELLED)) OR CANCEL
** ON ENTRY:
**	req		request.
**	req-&gt;valid_schemes
**			This function should only be called when
**			server has replied with a 401 (Unauthorized)
**			status code, and req structure has been filled
**			up according to server reply, especially the
**			req->valid_shemes list must have been set up
**			according to WWW-Authenticate: headers.
**	callback	the function to call when username and
**			password have been entered (HTLoadHTTP()).
** ON EXIT:
**	On GUI clients pops up a username/password dialog box
**	with "Ok" and "Cancel".
**	"Ok" button press should do a callback
**
**		HTLoadHTTP(req);
**
**	This actually done by function HTPasswordDialog(),
**	which GUI clients redefine.
**
**	returns		YES, if dialog box was popped up.
**			NO, on failure.
*/
extern BOOL HTAA_retryWithAuth PARAMS((HTRequest *	req));


/* PUPLIC						HTAA_cleanup()
**
**	Free the memory used by the entries concerning Access Authorization
**	in the request structure and put all pointers to NULL
**	Henrik 14/03-94.
**
** ON ENTRY:
**	req		the request structure
**
** ON EXIT:
**	returns		nothing.
*/
extern void HTAACleanup PARAMS((HTRequest *req));
</PRE>

<H2>Enabling Gateway httpds to Forward Authorization</H2>
These functions should only be called from daemon code, and
<CODE>HTAAForwardAuth_reset()</CODE> must be called before the next
request is handled to make sure that authorization string
isn't cached in daemon so that other people can access private
files using somebody elses previous authorization information.
<PRE>
extern void HTAAForwardAuth_set PARAMS((CONST char * scheme_name,
					CONST char * scheme_specifics));
extern void HTAAForwardAuth_reset NOPARAMS;
</PRE>

<PRE>
#endif	/* NOT HTAABROW_H */
</PRE>
End of file HTAABrow.h.
</BODY>

Webmaster