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: b96697d9825e9db62d959aa6f43cd99766377f8c $
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: b96697d9825e9db62d959aa6f43cd99766377f8c $")
27 
28 #include <freeradius-devel/server/base.h>
29 #include <freeradius-devel/server/module_rlm.h>
30 #include <freeradius-devel/unlang/xlat.h>
31 
32 /** Initialize src/lib/server/
33  *
34  * This is just so that the callers don't need to call a million functions.
35  *
36  * @param cs The root configuration section.
37  * @return
38  * - 0 on success.
39  * - -1 on failure.
40  */
42 {
43  /*
44  * Initialize the dictionary attributes needed by the tmpl code.
45  */
46  if (tmpl_global_init() < 0) return -1;
47 
48  /*
49  * Initialise the trigger rate limiting tree
50  */
51  if (trigger_exec_init(cs) < 0) return -1;
52 
53  /*
54  * Set up dictionaries and attributes for password comparisons
55  */
56  if (password_init() < 0) return -1;
57 
58  /*
59  * Initialize Auth-Type, etc. in the virtual servers
60  * before loading the modules. Some modules need those
61  * to be defined.
62  */
63  if (virtual_servers_bootstrap(cs) < 0) return -1;
64 
65  /*
66  * Bootstrap the modules. This links to them, and runs
67  * their "bootstrap" routines.
68  *
69  * After this step, all dynamic attributes, xlats, etc. are defined.
70  */
71  if (modules_rlm_bootstrap(cs) < 0) return -1;
72 
73  /*
74  * Now all the modules and virtual servers have been bootstrapped,
75  * we have all the dictionaries we're going to use in the server.
76  *
77  * We can now register xlats for any protocol encoders/decoders.
78  *
79  * Note: These xlats get freed automatically, so no explicit cleanup
80  * is required.
81  */
82  if (xlat_protocols_register() < 0) return -1;
83 
84  /*
85  * And then load the virtual servers.
86  */
87  if (virtual_servers_instantiate() < 0) return -1;
88 
89  /*
90  * Instantiate the modules
91  */
92  if (modules_rlm_instantiate() < 0) return -1;
93 
94  /*
95  * Call xlat instantiation functions (after the xlats have been compiled)
96  */
97  if (xlat_instantiate() < 0) return -1;
98 
99  /*
100  * load the 'Net.' packet attributes.
101  */
102  if (packet_global_init() < 0) return -1;
103 
104  return 0;
105 }
106 
107 /** Free src/lib/server/
108  *
109  * This is just so that the callers don't need to call a million functions.
110  */
111 void server_free(void)
112 {
113  /*
114  * Free any resources used by 'Net.' packet
115  */
117 
118  /*
119  * Free xlat instance data, and call any detach methods
120  */
122 
123  /*
124  * Free password dictionaries
125  */
126  password_free();
127 
128  /*
129  * The only maps remaining are the ones registered by the server core.
130  */
131  map_proc_free();
132 
133  /*
134  * Now we're sure no more triggers can fire, free the
135  * trigger tree.
136  */
138 
139  /*
140  * Free the internal dictionaries the request uses
141  */
143 
144  /*
145  * Free the internal dictionaries the tmpl code uses
146  */
148 }
#define RCSID(id)
Definition: build.h:444
A section grouping multiple CONF_PAIR.
Definition: cf_priv.h:89
void server_free(void)
Free src/lib/server/.
Definition: base.c:111
int server_init(CONF_SECTION *cs)
Initialize src/lib/server/.
Definition: base.c:41
int packet_global_init(void)
Initialises the Net.
Definition: packet.c:163
void packet_global_free(void)
Definition: packet.c:176
void map_proc_free(void)
Free all map_processors unregistering them.
Definition: map_proc.c:214
int modules_rlm_bootstrap(CONF_SECTION *root)
Bootstrap modules and virtual modules.
Definition: module_rlm.c:964
int modules_rlm_instantiate(void)
Performs the instantiation phase for all backend modules.
Definition: module_rlm.c:950
int password_init(void)
Load our dictionaries.
Definition: password.c:1031
void password_free(void)
Definition: password.c:1046
void request_global_free(void)
Definition: request.c:713
void tmpl_global_free(void)
Definition: tmpl_eval.c:1471
int tmpl_global_init(void)
Definition: tmpl_eval.c:1453
void trigger_exec_free(void)
Free trigger resources.
Definition: trigger.c:173
int trigger_exec_init(CONF_SECTION const *cs)
Set the global trigger section trigger_exec will search in, and register xlats.
Definition: trigger.c:143
int xlat_instantiate(void)
Call instantiation functions for all registered, "permanent" xlats.
Definition: xlat_inst.c:508
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:704
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.