Remove CLIENT.oper_by_my, Client_SetOperByMe() and Client_OperByMe()

All places where Client_OperByMe() is used can either be converted to
Client_HasMode(Client, 'o') or Op_Check().

And Op_Check() itself can use the connection handle for deciding whether
the IRC Operator is a local user or not.
This commit is contained in:
Alexander Barton 2013-09-25 01:29:23 +02:00
parent ec5ab4fcd1
commit eccbd97e1f
7 changed files with 21 additions and 50 deletions

View File

@ -545,14 +545,6 @@ Client_SetIntroducer( CLIENT *Client, CLIENT *Introducer )
} /* Client_SetIntroducer */
GLOBAL void
Client_SetOperByMe( CLIENT *Client, bool OperByMe )
{
assert( Client != NULL );
Client->oper_by_me = OperByMe;
} /* Client_SetOperByMe */
GLOBAL bool
Client_ModeAdd( CLIENT *Client, char Mode )
{
@ -889,14 +881,6 @@ Client_Flags( CLIENT *Client )
} /* Client_Flags */
GLOBAL bool
Client_OperByMe( CLIENT *Client )
{
assert( Client != NULL );
return Client->oper_by_me;
} /* Client_OperByMe */
GLOBAL int
Client_Hops( CLIENT *Client )
{
@ -1426,7 +1410,6 @@ New_Client_Struct( void )
c->type = CLIENT_UNKNOWN;
c->conn_id = NONE;
c->oper_by_me = false;
c->hops = -1;
c->token = -1;
c->mytoken = -1;

View File

@ -58,7 +58,6 @@ typedef struct _CLIENT
char info[CLIENT_INFO_LEN]; /* long user name (user) / info text (server) */
char modes[CLIENT_MODE_LEN]; /* client modes */
int hops, token, mytoken; /* "hops" and "Token" (see SERVER command) */
bool oper_by_me; /* client is local IRC operator on this server? */
char *away; /* AWAY text (valid if mode 'a' is set) */
char flags[CLIENT_FLAGS_LEN]; /* flags of the client */
char *account_name; /* login account (for services) */
@ -120,7 +119,6 @@ GLOBAL const char *Client_IPAText PARAMS(( CLIENT *Client ));
GLOBAL char *Client_Modes PARAMS(( CLIENT *Client ));
GLOBAL char *Client_Flags PARAMS(( CLIENT *Client ));
GLOBAL CLIENT *Client_Introducer PARAMS(( CLIENT *Client ));
GLOBAL bool Client_OperByMe PARAMS(( CLIENT *Client ));
GLOBAL int Client_Hops PARAMS(( CLIENT *Client ));
GLOBAL int Client_Token PARAMS(( CLIENT *Client ));
GLOBAL int Client_MyToken PARAMS(( CLIENT *Client ));
@ -142,7 +140,6 @@ GLOBAL void Client_SetInfo PARAMS(( CLIENT *Client, const char *Info ));
GLOBAL void Client_SetType PARAMS(( CLIENT *Client, int Type ));
GLOBAL void Client_SetHops PARAMS(( CLIENT *Client, int Hops ));
GLOBAL void Client_SetToken PARAMS(( CLIENT *Client, int Token ));
GLOBAL void Client_SetOperByMe PARAMS(( CLIENT *Client, bool OperByMe ));
GLOBAL void Client_SetModes PARAMS(( CLIENT *Client, const char *Modes ));
GLOBAL void Client_SetFlags PARAMS(( CLIENT *Client, const char *Flags ));
GLOBAL void Client_SetIntroducer PARAMS(( CLIENT *Client, CLIENT *Introducer ));

View File

@ -129,7 +129,7 @@ join_allowed(CLIENT *Client, CHANNEL *chan, const char *channame,
return false;
}
if (Channel_HasMode(chan, 'O') && !Client_OperByMe(Client)) {
if (Channel_HasMode(chan, 'O') && !Client_HasMode(Client, 'o')) {
/* Only IRC operators are allowed! */
IRC_WriteErrClient(Client, ERR_OPONLYCHANNEL_MSG,
Client_ID(Client), channame);
@ -619,7 +619,10 @@ IRC_LIST( CLIENT *Client, REQUEST *Req )
/* Gotcha! */
if (!Channel_HasMode(chan, 's')
|| Channel_IsMemberOf(chan, from)
|| (!Conf_MorePrivacy && Client_OperByMe(Client))) {
|| (!Conf_MorePrivacy
&& Client_HasMode(Client, 'o')
&& Client_Conn(Client) > NONE))
{
if ((Conf_MaxListSize > 0)
&& IRC_CheckListTooBig(from, count,
Conf_MaxListSize,

View File

@ -223,11 +223,12 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
else
x[0] = 'B';
break;
case 'c': /* Receive connect notices
* (only settable by IRC operators!) */
case 'c': /* Receive connect notices */
case 'q': /* KICK-protected user */
/* (only settable by IRC operators!) */
if (!set || Client_Type(Client) == CLIENT_SERVER
|| Client_OperByMe(Origin))
x[0] = 'c';
|| Client_HasMode(Origin, 'o'))
x[0] = *mode_ptr;
else
ok = IRC_WriteErrClient(Origin,
ERR_NOPRIVILEGES_MSG,
@ -235,22 +236,12 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
break;
case 'o': /* IRC operator (only unsettable!) */
if (!set || Client_Type(Client) == CLIENT_SERVER) {
Client_SetOperByMe(Target, false);
x[0] = 'o';
} else
ok = IRC_WriteErrClient(Origin,
ERR_NOPRIVILEGES_MSG,
Client_ID(Origin));
break;
case 'q': /* KICK-protected user */
if (!set || Client_Type(Client) == CLIENT_SERVER
|| Client_OperByMe(Origin))
x[0] = 'q';
else
ok = IRC_WriteErrClient(Origin,
ERR_NOPRIVILEGES_MSG,
Client_ID(Origin));
break;
case 'r': /* Restricted (only settable) */
if (set || Client_Type(Client) == CLIENT_SERVER)
x[0] = 'r';
@ -274,7 +265,7 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
Client_ID(Origin));
else if (!set || Conf_CloakHostModeX[0]
|| Client_Type(Client) == CLIENT_SERVER
|| Client_OperByMe(Client)) {
|| Client_HasMode(Origin, 'o')) {
x[0] = 'x';
send_RPL_HOSTHIDDEN_MSG = true;
} else
@ -455,7 +446,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
/* Check if origin is oper and opers can use mode */
use_servermode = Conf_OperServerMode;
if(Client_OperByMe(Client) && Conf_OperCanMode) {
if(Client_HasMode(Client, 'o') && Conf_OperCanMode) {
is_oper = true;
}

View File

@ -90,12 +90,10 @@ IRC_OPER( CLIENT *Client, REQUEST *Req )
Client_ID(Client));
}
if (!Client_OperByMe(Client))
Log(LOG_NOTICE|LOG_snotice,
"Got valid OPER for \"%s\" from \"%s\", user is an IRC operator now.",
Req->argv[0], Client_Mask(Client));
Log(LOG_NOTICE|LOG_snotice,
"Got valid OPER for \"%s\" from \"%s\", user is an IRC operator now.",
Req->argv[0], Client_Mask(Client));
Client_SetOperByMe(Client, true);
return IRC_WriteStrClient(Client, RPL_YOUREOPER_MSG, Client_ID(Client));
} /* IRC_OPER */
@ -357,9 +355,8 @@ IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
switch (Client_Type(Client)) {
case CLIENT_USER:
if (!Client_OperByMe(Client))
return IRC_WriteErrClient(Client, ERR_NOPRIVILEGES_MSG,
Client_ID(Client));
if (!Op_Check(Client, Req))
return Op_NoPrivileges(Client, Req);
from = Client;
break;
case CLIENT_SERVER:

View File

@ -33,6 +33,7 @@
#include "match.h"
#include "messages.h"
#include "parse.h"
#include "op.h"
#include "tool.h"
#include "exp.h"
@ -134,9 +135,8 @@ IRC_KILL(CLIENT *Client, REQUEST *Req)
assert (Client != NULL);
assert (Req != NULL);
if (Client_Type(Client) != CLIENT_SERVER && !Client_OperByMe(Client))
return IRC_WriteErrClient(Client, ERR_NOPRIVILEGES_MSG,
Client_ID(Client));
if (Client_Type(Client) != CLIENT_SERVER && !Op_Check(Client, Req))
return Op_NoPrivileges(Client, Req);
/* Get prefix (origin); use the client if no prefix is given. */
if (Req->prefix)

View File

@ -86,7 +86,7 @@ Op_Check(CLIENT * Client, REQUEST * Req)
return c;
if (!Client_HasMode(c, 'o'))
return NULL;
if (!Client_OperByMe(c) && !Conf_AllowRemoteOper)
if (Client_Conn(c) <= NONE && !Conf_AllowRemoteOper)
return NULL;
/* The client is an local IRC operator, or this server is configured