1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/*
* radconf2xml.c Converts radiusd.conf to XML.
*
* Version: $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*
* Copyright 2008 The FreeRADIUS server project
* Copyright 2008 Alan DeKok <aland@deployingradius.com>
*/
#include <freeradius-devel/ident.h>
RCSID("$Id$")
#include <freeradius-devel/radiusd.h>
#include <freeradius-devel/radpaths.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
/*
* For configuration file stuff.
*/
const char *radius_dir = RADDBDIR;
const char *progname = "radconf2xml";
/*
* The rest of this is because the conffile.c, etc. assume
* they're running inside of the server. And we don't (yet)
* have a "libfreeradius-server", or "libfreeradius-util".
*/
int debug_flag = 0;
struct main_config_t mainconfig;
char *request_log_file = NULL;
char *debug_log_file = NULL;
int radius_xlat(UNUSED char *out, UNUSED int outlen, UNUSED const char *fmt,
UNUSED REQUEST *request, UNUSED RADIUS_ESCAPE_STRING func)
{
return -1;
}
static int usage(void)
{
printf("Usage: %s [ -d raddb_dir ] [ -o output_file ] [ -n name ]\n", progname);
printf(" -d raddb_dir Configuration files are in \"raddbdir/*\".\n");
printf(" -n name Read raddb/name.conf instead of raddb/radiusd.conf\n");
printf(" -o output_file File where XML output will be written.\n");
exit(1);
}
int main(int argc, char **argv)
{
int argval;
CONF_SECTION *cs;
const char *file = NULL;
const char *name = "radiusd";
FILE *fp;
char buffer[2048];
if ((progname = strrchr(argv[0], FR_DIR_SEP)) == NULL)
progname = argv[0];
else
progname++;
while ((argval = getopt(argc, argv, "d:ho:n:")) != EOF) {
switch(argval) {
case 'd':
if (file) {
fprintf(stderr, "%s: -d and -f cannot be used together.\n", progname);
exit(1);
}
radius_dir = optarg;
break;
default:
case 'h':
usage();
break;
case 'n':
name = optarg;
break;
case 'o':
file = optarg;
break;
}
}
snprintf(buffer, sizeof(buffer), "%s/%s.conf", radius_dir, name);
cs = cf_file_read(buffer);
if (!cs) {
fprintf(stderr, "%s: Errors reading %s\n",
progname, buffer);
exit(1);
}
if (!file || (strcmp(file, "-") == 0)) {
fp = stdout;
} else {
fp = fopen(file, "w");
if (!fp) {
fprintf(stderr, "%s: Failed openng %s: %s\n",
progname, file, strerror(errno));
exit(1);
}
}
if (!cf_section2xml(fp, cs)) {
if (fp != stdout) unlink(file);
return 1;
}
return 0;
}
|