]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_oper.c: Makes a user an IRC Operator. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id: m_oper.c 1483 2006-05-27 18:58:12Z jilles $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "tools.h" | |
29 | #include "client.h" | |
30 | #include "common.h" | |
31 | #include "irc_string.h" | |
32 | #include "ircd.h" | |
33 | #include "numeric.h" | |
34 | #include "commio.h" | |
35 | #include "s_conf.h" | |
36 | #include "s_newconf.h" | |
37 | #include "s_log.h" | |
38 | #include "s_user.h" | |
39 | #include "send.h" | |
40 | #include "msg.h" | |
41 | #include "parse.h" | |
42 | #include "modules.h" | |
43 | #include "packet.h" | |
44 | #include "cache.h" | |
45 | ||
46 | static int m_oper(struct Client *, struct Client *, int, const char **); | |
47 | ||
48 | struct Message oper_msgtab = { | |
49 | "OPER", 0, 0, 0, MFLG_SLOW, | |
50 | {mg_unreg, {m_oper, 3}, mg_ignore, mg_ignore, mg_ignore, {m_oper, 3}} | |
51 | }; | |
52 | ||
53 | mapi_clist_av1 oper_clist[] = { &oper_msgtab, NULL }; | |
54 | DECLARE_MODULE_AV1(oper, NULL, NULL, oper_clist, NULL, NULL, "$Revision: 1483 $"); | |
55 | ||
56 | static int match_oper_password(const char *password, struct oper_conf *oper_p); | |
57 | extern char *crypt(); | |
58 | ||
59 | /* | |
60 | * m_oper | |
61 | * parv[0] = sender prefix | |
62 | * parv[1] = oper name | |
63 | * parv[2] = oper password | |
64 | */ | |
65 | static int | |
66 | m_oper(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
67 | { | |
68 | struct oper_conf *oper_p; | |
69 | const char *name; | |
70 | const char *password; | |
71 | ||
72 | name = parv[1]; | |
73 | password = parv[2]; | |
74 | ||
75 | if(IsOper(source_p)) | |
76 | { | |
77 | sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); | |
78 | send_oper_motd(source_p); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | /* end the grace period */ | |
83 | if(!IsFloodDone(source_p)) | |
84 | flood_endgrace(source_p); | |
85 | ||
86 | oper_p = find_oper_conf(source_p->username, source_p->orighost, | |
87 | source_p->sockhost, name); | |
88 | ||
89 | if(oper_p == NULL) | |
90 | { | |
91 | sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); | |
92 | ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", | |
93 | name, source_p->name, | |
94 | source_p->username, source_p->host, source_p->sockhost); | |
95 | ||
96 | if(ConfigFileEntry.failed_oper_notice) | |
97 | { | |
98 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
99 | "Failed OPER attempt - host mismatch by %s (%s@%s)", | |
100 | source_p->name, source_p->username, source_p->host); | |
101 | } | |
102 | ||
103 | return 0; | |
104 | } | |
105 | ||
106 | if(match_oper_password(password, oper_p)) | |
107 | { | |
108 | oper_up(source_p, oper_p); | |
109 | ||
110 | ilog(L_OPERED, "OPER %s by %s!%s@%s (%s)", | |
111 | name, source_p->name, source_p->username, source_p->host, | |
112 | source_p->sockhost); | |
113 | return 0; | |
114 | } | |
115 | else | |
116 | { | |
117 | sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), | |
118 | me.name, source_p->name); | |
119 | ||
120 | ilog(L_FOPER, "FAILED OPER (%s) by (%s!%s@%s) (%s)", | |
121 | name, source_p->name, source_p->username, source_p->host, | |
122 | source_p->sockhost); | |
123 | ||
124 | if(ConfigFileEntry.failed_oper_notice) | |
125 | { | |
126 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
127 | "Failed OPER attempt by %s (%s@%s)", | |
128 | source_p->name, source_p->username, source_p->host); | |
129 | } | |
130 | } | |
131 | ||
132 | return 0; | |
133 | } | |
134 | ||
135 | /* | |
136 | * match_oper_password | |
137 | * | |
138 | * inputs - pointer to given password | |
139 | * - pointer to Conf | |
140 | * output - YES or NO if match | |
141 | * side effects - none | |
142 | */ | |
143 | static int | |
144 | match_oper_password(const char *password, struct oper_conf *oper_p) | |
145 | { | |
146 | const char *encr; | |
147 | ||
148 | /* passwd may be NULL pointer. Head it off at the pass... */ | |
149 | if(EmptyString(oper_p->passwd)) | |
150 | return NO; | |
151 | ||
152 | if(IsOperConfEncrypted(oper_p)) | |
153 | { | |
154 | /* use first two chars of the password they send in as salt */ | |
155 | /* If the password in the conf is MD5, and ircd is linked | |
156 | * to scrypt on FreeBSD, or the standard crypt library on | |
157 | * glibc Linux, then this code will work fine on generating | |
158 | * the proper encrypted hash for comparison. | |
159 | */ | |
160 | if(!EmptyString(password)) | |
161 | encr = crypt(password, oper_p->passwd); | |
162 | else | |
163 | encr = ""; | |
164 | } | |
165 | else | |
166 | encr = password; | |
167 | ||
168 | if(strcmp(encr, oper_p->passwd) == 0) | |
169 | return YES; | |
170 | else | |
171 | return NO; | |
172 | } |