]> jfr.im git - irc/rqf/shadowircd.git/blob - extensions/m_mkpasswd.c
Removal of ancient SVN ID's part one
[irc/rqf/shadowircd.git] / extensions / m_mkpasswd.c
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 *
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"
16 #include "match.h"
17 #include "numeric.h"
18 #include "s_newconf.h"
19 #include "s_conf.h"
20 #include "logger.h"
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
29 static int m_mkpasswd(struct Client *client_p, struct Client *source_p,
30 int parc, const char *parv[]);
31 static int mo_mkpasswd(struct Client *client_p, struct Client *source_p,
32 int parc, const char *parv[]);
33 static char *make_salt(void);
34 static char *make_md5_salt(void);
35
36 static char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
37
38
39 struct 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
44 mapi_clist_av1 mkpasswd_clist[] = { &mkpasswd_msgtab, NULL };
45
46 DECLARE_MODULE_AV1(mkpasswd, NULL, NULL, mkpasswd_clist, NULL, NULL, "$Revision: 3161 $");
47
48
49 static int
50 m_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
55 if((last_used + ConfigFileEntry.pace_wait) > rb_current_time())
56 {
57 /* safe enough to give this on a local connect only */
58 sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD");
59 return 0;
60 }
61 else
62 {
63 last_used = rb_current_time();
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 {
81 sendto_one_notice(source_p, ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
82 return 0;
83 }
84 }
85
86 if(parc == 1)
87 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
88 else
89 sendto_one_notice(source_p, ":Encryption for [%s]: %s",
90 parv[1], rb_crypt(parv[1],
91 is_md5 ? make_md5_salt() :
92 make_salt()));
93
94 return 0;
95 }
96
97 /*
98 ** mo_test
99 ** parv[1] = parameter
100 */
101 static int
102 mo_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 {
121 sendto_one_notice(source_p,
122 ":MKPASSWD syntax error: MKPASSWD pass [DES|MD5]");
123 return 0;
124 }
125 }
126
127 if(parc == 1)
128 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
129 else
130 sendto_one_notice(source_p, ":Encryption for [%s]: %s",
131 parv[1], rb_crypt(parv[1], is_md5 ? make_md5_salt() : make_salt()));
132
133 return 0;
134 }
135
136 static char *
137 make_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
146 static char *
147 make_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 }