added some code
authorpk910 <philipp@zoelle1.de>
Thu, 24 Jul 2014 13:04:10 +0000 (15:04 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 24 Jul 2014 13:04:10 +0000 (15:04 +0200)
src/cmd_user.c [new file with mode: 0644]
src/ircd_auth.c
src/ircd_auth.h
src/ircd_client.c
src/ircd_client.h
src/ircd_parse.c
src/ircd_sock.c
src/ircd_sock.h
src/ircd_users.c
src/ircd_users.h [new file with mode: 0644]

diff --git a/src/cmd_user.c b/src/cmd_user.c
new file mode 100644 (file)
index 0000000..ea06a08
--- /dev/null
@@ -0,0 +1,53 @@
+/* cmd_user.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 <string.h>
+
+#include "cmd.h"
+#include "struct_auth.h"
+#include "ircd_users.h"
+#include "ircd_auth.h"
+
+int cmd_user_cli(struct Client *client, char *argv[], int argc) {
+       
+       return 0;
+}
+
+int cmd_user_auth(struct Auth *auth, char *argv[], int argc) {
+       char *user = argv[0];
+       char *mode = argv[1];
+       char *realname = argv[3];
+       
+       char *hostname;
+       if((hostname = strchr(user, '@'))) {
+               *hostname = '\0';
+               if(user == hostname)
+                       user = "NoUser";
+       }
+       if(!is_user_valid(user)) {
+               // invalid user
+               return 0;
+       }
+       
+       strncpy(auth->ident, user, USERLEN);
+       strncpy(auth->realname, realname, REALLEN);
+       auth->have_user = 1;
+       
+       auth_try_finish(auth);
+       
+       return 0;
+}
index c2ec7285a7d3a2087ab226aa4d2a58a226a2f0b3..56f4481ab9c9c207eac4c9748615bb1bc2a9f75d 100644 (file)
  * 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_auth.h"
 #include "ircd_client.h"
 #include "IOHandler/IOSockets.h"
 #include "IOHandler/IODNSLookup.h"
 #include "version.h"
 
 static IODNS_CALLBACK(auth_dns_callback);
+static void auth_free(struct Auth *auth);
 
 static struct Auth *authlist_first = NULL;
 static struct Auth *authlist_last = NULL;
 
-struct Auth *auth_new(struct Connection *conn) {
+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);
+       socket_printf(conn, "NOTICE AUTH :*** NextIRCd v%d.%d (%s)", VERSION_NUMBER, patchlevel, revision);
        
        auth->conn = conn;
        time(&auth->startup_time);
@@ -40,14 +37,16 @@ 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;
        
+       auth_start_dnsreverse(auth);
+       
        return auth;
 }
 
 void auth_start_dnsreverse(struct Auth *auth) {
-       client_printf(auth->conn, "NOTICE AUTH :*** Looking up your hostname");
+       socket_printf(auth->conn, "NOTICE AUTH :*** Looking up your hostname");
        
        struct IODNSAddress *sockaddr;
        sockaddr = iosocket_get_remote_addr(auth->conn->socket);
@@ -62,13 +61,21 @@ static IODNS_CALLBACK(auth_dns_callback) {
        struct Auth *auth = event->query->data;
        struct IODNSResult *dnsresult = event->result;
        
+       auth->dnslookup = NULL;
+       
        if(event->type == IODNSEVENT_SUCCESS) {
                strncpy(auth->host, dnsresult->result.host, HOSTLEN);
-               client_printf(auth->conn, "NOTICE AUTH :*** Found your hostname (%s)", auth->host);
+               socket_printf(auth->conn, "NOTICE AUTH :*** Found your hostname (%s)", auth->host);
        } else {
                struct IODNSAddress *sockaddr = iosocket_get_remote_addr(auth->conn->socket);
-               iodns_print_address(sockaddr, auth->conn->socket->ipv6, auth->host, HOSTLEN);
-               client_printf(auth->conn, "NOTICE AUTH :*** Couldn't look up your hostname. Using your IP instead (%s)", auth->host);
+               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);
+               }
+               socket_printf(auth->conn, "NOTICE AUTH :*** Couldn't look up your hostname. Using your IP instead (%s)", auth->host);
        }
        if(dnsresult)
                iodns_free_result(dnsresult);
@@ -78,5 +85,30 @@ static IODNS_CALLBACK(auth_dns_callback) {
 
 
 void auth_try_finish(struct Auth *auth) {
+       if(auth->server) {
+               
+       } else {
+               if(!auth->have_nick || !auth->have_user)
+                       return;
+               if(!auth->sent_ping) {
+                       
+                       auth->sent_ping = 1;
+               } else if(auth->have_pong && auth->have_dnsresolv) {
+                       struct Client *client = client_connected(auth);
+                       auth->conn->authed = 1;
+                       auth->conn->data.client = client;
+                       auth_free(auth);
+               }
+       }
+}
+
+void auth_abort(struct Auth *auth) {
+       
+}
 
+static void auth_free(struct Auth *auth) {
+       if(auth->dnslookup) {
+               
+       }
+       
 }
index fde02c429a03a10ee206558776b4898ca3fd690a..f200e5df13cced078513faad035ad2907193dc47 100644 (file)
@@ -21,5 +21,6 @@
 struct Auth *auth_new(struct Connection *conn);
 void auth_start_dnsreverse(struct Auth *auth);
 void auth_try_finish(struct Auth *auth);
+void auth_abort(struct Auth *auth);
 
 #endif
index 6fddf0966bbee8e2d5ab2b20dc144ce85526f54f..088d4c4da24700ad4d9873478977d1b016d04c3e 100644 (file)
 #include "struct_connection.h"
 #include "struct_auth.h"
 #include "ircd_config.h"
-#include "ircd_auth.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #define CLIENT_MAXLEN 512
 
-void client_printf(struct Connection *conn, const char *text, ...) {
+void client_connected(struct Auth *auth) {
+    
+}
+
+void client_printf(struct Client *client, const char *text, ...) {
     va_list arg_list;
        char sendBuf[CLIENT_MAXLEN];
        int pos;
@@ -38,15 +41,12 @@ void client_printf(struct Connection *conn, const char *text, ...) {
        if (pos < 0 || pos > (CLIENT_MAXLEN - 2)) pos = CLIENT_MAXLEN - 2;
        sendBuf[pos] = '\n';
     sendBuf[pos+1] = '\0';
-       socket_send(conn, sendBuf, pos+1);
+       socket_send(client->conn, sendBuf, pos+1);
 }
 
-void client_connected(struct Connection *conn) {
-    struct Auth *auth = auth_new(conn);
+void client_exit(struct Client *client, char *reason) {
+       if(client->conn) {
+               
+       }
        
-       auth_start_dnsreverse(auth);
-}
-
-void client_disconnected(struct Connection *conn) {
-    
 }
index c4a68a091d435e6e3b4d30aace100bbb449258f9..4a726af3a6c35062e464de7af45823577a960830 100644 (file)
 #ifndef _ircd_client_h
 #define _ircd_client_h
 
-struct Connection;
+struct Auth;
+struct Client;
 
-/* -- called from ircd_sock.c */
-void client_connected(struct Connection *conn);
-void client_disconnected(struct Connection *conn);
-/* -- */
-
-void client_printf(struct Connection *conn, const char *text, ...);
+struct Client *client_connected(struct Auth *auth);
+void client_printf(struct Client *client, const char *text, ...);
+void client_exit(struct Client *client, char *reason);
 
 #endif
index 1bfa8b78fbf482a29f47f372bff1b6491c2ed7f6..12dc6deb66faa12f582bb1ddf836a40aef61b3a4 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);
@@ -35,7 +27,7 @@ static struct ServerMsg parse_static_srvmsg;
 #define PARSE_CLIFLAG_OPONLY 0x01
 
 //include all commands
-#include "cmd_nick.h"
+#include "cmd_ping.h"
 
 
 struct {
@@ -62,7 +54,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 */
@@ -109,18 +101,18 @@ static char **parse_irc_params(char *data, int *argc, int maxargs) {
     char **argv = calloc(maxargs, sizeof(*argv));
     while(*data) {
         //skip leading spaces
-        while (*data == ' ')
-            *data++ = 0;
-        if (*data == ':') {
+        while (*line == ' ')
+            *line++ = 0;
+        if (*line == ':') {
            //the rest is a single parameter
-           argv[*argc++] = data + 1;
+           argv[*argc++] = line + 1;
            break;
         }
-        argv[*argc++] = data;
-        if (*argc >= maxargs)
+        argv[*argc++] = line;
+        if (argc >= maxargs)
             break;
-        while (*data != ' ' && *data)
-            data++;
+        while (*line != ' ' && *line)
+            line++;
     }
     return argv;
 }
@@ -245,7 +237,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].resolved_destination = 0;
+                       srvmsg->destinations->dst[0].destination.resolved_destination = 0;
                        break;
                case SERVERMSG_TYPE_MULTICAST:
                        if(buflen < 5) {
@@ -263,7 +255,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].resolved_destination = 0;
+                               srvmsg->destinations->dst[i].destination.resolved_destination = 0;
                                buf += 4;
                                buflen -= 4;
                        }
@@ -283,7 +275,7 @@ void parse_server_data(struct Server *server, struct IOSocketBuffer *buffer) {
                        goto parse_server_data_finish;
                }
                
-               srvmsg->arglen = srvmsg->msglen - (buf - (unsigned char *)buffer->buffer);
+               srvmsg->arglen = srvmsg->msglen - (buf - buffer->buffer);
                srvmsg->args = buf;
                
                int found = 0;
@@ -307,7 +299,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 
-                       buffer->bufpos = 0;
+                       srvmsg->bufpos = 0;
        }
 }
 
index 5e750082ca75ab57fb46a865ac15a53d7f3e43b0..a61686f5a22b089034b2b2d935f142e7b2d2fa62 100644 (file)
@@ -19,6 +19,7 @@
 #include "ircd_sock.h"
 #include "ircd_client.h"
 #include "ircd_parse.h"
+#include "ircd_auth.h"
 #include "struct_connection.h"
 
 #include "IOHandler/IOSockets.h"
@@ -135,7 +136,7 @@ static void sockets_accept_client(struct IOSocket *new_client, struct Connection
     new_client->data = connection;
     sockets_append_list(connection);
     
-    client_connected(connection);
+    auth_new(connection);
 }
 
 static CONFRELOAD_CALLBACK(sockets_config_reload) {
@@ -180,9 +181,13 @@ static IOSOCKET_CALLBACK(sockets_iohandler_callback) {
         sockets_remove_list(connection);
         if(connection->server) {
         
+        } else if(connection->authed) {
+                       connection->data.client->conn = NULL;
+            client_exit(connection->data.client, "Client disconnected.");
         } else {
-            client_disconnected(connection);
-        }
+                       connection->data.auth->conn = NULL;
+                       auth_abort(connection->data.auth);
+               }
         sockets_free_connection(connection);
         break;
     
@@ -197,12 +202,12 @@ static IOSOCKET_CALLBACK(sockets_iohandler_callback) {
         break;
     
     case IOSOCKETEVENT_RECV:
-               if(!connection->authed)
-                       parse_unauth_data(connection->data.auth, event->data.recv_str);
-        else if(connection->server)
+        if(connection->server)
             parse_server_data(connection->data.server, event->data.recv_buf);
-        else
+        else if(connection->authed)
             parse_client_data(connection->data.client, event->data.recv_str);
+        else
+                       parse_unauth_data(connection->data.auth, event->data.recv_str);
         break;
     
     default:
@@ -214,6 +219,25 @@ void socket_send(struct Connection *conn, char *data, int len) {
     iosocket_send(conn->socket, data, len);
 }
 
+void socket_printf(struct Connection *conn, const char *text, ...) {
+    va_list arg_list;
+       char sendBuf[512];
+       int pos;
+       sendBuf[0] = '\0';
+       va_start(arg_list, text);
+       pos = vsnprintf(sendBuf, 512 - 2, text, arg_list);
+       va_end(arg_list);
+       if (pos < 0 || pos > (512 - 2)) pos = CLIENT_MAXLEN - 2;
+       sendBuf[pos] = '\n';
+    sendBuf[pos+1] = '\0';
+       iosocket_send(conn->socket, sendBuf, pos+1);
+}
+
+void socket_close(struct Connection *conn) {
+    iosocket_close(conn->socket);
+    sockets_free_connection(conn);
+}
+
 void socket_set_server(struct Connection *conn) {
        struct IOSocket *iosock = conn->socket;
        iosock->parse_delimiter = 0;
index d0f52f4ebb23328cbb994be8504229c6c674801a..78806d6a0e2ba828f0ca618aa732169717ba00a3 100644 (file)
@@ -23,6 +23,9 @@ void init_sockets();
 
 struct Connection;
 
+void socket_close(struct Connection *conn);
 void socket_send(struct Connection *conn, char *data, int len);
+void socket_printf(struct Connection *conn, const char *text, ...);
+void socket_close(struct Connection *conn);
 
 #endif
index 8e5b39f5a5cc771afc361953107b979481ce13b9..9faaacd2d9bfb1f9a30b0e5c21c5aeb6dbc46acc 100644 (file)
@@ -14,9 +14,6 @@
  * 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 <time.h>
-
 #include "struct_user.h"
 
 struct UserDictEntry {
@@ -29,9 +26,13 @@ struct UserDict {
        struct UserDictEntry *users[65536]; // 2^16  (first 16 bit of nickhash as identifier)
 };
 
-
 void find_user_by_nick(char *nick) {
        //calculate checksum
        //search in UserDict
        //ask trusted server multicast
 }
+
+int is_nick_valid(char *nick) {
+       
+}
+
diff --git a/src/ircd_users.h b/src/ircd_users.h
new file mode 100644 (file)
index 0000000..a45a176
--- /dev/null
@@ -0,0 +1,23 @@
+/* ircd_users.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_users_h
+#define _ircd_users_h
+
+int is_nick_valid(char *nick);
+
+#endif