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 |
michael |
1011 |
#include "list.h" |
27 |
adx |
30 |
#include "client.h" |
28 |
|
|
#include "irc_string.h" |
29 |
|
|
#include "ircd.h" |
30 |
|
|
#include "numeric.h" |
31 |
michael |
1309 |
#include "conf.h" |
32 |
|
|
#include "log.h" |
33 |
adx |
30 |
#include "s_user.h" |
34 |
|
|
#include "send.h" |
35 |
|
|
#include "parse.h" |
36 |
|
|
#include "modules.h" |
37 |
|
|
#include "packet.h" |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
michael |
1230 |
/* failed_oper_notice() |
42 |
|
|
* |
43 |
|
|
* inputs - pointer to client doing /oper ... |
44 |
|
|
* - pointer to nick they tried to oper as |
45 |
|
|
* - pointer to reason they have failed |
46 |
|
|
* output - nothing |
47 |
|
|
* side effects - notices all opers of the failed oper attempt if enabled |
48 |
|
|
*/ |
49 |
|
|
static void |
50 |
|
|
failed_oper_notice(struct Client *source_p, const char *name, |
51 |
|
|
const char *reason) |
52 |
adx |
30 |
{ |
53 |
michael |
1230 |
if (ConfigFileEntry.failed_oper_notice) |
54 |
michael |
1618 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
55 |
|
|
"Failed OPER attempt as %s by %s (%s@%s) - %s", |
56 |
|
|
name, source_p->name, source_p->username, |
57 |
|
|
source_p->host, reason); |
58 |
michael |
1247 |
|
59 |
michael |
1618 |
ilog(LOG_TYPE_OPER, "Failed OPER attempt as %s by %s (%s@%s) - %s", |
60 |
|
|
name, source_p->name, source_p->username, |
61 |
|
|
source_p->host, reason); |
62 |
adx |
30 |
} |
63 |
|
|
|
64 |
|
|
/* |
65 |
|
|
** m_oper |
66 |
|
|
** parv[0] = sender prefix |
67 |
|
|
** parv[1] = oper name |
68 |
|
|
** parv[2] = oper password |
69 |
|
|
*/ |
70 |
|
|
static void |
71 |
|
|
m_oper(struct Client *client_p, struct Client *source_p, |
72 |
|
|
int parc, char *parv[]) |
73 |
|
|
{ |
74 |
michael |
1632 |
struct MaskItem *conf = NULL; |
75 |
adx |
30 |
const char *name = parv[1]; |
76 |
|
|
const char *password = parv[2]; |
77 |
|
|
|
78 |
|
|
if (EmptyString(password)) |
79 |
|
|
{ |
80 |
michael |
1832 |
sendto_one(source_p, ERR_NEEDMOREPARAMS, |
81 |
michael |
1446 |
me.name, source_p->name, "OPER"); |
82 |
adx |
30 |
return; |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
/* end the grace period */ |
86 |
|
|
if (!IsFloodDone(source_p)) |
87 |
|
|
flood_endgrace(source_p); |
88 |
|
|
|
89 |
michael |
1632 |
if ((conf = find_exact_name_conf(CONF_OPER, source_p, name, NULL, NULL)) == NULL) |
90 |
adx |
30 |
{ |
91 |
michael |
1832 |
sendto_one(source_p, ERR_NOOPERHOST, me.name, source_p->name); |
92 |
michael |
1632 |
conf = find_exact_name_conf(CONF_OPER, NULL, name, NULL, NULL); |
93 |
adx |
30 |
failed_oper_notice(source_p, name, (conf != NULL) ? |
94 |
|
|
"host mismatch" : "no oper {} block"); |
95 |
|
|
return; |
96 |
|
|
} |
97 |
|
|
|
98 |
michael |
1632 |
if (match_conf_password(password, conf)) |
99 |
adx |
30 |
{ |
100 |
|
|
if (attach_conf(source_p, conf) != 0) |
101 |
|
|
{ |
102 |
|
|
sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!", |
103 |
|
|
me.name, source_p->name); |
104 |
|
|
failed_oper_notice(source_p, name, "can't attach conf!"); |
105 |
|
|
return; |
106 |
|
|
} |
107 |
|
|
|
108 |
|
|
oper_up(source_p); |
109 |
|
|
|
110 |
michael |
1247 |
ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", |
111 |
adx |
30 |
name, source_p->name, source_p->username, source_p->host); |
112 |
|
|
} |
113 |
|
|
else |
114 |
|
|
{ |
115 |
michael |
1832 |
sendto_one(source_p, ERR_PASSWDMISMATCH, me.name, source_p->name); |
116 |
adx |
30 |
failed_oper_notice(source_p, name, "password mismatch"); |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
/* |
121 |
|
|
** mo_oper |
122 |
|
|
** parv[0] = sender prefix |
123 |
|
|
** parv[1] = oper name |
124 |
|
|
** parv[2] = oper password |
125 |
|
|
*/ |
126 |
|
|
static void |
127 |
|
|
mo_oper(struct Client *client_p, struct Client *source_p, |
128 |
|
|
int parc, char *parv[]) |
129 |
|
|
{ |
130 |
michael |
1832 |
sendto_one(source_p, RPL_YOUREOPER, |
131 |
michael |
1446 |
me.name, source_p->name); |
132 |
adx |
30 |
} |
133 |
|
|
|
134 |
michael |
1230 |
static struct Message oper_msgtab = { |
135 |
|
|
"OPER", 0, 0, 3, MAXPARA, MFLG_SLOW, 0, |
136 |
|
|
{ m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore } |
137 |
|
|
}; |
138 |
|
|
|
139 |
|
|
static void |
140 |
|
|
module_init(void) |
141 |
adx |
30 |
{ |
142 |
michael |
1230 |
mod_add_cmd(&oper_msgtab); |
143 |
adx |
30 |
} |
144 |
|
|
|
145 |
|
|
static void |
146 |
michael |
1230 |
module_exit(void) |
147 |
adx |
30 |
{ |
148 |
michael |
1230 |
mod_del_cmd(&oper_msgtab); |
149 |
adx |
30 |
} |
150 |
michael |
1230 |
|
151 |
|
|
struct module module_entry = { |
152 |
|
|
.node = { NULL, NULL, NULL }, |
153 |
|
|
.name = NULL, |
154 |
|
|
.version = "$Revision$", |
155 |
|
|
.handle = NULL, |
156 |
|
|
.modinit = module_init, |
157 |
|
|
.modexit = module_exit, |
158 |
|
|
.flags = 0 |
159 |
|
|
}; |