1 /* ircd_auth.c - NextIRCd
2 * Copyright (C) 2012-2013 Philipp Kreil (pk910)
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "struct_auth.h"
21 #include "struct_connection.h"
22 #include "ircd_auth.h"
23 #include "ircd_client.h"
24 #include "IOHandler/IOSockets.h"
25 #include "IOHandler/IODNSLookup.h"
28 static IODNS_CALLBACK(auth_dns_callback);
30 static struct Auth *authlist_first = NULL;
31 static struct Auth *authlist_last = NULL;
33 struct Auth *auth_new(struct Connection *conn) {
34 struct Auth *auth = calloc(1, sizeof(*auth));
35 client_printf(conn, "NOTICE AUTH :*** NextIRCd v%d.%d (%s)", VERSION_NUMBER, patchlevel, revision);
38 time(&auth->startup_time);
40 auth->prev = authlist_last;
43 authlist_first = auth;
49 void auth_start_dnsreverse(struct Auth *auth) {
50 client_printf(auth->conn, "NOTICE AUTH :*** Looking up your hostname");
52 struct IODNSAddress *sockaddr;
53 sockaddr = iosocket_get_remote_addr(auth->conn->socket);
55 auth->dnslookup = iodns_getnameinfo(sockaddr->address, sockaddr->addresslen, auth_dns_callback, auth);
61 static IODNS_CALLBACK(auth_dns_callback) {
62 struct Auth *auth = event->query->data;
63 struct IODNSResult *dnsresult = event->result;
65 if(event->type == IODNSEVENT_SUCCESS) {
66 strncpy(auth->host, dnsresult->result.host, HOSTLEN);
67 client_printf(auth->conn, "NOTICE AUTH :*** Found your hostname (%s)", auth->host);
69 struct IODNSAddress *sockaddr = iosocket_get_remote_addr(auth->conn->socket);
70 iodns_print_address(sockaddr, auth->conn->socket->ipv6, auth->host, HOSTLEN);
71 client_printf(auth->conn, "NOTICE AUTH :*** Couldn't look up your hostname. Using your IP instead (%s)", auth->host);
74 iodns_free_result(dnsresult);
76 auth_try_finish(auth);
80 void auth_try_finish(struct Auth *auth) {