From 8b3ff6f2a6727f87e74bf3c51be49e9abfa1e198 Mon Sep 17 00:00:00 2001 From: "David M. Syzdek" Date: Thu, 26 Jan 2023 00:46:06 -0900 Subject: ldapinfo: re-ordering functions --- src/ldapinfo.c | 126 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/src/ldapinfo.c b/src/ldapinfo.c index 0f68404..3eba31c 100644 --- a/src/ldapinfo.c +++ b/src/ldapinfo.c @@ -642,15 +642,16 @@ int my_monitor_database(MyConfig * cnf, const char * base) } -int my_monitor_operations(MyConfig * cnf, const char * base) +int my_monitor_listeners(MyConfig * cnf, const char * base) { int rc; int err; int msgid; int count; - char ** cn; - char ** initiated; - char ** completed; + char * uri; + char ** uris; + char * addr; + char ** addrs; char dn[256]; char buff[256]; LDAP * ld; @@ -663,7 +664,7 @@ int my_monitor_operations(MyConfig * cnf, const char * base) // searches for cn=Connections, timeout.tv_sec = 5; timeout.tv_usec = 0; - strncpy(dn, "cn=Operations,", sizeof(dn)); + strncpy(dn, "cn=Listeners,", sizeof(dn)); strncat(dn, base, (sizeof(dn)-strlen(dn)-1)); if ((err = ldap_search_ext(ld, dn, LDAP_SCOPE_ONE, "(objectclass=*)", cnf->lud->attrs, 0, NULL, NULL, &timeout, -1, &msgid)) != LDAP_SUCCESS) return(-1); @@ -683,58 +684,56 @@ int my_monitor_operations(MyConfig * cnf, const char * base) msg = ldap_first_entry(ld, res); while ((msg)) { - if ((cn = ldap_get_values(ld, msg, "cn")) == NULL) + if ((uris = ldap_get_values(ld, msg, "labeledURI")) == NULL) { msg = ldap_next_entry(ld, msg); continue; }; - if (!(cn[0][0])) + if (!(uris[0][0])) { - ldap_value_free(cn); + ldap_value_free(uris); msg = ldap_next_entry(ld, msg); continue; }; - if ((initiated = ldap_get_values(ld, msg, "monitorOpInitiated")) == NULL) + if ((addrs = ldap_get_values(ld, msg, "monitorConnectionLocalAddress")) == NULL) { - ldap_value_free(cn); + ldap_value_free(uris); msg = ldap_next_entry(ld, msg); continue; }; - if (!(initiated[0][0])) + if (!(addrs[0][0])) { - ldap_value_free(cn); - ldap_value_free(initiated); + ldap_value_free(addrs); + ldap_value_free(uris); msg = ldap_next_entry(ld, msg); continue; }; - if ((completed = ldap_get_values(ld, msg, "monitorOpCompleted")) == NULL) + if ((addr = rindex(addrs[0], '=')) == NULL) { - ldap_value_free(cn); - ldap_value_free(initiated); + ldap_value_free(addrs); + ldap_value_free(uris); msg = ldap_next_entry(ld, msg); continue; }; - if (!(completed[0][0])) + addr++; + uri = index(uris[0], '/'); + if ((uri != NULL)) + uri = &uri[2]; + if ((uri)) { - ldap_value_free(cn); - ldap_value_free(completed); - ldap_value_free(initiated); - msg = ldap_next_entry(ld, msg); - continue; + uri[0] = '\0'; + snprintf(buff, sizeof(buff), "%s%s", uris[0], addr); + if (!(count)) + my_field("Listeners:", buff, 0); + else + my_field(NULL, buff, 0); + count++; }; - snprintf(buff, sizeof(buff), "%s initiated: %s; completed %s", cn[0], initiated[0], completed[0]); - if (!(count)) - my_field("Operations:", buff, 0); - else - my_field(NULL, buff, 0); - count++; - - ldap_value_free(cn); - ldap_value_free(initiated); - ldap_value_free(completed); + ldap_value_free(addrs); + ldap_value_free(uris); // retrieves next entry msg = ldap_next_entry(ld, msg); @@ -746,16 +745,15 @@ int my_monitor_operations(MyConfig * cnf, const char * base) } -int my_monitor_listeners(MyConfig * cnf, const char * base) +int my_monitor_operations(MyConfig * cnf, const char * base) { int rc; int err; int msgid; int count; - char * uri; - char ** uris; - char * addr; - char ** addrs; + char ** cn; + char ** initiated; + char ** completed; char dn[256]; char buff[256]; LDAP * ld; @@ -768,7 +766,7 @@ int my_monitor_listeners(MyConfig * cnf, const char * base) // searches for cn=Connections, timeout.tv_sec = 5; timeout.tv_usec = 0; - strncpy(dn, "cn=Listeners,", sizeof(dn)); + strncpy(dn, "cn=Operations,", sizeof(dn)); strncat(dn, base, (sizeof(dn)-strlen(dn)-1)); if ((err = ldap_search_ext(ld, dn, LDAP_SCOPE_ONE, "(objectclass=*)", cnf->lud->attrs, 0, NULL, NULL, &timeout, -1, &msgid)) != LDAP_SUCCESS) return(-1); @@ -788,56 +786,58 @@ int my_monitor_listeners(MyConfig * cnf, const char * base) msg = ldap_first_entry(ld, res); while ((msg)) { - if ((uris = ldap_get_values(ld, msg, "labeledURI")) == NULL) + if ((cn = ldap_get_values(ld, msg, "cn")) == NULL) { msg = ldap_next_entry(ld, msg); continue; }; - if (!(uris[0][0])) + if (!(cn[0][0])) { - ldap_value_free(uris); + ldap_value_free(cn); msg = ldap_next_entry(ld, msg); continue; }; - if ((addrs = ldap_get_values(ld, msg, "monitorConnectionLocalAddress")) == NULL) + if ((initiated = ldap_get_values(ld, msg, "monitorOpInitiated")) == NULL) { - ldap_value_free(uris); + ldap_value_free(cn); msg = ldap_next_entry(ld, msg); continue; }; - if (!(addrs[0][0])) + if (!(initiated[0][0])) { - ldap_value_free(addrs); - ldap_value_free(uris); + ldap_value_free(cn); + ldap_value_free(initiated); msg = ldap_next_entry(ld, msg); continue; }; - if ((addr = rindex(addrs[0], '=')) == NULL) + if ((completed = ldap_get_values(ld, msg, "monitorOpCompleted")) == NULL) { - ldap_value_free(addrs); - ldap_value_free(uris); + ldap_value_free(cn); + ldap_value_free(initiated); msg = ldap_next_entry(ld, msg); continue; }; - addr++; - uri = index(uris[0], '/'); - if ((uri != NULL)) - uri = &uri[2]; - if ((uri)) + if (!(completed[0][0])) { - uri[0] = '\0'; - snprintf(buff, sizeof(buff), "%s%s", uris[0], addr); - if (!(count)) - my_field("Listeners:", buff, 0); - else - my_field(NULL, buff, 0); - count++; + ldap_value_free(cn); + ldap_value_free(completed); + ldap_value_free(initiated); + msg = ldap_next_entry(ld, msg); + continue; }; - ldap_value_free(addrs); - ldap_value_free(uris); + snprintf(buff, sizeof(buff), "%s initiated: %s; completed %s", cn[0], initiated[0], completed[0]); + if (!(count)) + my_field("Operations:", buff, 0); + else + my_field(NULL, buff, 0); + count++; + + ldap_value_free(cn); + ldap_value_free(initiated); + ldap_value_free(completed); // retrieves next entry msg = ldap_next_entry(ld, msg); -- cgit v1.2.3