Bug Summary

File:daemons/ipa-slapi-plugins/topology/topology_init.c
Warning:line 212, column 5
Value stored to 'rc' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name topology_init.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fmath-errno -fno-rounding-math -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -dwarf-column-info -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/10.0.0 -D HAVE_CONFIG_H -I . -I ../../.. -I . -I ./../common -D PREFIX="/usr/local" -D BINDIR="/usr/local/bin" -D LIBDIR="/usr/local/lib" -D LIBEXECDIR="/usr/local/libexec" -D DATADIR="/usr/local/share" -D USE_OPENLDAP -I /usr/include/dirsrv -I /usr/include/nspr4 -I /usr/include/nspr4 -I /usr/include/nss3 -I /usr/include/nspr4 -D __STDC_WANT_LIB_EXT1__=1 -D _DEFAULT_SOURCE=1 -D _POSIX_C_SOURCE=200809L -D PIC -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/10.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/heimes/redhat/freeipa/daemons/ipa-slapi-plugins/topology -ferror-limit 19 -fmessage-length 0 -fgnuc-version=4.2.1 -fobjc-runtime=gcc -fdiagnostics-show-option -analyzer-output=html -faddrsig -o /home/heimes/redhat/freeipa/report/2020-06-05-101548-295465-1 -x c topology_init.c
1
2#include "topology.h"
3
4char *ipa_topo_plugin_hostname;
5char *ipa_topo_plugin_shared_config_base;
6int ipa_topo_plugin_activated;
7
8static Slapi_PluginDesc pdesc = { PLUGIN_NAME"ipa-topology-plugin", PLUGIN_VENDOR"freeipa", PLUGIN_VERSION"1.0",
9 IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin" };
10
11static int ipa_topo_start(Slapi_PBlock * pb);
12static int ipa_topo_close(Slapi_PBlock * pb);
13static int ipa_topo_preop_init(Slapi_PBlock *pb);
14static int ipa_topo_postop_init(Slapi_PBlock *pb);
15static int ipa_topo_internal_postop_init(Slapi_PBlock *pb);
16static int ipa_topo_rootdse_init(Slapi_PBlock *pb);
17static int ipa_topo_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e,
18 Slapi_Entry* entryAfter, int *returncode,
19 char *returntext, void *arg);
20void ipa_topo_be_state_change(void *handle, char *be_name,
21 int old_be_state, int new_be_state);
22
23int ipa_topo_init(Slapi_PBlock *pb)
24{
25 int rc = 0;
26 void *ipa_topo_plugin_identity = NULL((void*)0);
27
28 slapi_log_error(SLAPI_LOG_PLUGIN14, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
29 "--> ipa_topo_init\n");
30
31 /**
32 * Store the plugin identity for later use.
33 * Used for internal operations
34 */
35
36 slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY13, &ipa_topo_plugin_identity);
37 ipa_topo_set_plugin_id(ipa_topo_plugin_identity);
38
39 if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION8, SLAPI_PLUGIN_VERSION_01"01") != 0
40 || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN212, (void *)ipa_topo_start) != 0
41 || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN210, (void *)ipa_topo_close) != 0
42 || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION12, (void *) &pdesc) != 0) {
43 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
44 "ipa_topo_init: failed to register plugin\n");
45 rc = 1;
46 }
47
48 if (rc == 0) {
49 char *plugin_type = "bepreoperation";
50 if (slapi_register_plugin(plugin_type, 1, "ipa_topo_init",
51 ipa_topo_preop_init, IPA_TOPO_PREOP_DESC"ipa-topology-preop-subplugin",
52 NULL((void*)0), ipa_topo_get_plugin_id())) {
53 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
54 "ipa_topo_init: failed to register preop plugin\n");
55 rc = 1;
56 }
57 }
58
59 if (rc == 0) {
60 char *plugin_type = "postoperation";
61 if (slapi_register_plugin(plugin_type, 1, "ipa_topo_init",
62 ipa_topo_postop_init, IPA_TOPO_POSTOP_DESC"ipa-topology-postop-subplugin",
63 NULL((void*)0), ipa_topo_get_plugin_id())) {
64 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
65 "ipa_topo_init: failed to register postop plugin\n");
66 rc = 1;
67 }
68 }
69 if (rc == 0) {
70 char *plugin_type = "internalpostoperation";
71 if (slapi_register_plugin(plugin_type, 1, "ipa_topo_internal_init",
72 ipa_topo_internal_postop_init,
73 IPA_TOPO_INTERNAL_POSTOP_DESC"ipa-topology-internal-postop-subplugin",
74 NULL((void*)0), ipa_topo_get_plugin_id())) {
75 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
76 "ipa_topo_init: failed to register internal postop plugin\n");
77 rc = 1;
78 }
79 }
80
81 slapi_log_error(SLAPI_LOG_PLUGIN14, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
82 "<-- ipa_topo_init\n");
83 return(rc);
84}
85
86static int
87ipa_topo_preop_init(Slapi_PBlock *pb)
88{
89 int rc;
90
91 rc = slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_MODIFY_FN451,
92 (void *)ipa_topo_pre_mod);
93 rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_MODRDN_FN452,
94 (void *)ipa_topo_pre_modrdn);
95 rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN450,
96 (void *)ipa_topo_pre_add);
97 rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN453,
98 (void *)ipa_topo_pre_del);
99
100 return(rc);
101
102}
103
104static int
105ipa_topo_postop_init(Slapi_PBlock *pb)
106{
107 int rc;
108 rc = slapi_pblock_set(pb, SLAPI_PLUGIN_POST_ADD_FN507,
109 (void *)ipa_topo_post_add);
110 rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_DELETE_FN508,
111 (void *)ipa_topo_post_del);
112 rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_POST_MODIFY_FN505,
113 (void *)ipa_topo_post_mod);
114 return(rc);
115}
116
117static int
118ipa_topo_internal_postop_init(Slapi_PBlock *pb)
119{
120 int rc;
121 rc = slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_ADD_FN520,
122 (void *)ipa_topo_post_add);
123 rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_INTERNAL_POST_DELETE_FN523,
124 (void *)ipa_topo_post_del);
125 return(rc);
126}
127
128int
129ipa_topo_setup_managed_servers(void)
130{
131 int rc = 0;
132
133 /* initially only read the entries below cn=masters
134 * and build the list of hostnames
135 */
136 rc = ipa_topo_util_setup_servers();
137
138 return rc;
139}
140void
141ipa_topo_queue_apply_shared_config(time_t event_time, void *arg)
142{
143 ipa_topo_apply_shared_config();
144}
145int
146ipa_topo_apply_shared_config(void)
147{
148 int i = 0;
149 int rc = 0;
150 char **shared_replica_root = NULL((void*)0);
151 TopoReplica *replica_config = NULL((void*)0);
152
153 while (0 == ipa_topo_acquire_startup_inprogress()) {
154 DS_Sleep(1);
155 }
156
157 shared_replica_root = ipa_topo_get_plugin_replica_root();
158 while (rc == 0 && shared_replica_root[i]) {
159 /* get replica onfig entry from shared tree */
160 replica_config = ipa_topo_util_get_replica_conf(shared_replica_root[i]);
161 if (NULL((void*)0) == replica_config) {
162 slapi_log_error(SLAPI_LOG_PLUGIN14, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
163 "cannot find replica entry for: %s\n", shared_replica_root[i]);
164 } else {
165 rc = ipa_topo_apply_shared_replica_config(replica_config);
166 }
167 i++;
168 }
169 /* initialize the list of managed servers */
170 rc = ipa_topo_setup_managed_servers();
171
172 if (ipa_topo_get_post_init()) {
173 /* this server has just been initialized, we reset the init
174 * flag in the segments which triggered this init
175 */
176 i = 0;
177 while(shared_replica_root[i]) {
178 ipa_topo_util_reset_init(shared_replica_root[i]);
179 i++;
180 }
181 ipa_topo_set_post_init(0);
182 }
183
184 ipa_topo_release_startup_inprogress();
185 return (rc);
186}
187
188int
189ipa_topo_apply_shared_replica_config(TopoReplica *replica_config)
190{
191 TopoReplicaSegmentList *replica_segments = NULL((void*)0);
192 int rc = 0;
193
194 if (replica_config) {
195 /* get all segments for the replica from the shared config */
196 replica_segments = ipa_topo_util_get_replica_segments(replica_config);
197 /* get all replication agreements for replica root */
198 rc = ipa_topo_util_update_agmt_list(replica_config, replica_segments);
199 }
200 return (rc);
201}
202
203static int
204ipa_topo_start(Slapi_PBlock * pb)
205{
206 int rc = 0;
207
208 slapi_log_error(SLAPI_LOG_PLUGIN14, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
209 "--> ipa_topo_start\n");
210
211 /* expose info about the plugin via rootdse */
212 rc = ipa_topo_rootdse_init(pb);
Value stored to 'rc' is never read
213
214 /* register callback to handle state changes of backends,
215 * required to check changes in domain level after online initialization
216 */
217 slapi_register_backend_state_change((void *)ipa_topo_be_state_change,
218 ipa_topo_be_state_change);
219
220 /* init plugin config data from the plugin entry in cn=config */
221 rc = ipa_topo_init_plugin_config(pb);
222 if (rc != 0) {
223 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
224 "unable to get configuration\n");
225 return (rc);
226 }
227
228 if (0 == ipa_topo_get_plugin_active()) {
229 slapi_log_error(SLAPI_LOG_PLUGIN14, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
230 "plugin not activated, waiting for increase of domain level\n");
231 return rc;
232 }
233
234 rc = ipa_topo_util_start(1);
235 slapi_log_error(SLAPI_LOG_PLUGIN14, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
236 "<-- ipa_topo_start\n");
237 return (rc);
238}
239
240static int
241ipa_topo_close(Slapi_PBlock * pb)
242{
243
244 ipa_topo_set_plugin_active(0);
245 slapi_config_remove_callback(SLAPI_OPERATION_SEARCH0x00000004UL, DSE_FLAG_PREOP0x0001,
246 "", LDAP_SCOPE_BASE((ber_int_t) 0x0000), "(objectclass=*)", ipa_topo_rootdse_search);
247 slapi_unregister_backend_state_change((void *)ipa_topo_be_state_change);
248 ipa_topo_free_plugin_config();
249 return 0;
250}
251static int
252ipa_topo_rootdse_init(Slapi_PBlock *pb)
253{
254 int rc = SLAPI_PLUGIN_FAILURE-1;
255
256 if (slapi_config_register_callback_plugin(SLAPI_OPERATION_SEARCH0x00000004UL,
257 DSE_FLAG_PREOP0x0001 | DSE_FLAG_PLUGIN0x0004,
258 "", LDAP_SCOPE_BASE((ber_int_t) 0x0000), "(objectclass=*)",
259 ipa_topo_rootdse_search, NULL((void*)0), pb)) {
260 rc = SLAPI_PLUGIN_SUCCESS0;
261 }
262
263 return rc;
264}
265
266static int
267ipa_topo_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, Slapi_Entry* entryAfter,
268 int *returncode, char *returntext, void *arg)
269{
270
271 char *version = slapi_ch_smprintf("%d.%d", ipa_topo_get_plugin_version_major(),
272 ipa_topo_get_plugin_version_minor());
273 slapi_entry_attr_set_charptr(e, "ipaTopologyPluginVersion", version);
274 if (ipa_topo_get_plugin_active()) {
275 slapi_entry_attr_set_charptr(e, "ipaTopologyIsManaged", "on");
276 } else {
277 slapi_entry_attr_set_charptr(e, "ipaTopologyIsManaged", "off");
278 }
279
280 /* we expose temporarily the domain level in this function, should
281 * finally be handled in a plugin managing the domain level
282 */
283 char *level = slapi_ch_smprintf("%d", ipa_topo_get_domain_level());
284 slapi_entry_attr_set_charptr(e, "ipaDomainLevel", level);
285 slapi_ch_free_string(&version);
286 slapi_ch_free_string(&level);
287 return SLAPI_DSE_CALLBACK_OK(1);
288}
289void
290ipa_topo_be_state_change(void *handle, char *be_name,
291 int old_be_state, int new_be_state)
292{
293 Slapi_Backend *be=NULL((void*)0);
294 const char *be_suffix;
295
296 /* check if different backends require different actions */
297 be = slapi_be_select_by_instance_name(be_name);
298 be_suffix = slapi_sdn_get_dn(slapi_be_getsuffix(be, 0));
299 if (0 == ipa_topo_cfg_plugin_suffix_is_managed(be_suffix)) {
300 /* nothing to do */
301 return;
302 }
303
304 if (new_be_state == SLAPI_BE_STATE_ON1) {
305 /* backend came back online - check change in domain level */
306 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
307 "ipa_topo_be_state_change - "
308 "backend %s is coming online; "
309 "checking domain level and init shared topology\n",
310 be_name);
311 ipa_topo_util_set_domain_level();
312 ipa_topo_util_check_plugin_active();
313 if (ipa_topo_get_plugin_active()) {
314 ipa_topo_set_post_init(1);
315 ipa_topo_util_start(1);
316 }
317 } else if (new_be_state == SLAPI_BE_STATE_OFFLINE2) {
318 /* backend is about to be taken down - inactivate plugin */
319 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
320 "ipa_topo_be_state_change"
321 "backend %s is going offline; inactivate plugin\n", be_name);
322 } else if (new_be_state == SLAPI_BE_STATE_DELETE3) {
323 /* backend is about to be removed - disable replication */
324 if (old_be_state == SLAPI_BE_STATE_ON1) {
325 slapi_log_error(SLAPI_LOG_FATAL0, IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin",
326 "ipa_topo_be_state_change"
327 "backend %s is about to be deleted; inactivate plugin\n", be_name);
328 }
329 }
330}