2 * radconf2xml.c Converts radiusd.conf to XML.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2008 The FreeRADIUS server project
21 * Copyright 2008 Alan DeKok <aland@deployingradius.com>
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/radpaths.h>
35 * For configuration file stuff.
37 char *radius_dir = RADDBDIR;
38 const char *progname = "radconf2xml";
41 * The rest of this is because the conffile.c, etc. assume
42 * they're running inside of the server. And we don't (yet)
43 * have a "libfreeradius-server", or "libfreeradius-util".
46 struct main_config_t mainconfig;
47 char *request_log_file = NULL;
48 char *debug_log_file = NULL;
49 int radius_xlat(UNUSED char *out, UNUSED int outlen, UNUSED const char *fmt,
50 UNUSED REQUEST *request, UNUSED RADIUS_ESCAPE_STRING func)
55 static int usage(void)
57 printf("Usage: %s [ -d raddb_dir ] [ -o output_file ] [ -n name ]\n", progname);
58 printf(" -d raddb_dir Configuration files are in \"raddbdir/*\".\n");
59 printf(" -n name Read raddb/name.conf instead of raddb/radiusd.conf\n");
60 printf(" -o output_file File where XML output will be written.\n");
65 int main(int argc, char **argv)
69 const char *file = NULL;
70 const char *name = "radiusd";
74 if ((progname = strrchr(argv[0], FR_DIR_SEP)) == NULL)
79 while ((argval = getopt(argc, argv, "d:ho:n:")) != EOF) {
83 fprintf(stderr, "%s: -d and -f cannot be used together.\n", progname);
104 snprintf(buffer, sizeof(buffer), "%s/%s.conf", radius_dir, name);
105 cs = cf_file_read(buffer);
107 fprintf(stderr, "%s: Errors reading %s\n",
112 if (!file || (strcmp(file, "-") == 0)) {
115 fp = fopen(file, "w");
117 fprintf(stderr, "%s: Failed openng %s: %s\n",
118 progname, file, strerror(errno));
123 if (!cf_section2xml(fp, cs)) {
124 if (fp != stdout) unlink(file);