X-Git-Url: http://git.pk910.de/?p=NextIRCd.git;a=blobdiff_plain;f=src%2Fircd_auth.c;fp=src%2Fircd_auth.c;h=0478f9b25b3ee319666d031908f237c055000678;hp=0000000000000000000000000000000000000000;hb=fc3df376babe61fd8b725fb8c48c189eaebeec50;hpb=59ddec51d649f0af9b91d2aab710258d5b97a596 diff --git a/src/ircd_auth.c b/src/ircd_auth.c new file mode 100644 index 0000000..0478f9b --- /dev/null +++ b/src/ircd_auth.c @@ -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 . + */ +#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) { + +}