/*
 * Copyright (c) 1996-2007, OpenFWTK Development Group
 * All rights reserved. See LICENSE.
 */

#include	<string.h>
#include	"firewall.h"
#include	"auth.h"

static	char	*moduleId ATTR_UNUSED = "$Id: proto.c,v 1.6 2007/09/10 02:49:12 arkenoi Exp $";

extern  size_t strlcat(char*,const char*,size_t);
extern  size_t strlcpy(char*,const char*,size_t);

#ifdef	AUTHPROTO_PASSWORD
extern	int	passverify(), passset();
#endif

#ifdef	AUTHPROTO_SKEY
extern	int	s_keychallng(), s_keyverify(), s_keyset(), 
		s_keyset_md4(), s_keyset_md5(), s_keyset_sha1(), s_keyset_rmd160();
#endif

#ifdef	AUTHPROTO_SNK
extern	int	snkchallng(), snkverify(), snkset();
#endif

#ifdef	AUTHPROTO_SECURID
extern	int	secichallng(), seciverify(), seciset();
#endif

#ifdef  AUTHPROTO_MDAUTH
extern  int	mdauthchallng(), mdauthverify(), mdauthset();
#endif

#ifdef	AUTHPROTO_CRYPTOC
extern	int	ccchallng(), ccverify(), ccauthset();
#endif

AProto aprototab[] = {
{	'0',	"none",		0,		0,		0	      },
#ifdef	AUTHPROTO_PASSWORD
{	'p',	"password",	0,		passverify,	passset       },
#endif
#ifdef	AUTHPROTO_SKEY
{	's',	"Skey-md4",	s_keychallng,	s_keyverify,	s_keyset_md4  },
{	'5',	"Skey-md5",	s_keychallng,	s_keyverify,	s_keyset_md5  },
{	'1',	"Skey-SHA1",	s_keychallng,	s_keyverify,	s_keyset_sha1 },
{	'r',	"Skey-rmd160",	s_keychallng,	s_keyverify,   s_keyset_rmd160},
#endif
#ifdef	AUTHPROTO_SNK
{	'd',	"Snk",		snkchallng,	snkverify,	snkset        },
#endif
#ifdef	AUTHPROTO_SECURID
{	'S',	"SecurID",	secichallng,	seciverify,	seciset       },
#endif
#ifdef	AUTHPROTO_MDAUTH
{	'm',	"MDauth",	mdauthchallng,	mdauthverify,	mdauthset     },
#endif
#ifdef	AUTHPROTO_CRYPTOC
{	'c',	"CryptoCard",	ccchallng,	ccverify,	ccauthset     },
#endif
{	0,	0,		0,		0,		0	      }
};



AProto	*
codetoproto(c)
char	c;
{
	AProto	*ap;
	for(ap = aprototab; ap->name != (char *)0; ap++)
		if(ap->typ == c)
			return(ap);
	return((AProto *)0);
}



AProto	*
nametoproto(c)
char	*c;
{
	AProto	*ap;
	int	l;

	l = strlen(c);
	for(ap = aprototab; ap->name != (char *)0; ap++)
		if(!strncasecmp(ap->name,c,l))
			return(ap);
	return((AProto *)0);
}


void
getprotolist(b,bs)
char	*b;
int	bs;
{
	int	l = 0;
	int	x;
	AProto	*ap;

	for(ap = aprototab; ap->name != (char *)0; ap++) {
		x = strlen(ap->name);
		if(x + l >= bs - 2) {
			b[l] = '\0';
			return;
		}
		if(l > 0)
			b[l++] = ' ';
		strlcpy(&b[l],ap->name,bs - l);
		l += x;
	}
	b[l] = '\0';
}
