ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/m_oper.c
Revision: 1011
Committed: Fri Sep 18 10:14:09 2009 UTC (14 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 5261 byte(s)
Log Message:
- move list manipulation routines from tools.c to list.c
- mem_frob() goes to memory.c
- sort out redundant/unneeded header includes

File Contents

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

Properties

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