added some files
authorpk910 <philipp@zoelle1.de>
Sun, 20 Jul 2014 22:04:42 +0000 (00:04 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 20 Jul 2014 22:04:42 +0000 (00:04 +0200)
src/Makefile.am
src/ircd_auth.c [new file with mode: 0644]
src/ircd_auth.h [new file with mode: 0644]
src/ircd_client.c
src/ircd_client.h
src/ircd_nicks.c [deleted file]
src/ircd_parse.c
src/struct_auth.h
src/struct_user.h

index e258ea28fa8abd4c73ecbd7c1d10c1ba5860b5ff..e27e2a169427db0307d54f820dc8c5160f9bc96b 100644 (file)
@@ -20,5 +20,8 @@ nextircd_SOURCES = \
        ircd_config.c \
        ircd_sock.c \
        ircd_client.c \
+       ircd_parse.c \
+       ircd_auth.c \
+       ircd_users.c \
        main.c
 
diff --git a/src/ircd_auth.c b/src/ircd_auth.c
new file mode 100644 (file)
index 0000000..0478f9b
--- /dev/null
@@ -0,0 +1,84 @@
+/* ircd_auth.c - NextIRCd
+ * Copyright (C) 2012-2013  Philipp Kreil (pk910)
+ * 
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * 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 "struct_auth.h"
+#include "struct_connection.h"
+#include "ircd_client.h"
+#include "IOHandler/IOSockets.h"
+#include "IOHandler/IODNSLookup.h"
+#include "version.h"
+
+static IODNS_CALLBACK(auth_dns_callback);
+
+static struct Auth *authlist_first = NULL;
+static struct Auth *authlist_last = NULL;
+
+struct Auth *auth_new(struct Connection *conn) {
+       struct Auth *auth = calloc(1, sizeof(*auth));
+       client_printf(conn, "NOTICE AUTH :*** NextIRCd v%d.%d (%s)", VERSION_NUMBER, patchlevel, revision);
+       
+       auth->conn = conn;
+       time(&auth->startup_time);
+       
+       auth->prev = authlist_last;
+       auth->next = NULL;
+       if(!authlist_last)
+               authlist_first = auth
+       authlist_last = auth;
+       
+       return auth;
+}
+
+void auth_start_dnsreverse(struct Auth *auth) {
+       client_printf(auth->conn, "NOTICE AUTH :*** Looking up your hostname");
+       
+       struct IODNSAddress *sockaddr;
+       sockaddr = iosocket_get_remote_addr(auth->conn->socket);
+       if(sockaddr) {
+               auth->dnslookup = iodns_getnameinfo(sockaddr->address, sockaddr->addresslen, auth_dns_callback, auth);
+       } else {
+               // critical error!
+       }
+}
+
+static IODNS_CALLBACK(auth_dns_callback) {
+       struct Auth *auth = event->query->data;
+       struct IODNSResult *dnsresult = event->result;
+       
+       if(event->type == IODNSEVENT_SUCCESS) {
+               strncpy(auth->host, dnsresult->result.host, HOSTLEN);
+               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
+                       inet_ntop(AF_INET6, (void *)(&((struct sockaddr_in6 *)sockaddr->address)->sin6_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)
+               iodns_free_result(dnsresult);
+       
+       auth_try_finish(auth);
+}
+
+
+void auth_try_finish(struct Auth *auth) {
+
+}
diff --git a/src/ircd_auth.h b/src/ircd_auth.h
new file mode 100644 (file)
index 0000000..fde02c4
--- /dev/null
@@ -0,0 +1,25 @@
+/* ircd_auth.h - NextIRCd
+ * Copyright (C) 2012-2013  Philipp Kreil (pk910)
+ * 
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+
+#ifndef _ircd_auth_h
+#define _ircd_auth_h
+
+struct Auth *auth_new(struct Connection *conn);
+void auth_start_dnsreverse(struct Auth *auth);
+void auth_try_finish(struct Auth *auth);
+
+#endif
index 28d650baea1def84998d0c7293526d67d04f91e5..5af6f1d2bf40d29864ad69d6619950e50d40e0cd 100644 (file)
 #include "struct_connection.h"
 #include "struct_auth.h"
 #include "ircd_config.h"
-#include "version.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #define CLIENT_MAXLEN 512
 
-static void client_printf(struct Connection *conn, const char *text, ...) {
+void client_printf(struct Connection *conn, const char *text, ...) {
     va_list arg_list;
        char sendBuf[CLIENT_MAXLEN];
        int pos;
@@ -42,13 +41,9 @@ static void client_printf(struct Connection *conn, const char *text, ...) {
 }
 
 void client_connected(struct Connection *conn) {
-    client_printf(conn, "NOTICE AUTH :*** NextIRCd v%d.%d (%s)", VERSION_NUMBER, patchlevel, revision);
-    
-    struct Auth *auth = calloc(1, sizeof(*auth));
-    auth->conn = conn;
-    conn->data.auth = auth;
-    
-    /* maybe do some stuff here? */
+    struct Auth *auth = auth_new(conn);
+       
+       auth_start_dnsreverse(auth);
 }
 
 void client_disconnected(struct Connection *conn) {
index f113ae373c4c26fc32abdac7b829de6ed29c0452..c4a68a091d435e6e3b4d30aace100bbb449258f9 100644 (file)
@@ -25,5 +25,6 @@ void client_connected(struct Connection *conn);
 void client_disconnected(struct Connection *conn);
 /* -- */
 
+void client_printf(struct Connection *conn, const char *text, ...);
 
 #endif
diff --git a/src/ircd_nicks.c b/src/ircd_nicks.c
deleted file mode 100644 (file)
index 5b64ad2..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/* ircd_nicks.c - NextIRCd
- * Copyright (C) 2012-2013  Philipp Kreil (pk910)
- * 
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * 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 "struct_user.h"
-
-struct UserDictEntry {
-       struct User *user;
-       struct UserDict *next, *prev;
-};
-
-struct UserDict {
-       struct UserDictEntry *users[65536]; // 2^16  (first 16 bit of nickhash as identifier)
-};
-
-
-
index 21197b1fbf2915b27db467845ad238b12c7de70c..12dc6deb66faa12f582bb1ddf836a40aef61b3a4 100644 (file)
@@ -66,8 +66,8 @@ struct {
                {NULL, 0, 1, 0}  /* Server */
        },
        {{"NICK", "N"}, /* Nick Command */
-               {cmd_nick_cli, 0, 1, 0}, /* Client */
-               {cmd_nick_auth, 0, 1, 0}, /* Unauthed */
+               {cmd_nick_cli, 1, 1, 0}, /* Client */
+               {cmd_nick_auth, 1, 1, 0}, /* Unauthed */
                {NULL, 0, 1, 0}  /* Server */
        },
        {{"USER", "U"}, /* User Command */
index 69a452af43f958a9a76fbc27dd38472b356c3194..335917e39005d77268c14a8bd0b8e1424d288a9f 100644 (file)
 
 #ifndef _struct_auth_h
 #define _struct_auth_h
+#include "struct_user.h"
+#include <time.h>
+
+#define PASSLEN 50
+
+struct IODNSQuery;
 
 struct Auth {
     struct Connection *conn;
        
-    char *nick;
-    char *ident;
-    char *realname;
-    char *passwd;
-    
-    unsigned int ping_number;
+    char nick[NICKLEN+1];
+    char ident[IDENTLEN+1];
+    char realname[REALLEN+1];
+       char host[HOSTLEN+1];
+    char passwd[PASSLEN+1];
+       
+    unsigned int ping_probe;
+       time_t startup_time;
+       
+       struct IODNSQuery *dnslookup;
     
        unsigned int server : 1;
        unsigned int have_nick : 1;
        unsigned int have_user : 1;
        unsigned int have_pass : 1;
     
+       unsigned int have_dnsresolv : 1;
+       unsigned int have_pong : 1;
+       
+       struct Auth *prev, *next;
 };
 
 #endif
index 47f722d1ccf96a854947a18bee11354606817dbe..9fc65c3597c78e1320c032550a34d039d0400664 100644 (file)
 #define _struct_user_h
 #include "crypto_md5.h"
 
-#define NICKLEN  30
-#define IDENTLEN 15
-#define HOSTLEN  63
-#define REALLEN  50
+#define NICKLEN   30
+#define IDENTLEN  15
+#define HOSTLEN   63
+#define REALLEN   50
 
 struct User {
     unsigned int usernum;