]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-mode.c
New configuration option "NoZeroConf" to disable ZeroConf registration
[ngircd-alex.git] / src / ngircd / irc-mode.c
index 9ada4f13c7f1e437733b4e2ea42bd89273bc4ba4..df464a7dba7efca0058cdede4d18ec8090a7eeea 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2008 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2010 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
 
 #include "defines.h"
 #include "conn.h"
-#include "client.h"
 #include "channel.h"
 #include "irc-write.h"
 #include "lists.h"
 #include "log.h"
 #include "parse.h"
 #include "messages.h"
-#include "resolve.h"
 #include "conf.h"
 
 #include "exp.h"
 #include "irc-mode.h"
 
 
-static bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
-static bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
+static bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin,
+       CLIENT *Target ));
+static bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin,
+       CHANNEL *Channel ));
 
-static bool Add_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern));
-static bool Del_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern));
+static bool Add_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client,
+       CHANNEL *Channel, const char *Pattern));
+static bool Del_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client,
+       CHANNEL *Channel, const char *Pattern));
 
-static bool Send_ListChange PARAMS(( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Mask ));
+static bool Send_ListChange PARAMS((const char *Mode, CLIENT *Prefix,
+       CLIENT *Client, CHANNEL *Channel, const char *Mask));
 
 
 GLOBAL bool
@@ -172,6 +175,17 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
                                else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
                                break;
 
+                       case 'c': /* Receive connect notices
+                                  * (only settable by IRC operators!) */
+                               if(!set || Client_OperByMe(Origin)
+                                  || Client_Type(Client) == CLIENT_SERVER)
+                                       x[0] = 'c';
+                               else
+                                       ok = IRC_WriteStrClient(Origin,
+                                                       ERR_NOPRIVILEGES_MSG,
+                                                       Client_ID(Origin));
+                               break;
+
                        case 'o': /* IRC operator (only unsettable!) */
                                if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
                                {
@@ -186,6 +200,15 @@ Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
                                else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
                                break;
 
+                       case 'x': /* Cloak hostname */
+                               if (Client_HasMode(Client, 'r'))
+                                       IRC_WriteStrClient(Origin,
+                                                          ERR_RESTRICTED_MSG,
+                                                          Client_ID(Origin));
+                               else
+                                       x[0] = 'x';
+                               break;
+
                        default:
                                Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ));
                                if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
@@ -284,14 +307,14 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
 {
        char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2],
            argadd[CLIENT_PASS_LEN], *mode_ptr;
-       bool ok, set, modeok = true, skiponce, use_servermode = false, retval;
+       bool connected, set, skiponce, retval, onchannel;
+       bool modeok = true, use_servermode = false;
        int mode_arg, arg_arg;
        CLIENT *client;
        long l;
        size_t len;
 
-       /* Are modes allowed on channel? */
-       if (Channel_Name(Channel)[0] == '+')
+       if (Channel_IsModeless(Channel))
                return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
                                Client_ID(Client), Channel_Name(Channel));
 
@@ -302,14 +325,13 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
        /* Is the user allowed to change modes? */
        if (Client_Type(Client) == CLIENT_USER) {
                /* Is the originating user on that channel? */
-               if (!Channel_IsMemberOf(Channel, Origin))
-                       return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
-                               Client_ID(Origin), Channel_Name(Channel));
+               onchannel = Channel_IsMemberOf(Channel, Origin);
                modeok = false;
                /* channel operator? */
-               if (strchr(Channel_UserModes(Channel, Origin), 'o'))
+               if (onchannel &&
+                   strchr(Channel_UserModes(Channel, Origin), 'o')) {
                        modeok = true;
-               else if (Conf_OperCanMode) {
+               else if (Conf_OperCanMode) {
                        /* IRC-Operators can use MODE as well */
                        if (Client_OperByMe(Origin)) {
                                modeok = true;
@@ -317,6 +339,10 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                        use_servermode = true; /* Change Origin to Server */
                        }
                }
+
+               if (!onchannel && !modeok)
+                       return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
+                               Client_ID(Origin), Channel_Name(Channel));
        }
 
        mode_arg = 1;
@@ -345,7 +371,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
        the_args[0] = '\0';
 
        x[1] = '\0';
-       ok = CONNECTED;
+       connected = CONNECTED;
        while (mode_ptr) {
                if (!skiponce)
                        mode_ptr++;
@@ -402,10 +428,11 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                case 'n': /* Only members can write */
                case 's': /* Secret channel */
                case 't': /* Topic locked */
+               case 'z': /* Secure connections only */
                        if (modeok)
                                x[0] = *mode_ptr;
                        else
-                               ok = IRC_WriteStrClient(Origin,
+                               connected = IRC_WriteStrClient(Origin,
                                        ERR_CHANOPRIVSNEEDED_MSG,
                                        Client_ID(Origin), Channel_Name(Channel));
                        break;
@@ -414,7 +441,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                if (modeok)
                                        x[0] = *mode_ptr;
                                else
-                                       ok = IRC_WriteStrClient(Origin,
+                                       connected = IRC_WriteStrClient(Origin,
                                                ERR_CHANOPRIVSNEEDED_MSG,
                                                Client_ID(Origin),
                                                Channel_Name(Channel));
@@ -429,7 +456,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                                sizeof(argadd));
                                        x[0] = *mode_ptr;
                                } else {
-                                       ok = IRC_WriteStrClient(Origin,
+                                       connected = IRC_WriteStrClient(Origin,
                                                ERR_CHANOPRIVSNEEDED_MSG,
                                                Client_ID(Origin),
                                                Channel_Name(Channel));
@@ -437,7 +464,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                Req->argv[arg_arg][0] = '\0';
                                arg_arg++;
                        } else {
-                               ok = IRC_WriteStrClient(Origin,
+                               connected = IRC_WriteStrClient(Origin,
                                        ERR_NEEDMOREPARAMS_MSG,
                                        Client_ID(Origin), Req->command);
                                goto chan_exit;
@@ -448,7 +475,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                if (modeok)
                                        x[0] = *mode_ptr;
                                else
-                                       ok = IRC_WriteStrClient(Origin,
+                                       connected = IRC_WriteStrClient(Origin,
                                                ERR_CHANOPRIVSNEEDED_MSG,
                                                Client_ID(Origin),
                                                Channel_Name(Channel));
@@ -465,7 +492,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                                x[0] = *mode_ptr;
                                        }
                                } else {
-                                       ok = IRC_WriteStrClient(Origin,
+                                       connected = IRC_WriteStrClient(Origin,
                                                ERR_CHANOPRIVSNEEDED_MSG,
                                                Client_ID(Origin),
                                                Channel_Name(Channel));
@@ -473,7 +500,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                Req->argv[arg_arg][0] = '\0';
                                arg_arg++;
                        } else {
-                               ok = IRC_WriteStrClient(Origin,
+                               connected = IRC_WriteStrClient(Origin,
                                        ERR_NEEDMOREPARAMS_MSG,
                                        Client_ID(Origin), Req->command);
                                goto chan_exit;
@@ -485,13 +512,13 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                 * set the 'P' channel mode! */
                                if (set && !(Client_OperByMe(Client)
                                    || Client_Type(Client) == CLIENT_SERVER))
-                                       ok = IRC_WriteStrClient(Origin,
+                                       connected = IRC_WriteStrClient(Origin,
                                                ERR_NOPRIVILEGES_MSG,
                                                Client_ID(Origin));
                                else
                                        x[0] = 'P';
                        } else
-                               ok = IRC_WriteStrClient(Origin,
+                               connected = IRC_WriteStrClient(Origin,
                                        ERR_CHANOPRIVSNEEDED_MSG,
                                        Client_ID(Origin),
                                        Channel_Name(Channel));
@@ -505,12 +532,12 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                        if (client)
                                                x[0] = *mode_ptr;
                                        else
-                                               ok = IRC_WriteStrClient(Client,
+                                               connected = IRC_WriteStrClient(Client,
                                                        ERR_NOSUCHNICK_MSG,
                                                        Client_ID(Client),
                                                        Req->argv[arg_arg]);
                                } else {
-                                       ok = IRC_WriteStrClient(Origin,
+                                       connected = IRC_WriteStrClient(Origin,
                                                ERR_CHANOPRIVSNEEDED_MSG,
                                                Client_ID(Origin),
                                                Channel_Name(Channel));
@@ -518,7 +545,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                Req->argv[arg_arg][0] = '\0';
                                arg_arg++;
                        } else {
-                               ok = IRC_WriteStrClient(Origin,
+                               connected = IRC_WriteStrClient(Origin,
                                        ERR_NEEDMOREPARAMS_MSG,
                                        Client_ID(Origin), Req->command);
                                goto chan_exit;
@@ -530,7 +557,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                        if (arg_arg > mode_arg) {
                                /* modify list */
                                if (modeok) {
-                                       ok = set
+                                       connected = set
                                           ? Add_Ban_Invite(*mode_ptr, Origin,
                                                Client, Channel,
                                                Req->argv[arg_arg])
@@ -538,7 +565,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                                                Client, Channel,
                                                Req->argv[arg_arg]);
                                } else {
-                                       ok = IRC_WriteStrClient(Origin,
+                                       connected = IRC_WriteStrClient(Origin,
                                                ERR_CHANOPRIVSNEEDED_MSG,
                                                Client_ID(Origin),
                                                Channel_Name(Channel));
@@ -558,7 +585,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                            set ? '+' : '-', *mode_ptr, Client_ID(Origin),
                            Channel_Name(Channel));
                        if (Client_Type(Client) != CLIENT_SERVER)
-                               ok = IRC_WriteStrClient(Origin,
+                               connected = IRC_WriteStrClient(Origin,
                                        ERR_UMODEUNKNOWNFLAG2_MSG,
                                        Client_ID(Origin),
                                        set ? '+' : '-', *mode_ptr);
@@ -566,7 +593,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                        goto chan_exit;
                }       /* switch() */
 
-               if (!ok)
+               if (!connected)
                        break;
 
                /* Is there a valid mode change? */
@@ -647,7 +674,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                        if (use_servermode)
                                Origin = Client_ThisServer();
                        /* Send reply to client and inform other servers and channel users */
-                       ok = IRC_WriteStrClientPrefix(Client, Origin,
+                       connected = IRC_WriteStrClientPrefix(Client, Origin,
                                        "MODE %s %s%s", Channel_Name(Channel),
                                        the_modes, the_args);
                        /* Only forward requests for non-local channels */
@@ -662,7 +689,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
        }
 
        IRC_SetPenalty(Client, 1);
-       return CONNECTED;
+       return connected;
 } /* Channel_Mode */
 
 
@@ -672,12 +699,10 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       /* Falsche Anzahl Parameter? */
        if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
        if(( Req->argc == 1 ) && (Req->argv[0][0] ))
        {
-               /* AWAY setzen */
                Client_SetAway( Client, Req->argv[0] );
                Client_ModeAdd( Client, 'a' );
                IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
@@ -685,7 +710,6 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req )
        }
        else
        {
-               /* AWAY loeschen */
                Client_ModeDel( Client, 'a' );
                IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
                return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
@@ -751,23 +775,22 @@ Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const
 
 
 static bool
-Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Mask )
+Send_ListChange(const char *Mode, CLIENT *Prefix, CLIENT *Client,
+               CHANNEL *Channel, const char *Mask)
 {
-       /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
-
        bool ok;
 
        if( Client_Type( Client ) == CLIENT_USER )
        {
-               /* Bestaetigung an Client */
+               /* send confirmation to client */
                ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
        }
        else ok = true;
 
-       /* an andere Server */
+       /* to other servers */
        IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
 
-       /* und lokale User im Channel */
+       /* and local users in channel */
        IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
        
        return ok;