/[svn]/ircd-hybrid/contrib/m_mkpasswd.c
ViewVC logotype

Contents of /ircd-hybrid/contrib/m_mkpasswd.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 33 - (show annotations)
Sun Oct 2 20:50:00 2005 UTC (14 years, 9 months ago) by knight
File MIME type: text/x-chdr
File size: 3702 byte(s)
- svn:keywords

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$
10 */
11
12 #include "handlers.h"
13 #include "ircd.h"
14 #include "irc_string.h"
15 #include "numeric.h"
16 #include "s_conf.h"
17 #include "s_serv.h"
18 #include "send.h"
19 #include "modules.h"
20
21 static void m_mkpasswd(struct Client *, struct Client *, int, char *[]);
22 static void mo_mkpasswd(struct Client *, struct Client *, int, char *[]);
23 static char *des(void);
24 static char *md5(void);
25
26 static const char saltChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
27
28 struct Message mkpasswd_msgtab = {
29 "MKPASSWD", 0, 0, 1, 2, MFLG_SLOW, 0,
30 {m_unregistered, m_mkpasswd, m_ignore, m_ignore, mo_mkpasswd, m_ignore}
31 };
32
33 #ifndef STATIC_MODULES
34 void
35 _modinit(void)
36 {
37 mod_add_cmd(&mkpasswd_msgtab);
38 }
39
40 void
41 _moddeinit(void)
42 {
43 mod_del_cmd(&mkpasswd_msgtab);
44 }
45
46 const char *_version = "$Revision$";
47 #endif
48
49 static void
50 m_mkpasswd(struct Client *client_p, struct Client *source_p,
51 int parc, char *parv[])
52 {
53 static time_t last_used = 0;
54
55 if (parc < 1)
56 {
57 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
58 me.name, source_p->name, "MKPASSWD");
59 return;
60 }
61
62 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
63 {
64 sendto_one(source_p, form_str(RPL_LOAD2HI),
65 me.name, source_p->name);
66 return;
67 }
68
69 last_used = CurrentTime;
70
71 if (parv[2] == NULL)
72 sendto_one(source_p, ":%s NOTICE %s :DES Encryption for [%s]: %s",
73 me.name, source_p->name, parv[1], crypt(parv[1],
74 des()));
75 else if (!irccmp(parv[2], "DES"))
76 sendto_one(source_p, ":%s NOTICE %s :DES Encryption for [%s]: %s",
77 me.name, source_p->name, parv[1], crypt(parv[1],
78 des()));
79 else if (!irccmp(parv[2], "MD5"))
80 sendto_one(source_p, ":%s NOTICE %s :MD5 Encryption for [%s]: %s",
81 me.name, source_p->name, parv[1], crypt(parv[1],
82 md5()));
83 else
84 sendto_one(source_p, ":%s NOTICE %s :Syntax: MKPASSWD pass [DES|MD5]",
85 me.name, source_p->name);
86 }
87
88 /*
89 ** mo_mkpasswd
90 ** parv[0] = sender prefix
91 ** parv[1] = parameter
92 */
93 static void
94 mo_mkpasswd(struct Client *client_p, struct Client *source_p,
95 int parc, char *parv[])
96 {
97 if (parc < 1)
98 {
99 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
100 me.name, source_p->name, "MKPASSWD");
101 return;
102 }
103
104 if (parv[2] == NULL)
105 sendto_one(source_p, ":%s NOTICE %s :DES Encryption for [%s]: %s",
106 me.name, source_p->name, parv[1], crypt(parv[1],
107 des()));
108 else if (!irccmp(parv[2], "DES"))
109 sendto_one(source_p, ":%s NOTICE %s :DES Encryption for [%s]: %s",
110 me.name, source_p->name, parv[1], crypt(parv[1],
111 des()));
112 else if (!irccmp(parv[2], "MD5"))
113 sendto_one(source_p, ":%s NOTICE %s :MD5 Encryption for [%s]: %s",
114 me.name, source_p->name, parv[1], crypt(parv[1],
115 md5()));
116 else
117 sendto_one(source_p, ":%s NOTICE %s :Syntax: MKPASSWD pass [DES|MD5]",
118 me.name, source_p->name);
119 }
120
121 static char *
122 des(void)
123 {
124 static char salt[3];
125
126 salt[0] = saltChars[rand() % 64];
127 salt[1] = saltChars[rand() % 64];
128 salt[2] = '\0';
129
130 return salt;
131 }
132
133 static char *
134 md5(void)
135 {
136 static char salt[13];
137 int i;
138
139 salt[0] = '$';
140 salt[1] = '1';
141 salt[2] = '$';
142
143 for (i = 3; i < 11; i++)
144 salt[i] = saltChars[rand() % 64];
145
146 salt[11] = '$';
147 salt[12] = '\0';
148
149 return salt;
150 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28