push
[NextIRCd.git] / src / ircd_auth.c
index c2ec7285a7d3a2087ab226aa4d2a58a226a2f0b3..1645892042e434b3965ea2fc330a40a7d0297e60 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 "ircd_auth.h"
+#include "ircd_sock.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 void auth_start_dnsreverse(struct Auth *auth);
 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;
+       conn->data.auth = auth;
        time(&auth->startup_time);
        
        auth->prev = authlist_last;
@@ -43,11 +46,13 @@ struct Auth *auth_new(struct Connection *conn) {
                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");
+static void auth_start_dnsreverse(struct Auth *auth) {
+       socket_printf(auth->conn, "NOTICE AUTH :*** Looking up your hostname");
        
        struct IODNSAddress *sockaddr;
        sockaddr = iosocket_get_remote_addr(auth->conn->socket);
@@ -62,13 +67,15 @@ 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);
+               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;
+                       socket_printf(auth->conn, ":AUTH PING :%d", auth->startup_time);
+               } 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) {
+               
+       }
+       
 }