*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*/
/*
#include "ldapctrl.h"
#include "mgutils.h"
+#include "editaddress_other_attributes_ldap.h"
+#include "common/utils.h"
/**
* Create new LDAP control block object.
void ldapctl_set_host( LdapControl* ctl, const gchar *value ) {
ctl->hostName = mgu_replace_string( ctl->hostName, value );
g_strstrip( ctl->hostName );
+ debug_print("setting hostname: %s\n", ctl->hostName);
}
/**
else {
ctl->port = LDAPCTL_DFL_PORT;
}
+ debug_print("setting port: %d\n", ctl->port);
}
/**
void ldapctl_set_base_dn( LdapControl* ctl, const gchar *value ) {
ctl->baseDN = mgu_replace_string( ctl->baseDN, value );
g_strstrip( ctl->baseDN );
+ debug_print("setting baseDN: %s\n", ctl->baseDN);
}
/**
void ldapctl_set_bind_dn( LdapControl* ctl, const gchar *value ) {
ctl->bindDN = mgu_replace_string( ctl->bindDN, value );
g_strstrip( ctl->bindDN );
+ debug_print("setting bindDN: %s\n", ctl->bindDN);
}
/**
void ldapctl_set_bind_password( LdapControl* ctl, const gchar *value ) {
ctl->bindPass = mgu_replace_string( ctl->bindPass, value );
g_strstrip( ctl->bindPass );
+ debug_print("setting bindPassword");
}
/**
else {
ctl->maxEntries = LDAPCTL_MAX_ENTRIES;
}
+ debug_print("setting maxEntries: %d\n", ctl->maxEntries);
}
/**
else {
ctl->timeOut = LDAPCTL_DFL_TIMEOUT;
}
+ debug_print("setting timeOut: %d\n", ctl->timeOut);
}
/**
else {
ctl->maxQueryAge = value;
}
+ debug_print("setting maxAge: %d\n", ctl->maxQueryAge);
}
/**
else {
ctl->matchingOption = value;
}
+ debug_print("setting matchingOption: %d\n", ctl->matchingOption);
}
/**
*/
void ldapctl_set_tls( LdapControl* ctl, const gboolean value ) {
ctl->enableTLS = value;
+ debug_print("setting TLS: %d\n", ctl->enableTLS);
}
void ldapctl_set_ssl( LdapControl* ctl, const gboolean value ) {
ctl->enableSSL = value;
+ debug_print("setting SSL: %d\n", ctl->enableSSL);
}
/**
g_return_if_fail( ctl != NULL );
if( attr != NULL ) {
if( mgu_list_test_unq_nc( ctl->listCriteria, attr ) ) {
+ debug_print("adding to criteria list: %s\n", attr);
ctl->listCriteria = g_list_append(
ctl->listCriteria, g_strdup( attr ) );
}
static void ldapctl_clear( LdapControl *ctl ) {
g_return_if_fail( ctl != NULL );
+ debug_print("clearing ldap controller members\n");
/* Free internal stuff */
g_free( ctl->hostName );
g_free( ctl->baseDN );
void ldapctl_free( LdapControl *ctl ) {
g_return_if_fail( ctl != NULL );
+ debug_print("releasing requested memory for ldap controller\n");
/* Free internal stuff */
ldapctl_clear( ctl );
g_return_if_fail( ctlFrom != NULL );
g_return_if_fail( ctlTo != NULL );
+ debug_print("ldap controller copy\n");
/* Lock both objects */
pthread_mutex_lock( ctlFrom->mutexCtl );
pthread_mutex_lock( ctlTo->mutexCtl );
g_free( p2 );
}
g_free( term );
+ debug_print("search criteria: %s\n", crit);
return crit;
}
node = ctl->listCriteria;
while( node ) {
gchar *attr, *tmp;
-
attr = node->data;
node = g_list_next( node );
retVal = p2;
g_free( p1 );
}
+ debug_print("current search string: %s\n", retVal);
return retVal;
}
*/
char **ldapctl_attribute_array( LdapControl *ctl ) {
char **ptrArray;
- GList *node;
+ GList *node, *def;
gint cnt, i;
g_return_val_if_fail( ctl != NULL, NULL );
+ def = ldapctl_get_default_criteria_list();
+ /* check if this servers config is updated to the new
+ * default list of search criteria. If not update the list */
+ if (! ldapctl_compare_list(ctl->listCriteria, def)) {
+ /* Deep copy search criteria */
+ ldapctl_criteria_list_clear(ctl);
+ while(def) {
+ ctl->listCriteria = g_list_append(
+ ctl->listCriteria, g_strdup(def->data));
+ def = g_list_next(def);
+ }
+ }
+ node = ctl->listCriteria;
cnt = g_list_length( ctl->listCriteria );
ptrArray = g_new0( char *, 1 + cnt );
i = 0;
- node = ctl->listCriteria;
while( node ) {
ptrArray[ i++ ] = node->data;
+ /*debug_print("adding search attribute: %s\n", (gchar *) node->data);*/
node = g_list_next( node );
}
ptrArray[ i ] = NULL;
}
}
+/**
+ * Return the default LDAP search criteria string.
+ * \return Formatted string or <i>""</i>. Should be g_free() when done.
+ */
+gchar *ldapctl_get_default_criteria() {
+ gchar *retVal = g_strdup(LDAPCTL_DFL_ATTR_LIST);
+ const gchar **attrs = ATTRIBUTE;
+
+ while (*attrs) {
+ gchar *tmp = g_strdup_printf("%s, %s", retVal, *attrs++);
+ g_free(retVal);
+ retVal = tmp;
+ }
+ debug_print("default search criteria: %s\n", retVal);
+ return retVal;
+}
+
+/**
+ * Return the default LDAP search criteria list.
+ * \return GList or <i>NULL</i>.
+ */
+GList *ldapctl_get_default_criteria_list() {
+ gchar *criteria, *item;
+ gchar **c_list, **w_list;
+ GList *attr_list = NULL;
+
+ criteria = ldapctl_get_default_criteria();
+ c_list = g_strsplit(criteria, " ", 0);
+ g_free(criteria);
+ criteria = NULL;
+ w_list = c_list;
+ while ((criteria = *w_list++) != 0) {
+ /* copy string elimination <,> */
+ if (*w_list)
+ item = g_strndup(criteria, strlen(criteria) - 1);
+ else
+ item = g_strdup(criteria);
+ debug_print("adding attribute to list: %s\n", item);
+ attr_list = g_list_append(attr_list, g_strdup(item));
+ g_free(item);
+ }
+ g_strfreev(c_list);
+ return attr_list;
+}
+
+/**
+ * Compare to GList for equality.
+ * \param l1 First GList
+ * \param l2 Second GList
+ * \Return TRUE or FALSE
+ */
+gboolean ldapctl_compare_list(GList *l1, GList *l2) {
+ gchar *first, *second;
+ if (! l1 && ! l2)
+ return TRUE;
+ if ((! l1 && l2) || (l1 && ! l2))
+ return FALSE;
+ while (l1 && l2) {
+ first = (gchar *) l1->data;
+ second = (gchar *) l2->data;
+ /*debug_print("comparing: %s = %s\n", first, second);*/
+ if ( ! (first && second) || strcmp(first, second) != 0) {
+ return FALSE;
+ }
+ l1 = g_list_next(l1);
+ l2 = g_list_next(l2);
+ }
+ return TRUE;
+}
+
#endif /* USE_LDAP */
/*