/************************************************************************
 *   IRC - Internet Relay Chat, modules/m_pass.c
 *
 *   Copyright (C) 2000-2003 TR-IRCD Development
 *
 *   Copyright (C) 1990 Jarkko Oikarinen and
 *                      University of Oulu, Co Center
 *
 *   See file AUTHORS in IRC package for additional names of
 *   the programmers.
 *
 *   This program is free softwmare; 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, 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.
 */

/* $Id: m_pass.c,v 1.3 2003/06/14 13:55:51 tr-ircd Exp $ */

#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include "h.h"

static struct Message _msgtab[] = {
    {MSG_PASS, 0, MAXPARA, M_SLOW, 0L,
     m_pass, m_ignore, m_ignore, m_ignore, m_ignore}
};

#ifndef STATIC_MODULES

char *_version = "$Revision: 1.3 $";

void _modinit(void)
{
    mod_add_cmd(_msgtab);
}

void _moddeinit(void)
{
    mod_del_cmd(_msgtab);
}
#else
void m_pass_init(void)
{
    mod_add_cmd(_msgtab);
}
#endif

/*
 * struct PwdItem {
 *  char *linepass;
 *  char *fakehost_override;   
 *  char *nspass;    
 *  char *langstring;      
 * };
 */

/*
 * m_pass() - Added Sat, 4 March 1989
 * * m_pass * parv[0] = sender prefix *       parv[1] = password *
 * parv[2] = optional extra version information
 */
int m_pass(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
    char *password = parc > 1 ? parv[1] : NULL;
    char *p = NULL;
    char *tmptext = NULL;

    if (BadPtr(password)) {
	send_me_numeric(cptr, ERR_NEEDMOREPARAMS, MSG_PASS);
	return 0;
    }
    if ((!IsUnknown(cptr) && !IsHandshake(cptr))) {
	send_me_numeric(cptr, ERR_ALREADYREGISTRED);
	return 0;
    }
    strlcpy_irc(cptr->passwd, password, sizeof(cptr->passwd));

    if (parc > 2) {
    int l = strlen(parv[2]);

	if (l < 2)
	    return 0;
	if (parv[2][0] == 'T' && parv[2][1] == 'S') {
	    cptr->tsval = (long) TS_DOESTS;
	    if (parv[2][2] == '7')
		cptr->protoflags |= PFLAGS_TS7;
	}
    }

    cptr->nspass[0] = '\0';
    cptr->langstring[0] = '\0';
    cptr->fakehost_override[0] = '\0';

    tmptext = strtoken(&p, password, ":");
    if (tmptext) {
	strlcpy_irc(cptr->passwd, tmptext, sizeof(cptr->passwd));
	tmptext = strtoken(&p, NULL, ":");
	if (tmptext) {
	    strlcpy_irc(cptr->nspass, tmptext, sizeof(cptr->nspass));
	    tmptext = strtoken(&p, NULL, ":");
	    if (tmptext) {
		strlcpy_irc(cptr->langstring, tmptext, sizeof(cptr->langstring));
		tmptext = strtoken(&p, NULL, ":");
		if (tmptext) {
		    strlcpy_irc(cptr->fakehost_override, tmptext,
			    sizeof(cptr->fakehost_override));
		}
	    }
	}
    }

    return 0;
}


syntax highlighted by Code2HTML, v. 0.9.1