]> jfr.im git - irc/rqf/shadowircd.git/blame - extensions/m_mkpasswd.c
Removal of ancient SVN ID's part one
[irc/rqf/shadowircd.git] / extensions / m_mkpasswd.c
CommitLineData
212380e3 1/*
2 * m_mkpasswd.c: Encrypts a password online, DES or MD5.
3 *
4 * Copyright 2002 W. Campbell and the ircd-ratbox development team
5 * Based on mkpasswd.c, originally by Nelson Minar (minar@reed.edu)
6 *
7 * You can use this code in any way as long as these names remain.
8 *
212380e3 9 */
10
11/* List of ircd includes from ../include/ */
12#include "stdinc.h"
13#include "client.h"
14#include "common.h" /* FALSE bleah */
15#include "ircd.h"
13ae2f4b 16#include "match.h"
212380e3 17#include "numeric.h"
212380e3 18#include "s_newconf.h"
19#include "s_conf.h"
d3455e2c 20#include "logger.h"
212380e3 21#include "s_serv.h"
22#include "send.h"
23#include "msg.h"
24#include "parse.h"
25#include "modules.h"
26
27#include <string.h>
28
212380e3 29static int m_mkpasswd(struct Client *client_p, struct Client *source_p,
30 int parc, const char *parv[]);
31static int mo_mkpasswd(struct Client *client_p, struct Client *source_p,
32 int parc, const char *parv[]);
33static char *make_salt(void);
34static char *make_md5_salt(void);
35
36static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
37
38
39struct Message mkpasswd_msgtab = {
40 "MKPASSWD", 0, 0, 0, MFLG_SLOW,
41 {mg_unreg, {m_mkpasswd, 2}, mg_ignore, mg_ignore, mg_ignore, {mo_mkpasswd, 2}}
42};
43
44mapi_clist_av1 mkpasswd_clist[] = { &mkpasswd_msgtab, NULL };
45
5366977b 46DECLARE_MODULE_AV1(mkpasswd, NULL, NULL, mkpasswd_clist, NULL, NULL, "$Revision: 3161 $");
212380e3 47
48
49static int
50m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
51{
52 static time_t last_used = 0;
53 int is_md5 = 0;
54
c51d32ba 55 if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
212380e3 56 {
57 /* safe enough to give this on a local connect only */
8e425f41 58 sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD");
212380e3 59 return 0;
60 }
61 else
62 {
c51d32ba 63 last_used = rb_current_time();
212380e3 64 }
65
66 if(parc == 3)
67 {
68 if(!irccmp(parv[2], "MD5"))
69 {
70 is_md5 = 1;
71 }
72 else if(!irccmp(parv[2], "DES"))
73 {
74 /* Not really needed, but we may want to have a default encryption
75 * setting somewhere down the road
76 */
77 is_md5 = 0;
78 }
79 else
80 {
5366977b 81 sendto_one_notice(source_p, ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
212380e3 82 return 0;
83 }
84 }
85
86 if(parc == 1)
8e425f41 87 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
212380e3 88 else
5366977b 89 sendto_one_notice(source_p, ":Encryption for [%s]: %s",
cf63b587 90 parv[1], rb_crypt(parv[1],
212380e3 91 is_md5 ? make_md5_salt() :
92 make_salt()));
93
94 return 0;
95}
96
97/*
98** mo_test
212380e3 99** parv[1] = parameter
100*/
101static int
102mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
103{
104 int is_md5 = 0;
105
106 if(parc == 3)
107 {
108 if(!irccmp(parv[2], "MD5"))
109 {
110 is_md5 = 1;
111 }
112 else if(!irccmp(parv[2], "DES"))
113 {
114 /* Not really needed, but we may want to have a default encryption
115 * setting somewhere down the road
116 */
117 is_md5 = 0;
118 }
119 else
120 {
5366977b 121 sendto_one_notice(source_p,
122 ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
212380e3 123 return 0;
124 }
125 }
126
127 if(parc == 1)
8e425f41 128 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
212380e3 129 else
5366977b 130 sendto_one_notice(source_p, ":Encryption for [%s]: %s",
cf63b587 131 parv[1], rb_crypt(parv[1], is_md5 ? make_md5_salt() : make_salt()));
212380e3 132
133 return 0;
134}
135
136static char *
137make_salt(void)
138{
139 static char salt[3];
140 salt[0] = saltChars[random() % 64];
141 salt[1] = saltChars[random() % 64];
142 salt[2] = '\0';
143 return salt;
144}
145
146static char *
147make_md5_salt(void)
148{
149 static char salt[13];
150 int i;
151 salt[0] = '$';
152 salt[1] = '1';
153 salt[2] = '$';
154 for(i = 3; i < 11; i++)
155 salt[i] = saltChars[random() % 64];
156 salt[11] = '$';
157 salt[12] = '\0';
158 return salt;
159}