⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htaabrow.c

📁 elinks下lynx是最重要的二个文本浏览器, 在linux下非常实用, lynx比elinks早的多, 目前好像停止开发, 这是lynx源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* MODULE							HTAABrow.c**		BROWSER SIDE ACCESS AUTHORIZATION MODULE****	Contains the code for keeping track on server hostnames,**	port numbers, scheme names, usernames, passwords**	(and servers' public keys).**** IMPORTANT:**	Routines in this module use dynamic allocation, but free**	automatically all the memory reserved by them.****	Therefore the caller never has to (and never should)**	free() any object returned by these functions.****	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.****	This also makes it easy to plug the AA package in:**	you don't have to ponder whether to free() something**	here or is it done somewhere else (because it is always**	done somewhere else).****	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.****	The AA package does not free() anything else than what**	it has itself allocated.**** AUTHORS:**	AL	Ari Luotonen	luotonen@dxcern.cern.ch**** HISTORY:**	Oct 17	AL	Made corrections suggested by marca:**			Added  if (!realm->username) return NULL;**			Changed some ""s to NULLs.**			Now doing calloc() to init uuencode source;**			otherwise HTUU_encode() reads uninitialized memory**			every now and then (not a real bug but not pretty).**			Corrected the formula for uuencode destination size.**** 28 Apr 1997	AJL	Do Proxy Authorisation.**** BUGS:*****/#include <HTUtils.h>#include <HTString.h>#include <HTParse.h>		/* URL parsing function		*/#include <HTList.h>		/* HTList object		*/#include <HTAlert.h>		/* HTConfirm(), HTPrompt()	*/#include <HTAAUtil.h>		/* AA common to both sides	*/#include <HTAssoc.h>		/* Assoc list			*/#include <HTAccess.h>		/* Are we using an HTTP gateway? */#include <HTAABrow.h>		/* Implemented here		*/#include <HTUU.h>		/* Uuencoding and uudecoding	*/#include <LYLeaks.h>/***  Local datatype definitions****  HTAAServer contains all the information about one server.*/typedef struct {    char *	hostname;	/* Host's name			*/    int		portnumber;	/* Port number			*/    BOOL	IsProxy;	/* Is it a proxy?		*/    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 {    HTAAServer *server;		/* Which server serves this tree	     */    char *	template;	/* Template for this tree		     */    HTList *	valid_schemes;	/* Valid authentic.schemes		     */    HTAssocList**scheme_specifics;/* Scheme specific params		     */    BOOL	retry;		/* Failed last time -- reprompt (or whatever)*/} HTAASetup;/***  Information about usernames and passwords in**  Basic and Pubkey authentication schemes;*/typedef struct {    char *	realmname;	/* Password domain name		*/    char *	username;	/* Username in that domain	*/    char *	password;	/* Corresponding password	*/} HTAARealm;/***  To free off all globals. - FM*/PRIVATE void free_HTAAGlobals NOPARAMS;PRIVATE BOOL free_HTAAGlobalsSet = FALSE;PRIVATE char *HTAA_composeAuthResult = NULL;PRIVATE char *compose_auth_stringResult = NULL;	/* Uuencoded presentation *//***  Module-wide global variables*/PRIVATE HTList *server_table	= NULL;	/* Browser's info about servers	     */PRIVATE char *secret_key	= NULL;	/* Browser's latest secret key       */PRIVATE HTAASetup *current_setup= NULL;	/* The server setup we are currently */					/* talking to			     */PRIVATE char *current_hostname	= NULL;	/* The server's name and portnumber  */PRIVATE int current_portnumber	= 80;	/* where we are currently trying to  */					/* connect.			     */PRIVATE char *current_docname	= NULL; /* The document's name we are	     */					/* trying to access.		     */PRIVATE char *HTAAForwardAuth	= NULL;	/* Authorization: line to forward    */					/* (used by gateway httpds)	     */PRIVATE HTAASetup *proxy_setup	= NULL;	/* Same as above, but for Proxy -AJL */PRIVATE char *proxy_hostname	= NULL;PRIVATE char *proxy_docname	= NULL;PRIVATE int proxy_portnumber	= 80;/*** HTAAForwardAuth for enabling gateway-httpds to forward Authorization ***/PUBLIC void HTAAForwardAuth_set ARGS2(	CONST char *,	scheme_name,	CONST char *,	scheme_specifics){    int len = 20 + (scheme_name      ? strlen(scheme_name)      : 0)		 + (scheme_specifics ? strlen(scheme_specifics) : 0);    FREE(HTAAForwardAuth);    if ((HTAAForwardAuth = typecallocn(char, len)) == 0)	outofmem(__FILE__, "HTAAForwardAuth_set");    strcpy(HTAAForwardAuth, "Authorization: ");    if (scheme_name) {	strcat(HTAAForwardAuth, scheme_name);	strcat(HTAAForwardAuth, " ");	if (scheme_specifics) {	    strcat(HTAAForwardAuth, scheme_specifics);	}    }}PUBLIC void HTAAForwardAuth_reset NOARGS{    FREE(HTAAForwardAuth);}/**************************** HTAAServer ***********************************/PRIVATE void HTAASetup_delete PARAMS((HTAASetup * killme));	/* Forward *//* PRIVATE						HTAAServer_new()**		ALLOCATE A NEW NODE TO HOLD SERVER INFO**		AND ADD IT TO THE LIST OF SERVERS** ON ENTRY:**	hostname	is the name of the host that the server**			is running in.**	portnumber	is the portnumber which the server listens.**	IsProxy		should be TRUE if this is a proxy.**** ON EXIT:**	returns		the newly-allocated node with all the strings**			duplicated.**			Strings will be automatically freed by**			the function HTAAServer_delete(), which also**			frees the node itself.*/PRIVATE HTAAServer *HTAAServer_new ARGS3(	CONST char*,	hostname,	int,		portnumber,	BOOL,		IsProxy){    HTAAServer *server;    if ((server = typecalloc(HTAAServer)) == 0)	outofmem(__FILE__, "HTAAServer_new");    server->hostname	= NULL;    server->portnumber	= (portnumber > 0 ? portnumber : 80);    server->IsProxy	= IsProxy;    server->setups	= HTList_new();    server->realms	= HTList_new();    if (hostname)	StrAllocCopy(server->hostname, hostname);    if (!server_table)	server_table = HTList_new();    HTList_addObject(server_table, (void*)server);    return server;}/* PRIVATE						HTAAServer_delete()****	DELETE THE ENTRY FOR THE SERVER FROM THE HOST TABLE,**	AND FREE THE MEMORY USED BY IT.**** ON ENTRY:**	killme		points to the HTAAServer to be freed.**** ON EXIT:**	returns		nothing.*/PRIVATE void HTAAServer_delete ARGS1(	HTAAServer *,	killme){    int n, i;    HTAASetup *setup;    HTAARealm *realm;    HTList *cur;    if (killme) {	if (killme->setups != NULL) {	    n = HTList_count(killme->setups);	    for (i = (n - 1); i >= 0; i--) {		if ((setup = (HTAASetup*)HTList_objectAt(killme->setups,							 i)) != NULL) {		    HTAASetup_delete(setup);		    setup = NULL;		}	    }	    HTList_delete(killme->setups);	    killme->setups = NULL;	}	cur = killme->realms;	while (NULL != (realm = (HTAARealm*)HTList_nextObject(cur))) {	    FREE(realm->realmname);	    FREE(realm->username);	    FREE(realm->password);	    FREE(realm);	}	HTList_delete(killme->realms);	killme->realms = NULL;	FREE(killme->hostname);	HTList_removeObject(server_table, (void*)killme);	FREE(killme);    }}/* PRIVATE						HTAAServer_lookup()**		LOOK UP SERVER BY HOSTNAME AND PORTNUMBER** ON ENTRY:**	hostname	obvious.**	portnumber	if non-positive defaults to 80.**	IsProxy		should be TRUE if this is a proxy.****	Looks up the server in the module-global server_table.**** ON EXIT:**	returns		pointer to a HTAAServer structure**			representing the looked-up server.**			NULL, if not found.*/PRIVATE HTAAServer *HTAAServer_lookup ARGS3(	CONST char *,	hostname,	int,		portnumber,	BOOL,		IsProxy){    if (hostname) {	HTList *cur = server_table;	HTAAServer *server;	if (portnumber <= 0)	    portnumber = 80;	while (NULL != (server = (HTAAServer*)HTList_nextObject(cur))) {	    if (server->portnumber == portnumber  &&		0==strcmp(server->hostname, hostname) &&		server->IsProxy == IsProxy)		return server;	}    }    return NULL;	/* NULL parameter, or not found */}/*************************** HTAASetup *******************************//* PRIVATE						HTAASetup_lookup()**	FIGURE OUT WHICH AUTHENTICATION SETUP THE SERVER**	IS USING FOR A GIVEN FILE ON A GIVEN HOST AND PORT**** ON ENTRY:**	hostname	is the name of the server host machine.**	portnumber	is the port that the server is running in.**	docname		is the (URL-)pathname of the document we**			are trying to access.**	IsProxy		should be TRUE if this is a proxy.****	This function goes through the information known about**	all the setups of the server, and finds out if the given**	filename resides in one of the protected directories.**** ON EXIT:**	returns		NULL if no match.**			Otherwise, a HTAASetup structure representing**			the protected server setup on the corresponding**			document tree.***/PRIVATE HTAASetup *HTAASetup_lookup ARGS4(	CONST char *,	hostname,	int,		portnumber,	CONST char *,	docname,	BOOL,		IsProxy){    HTAAServer *server;    HTAASetup *setup;    if (portnumber <= 0)	portnumber = 80;    if (hostname && docname && *hostname && *docname &&	NULL != (server = HTAAServer_lookup(hostname,					    portnumber,					    IsProxy))) {	HTList *cur = server->setups;	CTRACE((tfp, "%s %s (%s:%d:%s)\n",		    "HTAASetup_lookup: resolving setup for",		    (IsProxy ? "proxy" : "server"),		    hostname, portnumber, docname));	while (NULL != (setup = (HTAASetup*)HTList_nextObject(cur))) {	    if (HTAA_templateMatch(setup->template, docname)) {		CTRACE((tfp, "%s `%s' %s `%s'\n",			    "HTAASetup_lookup:", docname,			    "matched template", setup->template));		return setup;	    } else {		CTRACE((tfp, "%s `%s' %s `%s'\n",			    "HTAASetup_lookup:", docname,			    "did NOT match template", setup->template));	    }	} /* while setups remain */    } /* if valid parameters and server found */    CTRACE((tfp, "%s `%s' %s\n",		 "HTAASetup_lookup: No template matched",		 NONNULL(docname),		 "(so probably not protected)"));    return NULL;	/* NULL in parameters, or not found */}/* PRIVATE						HTAASetup_new()**			CREATE A NEW SETUP NODE** ON ENTRY:**	server		is a pointer to a HTAAServer structure**			to which this setup belongs.**	template	documents matching this template**			are protected according to this setup.**	valid_schemes	a list containing all valid authentication**			schemes for this setup.**			If NULL, all schemes are disallowed.**	scheme_specifics is an array of assoc lists, which**			contain scheme specific parameters given**			by server in Authenticate: fields.**			If NULL, all scheme specifics are**			set to NULL.** ON EXIT:**	returns		a new HTAASetup node, and also adds it as**			part of the HTAAServer given as parameter.*/PRIVATE HTAASetup *HTAASetup_new ARGS4(	HTAAServer *,	server,	char *,		template,	HTList *,	valid_schemes,	HTAssocList **,	scheme_specifics){    HTAASetup *setup;    if (!server || isEmpty(template))	return NULL;    if ((setup = typecalloc(HTAASetup)) == 0)	outofmem(__FILE__, "HTAASetup_new");    setup->retry = NO;    setup->server = server;    setup->template = NULL;    if (template)	StrAllocCopy(setup->template, template);    setup->valid_schemes = valid_schemes;    setup->scheme_specifics = scheme_specifics;    HTList_addObject(server->setups, (void*)setup);    return setup;}/* PRIVATE						HTAASetup_delete()**			FREE A HTAASetup STRUCTURE** ON ENTRY:**	killme		is a pointer to the structure to free().**** ON EXIT:**	returns		nothing.*/PRIVATE void HTAASetup_delete ARGS1(	HTAASetup *,	killme){    int scheme;    if (killme) {	FREE(killme->template);	if (killme->valid_schemes) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -