ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/contrib/m_mkpasswd.c
Revision: 265
Committed: Sun Nov 13 12:01:02 2005 UTC (20 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 3388 byte(s)
Log Message:
- Small cleanups to m_mkpasswd.c

File Contents

# Content
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 "stdinc.h"
13 #include "handlers.h"
14 #include "ircd.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 (EmptyString(parv[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 || !irccmp(parv[2], "DES"))
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], "MD5"))
76 sendto_one(source_p, ":%s NOTICE %s :MD5 Encryption for [%s]: %s",
77 me.name, source_p->name, parv[1], crypt(parv[1],
78 md5()));
79 else
80 sendto_one(source_p, ":%s NOTICE %s :Syntax: MKPASSWD pass [DES|MD5]",
81 me.name, source_p->name);
82 }
83
84 /*
85 ** mo_mkpasswd
86 ** parv[0] = sender prefix
87 ** parv[1] = parameter
88 */
89 static void
90 mo_mkpasswd(struct Client *client_p, struct Client *source_p,
91 int parc, char *parv[])
92 {
93 if (EmptyString(parv[1]))
94 {
95 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
96 me.name, source_p->name, "MKPASSWD");
97 return;
98 }
99
100 if (parv[2] == NULL || !irccmp(parv[2], "DES"))
101 sendto_one(source_p, ":%s NOTICE %s :DES Encryption for [%s]: %s",
102 me.name, source_p->name, parv[1], crypt(parv[1],
103 des()));
104 else if (!irccmp(parv[2], "MD5"))
105 sendto_one(source_p, ":%s NOTICE %s :MD5 Encryption for [%s]: %s",
106 me.name, source_p->name, parv[1], crypt(parv[1],
107 md5()));
108 else
109 sendto_one(source_p, ":%s NOTICE %s :Syntax: MKPASSWD pass [DES|MD5]",
110 me.name, source_p->name);
111 }
112
113 static char *
114 des(void)
115 {
116 static char salt[3];
117
118 salt[0] = saltChars[rand() % 64];
119 salt[1] = saltChars[rand() % 64];
120 salt[2] = '\0';
121
122 return salt;
123 }
124
125 static char *
126 md5(void)
127 {
128 static char salt[13];
129 int i;
130
131 salt[0] = '$';
132 salt[1] = '1';
133 salt[2] = '$';
134
135 for (i = 3; i < 11; i++)
136 salt[i] = saltChars[rand() % 64];
137
138 salt[11] = '$';
139 salt[12] = '\0';
140
141 return salt;
142 }

Properties

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