]>
jfr.im git - solanum.git/blob - tools/convertklines.c
1 /************************************************************************
2 * IRC - Internet Relay Chat, tools/convertklines.c
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 1, or (at your option)
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, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: convertklines.c 6 2005-09-10 01:02:21Z nenolod $
28 static void ConvertConf(FILE* file
,FILE *outkline
, FILE *outdline
);
29 static void usage(void);
30 static char *getfield(char *);
31 static void ReplaceQuotes(char *out
, char *in
);
32 static void parse(FILE *outkline
, FILE *outdline
, char *in
);
34 int main(int argc
,char *argv
[])
43 if (( in
= fopen(argv
[1],"r")) == NULL
)
45 fprintf(stderr
,"Can't open %s for reading\n", argv
[1]);
49 if (( outkline
= fopen(argv
[2],"w")) == NULL
)
51 fprintf(stderr
,"Can't open %s for writing\n", argv
[2]);
55 if(( outdline
= fopen(argv
[3], "w")) == NULL
)
57 fprintf(stderr
, "Can't open %s for writing\n", argv
[3]);
61 ConvertConf(in
, outkline
, outdline
);
63 fprintf(stderr
, "The kline file has been converted and should be renamed to\n");
64 fprintf(stderr
, "the config.h options (normally kline.conf and dline.conf) and\n");
65 fprintf(stderr
, "placed in your etc/ dir\n");
71 fprintf(stderr
, "klines and dlines now go in separate files:\n");
72 fprintf(stderr
,"convertklines kline.conf.old kline.conf.new dline.conf.new\n");
79 * Read configuration file.
82 * inputs - FILE* to config file to convert
83 * - FILE* to output for new klines
84 * - FILE* to output for new dlines
85 * outputs - -1 if the file cannot be opened
89 static void ConvertConf(FILE* file
, FILE *outkline
, FILE *outdline
)
92 char quotedLine
[BUFSIZE
];
95 while (fgets(line
, sizeof(line
), file
))
97 if ((p
= strchr(line
, '\n')))
100 ReplaceQuotes(quotedLine
,line
);
102 if (!*quotedLine
|| quotedLine
[0] == '#' || quotedLine
[0] == '\n' ||
103 quotedLine
[0] == ' ' || quotedLine
[0] == '\t')
106 /* Could we test if it's conf line at all? -Vesa */
107 if (quotedLine
[1] == ':')
109 parse(outkline
, outdline
, quotedLine
);
118 * Inputs - input line to quote
119 * Output - quoted line
120 * Side Effects - All quoted chars in input are replaced
121 * with quoted values in output, # chars replaced with '\0'
122 * otherwise input is copied to output.
124 static void ReplaceQuotes(char* quotedLine
,char *inputLine
)
128 static char quotes
[] = {
160 * Do quoting of characters and # detection.
162 for (out
= quotedLine
,in
= inputLine
; *in
; out
++, in
++)
172 *out
= quotes
[ (unsigned int) (*in
& 0x1F) ];
187 * Inputs - pointer to line to parse
188 * - pointer to output to write
190 * Side Effects - Parse one old style conf line.
193 static void parse(FILE *outkline
, FILE *outdline
, char* line
)
197 const char *user_field
= NULL
;
198 const char *passwd_field
= NULL
;
199 const char *host_field
= NULL
;
200 const char *operpasswd_field
= NULL
;
202 tmp
= getfield(line
);
206 for (;;) /* Fake loop, that I can use break here --msa */
209 if ((host_field
= getfield(NULL
)) == NULL
)
213 if ((passwd_field
= getfield(NULL
)) == NULL
)
217 /* if theres a password, try splitting the operreason out */
220 if((p
= strchr(passwd_field
, '|')))
223 operpasswd_field
= p
;
226 operpasswd_field
= "";
230 if ((user_field
= getfield(NULL
)) == NULL
)
233 /* what could possibly be after a userfield? */
240 operpasswd_field
= "";
246 switch( conf_letter
)
249 fprintf(stderr
, "exempt in old file, ignoring.\n");
252 case 'D': /* Deny lines (immediate refusal) */
253 if(host_field
&& passwd_field
)
254 fprintf(outdline
, "\"%s\",\"%s\",\"%s\",\"\",\"Unknown\",0\n",
255 host_field
, passwd_field
, operpasswd_field
);
258 case 'K': /* Kill user line on irc.conf */
260 if(host_field
&& passwd_field
&& user_field
)
261 fprintf(outkline
, "\"%s\",\"%s\",\"%s\",\"%s\",\"\",\"Unknown\",0\n",
262 user_field
, host_field
, passwd_field
, operpasswd_field
);
266 fprintf(stderr
, "Error in config file: %s", line
);
273 * field breakup for ircd.conf file.
275 static char *getfield(char *newline
)
277 static char *line
= NULL
;
285 fprintf(stderr
, "returned null!\n");
291 if ((end
= strchr(line
,':')) == NULL
)
294 if ((end
= strchr(field
,'\n')) == NULL
)
295 end
= field
+ strlen(field
);