/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	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.

**********************************************************************/


#include	<stdlib.h>
#include	"memory_debug.h"
#include	"utils.h"
#include	"xl.h"
#include	"xl_server.h"

ACCOUNT *	user_acc;

int
insert_account(
	L_CHAR * group,
	L_CHAR * ltype,
	L_CHAR * user,
	L_CHAR * passwd)
{
ACCOUNT * ua;
AGENT * a;
	for ( ua = user_acc ; ua ; ua = ua->next )
		if ( l_strcmp(ua->group,group) == 0 &&
			l_strcmp(ua->login_type,ltype) == 0 &&
			l_strcmp(ua->user,user) == 0 ) {

			if ( ua->passwd )
				d_f_ree(ua->passwd);
			ua->passwd = ll_copy_str(passwd);
			return 0;
		}
	ua = d_alloc(sizeof(*ua));
	ua->group = ll_copy_str(group);
	ua->login_type = ll_copy_str(ltype);
	ua->user = ll_copy_str(user);
	ua->passwd = ll_copy_str(passwd);
	ua->next = user_acc;
	user_acc = ua;
	return 0;
}

int
check_account(L_CHAR * group,L_CHAR * ltype,L_CHAR *user,L_CHAR * passwd)
{
ACCOUNT * ua;
	for ( ua = user_acc ; ua ; ua = ua->next )
		if ( l_strcmp(ua->group,group) == 0 &&
			l_strcmp(ua->login_type,ltype) == 0 &&
			l_strcmp(ua->user,user) == 0 ) {
			if ( l_strcmp(ua->passwd,passwd) )
				return -1;
			return 0;
		}
	return -1;
}
