From 3f65f687e5a6137e70c680dfaea7ab3b736b4c4f Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Sat, 6 Mar 1999 18:31:19 +0000 Subject: [PATCH] Put the ATTR_BOOL option numbers in attrs.offset instead of attrs.data, to avoid unportable casts of integers to pointers and back. --- libraries/libldap/init.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index ae298ff23d..8e31c25b0b 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -59,9 +59,9 @@ static struct ol_attribute { offsetof(struct ldapoptions, ldo_defhost)}, {ATTR_INT, "PORT", NULL, offsetof(struct ldapoptions, ldo_defport)}, - {ATTR_BOOL, "REFERRALS", (void *) LDAP_BOOL_REFERRALS, 0}, - {ATTR_BOOL, "RESTART", (void *) LDAP_BOOL_RESTART, 0}, - {ATTR_BOOL, "DNS", (void *) LDAP_BOOL_DNS, 0}, + {ATTR_BOOL, "REFERRALS", NULL, LDAP_BOOL_REFERRALS}, + {ATTR_BOOL, "RESTART", NULL, LDAP_BOOL_RESTART}, + {ATTR_BOOL, "DNS", NULL, LDAP_BOOL_DNS}, {ATTR_NONE, NULL, NULL, 0} }; @@ -130,23 +130,22 @@ static void openldap_ldap_init_w_conf(const char *file) continue; } - p = &((char *) &gopts)[attrs[i].offset]; - switch(attrs[i].type) { case ATTR_BOOL: if((strcasecmp(opt, "on") == 0) || (strcasecmp(opt, "yes") == 0) || (strcasecmp(opt, "true") == 0)) { - LDAP_BOOL_SET(&gopts, (int) attrs[i].data); + LDAP_BOOL_SET(&gopts, attrs[i].offset); } else { - LDAP_BOOL_CLR(&gopts, (int) attrs[i].data); + LDAP_BOOL_CLR(&gopts, attrs[i].offset); } break; case ATTR_INT: + p = &((char *) &gopts)[attrs[i].offset]; * (int*) p = atoi(opt); break; @@ -158,6 +157,7 @@ static void openldap_ldap_init_w_conf(const char *file) kv++) { if(strcasecmp(opt, kv->key) == 0) { + p = &((char *) &gopts)[attrs[i].offset]; * (int*) p = kv->value; break; } @@ -165,6 +165,7 @@ static void openldap_ldap_init_w_conf(const char *file) } break; case ATTR_STRING: + p = &((char *) &gopts)[attrs[i].offset]; if (* (char**) p != NULL) free(* (char**) p); * (char**) p = strdup(opt); break; @@ -235,22 +236,21 @@ static void openldap_ldap_init_w_env(const char *prefix) continue; } - p = &((char *) &gopts)[attrs[i].offset]; - switch(attrs[i].type) { case ATTR_BOOL: if((strcasecmp(value, "on") == 0) || (strcasecmp(value, "yes") == 0) || (strcasecmp(value, "true") == 0)) { - LDAP_BOOL_SET(&gopts, (int) attrs[i].data); + LDAP_BOOL_SET(&gopts, attrs[i].offset); } else { - LDAP_BOOL_CLR(&gopts, (int) attrs[i].data); + LDAP_BOOL_CLR(&gopts, attrs[i].offset); } break; case ATTR_INT: + p = &((char *) &gopts)[attrs[i].offset]; * (int*) p = atoi(value); break; @@ -262,6 +262,7 @@ static void openldap_ldap_init_w_env(const char *prefix) kv++) { if(strcasecmp(value, kv->key) == 0) { + p = &((char *) &gopts)[attrs[i].offset]; * (int*) p = kv->value; break; } @@ -269,6 +270,7 @@ static void openldap_ldap_init_w_env(const char *prefix) } break; case ATTR_STRING: + p = &((char *) &gopts)[attrs[i].offset]; if (* (char**) p != NULL) free(* (char**) p); if (*value == '\0') { * (char**) p = NULL; -- 2.39.5