unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

mkpasswd.c (2596B)

      1 /*
      2  *   IRC - Internet Relay Chat, src/modules/mkpasswd.c
      3  *   (C) 2001 The UnrealIRCd Team
      4  *
      5  *   mkpasswd command
      6  *
      7  *   See file AUTHORS in IRC package for additional names of
      8  *   the programmers.
      9  *
     10  *   This program is free software; you can redistribute it and/or modify
     11  *   it under the terms of the GNU General Public License as published by
     12  *   the Free Software Foundation; either version 1, or (at your option)
     13  *   any later version.
     14  *
     15  *   This program is distributed in the hope that it will be useful,
     16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     18  *   GNU General Public License for more details.
     19  *
     20  *   You should have received a copy of the GNU General Public License
     21  *   along with this program; if not, write to the Free Software
     22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     23  */
     24 
     25 #include "unrealircd.h"
     26 
     27 CMD_FUNC(cmd_mkpasswd);
     28 
     29 #define MSG_MKPASSWD 	"MKPASSWD"	
     30 
     31 ModuleHeader MOD_HEADER
     32   = {
     33 	"mkpasswd",
     34 	"5.0",
     35 	"command /mkpasswd", 
     36 	"UnrealIRCd Team",
     37 	"unrealircd-6",
     38     };
     39 
     40 MOD_INIT()
     41 {
     42 	CommandAdd(modinfo->handle, MSG_MKPASSWD, cmd_mkpasswd, MAXPARA, CMD_USER);
     43 	MARK_AS_OFFICIAL_MODULE(modinfo);
     44 	return MOD_SUCCESS;
     45 }
     46 
     47 MOD_LOAD()
     48 {
     49 	return MOD_SUCCESS;
     50 }
     51 
     52 MOD_UNLOAD()
     53 {
     54 	return MOD_SUCCESS;
     55 }
     56 
     57 /*
     58 ** cmd_mkpasswd
     59 **      parv[1] = password to encrypt
     60 */
     61 CMD_FUNC(cmd_mkpasswd)
     62 {
     63 	short type;
     64 	const char *result = NULL;
     65 
     66 	if (!MKPASSWD_FOR_EVERYONE && !IsOper(client))
     67 	{
     68 		sendnumeric(client, ERR_NOPRIVILEGES);
     69 		return;
     70 	}
     71 	if (!IsOper(client))
     72 	{
     73 		/* Non-opers /mkpasswd usage: lag them up, and send a notice to eyes snomask.
     74 		 * This notice is always sent, even in case of bad usage/bad auth methods/etc.
     75 		 */
     76 		add_fake_lag(client, 7000);
     77 		unreal_log(ULOG_INFO, "mkpasswd", "MKPASSWD_COMMAND", client,
     78 		           "mkpasswd command used by $client.details");
     79 	}
     80 
     81 	if ((parc < 3) || BadPtr(parv[2]))
     82 	{
     83 		sendnotice(client, "*** Syntax: /mkpasswd <authmethod> :parameter");
     84 		return;
     85 	}
     86 	/* Don't want to take any risk ;p. -- Syzop */
     87 	if (strlen(parv[2]) > 64)
     88 	{
     89 		sendnotice(client, "*** Your parameter (text-to-hash) is too long.");
     90 		return;
     91 	}
     92 	if ((type = Auth_FindType(NULL, parv[1])) == -1)
     93 	{
     94 		sendnotice(client, "*** %s is not an enabled authentication method", parv[1]);
     95 		return;
     96 	}
     97 
     98 	if (!(result = Auth_Hash(type, parv[2])))
     99 	{
    100 		sendnotice(client, "*** Authentication method %s failed", parv[1]);
    101 		return;
    102 	}
    103 
    104 	sendnotice(client, "*** Authentication phrase (method=%s, para=%s) is: %s",
    105 		parv[1], parv[2], result);
    106 }