/[svn]/ircd-hybrid-8/modules/m_oper.c
ViewVC logotype

Contents of /ircd-hybrid-8/modules/m_oper.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1285 - (show annotations)
Sun Feb 5 15:12:59 2012 UTC (8 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 4703 byte(s)
- added CIDR support for operator{} blocks
- operator "name"{} is no longer supported

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28