]> arthur.barton.de Git - ngircd.git/commitdiff
New "module" op.c/op.h for IRC operator related functions
authorAlexander Barton <alex@barton.de>
Wed, 22 Apr 2009 21:17:25 +0000 (23:17 +0200)
committerAlexander Barton <alex@barton.de>
Wed, 30 Sep 2009 14:00:06 +0000 (16:00 +0200)
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
src/ngircd/op.c [new file with mode: 0644]
src/ngircd/op.h [new file with mode: 0644]

index fca531d02847a6f56aaa6a5f9b7137725d38fc67..f94f8d92f055f87fd4adc44c2d73527c77e97b55 100644 (file)
@@ -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 (file)
index 0000000..031bc28
--- /dev/null
@@ -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 <assert.h>
+#include <string.h>
+
+#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 <exp.h>
+#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 (file)
index 0000000..544be25
--- /dev/null
@@ -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- */