]>
jfr.im git - irc/rqf/shadowircd.git/blob - src/kdparse.c
2 * ircd-ratbox: A slightly useful ircd.
3 * kdparse.c: Parses K and D lines.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 * $Id: kdparse.c 254 2005-09-21 23:35:12Z nenolod $
31 #include "s_newconf.h"
34 #include "irc_string.h"
40 * inputs - pointer to config item, host/pass/user/operreason/date fields
42 * side effects - update respective fields with pointers
45 conf_add_fields(struct ConfItem
*aconf
, const char *host_field
,
46 const char *pass_field
, const char *user_field
,
47 const char *operreason_field
, const char *date_field
)
49 if(host_field
!= NULL
)
50 DupString(aconf
->host
, host_field
);
51 if(pass_field
!= NULL
)
53 if(!EmptyString(date_field
))
55 aconf
->passwd
= MyMalloc(strlen(pass_field
) + strlen(date_field
) + 4);
56 rb_sprintf(aconf
->passwd
, "%s (%s)", pass_field
, date_field
);
59 DupString(aconf
->passwd
, pass_field
);
61 if(user_field
!= NULL
)
62 DupString(aconf
->user
, user_field
);
63 if(operreason_field
!= NULL
)
64 DupString(aconf
->spasswd
, operreason_field
);
69 * Inputs - pointer to line to parse
71 * Side Effects - Parse one new style K line
75 parse_k_file(FILE * file
)
77 struct ConfItem
*aconf
;
78 char *user_field
= NULL
;
79 char *reason_field
= NULL
;
80 char *operreason_field
= NULL
;
81 char *host_field
= NULL
;
82 char *date_field
= NULL
;
86 while (fgets(line
, sizeof(line
), file
))
88 if((p
= strchr(line
, '\n')) != NULL
)
91 if((*line
== '\0') || (*line
== '#'))
94 user_field
= getfield(line
);
95 if(EmptyString(user_field
))
98 host_field
= getfield(NULL
);
99 if(EmptyString(host_field
))
102 reason_field
= getfield(NULL
);
103 if(EmptyString(reason_field
))
106 operreason_field
= getfield(NULL
);
107 date_field
= getfield(NULL
);
110 aconf
->status
= CONF_KILL
;
111 conf_add_fields(aconf
, host_field
, reason_field
,
112 user_field
, operreason_field
, date_field
);
114 if(aconf
->host
!= NULL
)
115 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
121 * Inputs - pointer to line to parse
123 * Side Effects - Parse one new style D line
127 parse_d_file(FILE * file
)
129 struct ConfItem
*aconf
;
130 char *reason_field
= NULL
;
131 char *host_field
= NULL
;
132 char *operreason_field
= NULL
;
133 char *date_field
= NULL
;
137 while (fgets(line
, sizeof(line
), file
))
139 if((p
= strchr(line
, '\n')))
142 if((*line
== '\0') || (line
[0] == '#'))
145 host_field
= getfield(line
);
146 if(EmptyString(host_field
))
149 reason_field
= getfield(NULL
);
150 if(EmptyString(reason_field
))
153 operreason_field
= getfield(NULL
);
154 date_field
= getfield(NULL
);
157 aconf
->status
= CONF_DLINE
;
158 conf_add_fields(aconf
, host_field
, reason_field
, "", operreason_field
, date_field
);
159 conf_add_d_conf(aconf
);
164 parse_x_file(FILE * file
)
166 struct ConfItem
*aconf
;
167 char *gecos_field
= NULL
;
168 char *reason_field
= NULL
;
172 while (fgets(line
, sizeof(line
), file
))
174 if((p
= strchr(line
, '\n')))
177 if((*line
== '\0') || (line
[0] == '#'))
180 gecos_field
= getfield(line
);
181 if(EmptyString(gecos_field
))
184 /* field for xline types, which no longer exist */
187 reason_field
= getfield(NULL
);
188 if(EmptyString(reason_field
))
191 /* sanity checking */
192 if((find_xline_mask(gecos_field
) != NULL
) ||
193 (strchr(reason_field
, ':') != NULL
))
197 aconf
->status
= CONF_XLINE
;
199 DupString(aconf
->name
, gecos_field
);
200 DupString(aconf
->passwd
, reason_field
);
202 dlinkAddAlloc(aconf
, &xline_conf_list
);
207 parse_resv_file(FILE * file
)
209 struct ConfItem
*aconf
;
215 while (fgets(line
, sizeof(line
), file
))
217 if((p
= strchr(line
, '\n')))
220 if((*line
== '\0') || (line
[0] == '#'))
223 host_field
= getfield(line
);
224 if(EmptyString(host_field
))
227 reason_field
= getfield(NULL
);
228 if(EmptyString(reason_field
))
231 if(IsChannelName(host_field
))
233 if(hash_find_resv(host_field
))
237 aconf
->status
= CONF_RESV_CHANNEL
;
240 DupString(aconf
->name
, host_field
);
241 DupString(aconf
->passwd
, reason_field
);
242 add_to_resv_hash(aconf
->name
, aconf
);
244 else if(clean_resv_nick(host_field
))
246 if(find_nick_resv_mask(host_field
))
250 aconf
->status
= CONF_RESV_NICK
;
253 DupString(aconf
->name
, host_field
);
254 DupString(aconf
->passwd
, reason_field
);
255 dlinkAddAlloc(aconf
, &resv_conf_list
);
263 * inputs - input buffer
264 * output - next field
265 * side effects - field breakup for ircd.conf file.
268 getfield(char *newline
)
270 static char *line
= NULL
;
281 /* XXX make this skip to first " if present */
285 return (NULL
); /* mal-formed field */
287 end
= strchr(line
, ',');
291 /* no trailing , - last field */
294 end
= line
+ strlen(line
);
307 /* look for a ", to mark the end of a field.. */
308 if(*(end
- 1) == '"')
316 /* search for the next ',' */
318 end
= strchr(end
, ',');