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.
This commit is contained in:
Alexander Barton 2009-04-22 23:17:25 +02:00
parent 113bd34878
commit e46cf64cc1
3 changed files with 106 additions and 2 deletions

View 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 \ 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 \ 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 \ 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 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 \ 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 \ 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-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 resolve.h defines.h messages.h
clean-local: clean-local:

82
src/ngircd/op.c Normal file
View File

@ -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 */

22
src/ngircd/op.h Normal file
View File

@ -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- */