--- /dev/null
+/* 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;
+}
* 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);
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);
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);
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) {
+
+ }
+
}
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
#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;
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) {
-
}
#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
* 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);
#define PARSE_CLIFLAG_OPONLY 0x01
//include all commands
-#include "cmd_nick.h"
+#include "cmd_ping.h"
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 */
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;
}
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) {
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;
}
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;
memmove(buffer->buffer, buffer->buffer + srvmsg->msglen, srvmsg->msglen - buffer->bufpos);
buffer->bufpos -= srvmsg->msglen;
} else
- buffer->bufpos = 0;
+ srvmsg->bufpos = 0;
}
}
#include "ircd_sock.h"
#include "ircd_client.h"
#include "ircd_parse.h"
+#include "ircd_auth.h"
#include "struct_connection.h"
#include "IOHandler/IOSockets.h"
new_client->data = connection;
sockets_append_list(connection);
- client_connected(connection);
+ auth_new(connection);
}
static CONFRELOAD_CALLBACK(sockets_config_reload) {
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;
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:
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;
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
* 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 {
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) {
+
+}
+
--- /dev/null
+/* 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