2 * client.c Read clients into memory.
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 2000,2006 The FreeRADIUS server project
21 * Copyright 2000 Miquel van Smoorenburg <miquels@cistron.nl>
22 * Copyright 2000 Alan DeKok <aland@ox.org>
25 #include <freeradius-devel/ident.h>
28 #include <freeradius-devel/radiusd.h>
29 #include <freeradius-devel/rad_assert.h>
36 #ifdef WITH_DYNAMIC_CLIENTS
42 struct radclient_list {
44 * FIXME: One set of trees for IPv4, and another for IPv6?
46 rbtree_t *trees[129]; /* for 0..128, inclusive. */
52 static rbtree_t *tree_num = NULL; /* client numbers 0..N */
53 static int tree_num_max = 0;
55 static RADCLIENT_LIST *root_clients = NULL;
57 #ifdef WITH_DYNAMIC_CLIENTS
58 static fr_fifo_t *deleted_clients = NULL;
62 * Callback for freeing a client.
64 void client_free(RADCLIENT *client)
68 #ifdef WITH_DYNAMIC_CLIENTS
69 if (client->dynamic == 2) {
72 if (!deleted_clients) {
73 deleted_clients = fr_fifo_create(1024,
74 (void *) client_free);
75 if (!deleted_clients) return; /* MEMLEAK */
79 * Mark it as in the fifo, and remember when we
83 client->created = now = time(NULL); /* re-set it */
84 fr_fifo_push(deleted_clients, client);
87 * Peek at the head of the fifo. If it might
88 * still be in use, return. Otherwise, pop it
89 * from the queue and delete it.
91 client = fr_fifo_peek(deleted_clients);
92 if ((client->created + 120) >= now) return;
94 client = fr_fifo_pop(deleted_clients);
95 rad_assert(client != NULL);
99 free(client->longname);
100 free(client->secret);
101 free(client->shortname);
102 free(client->nastype);
104 free(client->password);
105 free(client->server);
107 #ifdef WITH_DYNAMIC_CLIENTS
108 free(client->client_server);
115 * Callback for comparing two clients.
117 static int client_ipaddr_cmp(const void *one, const void *two)
119 const RADCLIENT *a = one;
120 const RADCLIENT *b = two;
123 return fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
127 rcode = fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
128 if (rcode != 0) return rcode;
133 if ((a->proto == IPPROTO_IP) ||
134 (b->proto == IPPROTO_IP)) return 0;
136 return (a->proto - b->proto);
141 static int client_num_cmp(const void *one, const void *two)
143 const RADCLIENT *a = one;
144 const RADCLIENT *b = two;
146 return (a->number - b->number);
151 * Free a RADCLIENT list.
153 void clients_free(RADCLIENT_LIST *clients)
157 if (!clients) return;
159 for (i = 0; i <= 128; i++) {
160 if (clients->trees[i]) rbtree_free(clients->trees[i]);
161 clients->trees[i] = NULL;
164 if (clients == root_clients) {
166 if (tree_num) rbtree_free(tree_num);
173 #ifdef WITH_DYNAMIC_CLIENTS
175 * FIXME: No fr_fifo_delete()
183 * Return a new, initialized, set of clients.
185 RADCLIENT_LIST *clients_init(void)
187 RADCLIENT_LIST *clients = calloc(1, sizeof(RADCLIENT_LIST));
189 if (!clients) return NULL;
191 clients->min_prefix = 128;
198 * Sanity check a client.
200 static int client_sane(RADCLIENT *client)
202 switch (client->ipaddr.af) {
204 if (client->prefix > 32) {
209 * Zero out the subnet bits.
211 if (client->prefix == 0) {
212 memset(&client->ipaddr.ipaddr.ip4addr, 0,
213 sizeof(client->ipaddr.ipaddr.ip4addr));
215 } else if (client->prefix < 32) {
218 mask <<= (32 - client->prefix);
219 client->ipaddr.ipaddr.ip4addr.s_addr &= htonl(mask);
224 if (client->prefix > 128) return 0;
226 if (client->prefix == 0) {
227 memset(&client->ipaddr.ipaddr.ip6addr, 0,
228 sizeof(client->ipaddr.ipaddr.ip6addr));
230 } else if (client->prefix < 128) {
231 uint32_t mask, *addr;
233 addr = (uint32_t *) &client->ipaddr.ipaddr.ip6addr;
235 if ((client->prefix & 0x1f) == 0) {
238 mask = ~ ((uint32_t) 0);
239 mask <<= (32 - (client->prefix & 0x1f));
243 switch (client->prefix >> 5) {
272 * Add a client to the tree.
274 int client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
283 * If "clients" is NULL, it means add to the global list.
287 * Initialize it, if not done already.
290 root_clients = clients_init();
291 if (!root_clients) return 0;
293 clients = root_clients;
296 if ((client->prefix < 0) || (client->prefix > 128)) {
300 if (!client_sane(client)) return 0;
303 * Create a tree for it.
305 if (!clients->trees[client->prefix]) {
306 clients->trees[client->prefix] = rbtree_create(client_ipaddr_cmp,
307 (void *) client_free, 0);
308 if (!clients->trees[client->prefix]) {
313 #define namecmp(a) ((!old->a && !client->a) || (old->a && client->a && (strcmp(old->a, client->a) == 0)))
316 * Cannot insert the same client twice.
318 old = rbtree_finddata(clients->trees[client->prefix], client);
321 * If it's a complete duplicate, then free the new
322 * one, and return "OK".
324 if ((fr_ipaddr_cmp(&old->ipaddr, &client->ipaddr) == 0) &&
325 (old->prefix == client->prefix) &&
326 namecmp(longname) && namecmp(secret) &&
327 namecmp(shortname) && namecmp(nastype) &&
328 namecmp(login) && namecmp(password) && namecmp(server) &&
329 #ifdef WITH_DYNAMIC_CLIENTS
330 (old->lifetime == client->lifetime) &&
331 namecmp(client_server) &&
335 (old->coa_server == client->coa_server) &&
336 (old->coa_pool == client->coa_pool) &&
338 (old->message_authenticator == client->message_authenticator)) {
339 DEBUGW("Ignoring duplicate client %s", client->longname);
344 radlog(L_ERR, "Failed to add duplicate client %s",
351 * Other error adding client: likely is fatal.
353 if (!rbtree_insert(clients->trees[client->prefix], client)) {
359 tree_num = rbtree_create(client_num_cmp, NULL, 0);
362 #ifdef WITH_DYNAMIC_CLIENTS
364 * More catching of clients added by rlm_sql.
366 * The sql modules sets the dynamic flag BEFORE calling
367 * us. The client_create() function sets it AFTER
370 if (client->dynamic && (client->lifetime == 0)) {
374 * If there IS an enclosing network,
375 * inherit the lifetime from it.
377 network = client_find(clients, &client->ipaddr, client->proto);
379 client->lifetime = network->lifetime;
384 client->number = tree_num_max;
386 if (tree_num) rbtree_insert(tree_num, client);
389 if (client->prefix < clients->min_prefix) {
390 clients->min_prefix = client->prefix;
397 #ifdef WITH_DYNAMIC_CLIENTS
398 void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client)
402 if (!clients) clients = root_clients;
404 if (!client->dynamic) return;
406 rad_assert((client->prefix >= 0) && (client->prefix <= 128));
408 client->dynamic = 2; /* signal to client_free */
411 rbtree_deletebydata(tree_num, client);
413 rbtree_deletebydata(clients->trees[client->prefix], client);
419 * Find a client in the RADCLIENTS list by number.
420 * This is a support function for the statistics code.
422 RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
426 if (!clients) clients = root_clients;
428 if (!clients) return NULL;
430 if (number >= tree_num_max) return NULL;
435 myclient.number = number;
437 return rbtree_finddata(tree_num, &myclient);
440 clients = clients; /* -Wunused */
441 number = number; /* -Wunused */
448 * Find a client in the RADCLIENTS list.
450 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
451 const fr_ipaddr_t *ipaddr, int proto)
456 if (!clients) clients = root_clients;
458 if (!clients || !ipaddr) return NULL;
460 switch (ipaddr->af) {
473 for (i = max_prefix; i >= clients->min_prefix; i--) {
477 myclient.ipaddr = *ipaddr;
478 myclient.proto = proto;
479 client_sane(&myclient); /* clean up the ipaddress */
481 if (!clients->trees[i]) continue;
483 data = rbtree_finddata(clients->trees[i], &myclient);
494 * Old wrapper for client_find
496 RADCLIENT *client_find_old(const fr_ipaddr_t *ipaddr)
498 return client_find(root_clients, ipaddr, IPPROTO_UDP);
501 static struct in_addr cl_ip4addr;
502 static struct in6_addr cl_ip6addr;
503 static char *cl_srcipaddr = NULL;
505 static char *hs_proto = NULL;
509 static CONF_PARSER limit_config[] = {
510 { "max_connections", PW_TYPE_INTEGER,
511 offsetof(RADCLIENT, limit.max_connections), NULL, "16" },
513 { "lifetime", PW_TYPE_INTEGER,
514 offsetof(RADCLIENT, limit.lifetime), NULL, "0" },
516 { "idle_timeout", PW_TYPE_INTEGER,
517 offsetof(RADCLIENT, limit.idle_timeout), NULL, "30" },
519 { NULL, -1, 0, NULL, NULL } /* end the list */
523 static const CONF_PARSER client_config[] = {
524 { "ipaddr", PW_TYPE_IPADDR,
525 0, &cl_ip4addr, NULL },
526 { "ipv6addr", PW_TYPE_IPV6ADDR,
527 0, &cl_ip6addr, NULL },
528 { "netmask", PW_TYPE_INTEGER,
529 offsetof(RADCLIENT, prefix), 0, NULL },
531 { "src_ipaddr", PW_TYPE_STRING_PTR,
532 0, &cl_srcipaddr, NULL },
534 { "require_message_authenticator", PW_TYPE_BOOLEAN,
535 offsetof(RADCLIENT, message_authenticator), 0, "no" },
537 { "secret", PW_TYPE_STRING_PTR,
538 offsetof(RADCLIENT, secret), 0, NULL },
539 { "shortname", PW_TYPE_STRING_PTR,
540 offsetof(RADCLIENT, shortname), 0, NULL },
541 { "nastype", PW_TYPE_STRING_PTR,
542 offsetof(RADCLIENT, nastype), 0, NULL },
543 { "login", PW_TYPE_STRING_PTR,
544 offsetof(RADCLIENT, login), 0, NULL },
545 { "password", PW_TYPE_STRING_PTR,
546 offsetof(RADCLIENT, password), 0, NULL },
547 { "virtual_server", PW_TYPE_STRING_PTR,
548 offsetof(RADCLIENT, server), 0, NULL },
549 { "server", PW_TYPE_STRING_PTR, /* compatability with 2.0-pre */
550 offsetof(RADCLIENT, server), 0, NULL },
553 { "proto", PW_TYPE_STRING_PTR,
554 0, &hs_proto, NULL },
556 { "limit", PW_TYPE_SUBSECTION, 0, NULL, (const void *) limit_config },
559 #ifdef WITH_DYNAMIC_CLIENTS
560 { "dynamic_clients", PW_TYPE_STRING_PTR,
561 offsetof(RADCLIENT, client_server), 0, NULL },
562 { "lifetime", PW_TYPE_INTEGER,
563 offsetof(RADCLIENT, lifetime), 0, NULL },
564 { "rate_limit", PW_TYPE_BOOLEAN,
565 offsetof(RADCLIENT, rate_limit), 0, NULL },
569 { "coa_server", PW_TYPE_STRING_PTR,
570 offsetof(RADCLIENT, coa_name), 0, NULL },
573 { NULL, -1, 0, NULL, NULL }
577 static RADCLIENT *client_parse(CONF_SECTION *cs, int in_server)
582 name2 = cf_section_name2(cs);
584 cf_log_err(cf_sectiontoitem(cs),
585 "Missing client name");
590 * The size is fine.. Let's create the buffer
592 c = rad_malloc(sizeof(*c));
593 memset(c, 0, sizeof(*c));
596 memset(&cl_ip4addr, 0, sizeof(cl_ip4addr));
597 memset(&cl_ip6addr, 0, sizeof(cl_ip6addr));
600 if (cf_section_parse(cs, c, client_config) < 0) {
601 cf_log_err(cf_sectiontoitem(cs),
602 "Error parsing client section.");
616 * Global clients can set servers to use,
617 * per-server clients cannot.
619 if (in_server && c->server) {
620 cf_log_err(cf_sectiontoitem(cs),
621 "Clients inside of an server section cannot point to a server.");
626 * No "ipaddr" or "ipv6addr", use old-style
627 * "client <ipaddr> {" syntax.
629 if (!cf_pair_find(cs, "ipaddr") &&
630 !cf_pair_find(cs, "ipv6addr")) {
633 prefix_ptr = strchr(name2, '/');
639 c->prefix = atoi(prefix_ptr + 1);
640 if ((c->prefix < 0) || (c->prefix > 128)) {
641 cf_log_err(cf_sectiontoitem(cs),
642 "Invalid Prefix value '%s' for IP.",
646 /* Replace '/' with '\0' */
651 * Always get the numeric representation of IP
653 if (ip_hton(name2, AF_UNSPEC, &c->ipaddr) < 0) {
654 cf_log_err(cf_sectiontoitem(cs),
655 "Failed to look up hostname %s: %s",
656 name2, fr_strerror());
660 if (prefix_ptr) *prefix_ptr = '/';
661 c->longname = strdup(name2);
663 if (!c->shortname) c->shortname = strdup(c->longname);
669 * Figure out which one to use.
671 if (cf_pair_find(cs, "ipaddr")) {
672 c->ipaddr.af = AF_INET;
673 c->ipaddr.ipaddr.ip4addr = cl_ip4addr;
675 if ((c->prefix < -1) || (c->prefix > 32)) {
676 cf_log_err(cf_sectiontoitem(cs),
677 "Netmask must be between 0 and 32");
681 } else if (cf_pair_find(cs, "ipv6addr")) {
682 c->ipaddr.af = AF_INET6;
683 c->ipaddr.ipaddr.ip6addr = cl_ip6addr;
685 if ((c->prefix < -1) || (c->prefix > 128)) {
686 cf_log_err(cf_sectiontoitem(cs),
687 "Netmask must be between 0 and 128");
691 cf_log_err(cf_sectiontoitem(cs),
692 "No IP address defined for the client");
696 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
697 c->longname = strdup(buffer);
700 * Set the short name to the name2
702 if (!c->shortname) c->shortname = strdup(name2);
704 c->proto = IPPROTO_UDP;
707 if (strcmp(hs_proto, "udp") == 0) {
711 } else if (strcmp(hs_proto, "tcp") == 0) {
714 c->proto = IPPROTO_TCP;
716 } else if (strcmp(hs_proto, "*") == 0) {
719 c->proto = IPPROTO_IP; /* fake for dual */
722 cf_log_err(cf_sectiontoitem(cs),
723 "Unknown proto \"%s\".", hs_proto);
731 * If a src_ipaddr is specified, when we send the return packet
732 * we will use this address instead of the src from the
736 #ifdef WITH_UDPFROMTO
737 if (ip_hton(cl_srcipaddr, c->ipaddr.af, &c->src_ipaddr) < 0) {
738 cf_log_err(cf_sectiontoitem(cs), "Failed parsing src_ipaddr");
742 DEBUGW("Server not build with udpfromto, ignoring client src_ipaddr");
749 if (c->prefix < 0) switch (c->ipaddr.af) {
760 #ifdef WITH_DYNAMIC_CLIENTS
761 if (c->client_server) {
763 c->secret = strdup("testing123");
765 if (((c->ipaddr.af == AF_INET) &&
766 (c->prefix == 32)) ||
767 ((c->ipaddr.af == AF_INET6) &&
768 (c->prefix == 128))) {
769 cf_log_err(cf_sectiontoitem(cs),
770 "Dynamic clients MUST be a network, not a single IP address.");
778 if (!c->secret || !*c->secret) {
780 const char *value = NULL;
781 CONF_PAIR *cp = cf_pair_find(cs, "dhcp");
783 if (cp) value = cf_pair_value(cp);
786 * Secrets aren't needed for DHCP.
788 if (value && (strcmp(value, "yes") == 0)) return c;
791 cf_log_err(cf_sectiontoitem(cs),
792 "secret must be at least 1 character long");
798 * Point the client to the home server pool, OR to the
799 * home server. This gets around the problem of figuring
800 * out which port to use.
803 c->coa_pool = home_pool_byname(c->coa_name, HOME_TYPE_COA);
805 c->coa_server = home_server_byname(c->coa_name,
808 if (!c->coa_pool && !c->coa_server) {
809 cf_log_err(cf_sectiontoitem(cs), "No such home_server or home_server_pool \"%s\"", c->coa_name);
816 if ((c->proto == IPPROTO_TCP) || (c->proto == IPPROTO_IP)) {
817 if ((c->limit.idle_timeout > 0) && (c->limit.idle_timeout < 5))
818 c->limit.idle_timeout = 5;
819 if ((c->limit.lifetime > 0) && (c->limit.lifetime < 5))
820 c->limit.lifetime = 5;
821 if ((c->limit.lifetime > 0) && (c->limit.idle_timeout > c->limit.lifetime))
822 c->limit.idle_timeout = 0;
831 * Create the linked list of clients from the new configuration
832 * type. This way we don't have to change too much in the other
835 RADCLIENT_LIST *clients_parse_section(CONF_SECTION *section)
837 int global = FALSE, in_server = FALSE;
840 RADCLIENT_LIST *clients;
843 * Be forgiving. If there's already a clients, return
844 * it. Otherwise create a new one.
846 clients = cf_data_find(section, "clients");
847 if (clients) return clients;
849 clients = clients_init();
850 if (!clients) return NULL;
852 if (cf_top_section(section) == section) global = TRUE;
854 if (strcmp("server", cf_section_name1(section)) == 0) in_server = TRUE;
857 * Associate the clients structure with the section, where
858 * it will be freed once the section is freed.
860 if (cf_data_add(section, "clients", clients, (void *) clients_free) < 0) {
861 cf_log_err(cf_sectiontoitem(section),
862 "Failed to associate clients with section %s",
863 cf_section_name1(section));
864 clients_free(clients);
868 for (cs = cf_subsection_find_next(section, NULL, "client");
870 cs = cf_subsection_find_next(section, cs, "client")) {
871 c = client_parse(cs, in_server);
877 * FIXME: Add the client as data via cf_data_add,
878 * for migration issues.
881 #ifdef WITH_DYNAMIC_CLIENTS
883 if (c->client_server) {
888 struct stat stat_buf;
892 * Find the directory where individual
893 * client definitions are stored.
895 cp = cf_pair_find(cs, "directory");
896 if (!cp) goto add_client;
898 value = cf_pair_value(cp);
900 cf_log_err(cf_sectiontoitem(cs),
901 "The \"directory\" entry must not be empty");
906 DEBUG("including dynamic clients in %s", value);
908 dir = opendir(value);
910 cf_log_err(cf_sectiontoitem(cs), "Error reading directory %s: %s", value, strerror(errno));
916 * Read the directory, ignoring "." files.
918 while ((dp = readdir(dir)) != NULL) {
922 if (dp->d_name[0] == '.') continue;
925 * Check for valid characters
927 for (p = dp->d_name; *p != '\0'; p++) {
928 if (isalpha((int)*p) ||
931 (*p == '.')) continue;
934 if (*p != '\0') continue;
936 snprintf(buf2, sizeof(buf2), "%s/%s",
939 if ((stat(buf2, &stat_buf) != 0) ||
940 S_ISDIR(stat_buf.st_mode)) continue;
942 dc = client_read(buf2, in_server, TRUE);
944 cf_log_err(cf_sectiontoitem(cs),
945 "Failed reading client file \"%s\"", buf2);
952 * Validate, and add to the list.
954 if (!client_validate(clients, c, dc)) {
960 } /* loop over the directory */
963 #endif /* HAVE_DIRENT_H */
964 #endif /* WITH_DYNAMIC_CLIENTS */
967 if (!client_add(clients, c)) {
968 cf_log_err(cf_sectiontoitem(cs),
969 "Failed to add client %s",
970 cf_section_name2(cs));
978 * Replace the global list of clients with the new one.
979 * The old one is still referenced from the original
980 * configuration, and will be freed when that is freed.
983 root_clients = clients;
989 #ifdef WITH_DYNAMIC_CLIENTS
991 * We overload this structure a lot.
993 static const CONF_PARSER dynamic_config[] = {
994 { "FreeRADIUS-Client-IP-Address", PW_TYPE_IPADDR,
995 offsetof(RADCLIENT, ipaddr), 0, NULL },
996 { "FreeRADIUS-Client-IPv6-Address", PW_TYPE_IPV6ADDR,
997 offsetof(RADCLIENT, ipaddr), 0, NULL },
998 { "FreeRADIUS-Client-Src-IP-Address", PW_TYPE_IPADDR,
999 offsetof(RADCLIENT, src_ipaddr), 0, NULL },
1000 { "FreeRADIUS-Client-Src-IPv6-Address", PW_TYPE_IPV6ADDR,
1001 offsetof(RADCLIENT, src_ipaddr), 0, NULL },
1003 { "FreeRADIUS-Client-Require-MA", PW_TYPE_BOOLEAN,
1004 offsetof(RADCLIENT, message_authenticator), NULL, NULL },
1006 { "FreeRADIUS-Client-Secret", PW_TYPE_STRING_PTR,
1007 offsetof(RADCLIENT, secret), 0, "" },
1008 { "FreeRADIUS-Client-Shortname", PW_TYPE_STRING_PTR,
1009 offsetof(RADCLIENT, shortname), 0, "" },
1010 { "FreeRADIUS-Client-NAS-Type", PW_TYPE_STRING_PTR,
1011 offsetof(RADCLIENT, nastype), 0, NULL },
1012 { "FreeRADIUS-Client-Virtual-Server", PW_TYPE_STRING_PTR,
1013 offsetof(RADCLIENT, server), 0, NULL },
1015 { NULL, -1, 0, NULL, NULL }
1019 int client_validate(RADCLIENT_LIST *clients, RADCLIENT *master, RADCLIENT *c)
1024 * No virtual server defined. Inherit the parent's
1027 if (master->server && !c->server) {
1028 c->server = strdup(master->server);
1032 * If the client network isn't global (not tied to a
1033 * virtual server), then ensure that this clients server
1034 * is the same as the enclosing networks virtual server.
1036 if (master->server &&
1037 (strcmp(master->server, c->server) != 0)) {
1038 DEBUG("- Cannot add client %s: Virtual server %s is not the same as the virtual server for the network.",
1040 buffer, sizeof(buffer)),
1046 if (!client_add(clients, c)) {
1047 DEBUG("- Cannot add client %s: Internal error",
1049 buffer, sizeof(buffer)));
1055 * Initialize the remaining fields.
1058 c->lifetime = master->lifetime;
1059 c->created = time(NULL);
1060 c->longname = strdup(c->shortname);
1062 DEBUG("- Added client %s with shared secret %s",
1063 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer)),
1074 RADCLIENT *client_create(RADCLIENT_LIST *clients, REQUEST *request)
1081 if (!clients || !request) return NULL;
1083 c = rad_malloc(sizeof(*c));
1084 memset(c, 0, sizeof(*c));
1085 c->cs = request->client->cs;
1086 c->ipaddr.af = AF_UNSPEC;
1087 c->src_ipaddr.af = AF_UNSPEC;
1089 for (i = 0; dynamic_config[i].name != NULL; i++) {
1090 const DICT_ATTR *da;
1093 da = dict_attrbyname(dynamic_config[i].name);
1095 DEBUG("- Cannot add client %s: attribute \"%s\"is not in the dictionary",
1096 ip_ntoh(&request->packet->src_ipaddr,
1097 buffer, sizeof(buffer)),
1098 dynamic_config[i].name);
1104 vp = pairfind(request->config_items, da->attr, da->vendor, TAG_ANY);
1107 * Not required. Skip it.
1109 if (!dynamic_config[i].dflt) continue;
1111 DEBUG("- Cannot add client %s: Required attribute \"%s\" is missing.",
1112 ip_ntoh(&request->packet->src_ipaddr,
1113 buffer, sizeof(buffer)),
1114 dynamic_config[i].name);
1118 switch (dynamic_config[i].type) {
1119 case PW_TYPE_IPADDR:
1120 if (da->type == PW_FREERADIUS_CLIENT_IP_ADDRESS) {
1121 c->ipaddr.af = AF_INET;
1122 c->ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
1124 } else if (da->type == PW_FREERADIUS_CLIENT_SRC_IP_ADDRESS) {
1125 #ifdef WITH_UDPFROMTO
1126 c->src_ipaddr.af = AF_INET;
1127 c->src_ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
1129 DEBUGW("Server not build with udpfromto, ignoring FreeRADIUS-Client-Src-IP-Address.");
1135 case PW_TYPE_IPV6ADDR:
1136 if (da->type == PW_FREERADIUS_CLIENT_SRC_IPV6_ADDRESS) {
1137 c->ipaddr.af = AF_INET6;
1138 c->ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
1140 } else if (da->type == PW_FREERADIUS_CLIENT_SRC_IPV6_ADDRESS) {
1141 #ifdef WITH_UDPFROMTO
1142 c->src_ipaddr.af = AF_INET6;
1143 c->src_ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
1145 DEBUGW("Server not build with udpfromto, ignoring FreeRADIUS-Client-Src-IPv6-Address.");
1151 case PW_TYPE_STRING_PTR:
1152 p = (char **) ((char *) c + dynamic_config[i].offset);
1154 if (vp->vp_strvalue[0]) {
1155 *p = strdup(vp->vp_strvalue);
1161 case PW_TYPE_BOOLEAN:
1162 pi = (int *) ((char *) c + dynamic_config[i].offset);
1163 *pi = vp->vp_integer;
1171 if (c->ipaddr.af == AF_UNSPEC) {
1172 DEBUG("- Cannot add client %s: No IP address was specified.",
1173 ip_ntoh(&request->packet->src_ipaddr,
1174 buffer, sizeof(buffer)));
1179 if (fr_ipaddr_cmp(&request->packet->src_ipaddr, &c->ipaddr) != 0) {
1182 DEBUG("- Cannot add client %s: IP address %s do not match",
1183 ip_ntoh(&request->packet->src_ipaddr,
1184 buffer, sizeof(buffer)),
1186 buf2, sizeof(buf2)));
1190 if (!c->secret || !*c->secret) {
1191 DEBUG("- Cannot add client %s: No secret was specified.",
1192 ip_ntoh(&request->packet->src_ipaddr,
1193 buffer, sizeof(buffer)));
1197 if (!client_validate(clients, request->client, c)) {
1201 if ((c->src_ipaddr.af != AF_UNSPEC) && (c->src_ipaddr.af != c->ipaddr.af)) {
1202 DEBUG("- Cannot add client %s: Client IP and src address are different IP version.",
1203 ip_ntoh(&request->packet->src_ipaddr,
1204 buffer, sizeof(buffer)));
1213 * Read a client definition from the given filename.
1215 RADCLIENT *client_read(const char *filename, int in_server, int flag)
1222 if (!filename) return NULL;
1224 cs = cf_file_read(filename);
1225 if (!cs) return NULL;
1227 cs = cf_section_sub_find(cs, "client");
1229 radlog(L_ERR, "No \"client\" section found in client file");
1233 c = client_parse(cs, in_server);
1234 if (!c) return NULL;
1236 p = strrchr(filename, FR_DIR_SEP);
1243 if (!flag) return c;
1246 * Additional validations
1248 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
1249 if (strcmp(p, buffer) != 0) {
1250 DEBUG("Invalid client definition in %s: IP address %s does not match name %s", filename, buffer, p);