]>
jfr.im git - irc/rqf/shadowircd.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.
27 static void ConvertConf(FILE* file
,FILE *outkline
, FILE *outdline
);
28 static void usage(void);
29 static char *getfield(char *);
30 static void ReplaceQuotes(char *out
, char *in
);
31 static void parse(FILE *outkline
, FILE *outdline
, char *in
);
33 int main(int argc
,char *argv
[])
42 if (( in
= fopen(argv
[1],"r")) == NULL
)
44 fprintf(stderr
,"Can't open %s for reading\n", argv
[1]);
48 if (( outkline
= fopen(argv
[2],"w")) == NULL
)
50 fprintf(stderr
,"Can't open %s for writing\n", argv
[2]);
54 if(( outdline
= fopen(argv
[3], "w")) == NULL
)
56 fprintf(stderr
, "Can't open %s for writing\n", argv
[3]);
60 ConvertConf(in
, outkline
, outdline
);
62 fprintf(stderr
, "The kline file has been converted and should be renamed to\n");
63 fprintf(stderr
, "the config.h options (normally kline.conf and dline.conf) and\n");
64 fprintf(stderr
, "placed in your etc/ dir\n");
70 fprintf(stderr
, "klines and dlines now go in separate files:\n");
71 fprintf(stderr
,"convertklines kline.conf.old kline.conf.new dline.conf.new\n");
78 * Read configuration file.
81 * inputs - FILE* to config file to convert
82 * - FILE* to output for new klines
83 * - FILE* to output for new dlines
84 * outputs - -1 if the file cannot be opened
88 static void ConvertConf(FILE* file
, FILE *outkline
, FILE *outdline
)
91 char quotedLine
[BUFSIZE
];
94 while (fgets(line
, sizeof(line
), file
))
96 if ((p
= strchr(line
, '\n')))
99 ReplaceQuotes(quotedLine
,line
);
101 if (!*quotedLine
|| quotedLine
[0] == '#' || quotedLine
[0] == '\n' ||
102 quotedLine
[0] == ' ' || quotedLine
[0] == '\t')
105 /* Could we test if it's conf line at all? -Vesa */
106 if (quotedLine
[1] == ':')
108 parse(outkline
, outdline
, quotedLine
);
117 * Inputs - input line to quote
118 * Output - quoted line
119 * Side Effects - All quoted chars in input are replaced
120 * with quoted values in output, # chars replaced with '\0'
121 * otherwise input is copied to output.
123 static void ReplaceQuotes(char* quotedLine
,char *inputLine
)
127 static char quotes
[] = {
159 * Do quoting of characters and # detection.
161 for (out
= quotedLine
,in
= inputLine
; *in
; out
++, in
++)
171 *out
= quotes
[ (unsigned int) (*in
& 0x1F) ];
186 * Inputs - pointer to line to parse
187 * - pointer to output to write
189 * Side Effects - Parse one old style conf line.
192 static void parse(FILE *outkline
, FILE *outdline
, char* line
)
196 const char *user_field
= NULL
;
197 const char *passwd_field
= NULL
;
198 const char *host_field
= NULL
;
199 const char *operpasswd_field
= NULL
;
201 tmp
= getfield(line
);
205 for (;;) /* Fake loop, that I can use break here --msa */
208 if ((host_field
= getfield(NULL
)) == NULL
)
212 if ((passwd_field
= getfield(NULL
)) == NULL
)
216 /* if theres a password, try splitting the operreason out */
219 if((p
= strchr(passwd_field
, '|')))
222 operpasswd_field
= p
;
225 operpasswd_field
= "";
229 if ((user_field
= getfield(NULL
)) == NULL
)
232 /* what could possibly be after a userfield? */
239 operpasswd_field
= "";
245 switch( conf_letter
)
248 fprintf(stderr
, "exempt in old file, ignoring.\n");
251 case 'D': /* Deny lines (immediate refusal) */
252 if(host_field
&& passwd_field
)
253 fprintf(outdline
, "\"%s\",\"%s\",\"%s\",\"\",\"Unknown\",0\n",
254 host_field
, passwd_field
, operpasswd_field
);
257 case 'K': /* Kill user line on irc.conf */
259 if(host_field
&& passwd_field
&& user_field
)
260 fprintf(outkline
, "\"%s\",\"%s\",\"%s\",\"%s\",\"\",\"Unknown\",0\n",
261 user_field
, host_field
, passwd_field
, operpasswd_field
);
265 fprintf(stderr
, "Error in config file: %s", line
);
272 * field breakup for ircd.conf file.
274 static char *getfield(char *newline
)
276 static char *line
= NULL
;
284 fprintf(stderr
, "returned null!\n");
290 if ((end
= strchr(line
,':')) == NULL
)
293 if ((end
= strchr(field
,'\n')) == NULL
)
294 end
= field
+ strlen(field
);