]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/irc-oper.c
SSL/TLS: fix error path in gnutls ssl ctx allocation
[ngircd-alex.git] / src / ngircd / irc-oper.c
index 1b3011761ceab4e4d0b646057144d75d10b2c9ce..b0271df2576a99dff7f3d493034a0765e53b57e3 100644 (file)
@@ -14,8 +14,6 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-oper.c,v 1.27 2006/07/23 15:43:18 alex Exp $";
-
 #include "imp.h"
 #include <assert.h>
 #include <stdlib.h>
@@ -55,10 +53,8 @@ IRC_OPER( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-       /* Falsche Anzahl Parameter? */
        if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
 
-       /* Operator suchen */
        for( i = 0; i < Conf_Oper_Count; i++)
        {
                if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
@@ -66,17 +62,14 @@ IRC_OPER( CLIENT *Client, REQUEST *Req )
        if( i >= Conf_Oper_Count )
                return Bad_OperPass(Client, Req->argv[0], "not configured");
 
-       /* Stimmt das Passwort? */
        if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
                return Bad_OperPass(Client, Conf_Oper[i].name, "Bad password");
 
-       /* Authorized Mask? */
        if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) )))
                return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" );
 
        if( ! Client_HasMode( Client, 'o' ))
        {
-               /* noch kein o-Mode gesetzt */
                Client_ModeAdd( Client, 'o' );
                if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
                IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client ));
@@ -191,12 +184,12 @@ IRC_CONNECT(CLIENT * Client, REQUEST * Req)
                                          Client_ID(Client));
 
        /* Bad number of parameters? */
-       if ((Req->argc != 2) && (Req->argc != 5))
+       if ((Req->argc != 1) && (Req->argc != 2) && (Req->argc != 5))
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
                                          Client_ID(Client), Req->command);
 
        /* Invalid port number? */
-       if (atoi(Req->argv[1]) < 1)
+       if ((Req->argc > 1) && atoi(Req->argv[1]) < 1)
                return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG,
                                          Client_ID(Client), Req->command);
 
@@ -204,14 +197,22 @@ IRC_CONNECT(CLIENT * Client, REQUEST * Req)
            "Got CONNECT command from \"%s\" for \"%s\".", Client_Mask(Client),
            Req->argv[0]);
 
-       if (Req->argc == 2) {
+       switch (Req->argc) {
+       case 1:
+               if (!Conf_EnablePassiveServer(Req->argv[0]))
+                       return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
+                                                 Client_ID(Client),
+                                                 Req->argv[0]);
+       break;
+       case 2:
                /* Connect configured server */
                if (!Conf_EnableServer
                    (Req->argv[0], (UINT16) atoi(Req->argv[1])))
                        return IRC_WriteStrClient(Client, ERR_NOSUCHSERVER_MSG,
                                                  Client_ID(Client),
                                                  Req->argv[0]);
-       } else {
+       break;
+       default:
                /* Add server */
                if (!Conf_AddServer
                    (Req->argv[0], (UINT16) atoi(Req->argv[1]), Req->argv[2],
@@ -255,4 +256,54 @@ IRC_DISCONNECT(CLIENT *Client, REQUEST *Req )
 } /* IRC_CONNECT */
 
 
+GLOBAL bool
+IRC_WALLOPS( CLIENT *Client, REQUEST *Req )
+{
+       CLIENT *to, *from;
+       int client_type;
+
+       assert( Client != NULL );
+       assert( Req != NULL );
+
+       if (Req->argc != 1)
+               return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command);
+
+       client_type = Client_Type(Client);
+       switch (client_type) {
+       case CLIENT_USER:
+               if (!Client_OperByMe(Client))
+                       return IRC_WriteStrClient(Client, ERR_NOPRIVILEGES_MSG, Client_ID(Client));
+               from = Client;
+               break;
+       case CLIENT_SERVER:
+               from = Client_Search(Req->prefix);
+               break;
+       default:
+               return CONNECTED;
+       }
+
+       if (!from)
+               return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->prefix);
+
+       for (to=Client_First(); to != NULL; to=Client_Next(to)) {
+               if (Client_Conn(to) < 0) /* no local connection or WALLOPS origin */
+                       continue;
+
+               client_type = Client_Type(to);
+               switch (client_type) {
+               case CLIENT_USER:
+                       if (Client_HasMode(to, 'w'))
+                               IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);
+                       break;
+               case CLIENT_SERVER:
+                       if (to != Client)
+                               IRC_WriteStrClientPrefix(to, from, "WALLOPS :%s", Req->argv[0]);
+                       break;
+               }
+       }
+       return CONNECTED;
+}
+
+
+
 /* -eof- */