2 * ircd-ratbox: A slightly useful ircd.
3 * m_oper.c: Makes a user an IRC Operator.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: m_oper.c 1483 2006-05-27 18:58:12Z jilles $
30 #include "irc_string.h"
34 #include "s_newconf.h"
44 static int m_oper(struct Client
*, struct Client
*, int, const char **);
46 struct Message oper_msgtab
= {
47 "OPER", 0, 0, 0, MFLG_SLOW
,
48 {mg_unreg
, {m_oper
, 3}, mg_ignore
, mg_ignore
, mg_ignore
, {m_oper
, 3}}
51 mapi_clist_av1 oper_clist
[] = { &oper_msgtab
, NULL
};
52 DECLARE_MODULE_AV1(oper
, NULL
, NULL
, oper_clist
, NULL
, NULL
, "$Revision: 1483 $");
54 static int match_oper_password(const char *password
, struct oper_conf
*oper_p
);
59 * parv[0] = sender prefix
61 * parv[2] = oper password
64 m_oper(struct Client
*client_p
, struct Client
*source_p
, int parc
, const char *parv
[])
66 struct oper_conf
*oper_p
;
75 sendto_one(source_p
, form_str(RPL_YOUREOPER
), me
.name
, source_p
->name
);
76 send_oper_motd(source_p
);
80 /* end the grace period */
81 if(!IsFloodDone(source_p
))
82 flood_endgrace(source_p
);
84 oper_p
= find_oper_conf(source_p
->username
, source_p
->orighost
,
85 source_p
->sockhost
, name
);
89 sendto_one(source_p
, form_str(ERR_NOOPERHOST
), me
.name
, source_p
->name
);
90 ilog(L_FOPER
, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
92 source_p
->username
, source_p
->host
, source_p
->sockhost
);
94 if(ConfigFileEntry
.failed_oper_notice
)
96 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
97 "Failed OPER attempt - host mismatch by %s (%s@%s)",
98 source_p
->name
, source_p
->username
, source_p
->host
);
104 if(match_oper_password(password
, oper_p
))
106 oper_up(source_p
, oper_p
);
108 ilog(L_OPERED
, "OPER %s by %s!%s@%s (%s)",
109 name
, source_p
->name
, source_p
->username
, source_p
->host
,
115 sendto_one(source_p
, form_str(ERR_PASSWDMISMATCH
),
116 me
.name
, source_p
->name
);
118 ilog(L_FOPER
, "FAILED OPER (%s) by (%s!%s@%s) (%s)",
119 name
, source_p
->name
, source_p
->username
, source_p
->host
,
122 if(ConfigFileEntry
.failed_oper_notice
)
124 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
125 "Failed OPER attempt by %s (%s@%s)",
126 source_p
->name
, source_p
->username
, source_p
->host
);
134 * match_oper_password
136 * inputs - pointer to given password
138 * output - YES or NO if match
139 * side effects - none
142 match_oper_password(const char *password
, struct oper_conf
*oper_p
)
146 /* passwd may be NULL pointer. Head it off at the pass... */
147 if(EmptyString(oper_p
->passwd
))
150 if(IsOperConfEncrypted(oper_p
))
152 /* use first two chars of the password they send in as salt */
153 /* If the password in the conf is MD5, and ircd is linked
154 * to scrypt on FreeBSD, or the standard crypt library on
155 * glibc Linux, then this code will work fine on generating
156 * the proper encrypted hash for comparison.
158 if(!EmptyString(password
))
159 encr
= crypt(password
, oper_p
->passwd
);
166 if(strcmp(encr
, oper_p
->passwd
) == 0)