1 |
adx |
30 |
/* |
2 |
|
|
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
|
|
* m_oper.c: Makes a user an IRC Operator. |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2002 by the past and present ircd coders, and others. |
6 |
|
|
* |
7 |
|
|
* This program is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* This program is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with this program; if not, write to the Free Software |
19 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
|
|
* USA |
21 |
|
|
* |
22 |
knight |
31 |
* $Id$ |
23 |
adx |
30 |
*/ |
24 |
|
|
|
25 |
|
|
#include "stdinc.h" |
26 |
|
|
#include "tools.h" |
27 |
|
|
#include "handlers.h" |
28 |
|
|
#include "client.h" |
29 |
|
|
#include "common.h" |
30 |
|
|
#include "irc_string.h" |
31 |
|
|
#include "ircd.h" |
32 |
|
|
#include "numeric.h" |
33 |
|
|
#include "s_bsd.h" |
34 |
|
|
#include "s_conf.h" |
35 |
|
|
#include "s_log.h" |
36 |
|
|
#include "s_user.h" |
37 |
|
|
#include "send.h" |
38 |
|
|
#include "list.h" |
39 |
|
|
#include "msg.h" |
40 |
|
|
#include "parse.h" |
41 |
|
|
#include "modules.h" |
42 |
|
|
#include "packet.h" |
43 |
|
|
|
44 |
|
|
static struct ConfItem *find_password_conf(const char *, struct Client *); |
45 |
|
|
static void failed_oper_notice(struct Client *, const char *, const char *); |
46 |
|
|
static void m_oper(struct Client *, struct Client *, int, char *[]); |
47 |
|
|
static void mo_oper(struct Client *, struct Client *, int, char *[]); |
48 |
|
|
|
49 |
|
|
struct Message oper_msgtab = { |
50 |
|
|
"OPER", 0, 0, 3, 0, MFLG_SLOW, 0, |
51 |
|
|
{ m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore } |
52 |
|
|
}; |
53 |
|
|
|
54 |
|
|
#ifndef STATIC_MODULES |
55 |
|
|
void |
56 |
|
|
_modinit(void) |
57 |
|
|
{ |
58 |
|
|
mod_add_cmd(&oper_msgtab); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
void |
62 |
|
|
_moddeinit(void) |
63 |
|
|
{ |
64 |
|
|
mod_del_cmd(&oper_msgtab); |
65 |
|
|
} |
66 |
|
|
|
67 |
knight |
31 |
const char *_version = "$Revision$"; |
68 |
adx |
30 |
#endif |
69 |
|
|
|
70 |
|
|
/* |
71 |
|
|
** m_oper |
72 |
|
|
** parv[0] = sender prefix |
73 |
|
|
** parv[1] = oper name |
74 |
|
|
** parv[2] = oper password |
75 |
|
|
*/ |
76 |
|
|
static void |
77 |
|
|
m_oper(struct Client *client_p, struct Client *source_p, |
78 |
|
|
int parc, char *parv[]) |
79 |
|
|
{ |
80 |
|
|
struct ConfItem *conf; |
81 |
|
|
struct AccessItem *aconf=NULL; |
82 |
|
|
const char *name = parv[1]; |
83 |
|
|
const char *password = parv[2]; |
84 |
|
|
|
85 |
|
|
if (EmptyString(password)) |
86 |
|
|
{ |
87 |
|
|
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
88 |
|
|
me.name, source_p->name, "OPER"); |
89 |
|
|
return; |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
/* end the grace period */ |
93 |
|
|
if (!IsFloodDone(source_p)) |
94 |
|
|
flood_endgrace(source_p); |
95 |
|
|
|
96 |
|
|
if ((conf = find_password_conf(name, source_p)) == NULL) |
97 |
|
|
{ |
98 |
|
|
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
99 |
|
|
conf = find_exact_name_conf(OPER_TYPE, name, NULL, NULL); |
100 |
|
|
failed_oper_notice(source_p, name, (conf != NULL) ? |
101 |
|
|
"host mismatch" : "no oper {} block"); |
102 |
|
|
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
103 |
|
|
return; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
aconf = (struct AccessItem *)map_to_conf(conf); |
107 |
|
|
|
108 |
|
|
if (match_conf_password(password, aconf)) |
109 |
|
|
{ |
110 |
|
|
if (attach_conf(source_p, conf) != 0) |
111 |
|
|
{ |
112 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!", |
113 |
|
|
me.name, source_p->name); |
114 |
|
|
failed_oper_notice(source_p, name, "can't attach conf!"); |
115 |
|
|
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
116 |
|
|
return; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
oper_up(source_p); |
120 |
|
|
|
121 |
|
|
ilog(L_TRACE, "OPER %s by %s!%s@%s", |
122 |
|
|
name, source_p->name, source_p->username, source_p->host); |
123 |
|
|
log_oper_action(LOG_OPER_TYPE, source_p, "%s\n", name); |
124 |
|
|
} |
125 |
|
|
else |
126 |
|
|
{ |
127 |
|
|
sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, parv[0]); |
128 |
|
|
failed_oper_notice(source_p, name, "password mismatch"); |
129 |
|
|
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
130 |
|
|
} |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
/* |
134 |
|
|
** mo_oper |
135 |
|
|
** parv[0] = sender prefix |
136 |
|
|
** parv[1] = oper name |
137 |
|
|
** parv[2] = oper password |
138 |
|
|
*/ |
139 |
|
|
static void |
140 |
|
|
mo_oper(struct Client *client_p, struct Client *source_p, |
141 |
|
|
int parc, char *parv[]) |
142 |
|
|
{ |
143 |
|
|
sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); |
144 |
|
|
send_message_file(source_p, &ConfigFileEntry.opermotd); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
/* find_password_conf() |
148 |
|
|
* |
149 |
|
|
* inputs - name |
150 |
|
|
* - pointer to source_p |
151 |
|
|
* output - pointer to oper conf or NULL |
152 |
|
|
* side effects - NONE |
153 |
|
|
*/ |
154 |
|
|
static struct ConfItem * |
155 |
|
|
find_password_conf(const char *name, struct Client *source_p) |
156 |
|
|
{ |
157 |
|
|
struct ConfItem *conf = NULL; |
158 |
|
|
|
159 |
|
|
if ((conf = find_exact_name_conf(OPER_TYPE, |
160 |
|
|
name, source_p->username, source_p->host |
161 |
|
|
)) != NULL) |
162 |
|
|
{ |
163 |
|
|
return(conf); |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
if ((conf = find_exact_name_conf(OPER_TYPE, |
167 |
|
|
name, source_p->username, |
168 |
|
|
source_p->sockhost)) != NULL) |
169 |
|
|
{ |
170 |
|
|
return(conf); |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
return(NULL); |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
/* failed_oper_notice() |
177 |
|
|
* |
178 |
|
|
* inputs - pointer to client doing /oper ... |
179 |
|
|
* - pointer to nick they tried to oper as |
180 |
|
|
* - pointer to reason they have failed |
181 |
|
|
* output - nothing |
182 |
|
|
* side effects - notices all opers of the failed oper attempt if enabled |
183 |
|
|
*/ |
184 |
|
|
static void |
185 |
|
|
failed_oper_notice(struct Client *source_p, const char *name, |
186 |
|
|
const char *reason) |
187 |
|
|
{ |
188 |
|
|
if (ConfigFileEntry.failed_oper_notice) |
189 |
|
|
sendto_realops_flags(UMODE_ALL, L_ALL, "Failed OPER attempt as %s " |
190 |
|
|
"by %s (%s@%s) - %s", name, source_p->name, |
191 |
|
|
source_p->username, source_p->host, reason); |
192 |
|
|
} |