All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rlm_always.c
Go to the documentation of this file.
1 /*
2  * This program 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
5  * (at 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 /**
19  * $Id: fa36a9c5dfa6dd1c2ce3bd7ab1d70bdda91580fb $
20  * @file rlm_always.c
21  * @brief Return preconfigured fixed rcodes.
22  *
23  * @copyright 2000,2006 The FreeRADIUS server project
24  */
25 RCSID("$Id: fa36a9c5dfa6dd1c2ce3bd7ab1d70bdda91580fb $")
26 
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 #include <freeradius-devel/modcall.h>
30 
31 /*
32  * The instance data for rlm_always is the list of fake values we are
33  * going to return.
34  */
35 typedef struct rlm_always_t {
36  char const *name; //!< Name of this instance of the always module.
37  char const *rcode_str; //!< The base value.
38  char const *rcode_old; //!< Make changing the rcode work with %{poke:} and radmin.
39 
40  rlm_rcode_t rcode; //!< The integer constant representing rcode_str.
41  uint32_t simulcount;
42  bool mpp;
43 } rlm_always_t;
44 
45 /*
46  * A mapping of configuration file names to internal variables.
47  */
48 static const CONF_PARSER module_config[] = {
49  { FR_CONF_OFFSET("rcode", PW_TYPE_STRING, rlm_always_t, rcode_str), .dflt = "fail" },
50  { FR_CONF_OFFSET("simulcount", PW_TYPE_INTEGER, rlm_always_t, simulcount), .dflt = "0" },
51  { FR_CONF_OFFSET("mpp", PW_TYPE_BOOLEAN, rlm_always_t, mpp), .dflt = "no" },
53 };
54 
55 static int mod_instantiate(CONF_SECTION *conf, void *instance)
56 {
57  rlm_always_t *inst = instance;
58 
59  inst->name = cf_section_name1(conf);
60  if (!inst->name) inst->name = cf_section_name2(conf);
61  /*
62  * Convert the rcode string to an int
63  */
65  if (inst->rcode == RLM_MODULE_UNKNOWN) {
66  cf_log_err_cs(conf, "rcode value \"%s\" is invalid", inst->rcode_str);
67  return -1;
68  }
69  inst->rcode_old = NULL; /* Hack - forces the compiler not to optimise away rcode_old */
70 
71  return 0;
72 }
73 
74 /** Reparse the rcode if it changed
75  *
76  * @note Look ma, no locks...
77  *
78  * @param inst Module instance.
79  */
81 {
82  rlm_rcode_t rcode;
83 
85  if (rcode == RLM_MODULE_UNKNOWN) {
86  WARN("rlm_always (%s): Ignoring rcode change. rcode value \"%s\" is invalid ", inst->name,
87  inst->rcode_str);
88  return;
89  }
90 
91  inst->rcode = rcode;
92  inst->rcode_old = inst->rcode_str;
93 }
94 
95 /*
96  * Just return the rcode ... this function is autz, auth, acct, and
97  * preacct!
98  */
99 static rlm_rcode_t CC_HINT(nonnull) mod_always_return(void *instance, UNUSED REQUEST *request)
100 {
101  rlm_always_t *inst = instance;
102 
103  if (inst->rcode_old != inst->rcode_str) reparse_rcode(inst);
104 
105  return inst->rcode;
106 }
107 
108 #ifdef WITH_SESSION_MGMT
109 /*
110  * checksimul fakes some other variables besides the rcode...
111  */
112 static rlm_rcode_t CC_HINT(nonnull) mod_checksimul(void *instance, REQUEST *request)
113 {
114  struct rlm_always_t *inst = instance;
115 
116  if (inst->rcode_old != inst->rcode_str) reparse_rcode(inst);
117 
118  request->simul_count = inst->simulcount;
119 
120  if (inst->mpp) request->simul_mpp = 2;
121 
122  return inst->rcode;
123 }
124 #endif
125 
126 extern module_t rlm_always;
127 module_t rlm_always = {
129  .name = "always",
130  .type = RLM_TYPE_HUP_SAFE,
131  .inst_size = sizeof(rlm_always_t),
132  .config = module_config,
133  .instantiate = mod_instantiate,
134  .methods = {
135  [MOD_AUTHENTICATE] = mod_always_return,
136  [MOD_AUTHORIZE] = mod_always_return,
137  [MOD_PREACCT] = mod_always_return,
138  [MOD_ACCOUNTING] = mod_always_return,
139 #ifdef WITH_SESSION_MGMT
141 #endif
142  [MOD_PRE_PROXY] = mod_always_return,
143  [MOD_POST_PROXY] = mod_always_return,
144  [MOD_POST_AUTH] = mod_always_return,
145 #ifdef WITH_COA
146  [MOD_RECV_COA] = mod_always_return,
147  [MOD_SEND_COA] = mod_always_return
148 #endif
149  },
150 };
5 methods index for preproxy section.
Definition: modules.h:46
Metadata exported by the module.
Definition: modules.h:134
7 methods index for postauth section.
Definition: modules.h:48
#define UNUSED
Definition: libradius.h:134
#define RLM_MODULE_INIT
Definition: modules.h:86
#define CONF_PARSER_TERMINATOR
Definition: conffile.h:289
Error resolving rcode (should not be returned by modules).
Definition: radiusd.h:99
rlm_rcode_t rcode
The integer constant representing rcode_str.
Definition: rlm_always.c:40
#define inst
static rlm_rcode_t CC_HINT(nonnull)
Definition: rlm_always.c:99
#define RLM_TYPE_HUP_SAFE
Will be restarted on HUP.
Definition: modules.h:79
static int mod_instantiate(CONF_SECTION *conf, void *instance)
Definition: rlm_always.c:55
Defines a CONF_PAIR to C data type mapping.
Definition: conffile.h:267
const FR_NAME_NUMBER mod_rcode_table[]
Definition: modcall.c:186
int fr_str2int(FR_NAME_NUMBER const *table, char const *name, int def)
Definition: token.c:451
4 methods index for checksimul section.
Definition: modules.h:45
3 methods index for accounting section.
Definition: modules.h:44
struct rlm_always_t rlm_always_t
char const * rcode_old
Make changing the rcode work with %{poke:} and radmin.
Definition: rlm_always.c:38
static rlm_rcode_t mod_checksimul(void *instance, REQUEST *request)
Check if a given user is already logged in.
static const CONF_PARSER module_config[]
Definition: rlm_always.c:48
void void cf_log_err_cs(CONF_SECTION const *cs, char const *fmt,...) CC_HINT(format(printf
0 methods index for authenticate section.
Definition: modules.h:41
A truth value.
Definition: radius.h:56
32 Bit unsigned integer.
Definition: radius.h:34
char const * rcode_str
The base value.
Definition: rlm_always.c:37
enum rlm_rcodes rlm_rcode_t
Return codes indicating the result of the module call.
static rs_t * conf
Definition: radsniff.c:46
char const * cf_section_name1(CONF_SECTION const *cs)
Definition: conffile.c:3592
uint64_t magic
Used to validate module struct.
Definition: modules.h:135
#define FR_CONF_OFFSET(_n, _t, _s, _f)
Definition: conffile.h:168
module_t rlm_always
Definition: rlm_always.c:127
#define WARN(fmt,...)
Definition: log.h:144
uint32_t simulcount
Definition: rlm_always.c:41
6 methods index for postproxy section.
Definition: modules.h:47
2 methods index for preacct section.
Definition: modules.h:43
8 methods index for recvcoa section.
Definition: modules.h:50
char const * name
Name of this instance of the always module.
Definition: rlm_always.c:36
9 methods index for sendcoa section.
Definition: modules.h:51
String of printable characters.
Definition: radius.h:33
1 methods index for authorize section.
Definition: modules.h:42
#define RCSID(id)
Definition: build.h:135
char const * cf_section_name2(CONF_SECTION const *cs)
Definition: conffile.c:3601
static void reparse_rcode(rlm_always_t *inst)
Reparse the rcode if it changed.
Definition: rlm_always.c:80