The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
base.c
Go to the documentation of this file.
1 /*
2  * This library is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU Lesser General Public
4  * License as published by the Free Software Foundation; either
5  * version 2.1 of the License, or (at your option) any later version.
6  *
7  * This library 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 GNU
10  * Lesser General Public License for more details.
11  *
12  * You should have received a copy of the GNU Lesser General Public
13  * License along with this library; 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: 966e555dfb03d456c1ff920e7e464ab66bb39b11 $
19  *
20  * @file src/lib/server/base.c
21  * @brief Functions to bootstrap this library
22  *
23  * @copyright 2019 The FreeRADIUS server project
24  */
25 
26 RCSID("$Id: 966e555dfb03d456c1ff920e7e464ab66bb39b11 $")
27 
28 #include <freeradius-devel/server/base.h>
29 #include <freeradius-devel/server/module_rlm.h>
30 #include <freeradius-devel/server/trigger.h>
31 #include <freeradius-devel/server/password.h>
32 #include <freeradius-devel/server/packet.h>
33 #include <freeradius-devel/unlang/xlat.h>
34 #include <freeradius-devel/util/dict.h>
35 
36 extern bool tmpl_require_enum_prefix;
37 
38 /** Initialize src/lib/server/
39  *
40  * This is just so that the callers don't need to call a million functions.
41  *
42  * @param[in] cs The root configuration section.
43  * @param[in] dict_dir The path to the raddb directory.
44  * @param[in] dict the main dictionary, usually the internal dictionary.
45  * @return
46  * - 0 on success.
47  * - -1 on failure.
48  */
49 int server_init(CONF_SECTION *cs, char const *dict_dir, fr_dict_t *dict)
50 {
51  /*
52  * Initialize the dictionary attributes needed by the tmpl code.
53  */
54  if (tmpl_global_init() < 0) return -1;
55 
56  /*
57  * Initialise the trigger rate limiting tree
58  */
59  if (trigger_exec_init(cs) < 0) return -1;
60 
61  /*
62  * Set up dictionaries and attributes for password comparisons
63  */
64  if (password_init() < 0) return -1;
65 
66  /*
67  * Initialize Auth-Type, etc. in the virtual servers
68  * before loading the modules. Some modules need those
69  * to be defined.
70  */
71  if (virtual_servers_bootstrap(cs) < 0) return -1;
72 
73  /*
74  * Bootstrap the modules. This links to them, and runs
75  * their "bootstrap" routines.
76  *
77  * After this step, all dynamic attributes, xlats, etc. are defined.
78  */
79  if (modules_rlm_bootstrap(cs) < 0) return -1;
80 
81  /*
82  * Now all the modules and virtual servers have been bootstrapped,
83  * we have all the dictionaries we're going to use in the server.
84  *
85  * We can now register xlats for any protocol encoders/decoders.
86  *
87  * Note: These xlats get freed automatically, so no explicit cleanup
88  * is required.
89  */
90  if (xlat_protocols_register() < 0) return -1;
91 
92  /*
93  * Load in the custom dictionary. We do this after the listeners
94  * have loaded their relevant dictionaries, and after the modules
95  * have created any attributes they need to, so that we can define
96  * additional protocol attributes, and add
97  */
98  switch (fr_dict_read(dict, dict_dir, FR_DICTIONARY_FILE)) {
99  case -1:
100  PERROR("Error reading custom dictionary");
101  return -1;
102  case 0:
103  DEBUG2("Including dictionary file \"%s/%s\"", dict_dir, FR_DICTIONARY_FILE);
104  break;
105 
106  default:
107  break;
108  }
109 
110  /*
111  * And then load the virtual servers.
112  */
113  if (virtual_servers_instantiate() < 0) return -1;
114 
115  /*
116  * Instantiate the modules
117  */
118  if (modules_rlm_instantiate() < 0) return -1;
119 
120  /*
121  * Call xlat instantiation functions (after the xlats have been compiled)
122  */
123  if (xlat_instantiate() < 0) return -1;
124 
125  /*
126  * load the 'Net.' packet attributes.
127  */
128  if (packet_global_init() < 0) return -1;
129 
131 
132  return 0;
133 }
134 
135 /** Free src/lib/server/
136  *
137  * This is just so that the callers don't need to call a million functions.
138  */
139 void server_free(void)
140 {
141  /*
142  * Free xlat instance data, and call any detach methods
143  */
145 }
static fr_dict_t * dict
Definition: fuzzer.c:46
#define RCSID(id)
Definition: build.h:481
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:101
int fr_dict_read(fr_dict_t *dict, char const *dict_dir, char const *filename)
Read supplementary attribute definitions into an existing dictionary.
int server_init(CONF_SECTION *cs, char const *dict_dir, fr_dict_t *dict)
Initialize src/lib/server/.
Definition: base.c:49
bool tmpl_require_enum_prefix
Definition: tmpl_tokenize.c:49
void server_free(void)
Free src/lib/server/.
Definition: base.c:139
#define PERROR(_fmt,...)
Definition: log.h:228
int packet_global_init(void)
Initialises the Net.
Definition: packet.c:185
bool main_config_migrate_option_get(char const *name)
Definition: main_config.c:1546
int modules_rlm_bootstrap(CONF_SECTION *root)
Bootstrap modules and virtual modules.
Definition: module_rlm.c:1214
int modules_rlm_instantiate(void)
Performs the instantiation phase for all backend modules.
Definition: module_rlm.c:987
int password_init(void)
Load our dictionaries.
Definition: password.c:1044
#define DEBUG2(fmt,...)
Definition: radclient.h:43
int tmpl_global_init(void)
Definition: tmpl_eval.c:1485
int trigger_exec_init(CONF_SECTION const *cs)
Definition: trigger.c:540
int xlat_instantiate(void)
Call instantiation functions for all registered, "permanent" xlats.
Definition: xlat_inst.c:513
int xlat_protocols_register(void)
Register xlats for any loaded dictionaries.
void xlat_instances_free(void)
Walk over all registered instance data and free them explicitly.
Definition: xlat_inst.c:709
#define FR_DICTIONARY_FILE
Definition: conf.h:7
int virtual_servers_bootstrap(CONF_SECTION *config)
Load protocol modules and call their bootstrap methods.
int virtual_servers_instantiate(void)
Instantiate all the virtual servers.