Make radwho and radzap read 'radiusd.conf', to get the locations
authoraland <aland>
Thu, 22 Aug 2002 18:44:37 +0000 (18:44 +0000)
committeraland <aland>
Thu, 22 Aug 2002 18:44:37 +0000 (18:44 +0000)
of the radutmp files.

Patch from Andrea Gabellini

These files should really be moved to 'src/modules/rlm_radutmp',
and cleaned up.

man/man1/radzap.1
src/main/radwho.c
src/main/radzap.c

index 5317491..3403cb0 100644 (file)
@@ -3,6 +3,8 @@
 radzap - remove rogue entries from the active sessions database
 .SH SYNOPSIS
 .B radzap
+.RB [ \-d
+.IR raddb_directory ]
 .RB [ \-r
 .IR radius_server ]
 .RB [ \-p
@@ -18,6 +20,8 @@ use this database. Sometimes that database can get out of sync, and
 then it might contain rogue entries. \fBradzap\fP can clean up this
 database.
 .SH OPTIONS
+.IP \-d\ \fIraddb_directory\fP
+The directory that contains the RADIUS configuration files.
 .IP \-r\ \fIradius_server\fP
 Host name or IP address of the RADIUS server.
 .IP \-p\ \fIaccounting_port\fP
index 83f03d3..687145b 100644 (file)
@@ -91,6 +91,15 @@ int proxy_dead_time;
 int log_stripped_names;
 struct main_config_t mainconfig;
 
+struct radutmp_config_t {
+  char *radutmp_fn;
+} radutmpconfig;
+
+static CONF_PARSER module_config[] = {
+  { "filename", PW_TYPE_STRING_PTR, 0, &radutmpconfig.radutmp_fn,  RADUTMP },
+  { NULL, -1, 0, NULL, NULL }
+};
+
 /*
  *     A mapping of configuration file names to internal variables
  */
@@ -363,7 +372,6 @@ int main(int argc, char **argv)
        int c, portno;
 
        radius_dir = strdup(RADIUS_DIR);
-       radutmp_file = strdup(RADUTMP);
 
        while((c = getopt(argc, argv, "d:flhnsipcr")) != EOF) switch(c) {
                case 'd':
@@ -418,6 +426,19 @@ int main(int argc, char **argv)
        }
        cf_section_parse(cs, NULL, server_config);
 
+       /* Read the radutmp section of radiusd.conf */
+       cs = cf_section_sub_find(cf_section_find("modules"), "radutmp");
+       if(!cs) {
+               fprintf(stderr, "%s: No configuration information in radutmp section of radiusd.conf!\n",
+                       argv[0]);
+               exit(1);
+       }
+
+       cf_section_parse(cs, NULL, module_config);
+
+       /* Assign the correct path for the radutmp file */
+       radutmp_file = radutmpconfig.radutmp_fn;
+
        /*
         *      See if we are "fingerd".
         */
@@ -500,7 +521,7 @@ int main(int argc, char **argv)
        /*
         *      Show the users logged in on the terminal server(s).
         */
-       if ((fp = fopen(RADUTMP, "r")) == NULL)
+       if ((fp = fopen(radutmp_file, "r")) == NULL)
                return 0;
 
        if (!hdrdone) {
index 5629f4d..d38c15a 100644 (file)
@@ -58,10 +58,20 @@ int proxy_retry_count = RETRY_COUNT;
 int proxy_dead_time;
 int log_stripped_names;
 radlog_dest_t radlog_dest = RADLOG_FILES;
+const char *radutmp_file = NULL;
 struct main_config_t mainconfig;
 uint32_t radiusip = INADDR_NONE;
 static void usage(void);
 
+struct radutmp_config_t {
+  char *radutmp_fn;
+} radutmpconfig;
+
+static CONF_PARSER module_config[] = {
+  { "filename", PW_TYPE_STRING_PTR, 0, &radutmpconfig.radutmp_fn,  RADUTMP },
+  { NULL, -1, 0, NULL, NULL }
+};
+
 /*
  *      A mapping of configuration file names to internal variables
  */
@@ -77,7 +87,7 @@ static int radutmp_lookup(struct radutmp *u, uint32_t nasaddr,
 {
        int fd;
 
-       if ((fd = open(RADUTMP, O_RDONLY|O_CREAT, 0644)) >= 0) {
+       if ((fd = open(radutmp_file, O_RDONLY|O_CREAT, 0644)) >= 0) {
                /*
                 *      Lock the utmp file.
                 */
@@ -112,8 +122,9 @@ static int do_stop_packet(const struct radutmp *u);
 static void usage(void)
 {
         fprintf(stderr,
-                        "Usage: %s [-p acct_port] [-r servername|serverip] termserver [port] [user]\n", progname);
+                        "Usage: %s [-d raddb] [-p acct_port] [-r servername|serverip] termserver [port] [user]\n", progname);
         fprintf(stderr, "Options:\n\n");
+       fprintf(stderr, "  -d raddb        Set the raddb directory (default is %s)\n", RADIUS_DIR);
         fprintf(stderr, "  -p acct_port    Accounting port on radius server\n");
         fprintf(stderr, "  -r radserver    Radius server name or IP address\n");
         fprintf(stderr, "  termserver      Terminal Server (NAS) name or IP address to match, can be '' for any\n");
@@ -140,11 +151,17 @@ int main(int argc, char **argv)
 
        progname = argv[0];
 
+       radius_dir = strdup(RADIUS_DIR);
+
         /*  Process the options.  */
-        while ((argval = getopt(argc, argv, "p:r:")) != EOF) {
+        while ((argval = getopt(argc, argv, "d:p:r:")) != EOF) {
                                 
                 switch(argval) {
                         
+                       case 'd':
+                               if (radius_dir) free(radius_dir);
+                               radius_dir = strdup(optarg);
+                               break;
                         case 'p':
                                acct_port = atoi(optarg);
                                 break;
@@ -191,8 +208,7 @@ int main(int argc, char **argv)
        if (nas != NULL) 
                ip = nas->ipaddr;
 
-       radius_dir = strdup(RADIUS_DIR);
-
+        /* Read radiusd.conf */
        if(read_radius_conf_file() < 0) {
                fprintf(stderr, "%s: Error reading radiusd.conf.\n", argv[0]);
                exit(1);
@@ -206,6 +222,18 @@ int main(int argc, char **argv)
        }
        cf_section_parse(cs, NULL, server_config);
 
+        /* Read the radutmp section of radiusd.conf */
+        cs = cf_section_sub_find(cf_section_find("modules"), "radutmp");
+        if(!cs) {
+                fprintf(stderr, "%s: No configuration information in radutmp section of radiusd.conf!\n",
+                        argv[0]);
+                exit(1);
+        }
+
+        cf_section_parse(cs, NULL, module_config);
+
+        /* Assign the correct path for the radutmp file */
+        radutmp_file = radutmpconfig.radutmp_fn;
 
        printf("%s: zapping termserver %s, port %u",
                progname, ip_hostname(buf, sizeof(buf), ip), nas_port);