/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2007 Match Grun and the Claws Mail team
+ * Copyright (C) 2003-2012 Match Grun and the Claws Mail team
*
* 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
#ifdef HAVE_CONFIG_H
# include "config.h"
+#include "claws-features.h"
#endif
#ifdef USE_LDAP
#include "ldapctrl.h"
#include "mgutils.h"
+#include "passwordstore.h"
#include "editaddress_other_attributes_ldap.h"
#include "common/utils.h"
+#include "common/quoted-printable.h"
/**
* Create new LDAP control block object.
ctl->port = LDAPCTL_DFL_PORT;
ctl->baseDN = NULL;
ctl->bindDN = NULL;
- ctl->bindPass = NULL;
ctl->listCriteria = NULL;
ctl->attribEMail = g_strdup( LDAPCTL_ATTR_EMAIL );
ctl->attribCName = g_strdup( LDAPCTL_ATTR_COMMONNAME );
*/
void ldapctl_set_host( LdapControl* ctl, const gchar *value ) {
ctl->hostName = mgu_replace_string( ctl->hostName, value );
+
+ if ( ctl->hostName == NULL )
+ return;
+
g_strstrip( ctl->hostName );
debug_print("setting hostname: %s\n", ctl->hostName);
}
*/
void ldapctl_set_base_dn( LdapControl* ctl, const gchar *value ) {
ctl->baseDN = mgu_replace_string( ctl->baseDN, value );
+
+ if ( ctl->baseDN == NULL )
+ return;
+
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 );
+
+ if ( ctl->bindDN == NULL )
+ return;
+
g_strstrip( ctl->bindDN );
debug_print("setting bindDN: %s\n", ctl->bindDN);
}
-/**
- * Specify bind password to be used.
- * \param ctl Control object to process.
- * \param value Password.
- */
-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");
-}
-
/**
* Specify maximum number of entries to retrieve.
* \param ctl Control object to process.
* \param value <i>TRUE</i> to enable TLS.
*/
void ldapctl_set_tls( LdapControl* ctl, const gboolean value ) {
+#if (defined USE_LDAP_TLS || defined G_OS_WIN32)
ctl->enableTLS = value;
- debug_print("setting TLS: %d\n", ctl->enableTLS);
+ debug_print("setting STARTTLS: %d\n", ctl->enableTLS);
+#endif
}
void ldapctl_set_ssl( LdapControl* ctl, const gboolean value ) {
+#if (defined USE_LDAP_TLS || defined G_OS_WIN32)
ctl->enableSSL = value;
- debug_print("setting SSL: %d\n", ctl->enableSSL);
+ debug_print("setting SSL/TLS: %d\n", ctl->enableSSL);
+#endif
}
/**
* <code>ldapctl_criteria_list_add()</code> functions for this purpose.
*/
GList *ldapctl_get_criteria_list( const LdapControl* ctl ) {
- g_return_val_if_fail( ctl != NULL, NULL );
+ cm_return_val_if_fail( ctl != NULL, NULL );
return ctl->listCriteria;
}
* \param ctl Control data object.
*/
void ldapctl_criteria_list_clear( LdapControl *ctl ) {
- g_return_if_fail( ctl != NULL );
+ cm_return_if_fail( ctl != NULL );
mgu_free_dlist( ctl->listCriteria );
ctl->listCriteria = NULL;
}
* be appended to the list.
*/
void ldapctl_criteria_list_add( LdapControl *ctl, gchar *attr ) {
- g_return_if_fail( ctl != NULL );
+ cm_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);
* \param ctl Control object to clear.
*/
static void ldapctl_clear( LdapControl *ctl ) {
- g_return_if_fail( ctl != NULL );
+ cm_return_if_fail( ctl != NULL );
debug_print("clearing ldap controller members\n");
/* Free internal stuff */
g_free( ctl->hostName );
g_free( ctl->baseDN );
g_free( ctl->bindDN );
- g_free( ctl->bindPass );
g_free( ctl->attribEMail );
g_free( ctl->attribCName );
g_free( ctl->attribFName );
ctl->port = 0;
ctl->baseDN = NULL;
ctl->bindDN = NULL;
- ctl->bindPass = NULL;
ctl->attribEMail = NULL;
ctl->attribCName = NULL;
ctl->attribFName = NULL;
* \param ctl Control object to free.
*/
void ldapctl_free( LdapControl *ctl ) {
- g_return_if_fail( ctl != NULL );
+ cm_return_if_fail( ctl != NULL );
debug_print("releasing requested memory for ldap controller\n");
/* Free internal stuff */
* \param stream Output stream.
*/
void ldapctl_print( const LdapControl *ctl, FILE *stream ) {
- g_return_if_fail( ctl != NULL );
+ cm_return_if_fail( ctl != NULL );
+ gchar *pwd;
pthread_mutex_lock( ctl->mutexCtl );
fprintf( stream, "LdapControl:\n" );
- fprintf( stream, "host name: '%s'\n", ctl->hostName );
+ fprintf( stream, "host name: '%s'\n", ctl->hostName?ctl->hostName:"null" );
fprintf( stream, " port: %d\n", ctl->port );
- fprintf( stream, " base dn: '%s'\n", ctl->baseDN );
- fprintf( stream, " bind dn: '%s'\n", ctl->bindDN );
- fprintf( stream, "bind pass: '%s'\n", ctl->bindPass );
- fprintf( stream, "attr mail: '%s'\n", ctl->attribEMail );
- fprintf( stream, "attr comn: '%s'\n", ctl->attribCName );
- fprintf( stream, "attr frst: '%s'\n", ctl->attribFName );
- fprintf( stream, "attr last: '%s'\n", ctl->attribLName );
- fprintf( stream, "attr disn: '%s'\n", ctl->attribDName );
+ fprintf( stream, " base dn: '%s'\n", ctl->baseDN?ctl->baseDN:"null" );
+ fprintf( stream, " bind dn: '%s'\n", ctl->bindDN?ctl->bindDN:"null" );
+ pwd = passwd_store_get(PWS_CORE, "LDAP", ctl->hostName);
+ fprintf( stream, "bind pass: '%s'\n", pwd?pwd:"null" );
+ if (pwd != NULL && strlen(pwd) > 0)
+ memset(pwd, 0, strlen(pwd));
+ g_free(pwd);
+ fprintf( stream, "attr mail: '%s'\n", ctl->attribEMail?ctl->attribEMail:"null" );
+ fprintf( stream, "attr comn: '%s'\n", ctl->attribCName?ctl->attribCName:"null" );
+ fprintf( stream, "attr frst: '%s'\n", ctl->attribFName?ctl->attribFName:"null" );
+ fprintf( stream, "attr last: '%s'\n", ctl->attribLName?ctl->attribLName:"null" );
+ fprintf( stream, "attr disn: '%s'\n", ctl->attribDName?ctl->attribDName:"null" );
fprintf( stream, "max entry: %d\n", ctl->maxEntries );
fprintf( stream, " timeout: %d\n", ctl->timeOut );
fprintf( stream, " max age: %d\n", ctl->maxQueryAge );
fprintf( stream, "match opt: %d\n", ctl->matchingOption );
fprintf( stream, " version: %d\n", ctl->version );
- fprintf( stream, " TLS: %s\n", ctl->enableTLS ? "yes" : "no" );
- fprintf( stream, " SSL: %s\n", ctl->enableSSL ? "yes" : "no" );
+ fprintf( stream, " STARTTLS: %s\n", ctl->enableTLS ? "yes" : "no" );
+ fprintf( stream, " SSL/TLS: %s\n", ctl->enableSSL ? "yes" : "no" );
fprintf( stream, "crit list:\n" );
if( ctl->listCriteria ) {
mgu_print_dlist( ctl->listCriteria, stream );
void ldapctl_copy( const LdapControl *ctlFrom, LdapControl *ctlTo ) {
GList *node;
- g_return_if_fail( ctlFrom != NULL );
- g_return_if_fail( ctlTo != NULL );
+ cm_return_if_fail( ctlFrom != NULL );
+ cm_return_if_fail( ctlTo != NULL );
debug_print("ldap controller copy\n");
/* Lock both objects */
ctlTo->hostName = g_strdup( ctlFrom->hostName );
ctlTo->baseDN = g_strdup( ctlFrom->baseDN );
ctlTo->bindDN = g_strdup( ctlFrom->bindDN );
- ctlTo->bindPass = g_strdup( ctlFrom->bindPass );
ctlTo->attribEMail = g_strdup( ctlFrom->attribEMail );
ctlTo->attribCName = g_strdup( ctlFrom->attribCName );
ctlTo->attribFName = g_strdup( ctlFrom->attribFName );
g_free( p2 );
}
g_free( term );
- debug_print("search criteria: %s\n", crit);
+ debug_print("search criteria: %s\n", crit?crit:"null");
return crit;
}
gchar *p1, *p2, *retVal;
gchar *criteriaFmt;
- g_return_val_if_fail( ctl != NULL, NULL );
- g_return_val_if_fail( searchVal != NULL, NULL );
+ cm_return_val_if_fail( ctl != NULL, NULL );
+ cm_return_val_if_fail( searchVal != NULL, NULL );
/* Test whether there are more that one search terms */
retVal = ldapctl_build_ldap_criteria( searchVal, ctl->matchingOption );
/* Subsequent time through */
gchar *crit;
- /* Format query criteria */
- crit = g_strdup_printf( criteriaFmt, attr, searchVal );
+ debug_print("crit: %s\n", searchVal);
+ /* fix bug when doing a search any */
+ if (strcmp("*@", searchVal) == 0) {
+ crit = g_strdup_printf( "(%s=*)", attr );
+ }
+ else {
+ /* Format query criteria */
+ crit = g_strdup_printf( criteriaFmt, attr, searchVal );
+ }
/* Append to existing criteria */
g_free( p2 );
}
else {
/* First time through - Format query criteria */
- p2 = g_strdup_printf( criteriaFmt, attr, searchVal );
+ /* fix bug when doing a search any */
+ if (strcmp("*@", searchVal) == 0) {
+ p2 = g_strdup_printf( "(%s=*)", attr );
+ }
+ else {
+ p2 = g_strdup_printf( criteriaFmt, attr, searchVal );
+ }
}
}
* \return NULL terminated list.
*/
char **ldapctl_attribute_array( LdapControl *ctl ) {
+ char **ptrArray;
+ GList *node;
+ gint cnt, i;
+ cm_return_val_if_fail( ctl != NULL, NULL );
+
+ node = ctl->listCriteria;
+ cnt = g_list_length( ctl->listCriteria );
+ ptrArray = g_new0( char *, 1 + cnt );
+ i = 0;
+ 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 ptrArray;
+}
+
+/**
+ * Return array of pointers to attributes for LDAP query.
+ * \param ctl Control object to process.
+ * \return NULL terminated list.
+ */
+char **ldapctl_full_attribute_array( LdapControl *ctl ) {
char **ptrArray;
GList *node, *def;
+ GList *tmp = NULL;
gint cnt, i;
- g_return_val_if_fail( ctl != NULL, NULL );
+ cm_return_val_if_fail( ctl != NULL, NULL );
+
+ def = ctl->listCriteria;
+ while (def) {
+ tmp = g_list_append(tmp, g_strdup(def->data));
+ def = def->next;
+ }
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 = def;
+
+ while (node) {
+ if( g_list_find_custom(tmp, (gpointer)def->data,
+ (GCompareFunc)strcmp2) == NULL) {
+ tmp = g_list_append(tmp, g_strdup(node->data));
}
+ node = node->next;
}
- node = ctl->listCriteria;
- cnt = g_list_length( ctl->listCriteria );
- ptrArray = g_new0( char *, 1 + cnt );
+
+ g_list_free_full(def, g_free);
+
+ node = tmp;
+ cnt = g_list_length( tmp );
+ ptrArray = g_new0( char *, 1 + cnt);
i = 0;
while( node ) {
ptrArray[ i++ ] = node->data;
/* Clear array to NULL's */
for( i = 0; ptrArray[i] != NULL; i++ ) {
+ g_free(ptrArray[i]);
ptrArray[i] = NULL;
}
g_free( ptrArray );
gchar *attrib;
gint iLen;
- g_return_if_fail( ctl != NULL );
+ cm_return_if_fail( ctl != NULL );
ldapctl_criteria_list_clear( ctl );
if( criteria == NULL ) return;
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);
+ attr_list = g_list_append(attr_list, item);
}
g_strfreev(c_list);
return attr_list;