2007-01-25 06:40:21 +00:00
|
|
|
/*
|
|
|
|
* ircd-ratbox: A slightly useful ircd.
|
|
|
|
* kdparse.c: Parses K and D lines.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
|
|
|
|
* Copyright (C) 1996-2002 Hybrid Development Team
|
|
|
|
* Copyright (C) 2002-2005 ircd-ratbox development team
|
|
|
|
*
|
|
|
|
* 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 2 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA
|
|
|
|
*
|
|
|
|
* $Id: kdparse.c 254 2005-09-21 23:35:12Z nenolod $
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdinc.h"
|
2008-04-03 02:52:01 +00:00
|
|
|
#include "logger.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "s_conf.h"
|
|
|
|
#include "s_newconf.h"
|
|
|
|
#include "hostmask.h"
|
|
|
|
#include "client.h"
|
2008-04-20 05:47:38 +00:00
|
|
|
#include "match.h"
|
2007-01-25 06:40:21 +00:00
|
|
|
#include "hash.h"
|
|
|
|
|
|
|
|
/* conf_add_fields()
|
|
|
|
*
|
2008-01-01 23:06:08 +00:00
|
|
|
* inputs - pointer to config item, host/pass/user/operreason/date fields
|
2007-01-25 06:40:21 +00:00
|
|
|
* output - NONE
|
|
|
|
* side effects - update respective fields with pointers
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
conf_add_fields(struct ConfItem *aconf, const char *host_field,
|
|
|
|
const char *pass_field, const char *user_field,
|
2008-01-01 23:06:08 +00:00
|
|
|
const char *operreason_field, const char *date_field)
|
2007-01-25 06:40:21 +00:00
|
|
|
{
|
|
|
|
if(host_field != NULL)
|
2008-04-01 23:26:34 +00:00
|
|
|
aconf->host = rb_strdup(host_field);
|
2007-01-25 06:40:21 +00:00
|
|
|
if(pass_field != NULL)
|
2008-01-01 23:06:08 +00:00
|
|
|
{
|
|
|
|
if(!EmptyString(date_field))
|
|
|
|
{
|
2008-04-01 23:07:29 +00:00
|
|
|
aconf->passwd = rb_malloc(strlen(pass_field) + strlen(date_field) + 4);
|
2008-04-01 20:38:40 +00:00
|
|
|
rb_sprintf(aconf->passwd, "%s (%s)", pass_field, date_field);
|
2008-01-01 23:06:08 +00:00
|
|
|
}
|
|
|
|
else
|
2008-04-01 23:26:34 +00:00
|
|
|
aconf->passwd = rb_strdup(pass_field);
|
2008-01-01 23:06:08 +00:00
|
|
|
}
|
2007-01-25 06:40:21 +00:00
|
|
|
if(user_field != NULL)
|
2008-04-01 23:26:34 +00:00
|
|
|
aconf->user = rb_strdup(user_field);
|
2007-01-25 06:40:21 +00:00
|
|
|
if(operreason_field != NULL)
|
2008-04-01 23:26:34 +00:00
|
|
|
aconf->spasswd = rb_strdup(operreason_field);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse_k_file
|
|
|
|
* Inputs - pointer to line to parse
|
|
|
|
* Output - NONE
|
|
|
|
* Side Effects - Parse one new style K line
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
parse_k_file(FILE * file)
|
|
|
|
{
|
|
|
|
struct ConfItem *aconf;
|
|
|
|
char *user_field = NULL;
|
|
|
|
char *reason_field = NULL;
|
|
|
|
char *operreason_field = NULL;
|
|
|
|
char *host_field = NULL;
|
2008-01-01 23:06:08 +00:00
|
|
|
char *date_field = NULL;
|
2007-01-25 06:40:21 +00:00
|
|
|
char line[BUFSIZE];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), file))
|
|
|
|
{
|
|
|
|
if((p = strchr(line, '\n')) != NULL)
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
if((*line == '\0') || (*line == '#'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
user_field = getfield(line);
|
|
|
|
if(EmptyString(user_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
host_field = getfield(NULL);
|
|
|
|
if(EmptyString(host_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
reason_field = getfield(NULL);
|
|
|
|
if(EmptyString(reason_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
operreason_field = getfield(NULL);
|
2008-01-01 23:06:08 +00:00
|
|
|
date_field = getfield(NULL);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
aconf = make_conf();
|
|
|
|
aconf->status = CONF_KILL;
|
|
|
|
conf_add_fields(aconf, host_field, reason_field,
|
2008-01-01 23:06:08 +00:00
|
|
|
user_field, operreason_field, date_field);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
if(aconf->host != NULL)
|
2008-06-26 06:18:58 +00:00
|
|
|
add_conf_by_address(aconf->host, CONF_KILL, aconf->user, NULL, aconf);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse_d_file
|
|
|
|
* Inputs - pointer to line to parse
|
|
|
|
* Output - NONE
|
|
|
|
* Side Effects - Parse one new style D line
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
parse_d_file(FILE * file)
|
|
|
|
{
|
|
|
|
struct ConfItem *aconf;
|
|
|
|
char *reason_field = NULL;
|
|
|
|
char *host_field = NULL;
|
|
|
|
char *operreason_field = NULL;
|
2008-01-01 23:06:08 +00:00
|
|
|
char *date_field = NULL;
|
2007-01-25 06:40:21 +00:00
|
|
|
char line[BUFSIZE];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), file))
|
|
|
|
{
|
|
|
|
if((p = strchr(line, '\n')))
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
if((*line == '\0') || (line[0] == '#'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
host_field = getfield(line);
|
|
|
|
if(EmptyString(host_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
reason_field = getfield(NULL);
|
|
|
|
if(EmptyString(reason_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
operreason_field = getfield(NULL);
|
2008-01-01 23:06:08 +00:00
|
|
|
date_field = getfield(NULL);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
aconf = make_conf();
|
|
|
|
aconf->status = CONF_DLINE;
|
2008-01-01 23:06:08 +00:00
|
|
|
conf_add_fields(aconf, host_field, reason_field, "", operreason_field, date_field);
|
2007-01-25 06:40:21 +00:00
|
|
|
conf_add_d_conf(aconf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-07 22:21:14 +00:00
|
|
|
char *
|
|
|
|
xline_encode_spaces(const char *mask)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int spaces = 0;
|
|
|
|
int backslash = 0;
|
|
|
|
char *encoded;
|
|
|
|
|
|
|
|
for (i = 0; mask[i] != '\0'; i++)
|
|
|
|
if (mask[i] == ' ')
|
|
|
|
spaces++;
|
|
|
|
encoded = rb_malloc(i + spaces + 1);
|
|
|
|
for (i = 0, j = 0; mask[i] != '\0'; i++)
|
|
|
|
{
|
|
|
|
if (mask[i] == '\\')
|
|
|
|
backslash = !backslash;
|
|
|
|
else if (mask[i] == ' ')
|
|
|
|
{
|
|
|
|
if (!backslash)
|
|
|
|
encoded[j++] = '\\';
|
|
|
|
encoded[j++] = 's';
|
|
|
|
backslash = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
backslash = 0;
|
|
|
|
encoded[j++] = mask[i];
|
|
|
|
}
|
|
|
|
return encoded;
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
void
|
|
|
|
parse_x_file(FILE * file)
|
|
|
|
{
|
|
|
|
struct ConfItem *aconf;
|
|
|
|
char *gecos_field = NULL;
|
|
|
|
char *reason_field = NULL;
|
|
|
|
char line[BUFSIZE];
|
|
|
|
char *p;
|
2009-05-07 22:21:14 +00:00
|
|
|
char *encoded;
|
2007-01-25 06:40:21 +00:00
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), file))
|
|
|
|
{
|
|
|
|
if((p = strchr(line, '\n')))
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
if((*line == '\0') || (line[0] == '#'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gecos_field = getfield(line);
|
|
|
|
if(EmptyString(gecos_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* field for xline types, which no longer exist */
|
|
|
|
getfield(NULL);
|
|
|
|
|
|
|
|
reason_field = getfield(NULL);
|
|
|
|
if(EmptyString(reason_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* sanity checking */
|
2007-11-25 17:18:07 +00:00
|
|
|
if((find_xline_mask(gecos_field) != NULL) ||
|
2007-01-25 06:40:21 +00:00
|
|
|
(strchr(reason_field, ':') != NULL))
|
|
|
|
continue;
|
|
|
|
|
2009-05-07 22:21:14 +00:00
|
|
|
encoded = xline_encode_spaces(gecos_field);
|
|
|
|
if (find_xline_mask(encoded) != NULL)
|
|
|
|
{
|
|
|
|
rb_free(encoded);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-25 06:40:21 +00:00
|
|
|
aconf = make_conf();
|
|
|
|
aconf->status = CONF_XLINE;
|
|
|
|
|
2009-05-07 22:21:14 +00:00
|
|
|
aconf->name = encoded;
|
2008-04-01 23:26:34 +00:00
|
|
|
aconf->passwd = rb_strdup(reason_field);
|
2007-01-25 06:40:21 +00:00
|
|
|
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkAddAlloc(aconf, &xline_conf_list);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
parse_resv_file(FILE * file)
|
|
|
|
{
|
|
|
|
struct ConfItem *aconf;
|
|
|
|
char *reason_field;
|
|
|
|
char *host_field;
|
|
|
|
char line[BUFSIZE];
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), file))
|
|
|
|
{
|
|
|
|
if((p = strchr(line, '\n')))
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
if((*line == '\0') || (line[0] == '#'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
host_field = getfield(line);
|
|
|
|
if(EmptyString(host_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
reason_field = getfield(NULL);
|
|
|
|
if(EmptyString(reason_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if(IsChannelName(host_field))
|
|
|
|
{
|
|
|
|
if(hash_find_resv(host_field))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
aconf = make_conf();
|
|
|
|
aconf->status = CONF_RESV_CHANNEL;
|
|
|
|
aconf->port = 0;
|
|
|
|
|
2008-04-01 23:26:34 +00:00
|
|
|
aconf->name = rb_strdup(host_field);
|
|
|
|
aconf->passwd = rb_strdup(reason_field);
|
2007-01-25 06:40:21 +00:00
|
|
|
add_to_resv_hash(aconf->name, aconf);
|
|
|
|
}
|
|
|
|
else if(clean_resv_nick(host_field))
|
|
|
|
{
|
2007-11-25 17:18:07 +00:00
|
|
|
if(find_nick_resv_mask(host_field))
|
2007-01-25 06:40:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
aconf = make_conf();
|
|
|
|
aconf->status = CONF_RESV_NICK;
|
|
|
|
aconf->port = 0;
|
|
|
|
|
2008-04-01 23:26:34 +00:00
|
|
|
aconf->name = rb_strdup(host_field);
|
|
|
|
aconf->passwd = rb_strdup(reason_field);
|
2008-04-01 20:41:52 +00:00
|
|
|
rb_dlinkAddAlloc(aconf, &resv_conf_list);
|
2007-01-25 06:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getfield
|
|
|
|
*
|
|
|
|
* inputs - input buffer
|
|
|
|
* output - next field
|
|
|
|
* side effects - field breakup for ircd.conf file.
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
getfield(char *newline)
|
|
|
|
{
|
|
|
|
static char *line = NULL;
|
|
|
|
char *end, *field;
|
|
|
|
|
|
|
|
if(newline != NULL)
|
|
|
|
line = newline;
|
|
|
|
|
|
|
|
if(line == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
field = line;
|
|
|
|
|
|
|
|
/* XXX make this skip to first " if present */
|
|
|
|
if(*field == '"')
|
|
|
|
field++;
|
|
|
|
else
|
|
|
|
return (NULL); /* mal-formed field */
|
|
|
|
|
|
|
|
end = strchr(line, ',');
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
/* no trailing , - last field */
|
|
|
|
if(end == NULL)
|
|
|
|
{
|
|
|
|
end = line + strlen(line);
|
|
|
|
line = NULL;
|
|
|
|
|
|
|
|
if(*end == '"')
|
|
|
|
{
|
|
|
|
*end = '\0';
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* look for a ", to mark the end of a field.. */
|
|
|
|
if(*(end - 1) == '"')
|
|
|
|
{
|
|
|
|
line = end + 1;
|
|
|
|
end--;
|
|
|
|
*end = '\0';
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* search for the next ',' */
|
|
|
|
end++;
|
|
|
|
end = strchr(end, ',');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|