summaryrefslogtreecommitdiffstats
path: root/daemons/ipa-slapi-plugins
diff options
context:
space:
mode:
authorTomas Babej <tbabej@redhat.com>2014-04-22 12:34:12 +0200
committerMartin Kosek <mkosek@redhat.com>2014-04-23 13:18:41 +0200
commit5e5d4818a1d9a4422b28f445fbac2e1daa513e82 (patch)
tree6f13800e0d2e7477377c17c4862014c168f27100 /daemons/ipa-slapi-plugins
parent91d68864d1b59cfc30fa68303f2f664d2e2368bf (diff)
downloadfreeipa-5e5d4818a1d9a4422b28f445fbac2e1daa513e82.tar.gz
freeipa-5e5d4818a1d9a4422b28f445fbac2e1daa513e82.tar.xz
freeipa-5e5d4818a1d9a4422b28f445fbac2e1daa513e82.zip
ipa_range_check: Change range_check return values from int to range_check_result_t enum
Using integers for return values that are used for complex casing can be fragile and typo-prone. Change range_check function to return range_check_result_t enum, whose values properly describes each of the range_check results. Part of: https://fedorahosted.org/freeipa/ticket/4137 Reviewed-By: Martin Kosek <mkosek@redhat.com>
Diffstat (limited to 'daemons/ipa-slapi-plugins')
-rw-r--r--daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c b/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c
index b55624912..d659dc7d8 100644
--- a/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c
+++ b/daemons/ipa-slapi-plugins/ipa-range-check/ipa_range_check.c
@@ -79,6 +79,16 @@ struct ipa_range_check_ctx {
const char *base_dn;
};
+typedef enum {
+ RANGE_CHECK_OK,
+ RANGE_CHECK_BASE_OVERLAP,
+ RANGE_CHECK_PRIMARY_PRIMARY_RID_OVERLAP,
+ RANGE_CHECK_SECONDARY_SECONDARY_RID_OVERLAP,
+ RANGE_CHECK_PRIMARY_SECONDARY_RID_OVERLAP,
+ RANGE_CHECK_SECONDARY_PRIMARY_RID_OVERLAP,
+ RANGE_CHECK_DIFFERENT_TYPE_IN_DOMAIN,
+} range_check_result_t;
+
struct range_info {
char *name;
char *domain_id;
@@ -377,12 +387,12 @@ static bool intervals_overlap(uint32_t x, uint32_t base, uint32_t x_size, uint32
* | | / \ |
* new range: base rid sec_rid
**/
-static int check_ranges(struct range_info *r1, struct range_info *r2)
+static range_check_result_t check_ranges(struct range_info *r1, struct range_info *r2)
{
/* Do not check overlaps of range with the range itself */
if (r1->name != NULL && r2->name != NULL &&
strcasecmp(r1->name, r2->name) == 0) {
- return 0;
+ return RANGE_CHECK_OK;
}
/* Check if base range overlaps with existing base range.
@@ -394,7 +404,7 @@ static int check_ranges(struct range_info *r1, struct range_info *r2)
if (intervals_overlap(r1->base_id, r2->base_id,
r1->id_range_size, r2->id_range_size)){
- return 1;
+ return RANGE_CHECK_BASE_OVERLAP;
}
}
@@ -409,7 +419,7 @@ static int check_ranges(struct range_info *r1, struct range_info *r2)
/* Ranges from the same domain must have the same type */
if (strcasecmp(r1->id_range_type, r2->id_range_type) != 0) {
- return 6;
+ return RANGE_CHECK_DIFFERENT_TYPE_IN_DOMAIN;
}
/* For ipa-local or ipa-ad-trust range types primary RID ranges should
@@ -422,7 +432,7 @@ static int check_ranges(struct range_info *r1, struct range_info *r2)
if ((r1->base_rid_set && r2->base_rid_set) &&
intervals_overlap(r1->base_rid, r2->base_rid,
r1->id_range_size, r2->id_range_size))
- return 2;
+ return RANGE_CHECK_PRIMARY_PRIMARY_RID_OVERLAP;
}
/* The following 3 checks are relevant only if both ranges are local. */
@@ -433,23 +443,23 @@ static int check_ranges(struct range_info *r1, struct range_info *r2)
if ((r1->secondary_base_rid_set && r2->secondary_base_rid_set) &&
intervals_overlap(r1->secondary_base_rid, r2->secondary_base_rid,
r1->id_range_size, r2->id_range_size))
- return 3;
+ return RANGE_CHECK_SECONDARY_SECONDARY_RID_OVERLAP;
/* Check if RID range overlaps with existing secondary RID range */
if ((r1->base_rid_set && r2->secondary_base_rid_set) &&
intervals_overlap(r1->base_rid, r2->secondary_base_rid,
r1->id_range_size, r2->id_range_size))
- return 4;
+ return RANGE_CHECK_PRIMARY_SECONDARY_RID_OVERLAP;
/* Check if secondary RID range overlaps with existing RID range */
if ((r1->secondary_base_rid_set && r2->base_rid_set) &&
intervals_overlap(r1->secondary_base_rid, r2->base_rid,
r1->id_range_size, r2->id_range_size))
- return 5;
+ return RANGE_CHECK_SECONDARY_PRIMARY_RID_OVERLAP;
}
}
- return 0;
+ return RANGE_CHECK_OK;
}
static int ipa_range_check_start(Slapi_PBlock *pb)
@@ -629,26 +639,26 @@ static int ipa_range_check_pre_op(Slapi_PBlock *pb, int modtype)
ranges_valid = check_ranges(new_range, old_range);
free_range_info(old_range);
old_range = NULL;
- if (ranges_valid != 0) {
+ if (ranges_valid != RANGE_CHECK_OK) {
ret = LDAP_CONSTRAINT_VIOLATION;
switch (ranges_valid){
- case 1:
+ case RANGE_CHECK_BASE_OVERLAP:
errmsg = "New base range overlaps with existing base range.";
break;
- case 2:
+ case RANGE_CHECK_PRIMARY_PRIMARY_RID_OVERLAP:
errmsg = "New primary rid range overlaps with existing primary rid range.";
break;
- case 3:
+ case RANGE_CHECK_SECONDARY_SECONDARY_RID_OVERLAP:
errmsg = "New secondary rid range overlaps with existing secondary rid range.";
break;
- case 4:
+ case RANGE_CHECK_PRIMARY_SECONDARY_RID_OVERLAP:
errmsg = "New primary rid range overlaps with existing secondary rid range.";
break;
- case 5:
+ case RANGE_CHECK_SECONDARY_PRIMARY_RID_OVERLAP:
errmsg = "New secondary rid range overlaps with existing primary rid range.";
break;
- case 6:
+ case RANGE_CHECK_DIFFERENT_TYPE_IN_DOMAIN:
errmsg = "New ID range has invalid type. All ranges in the same domain must be of the same type.";
default:
errmsg = "New range overlaps with existing one.";