Fix bug 3931: segfault searching server with master password
authorAndrej Kacian <ticho@claws-mail.org>
Sun, 10 Dec 2017 09:49:02 +0000 (10:49 +0100)
committerRicardo Mones <ricardo@mones.org>
Sun, 10 Dec 2017 17:13:35 +0000 (18:13 +0100)
Request master passphrase earlier and inhibit search if no master
passphrase is available.

src/addressbook.c

index 5b76120237f8e54910124ba12096fb56a91631e9..fef1ee1e89283c3cdb07cac622066c72266a365b 100644 (file)
@@ -49,6 +49,7 @@
 #include "codeconv.h"
 #include "about.h"
 #include "addr_compl.h"
+#include "password.h"
 
 #include "mgutils.h"
 #include "addressitem.h"
@@ -4695,6 +4696,10 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
        AddressInterface *iface;
        gchar *searchTerm;
        GtkCMCTreeNode *node, *parentNode;
+#ifdef USE_LDAP
+       LdapServer *ldap_server;
+       LdapControl *ldap_ctl;
+#endif
 
        node = addrbook.treeSelected;
        if( ! node ) return;
@@ -4720,6 +4725,21 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
        if( ! iface->haveLibrary ) return;
        if( ! iface->externalQuery ) return;
 
+#ifdef USE_LDAP
+       if (iface->type == ADDR_IF_LDAP) {
+               ldap_server = ds->rawDataSource;
+               ldap_ctl = ldap_server->control;
+               if (ldap_ctl != NULL &&
+                               ldap_ctl->bindDN != NULL && strlen(ldap_ctl->bindDN) > 0) {
+                       /* LDAP server is password-protected. */
+                       if (master_passphrase() == NULL) {
+                               /* User did not enter master passphrase, do not start a search. */
+                               return;
+                       }
+               }
+       }
+#endif
+
        searchTerm =
                gtk_editable_get_chars( GTK_EDITABLE(addrbook.entry), 0, -1 );
        g_strchomp( searchTerm );