Exemple #1
0
int
ipa_topo_check_topology_disconnect(Slapi_PBlock *pb)
{
    int rc = 1;
    Slapi_Entry *del_entry;
    struct node_fanout *fanout = NULL;
    char *pi;

    /* we have to check if the operation is triggered by the
     * topology plugin itself - allow it
     */
    slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY,&pi);
    if (pi && 0 == strcasecmp(pi, ipa_topo_get_plugin_id())) {
        return 0;
    }
    slapi_pblock_get(pb,SLAPI_DELETE_EXISTING_ENTRY,&del_entry);
    if (TOPO_SEGMENT_ENTRY != ipa_topo_check_entry_type(del_entry)) {
        return 0;
    } else {
        TopoReplica *tconf = ipa_topo_util_get_conf_for_segment(del_entry);
        if (tconf == NULL) {
            slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                            "topology not configured for segment\n");
            rc = 0; /* this segment is not controlled by the plugin */
            goto done;
        }
        TopoReplicaSegment *tsegm = NULL;
        tsegm = ipa_topo_util_find_segment(tconf, del_entry);
        if (tsegm == NULL) {
            slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                            "segment to be deleted does not exist\n");
            goto done;
        }
        if (!ipa_topo_util_segment_is_managed(tconf,tsegm)) {
            /* not both endpoints are managed servers, delete is ok */
            rc = 0;
            goto done;
        }
        /* check if removal of segment would break connectivity */
        fanout = ipa_topo_connection_fanout(tconf, tsegm);
        if (fanout == NULL) goto done;

        if (ipa_topo_connection_exists(fanout, tsegm->from, tsegm->to) &&
            ipa_topo_connection_exists(fanout, tsegm->to, tsegm->from)) {
            rc = 0;
        }
        ipa_topo_connection_fanout_free(fanout);
    }

done:
    return rc;
}
Exemple #2
0
int
ipa_topo_check_host_updates(Slapi_PBlock *pb)
{
    int rc = 0;
    Slapi_Entry *mod_entry;
    char *pi;

    /* we have to check if the operation is triggered by the
     * topology plugin itself - allow it
     */
    slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY,&pi);
    if (pi && 0 == strcasecmp(pi, ipa_topo_get_plugin_id())) {
        return 0;
    }
    slapi_pblock_get(pb,SLAPI_MODIFY_EXISTING_ENTRY,&mod_entry);
    if (TOPO_HOST_ENTRY == ipa_topo_check_entry_type(mod_entry) &&
        (ipa_topo_is_invalid_managed_suffix(pb))) {
        rc = 1;
    }
    return rc;
}
Exemple #3
0
int ipa_topo_is_entry_managed(Slapi_PBlock *pb)
{
    Slapi_Entry *e;
    char *pi;
    int op_type;

    if (!ipa_topo_pre_entry_in_scope(pb)) {
        /* we don't care for general mods, only specific
         * entries in the mapping tree
         */
        return 0;
    }
    slapi_pblock_get(pb, SLAPI_OPERATION_TYPE, &op_type);
    if (op_type == SLAPI_OPERATION_ADD) {
        slapi_pblock_get(pb, SLAPI_ADD_ENTRY, &e);
    } else {
        slapi_pblock_get(pb, SLAPI_ENTRY_PRE_OP, &e);
    }
    if (!ipa_topo_util_entry_is_candidate(e)) {
        /* entry has no objectclass the plugin controls */
        return 0;
    }

    /* we have to check if the operation is triggered by the
     * topology plugin itself - allow it
     */
    slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY,&pi);
    if (pi && 0 == strcasecmp(pi, ipa_topo_get_plugin_id())) {
        return 0;
    }
    /* last check: is the endpoint of the agreement amanaged host ? */
    if (ipa_topo_util_target_is_managed(e)) {
        return 1;
    } else {
        return 0;
    }

}
Exemple #4
0
int
ipa_topo_check_segment_is_valid(Slapi_PBlock *pb, char **errtxt)
{
    int rc = 0;
    Slapi_Entry *add_entry;
    char *pi;

    /* we have to check if the operation is triggered by the
     * topology plugin itself - allow it
     */
    slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY,&pi);
    if (pi && 0 == strcasecmp(pi, ipa_topo_get_plugin_id())) {
        return 0;
    }
    slapi_pblock_get(pb,SLAPI_ADD_ENTRY,&add_entry);
    if (TOPO_SEGMENT_ENTRY != ipa_topo_check_entry_type(add_entry)) {
        return 0;
    } else {
        /* a new segment is added
         * verify that the segment does not yet exist
         */
        char *leftnode = slapi_entry_attr_get_charptr(add_entry,"ipaReplTopoSegmentLeftNode");
        char *rightnode = slapi_entry_attr_get_charptr(add_entry,"ipaReplTopoSegmentRightNode");
        char *dir = slapi_entry_attr_get_charptr(add_entry,"ipaReplTopoSegmentDirection");
        if (leftnode == NULL || rightnode == NULL || dir == NULL) {
                *errtxt = slapi_ch_smprintf("Segment definition is incomplete"
                                   ". Add rejected.\n");
            rc = 1;
        } else if (strcasecmp(dir,SEGMENT_DIR_BOTH) && strcasecmp(dir,SEGMENT_DIR_LEFT_ORIGIN) &&
            strcasecmp(dir,SEGMENT_DIR_RIGHT_ORIGIN)) {
                *errtxt = slapi_ch_smprintf("Segment has unsupported direction"
                                   ". Add rejected.\n");
                slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                                "segment has unknown direction: %s\n", dir);
                rc = 1;
        } else if (0 == strcasecmp(leftnode,rightnode)) {
                *errtxt = slapi_ch_smprintf("Segment is self referential"
                                   ". Add rejected.\n");
                slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                                "segment is self referential\n");
                rc = 1;
        } else {
            TopoReplicaSegment *tsegm = NULL;
            TopoReplica *tconf = ipa_topo_util_get_conf_for_segment(add_entry);
            if (tconf == NULL ) {
                *errtxt = slapi_ch_smprintf("Segment configuration suffix not found"
                                   ". Add rejected.\n");
                slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                                "topology not configured for segment\n");
                rc = 1;
            } else {
                tsegm = ipa_topo_util_find_segment(tconf, add_entry);
            }
            if (tsegm) {
                *errtxt = slapi_ch_smprintf("Segment already exists in topology"
                                   ". Add rejected.\n");
                slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                                "segment to be added does already exist\n");
                rc = 1;
            }
        }
        slapi_ch_free_string(&leftnode);
        slapi_ch_free_string(&rightnode);
        slapi_ch_free_string(&dir);
    }
    return rc;
}
Exemple #5
0
int ipa_topo_init(Slapi_PBlock *pb)
{
    int rc = 0;
    void *ipa_topo_plugin_identity = NULL;

    slapi_log_error(SLAPI_LOG_PLUGIN, IPA_TOPO_PLUGIN_SUBSYSTEM,
                    "--> ipa_topo_init\n");

    /**
     * Store the plugin identity for later use.
     * Used for internal operations
     */

    slapi_pblock_get(pb, SLAPI_PLUGIN_IDENTITY, &ipa_topo_plugin_identity);
    ipa_topo_set_plugin_id(ipa_topo_plugin_identity);

    if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) != 0
        || slapi_pblock_set(pb, SLAPI_PLUGIN_START_FN, (void *)ipa_topo_start) != 0
        || slapi_pblock_set(pb, SLAPI_PLUGIN_CLOSE_FN, (void *)ipa_topo_close) != 0
        || slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, (void *) &pdesc) != 0) {
        slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                        "ipa_topo_init: failed to register plugin\n");
        rc = 1;
    }

    if (rc == 0) {
        char *plugin_type = "bepreoperation";
        if (slapi_register_plugin(plugin_type, 1, "ipa_topo_init",
                                  ipa_topo_preop_init, IPA_TOPO_PREOP_DESC,
                                  NULL, ipa_topo_get_plugin_id())) {
            slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                            "ipa_topo_init: failed to register preop plugin\n");
            rc = 1;
        }
    }

    if (rc == 0) {
        char *plugin_type = "postoperation";
        if (slapi_register_plugin(plugin_type, 1, "ipa_topo_init",
                                  ipa_topo_postop_init, IPA_TOPO_POSTOP_DESC,
                                  NULL, ipa_topo_get_plugin_id())) {
            slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                            "ipa_topo_init: failed to register postop plugin\n");
            rc = 1;
        }
    }
    if (rc == 0) {
        char *plugin_type = "internalpostoperation";
        if (slapi_register_plugin(plugin_type, 1, "ipa_topo_internal_init",
                                  ipa_topo_internal_postop_init,
                                  IPA_TOPO_INTERNAL_POSTOP_DESC,
                                  NULL, ipa_topo_get_plugin_id())) {
            slapi_log_error(SLAPI_LOG_FATAL, IPA_TOPO_PLUGIN_SUBSYSTEM,
                            "ipa_topo_init: failed to register internal postop plugin\n");
            rc = 1;
        }
    }

    slapi_log_error(SLAPI_LOG_PLUGIN, IPA_TOPO_PLUGIN_SUBSYSTEM,
                    "<-- ipa_topo_init\n");
    return(rc);
}