]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Merge branch 'recognize-umode-R'
authorAlexander Barton <alex@barton.de>
Mon, 27 Aug 2012 21:21:28 +0000 (23:21 +0200)
committerAlexander Barton <alex@barton.de>
Mon, 27 Aug 2012 21:21:28 +0000 (23:21 +0200)
By Alexander Barton (1) and DNS777 (1)

* recognize-umode-R:
  Only allow IRC services to modify user mode "R"
  Recognize user mode "R"

15 files changed:
doc/Modes.txt
src/ngircd/channel.c
src/ngircd/client.c
src/ngircd/client.h
src/ngircd/conn.c
src/ngircd/conn.h
src/ngircd/defines.h
src/ngircd/irc-cap.c
src/ngircd/irc-login.c
src/ngircd/irc-mode.c
src/ngircd/irc-server.c
src/ngircd/login.c
src/ngircd/messages.h
src/ngircd/pam.c
src/tool/tool.c

index e47e2707244f9d30894c6b108357918468fa92af..2b700f0cb66a5da6065eb07bf2e8ae2733908da3 100644 (file)
@@ -49,6 +49,7 @@ users to lists (e.g. "invite list", "ban list"), others have parameters
   k    0.6.0   Channel has a "key" (a password).
   l    0.6.0   Channel has a user limit.
   m    0.3.0   Channel is moderated, only "voiced" users can send messages.
+  M    20      Only registered users (and IRC Ops) can send messages.
   n    0.3.0   Channel doesn't allow messages of users not being members.
   O    18      Only IRC operators are allowed to join this channel.
   P    0.5.0   Channel is "persistent".
index ff470246fec79e09d67ab764c6bca583138e2a00..0f21a459c3a6644c0f14b2c581f8a45aca154bdc 100644 (file)
@@ -832,6 +832,10 @@ Can_Send_To_Channel(CHANNEL *Chan, CLIENT *From)
        if (strchr(Channel_Modes(Chan), 'n') && !is_member)
                return false;
 
+       if (strchr(Channel_Modes(Chan), 'M') && !Client_HasMode(From, 'R')
+           && !Client_HasMode(From, 'o'))
+               return false;
+
        if (is_op || has_voice)
                return true;
 
index f163f72c371e2a84121a84d178c3552530109b3d..0d2d4147345046b87f7f3c6e46fd018749f4da36 100644 (file)
@@ -440,18 +440,6 @@ Client_SetFlags( CLIENT *Client, const char *Flags )
 } /* Client_SetFlags */
 
 
-GLOBAL void
-Client_SetPassword( CLIENT *Client, const char *Pwd )
-{
-       /* set password sent by client */
-
-       assert( Client != NULL );
-       assert( Pwd != NULL );
-
-       strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
-} /* Client_SetPassword */
-
-
 GLOBAL void
 Client_SetAway( CLIENT *Client, const char *Txt )
 {
@@ -714,14 +702,6 @@ Client_HostnameCloaked(CLIENT *Client)
 } /* Client_HostnameCloaked */
 
 
-GLOBAL char *
-Client_Password( CLIENT *Client )
-{
-       assert( Client != NULL );
-       return Client->pwd;
-} /* Client_Password */
-
-
 GLOBAL char *
 Client_Modes( CLIENT *Client )
 {
index 4dbcc7a072232eacfe7cf45020cd2136fb774eb2..16b2a61ab8564808ad6c58066898602e30431cab 100644 (file)
@@ -47,7 +47,6 @@ typedef struct _CLIENT
        CONN_ID conn_id;                /* ID of the connection (if local) or NONE (remote) */
        struct _CLIENT *introducer;     /* ID of the servers which the client is connected to */
        struct _CLIENT *topserver;      /* toplevel servers (only valid if client is a server) */
-       char pwd[CLIENT_PASS_LEN];      /* password received of the client */
        char host[CLIENT_HOST_LEN];     /* hostname of the client */
        char user[CLIENT_USER_LEN];     /* user name ("login") */
 #if defined(PAM) && defined(IDENTAUTH)
@@ -109,7 +108,6 @@ GLOBAL char *Client_OrigUser PARAMS(( CLIENT *Client ));
 #endif
 GLOBAL char *Client_Hostname PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_HostnameCloaked PARAMS(( CLIENT *Client ));
-GLOBAL char *Client_Password PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Modes PARAMS(( CLIENT *Client ));
 GLOBAL char *Client_Flags PARAMS(( CLIENT *Client ));
 GLOBAL CLIENT *Client_Introducer PARAMS(( CLIENT *Client ));
@@ -129,7 +127,6 @@ GLOBAL void Client_SetID PARAMS(( CLIENT *Client, const char *Nick ));
 GLOBAL void Client_SetUser PARAMS(( CLIENT *Client, const char *User, bool Idented ));
 GLOBAL void Client_SetOrigUser PARAMS(( CLIENT *Client, const char *User ));
 GLOBAL void Client_SetInfo PARAMS(( CLIENT *Client, const char *Info ));
-GLOBAL void Client_SetPassword PARAMS(( CLIENT *Client, const char *Pwd ));
 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 ));
index 28a0341e0a28e1485c077393671b51702b1e6141..fd175971a16d9b48a546efa94df84dc8ff39ebc5 100644 (file)
@@ -918,6 +918,30 @@ va_dcl
        return ok;
 } /* Conn_WriteStr */
 
+GLOBAL char*
+Conn_Password( CONN_ID Idx )
+{
+       assert( Idx > NONE );
+       if (My_Connections[Idx].pwd == NULL)
+               return (char*)"\0";
+       else
+               return My_Connections[Idx].pwd;
+} /* Conn_Password */
+
+GLOBAL void
+Conn_SetPassword( CONN_ID Idx, const char *Pwd )
+{
+       assert( Idx > NONE );
+
+       if (My_Connections[Idx].pwd)
+               free(My_Connections[Idx].pwd);
+
+       My_Connections[Idx].pwd = strdup(Pwd);
+       if (My_Connections[Idx].pwd == NULL) {
+               Log(LOG_EMERG, "Can't allocate memory! [Conn_SetPassword]");
+               exit(1);
+       }
+} /* Conn_SetPassword */
 
 /**
  * Append Data to the outbound write buffer of a connection.
@@ -1146,6 +1170,8 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie
 
        array_free(&My_Connections[Idx].rbuf);
        array_free(&My_Connections[Idx].wbuf);
+       if (My_Connections[Idx].pwd != NULL)
+               free(My_Connections[Idx].pwd);
 
        /* Clean up connection structure (=free it) */
        Init_Conn_Struct( Idx );
@@ -2231,7 +2257,8 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
                Client_SetHostname(c, readbuf);
                if (Conf_NoticeAuth)
                        (void)Conn_WriteStr(i,
-                                       "NOTICE AUTH :*** Found your hostname");
+                                       "NOTICE AUTH :*** Found your hostname: %s",
+                                       My_Connections[i].host);
 #ifdef IDENTAUTH
                ++identptr;
                if (*identptr) {
@@ -2256,8 +2283,10 @@ cb_Read_Resolver_Result( int r_fd, UNUSED short events )
                        }
                        if (Conf_NoticeAuth) {
                                (void)Conn_WriteStr(i,
-                                       "NOTICE AUTH :*** Got %sident response",
-                                       *ptr ? "invalid " : "");
+                                       "NOTICE AUTH :*** Got %sident response%s%s",
+                                       *ptr ? "invalid " : "",
+                                       *ptr ? "" : ": ",
+                                       *ptr ? "" : identptr);
                        }
                } else {
                        Log(LOG_INFO, "IDENT lookup for connection %d: no result.", i);
index 4752ec1ede359ee4764066d0b80b578599ff6b74..7dcc8d9d590619c143276d93b003c0c565d3a4e4 100644 (file)
@@ -72,6 +72,7 @@ typedef struct _Connection
        ng_ipaddr_t addr;               /* Client address */
        PROC_STAT proc_stat;            /* Status of resolver process */
        char host[HOST_LEN];            /* Hostname */
+       char *pwd;                      /* password received of the client */
        array rbuf;                     /* Read buffer */
        array wbuf;                     /* Write buffer */
        time_t signon;                  /* Signon ("connect") time */
@@ -115,6 +116,9 @@ GLOBAL void Conn_Handler PARAMS(( void ));
 
 GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, const char *Format, ... ));
 
+GLOBAL char* Conn_Password PARAMS(( CONN_ID Idx ));
+GLOBAL void Conn_SetPassword PARAMS(( CONN_ID Idx, const char *Pwd ));
+
 GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient ));
 
 GLOBAL void Conn_SyncServerStruct PARAMS(( void ));
index cd0a1666ae58a7696c27f7c5aeac40fcfeea565b..310e0699857b2327cee44b440a44061386133805 100644 (file)
 #define USERMODES "acCiorRswx"
 
 /** Supported channel modes. */
-#define CHANMODES "beiIklmnoOPrRstvz"
+#define CHANMODES "beiIklmMnoOPrRstvz"
 
 /** Away message for users connected to linked servers. */
 #define DEFAULT_AWAY_MSG "Away"
index 2ea4c9af135f6a9309be449924946bd6ca6ae879..af34c38c18403370f16f223eac257e429bc6fb3d 100644 (file)
@@ -275,8 +275,8 @@ Parse_CAP(int Capabilities, char *Args)
  * @param Capabilities Capability flags (bitmask).
  * @return Pointer to textual representation.
  */
-char
-*Get_CAP_String(int Capabilities)
+char *
+Get_CAP_String(int Capabilities)
 {
        static char txt[COMMAND_LEN];
 
index 3fb1b902412118e2cad5b58bcae8af0dacec6379..9e1abdd59e8b0349b535b9b1299989f994a3827c 100644 (file)
@@ -87,7 +87,7 @@ IRC_PASS( CLIENT *Client, REQUEST *Req )
                                          Client_ID(Client));
        }
 
-       Client_SetPassword(Client, Req->argv[0]);
+       Conn_SetPassword(Client_Conn(Client), Req->argv[0]);
 
        /* Protocol version */
        if (Req->argc >= 2 && strlen(Req->argv[1]) >= 4) {
index ca4cdd0624f6db851d7fdd2e0920612835066a2f..8da4a65aefed06ed1f41f0b0de43c9fc348201cd 100644 (file)
@@ -508,6 +508,7 @@ Channel_Mode(CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel)
                switch (*mode_ptr) {
                /* --- Channel modes --- */
                case 'i': /* Invite only */
+               case 'M': /* Only identified nicks can write */
                case 'm': /* Moderated */
                case 'n': /* Only members can write */
                case 'R': /* Registered users only */
index cca295ac831dc486675f08778ec3d0de881a63ea..8526a573ec361b0851222314343e079b447114f6 100644 (file)
@@ -80,7 +80,8 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
                        Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", true);
                        return DISCONNECTED;
                }
-               if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 )
+               if( strcmp( Conn_Password( Client_Conn( Client ) ),
+                           Conf_Server[i].pwd_in ) != 0 )
                {
                        /* wrong password */
                        Log( LOG_ERR, "Connection %d: Got bad password from server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
index 7f0299cb09088622b03787a7815950db772f02c7..460fcd1e4c1954e80d946d6ac1a08a0ba9e7722e 100644 (file)
@@ -93,13 +93,14 @@ Login_User(CLIENT * Client)
                 * the beahiour of the daemon compiled without PAM support:
                 * because there can't be any "server password", all
                 * passwords supplied are classified as "wrong". */
-               if(Client_Password(Client)[0] == '\0')
+               if(Conn_Password(conn)[0] == '\0')
                        return Login_User_PostAuth(Client);
                Client_Reject(Client, "Non-empty password", false);
                return DISCONNECTED;
        }
 
-       if (Conf_PAMIsOptional && strcmp(Client_Password(Client), "") == 0) {
+       if (Conf_PAMIsOptional &&
+           strcmp(Conn_Password(conn), "") == 0) {
                /* Clients are not required to send a password and to be PAM-
                 * authenticated at all. If not, they won't become "identified"
                 * and keep the "~" in their supplied user name.
@@ -129,7 +130,7 @@ Login_User(CLIENT * Client)
        }
 #else
        /* Check global server password ... */
-       if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
+       if (strcmp(Conn_Password(conn), Conf_ServerPwd) != 0) {
                /* Bad password! */
                Client_Reject(Client, "Bad server password", false);
                return DISCONNECTED;
index 82cc30fe03250ce7186fc082968cad37fc9fdae0..da861f9a8b45f8743f87575c912101de251daef4 100644 (file)
@@ -21,7 +21,7 @@
 #define RPL_YOURHOST_MSG               "002 %s :Your host is %s, running version ngircd-%s (%s/%s/%s)"
 #define RPL_CREATED_MSG                        "003 %s :This server has been started %s"
 #define RPL_MYINFO_MSG                 "004 %s %s ngircd-%s %s %s"
-#define RPL_ISUPPORT1_MSG              "005 %s RFC2812 IRCD=ngIRCd CASEMAPPING=ascii PREFIX=(ov)@+ CHANTYPES=#&+ CHANMODES=beI,k,l,imnOPRstz CHANLIMIT=#&+:%d :are supported on this server"
+#define RPL_ISUPPORT1_MSG              "005 %s RFC2812 IRCD=ngIRCd CASEMAPPING=ascii PREFIX=(ov)@+ CHANTYPES=#&+ CHANMODES=beI,k,l,imMnOPRstz CHANLIMIT=#&+:%d :are supported on this server"
 #define RPL_ISUPPORT2_MSG              "005 %s CHANNELLEN=%d NICKLEN=%d TOPICLEN=%d AWAYLEN=%d KICKLEN=%d MODES=%d MAXLIST=beI:%d EXCEPTS=e INVEX=I PENALTY :are supported on this server"
 
 #define RPL_TRACELINK_MSG              "200 %s Link %s-%s %s %s V%s %ld %d %d"
@@ -99,7 +99,7 @@
 #define ERR_NOSUCHNICK_MSG             "401 %s %s :No such nick or channel name"
 #define ERR_NOSUCHSERVER_MSG           "402 %s %s :No such server"
 #define ERR_NOSUCHCHANNEL_MSG          "403 %s %s :No such channel"
-#define ERR_CANNOTSENDTOCHAN_MSG       "404 %s %s :Cannot send to channel"
+#define ERR_CANNOTSENDTOCHAN_MSG       "404 %s %s :Cannot send to channel (+m) -- Moderated"
 #define ERR_TOOMANYCHANNELS_MSG                "405 %s %s :You have joined too many channels"
 #define ERR_WASNOSUCHNICK_MSG          "406 %s %s :There was no such nickname"
 #define ERR_NOORIGIN_MSG               "409 %s :No origin specified"
 #define ERR_NEEDMOREPARAMS_MSG         "461 %s %s :Syntax error"
 #define ERR_ALREADYREGISTRED_MSG       "462 %s :Connection already registered"
 #define ERR_PASSWDMISMATCH_MSG         "464 %s :Invalid password"
-#define ERR_CHANNELISFULL_MSG          "471 %s %s :Cannot join channel (+l)"
-#define ERR_SECURECHANNEL_MSG          "471 %s %s :Cannot join channel (+z)"
-#define ERR_OPONLYCHANNEL_MSG          "471 %s %s :Cannot join channel (+O)"
-#define ERR_REGONLYCHANNEL_MSG         "471 %s %s :Cannot join channel (+R)"
+#define ERR_CHANNELISFULL_MSG          "471 %s %s :Cannot join channel (+l) -- Channel is too full, try later"
+#define ERR_SECURECHANNEL_MSG          "471 %s %s :Cannot join channel (+z) -- SSL connections only"
+#define ERR_OPONLYCHANNEL_MSG          "471 %s %s :Cannot join channel (+O) -- IRC opers only"
+#define ERR_REGONLYCHANNEL_MSG         "471 %s %s :Cannot join channel (+R) -- Registered users only"
 #define ERR_UNKNOWNMODE_MSG            "472 %s %c :is unknown mode char for %s"
-#define ERR_INVITEONLYCHAN_MSG         "473 %s %s :Cannot join channel (+i)"
-#define ERR_BANNEDFROMCHAN_MSG         "474 %s %s :Cannot join channel (+b)"
-#define ERR_BADCHANNELKEY_MSG          "475 %s %s :Cannot join channel (+k)"
+#define ERR_INVITEONLYCHAN_MSG         "473 %s %s :Cannot join channel (+i) -- Invited users only"
+#define ERR_BANNEDFROMCHAN_MSG         "474 %s %s :Cannot join channel (+b) -- You are banned"
+#define ERR_BADCHANNELKEY_MSG          "475 %s %s :Cannot join channel (+k) -- Wrong channel key"
 #define ERR_NOCHANMODES_MSG            "477 %s %s :Channel doesn't support modes"
 #define ERR_LISTFULL_MSG               "478 %s %s %s: Channel list is full (%d)"
 #define ERR_NOPRIVILEGES_MSG           "481 %s :Permission denied"
index 6382c594db0747f5872b7042cb553713d3abd4f1..88872c47c5f841d9b008da5fdc59a39281f4f2bb 100644 (file)
@@ -102,8 +102,8 @@ PAM_Authenticate(CLIENT *Client) {
        /* Set supplied client password */
        if (password)
                free(password);
-       password = strdup(Client_Password(Client));
-       conv.appdata_ptr = Client_Password(Client);
+       password = strdup(Conn_Password(Client_Conn(Client)));
+       conv.appdata_ptr = Conn_Password(Client_Conn(Client));
 
        /* Initialize PAM */
        retval = pam_start("ngircd", Client_OrigUser(Client), &conv, &pam);
index df10918893348a4a1ef4205938e00db49eddb6b7..eb6c131e428462e81d3aad67075c721b429edd00 100644 (file)
@@ -135,24 +135,20 @@ ngt_TrimLastChr( char *String, const char Chr)
  * Fill a String with random chars
  */
 GLOBAL char *
-ngt_RandomStr( char *String, const size_t len)
+ngt_RandomStr(char *String, const size_t len)
 {
-       assert(String != NULL);
+       static const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!\"#$&'()*+,-./:;<=>?@[\\]^_`";
+       struct timeval t;
+       size_t i;
 
-       static const char chars[] = 
-               "0123456789ABCDEFGHIJKLMNO"
-               "PQRSTUVWXYZabcdefghijklmn"
-               "opqrstuvwxyz!\"#$&'()*+,-"
-               "./:;<=>?@[\\]^_`";
+       assert(String != NULL);
 
-       struct timeval t;
        gettimeofday(&t, NULL);
        srand((unsigned)(t.tv_usec * t.tv_sec));
 
-       for (size_t i = 0; i < len; ++i) {
+       for (i = 0; i < len; ++i) {
                String[i] = chars[rand() % (sizeof(chars) - 1)];
        }
-
        String[len] = '\0';
 
        return String;