ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_oper.c
(Generate patch)

Comparing ircd-hybrid/trunk/modules/m_oper.c (file contents):
Revision 1618 by michael, Tue Oct 30 21:04:38 2012 UTC vs.
Revision 7403 by michael, Sun Mar 6 16:33:12 2016 UTC

# Line 1 | Line 1
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-2016 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
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
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"
# Line 30 | Line 32
32   #include "numeric.h"
33   #include "conf.h"
34   #include "log.h"
35 < #include "s_user.h"
35 > #include "user.h"
36   #include "send.h"
37   #include "parse.h"
38   #include "modules.h"
39   #include "packet.h"
40  
41  
42 + /*! \brief Blindly opers up given source_p, using conf info.
43 + *         All checks on passwords have already been done.
44 + * \param source_p Pointer to given client to oper
45 + */
46 + static void
47 + oper_up(struct Client *source_p)
48 + {
49 +  const unsigned int old = source_p->umodes;
50 +  const struct MaskItem *const conf = source_p->connection->confs.head->data;
51 +
52 +  ++Count.oper;
53 +  SetOper(source_p);
54 +
55 +  if (conf->modes)
56 +    AddUMode(source_p, conf->modes);
57 +  else if (ConfigGeneral.oper_umodes)
58 +    AddUMode(source_p, ConfigGeneral.oper_umodes);
59 +
60 +  if (!(old & UMODE_INVISIBLE) && HasUMode(source_p, UMODE_INVISIBLE))
61 +    ++Count.invisi;
62 +  else if ((old & UMODE_INVISIBLE) && !HasUMode(source_p, UMODE_INVISIBLE))
63 +    --Count.invisi;
64  
65 < /* failed_oper_notice()
65 >  assert(dlinkFind(&oper_list, source_p) == NULL);
66 >  dlinkAdd(source_p, make_dlink_node(), &oper_list);
67 >
68 >  AddOFlag(source_p, conf->port);
69 >
70 >  if (HasOFlag(source_p, OPER_FLAG_ADMIN))
71 >    AddUMode(source_p, UMODE_ADMIN);
72 >
73 >  if (!EmptyString(conf->whois))
74 >  {
75 >    client_attach_svstag(source_p, RPL_WHOISOPERATOR, "+", conf->whois);
76 >    sendto_server(source_p, 0, 0, ":%s SVSTAG %s %ju %u + :%s",
77 >                  me.id, source_p->id, source_p->tsinfo,
78 >                  RPL_WHOISOPERATOR, conf->whois);
79 >  }
80 >
81 >  sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "%s is now an operator",
82 >                       get_oper_name(source_p));
83 >  sendto_server(NULL, 0, 0, ":%s GLOBOPS :%s is now an operator",
84 >                me.id, get_oper_name(source_p));
85 >  send_umode_out(source_p, old);
86 >  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
87 > }
88 >
89 > /*! \brief Notices all opers of the failed oper attempt if enabled
90   *
91 < * inputs       - pointer to client doing /oper ...
92 < *              - pointer to nick they tried to oper as
93 < *              - pointer to reason they have failed
46 < * output       - nothing
47 < * side effects - notices all opers of the failed oper attempt if enabled
91 > * \param source_p Client doing /oper ...
92 > * \param name     The nick they tried to oper as
93 > * \param reason   The reason why they have failed
94   */
95   static void
96   failed_oper_notice(struct Client *source_p, const char *name,
97                     const char *reason)
98   {
99 <  if (ConfigFileEntry.failed_oper_notice)
100 <    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
99 >  if (ConfigGeneral.failed_oper_notice)
100 >    sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
101                           "Failed OPER attempt as %s by %s (%s@%s) - %s",
102                           name, source_p->name, source_p->username,
103                           source_p->host, reason);
# Line 61 | Line 107 | failed_oper_notice(struct Client *source
107         source_p->host, reason);
108   }
109  
110 < /*
111 < ** m_oper
112 < **      parv[0] = sender prefix
113 < **      parv[1] = oper name
114 < **      parv[2] = oper password
115 < */
116 < static void
117 < m_oper(struct Client *client_p, struct Client *source_p,
118 <       int parc, char *parv[])
110 > /*! \brief OPER command handler
111 > *
112 > * \param source_p Pointer to allocated Client struct from which the message
113 > *                 originally comes from.  This can be a local or remote client.
114 > * \param parc     Integer holding the number of supplied arguments.
115 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
116 > *                 pointers.
117 > * \note Valid arguments for this command are:
118 > *      - parv[0] = command
119 > *      - parv[1] = oper name
120 > *      - parv[2] = oper password
121 > */
122 > static int
123 > m_oper(struct Client *source_p, int parc, char *parv[])
124   {
125 <  struct ConfItem *conf;
126 <  struct AccessItem *aconf=NULL;
127 <  const char *name = parv[1];
77 <  const char *password = parv[2];
125 >  struct MaskItem *conf = NULL;
126 >  const char *const opername = parv[1];
127 >  const char *const password = parv[2];
128  
129    if (EmptyString(password))
130    {
131 <    sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
132 <               me.name, source_p->name, "OPER");
83 <    return;
131 >    sendto_one_numeric(source_p, &me, ERR_NEEDMOREPARAMS, "OPER");
132 >    return 0;
133    }
134  
135    /* end the grace period */
136    if (!IsFloodDone(source_p))
137      flood_endgrace(source_p);
138  
139 <  if ((conf = find_exact_name_conf(OPER_TYPE, source_p, name, NULL, NULL)) == NULL)
139 >  if ((conf = operator_find(source_p, opername)) == NULL)
140    {
141 <    sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, source_p->name);
142 <    conf = find_exact_name_conf(OPER_TYPE, NULL, name, NULL, NULL);
143 <    failed_oper_notice(source_p, name, (conf != NULL) ?
144 <                       "host mismatch" : "no oper {} block");
145 <    return;
141 >    sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
142 >    conf = operator_find(NULL, opername);
143 >    failed_oper_notice(source_p, opername, (conf != NULL) ?
144 >                       "host mismatch" : "no operator {} block");
145 >    return 0;
146    }
147  
148 <  aconf = map_to_conf(conf);
148 >  if (IsConfSSL(conf) && !HasUMode(source_p, UMODE_SSL))
149 >  {
150 >    sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
151 >    failed_oper_notice(source_p, opername, "requires SSL/TLS");
152 >    return 0;
153 >  }
154  
155 <  if (match_conf_password(password, aconf))
155 >  if (!EmptyString(conf->certfp))
156    {
157 <    if (attach_conf(source_p, conf) != 0)
157 >    if (EmptyString(source_p->certfp) || strcasecmp(source_p->certfp, conf->certfp))
158      {
159 <      sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!",
160 <                 me.name, source_p->name);
161 <      failed_oper_notice(source_p, name, "can't attach conf!");
162 <      return;
159 >      sendto_one_numeric(source_p, &me, ERR_NOOPERHOST);
160 >      failed_oper_notice(source_p, opername, "client certificate fingerprint mismatch");
161 >      return 0;
162 >    }
163 >  }
164 >
165 >  if (match_conf_password(password, conf))
166 >  {
167 >    if (attach_conf(source_p, conf))
168 >    {
169 >      sendto_one_notice(source_p, &me, ":Can't attach conf!");
170 >      failed_oper_notice(source_p, opername, "can't attach conf!");
171 >      return 0;
172      }
173  
174      oper_up(source_p);
175  
176 <    ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s",
177 <         name, source_p->name, source_p->username, source_p->host);
176 >    ilog(LOG_TYPE_OPER, "OPER %s by %s!%s@%s", opername, source_p->name,
177 >         source_p->username, source_p->host);
178    }
179    else
180    {
181 <    sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name);
182 <    failed_oper_notice(source_p, name, "password mismatch");
181 >    sendto_one_numeric(source_p, &me, ERR_PASSWDMISMATCH);
182 >    failed_oper_notice(source_p, opername, "password mismatch");
183    }
184 +
185 +  return 0;
186   }
187  
188 < /*
189 < ** mo_oper
190 < **      parv[0] = sender prefix
191 < **      parv[1] = oper name
192 < **      parv[2] = oper password
193 < */
194 < static void
195 < mo_oper(struct Client *client_p, struct Client *source_p,
196 <        int parc, char *parv[])
188 > /*! \brief OPER command handler
189 > *
190 > * \param source_p Pointer to allocated Client struct from which the message
191 > *                 originally comes from.  This can be a local or remote client.
192 > * \param parc     Integer holding the number of supplied arguments.
193 > * \param parv     Argument vector where parv[0] .. parv[parc-1] are non-NULL
194 > *                 pointers.
195 > * \note Valid arguments for this command are:
196 > *      - parv[0] = command
197 > *      - parv[1] = oper name
198 > *      - parv[2] = oper password
199 > */
200 > static int
201 > mo_oper(struct Client *source_p, int parc, char *parv[])
202   {
203 <  sendto_one(source_p, form_str(RPL_YOUREOPER),
204 <             me.name, source_p->name);
203 >  sendto_one_numeric(source_p, &me, RPL_YOUREOPER);
204 >  return 0;
205   }
206  
207 < static struct Message oper_msgtab = {
208 <  "OPER", 0, 0, 3, MAXPARA, MFLG_SLOW, 0,
209 <  { m_unregistered, m_oper, m_ignore, m_ignore, mo_oper, m_ignore }
207 > static struct Message oper_msgtab =
208 > {
209 >  .cmd = "OPER",
210 >  .args_min = 3,
211 >  .args_max = MAXPARA,
212 >  .handlers[UNREGISTERED_HANDLER] = m_unregistered,
213 >  .handlers[CLIENT_HANDLER] = m_oper,
214 >  .handlers[SERVER_HANDLER] = m_ignore,
215 >  .handlers[ENCAP_HANDLER] = m_ignore,
216 >  .handlers[OPER_HANDLER] = mo_oper
217   };
218  
219   static void
# Line 151 | Line 228 | module_exit(void)
228    mod_del_cmd(&oper_msgtab);
229   }
230  
231 < struct module module_entry = {
232 <  .node    = { NULL, NULL, NULL },
156 <  .name    = NULL,
231 > struct module module_entry =
232 > {
233    .version = "$Revision$",
158  .handle  = NULL,
234    .modinit = module_init,
235    .modexit = module_exit,
161  .flags   = 0
236   };

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)