ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_oper.c
Revision: 1155
Committed: Tue Aug 9 20:27:45 2011 UTC (14 years ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/modules/m_oper.c
File size: 5210 byte(s)
Log Message:
- recreate "trunk"

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

Properties

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