1 |
|
/* |
2 |
< |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
< |
* m_oper.c: Makes a user an IRC Operator. |
2 |
> |
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
4 |
> |
* Copyright (c) 1997-2014 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 |
|
* USA |
20 |
< |
* |
21 |
< |
* $Id$ |
20 |
> |
*/ |
21 |
> |
|
22 |
> |
/*! \file m_oper.c |
23 |
> |
* \brief Includes required functions for processing the OPER command. |
24 |
> |
* \version $Id$ |
25 |
|
*/ |
26 |
|
|
27 |
|
#include "stdinc.h" |
28 |
< |
#include "tools.h" |
27 |
< |
#include "handlers.h" |
28 |
> |
#include "list.h" |
29 |
|
#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" |
33 |
> |
#include "conf.h" |
34 |
> |
#include "log.h" |
35 |
|
#include "s_user.h" |
36 |
|
#include "send.h" |
38 |
– |
#include "list.h" |
39 |
– |
#include "msg.h" |
37 |
|
#include "parse.h" |
38 |
|
#include "modules.h" |
39 |
|
#include "packet.h" |
40 |
|
|
44 |
– |
static struct ConfItem *find_password_conf(const char *, struct Client *); |
45 |
– |
static void failed_oper_notice(struct Client *, const char *, const char *); |
46 |
– |
static void m_oper(struct Client *, struct Client *, int, char *[]); |
47 |
– |
static void mo_oper(struct Client *, struct Client *, int, char *[]); |
41 |
|
|
49 |
– |
struct Message oper_msgtab = { |
50 |
– |
"OPER", 0, 0, 3, 0, MFLG_SLOW, 0, |
51 |
– |
{ m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore } |
52 |
– |
}; |
42 |
|
|
43 |
< |
#ifndef STATIC_MODULES |
44 |
< |
void |
45 |
< |
_modinit(void) |
46 |
< |
{ |
47 |
< |
mod_add_cmd(&oper_msgtab); |
48 |
< |
} |
49 |
< |
|
50 |
< |
void |
62 |
< |
_moddeinit(void) |
63 |
< |
{ |
64 |
< |
mod_del_cmd(&oper_msgtab); |
65 |
< |
} |
66 |
< |
|
67 |
< |
const char *_version = "$Revision$"; |
68 |
< |
#endif |
69 |
< |
|
70 |
< |
/* |
71 |
< |
** m_oper |
72 |
< |
** parv[0] = sender prefix |
73 |
< |
** parv[1] = oper name |
74 |
< |
** parv[2] = oper password |
75 |
< |
*/ |
43 |
> |
/* failed_oper_notice() |
44 |
> |
* |
45 |
> |
* inputs - pointer to client doing /oper ... |
46 |
> |
* - pointer to nick they tried to oper as |
47 |
> |
* - pointer to reason they have failed |
48 |
> |
* output - nothing |
49 |
> |
* side effects - notices all opers of the failed oper attempt if enabled |
50 |
> |
*/ |
51 |
|
static void |
52 |
< |
m_oper(struct Client *client_p, struct Client *source_p, |
53 |
< |
int parc, char *parv[]) |
52 |
> |
failed_oper_notice(struct Client *source_p, const char *name, |
53 |
> |
const char *reason) |
54 |
> |
{ |
55 |
> |
if (ConfigFileEntry.failed_oper_notice) |
56 |
> |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
57 |
> |
"Failed OPER attempt as %s by %s (%s@%s) - %s", |
58 |
> |
name, source_p->name, source_p->username, |
59 |
> |
source_p->host, reason); |
60 |
> |
|
61 |
> |
ilog(LOG_TYPE_OPER, "Failed OPER attempt as %s by %s (%s@%s) - %s", |
62 |
> |
name, source_p->name, source_p->username, |
63 |
> |
source_p->host, reason); |
64 |
> |
} |
65 |
> |
|
66 |
> |
/*! \brief OPER command handler |
67 |
> |
* |
68 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
69 |
> |
* originally comes from. This can be a local or remote client. |
70 |
> |
* \param parc Integer holding the number of supplied arguments. |
71 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
72 |
> |
* pointers. |
73 |
> |
* \note Valid arguments for this command are: |
74 |
> |
* - parv[0] = command |
75 |
> |
* - parv[1] = oper name |
76 |
> |
* - parv[2] = oper password |
77 |
> |
*/ |
78 |
> |
static int |
79 |
> |
m_oper(struct Client *source_p, int parc, char *parv[]) |
80 |
|
{ |
81 |
< |
struct ConfItem *conf; |
81 |
< |
struct AccessItem *aconf=NULL; |
81 |
> |
struct MaskItem *conf = NULL; |
82 |
|
const char *name = parv[1]; |
83 |
|
const char *password = parv[2]; |
84 |
|
|
85 |
|
if (EmptyString(password)) |
86 |
|
{ |
87 |
< |
sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), |
88 |
< |
me.name, source_p->name, "OPER"); |
89 |
< |
return; |
87 |
> |
sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "OPER"); |
88 |
> |
return 0; |
89 |
|
} |
90 |
|
|
91 |
|
/* end the grace period */ |
92 |
|
if (!IsFloodDone(source_p)) |
93 |
|
flood_endgrace(source_p); |
94 |
|
|
95 |
< |
if ((conf = find_password_conf(name, source_p)) == NULL) |
95 |
> |
if ((conf = find_exact_name_conf(CONF_OPER, source_p, name, NULL, NULL)) == NULL) |
96 |
|
{ |
97 |
< |
sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name); |
98 |
< |
conf = find_exact_name_conf(OPER_TYPE, name, NULL, NULL); |
97 |
> |
sendto_one_numeric(source_p, &me, ERR_NOOPERHOST); |
98 |
> |
conf = find_exact_name_conf(CONF_OPER, NULL, name, NULL, NULL); |
99 |
|
failed_oper_notice(source_p, name, (conf != NULL) ? |
100 |
|
"host mismatch" : "no oper {} block"); |
101 |
< |
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
103 |
< |
return; |
101 |
> |
return 0; |
102 |
|
} |
103 |
|
|
104 |
< |
aconf = (struct AccessItem *)map_to_conf(conf); |
104 |
> |
if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL)) |
105 |
> |
{ |
106 |
> |
sendto_one_numeric(source_p, &me, ERR_NOOPERHOST); |
107 |
> |
failed_oper_notice(source_p, name, "requires SSL/TLS"); |
108 |
> |
return 0; |
109 |
> |
} |
110 |
> |
|
111 |
> |
if (!EmptyString(conf->certfp)) |
112 |
> |
{ |
113 |
> |
if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp)) |
114 |
> |
{ |
115 |
> |
sendto_one_numeric(source_p, &me, ERR_NOOPERHOST); |
116 |
> |
failed_oper_notice(source_p, name, "client certificate fingerprint mismatch"); |
117 |
> |
return 0; |
118 |
> |
} |
119 |
> |
} |
120 |
|
|
121 |
< |
if (match_conf_password(password, aconf)) |
121 |
> |
if (match_conf_password(password, conf)) |
122 |
|
{ |
123 |
|
if (attach_conf(source_p, conf) != 0) |
124 |
|
{ |
125 |
< |
sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!", |
113 |
< |
me.name, source_p->name); |
125 |
> |
sendto_one_notice(source_p, &me, ":Can't attach conf!"); |
126 |
|
failed_oper_notice(source_p, name, "can't attach conf!"); |
127 |
< |
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
116 |
< |
return; |
127 |
> |
return 0; |
128 |
|
} |
129 |
|
|
130 |
|
oper_up(source_p); |
131 |
|
|
132 |
< |
ilog(L_TRACE, "OPER %s by %s!%s@%s", |
132 |
> |
ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", |
133 |
|
name, source_p->name, source_p->username, source_p->host); |
123 |
– |
log_oper_action(LOG_OPER_TYPE, source_p, "%s\n", name); |
134 |
|
} |
135 |
|
else |
136 |
|
{ |
137 |
< |
sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, parv[0]); |
137 |
> |
sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH); |
138 |
|
failed_oper_notice(source_p, name, "password mismatch"); |
129 |
– |
log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", name); |
139 |
|
} |
131 |
– |
} |
140 |
|
|
141 |
< |
/* |
134 |
< |
** mo_oper |
135 |
< |
** parv[0] = sender prefix |
136 |
< |
** parv[1] = oper name |
137 |
< |
** parv[2] = oper password |
138 |
< |
*/ |
139 |
< |
static void |
140 |
< |
mo_oper(struct Client *client_p, struct Client *source_p, |
141 |
< |
int parc, char *parv[]) |
142 |
< |
{ |
143 |
< |
sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, source_p->name); |
144 |
< |
send_message_file(source_p, &ConfigFileEntry.opermotd); |
141 |
> |
return 0; |
142 |
|
} |
143 |
|
|
144 |
< |
/* find_password_conf() |
144 |
> |
/*! \brief OPER command handler |
145 |
|
* |
146 |
< |
* inputs - name |
147 |
< |
* - pointer to source_p |
148 |
< |
* output - pointer to oper conf or NULL |
149 |
< |
* side effects - NONE |
146 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
147 |
> |
* originally comes from. This can be a local or remote client. |
148 |
> |
* \param parc Integer holding the number of supplied arguments. |
149 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
150 |
> |
* pointers. |
151 |
> |
* \note Valid arguments for this command are: |
152 |
> |
* - parv[0] = command |
153 |
> |
* - parv[1] = oper name |
154 |
> |
* - parv[2] = oper password |
155 |
|
*/ |
156 |
< |
static struct ConfItem * |
157 |
< |
find_password_conf(const char *name, struct Client *source_p) |
156 |
> |
static int |
157 |
> |
mo_oper(struct Client *source_p, int parc, char *parv[]) |
158 |
|
{ |
159 |
< |
struct ConfItem *conf = NULL; |
160 |
< |
|
161 |
< |
if ((conf = find_exact_name_conf(OPER_TYPE, |
160 |
< |
name, source_p->username, source_p->host |
161 |
< |
)) != NULL) |
162 |
< |
{ |
163 |
< |
return(conf); |
164 |
< |
} |
159 |
> |
sendto_one_numeric(source_p, &me, RPL_YOUREOPER); |
160 |
> |
return 0; |
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); |
171 |
< |
} |
163 |
> |
static struct Message oper_msgtab = |
164 |
> |
{ |
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 |
< |
return(NULL); |
169 |
> |
static void |
170 |
> |
module_init(void) |
171 |
> |
{ |
172 |
> |
mod_add_cmd(&oper_msgtab); |
173 |
|
} |
174 |
|
|
176 |
– |
/* failed_oper_notice() |
177 |
– |
* |
178 |
– |
* inputs - pointer to client doing /oper ... |
179 |
– |
* - pointer to nick they tried to oper as |
180 |
– |
* - pointer to reason they have failed |
181 |
– |
* output - nothing |
182 |
– |
* side effects - notices all opers of the failed oper attempt if enabled |
183 |
– |
*/ |
175 |
|
static void |
176 |
< |
failed_oper_notice(struct Client *source_p, const char *name, |
186 |
< |
const char *reason) |
176 |
> |
module_exit(void) |
177 |
|
{ |
178 |
< |
if (ConfigFileEntry.failed_oper_notice) |
189 |
< |
sendto_realops_flags(UMODE_ALL, L_ALL, "Failed OPER attempt as %s " |
190 |
< |
"by %s (%s@%s) - %s", name, source_p->name, |
191 |
< |
source_p->username, source_p->host, reason); |
178 |
> |
mod_del_cmd(&oper_msgtab); |
179 |
|
} |
180 |
+ |
|
181 |
+ |
struct module module_entry = |
182 |
+ |
{ |
183 |
+ |
.node = { NULL, NULL, NULL }, |
184 |
+ |
.name = NULL, |
185 |
+ |
.version = "$Revision$", |
186 |
+ |
.handle = NULL, |
187 |
+ |
.modinit = module_init, |
188 |
+ |
.modexit = module_exit, |
189 |
+ |
.flags = 0 |
190 |
+ |
}; |