2 * Written by David Herrmann.
3 * Dedicated to the Public Domain.
13 char iauth_servname[IAUTH_DATALEN + 1];
15 static char *iauth_next_data(char **arg) {
19 while(**arg == ' ') ++*arg;
20 if(!**arg) return NULL;
21 if(**arg == ':' || !(sep = strchr(*arg, ' '))) {
22 if(**arg == ':') ++*arg;
24 ret = iauth_malloc(len + 1);
27 if(len > IAUTH_DATALEN) ret[IAUTH_DATALEN] = 0;
34 ret = iauth_malloc(len + 1);
36 if(len > IAUTH_DATALEN) ret[IAUTH_DATALEN] = 0;
44 /* Client Introduction: <id> C <remoteip> <remoteport> <localip> <localport> */
45 void iauth_cmd_C(signed int id, char *arg) {
47 struct iauth_client *cli;
51 cli = &iauth_clients[id];
53 str = iauth_next_data(&arg);
54 if(!str) goto parse_error;
55 iauth_set(cli->ip, str);
57 str = iauth_next_data(&arg);
58 if(!str) goto parse_error;
59 cli->port = atoi(str);
62 str = iauth_next_data(&arg);
63 if(!str) goto parse_error;
64 iauth_set(cli->lo_ip, str);
66 str = iauth_next_data(&arg);
67 if(!str) goto parse_error;
68 cli->lo_port = atoi(str);
71 iauth_flog(IAUTH_INFO, "New client (%d) from '%s':%hu to '%s':%hu.", id, cli->ip, cli->port, cli->lo_ip, cli->lo_port);
75 iauth_flog(IAUTH_WARNING, "Parse error: Invalid C line.");
80 /* Client Disconnect: <id> D */
81 void iauth_cmd_D(struct iauth_client *client) {
82 iauth_delid(client->id);
85 /* Login On Connect: <id> L <account>[:<accountstamp>][ <fakehost>] */
86 void iauth_cmd_L(struct iauth_client *client, char *arg) {
88 const struct iauth_result *res;
90 str = iauth_next_data(&arg);
91 if(!str) goto parse_error;
92 iauth_set(client->account, str);
94 str = iauth_next_data(&arg);
95 if(str) iauth_set(client->fakehost, str);
97 /* Query database for account query. */
98 res = iauth_query(client);
100 iauth_query_reject(client->id, "Access denied.");
101 iauth_stats_loc_deny();
104 if(*res->ident) iauth_query_set_username(client->id, res->ident);
105 if(*res->host) iauth_query_sethost(client->id, res->host);
106 if(*res->ip) iauth_query_setip(client->id, res->ip);
107 if(*res->modes) iauth_query_setmodes(client->id, res->modes);
108 iauth_query_assign(client->id, (*res->cclass)?res->cclass:NULL);
109 iauth_stats_loc_allow();
112 iauth_delid(client->id);
116 iauth_flog(IAUTH_WARNING, "Parse error: Invalid L line.");
120 /* Hurry Up: <id> H <class> */
121 void iauth_cmd_H(struct iauth_client *client, char *arg) {
123 const struct iauth_result *res;
125 str = iauth_next_data(&arg);
126 if(!str) goto parse_error;
127 iauth_set(client->cclass, str);
130 /* Query database for account query. */
131 res = iauth_query(client);
133 iauth_query_reject(client->id, "Access denied.");
134 iauth_stats_def_deny();
137 if(*res->ident) iauth_query_set_username(client->id, res->ident);
138 if(*res->host) iauth_query_sethost(client->id, res->host);
139 if(*res->ip) iauth_query_setip(client->id, res->ip);
140 if(*res->modes) iauth_query_setmodes(client->id, res->modes);
141 iauth_query_assign(client->id, (*res->cclass)?res->cclass:NULL);
142 iauth_stats_def_allow();
144 iauth_delid(client->id);
148 iauth_flog(IAUTH_WARNING, "Parse error: Invalid H line.");
152 /* Server Name and Capacity: <id> M <servername> <capacity> */
153 void iauth_cmd_M(char *arg) {
154 char *server = NULL, *str = NULL;
157 server = iauth_next_data(&arg);
158 if(!server) goto parse_error;
160 str = iauth_next_data(&arg);
161 if(!str || !*str || (cap = atoi(str)) == 0) goto parse_error;
163 iauth_flog(IAUTH_INFO, "Setting server (%s) capacity to: %u.", server, cap);
164 strcpy(iauth_servname, server);
170 iauth_flog(IAUTH_WARNING, "Parse error: Invalid M line.");
176 /* Hostname Received: <id> N <hostname> */
177 void iauth_cmd_N(struct iauth_client *client, char *arg) {
180 str = iauth_next_data(&arg);
181 if(!str) goto parse_error;
182 iauth_set(client->host, str);
186 iauth_flog(IAUTH_WARNING, "Parse error: Invalid N line.");
190 /* Hostname Timeout: <id> d */
191 void iauth_cmd_d(struct iauth_client *client) {
194 str = iauth_malloc(1);
195 iauth_set(client->host, str);
200 /* Client Password: <id> P :<password ...> */
201 void iauth_cmd_P(struct iauth_client *client, char *arg) {
204 str = iauth_next_data(&arg);
205 if(!str) goto parse_error;
206 iauth_set(client->password, str);
210 iauth_flog(IAUTH_WARNING, "Parse error: Invalid P line.");
214 /* Client Username: <id> U <username> <hostname> <servername> :<userinfo ...> */
215 void iauth_cmd_U(struct iauth_client *client, char *arg) {
218 str = iauth_next_data(&arg);
219 if(!str) goto parse_error;
220 iauth_set(client->username, str);
222 str = iauth_next_data(&arg);
223 if(!str) goto parse_error;
224 iauth_set(client->c_host, str);
226 str = iauth_next_data(&arg);
227 if(!str) goto parse_error;
228 iauth_set(client->c_serv, str);
230 str = iauth_next_data(&arg);
231 if(!str) goto parse_error;
232 iauth_set(client->realname, str);
236 iauth_flog(IAUTH_WARNING, "Parse error: Invalid U line.");
240 /* Client Username: <id> u <username> */
241 void iauth_cmd_u(struct iauth_client *client, char *arg) {
244 str = iauth_next_data(&arg);
245 if(!str) goto parse_error;
246 iauth_set(client->ident, str);
250 iauth_flog(IAUTH_WARNING, "Parse error: Invalid u line.");
254 /* Client Nickname: <id> n <nickname> */
255 void iauth_cmd_n(struct iauth_client *client, char *arg) {
258 str = iauth_next_data(&arg);
259 if(!str) goto parse_error;
260 iauth_set(client->nick, str);
264 iauth_flog(IAUTH_WARNING, "Parse error: Invalid n line.");
268 /* Client Registered: <id> T */
269 void iauth_cmd_T(struct iauth_client *client) {
270 iauth_flog(IAUTH_INFO, "Client %d was registered without IAuth answer.", client->id);
271 iauth_delid(client->id);
274 /* Error: <id> E <type> :<additional text> */
275 void iauth_cmd_E(signed int id, char *arg) {
276 iauth_flog(IAUTH_WARNING, "Received IRCd error: %s", arg);