]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
added provisions for dynamic home servers
authorAlan T. DeKok <aland@freeradius.org>
Sat, 18 Apr 2020 23:56:50 +0000 (19:56 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 19 Apr 2020 00:13:48 +0000 (20:13 -0400)
and glued them into radmin.

Untested as of yet.

src/include/realms.h
src/main/command.c
src/main/realms.c

index 6dae8b4f85a46880234b24b921262c458918eaa2..cbbb9da4a92e930b05b490605b9b62ba29ddd33b 100644 (file)
@@ -206,6 +206,9 @@ home_server_t       *home_server_bynumber(int number);
 #endif
 home_pool_t    *home_pool_byname(char const *name, int type);
 
+int            home_server_afrom_file(char const *filename);
+int            home_server_delete(char const *name, char const *type);
+
 #ifdef __cplusplus
 }
 #endif
index 844898eed105e750b82825ffd8c848547558beeb..b38cc0d19524e99edfa13df61846c8f633ecc70e 100644 (file)
@@ -2597,6 +2597,36 @@ static int command_del_client(rad_listen_t *listener, int argc, char *argv[])
 }
 
 
+static int command_del_home_server(rad_listen_t *listener, int argc, char *argv[])
+{
+       if (argc < 2) {
+               cprintf_error(listener, "<name> and <type> are required\n");
+               return 0;
+       }
+
+       if (home_server_delete(argv[0], argv[1]) < 0) {
+               cprintf_error(listener, "Failed deleted home_server %s - %s", fr_strerror());
+               return 0;
+       }
+
+       return CMD_OK;
+}
+
+static int command_add_home_server_file(rad_listen_t *listener, int argc, char *argv[])
+{
+       if (argc < 1) {
+               cprintf_error(listener, "<file> is required\n");
+               return 0;
+       }
+
+       if (home_server_afrom_file(argv[0]) < 0) {
+               cprintf_error(listener, "Unable to add home server - %s\n", fr_strerror());
+               return 0;
+       }
+
+       return CMD_OK;
+}
+
 static fr_command_table_t command_table_del_client[] = {
        { "ipaddr", FR_WRITE,
          "del client ipaddr <ipaddr> [udp|tcp] [listen <ipaddr> <port>] - Delete a dynamically created client",
@@ -2606,11 +2636,23 @@ static fr_command_table_t command_table_del_client[] = {
 };
 
 
+static fr_command_table_t command_table_del_home_server[] = {
+       { "dynamic", FR_WRITE,
+         "del home_server dynamic <name> [auth|acct|coa] - Delete a dynamically created home_server",
+         command_del_client, NULL },
+
+       { NULL, 0, NULL, NULL, NULL }
+};
+
 static fr_command_table_t command_table_del[] = {
        { "client", FR_WRITE,
          "del client <command> - Delete client configuration commands",
          NULL, command_table_del_client },
 
+       { "home_server", FR_WRITE,
+         "del home_server <command> - Delete home_server configuration commands",
+         NULL, command_table_del_client },
+
        { NULL, 0, NULL, NULL, NULL }
 };
 
@@ -2624,11 +2666,24 @@ static fr_command_table_t command_table_add_client[] = {
 };
 
 
+static fr_command_table_t command_table_add_home_server[] = {
+       { "file", FR_WRITE,
+         "add home_server file <filename> - Add new home serverdefinition from <filename>",
+         command_add_home_server_file, NULL },
+
+       { NULL, 0, NULL, NULL, NULL }
+};
+
+
 static fr_command_table_t command_table_add[] = {
        { "client", FR_WRITE,
          "add client <command> - Add client configuration commands",
          NULL, command_table_add_client },
 
+       { "home_server", FR_WRITE,
+         "add home_server <command> - Add home server configuration commands",
+         NULL, command_table_add_home_server },
+
        { NULL, 0, NULL, NULL, NULL }
 };
 #endif
index eb4259811639641ea497eedf4f034395014ee8af..1bd916c05bc23463726f67fd21f5a4241dc7e7dd 100644 (file)
@@ -2805,4 +2805,102 @@ home_pool_t *home_pool_byname(char const *name, int type)
        return rbtree_finddata(home_pools_byname, &mypool);
 }
 
+
+int home_server_afrom_file(char const *filename)
+{
+       CONF_SECTION *cs, *subcs;
+       char const *p;
+
+       if (!realm_config->dynamic) {
+               fr_strerror_printf("Must set 'dynamic' in proxy.conf for dynamic home servers to work");
+               return -1;
+       }
+
+       cs = cf_section_alloc(NULL, "home", filename);
+       if (!cs) {
+               fr_strerror_printf("Failed allocating memory");
+               return -1;
+       }
+
+       if (cf_file_read(cs, filename) < 0) {
+               fr_strerror_printf("Failed reading file %s", filename);
+               talloc_free(cs);
+               return -1;
+       }
+
+       p = strrchr(filename, '/');
+       if (p) {
+               p++;
+       } else {
+               p = filename;
+       }
+
+       subcs = cf_section_sub_find_name2(cs, "home", p);
+       if (!subcs) {
+               fr_strerror_printf("No 'home_server %p' definition in the file.");
+               talloc_free(cs);
+               return -1;
+       }
+
+       home = home_server_afrom_cs(realm_config, realm_config, cs);
+       if (!home) {
+               fr_strerror_printf("Failed parsing configuration to a home_server structure");
+               talloc_free(cs);
+               return -1;
+       }
+
+       home->dynamic = true;
+
+       if (home->server || home->dual) {
+               fr_strerror_printf("Dynamic home_server '%s' cannot have 'server' or 'auth+acct'", p);
+               talloc_free(cs);
+               talloc_free(home);
+               return -1;
+       }
+
+       if (!realm_home_server_add(home)) {
+               fr_strerror_printf("Failed adding home_server to the internal data structures");
+               talloc_free(cs);
+               talloc_free(home);
+               return -1;
+       }
+
+       return 0;
+}
+
+int home_server_delete(char const *name, char const *type_name)
+{
+       home_server_t *home;
+       int type;
+
+       if (!realm_config->dynamic) {
+               fr_strerror_printf("Must set 'dynamic' in proxy.conf for dynamic home servers to work");
+               return -1;
+       }
+
+       type = fr_str2int(home_server_types, home->type_str, HOME_TYPE_INVALID);
+       if (type == HOME_TYPE_INVALID) {
+               fr_strerror_printf("Unknown home_server type '%s'", type_name);
+               return -1;
+       }
+
+       home = home_server_byname(name, type);
+       if (!home) {
+               fr_strerror_printf("Failed to find home_server %s", name);
+               return -1;
+       }
+
+       if (!home->dynamic) {
+               fr_strerror_printf("Cannot delete static home_server %s", name);
+               return -1;
+       }
+
+       (void) rbtree_deletebydata(home_servers_byname, home);
+       (void) rbtree_deletebydata(home_servers_byaddr, home);
+
+       /*
+        *      Leak home, and home->cs.  Oh well.
+        */
+       return 0;
+}
 #endif