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>
26 #include <freeradius-devel/radiusd.h>
33 * For configuration file stuff.
35 char const *raddb_dir = RADDBDIR;
36 char const *progname = "radconf2xml";
39 * The rest of this is because the conffile.c, etc. assume
40 * they're running inside of the server. And we don't (yet)
41 * have a "libfreeradius-server", or "libfreeradius-util".
43 log_debug_t debug_flag = 0;
44 struct main_config_t mainconfig;
45 char *request_log_file = NULL;
46 char *debug_log_file = NULL;
55 pid_t rad_waitpid(pid_t pid, int *status)
57 return waitpid(pid, status, 0);
61 bool check_config = false;
63 static int usage(void)
65 printf("Usage: %s [ -d raddb_dir ] [ -o output_file ] [ -n name ]\n", progname);
66 printf(" -d raddb_dir Configuration files are in \"raddbdir/*\".\n");
67 printf(" -n name Read raddb/name.conf instead of raddb/radiusd.conf\n");
68 printf(" -o output_file File where XML output will be written.\n");
73 int main(int argc, char **argv)
77 char const *file = NULL;
78 char const *name = "radiusd";
82 if ((progname = strrchr(argv[0], FR_DIR_SEP)) == NULL)
87 while ((argval = getopt(argc, argv, "d:ho:n:")) != EOF) {
91 fprintf(stderr, "%s: -d and -f cannot be used together.\n", progname);
113 * Mismatch between the binary and the libraries it depends on
115 if (fr_check_lib_magic(RADIUSD_MAGIC_NUMBER) < 0) {
116 fr_perror("radconf2xml");
120 snprintf(buffer, sizeof(buffer), "%s/%s.conf", raddb_dir, name);
121 cs = cf_file_read(buffer);
123 fprintf(stderr, "%s: Errors reading or parsing %s\n",
128 if (!file || (strcmp(file, "-") == 0)) {
132 fp = fopen(file, "w");
134 fprintf(stderr, "%s: Failed openng %s: %s\n",
135 progname, file, strerror(errno));
140 if (!cf_section2xml(fp, cs)) {
141 if (file) unlink(file);