2010-02-03 [mir] 3.7.5cvs5
authorMichael Rasmussen <mir@datanom.net>
Wed, 3 Feb 2010 16:58:03 +0000 (16:58 +0000)
committerMichael Rasmussen <mir@datanom.net>
Wed, 3 Feb 2010 16:58:03 +0000 (16:58 +0000)
* src/addrindex.c
* src/editldap.c
* src/ldapctrl.c
* src/ldapctrl.h
* src/ldapquery.c
* src/ldapupdate.c
    Save LDAP password encrypted. See bug 2113.

ChangeLog
PATCHSETS
configure.ac
src/addrindex.c
src/editldap.c
src/ldapctrl.c
src/ldapctrl.h
src/ldapquery.c
src/ldapupdate.c

index e8f46a7f2ac9563d251476256ce764a002068a87..2ef5b0157958db35ff5a37be92cd9457493dfbb1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-02-03 [mir]       3.7.5cvs5
+
+       * src/addrindex.c
+       * src/editldap.c
+       * src/ldapctrl.c
+       * src/ldapctrl.h
+       * src/ldapquery.c
+       * src/ldapupdate.c
+           Save LDAP password encrypted. See bug 2113.
+
+
 2010-02-03 [colin]     3.7.5cvs4
 
        * src/privacy.c
index 96c8373267038c96580aea6985013a33a310b419..eb5a5eded0906dce742609c37219f1b8ee5d80e8 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.1.2.63 -r 1.1.2.64 src/gtk/authors.h;  ) > 3.7.5cvs2.patchset
 ( cvs diff -u -r 1.1.2.7 -r 1.1.2.8 src/plugins/smime/smime.c;  cvs diff -u -r 1.10.2.23 -r 1.10.2.24 src/privacy.c;  ) > 3.7.5cvs3.patchset
 ( cvs diff -u -r 1.10.2.24 -r 1.10.2.25 src/privacy.c;  ) > 3.7.5cvs4.patchset
+( cvs diff -u -r 1.28.2.42 -r 1.28.2.43 src/addrindex.c;  cvs diff -u -r 1.8.2.36 -r 1.8.2.37 src/editldap.c;  cvs diff -u -r 1.2.2.19 -r 1.2.2.20 src/ldapctrl.c;  cvs diff -u -r 1.1.4.14 -r 1.1.4.15 src/ldapctrl.h;  cvs diff -u -r 1.3.2.33 -r 1.3.2.34 src/ldapquery.c;  cvs diff -u -r 1.1.2.23 -r 1.1.2.24 src/ldapupdate.c;  ) > 3.7.5cvs5.patchset
index f2e3cc7d67d2898434feaa9ad95e9bd807992d9d..022d0ed7f4ba221467dd6e3a9ed11095b1084f2f 100644 (file)
@@ -12,7 +12,7 @@ MINOR_VERSION=7
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=4
+EXTRA_VERSION=5
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index a6e0de58cbe21d6464d39242cab57d3907a09fe9..30a46f424da9616e3c88afad08370adbd6e334ef 100644 (file)
@@ -1382,7 +1382,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 );
+                       ldapctl_set_bind_password( ctl, value, FALSE, FALSE );
                }
                else if( strcmp( name, ATTAG_LDAP_CRITERIA ) == 0 ) {
                        g_free( criteria );
index 0b223013f0d727a36be77ce1ee7522bc1f3a0c7a..13096adabc38cba0be1faede018758eb535b2bc0 100644 (file)
@@ -892,6 +892,7 @@ static void edit_ldap_clear_fields(void) {
 static void edit_ldap_set_fields( LdapServer *server ) {
        LdapControl *ctl;
        gchar *crit;
+       gchar *pwd;
 
        if( ldapsvr_get_name( server ) )
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_name),
@@ -907,9 +908,11 @@ static void edit_ldap_set_fields( LdapServer *server ) {
        if( ctl->bindDN )
                gtk_entry_set_text(
                        GTK_ENTRY(ldapedit.entry_bindDN), ctl->bindDN );
-       if( ctl->bindPass )
-               gtk_entry_set_text(
-                       GTK_ENTRY(ldapedit.entry_bindPW), ctl->bindPass );
+       if( ctl->bindPass ) {
+               pwd = ldapctl_get_bind_password( ctl );
+               gtk_entry_set_text(     GTK_ENTRY(ldapedit.entry_bindPW),  pwd );
+               g_free(pwd);
+       }
        gtk_spin_button_set_value(
                GTK_SPIN_BUTTON(ldapedit.spinbtn_timeout), ctl->timeOut );
        gtk_spin_button_set_value(
@@ -1040,7 +1043,7 @@ AdapterDSource *addressbook_edit_ldap(
                ldapctl_set_host( ctl, sHost );
                ldapctl_set_base_dn( ctl, sBase );
                ldapctl_set_bind_dn( ctl, sBind );
-               ldapctl_set_bind_password( ctl, sPass );
+               ldapctl_set_bind_password( ctl, sPass, TRUE, TRUE );
                ldapctl_set_port( ctl, iPort );
                ldapctl_set_max_entries( ctl, iMaxE );
                ldapctl_set_timeout( ctl, iTime );
@@ -1053,6 +1056,8 @@ AdapterDSource *addressbook_edit_ldap(
                        ctl, bMatch ?
                        LDAPCTL_MATCH_CONTAINS : LDAPCTL_MATCH_BEGINWITH );
 
+               addrindex_save_data(addrIndex);
+
                /* Save attributes */
                editldap_parse_criteria( sCrit, ctl );
 
index c4969ff63f4097b4c9226b26af06b29ecbb73500..f9693882ec1d387f7eb676744ad7b905d112fe45 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "ldapctrl.h"
 #include "mgutils.h"
+#include "passcrypt.h"
 #include "editaddress_other_attributes_ldap.h"
 #include "common/utils.h"
 
@@ -134,17 +135,66 @@ void ldapctl_set_bind_dn( LdapControl* ctl, const gchar *value ) {
  * Specify bind password to be used.
  * \param ctl  Control object to process.
  * \param value Password.
+ * \param encrypt Encrypt password
+ * \param change Save encrypted
  */
-void ldapctl_set_bind_password( LdapControl* ctl, const gchar *value ) {
+void ldapctl_set_bind_password( 
+       LdapControl* ctl, const gchar *value, gboolean encrypt, gboolean change ) {
+       gchar *buf = NULL, *tmp;
+
        ctl->bindPass = mgu_replace_string( ctl->bindPass, value );
 
        if ( ctl->bindPass == NULL )
                return;
 
        g_strstrip( ctl->bindPass );
+
+       if ( encrypt ) {
+               /* If first char is not ! the password is not encrypted */
+               if (ctl->bindPass[0] == '!' || change) {
+                       if (ctl->bindPass[0] != '!' && change)
+                               buf = mgu_replace_string( buf, ctl->bindPass );
+                       else
+                               buf = mgu_replace_string( buf, ctl->bindPass + 1 );
+                       passcrypt_encrypt( buf, strlen(buf) );
+                       if (ctl->bindPass[0] != '!' && change) {
+                               tmp = g_strconcat( "!", buf, NULL );
+                               g_free(buf);
+                               buf = g_strdup(tmp);
+                               g_free(tmp);
+                       }
+                       ctl->bindPass = mgu_replace_string( ctl->bindPass, buf );
+                       g_free(buf);
+               }
+       }
        debug_print("setting bindPassword\n");
 }
 
+/**
+ * Fetch bind password to be used.
+ * \param ctl  Control object to process.
+ * \return Decrypted password.
+ */
+gchar* ldapctl_get_bind_password( LdapControl* ctl ) {
+       gchar *pwd = NULL, *buf;
+
+       if ( ctl->bindPass != NULL ) {
+               pwd = mgu_replace_string( pwd, ctl->bindPass );
+               /* If first char is not ! the password is not encrypted */
+               if (pwd && pwd[0] == '!') {
+                       buf = g_strdup(pwd + 1);
+                       g_free(pwd);
+                       passcrypt_decrypt( buf, strlen(buf) );
+                       pwd = g_strdup(buf);
+                       g_free(buf);
+               }
+       }
+
+       debug_print("getting bindPassword\n");
+
+       return pwd;
+}
+
 /**
  * Specify maximum number of entries to retrieve.
  * \param ctl  Control object to process.
@@ -339,6 +389,7 @@ void ldapctl_free( LdapControl *ctl ) {
  */
 void ldapctl_print( const LdapControl *ctl, FILE *stream ) {
        cm_return_if_fail( ctl != NULL );
+       gchar *pwd;
 
        pthread_mutex_lock( ctl->mutexCtl );
        fprintf( stream, "LdapControl:\n" );
@@ -346,7 +397,9 @@ void ldapctl_print( const LdapControl *ctl, FILE *stream ) {
        fprintf( stream, "     port: %d\n",   ctl->port );
        fprintf( stream, "  base dn: '%s'\n", ctl->baseDN?ctl->baseDN:"null" );
        fprintf( stream, "  bind dn: '%s'\n", ctl->bindDN?ctl->bindDN:"null" );
-       fprintf( stream, "bind pass: '%s'\n", ctl->bindPass?ctl->bindPass:"null" );
+       pwd = ldapctl_get_bind_password((LdapControl *) ctl);
+       fprintf( stream, "bind pass: '%s'\n", pwd?pwd:"null" );
+       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" );
index 678ecccd01b7fd7abfaf43dcc062d60e53e1c08d..8d1b7699a2771b06091f66012f848906e24e1d55 100644 (file)
@@ -87,7 +87,9 @@ void ldapctl_set_host         ( LdapControl* ctl, const gchar *value );
 void ldapctl_set_port          ( LdapControl* ctl, const gint value );
 void ldapctl_set_base_dn       ( LdapControl* ctl, const gchar *value );
 void ldapctl_set_bind_dn       ( LdapControl* ctl, const gchar *value );
-void ldapctl_set_bind_password ( LdapControl* ctl, const gchar *value );
+void ldapctl_set_bind_password 
+       ( LdapControl* ctl, const gchar *value, gboolean encrypt, gboolean change );
+gchar* ldapctl_get_bind_password ( LdapControl* ctl );
 void ldapctl_set_max_entries   ( LdapControl* ctl, const gint value );
 void ldapctl_set_timeout       ( LdapControl* ctl, const gint value );
 void ldapctl_set_max_query_age ( LdapControl* ctl, const gint value );
index b1d32300e1ef3eed92d4856a92bf2caf63cdba86..b8bb4eddb0d74b447ceffa75fe91bd447c917127 100644 (file)
@@ -691,6 +691,7 @@ static gint ldapqry_connect( LdapQuery *qry ) {
        gint rc;
        gint version;
        gchar *uri = NULL;
+       gchar *pwd;
 
        /* Initialize connection */
        if (debug_get_mode()) {
@@ -756,7 +757,9 @@ static gint ldapqry_connect( LdapQuery *qry ) {
        if( ctl->bindDN ) {
                if( * ctl->bindDN != '\0' ) {
                        debug_print("binding...\n");
-                       rc = claws_ldap_simple_bind_s( ld, ctl->bindDN, ctl->bindPass );
+                       pwd = ldapctl_get_bind_password(ctl);
+                       rc = claws_ldap_simple_bind_s(ld, ctl->bindDN, pwd);
+                       g_free(pwd);
                        debug_print("rc=%d\n", rc);
                        if( rc != LDAP_SUCCESS ) {
                                debug_print("LDAP Error: ldap_simple_bind_s: %s\n",     ldap_err2string(rc));
index 4f37d3e939a50dbeb33d6940384dc1fd5a711115..d81833821b8d1941da6c5a0840bc1e595af17b65 100644 (file)
@@ -317,6 +317,7 @@ LDAP *ldapsvr_connect(LdapControl *ctl) {
        gint rc;
        gint version;
        gchar *uri = NULL;
+       gchar *pwd;
 
        cm_return_val_if_fail(ctl != NULL, NULL);
 
@@ -357,13 +358,16 @@ LDAP *ldapsvr_connect(LdapControl *ctl) {
        /* Bind to the server, if required */
        if (ctl->bindDN) {
                if (* ctl->bindDN != '\0') {
-                       rc = claws_ldap_simple_bind_s(ld, ctl->bindDN, ctl->bindPass);
+                       pwd = ldapctl_get_bind_password(ctl);
+                       rc = claws_ldap_simple_bind_s(ld, ctl->bindDN, pwd);
                        if (rc != LDAP_SUCCESS) {
-                               g_printerr("bindDN: %s, bindPass: %s\n", ctl->bindDN, ctl->bindPass);
+                               g_printerr("bindDN: %s, bindPass: %s\n", ctl->bindDN, pwd);
                                g_printerr("LDAP Error(bind): ldap_simple_bind_s: %s\n",
                                        ldap_err2string(rc));
+                               g_free(pwd);
                                return NULL;
                        }
+                       g_free(pwd);
                }
        }
        return ld;