ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_oper.c
Revision: 1243
Committed: Fri Sep 30 10:47:53 2011 UTC (14 years, 9 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-8/modules/m_oper.c
File size: 5164 byte(s)
Log Message:
- move content of msg.h, ircd_handler.h and handlers.h into parse.h and
  remove headers accordingly
- killed common.h
- remove m_killhost.c and m_flags.c from contrib/
- sort out unused header includes here and there

File Contents

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

Properties

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