ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_oper.c
Revision: 1247
Committed: Sat Oct 1 07:54:24 2011 UTC (14 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 5062 byte(s)
Log Message:
- Rewrite and cleanup half-broken logging subsystem.
  Logfile rotating is not working yet

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 michael 1247
86     ilog(LOG_TYPE_OPER, "Failed OPER attempt as %s "
87     "by %s (%s@%s) - %s", name, source_p->name,
88     source_p->username, source_p->host, reason);
89 adx 30 }
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     return;
124     }
125    
126 michael 1121 aconf = map_to_conf(conf);
127 adx 30
128     if (match_conf_password(password, aconf))
129     {
130     if (attach_conf(source_p, conf) != 0)
131     {
132     sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!",
133     me.name, source_p->name);
134     failed_oper_notice(source_p, name, "can't attach conf!");
135     return;
136     }
137    
138     oper_up(source_p);
139    
140 michael 1247 ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s",
141 adx 30 name, source_p->name, source_p->username, source_p->host);
142     }
143     else
144     {
145 michael 1230 sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name);
146 adx 30 failed_oper_notice(source_p, name, "password mismatch");
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