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);
109 #ifdef WITH_ACCOUNTING
114 #ifdef WITH_DYNAMIC_CLIENTS
115 free(client->client_server);
122 * Callback for comparing two clients.
124 static int client_ipaddr_cmp(const void *one, const void *two)
126 const RADCLIENT *a = one;
127 const RADCLIENT *b = two;
129 return fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
133 static int client_num_cmp(const void *one, const void *two)
135 const RADCLIENT *a = one;
136 const RADCLIENT *b = two;
138 return (a->number - b->number);
143 * Free a RADCLIENT list.
145 void clients_free(RADCLIENT_LIST *clients)
149 if (!clients) return;
151 for (i = 0; i <= 128; i++) {
152 if (clients->trees[i]) rbtree_free(clients->trees[i]);
153 clients->trees[i] = NULL;
156 if (clients == root_clients) {
158 if (tree_num) rbtree_free(tree_num);
165 #ifdef WITH_DYNAMIC_CLIENTS
167 * FIXME: No fr_fifo_delete()
175 * Return a new, initialized, set of clients.
177 RADCLIENT_LIST *clients_init(void)
179 RADCLIENT_LIST *clients = calloc(1, sizeof(RADCLIENT_LIST));
181 if (!clients) return NULL;
183 clients->min_prefix = 128;
190 * Sanity check a client.
192 static int client_sane(RADCLIENT *client)
194 switch (client->ipaddr.af) {
196 if (client->prefix > 32) {
201 * Zero out the subnet bits.
203 if (client->prefix == 0) {
204 memset(&client->ipaddr.ipaddr.ip4addr, 0,
205 sizeof(client->ipaddr.ipaddr.ip4addr));
207 } else if (client->prefix < 32) {
210 mask <<= (32 - client->prefix);
211 client->ipaddr.ipaddr.ip4addr.s_addr &= htonl(mask);
216 if (client->prefix > 128) return 0;
218 if (client->prefix == 0) {
219 memset(&client->ipaddr.ipaddr.ip6addr, 0,
220 sizeof(client->ipaddr.ipaddr.ip6addr));
222 } else if (client->prefix < 128) {
223 uint32_t mask, *addr;
225 addr = (uint32_t *) &client->ipaddr.ipaddr.ip6addr;
227 if ((client->prefix & 0x1f) == 0) {
230 mask = ~ ((uint32_t) 0);
231 mask <<= (32 - (client->prefix & 0x1f));
235 switch (client->prefix >> 5) {
264 * Add a client to the tree.
266 int client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
275 * If "clients" is NULL, it means add to the global list,
276 * unless we're trying to add it to a virtual server...
279 if (client->server != NULL) {
281 CONF_SECTION *listen;
283 cs = cf_section_sub_find_name2(mainconfig.config,
284 "server", client->server);
286 radlog(L_ERR, "Failed to find virtual server %s",
292 * If this server has no "listen" section, add the clients
293 * to the global client list.
295 listen = cf_section_sub_find(cs, "listen");
296 if (!listen) goto global_clients;
299 * If the client list already exists, use that.
300 * Otherwise, create a new client list.
302 clients = cf_data_find(cs, "clients");
304 clients = clients_init();
306 radlog(L_ERR, "Out of memory");
310 if (cf_data_add(cs, "clients", clients, (void *) clients_free) < 0) {
311 radlog(L_ERR, "Failed to associate clients with virtual server %s",
313 clients_free(clients);
321 * Initialize the global list, if not done already.
324 root_clients = clients_init();
325 if (!root_clients) return 0;
327 clients = root_clients;
331 if ((client->prefix < 0) || (client->prefix > 128)) {
335 if (!client_sane(client)) return 0;
338 * Create a tree for it.
340 if (!clients->trees[client->prefix]) {
341 clients->trees[client->prefix] = rbtree_create(client_ipaddr_cmp,
342 (void *) client_free, 0);
343 if (!clients->trees[client->prefix]) {
348 #define namecmp(a) ((!old->a && !client->a) || (old->a && client->a && (strcmp(old->a, client->a) == 0)))
351 * Cannot insert the same client twice.
353 old = rbtree_finddata(clients->trees[client->prefix], client);
356 * If it's a complete duplicate, then free the new
357 * one, and return "OK".
359 if ((fr_ipaddr_cmp(&old->ipaddr, &client->ipaddr) == 0) &&
360 (old->prefix == client->prefix) &&
361 namecmp(longname) && namecmp(secret) &&
362 namecmp(shortname) && namecmp(nastype) &&
363 namecmp(login) && namecmp(password) && namecmp(server) &&
364 #ifdef WITH_DYNAMIC_CLIENTS
365 (old->lifetime == client->lifetime) &&
366 namecmp(client_server) &&
370 (old->coa_server == client->coa_server) &&
371 (old->coa_pool == client->coa_pool) &&
373 (old->message_authenticator == client->message_authenticator)) {
374 DEBUG("WARNING: Ignoring duplicate client %s", client->longname);
379 radlog(L_ERR, "Failed to add duplicate client %s",
386 * Other error adding client: likely is fatal.
388 if (!rbtree_insert(clients->trees[client->prefix], client)) {
394 tree_num = rbtree_create(client_num_cmp, NULL, 0);
399 * Catch clients added by rlm_sql.
402 client->auth = rad_malloc(sizeof(*client->auth));
403 memset(client->auth, 0, sizeof(*client->auth));
406 #ifdef WITH_ACCOUNTING
408 client->acct = rad_malloc(sizeof(*client->acct));
409 memset(client->acct, 0, sizeof(*client->acct));
413 #ifdef WITH_DYNAMIC_CLIENTS
415 * More catching of clients added by rlm_sql.
417 * The sql modules sets the dynamic flag BEFORE calling
418 * us. The client_create() function sets it AFTER
421 if (client->dynamic && (client->lifetime == 0)) {
425 * If there IS an enclosing network,
426 * inherit the lifetime from it.
428 network = client_find(clients, &client->ipaddr);
430 client->lifetime = network->lifetime;
435 client->number = tree_num_max;
437 if (tree_num) rbtree_insert(tree_num, client);
440 if (client->prefix < clients->min_prefix) {
441 clients->min_prefix = client->prefix;
448 #ifdef WITH_DYNAMIC_CLIENTS
449 void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client)
453 if (!clients) clients = root_clients;
455 if (!client->dynamic) return;
457 rad_assert((client->prefix >= 0) && (client->prefix <= 128));
459 client->dynamic = 2; /* signal to client_free */
461 rbtree_deletebydata(tree_num, client);
462 rbtree_deletebydata(clients->trees[client->prefix], client);
468 * Find a client in the RADCLIENTS list by number.
469 * This is a support function for the statistics code.
471 RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
475 if (!clients) clients = root_clients;
477 if (!clients) return NULL;
479 if (number >= tree_num_max) return NULL;
484 myclient.number = number;
486 return rbtree_finddata(tree_num, &myclient);
489 clients = clients; /* -Wunused */
490 number = number; /* -Wunused */
497 * Find a client in the RADCLIENTS list.
499 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
500 const fr_ipaddr_t *ipaddr)
505 if (!clients) clients = root_clients;
507 if (!clients || !ipaddr) return NULL;
509 switch (ipaddr->af) {
522 for (i = max_prefix; i >= clients->min_prefix; i--) {
526 myclient.ipaddr = *ipaddr;
527 client_sane(&myclient); /* clean up the ipaddress */
529 if (!clients->trees[i]) continue;
531 data = rbtree_finddata(clients->trees[i], &myclient);
542 * Old wrapper for client_find
544 RADCLIENT *client_find_old(const fr_ipaddr_t *ipaddr)
546 return client_find(root_clients, ipaddr);
549 static struct in_addr cl_ip4addr;
550 static struct in6_addr cl_ip6addr;
552 static const CONF_PARSER client_config[] = {
553 { "ipaddr", PW_TYPE_IPADDR,
554 0, &cl_ip4addr, NULL },
555 { "ipv6addr", PW_TYPE_IPV6ADDR,
556 0, &cl_ip6addr, NULL },
557 { "netmask", PW_TYPE_INTEGER,
558 offsetof(RADCLIENT, prefix), 0, NULL },
560 { "require_message_authenticator", PW_TYPE_BOOLEAN,
561 offsetof(RADCLIENT, message_authenticator), 0, "no" },
563 { "secret", PW_TYPE_STRING_PTR,
564 offsetof(RADCLIENT, secret), 0, NULL },
565 { "shortname", PW_TYPE_STRING_PTR,
566 offsetof(RADCLIENT, shortname), 0, NULL },
567 { "nastype", PW_TYPE_STRING_PTR,
568 offsetof(RADCLIENT, nastype), 0, NULL },
569 { "login", PW_TYPE_STRING_PTR,
570 offsetof(RADCLIENT, login), 0, NULL },
571 { "password", PW_TYPE_STRING_PTR,
572 offsetof(RADCLIENT, password), 0, NULL },
573 { "virtual_server", PW_TYPE_STRING_PTR,
574 offsetof(RADCLIENT, server), 0, NULL },
575 { "server", PW_TYPE_STRING_PTR, /* compatability with 2.0-pre */
576 offsetof(RADCLIENT, server), 0, NULL },
578 #ifdef WITH_DYNAMIC_CLIENTS
579 { "dynamic_clients", PW_TYPE_STRING_PTR,
580 offsetof(RADCLIENT, client_server), 0, NULL },
581 { "lifetime", PW_TYPE_INTEGER,
582 offsetof(RADCLIENT, lifetime), 0, NULL },
583 { "rate_limit", PW_TYPE_BOOLEAN,
584 offsetof(RADCLIENT, rate_limit), 0, NULL },
588 { "coa_server", PW_TYPE_STRING_PTR,
589 offsetof(RADCLIENT, coa_name), 0, NULL },
592 { NULL, -1, 0, NULL, NULL }
596 static RADCLIENT *client_parse(CONF_SECTION *cs, int in_server)
601 name2 = cf_section_name2(cs);
603 cf_log_err(cf_sectiontoitem(cs),
604 "Missing client name");
609 * The size is fine.. Let's create the buffer
611 c = rad_malloc(sizeof(*c));
612 memset(c, 0, sizeof(*c));
616 c->auth = rad_malloc(sizeof(*c->auth));
617 memset(c->auth, 0, sizeof(*c->auth));
619 #ifdef WITH_ACCOUNTING
620 c->acct = rad_malloc(sizeof(*c->acct));
621 memset(c->acct, 0, sizeof(*c->acct));
625 memset(&cl_ip4addr, 0, sizeof(cl_ip4addr));
626 memset(&cl_ip6addr, 0, sizeof(cl_ip6addr));
629 if (cf_section_parse(cs, c, client_config) < 0) {
631 cf_log_err(cf_sectiontoitem(cs),
632 "Error parsing client section.");
637 * Global clients can set servers to use,
638 * per-server clients cannot.
640 if (in_server && c->server) {
642 cf_log_err(cf_sectiontoitem(cs),
643 "Clients inside of an server section cannot point to a server.");
648 * No "ipaddr" or "ipv6addr", use old-style
649 * "client <ipaddr> {" syntax.
651 if (!cf_pair_find(cs, "ipaddr") &&
652 !cf_pair_find(cs, "ipv6addr")) {
655 prefix_ptr = strchr(name2, '/');
661 c->prefix = atoi(prefix_ptr + 1);
662 if ((c->prefix < 0) || (c->prefix > 128)) {
664 cf_log_err(cf_sectiontoitem(cs),
665 "Invalid Prefix value '%s' for IP.",
669 /* Replace '/' with '\0' */
674 * Always get the numeric representation of IP
676 if (ip_hton(name2, AF_UNSPEC, &c->ipaddr) < 0) {
678 cf_log_err(cf_sectiontoitem(cs),
679 "Failed to look up hostname %s: %s",
680 name2, fr_strerror());
684 if (prefix_ptr) *prefix_ptr = '/';
685 c->longname = strdup(name2);
687 if (!c->shortname) c->shortname = strdup(c->longname);
693 * Figure out which one to use.
695 if (cf_pair_find(cs, "ipaddr")) {
696 c->ipaddr.af = AF_INET;
697 c->ipaddr.ipaddr.ip4addr = cl_ip4addr;
699 if ((c->prefix < -1) || (c->prefix > 32)) {
701 cf_log_err(cf_sectiontoitem(cs),
702 "Netmask must be between 0 and 32");
706 } else if (cf_pair_find(cs, "ipv6addr")) {
707 c->ipaddr.af = AF_INET6;
708 c->ipaddr.ipaddr.ip6addr = cl_ip6addr;
710 if ((c->prefix < -1) || (c->prefix > 128)) {
712 cf_log_err(cf_sectiontoitem(cs),
713 "Netmask must be between 0 and 128");
717 cf_log_err(cf_sectiontoitem(cs),
718 "No IP address defined for the client");
723 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
724 c->longname = strdup(buffer);
727 * Set the short name to the name2
729 if (!c->shortname) c->shortname = strdup(name2);
732 if (c->prefix < 0) switch (c->ipaddr.af) {
743 #ifdef WITH_DYNAMIC_CLIENTS
744 if (c->client_server) {
746 c->secret = strdup("testing123");
748 if (((c->ipaddr.af == AF_INET) &&
749 (c->prefix == 32)) ||
750 ((c->ipaddr.af == AF_INET6) &&
751 (c->prefix == 128))) {
752 cf_log_err(cf_sectiontoitem(cs),
753 "Dynamic clients MUST be a network, not a single IP address.");
762 if (!c->secret || !*c->secret) {
764 const char *value = NULL;
765 CONF_PAIR *cp = cf_pair_find(cs, "dhcp");
767 if (cp) value = cf_pair_value(cp);
770 * Secrets aren't needed for DHCP.
772 if (value && (strcmp(value, "yes") == 0)) return c;
776 cf_log_err(cf_sectiontoitem(cs),
777 "secret must be at least 1 character long");
783 * Point the client to the home server pool, OR to the
784 * home server. This gets around the problem of figuring
785 * out which port to use.
788 c->coa_pool = home_pool_byname(c->coa_name, HOME_TYPE_COA);
790 c->coa_server = home_server_byname(c->coa_name,
793 if (!c->coa_pool && !c->coa_server) {
794 cf_log_err(cf_sectiontoitem(cs), "No such home_server or home_server_pool \"%s\"", c->coa_name);
806 * Create the linked list of clients from the new configuration
807 * type. This way we don't have to change too much in the other
810 RADCLIENT_LIST *clients_parse_section(CONF_SECTION *section)
812 int global = FALSE, in_server = FALSE;
815 RADCLIENT_LIST *clients;
818 * Be forgiving. If there's already a clients, return
819 * it. Otherwise create a new one.
821 clients = cf_data_find(section, "clients");
822 if (clients) return clients;
824 clients = clients_init();
825 if (!clients) return NULL;
827 if (cf_top_section(section) == section) global = TRUE;
829 if (strcmp("server", cf_section_name1(section)) == 0) in_server = TRUE;
832 * Associate the clients structure with the section, where
833 * it will be freed once the section is freed.
835 if (cf_data_add(section, "clients", clients, (void *) clients_free) < 0) {
836 cf_log_err(cf_sectiontoitem(section),
837 "Failed to associate clients with section %s",
838 cf_section_name1(section));
839 clients_free(clients);
843 for (cs = cf_subsection_find_next(section, NULL, "client");
845 cs = cf_subsection_find_next(section, cs, "client")) {
846 c = client_parse(cs, in_server);
852 * FIXME: Add the client as data via cf_data_add,
853 * for migration issues.
856 #ifdef WITH_DYNAMIC_CLIENTS
858 if (c->client_server) {
863 struct stat stat_buf;
867 * Find the directory where individual
868 * client definitions are stored.
870 cp = cf_pair_find(cs, "directory");
871 if (!cp) goto add_client;
873 value = cf_pair_value(cp);
875 cf_log_err(cf_sectiontoitem(cs),
876 "The \"directory\" entry must not be empty");
881 DEBUG("including dynamic clients in %s", value);
883 dir = opendir(value);
885 cf_log_err(cf_sectiontoitem(cs), "Error reading directory %s: %s", value, strerror(errno));
891 * Read the directory, ignoring "." files.
893 while ((dp = readdir(dir)) != NULL) {
897 if (dp->d_name[0] == '.') continue;
900 * Check for valid characters
902 for (p = dp->d_name; *p != '\0'; p++) {
903 if (isalpha((int)*p) ||
906 (*p == '.')) continue;
909 if (*p != '\0') continue;
911 snprintf(buf2, sizeof(buf2), "%s/%s",
914 if ((stat(buf2, &stat_buf) != 0) ||
915 S_ISDIR(stat_buf.st_mode)) continue;
917 dc = client_read(buf2, in_server, TRUE);
919 cf_log_err(cf_sectiontoitem(cs),
920 "Failed reading client file \"%s\"", buf2);
927 * Validate, and add to the list.
929 if (!client_validate(clients, c, dc)) {
935 } /* loop over the directory */
938 #endif /* HAVE_DIRENT_H */
939 #endif /* WITH_DYNAMIC_CLIENTS */
942 if (!client_add(clients, c)) {
943 cf_log_err(cf_sectiontoitem(cs),
944 "Failed to add client %s",
945 cf_section_name2(cs));
953 * Replace the global list of clients with the new one.
954 * The old one is still referenced from the original
955 * configuration, and will be freed when that is freed.
958 root_clients = clients;
964 #ifdef WITH_DYNAMIC_CLIENTS
966 * We overload this structure a lot.
968 static const CONF_PARSER dynamic_config[] = {
969 { "FreeRADIUS-Client-IP-Address", PW_TYPE_IPADDR,
970 offsetof(RADCLIENT, ipaddr), 0, NULL },
971 { "FreeRADIUS-Client-IPv6-Address", PW_TYPE_IPV6ADDR,
972 offsetof(RADCLIENT, ipaddr), 0, NULL },
974 { "FreeRADIUS-Client-Require-MA", PW_TYPE_BOOLEAN,
975 offsetof(RADCLIENT, message_authenticator), NULL, NULL },
977 { "FreeRADIUS-Client-Secret", PW_TYPE_STRING_PTR,
978 offsetof(RADCLIENT, secret), 0, "" },
979 { "FreeRADIUS-Client-Shortname", PW_TYPE_STRING_PTR,
980 offsetof(RADCLIENT, shortname), 0, "" },
981 { "FreeRADIUS-Client-NAS-Type", PW_TYPE_STRING_PTR,
982 offsetof(RADCLIENT, nastype), 0, NULL },
983 { "FreeRADIUS-Client-Virtual-Server", PW_TYPE_STRING_PTR,
984 offsetof(RADCLIENT, server), 0, NULL },
986 { NULL, -1, 0, NULL, NULL }
990 int client_validate(RADCLIENT_LIST *clients, RADCLIENT *master, RADCLIENT *c)
995 * No virtual server defined. Inherit the parent's
998 if (master->server && !c->server) {
999 c->server = strdup(master->server);
1003 * If the client network isn't global (not tied to a
1004 * virtual server), then ensure that this clients server
1005 * is the same as the enclosing networks virtual server.
1007 if (master->server &&
1008 (strcmp(master->server, c->server) != 0)) {
1009 DEBUG("- Cannot add client %s: Virtual server %s is not the same as the virtual server for the network.",
1011 buffer, sizeof(buffer)),
1017 if (!client_add(clients, c)) {
1018 DEBUG("- Cannot add client %s: Internal error",
1020 buffer, sizeof(buffer)));
1026 * Initialize the remaining fields.
1029 c->lifetime = master->lifetime;
1030 c->created = time(NULL);
1031 c->longname = strdup(c->shortname);
1033 DEBUG("- Added client %s with shared secret %s",
1034 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer)),
1045 RADCLIENT *client_create(RADCLIENT_LIST *clients, REQUEST *request)
1052 if (!clients || !request) return NULL;
1054 c = rad_malloc(sizeof(*c));
1055 memset(c, 0, sizeof(*c));
1056 c->cs = request->client->cs;
1057 c->ipaddr.af = AF_UNSPEC;
1059 for (i = 0; dynamic_config[i].name != NULL; i++) {
1063 da = dict_attrbyname(dynamic_config[i].name);
1065 DEBUG("- Cannot add client %s: attribute \"%s\"is not in the dictionary",
1066 ip_ntoh(&request->packet->src_ipaddr,
1067 buffer, sizeof(buffer)),
1068 dynamic_config[i].name);
1074 vp = pairfind(request->config_items, da->attr);
1077 * Not required. Skip it.
1079 if (!dynamic_config[i].dflt) continue;
1081 DEBUG("- Cannot add client %s: Required attribute \"%s\" is missing.",
1082 ip_ntoh(&request->packet->src_ipaddr,
1083 buffer, sizeof(buffer)),
1084 dynamic_config[i].name);
1088 switch (dynamic_config[i].type) {
1089 case PW_TYPE_IPADDR:
1090 c->ipaddr.af = AF_INET;
1091 c->ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
1095 case PW_TYPE_IPV6ADDR:
1096 c->ipaddr.af = AF_INET6;
1097 c->ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
1101 case PW_TYPE_STRING_PTR:
1102 p = (char **) ((char *) c + dynamic_config[i].offset);
1104 if (vp->vp_strvalue[0]) {
1105 *p = strdup(vp->vp_strvalue);
1111 case PW_TYPE_BOOLEAN:
1112 pi = (int *) ((char *) c + dynamic_config[i].offset);
1113 *pi = vp->vp_integer;
1121 if (c->ipaddr.af == AF_UNSPEC) {
1122 DEBUG("- Cannot add client %s: No IP address was specified.",
1123 ip_ntoh(&request->packet->src_ipaddr,
1124 buffer, sizeof(buffer)));
1129 if (fr_ipaddr_cmp(&request->packet->src_ipaddr, &c->ipaddr) != 0) {
1132 DEBUG("- Cannot add client %s: IP address %s do not match",
1133 ip_ntoh(&request->packet->src_ipaddr,
1134 buffer, sizeof(buffer)),
1136 buf2, sizeof(buf2)));
1140 if (!c->secret || !*c->secret) {
1141 DEBUG("- Cannot add client %s: No secret was specified.",
1142 ip_ntoh(&request->packet->src_ipaddr,
1143 buffer, sizeof(buffer)));
1147 if (!client_validate(clients, request->client, c)) {
1155 * Read a client definition from the given filename.
1157 RADCLIENT *client_read(const char *filename, int in_server, int flag)
1164 if (!filename) return NULL;
1166 cs = cf_file_read(filename);
1167 if (!cs) return NULL;
1169 cs = cf_section_sub_find(cs, "client");
1171 radlog(L_ERR, "No \"client\" section found in client file");
1175 c = client_parse(cs, in_server);
1176 if (!c) return NULL;
1178 p = strrchr(filename, FR_DIR_SEP);
1185 if (!flag) return c;
1188 * Additional validations
1190 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
1191 if (strcmp(p, buffer) != 0) {
1192 DEBUG("Invalid client definition in %s: IP address %s does not match name %s", filename, buffer, p);