ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_oper.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 5181 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


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     struct ConfItem *conf;
76     struct AccessItem *aconf=NULL;
77     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     conf = find_exact_name_conf(OPER_TYPE, name, NULL, NULL);
95     failed_oper_notice(source_p, name, (conf != NULL) ?
96     "host mismatch" : "no oper {} block");
97     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name);
98     return;
99     }
100    
101     aconf = (struct AccessItem *)map_to_conf(conf);
102    
103     if (match_conf_password(password, aconf))
104     {
105     if (attach_conf(source_p, conf) != 0)
106     {
107     sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!",
108     me.name, source_p->name);
109     failed_oper_notice(source_p, name, "can't attach conf!");
110     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name);
111     return;
112     }
113    
114     oper_up(source_p);
115    
116     ilog(L_TRACE, "OPER %s by %s!%s@%s",
117     name, source_p->name, source_p->username, source_p->host);
118     log_oper_action(LOG_OPER_TYPE, source_p, "%s\n", name);
119     }
120     else
121     {
122     sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, parv[0]);
123     failed_oper_notice(source_p, name, "password mismatch");
124     log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name);
125     }
126     }
127    
128     /*
129     ** mo_oper
130     ** parv[0] = sender prefix
131     ** parv[1] = oper name
132     ** parv[2] = oper password
133     */
134     static void
135     mo_oper(struct Client *client_p, struct Client *source_p,
136     int parc, char *parv[])
137     {
138     sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name);
139     send_message_file(source_p, &ConfigFileEntry.opermotd);
140     }
141    
142     /* find_password_conf()
143     *
144     * inputs - name
145     * - pointer to source_p
146     * output - pointer to oper conf or NULL
147     * side effects - NONE
148     */
149     static struct ConfItem *
150     find_password_conf(const char *name, struct Client *source_p)
151     {
152     struct ConfItem *conf = NULL;
153    
154     if ((conf = find_exact_name_conf(OPER_TYPE,
155     name, source_p->username, source_p->host
156     )) != NULL)
157     {
158     return(conf);
159     }
160    
161     if ((conf = find_exact_name_conf(OPER_TYPE,
162     name, source_p->username,
163     source_p->sockhost)) != NULL)
164     {
165     return(conf);
166     }
167    
168     return(NULL);
169     }
170    
171     /* failed_oper_notice()
172     *
173     * inputs - pointer to client doing /oper ...
174     * - pointer to nick they tried to oper as
175     * - pointer to reason they have failed
176     * output - nothing
177     * side effects - notices all opers of the failed oper attempt if enabled
178     */
179     static void
180     failed_oper_notice(struct Client *source_p, const char *name,
181     const char *reason)
182     {
183     if (ConfigFileEntry.failed_oper_notice)
184     sendto_realops_flags(UMODE_ALL, L_ALL, "Failed OPER attempt as %s "
185     "by %s (%s@%s) - %s", name, source_p->name,
186     source_p->username, source_p->host, reason);
187     }

Properties

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