All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rlm_dynamic_clients.c
Go to the documentation of this file.
1 /*
2  * This program is is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or (at
5  * your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15  */
16 
17 /**
18  * $Id: 61a5483851b769f32c04ffc7320bbd7b25752a08 $
19  * @file rlm_dynamic_clients.c
20  * @brief Reads client definitions from flat files as required.
21  *
22  * @copyright 2008 The FreeRADIUS server project
23  * @copyright 2008 Alan DeKok <aland@deployingradius.com>
24  */
25 RCSID("$Id: 61a5483851b769f32c04ffc7320bbd7b25752a08 $")
26 
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 
30 #ifdef WITH_DYNAMIC_CLIENTS
31 /*
32  * Find the client definition.
33  */
34 static rlm_rcode_t CC_HINT(nonnull) mod_authorize(UNUSED void *instance,
35  REQUEST *request)
36 {
37  size_t length;
38  char const *value;
39  CONF_PAIR *cp;
40  RADCLIENT *c;
41  char buffer[2048];
42 
43  /*
44  * Ensure we're only being called from the main thread,
45  * with fake packets.
46  */
47  if ((request->packet->src_port != 0) || (request->packet->vps != NULL) ||
48  (request->parent != NULL)) {
49  RDEBUG("Improper configuration");
50  return RLM_MODULE_NOOP;
51  }
52 
53  if (!request->client || !request->client->cs) {
54  RDEBUG("Unknown client definition");
55  return RLM_MODULE_NOOP;
56  }
57 
58  cp = cf_pair_find(request->client->cs, "directory");
59  if (!cp) {
60  RDEBUG("No directory configuration in the client");
61  return RLM_MODULE_NOOP;
62  }
63 
64  value = cf_pair_value(cp);
65  if (!value) {
66  RDEBUG("No value given for the directory entry in the client");
67  return RLM_MODULE_NOOP;
68  }
69 
70  length = strlen(value);
71  if (length > (sizeof(buffer) - 256)) {
72  RDEBUG("Directory name too long");
73  return RLM_MODULE_NOOP;
74  }
75 
76  memcpy(buffer, value, length + 1);
77  fr_inet_ntoh(&request->packet->src_ipaddr,
78  buffer + length, sizeof(buffer) - length - 1);
79 
80  /*
81  * Read the buffer and generate the client.
82  */
83  c = client_read(buffer, (request->client->server != NULL), true);
84  if (!c) return RLM_MODULE_FAIL;
85 
86  /*
87  * Replace the client. This is more than a bit of a
88  * hack.
89  */
90  request->client = c;
91 
92  return RLM_MODULE_OK;
93 }
94 #else
95 static rlm_rcode_t CC_HINT(nonnull) mod_authorize(UNUSED void *instance, REQUEST *request)
96 {
97  RDEBUG("Dynamic clients are unsupported in this build");
98  return RLM_MODULE_FAIL;
99 }
100 #endif
101 
102 /*
103  * The module name should be the only globally exported symbol.
104  * That is, everything else should be 'static'.
105  *
106  * If the module needs to temporarily modify it's instantiation
107  * data, the type should be changed to RLM_TYPE_THREAD_UNSAFE.
108  * The server will then take care of ensuring that the module
109  * is single-threaded.
110  */
112 module_t rlm_dynamic_clients = {
114  .name = "dynamic_clients",
115  .type = RLM_TYPE_THREAD_SAFE, /* type */
116  .methods = {
118  },
119 };
module_t rlm_dynamic_clients
The module is OK, continue.
Definition: radiusd.h:91
Metadata exported by the module.
Definition: modules.h:134
static rlm_rcode_t mod_authorize(void *instance, REQUEST *request)
Handle authorization requests using Couchbase document data.
#define RLM_TYPE_THREAD_SAFE
Module is threadsafe.
Definition: modules.h:75
#define UNUSED
Definition: libradius.h:134
#define RLM_MODULE_INIT
Definition: modules.h:86
uint8_t length
Definition: proto_bfd.c:203
CONF_PAIR * cf_pair_find(CONF_SECTION const *, char const *name)
Definition: conffile.c:3478
char const * cf_pair_value(CONF_PAIR const *pair)
Definition: conffile.c:3506
RADCLIENT * client_read(char const *filename, int in_server, int flag)
Definition: client.c:1449
Configuration AVP similar to a VALUE_PAIR.
Definition: conffile.c:82
enum rlm_rcodes rlm_rcode_t
Return codes indicating the result of the module call.
Module succeeded without doing anything.
Definition: radiusd.h:96
Describes a host allowed to send packets to the server.
Definition: clients.h:35
uint64_t magic
Used to validate module struct.
Definition: modules.h:135
Module failed, don't reply.
Definition: radiusd.h:90
1 methods index for authorize section.
Definition: modules.h:42
#define RCSID(id)
Definition: build.h:135
char const * fr_inet_ntoh(fr_ipaddr_t const *src, char *out, size_t outlen)
Perform reverse resolution of an IP address.
Definition: inet.c:226
#define RDEBUG(fmt,...)
Definition: log.h:243
static rlm_rcode_t CC_HINT(nonnull)