From: pk910 Date: Thu, 24 Jul 2014 08:48:08 +0000 (+0200) Subject: Merge remote-tracking branch 'IOMultiplexer/v2' X-Git-Url: http://git.pk910.de/?p=NextIRCd.git;a=commitdiff_plain;h=e17a8a5dc929df2a5ae6169f1955fcde7c70e04b;hp=285018f265af0f32438a5de357905963daaaa86f Merge remote-tracking branch 'IOMultiplexer/v2' Conflicts: src/IOHandler/IODNSLookup.c src/IOHandler/IODNSLookup.h --- diff --git a/configure.ac b/configure.ac index 44f4e88..aa5b500 100644 --- a/configure.ac +++ b/configure.ac @@ -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" diff --git a/src/IOHandler/IODNSLookup.c b/src/IOHandler/IODNSLookup.c index 732cc0e..e620163 100644 --- a/src/IOHandler/IODNSLookup.c +++ b/src/IOHandler/IODNSLookup.c @@ -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) diff --git a/src/IOHandler/IODNSLookup.h b/src/IOHandler/IODNSLookup.h index 8178008..61966d8 100644 --- a/src/IOHandler/IODNSLookup.h +++ b/src/IOHandler/IODNSLookup.h @@ -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); diff --git a/src/crypt_base64.c b/src/crypt_base64.c index 2e54c92..60e10ee 100644 --- a/src/crypt_base64.c +++ b/src/crypt_base64.c @@ -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; } diff --git a/src/crypt_base64.h b/src/crypt_base64.h index 5ada93c..2892573 100644 --- a/src/crypt_base64.h +++ b/src/crypt_base64.h @@ -17,6 +17,7 @@ #ifndef _crypt_base64_h #define _crypt_base64_h +#include void crypt_base64_init(); void crypt_base64_deinit(); diff --git a/src/crypt_rsa.c b/src/crypt_rsa.c index 80450f1..c78bf89 100644 --- a/src/crypt_rsa.c +++ b/src/crypt_rsa.c @@ -22,49 +22,6 @@ #include #include - -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... diff --git a/src/ircd_auth.c b/src/ircd_auth.c index 0478f9b..8079db1 100644 --- a/src/ircd_auth.c +++ b/src/ircd_auth.c @@ -14,6 +14,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ + +#include + #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) diff --git a/src/ircd_client.c b/src/ircd_client.c index 5af6f1d..6fddf09 100644 --- a/src/ircd_client.c +++ b/src/ircd_client.c @@ -20,6 +20,7 @@ #include "struct_connection.h" #include "struct_auth.h" #include "ircd_config.h" +#include "ircd_auth.h" #include #include diff --git a/src/ircd_parse.c b/src/ircd_parse.c index 12dc6de..1bfa8b7 100644 --- a/src/ircd_parse.c +++ b/src/ircd_parse.c @@ -15,8 +15,16 @@ * along with this program. If not, see . */ +#include +#include + #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; } } diff --git a/src/struct_client.h b/src/struct_client.h index 537b832..a944bb2 100644 --- a/src/struct_client.h +++ b/src/struct_client.h @@ -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 { diff --git a/src/struct_user.h b/src/struct_user.h index 9fc65c3..57aac3d 100644 --- a/src/struct_user.h +++ b/src/struct_user.h @@ -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