1 |
/* |
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 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.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 "msg.h" |
39 |
#include "parse.h" |
40 |
#include "modules.h" |
41 |
#include "packet.h" |
42 |
|
43 |
|
44 |
/* find_password_conf() |
45 |
* |
46 |
* inputs - name |
47 |
* - pointer to source_p |
48 |
* output - pointer to oper conf or NULL |
49 |
* side effects - NONE |
50 |
*/ |
51 |
static struct ConfItem * |
52 |
find_password_conf(const char *name, struct Client *source_p) |
53 |
{ |
54 |
struct ConfItem *conf = NULL; |
55 |
|
56 |
if ((conf = find_exact_name_conf(OPER_TYPE, |
57 |
name, source_p->username, source_p->host |
58 |
)) != NULL) |
59 |
{ |
60 |
return conf; |
61 |
} |
62 |
|
63 |
if ((conf = find_exact_name_conf(OPER_TYPE, |
64 |
name, source_p->username, |
65 |
source_p->sockhost)) != NULL) |
66 |
{ |
67 |
return conf; |
68 |
} |
69 |
|
70 |
return NULL; |
71 |
} |
72 |
|
73 |
/* failed_oper_notice() |
74 |
* |
75 |
* inputs - pointer to client doing /oper ... |
76 |
* - pointer to nick they tried to oper as |
77 |
* - pointer to reason they have failed |
78 |
* output - nothing |
79 |
* side effects - notices all opers of the failed oper attempt if enabled |
80 |
*/ |
81 |
static void |
82 |
failed_oper_notice(struct Client *source_p, const char *name, |
83 |
const char *reason) |
84 |
{ |
85 |
if (ConfigFileEntry.failed_oper_notice) |
86 |
sendto_realops_flags(UMODE_ALL, L_ALL, "Failed OPER attempt as %s " |
87 |
"by %s (%s@%s) - %s", name, source_p->name, |
88 |
source_p->username, source_p->host, reason); |
89 |
} |
90 |
|
91 |
/* |
92 |
** m_oper |
93 |
** parv[0] = sender prefix |
94 |
** parv[1] = oper name |
95 |
** parv[2] = oper password |
96 |
*/ |
97 |
static void |
98 |
m_oper(struct Client *client_p, struct Client *source_p, |
99 |
int parc, char *parv[]) |
100 |
{ |
101 |
struct ConfItem *conf; |
102 |
struct AccessItem *aconf=NULL; |
103 |
const char *name = parv[1]; |
104 |
const char *password = parv[2]; |
105 |
|
106 |
if (EmptyString(password)) |
107 |
{ |
108 |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
109 |
me.name, source_p->name, "OPER"); |
110 |
return; |
111 |
} |
112 |
|
113 |
/* end the grace period */ |
114 |
if (!IsFloodDone(source_p)) |
115 |
flood_endgrace(source_p); |
116 |
|
117 |
if ((conf = find_password_conf(name, source_p)) == NULL) |
118 |
{ |
119 |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
120 |
conf = find_exact_name_conf(OPER_TYPE, name, NULL, NULL); |
121 |
failed_oper_notice(source_p, name, (conf != NULL) ? |
122 |
"host mismatch" : "no oper {} block"); |
123 |
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
124 |
return; |
125 |
} |
126 |
|
127 |
aconf = map_to_conf(conf); |
128 |
|
129 |
if (match_conf_password(password, aconf)) |
130 |
{ |
131 |
if (attach_conf(source_p, conf) != 0) |
132 |
{ |
133 |
sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!", |
134 |
me.name, source_p->name); |
135 |
failed_oper_notice(source_p, name, "can't attach conf!"); |
136 |
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
137 |
return; |
138 |
} |
139 |
|
140 |
oper_up(source_p); |
141 |
|
142 |
ilog(L_TRACE, "OPER %s by %s!%s@%s", |
143 |
name, source_p->name, source_p->username, source_p->host); |
144 |
log_oper_action(LOG_OPER_TYPE, source_p, "%s\n", name); |
145 |
} |
146 |
else |
147 |
{ |
148 |
sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name); |
149 |
failed_oper_notice(source_p, name, "password mismatch"); |
150 |
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
151 |
} |
152 |
} |
153 |
|
154 |
/* |
155 |
** mo_oper |
156 |
** parv[0] = sender prefix |
157 |
** parv[1] = oper name |
158 |
** parv[2] = oper password |
159 |
*/ |
160 |
static void |
161 |
mo_oper(struct Client *client_p, struct Client *source_p, |
162 |
int parc, char *parv[]) |
163 |
{ |
164 |
sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); |
165 |
send_message_file(source_p, &ConfigFileEntry.opermotd); |
166 |
} |
167 |
|
168 |
static struct Message oper_msgtab = { |
169 |
"OPER", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
170 |
{ m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore } |
171 |
}; |
172 |
|
173 |
static void |
174 |
module_init(void) |
175 |
{ |
176 |
mod_add_cmd(&oper_msgtab); |
177 |
} |
178 |
|
179 |
static void |
180 |
module_exit(void) |
181 |
{ |
182 |
mod_del_cmd(&oper_msgtab); |
183 |
} |
184 |
|
185 |
struct module module_entry = { |
186 |
.node = { NULL, NULL, NULL }, |
187 |
.name = NULL, |
188 |
.version = "$Revision$", |
189 |
.handle = NULL, |
190 |
.modinit = module_init, |
191 |
.modexit = module_exit, |
192 |
.flags = 0 |
193 |
}; |