From e46cf64cc1e3bf21060df1d1125502277d035170 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Wed, 22 Apr 2009 23:17:25 +0200 Subject: [PATCH] New "module" op.c/op.h for IRC operator related functions The new "module" op.c is used to implement functions related to IRC Ops. At the moment, these two functions are available: - Op_Check() to check for a valid IRC Op, and - Op_NoPrivileges() to generate "permission denied" messages. --- src/ngircd/Makefile.am | 4 +-- src/ngircd/op.c | 82 ++++++++++++++++++++++++++++++++++++++++++ src/ngircd/op.h | 22 ++++++++++++ 3 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/ngircd/op.c create mode 100644 src/ngircd/op.h diff --git a/src/ngircd/Makefile.am b/src/ngircd/Makefile.am index fca531d0..f94f8d92 100644 --- a/src/ngircd/Makefile.am +++ b/src/ngircd/Makefile.am @@ -23,7 +23,7 @@ sbin_PROGRAMS = ngircd ngircd_SOURCES = ngircd.c array.c channel.c client.c conf.c conn.c conn-func.c \ conn-ssl.c conn-zip.c hash.c io.c irc.c irc-channel.c irc-info.c irc-login.c \ irc-mode.c irc-op.c irc-oper.c irc-server.c irc-write.c lists.c log.c \ - match.c numeric.c parse.c rendezvous.c resolve.c + match.c op.c numeric.c parse.c rendezvous.c resolve.c ngircd_LDFLAGS = -L../portab -L../tool -L../ipaddr @@ -32,7 +32,7 @@ ngircd_LDADD = -lngportab -lngtool -lngipaddr noinst_HEADERS = ngircd.h array.h channel.h client.h conf.h conf-ssl.h conn.h \ conn-func.h conn-ssl.h conn-zip.h hash.h io.h irc.h irc-channel.h \ irc-info.h irc-login.h irc-mode.h irc-op.h irc-oper.h irc-server.h \ - irc-write.h lists.h log.h match.h numeric.h parse.h rendezvous.h \ + irc-write.h lists.h log.h match.h numeric.h op.h parse.h rendezvous.h \ resolve.h defines.h messages.h clean-local: diff --git a/src/ngircd/op.c b/src/ngircd/op.c new file mode 100644 index 00000000..031bc281 --- /dev/null +++ b/src/ngircd/op.c @@ -0,0 +1,82 @@ +/* + * ngIRCd -- The Next Generation IRC Daemon + * Copyright (c)2001-2008 Alexander Barton (alex@barton.de) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * Please read the file COPYING, README and AUTHORS for more information. + * + * IRC operator functions + */ + + +#include "portab.h" + +#include "imp.h" +#include +#include + +#include "conn.h" +#include "client.h" +#include "channel.h" +#include "conf.h" +#include "log.h" +#include "parse.h" +#include "messages.h" +#include "irc-write.h" + +#include +#include "op.h" + +/** + * Return and log a "no privileges" message. + */ +GLOBAL bool +Op_NoPrivileges(CLIENT * Client, REQUEST * Req) +{ + CLIENT *from = NULL; + + if (Req->prefix) + from = Client_Search(Req->prefix); + + if (from) { + Log(LOG_NOTICE, "No privileges: client \"%s\" (%s), command \"%s\"", + Req->prefix, Client_Mask(Client), Req->command); + return IRC_WriteStrClient(from, ERR_NOPRIVILEGES_MSG, + Client_ID(from)); + } else { + Log(LOG_NOTICE, "No privileges: client \"%s\", command \"%s\"", + Client_Mask(Client), Req->command); + return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, + Client_ID(Client)); + } +} /* Op_NoPrivileges */ + + +/** + * Check that the client is an IRC operator allowed to administer this server. + */ +GLOBAL bool +Op_Check(CLIENT * Client, REQUEST * Req) +{ + CLIENT *c; + + assert(Client != NULL); + assert(Req != NULL); + + if (Client_Type(Client) == CLIENT_SERVER && Req->prefix) + c = Client_Search(Req->prefix); + else + c = Client; + if (!c) + return false; + if (!Client_HasMode(c, 'o')) + return false; + if (!Client_OperByMe(c) && !Conf_AllowRemoteOper) + return false; + /* The client is an local IRC operator, or this server is configured + * to trust remote operators. */ + return true; +} /* Op_Check */ diff --git a/src/ngircd/op.h b/src/ngircd/op.h new file mode 100644 index 00000000..544be25a --- /dev/null +++ b/src/ngircd/op.h @@ -0,0 +1,22 @@ +/* + * ngIRCd -- The Next Generation IRC Daemon + * Copyright (c)2001-2009 Alexander Barton (alex@barton.de) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * Please read the file COPYING, README and AUTHORS for more information. + * + * Operator management (header) + */ + +#ifndef __oper_h__ +#define __oper_h__ + +GLOBAL bool Op_NoPrivileges PARAMS((CLIENT * Client, REQUEST * Req)); +GLOBAL bool Op_Check PARAMS((CLIENT * Client, REQUEST * Req)); + +#endif + +/* -eof- */ -- 2.39.2