2 * m_mkpasswd.c: Encrypts a password online, DES or MD5.
4 * Copyright 2002 W. Campbell and the ircd-ratbox development team
5 * Based on mkpasswd.c, originally by Nelson Minar (minar@reed.edu)
7 * You can use this code in any way as long as these names remain.
9 * $Id: m_mkpasswd.c 3161 2007-01-25 07:23:01Z nenolod $
12 /* List of ircd includes from ../include/ */
15 #include "common.h" /* FALSE bleah */
19 #include "s_newconf.h"
30 static int m_mkpasswd(struct Client
*client_p
, struct Client
*source_p
,
31 int parc
, const char *parv
[]);
32 static int mo_mkpasswd(struct Client
*client_p
, struct Client
*source_p
,
33 int parc
, const char *parv
[]);
34 static char *make_salt(void);
35 static char *make_md5_salt(void);
37 static char saltChars
[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
40 struct Message mkpasswd_msgtab
= {
41 "MKPASSWD", 0, 0, 0, MFLG_SLOW
,
42 {mg_unreg
, {m_mkpasswd
, 2}, mg_ignore
, mg_ignore
, mg_ignore
, {mo_mkpasswd
, 2}}
45 mapi_clist_av1 mkpasswd_clist
[] = { &mkpasswd_msgtab
, NULL
};
47 DECLARE_MODULE_AV1(mkpasswd
, NULL
, NULL
, mkpasswd_clist
, NULL
, NULL
, "$Revision: 3161 $");
51 m_mkpasswd(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
53 static time_t last_used
= 0;
56 if((last_used
+ ConfigFileEntry
.pace_wait
) > rb_current_time())
58 /* safe enough to give this on a local connect only */
59 sendto_one(source_p
, form_str(RPL_LOAD2HI
), me
.name
, parv
[0], "MKPASSWD");
64 last_used
= rb_current_time();
69 if(!irccmp(parv
[2], "MD5"))
73 else if(!irccmp(parv
[2], "DES"))
75 /* Not really needed, but we may want to have a default encryption
76 * setting somewhere down the road
82 sendto_one_notice(source_p
, ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
88 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, parv
[0], "MKPASSWD");
90 sendto_one_notice(source_p
, ":Encryption for [%s]: %s",
91 parv
[1], rb_crypt(parv
[1],
92 is_md5
? make_md5_salt() :
100 ** parv[0] = sender prefix
101 ** parv[1] = parameter
104 mo_mkpasswd(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
110 if(!irccmp(parv
[2], "MD5"))
114 else if(!irccmp(parv
[2], "DES"))
116 /* Not really needed, but we may want to have a default encryption
117 * setting somewhere down the road
123 sendto_one_notice(source_p
,
124 ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
130 sendto_one(source_p
, form_str(ERR_NEEDMOREPARAMS
), me
.name
, parv
[0], "MKPASSWD");
132 sendto_one_notice(source_p
, ":Encryption for [%s]: %s",
133 parv
[1], rb_crypt(parv
[1], is_md5
? make_md5_salt() : make_salt()));
142 salt
[0] = saltChars
[random() % 64];
143 salt
[1] = saltChars
[random() % 64];
151 static char salt
[13];
156 for(i
= 3; i
< 11; i
++)
157 salt
[i
] = saltChars
[random() % 64];