Merge remote-tracking branch 'IOMultiplexer/v2'
authorpk910 <philipp@zoelle1.de>
Thu, 24 Jul 2014 08:48:08 +0000 (10:48 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 24 Jul 2014 08:48:08 +0000 (10:48 +0200)
Conflicts:
src/IOHandler/IODNSLookup.c
src/IOHandler/IODNSLookup.h

configure.ac
src/IOHandler/IODNSLookup.c
src/IOHandler/IODNSLookup.h
src/crypt_base64.c
src/crypt_base64.h
src/crypt_rsa.c
src/ircd_auth.c
src/ircd_client.c
src/ircd_parse.c
src/struct_client.h
src/struct_user.h

index 44f4e88c1f7f52e9981d1bd612deda67d5edb5e7..aa5b500c48416c132aef6208d20914ec46576a36 100644 (file)
@@ -5,7 +5,7 @@ AC_INIT([IOMultiplexer], [2.0], [iohandler@pk910.de], [pk910], [http://pk910.de]
 AC_PREFIX_DEFAULT([~/iotest])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE([foreign])
-AM_SILENT_RULES([no])
+AM_SILENT_RULES([yes])
 AC_CONFIG_HEADERS([config.h])
 
 LT_INIT([disable-static])
@@ -36,22 +36,14 @@ AC_CHECK_FUNCS([usleep select socket inet_pton inet_ntop])
 AC_CHECK_HEADERS([fcntl.h sys/socket.h sys/select.h sys/time.h sys/types.h unistd.h windows.h winsock2.h errno.h sys/epoll.h sys/event.h])
 
 AC_CHECK_LIB(ws2_32, main, [ LIBS="$LIBS -lws2_32" ], [])
-have_gnutls="no"
-AC_CHECK_LIB(gnutls, gnutls_init, [
-  AC_CHECK_HEADERS(gnutls/gnutls.h, [
-    LIBS="$LIBS -lgnutls"
-    have_gnutls="yes"
-  ])
-])
-if test x"$have_gnutls" = xno; then
-  AC_CHECK_LIB(ssl, SSL_read, [
-    AC_CHECK_LIB(crypto, X509_new, [
-      AC_CHECK_HEADERS(openssl/ssl.h openssl/err.h openssl/rand.h, [
-        LIBS="$LIBS -lssl -lcrypto"
-      ])
+
+AC_CHECK_LIB(ssl, SSL_read, [
+  AC_CHECK_LIB(crypto, X509_new, [
+    AC_CHECK_HEADERS(openssl/ssl.h openssl/err.h openssl/rand.h, [
+      LIBS="$LIBS -lssl -lcrypto"
     ])
   ])
-fi
+])
 AC_CHECK_LIB(pthread, pthread_create, [
   AC_CHECK_HEADERS(pthread.h, [
     LIBS="$LIBS -lpthread"
index 732cc0efedaef4434cd281d56c2a346c14fce113..e6201639fa84af990c2e4fa6cd3b3a5bf376837b 100644 (file)
@@ -228,15 +228,15 @@ void iodns_abort(struct IODNSQuery *descriptor) {
        _stop_dnsquery(query);
 }
 
-int iodns_print_address(struct IODNSAddress *addr, int ipv6, const char *buffer, int length) {
+int iodns_print_address(struct IODNSAddress *address, int ipv6, char *buffer, int length) {
        int af;
        void *addr;
        if(ipv6) {
                af = AF_INET6;
-               addr = (void *)(&((struct sockaddr_in6 *)sockaddr->address)->sin6_addr);
+               addr = (void *)(&((struct sockaddr_in6 *)address->address)->sin6_addr);
        } else {
                af = AF_INET;
-               addr = (void *)(&((struct sockaddr_in *)sockaddr->address)->sin_addr);
+               addr = (void *)(&((struct sockaddr_in *)address->address)->sin_addr);
        }
        buffer = inet_ntop(af, addr, buffer, length);
        if(!buffer)
index 817800851214f2e8ebe171bb7509426c43340ca9..61966d83363b54d502cf0b43455e5a3a04087b23 100644 (file)
@@ -152,7 +152,7 @@ struct IODNSQuery *iodns_getaddrinfo(char *hostname, int records, iodns_callback
 struct IODNSQuery *iodns_getnameinfo(const struct sockaddr *addr, size_t addrlen, iodns_callback *callback, void *arg);
 void iodns_abort(struct IODNSQuery *query);
 
-int iodns_print_address(struct IODNSAddress *addr, int ipv6,const char *buffer, int length);
+int iodns_print_address(struct IODNSAddress *addr, int ipv6, char *buffer, int length);
 
 void iodns_free_result(struct IODNSResult *result);
 
index 2e54c922e90674f63d633f71fcc4c93fe7762cce..60e10eee7182f8b907aac0d09b00c4fe6b80a94f 100644 (file)
@@ -37,7 +37,8 @@ char *crypt_base64_encode(const unsigned char *data, size_t input_length, size_t
        if (encoded_data == NULL)
                return NULL;
        
-       for (int i = 0, j = 0; i < input_length;) {
+       int i, j;
+       for (i = 0, j = 0; i < input_length;) {
                uint32_t octet_a = i < input_length ? (unsigned char)data[i++] : 0;
                uint32_t octet_b = i < input_length ? (unsigned char)data[i++] : 0;
                uint32_t octet_c = i < input_length ? (unsigned char)data[i++] : 0;
@@ -50,7 +51,7 @@ char *crypt_base64_encode(const unsigned char *data, size_t input_length, size_t
                encoded_data[j++] = encoding_table[(triple >> 0 * 6) & 0x3F];
        }
        
-       for (int i = 0; i < mod_table[input_length % 3]; i++)
+       for (i = 0; i < mod_table[input_length % 3]; i++)
                encoded_data[*output_length - 1 - i] = '=';
        
        return encoded_data;
@@ -71,7 +72,8 @@ unsigned char *crypt_base64_decode(const char *data, size_t input_length, size_t
        if (decoded_data == NULL)
                return NULL;
        
-       for (int i = 0, j = 0; i < input_length;) {
+       int i, j;
+       for (i = 0, j = 0; i < input_length;) {
                uint32_t sextet_a = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
                uint32_t sextet_b = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
                uint32_t sextet_c = data[i] == '=' ? 0 & i++ : decoding_table[data[i++]];
@@ -93,7 +95,8 @@ unsigned char *crypt_base64_decode(const char *data, size_t input_length, size_t
 
 void crypt_base64_init() {
        decoding_table = malloc(256);
-       for (int i = 0; i < 64; i++)
+       int i;
+       for (i = 0; i < 64; i++)
                decoding_table[(unsigned char) encoding_table[i]] = i;
 }
 
index 5ada93c6b675a3c2e0dca528ce0be000d02b44e8..2892573ed7a8ce977a64464d421f49cf16f1eaf7 100644 (file)
@@ -17,6 +17,7 @@
 
 #ifndef _crypt_base64_h
 #define _crypt_base64_h
+#include <stdlib.h>
 
 void crypt_base64_init();
 void crypt_base64_deinit();
index 80450f1222cabb1a9b3b09ca84a5dd8fe4fd6cda..c78bf8907ad31c447217b7692dbdd83e54c6184c 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
-
-int main(char *argv[], int argc) {
-       crypt_init();
-       
-       struct crypt_rsa_privkey *privkey;
-       FILE *fp;
-       if(fp = fopen("privkey.pem", "r")) {
-               char buffer[4096];
-               fread(buffer, sizeof(buffer), 1, fp);
-               fclose(fp);
-               
-               privkey = crypt_load_privkey(buffer);
-       } else {
-               privkey = crypt_generate_privkey(2048);
-               
-               fp = fopen("privkey.pem", "w");
-               char *buffer = crypt_export_privkey(privkey, 0);
-               fprintf(fp, "%s", buffer);
-               free(buffer);
-               fclose(fp);
-       }
-       
-       struct crypt_rsa_pubkey *pubkey = crypt_get_pubkey(privkey);
-       char plain[] = "Test String!!!";
-       char *crypted = NULL;
-       int len = crypt_encrypt_data(pubkey, plain, sizeof(plain), &crypted);
-       
-       printf("Crypt Len: %d\n", len);
-       printf("Crypt: ");
-       int i;
-       for(i = 0; i < len; i++) {
-               printf(" %02X", ((unsigned int)crypted[i] & 0xFF));
-       }
-       printf("\n");
-       
-       char *decrypted = NULL;
-       len = crypt_decrypt_data(privkey, crypted, len, &decrypted);
-       printf("Decrypt Len: %d\n", len);
-       printf("Decrypt: %s\n", decrypted);
-}
-
-
-
 /*
 // GnuTLS Backend not working because of gnutls_pubkey_encrypt_data doesn't exists prior to GnuTLS 3.0
 // still searching for a replacement...
index 0478f9b25b3ee319666d031908f237c055000678..8079db1c78ff89092687b1ca5a1be44eba316dca 100644 (file)
@@ -14,6 +14,9 @@
  * You should have received a copy of the GNU General Public License 
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
+
+#include <string.h>
+
 #include "struct_auth.h"
 #include "struct_connection.h"
 #include "ircd_client.h"
@@ -36,7 +39,7 @@ struct Auth *auth_new(struct Connection *conn) {
        auth->prev = authlist_last;
        auth->next = NULL;
        if(!authlist_last)
-               authlist_first = auth
+               authlist_first = auth;
        authlist_last = auth;
        
        return auth;
@@ -63,13 +66,11 @@ static IODNS_CALLBACK(auth_dns_callback) {
                client_printf(auth->conn, "NOTICE AUTH :*** Found your hostname (%s)", auth->host);
        } else {
                struct IODNSAddress *sockaddr = iosocket_get_remote_addr(auth->conn->socket);
-               if(sockaddr->addresslen == sizeof(struct sockaddr_in)) {
-                       //ipv4
-                       inet_ntop(AF_INET, (void *)(&((struct sockaddr_in *)sockaddr->address)->sin_addr), auth->host, HOSTLEN);
-               } else {
-                       //ipv6
+               if(auth->conn->ipv6)
                        inet_ntop(AF_INET6, (void *)(&((struct sockaddr_in6 *)sockaddr->address)->sin6_addr), auth->host, HOSTLEN);
-               }
+               else
+                       inet_ntop(AF_INET, (void *)(&((struct sockaddr_in *)sockaddr->address)->sin_addr), auth->host, HOSTLEN);
+               
                client_printf(auth->conn, "NOTICE AUTH :*** Couldn't look up your hostname. Using your IP instead (%s)", auth->host);
        }
        if(dnsresult)
index 5af6f1d2bf40d29864ad69d6619950e50d40e0cd..6fddf0966bbee8e2d5ab2b20dc144ce85526f54f 100644 (file)
@@ -20,6 +20,7 @@
 #include "struct_connection.h"
 #include "struct_auth.h"
 #include "ircd_config.h"
+#include "ircd_auth.h"
 
 #include <stdio.h>
 #include <stdlib.h>
index 12dc6deb66faa12f582bb1ddf836a40aef61b3a4..1bfa8b78fbf482a29f47f372bff1b6491c2ed7f6 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
  */
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "tools.h"
 #include "IOHandler/IOSockets.h"
+#include "ircd_parse.h"
+struct Server;
+#include "struct_client.h"
+#include "struct_auth.h"
+#include "struct_servermsg.h"
 
 typedef int cmd_client_t(struct Client *client, char *argv[], int argc);
 typedef int cmd_auth_t(struct Auth *auth, char *argv[], int argc);
@@ -27,7 +35,7 @@ static struct ServerMsg parse_static_srvmsg;
 #define PARSE_CLIFLAG_OPONLY 0x01
 
 //include all commands
-#include "cmd_ping.h"
+#include "cmd_nick.h"
 
 
 struct {
@@ -54,7 +62,7 @@ struct {
                unsigned int flags : 8;
        } server;
        
-} parse_command_list {
+} parse_command_list[] = {
        {{"PING", "P"}, /* Ping Command */
                {NULL, 0, 1, 0}, /* Client */
                {NULL, 0, 1, 0}, /* Unauthed */
@@ -101,18 +109,18 @@ static char **parse_irc_params(char *data, int *argc, int maxargs) {
     char **argv = calloc(maxargs, sizeof(*argv));
     while(*data) {
         //skip leading spaces
-        while (*line == ' ')
-            *line++ = 0;
-        if (*line == ':') {
+        while (*data == ' ')
+            *data++ = 0;
+        if (*data == ':') {
            //the rest is a single parameter
-           argv[*argc++] = line + 1;
+           argv[*argc++] = data + 1;
            break;
         }
-        argv[*argc++] = line;
-        if (argc >= maxargs)
+        argv[*argc++] = data;
+        if (*argc >= maxargs)
             break;
-        while (*line != ' ' && *line)
-            line++;
+        while (*data != ' ' && *data)
+            data++;
     }
     return argv;
 }
@@ -237,7 +245,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) {
                        srvmsg->destinations = malloc(sizeof(struct ServerMsgDstMap));
                        srvmsg->destinations->dstcount = 1;
                        srvmsg->destinations->dst[0].destination.srvnum = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
-                       srvmsg->destinations->dst[0].destination.resolved_destination = 0;
+                       srvmsg->destinations->dst[0].resolved_destination = 0;
                        break;
                case SERVERMSG_TYPE_MULTICAST:
                        if(buflen < 5) {
@@ -255,7 +263,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) {
                        srvmsg->destinations->dstcount = srvcount;
                        for(i = 0; i < srvcount; i++) {
                                srvmsg->destinations->dst[i].destination.srvnum = ((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]);
-                               srvmsg->destinations->dst[i].destination.resolved_destination = 0;
+                               srvmsg->destinations->dst[i].resolved_destination = 0;
                                buf += 4;
                                buflen -= 4;
                        }
@@ -275,7 +283,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) {
                        goto parse_server_data_finish;
                }
                
-               srvmsg->arglen = srvmsg->msglen - (buf - buffer->buffer);
+               srvmsg->arglen = srvmsg->msglen - (buf - (unsigned char *)buffer->buffer);
                srvmsg->args = buf;
                
                int found = 0;
@@ -299,7 +307,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) {
                        memmove(buffer->buffer, buffer->buffer + srvmsg->msglen, srvmsg->msglen - buffer->bufpos);
                        buffer->bufpos -= srvmsg->msglen;
                } else 
-                       srvmsg->bufpos = 0;
+                       buffer->bufpos = 0;
        }
 }
 
index 537b832a5abd8c3c65181c9cddb73ddcd1ad81ad..a944bb2a0df7d811663bb6108ab9ac3730b27be9 100644 (file)
@@ -17,7 +17,7 @@
 
 #ifndef _struct_client_h
 #define _struct_client_h
-#include "crypto_md5.h"
+#include "crypt_md5.h"
 #include "struct_user.h"
 
 struct Connection;
@@ -47,7 +47,7 @@ struct Client {
        unsigned int isonline : 1;
        unsigned int isaway : 1;
        
-       struct Client *prev, *next
+       struct Client *prev, *next;
 };
 
 struct ClientNickChange {
index 9fc65c3597c78e1320c032550a34d039d0400664..57aac3db5f97a634a4b6d4db310fb3383574e101 100644 (file)
@@ -17,7 +17,7 @@
 
 #ifndef _struct_user_h
 #define _struct_user_h
-#include "crypto_md5.h"
+#include "crypt_md5.h"
 
 #define NICKLEN   30
 #define IDENTLEN  15