ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_oper.c
Revision: 129
Committed: Fri Oct 14 20:27:45 2005 UTC (20 years, 10 months ago) by michael
Content type: text/x-csrc
File size: 4947 byte(s)
Log Message:
- Don't do any client/oper conf attach at all if any possible

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     #include "handlers.h"
27     #include "client.h"
28     #include "common.h"
29     #include "ircd.h"
30     #include "numeric.h"
31     #include "s_conf.h"
32     #include "s_user.h"
33     #include "send.h"
34     #include "msg.h"
35     #include "parse.h"
36     #include "modules.h"
37     #include "packet.h"
38    
39     static struct ConfItem *find_password_conf(const char *, struct Client *);
40     static void failed_oper_notice(struct Client *, const char *, const char *);
41     static void m_oper(struct Client *, struct Client *, int, char *[]);
42     static void mo_oper(struct Client *, struct Client *, int, char *[]);
43    
44     struct Message oper_msgtab = {
45     "OPER", 0, 0, 3, 0, MFLG_SLOW, 0,
46     { m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore }
47     };
48    
49     #ifndef STATIC_MODULES
50     void
51     _modinit(void)
52     {
53     mod_add_cmd(&oper_msgtab);
54     }
55    
56     void
57     _moddeinit(void)
58     {
59     mod_del_cmd(&oper_msgtab);
60     }
61    
62 knight 31 const char *_version = "$Revision$";
63 adx 30 #endif
64    
65     /*
66     ** m_oper
67     ** parv[0] = sender prefix
68     ** parv[1] = oper name
69     ** parv[2] = oper password
70     */
71     static void
72     m_oper(struct Client *client_p, struct Client *source_p,
73     int parc, char *parv[])
74     {
75 michael 129 struct ConfItem *conf = NULL;
76     struct AccessItem *aconf = NULL;
77 adx 30 const char *name = parv[1];
78     const char *password = parv[2];
79    
80     if (EmptyString(password))
81     {
82     sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
83     me.name, source_p->name, "OPER");
84     return;
85     }
86    
87     /* end the grace period */
88     if (!IsFloodDone(source_p))
89     flood_endgrace(source_p);
90    
91     if ((conf = find_password_conf(name, source_p)) == NULL)
92     {
93     sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
94 michael 129 /* XXX - eh? what's that find_exact_name_conf() call for? why is it here? */
95 adx 30 conf = find_exact_name_conf(OPER_TYPE, name, NULL, NULL);
96     failed_oper_notice(source_p, name, (conf != NULL) ?
97     "host mismatch" : "no oper {} block");
98     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name);
99     return;
100     }
101    
102 michael 129 aconf = map_to_conf(conf);
103 adx 30
104     if (match_conf_password(password, aconf))
105     {
106 db 101 oper_up(source_p, conf);
107 adx 30
108     ilog(L_TRACE, "OPER %s by %s!%s@%s",
109     name, source_p->name, source_p->username, source_p->host);
110     log_oper_action(LOG_OPER_TYPE, source_p, "%s\n", name);
111     }
112     else
113     {
114     sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, parv[0]);
115     failed_oper_notice(source_p, name, "password mismatch");
116     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name);
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     sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
131     send_message_file(source_p, &ConfigFileEntry.opermotd);
132     }
133    
134     /* find_password_conf()
135     *
136     * inputs - name
137     * - pointer to source_p
138     * output - pointer to oper conf or NULL
139     * side effects - NONE
140     */
141     static struct ConfItem *
142     find_password_conf(const char *name, struct Client *source_p)
143     {
144     struct ConfItem *conf = NULL;
145    
146     if ((conf = find_exact_name_conf(OPER_TYPE,
147     name, source_p->username, source_p->host
148     )) != NULL)
149     {
150     return(conf);
151     }
152    
153     if ((conf = find_exact_name_conf(OPER_TYPE,
154     name, source_p->username,
155     source_p->sockhost)) != NULL)
156     {
157     return(conf);
158     }
159    
160     return(NULL);
161     }
162    
163     /* failed_oper_notice()
164     *
165     * inputs - pointer to client doing /oper ...
166     * - pointer to nick they tried to oper as
167     * - pointer to reason they have failed
168     * output - nothing
169     * side effects - notices all opers of the failed oper attempt if enabled
170     */
171     static void
172     failed_oper_notice(struct Client *source_p, const char *name,
173     const char *reason)
174     {
175     if (ConfigFileEntry.failed_oper_notice)
176     sendto_realops_flags(UMODE_ALL, L_ALL, "Failed OPER attempt as %s "
177     "by %s (%s@%s) - %s", name, source_p->name,
178     source_p->username, source_p->host, reason);
179     }

Properties

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