| File: | daemons/ipa-slapi-plugins/topology/topology_init.c |
| Warning: | line 212, column 5 Value stored to 'rc' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | |
| 2 | #include "topology.h" |
| 3 | |
| 4 | char *ipa_topo_plugin_hostname; |
| 5 | char *ipa_topo_plugin_shared_config_base; |
| 6 | int ipa_topo_plugin_activated; |
| 7 | |
| 8 | static Slapi_PluginDesc pdesc = { PLUGIN_NAME"ipa-topology-plugin", PLUGIN_VENDOR"freeipa", PLUGIN_VERSION"1.0", |
| 9 | IPA_TOPO_PLUGIN_SUBSYSTEM"ipa-topology-plugin" }; |
| 10 | |
| 11 | static int ipa_topo_start(Slapi_PBlock * pb); |
| 12 | static int ipa_topo_close(Slapi_PBlock * pb); |
| 13 | static int ipa_topo_preop_init(Slapi_PBlock *pb); |
| 14 | static int ipa_topo_postop_init(Slapi_PBlock *pb); |
| 15 | static int ipa_topo_internal_postop_init(Slapi_PBlock *pb); |
| 16 | static int ipa_topo_rootdse_init(Slapi_PBlock *pb); |
| 17 | static int ipa_topo_rootdse_search(Slapi_PBlock *pb, Slapi_Entry* e, |
| 18 | Slapi_Entry* entryAfter, int *returncode, |
| 19 | char *returntext, void *arg); |
| 20 | void ipa_topo_be_state_change(void *handle, char *be_name, |
| 21 | int old_be_state, int new_be_state); |
| 22 | |
| 23 | int 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 | |
| 86 | static int |
| 87 | ipa_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 | |
| 104 | static int |
| 105 | ipa_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 | |
| 117 | static int |
| 118 | ipa_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 | |
| 128 | int |
| 129 | ipa_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 | } |
| 140 | void |
| 141 | ipa_topo_queue_apply_shared_config(time_t event_time, void *arg) |
| 142 | { |
| 143 | ipa_topo_apply_shared_config(); |
| 144 | } |
| 145 | int |
| 146 | ipa_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 | |
| 188 | int |
| 189 | ipa_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 | |
| 203 | static int |
| 204 | ipa_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 | |
| 240 | static int |
| 241 | ipa_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 | } |
| 251 | static int |
| 252 | ipa_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 | |
| 266 | static int |
| 267 | ipa_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 | } |
| 289 | void |
| 290 | ipa_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 | } |