Fix bug 3793: segfault when autocompletion asks for master passphrase
[claws.git] / src / addrindex.c
index da431b92ddc1eb7eb007ff0509d3a459e6976a1f..282281f6224b2b9c33663124965000868222177f 100644 (file)
@@ -42,6 +42,7 @@
 #include "addr_compl.h"
 #include "utils.h"
 #include "alertpanel.h"
+#include "passwordstore.h"
 
 #ifndef DEV_STANDALONE
 #include "prefs_gtk.h"
@@ -1321,7 +1322,6 @@ static void addrindex_parse_ldap_attrlist( XMLFile *file, LdapControl *ctl ) {
                                break;
                        }
                }
-               xtag = xtagPrev;
        }
 
        /* Build list of search attributes */
@@ -1354,6 +1354,7 @@ static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
        gboolean bDynSearch;
        gboolean bTLS, bSSL;
        gint iMatch;
+       gchar *password = NULL;
 
        /* g_print( "addrindex_parse_ldap\n" ); */
        /* Set up some defaults */
@@ -1387,7 +1388,7 @@ static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
                        ldapctl_set_bind_dn( ctl, value );
                }
                else if( strcmp( name, ATTAG_LDAP_BIND_PASS ) == 0 ) {
-                       ldapctl_set_bind_password( ctl, value, FALSE, FALSE );
+                       password = value;
                }
                else if( strcmp( name, ATTAG_LDAP_CRITERIA ) == 0 ) {
                        g_free( criteria );
@@ -1430,6 +1431,9 @@ static AddressDataSource *addrindex_parse_ldap( XMLFile *file ) {
                attr = g_list_next( attr );
        }
 
+       if (password != NULL)
+               passwd_store_set(PWS_CORE, "LDAP", ctl->hostName, password, TRUE);
+
        server = ldapsvr_create_noctl();
        ldapsvr_set_name( server, serverName );
        ldapsvr_set_search_flag( server, bDynSearch );
@@ -1484,8 +1488,6 @@ static int addrindex_write_ldap( FILE *fp, AddressDataSource *ds, gint lvl ) {
                return -1;
        if (addrindex_write_attr( fp, ATTAG_LDAP_BIND_DN, ctl->bindDN ) < 0)
                return -1;
-       if (addrindex_write_attr( fp, ATTAG_LDAP_BIND_PASS, ctl->bindPass ) < 0)
-               return -1;
 
        sprintf( value, "%d", ctl->maxEntries );
        if (addrindex_write_attr( fp, ATTAG_LDAP_MAX_ENTRY, value ) < 0)
@@ -1791,7 +1793,7 @@ static gint addrindex_write_to( AddressIndex *addrIndex, const gchar *newFile )
        fileSpec = NULL;
        return addrIndex->retVal;
 fail:
-       g_warning("error writing AB index\n");
+       g_warning("error writing AB index");
        addrIndex->retVal = MGU_ERROR_WRITE;
        if (pfile)
                prefs_file_close_revert( pfile );
@@ -2004,8 +2006,7 @@ static void addrindex_add_obj( XMLFile *file, AddressCvtNode *node ) {
                        node->list = g_list_append( node->list, newNode );
                }
                else {
-                       /* g_print( "invalid: !!! \n" ); */
-                       attr = xml_get_current_tag_attr( file );
+                       g_warning("Invalid tag");
                }
        }
 }
@@ -2919,7 +2920,7 @@ gboolean addrindex_load_completion(
                   folderpath must not be empty or NULL */
                
                if( ! addressbook_peek_folder_exists( folderpath, &book, &folder ) ) {
-                       g_warning("addrindex_load_completion: folder path '%s' doesn't exist\n", folderpath);
+                       g_warning("addrindex_load_completion: folder path '%s' doesn't exist", folderpath);
                        return FALSE;
                }
 
@@ -2973,7 +2974,7 @@ gboolean addrindex_load_completion(
                                return TRUE;
 
                        } else {
-                               g_warning("addrindex_load_completion: book/folder path is valid but got no pointer\n");
+                               g_warning("addrindex_load_completion: book/folder path is valid but got no pointer");
                        }
                }
                return FALSE;
@@ -3199,6 +3200,52 @@ gchar *addrindex_get_picture_file(const gchar *emailaddr)
        return filename;
 }
 
+#ifdef USE_LDAP
+GSList *addrindex_get_password_protected_ldap_servers()
+{
+       AddressInterface *iface;
+       AddressDataSource *ds;
+       GList *nodeIf;
+       GList *nodeDS;
+       GSList *list = NULL;
+       LdapServer *server;
+       LdapControl *ctl;
+
+       nodeIf = _addressIndex_->searchOrder;
+       while (nodeIf) {
+               iface = nodeIf->data;
+               nodeIf = g_list_next(nodeIf);
+
+               if (!iface->useInterface)
+                       continue;
+               if (!iface->externalQuery)
+                       continue;
+               if (iface->type != ADDR_IF_LDAP)
+                       continue;
+
+               nodeDS = iface->listSource;
+               while (nodeDS) {
+                       ds = nodeDS->data;
+                       nodeDS = g_list_next(nodeDS);
+                       server = ds->rawDataSource;
+                       if (!server->searchFlag)
+                               continue;
+
+                       ctl = server->control;
+
+                       if (!ctl)
+                               continue;
+
+                       if (ctl->bindDN != NULL && strlen(ctl->bindDN)) {
+                               list = g_slist_append(list, server);
+                       }
+               }
+       }
+
+       return list;
+}
+#endif /* USE_LDAP */
+
 /*
  * End of Source.
  */