1 |
/* |
2 |
* m_mkpasswd.c: Encrypts a password online, DES or MD5. |
3 |
* |
4 |
* Copyright 2002 W. Campbell and the ircd-hybrid 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 |
* |
9 |
* $Id: m_mkpasswd.c 801 2006-08-30 16:54:25Z adx $ |
10 |
*/ |
11 |
|
12 |
#include "stdinc.h" |
13 |
#include "conf/conf.h" |
14 |
#include "handlers.h" |
15 |
#include "client.h" |
16 |
#include "ircd.h" |
17 |
#include "numeric.h" |
18 |
#include "server.h" |
19 |
#include "send.h" |
20 |
#include "msg.h" |
21 |
#include "parse.h" |
22 |
|
23 |
static void m_mkpasswd(struct Client *, struct Client *, int, char *[]); |
24 |
static const char *m_mkpasswd_des(void); |
25 |
static const char *m_mkpasswd_md5(void); |
26 |
|
27 |
static const char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"; |
28 |
|
29 |
struct Message mkpasswd_msgtab = { |
30 |
"MKPASSWD", 0, 0, 1, 2, MFLG_SLOW, 0, |
31 |
{ m_unregistered, m_mkpasswd, m_ignore, m_ignore, m_mkpasswd, m_ignore } |
32 |
}; |
33 |
|
34 |
INIT_MODULE(m_mkpasswd, "$Revision: 801 $") |
35 |
{ |
36 |
mod_add_cmd(&mkpasswd_msgtab); |
37 |
} |
38 |
|
39 |
CLEANUP_MODULE |
40 |
{ |
41 |
mod_del_cmd(&mkpasswd_msgtab); |
42 |
} |
43 |
|
44 |
static void |
45 |
m_mkpasswd(struct Client *client_p, struct Client *source_p, |
46 |
int parc, char *parv[]) |
47 |
{ |
48 |
static time_t last_used = 0; |
49 |
|
50 |
if (EmptyString(parv[1])) |
51 |
{ |
52 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
53 |
me.name, source_p->name, "MKPASSWD"); |
54 |
return; |
55 |
} |
56 |
|
57 |
if (!IsOper(source_p)) |
58 |
{ |
59 |
if ((last_used + General.pace_wait) > CurrentTime) |
60 |
{ |
61 |
sendto_one(source_p, form_str(RPL_LOAD2HI), |
62 |
me.name, source_p->name); |
63 |
return; |
64 |
} |
65 |
|
66 |
last_used = CurrentTime; |
67 |
} |
68 |
|
69 |
if (parv[2] == NULL || !irccmp(parv[2], "DES")) |
70 |
sendto_one(source_p, ":%s NOTICE %s :DES Encryption for [%s]: %s", |
71 |
me.name, source_p->name, parv[1], crypt(parv[1], |
72 |
m_mkpasswd_des())); |
73 |
else if (!irccmp(parv[2], "MD5")) |
74 |
sendto_one(source_p, ":%s NOTICE %s :MD5 Encryption for [%s]: %s", |
75 |
me.name, source_p->name, parv[1], crypt(parv[1], |
76 |
m_mkpasswd_md5())); |
77 |
else |
78 |
sendto_one(source_p, ":%s NOTICE %s :Syntax: MKPASSWD pass [DES|MD5]", |
79 |
me.name, source_p->name); |
80 |
} |
81 |
|
82 |
static const char * |
83 |
m_mkpasswd_des(void) |
84 |
{ |
85 |
static char salt[3]; |
86 |
|
87 |
salt[0] = saltChars[rand() % 64]; |
88 |
salt[1] = saltChars[rand() % 64]; |
89 |
salt[2] = '\0'; |
90 |
|
91 |
return salt; |
92 |
} |
93 |
|
94 |
static const char * |
95 |
m_mkpasswd_md5(void) |
96 |
{ |
97 |
static char salt[13]; |
98 |
int i; |
99 |
|
100 |
salt[0] = '$'; |
101 |
salt[1] = '1'; |
102 |
salt[2] = '$'; |
103 |
|
104 |
for (i = 3; i < 11; ++i) |
105 |
salt[i] = saltChars[rand() % 64]; |
106 |
|
107 |
salt[11] = '$'; |
108 |
salt[12] = '\0'; |
109 |
|
110 |
return salt; |
111 |
} |