/src/freeradius-server/src/lib/server/base.c
Line | Count | Source |
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: 1e9cbe773d550eea4b2f9fb2169032db7bf875a7 $ |
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: 1e9cbe773d550eea4b2f9fb2169032db7bf875a7 $") |
27 | | |
28 | | #include <freeradius-devel/server/base.h> |
29 | | #include <freeradius-devel/server/module_rlm.h> |
30 | | |
31 | | /** Initialize src/lib/server/ |
32 | | * |
33 | | * This is just so that the callers don't need to call a million functions. |
34 | | * |
35 | | * @param[in] cs The root configuration section. |
36 | | * @param[in] conf_dir The path to the main configuration directory. |
37 | | * @param[in] dict the main dictionary, usually the internal dictionary. |
38 | | * @return |
39 | | * - 0 on success. |
40 | | * - -1 on failure. |
41 | | */ |
42 | | int server_init(CONF_SECTION *cs, char const *conf_dir, fr_dict_t *dict) |
43 | 0 | { |
44 | | /* |
45 | | * Initialize the dictionary attributes needed by the tmpl code. |
46 | | */ |
47 | 0 | if (tmpl_global_init() < 0) return -1; |
48 | | |
49 | | /* |
50 | | * Set up dictionaries and attributes for password comparisons |
51 | | */ |
52 | 0 | if (password_init() < 0) return -1; |
53 | | |
54 | | /* |
55 | | * Initialize Auth-Type, etc. in the virtual servers |
56 | | * before loading the modules. Some modules need those |
57 | | * to be defined. |
58 | | */ |
59 | 0 | if (virtual_servers_bootstrap(cs) < 0) return -1; |
60 | | |
61 | | /* |
62 | | * Bootstrap the modules. This links to them, and runs |
63 | | * their "bootstrap" routines. |
64 | | * |
65 | | * After this step, all dynamic attributes, xlats, etc. are defined. |
66 | | */ |
67 | 0 | if (modules_rlm_bootstrap(cs) < 0) return -1; |
68 | | |
69 | | /* |
70 | | * Now all the modules and virtual servers have been bootstrapped, |
71 | | * we have all the dictionaries we're going to use in the server. |
72 | | * |
73 | | * We can now register xlats for any protocol encoders/decoders. |
74 | | * |
75 | | * Note: These xlats get freed automatically, so no explicit cleanup |
76 | | * is required. |
77 | | */ |
78 | 0 | if (xlat_protocols_register() < 0) return -1; |
79 | | |
80 | | /* |
81 | | * Load in the custom dictionary. We do this after the listeners |
82 | | * have loaded their relevant dictionaries, and after the modules |
83 | | * have created any attributes they need to, so that we can define |
84 | | * additional protocol attributes, and add |
85 | | */ |
86 | 0 | switch (fr_dict_read(dict, conf_dir, FR_DICTIONARY_FILE)) { |
87 | 0 | case -1: |
88 | 0 | PERROR("Failed reading site-local dictionary"); |
89 | 0 | return -1; |
90 | 0 | case 0: |
91 | 0 | DEBUG2("Including dictionary file \"%s/%s\"", conf_dir, FR_DICTIONARY_FILE); |
92 | 0 | break; |
93 | | |
94 | 0 | default: |
95 | 0 | break; |
96 | 0 | } |
97 | | |
98 | | /* |
99 | | * Initialise the trigger rate limiting tree. |
100 | | * |
101 | | * This must be done after the modules have been bootstrapped, so that |
102 | | * any xlat functions/dictionary attributes have been registered and |
103 | | * before the modules actually want to use triggers or open connections. |
104 | | */ |
105 | 0 | if (trigger_init(cs) < 0) return -1; |
106 | | |
107 | | /* |
108 | | * And then load the virtual servers. |
109 | | */ |
110 | 0 | if (virtual_servers_instantiate() < 0) return -1; |
111 | | |
112 | | /* |
113 | | * Instantiate the modules |
114 | | */ |
115 | 0 | if (modules_rlm_instantiate() < 0) return -1; |
116 | | |
117 | | /* |
118 | | * Call xlat instantiation functions (after the xlats have been compiled) |
119 | | */ |
120 | 0 | if (xlat_instantiate() < 0) return -1; |
121 | | |
122 | | /* |
123 | | * load the 'Net.' packet attributes. |
124 | | */ |
125 | 0 | if (packet_global_init() < 0) return -1; |
126 | | |
127 | 0 | fr_suid_up = rad_suid_up; |
128 | 0 | fr_suid_down = rad_suid_down; |
129 | |
|
130 | 0 | return 0; |
131 | 0 | } |
132 | | |
133 | | /** Free src/lib/server/ |
134 | | * |
135 | | * This is just so that the callers don't need to call a million functions. |
136 | | */ |
137 | | void server_free(void) |
138 | 0 | { |
139 | | /* |
140 | | * Free xlat instance data, and call any detach methods |
141 | | */ |
142 | 0 | xlat_instances_free(); |
143 | |
|
144 | 0 | fr_suid_up = fr_suid_noop; |
145 | 0 | fr_suid_down = fr_suid_noop; |
146 | 0 | } |