2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2015 Match Grun and the Claws Mail team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Edit LDAP address book data.
25 #include "claws-features.h"
33 #include <glib/gi18n.h>
34 #include <gdk/gdkkeysyms.h>
37 #include "addressbook.h"
38 #include "prefs_common.h"
39 #include "addressitem.h"
41 #include "ldapserver.h"
44 #include "editldap_basedn.h"
45 #include "manage_window.h"
47 #include "prefs_gtk.h"
48 #include "passwordstore.h"
52 #define PAGE_EXTENDED 2
54 #define ADDRESSBOOK_GUESS_LDAP_NAME "MyServer"
55 #define ADDRESSBOOK_GUESS_LDAP_SERVER "localhost"
57 #define LDAPEDIT_TABLE_ROWS 6
58 #define LDAPEDIT_TABLE_COLS 3
60 static struct _LDAPEdit
{
64 GtkWidget
*cancel_btn
;
67 GtkWidget
*entry_name
;
68 GtkWidget
*entry_server
;
69 GtkWidget
*spinbtn_port
;
70 GtkWidget
*entry_baseDN
;
71 GtkWidget
*spinbtn_timeout
;
72 GtkWidget
*entry_bindDN
;
73 GtkWidget
*entry_bindPW
;
74 GtkWidget
*spinbtn_maxentry
;
75 GtkWidget
*entry_criteria
;
76 GtkWidget
*spinbtn_queryage
;
77 GtkWidget
*check_dynsearch
;
78 GtkWidget
*check_matchoption
;
79 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
80 GtkWidget
*enable_ssl
;
81 GtkWidget
*enable_tls
;
86 * Parse out individual attribute names from criteria string.
87 * \param criteria Criteria string.
88 * \ctl Control object.
90 static gboolean
editldap_validate_criteria( gchar
*criteria
) {
96 cm_return_val_if_fail(criteria
!= NULL
, TRUE
);
100 /* Replace delimiters with spaces */
103 if( *ptr
== ',' || *ptr
== ';' || *ptr
== '|' )
107 debug_print("cleaned criteria list: %s\n", criteria
);
110 splitStr
= g_strsplit( criteria
, " ", 0 );
124 g_strfreev( splitStr
);
131 static void edit_ldap_status_show( gchar
*msg
) {
132 if( ldapedit
.statusbar
!= NULL
) {
133 gtk_statusbar_pop( GTK_STATUSBAR(ldapedit
.statusbar
), ldapedit
.status_cid
);
135 gtk_statusbar_push( GTK_STATUSBAR(ldapedit
.statusbar
),
136 ldapedit
.status_cid
, msg
);
141 static gboolean
edit_ldap_validate( void ) {
147 str
= gtk_editable_get_chars(
148 GTK_EDITABLE(ldapedit
.entry_name
), 0, -1 );
151 gtk_widget_grab_focus( ldapedit
.entry_name
);
152 edit_ldap_status_show( _( "A Name must be supplied." ) );
158 str
= gtk_editable_get_chars(
159 GTK_EDITABLE(ldapedit
.entry_server
), 0, -1 );
162 gtk_widget_grab_focus( ldapedit
.entry_server
);
163 edit_ldap_status_show(
164 _( "A Hostname must be supplied for the server." ) );
171 str
= gtk_editable_get_chars(
172 GTK_EDITABLE(ldapedit
.entry_criteria
), 0, -1 );
173 if( editldap_validate_criteria( str
) ) {
175 gtk_widget_grab_focus( ldapedit
.entry_criteria
);
176 edit_ldap_status_show(
177 _( "At least one LDAP search attribute should be supplied." ) );
183 /* Switch to page with error */
185 gtk_notebook_set_current_page( GTK_NOTEBOOK(ldapedit
.notebook
), page
);
191 static void edit_ldap_ok( GtkWidget
*widget
, gboolean
*cancelled
) {
192 if( ! edit_ldap_validate() ) {
198 static void edit_ldap_cancel( GtkWidget
*widget
, gboolean
*cancelled
) {
203 static gint
edit_ldap_delete_event( GtkWidget
*widget
, GdkEventAny
*event
, gboolean
*cancelled
) {
209 static gboolean
edit_ldap_key_pressed( GtkWidget
*widget
, GdkEventKey
*event
, gboolean
*cancelled
) {
210 if (event
&& event
->keyval
== GDK_KEY_Escape
) {
217 static void edit_ldap_server_check( void ) {
218 gchar
*sHost
, *sBind
, *sPass
;
221 gchar
*sBaseDN
= NULL
;
224 gboolean tls
= FALSE
, ssl
= FALSE
;
225 GList
*baseDN
= NULL
;
227 edit_ldap_status_show( "" );
229 sHost
= gtk_editable_get_chars( GTK_EDITABLE(ldapedit
.entry_server
), 0, -1 );
230 sBind
= gtk_editable_get_chars( GTK_EDITABLE(ldapedit
.entry_bindDN
), 0, -1 );
231 sPass
= gtk_editable_get_chars( GTK_EDITABLE(ldapedit
.entry_bindPW
), 0, -1 );
232 iPort
= gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit
.spinbtn_port
) );
233 iTime
= gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit
.spinbtn_timeout
) );
234 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
235 tls
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit
.enable_tls
));
236 ssl
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit
.enable_ssl
));
242 if( *sHost
!= '\0' ) {
243 /* Test connection to server */
244 debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost
, iPort
, ssl
, tls
, sBind
);
245 if( ldaputil_test_connect( sHost
, iPort
, ssl
, tls
, iTime
) ) {
246 /* Attempt to read base DN */
247 baseDN
= ldaputil_read_basedn(sHost
, iPort
, sBind
, sPass
, iTime
, ssl
, tls
);
249 GList
*node
= baseDN
;
253 sBaseDN
= g_strdup( node
->data
);
255 node
= g_list_next( node
);
257 g_list_free_full( baseDN
, g_free
);
258 baseDN
= node
= NULL
;
271 debug_print("baseDN: %s\n", sBaseDN
);
272 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_baseDN
), sBaseDN
);
276 /* Display appropriate message */
278 sMsg
= _( "Connected successfully to server" );
281 sMsg
= _( "Could not connect to server" );
283 edit_ldap_status_show( sMsg
);
286 static void edit_ldap_basedn_select( void ) {
287 gchar
*sHost
, *sBind
, *sPass
, *sBase
;
288 gint iPort
, iTime
, tls
= 0, ssl
= 0;
291 sHost
= gtk_editable_get_chars( GTK_EDITABLE(ldapedit
.entry_server
), 0, -1 );
292 sBase
= gtk_editable_get_chars( GTK_EDITABLE(ldapedit
.entry_baseDN
), 0, -1 );
293 sBind
= gtk_editable_get_chars( GTK_EDITABLE(ldapedit
.entry_bindDN
), 0, -1 );
294 sPass
= gtk_editable_get_chars( GTK_EDITABLE(ldapedit
.entry_bindPW
), 0, -1 );
295 iPort
= gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit
.spinbtn_port
) );
296 iTime
= gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON( ldapedit
.spinbtn_timeout
) );
297 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
298 tls
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit
.enable_tls
));
299 ssl
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ldapedit
.enable_ssl
));
305 debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost
, iPort
, ssl
, tls
, sBind
);
306 selectDN
= edit_ldap_basedn_selection( sHost
, iPort
, sBase
, iTime
, sBind
, sPass
, ssl
, tls
);
308 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_baseDN
), selectDN
);
318 static void edit_ldap_search_reset(void) {
319 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_criteria
), LDAPCTL_DFL_ATTR_LIST
);
322 static void addressbook_edit_ldap_dialog_create( gboolean
*cancelled
) {
328 GtkWidget
*cancel_btn
;
330 GtkWidget
*statusbar
;
332 debug_print("creating edit_ldap_dialog\n");
333 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "editldap");
334 gtk_container_set_border_width(GTK_CONTAINER(window
), 0);
335 gtk_window_set_title(GTK_WINDOW(window
), _("Edit LDAP Server"));
336 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
337 gtk_window_set_type_hint(GTK_WINDOW(window
), GDK_WINDOW_TYPE_HINT_DIALOG
);
338 g_signal_connect(G_OBJECT(window
), "delete_event",
339 G_CALLBACK(edit_ldap_delete_event
),
341 g_signal_connect(G_OBJECT(window
), "key_press_event",
342 G_CALLBACK(edit_ldap_key_pressed
),
345 vbox
= gtk_vbox_new( FALSE
, 6 );
346 gtk_widget_show( vbox
);
347 gtk_container_add( GTK_CONTAINER( window
), vbox
);
350 notebook
= gtk_notebook_new();
351 gtk_widget_show( notebook
);
352 gtk_box_pack_start( GTK_BOX( vbox
), notebook
, TRUE
, TRUE
, 0 );
353 gtk_container_set_border_width( GTK_CONTAINER( notebook
), 6 );
356 hsbox
= gtk_hbox_new(FALSE
, 0);
357 gtk_box_pack_end(GTK_BOX(vbox
), hsbox
, FALSE
, FALSE
, BORDER_WIDTH
);
358 statusbar
= gtk_statusbar_new();
359 gtk_box_pack_start(GTK_BOX(hsbox
), statusbar
, TRUE
, TRUE
, BORDER_WIDTH
);
362 gtkut_stock_button_set_create(&hbbox
, &cancel_btn
, GTK_STOCK_CANCEL
,
363 &ok_btn
, GTK_STOCK_OK
,
365 gtk_box_pack_end(GTK_BOX(vbox
), hbbox
, FALSE
, FALSE
, 0);
366 gtk_widget_grab_default(ok_btn
);
368 g_signal_connect(G_OBJECT(ok_btn
), "clicked",
369 G_CALLBACK(edit_ldap_ok
), cancelled
);
370 g_signal_connect(G_OBJECT(cancel_btn
), "clicked",
371 G_CALLBACK(edit_ldap_cancel
), cancelled
);
373 gtk_widget_show_all(vbox
);
375 ldapedit
.window
= window
;
376 ldapedit
.notebook
= notebook
;
377 ldapedit
.ok_btn
= ok_btn
;
378 ldapedit
.cancel_btn
= cancel_btn
;
379 ldapedit
.statusbar
= statusbar
;
380 ldapedit
.status_cid
=
381 gtk_statusbar_get_context_id(
382 GTK_STATUSBAR(statusbar
), "Edit LDAP Server Dialog" );
385 static void editldap_update_port (GtkToggleButton
*ssl_btn
, gpointer data
) {
386 gboolean val
= gtk_toggle_button_get_active(ssl_btn
);
387 gtk_spin_button_set_value(
388 GTK_SPIN_BUTTON( ldapedit
.spinbtn_port
),
389 val
? LDAPCTL_DFL_SSL_PORT
:LDAPCTL_DFL_PORT
);
390 debug_print("Setting port: %d\n", val
? LDAPCTL_DFL_SSL_PORT
:LDAPCTL_DFL_PORT
);
393 static void addressbook_edit_ldap_page_basic( gint pageNum
, gchar
*pageLbl
) {
397 GtkWidget
*entry_name
;
398 GtkWidget
*entry_server
;
399 GtkWidget
*hbox_spin
;
400 GtkAdjustment
*spinbtn_port_adj
;
401 GtkWidget
*spinbtn_port
;
402 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
403 GtkWidget
*enable_ssl_checkbtn
, *enable_tls_checkbtn
;
405 GtkWidget
*entry_baseDN
;
406 GtkWidget
*check_btn
;
407 GtkWidget
*lookdn_btn
;
410 vbox
= gtk_vbox_new( FALSE
, 8 );
411 gtk_widget_show( vbox
);
412 gtk_container_add( GTK_CONTAINER( ldapedit
.notebook
), vbox
);
414 label
= gtk_label_new( pageLbl
);
415 gtk_widget_show( label
);
416 gtk_notebook_set_tab_label(
417 GTK_NOTEBOOK( ldapedit
.notebook
),
418 gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit
.notebook
), pageNum
), label
);
420 table
= gtk_table_new( LDAPEDIT_TABLE_ROWS
, LDAPEDIT_TABLE_COLS
, FALSE
);
421 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
422 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
423 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
424 gtk_table_set_col_spacings(GTK_TABLE(table
), 8);
428 label
= gtk_label_new(_("Name"));
429 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
430 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
432 entry_name
= gtk_entry_new();
433 gtk_table_attach(GTK_TABLE(table
), entry_name
, 1, 2, top
, (top
+ 1),
434 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
436 CLAWS_SET_TIP(entry_name
, _(
437 "A name that you wish to call the server." ));
441 label
= gtk_label_new(_("Hostname"));
442 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
443 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
445 entry_server
= gtk_entry_new();
446 gtk_table_attach(GTK_TABLE(table
), entry_server
, 1, 2, top
, (top
+ 1),
447 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
449 CLAWS_SET_TIP(entry_server
, _(
450 "This is the hostname of the server. For example, " \
451 "\"ldap.example.org\" may be appropriate for the " \
452 "\"example.org\" organization. An IP address may also be " \
453 "used. You may specify \"localhost\" if running an LDAP " \
454 "server on the same computer as Claws Mail." ));
458 label
= gtk_label_new(_("Port"));
459 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
460 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
462 hbox_spin
= gtk_hbox_new (FALSE
, 8);
463 spinbtn_port_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (389, 1, 65535, 1, 1000, 0));
464 spinbtn_port
= gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_port_adj
), 1, 0);
465 gtk_box_pack_start (GTK_BOX (hbox_spin
), spinbtn_port
, TRUE
, FALSE
, 0);
466 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_port
), TRUE
);
468 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
469 enable_tls_checkbtn
= gtk_check_button_new_with_label(_("STARTTLS"));
470 enable_ssl_checkbtn
= gtk_check_button_new_with_label(_("SSL/TLS"));
471 SET_TOGGLE_SENSITIVITY_REVERSE(enable_tls_checkbtn
, enable_ssl_checkbtn
);
472 SET_TOGGLE_SENSITIVITY_REVERSE(enable_ssl_checkbtn
, enable_tls_checkbtn
);
473 CLAWS_SET_TIP(enable_tls_checkbtn
, _(
474 "Enable secure connection to the LDAP server via STARTTLS. "
475 "Connection starts unencrypted and is secured by STARTTLS command. "
476 "If connection fails, be sure to check the correct "
477 "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ));
478 CLAWS_SET_TIP(enable_ssl_checkbtn
, _(
479 "Enable secure connection to the LDAP server via SSL/TLS. "
480 "If connection fails, be sure to check the correct "
481 "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ));
483 gtk_box_pack_start (GTK_BOX (hbox_spin
), enable_tls_checkbtn
, TRUE
, FALSE
, 0);
484 gtk_box_pack_start (GTK_BOX (hbox_spin
), enable_ssl_checkbtn
, TRUE
, FALSE
, 0);
487 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
488 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
490 CLAWS_SET_TIP(spinbtn_port
, _(
491 "The port number that the server listens on. Port 389 is " \
494 check_btn
= gtk_button_new_with_label( _(" Check Server "));
495 gtk_table_attach(GTK_TABLE(table
), check_btn
, 2, 3, top
, (top
+ 1), GTK_FILL
, 0, 3, 0);
497 CLAWS_SET_TIP(check_btn
, _(
498 "Press this button to test the connection to the server." ));
502 label
= gtk_label_new(_("Search Base"));
503 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
504 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
506 entry_baseDN
= gtk_entry_new();
507 gtk_table_attach(GTK_TABLE(table
), entry_baseDN
, 1, 2, top
, (top
+ 1),
508 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
510 CLAWS_SET_TIP(entry_baseDN
, _(
511 "This specifies the name of the directory to be searched " \
512 "on the server. Examples include:\n" \
513 " dc=claws-mail,dc=org\n" \
514 " ou=people,dc=domainname,dc=com\n" \
515 " o=Organization Name,c=Country\n"
518 lookdn_btn
= gtkut_get_browse_file_btn(_("_Browse"));
519 gtk_table_attach(GTK_TABLE(table
), lookdn_btn
, 2, 3, top
, (top
+ 1), GTK_FILL
, 0, 3, 0);
521 CLAWS_SET_TIP(lookdn_btn
, _(
522 "Press this button to lookup the name of available " \
523 "directory names on the server." ));
525 /* Signal handlers */
526 g_signal_connect(G_OBJECT(check_btn
), "clicked",
527 G_CALLBACK(edit_ldap_server_check
), NULL
);
528 g_signal_connect(G_OBJECT(lookdn_btn
), "clicked",
529 G_CALLBACK(edit_ldap_basedn_select
), NULL
);
532 gtk_widget_show_all(vbox
);
534 ldapedit
.entry_name
= entry_name
;
535 ldapedit
.entry_server
= entry_server
;
536 ldapedit
.spinbtn_port
= spinbtn_port
;
537 ldapedit
.entry_baseDN
= entry_baseDN
;
538 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
539 ldapedit
.enable_ssl
= enable_ssl_checkbtn
;
540 ldapedit
.enable_tls
= enable_tls_checkbtn
;
542 g_signal_connect(G_OBJECT(enable_ssl_checkbtn
), "toggled", \
543 G_CALLBACK(editldap_update_port
), NULL
);
547 static void addressbook_edit_ldap_page_search( gint pageNum
, gchar
*pageLbl
) {
551 GtkWidget
*entry_criteria
;
552 GtkWidget
*hbox_spin
;
553 GtkAdjustment
*spinbtn_queryage_adj
;
554 GtkWidget
*spinbtn_queryage
;
555 GtkWidget
*check_dynsearch
;
556 GtkWidget
*check_matchoption
;
557 GtkWidget
*reset_btn
;
560 vbox
= gtk_vbox_new( FALSE
, 8 );
561 gtk_widget_show( vbox
);
562 gtk_container_add( GTK_CONTAINER( ldapedit
.notebook
), vbox
);
564 label
= gtk_label_new( pageLbl
);
565 gtk_widget_show( label
);
566 gtk_notebook_set_tab_label(
567 GTK_NOTEBOOK( ldapedit
.notebook
),
568 gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit
.notebook
), pageNum
), label
);
570 table
= gtk_table_new( LDAPEDIT_TABLE_ROWS
, LDAPEDIT_TABLE_COLS
, FALSE
);
571 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
572 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
573 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
574 gtk_table_set_col_spacings(GTK_TABLE(table
), 8);
578 label
= gtk_label_new(_("Search Attributes"));
579 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
580 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
582 entry_criteria
= gtk_entry_new();
583 gtk_table_attach(GTK_TABLE(table
), entry_criteria
, 1, 2, top
, (top
+ 1),
584 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
586 CLAWS_SET_TIP(entry_criteria
, _(
587 "A list of LDAP attribute names that should be searched " \
588 "when attempting to find a name or address." ));
590 reset_btn
= gtk_button_new_with_label( _(" Defaults "));
591 gtk_table_attach(GTK_TABLE(table
), reset_btn
, 2, 3, top
, (top
+ 1), GTK_FILL
, 0, 3, 0);
593 CLAWS_SET_TIP(reset_btn
, _(
594 "This resets the attribute names to a default value " \
595 "that should find most names and addresses during a " \
596 "name or address search process." ));
600 label
= gtk_label_new(_("Max Query Age (secs)"));
601 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
602 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
604 hbox_spin
= gtk_hbox_new (FALSE
, 8);
605 spinbtn_queryage_adj
= GTK_ADJUSTMENT(gtk_adjustment_new(
606 LDAPCTL_DFL_QUERY_AGE
, 1, LDAPCTL_MAX_QUERY_AGE
, 10, 1000, 0 ));
607 spinbtn_queryage
= gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_queryage_adj
), 1, 0);
608 gtk_box_pack_start (GTK_BOX (hbox_spin
), spinbtn_queryage
, FALSE
, FALSE
, 0);
609 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_queryage
), TRUE
);
610 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
611 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
613 CLAWS_SET_TIP(spinbtn_queryage
, _(
614 "This defines the maximum period of time (in seconds) that " \
615 "an address search result is valid for address completion " \
616 "purposes. Search results are stored in a cache until this " \
617 "period of time has passed and then retired. This will " \
618 "improve the response time when attempting to search for " \
619 "the same name or address on subsequent address completion " \
620 "requests. The cache will be searched in preference to " \
621 "performing a new server search request. The default value " \
622 "of 600 seconds (10 minutes), should be sufficient for most " \
623 "servers. A larger value will reduce the search time for " \
624 "subsequent searches. This is useful for servers that have " \
625 "slow response times at the expense of more memory to cache " \
630 check_dynsearch
= gtk_check_button_new_with_label(
631 _("Include server in dynamic search") );
632 gtk_table_attach(GTK_TABLE(table
), check_dynsearch
, 1, 3, top
, (top
+ 1),
633 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
635 CLAWS_SET_TIP(check_dynsearch
, _(
636 "Check this option to include this server for dynamic " \
637 "searches when using address completion." ));
641 check_matchoption
= gtk_check_button_new_with_label(
642 _("Match names 'containing' search term") );
643 gtk_table_attach(GTK_TABLE(table
), check_matchoption
, 1, 3, top
, (top
+ 1),
644 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
646 CLAWS_SET_TIP(check_matchoption
, _(
647 "Searches for names and addresses can be performed either " \
648 "using \"begins-with\" or \"contains\" search term. Check " \
649 "this option to perform a \"contains\" search; this type of " \
650 "search usually takes longer to complete. Note that for " \
651 "performance reasons, address completion uses " \
652 "\"begins-with\" for all searches against other address " \
656 /* Signal handlers */
657 g_signal_connect(G_OBJECT(reset_btn
), "clicked",
658 G_CALLBACK(edit_ldap_search_reset
), NULL
);
661 gtk_widget_show_all(vbox
);
663 ldapedit
.entry_criteria
= entry_criteria
;
664 ldapedit
.spinbtn_queryage
= spinbtn_queryage
;
665 ldapedit
.check_dynsearch
= check_dynsearch
;
666 ldapedit
.check_matchoption
= check_matchoption
;
669 static void showpwd_checkbtn_toggled(GtkToggleButton
*button
,
672 gboolean active
= gtk_toggle_button_get_active(button
);
673 GtkWidget
*entry
= GTK_WIDGET(user_data
);
675 gtk_entry_set_visibility(GTK_ENTRY(entry
), active
);
678 static void addressbook_edit_ldap_page_extended( gint pageNum
, gchar
*pageLbl
) {
682 GtkWidget
*entry_bindDN
;
683 GtkWidget
*entry_bindPW
;
684 GtkWidget
*showpwd_checkbtn
;
685 GtkWidget
*hbox_spin
;
686 GtkAdjustment
*spinbtn_timeout_adj
;
687 GtkWidget
*spinbtn_timeout
;
688 GtkAdjustment
*spinbtn_maxentry_adj
;
689 GtkWidget
*spinbtn_maxentry
;
692 vbox
= gtk_vbox_new( FALSE
, 8 );
693 gtk_widget_show( vbox
);
694 gtk_container_add( GTK_CONTAINER( ldapedit
.notebook
), vbox
);
696 label
= gtk_label_new( pageLbl
);
697 gtk_widget_show( label
);
698 gtk_notebook_set_tab_label(
699 GTK_NOTEBOOK( ldapedit
.notebook
),
700 gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit
.notebook
), pageNum
), label
);
702 table
= gtk_table_new( LDAPEDIT_TABLE_ROWS
, LDAPEDIT_TABLE_COLS
, FALSE
);
703 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
704 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
705 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
706 gtk_table_set_col_spacings(GTK_TABLE(table
), 8);
710 label
= gtk_label_new(_("Bind DN"));
711 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
712 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
714 entry_bindDN
= gtk_entry_new();
715 gtk_table_attach(GTK_TABLE(table
), entry_bindDN
, 1, 3, top
, (top
+ 1),
716 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
718 CLAWS_SET_TIP(entry_bindDN
, _(
719 "The LDAP user account name to be used to connect to the server. " \
720 "This is usually only used for protected servers. This name " \
721 "is typically formatted as: \"cn=user,dc=claws-mail,dc=org\". " \
722 "This is usually left empty when performing a search." ));
726 label
= gtk_label_new(_("Bind Password"));
727 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
728 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
730 entry_bindPW
= gtk_entry_new();
731 gtk_table_attach(GTK_TABLE(table
), entry_bindPW
, 1, 2, top
, (top
+ 1),
732 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
733 gtk_entry_set_visibility(GTK_ENTRY(entry_bindPW
), FALSE
);
735 CLAWS_SET_TIP(entry_bindPW
, _(
736 "The password to be used when connecting as the \"Bind DN\" " \
739 showpwd_checkbtn
= gtk_check_button_new_with_label (_("Show password"));
740 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn
), FALSE
);
741 g_signal_connect(G_OBJECT(showpwd_checkbtn
), "toggled",
742 G_CALLBACK(showpwd_checkbtn_toggled
), entry_bindPW
);
743 gtk_table_attach(GTK_TABLE(table
), showpwd_checkbtn
, 2, 3, top
, (top
+ 1),
748 label
= gtk_label_new(_("Timeout (secs)"));
749 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
750 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
752 hbox_spin
= gtk_hbox_new (FALSE
, 8);
753 spinbtn_timeout_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 300, 1, 10, 0));
754 spinbtn_timeout
= gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_timeout_adj
), 1, 0);
755 gtk_box_pack_start (GTK_BOX (hbox_spin
), spinbtn_timeout
, FALSE
, FALSE
, 0);
756 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_timeout
), TRUE
);
757 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
758 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
760 CLAWS_SET_TIP(spinbtn_timeout
, _(
761 "The timeout period in seconds." ));
765 label
= gtk_label_new(_("Maximum Entries"));
766 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
767 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
769 hbox_spin
= gtk_hbox_new (FALSE
, 8);
770 spinbtn_maxentry_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 500, 1, 10, 0));
771 spinbtn_maxentry
= gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_maxentry_adj
), 1, 0);
772 gtk_box_pack_start (GTK_BOX (hbox_spin
), spinbtn_maxentry
, FALSE
, FALSE
, 0);
773 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_maxentry
), TRUE
);
774 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
775 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
777 CLAWS_SET_TIP(spinbtn_maxentry
, _(
778 "The maximum number of entries that should be returned " \
779 "in the search result." ));
782 gtk_widget_show_all(vbox
);
784 ldapedit
.entry_bindDN
= entry_bindDN
;
785 ldapedit
.entry_bindPW
= entry_bindPW
;
786 ldapedit
.spinbtn_timeout
= spinbtn_timeout
;
787 ldapedit
.spinbtn_maxentry
= spinbtn_maxentry
;
790 static void addressbook_edit_ldap_create( gboolean
*cancelled
) {
792 addressbook_edit_ldap_dialog_create( cancelled
);
793 addressbook_edit_ldap_page_basic( page
++, _( "Basic" ) );
794 addressbook_edit_ldap_page_search( page
++, _( "Search" ) );
795 addressbook_edit_ldap_page_extended( page
++, _( "Extended" ) );
796 gtk_widget_show_all( ldapedit
.window
);
800 * Format criteria list for display.
801 * \param ctl Control object.
802 * \return Formatted string, or <i>NULL</i> if no attributes found.
804 static gchar
*editldap_build_criteria_list( const LdapControl
*ctl
) {
809 node
= ldapctl_get_criteria_list( ctl
);
811 gchar
*attr
= node
->data
;
813 tmp
= g_strdup_printf( "%s, %s", str
, attr
);
819 str
= g_strdup( attr
);
821 node
= g_list_next( node
);
828 * Parse out individual attribute names from criteria string.
829 * \param criteria Criteria string.
830 * \ctl Control object.
832 static void editldap_parse_criteria( gchar
*criteria
, LdapControl
*ctl
) {
837 /* Replace delimiters with spaces */
840 if( *ptr
== ',' || *ptr
== ';' || *ptr
== '|' )
846 ldapctl_criteria_list_clear( ctl
);
847 splitStr
= g_strsplit( criteria
, " ", 0 );
852 ldapctl_criteria_list_add( ctl
, splitStr
[i
] );
860 g_strfreev( splitStr
);
864 * Clear entry fields to reasonable defaults (for a new server entry).
866 static void edit_ldap_clear_fields(void) {
868 GTK_ENTRY(ldapedit
.entry_name
), ADDRESSBOOK_GUESS_LDAP_NAME
);
870 GTK_ENTRY(ldapedit
.entry_server
), ADDRESSBOOK_GUESS_LDAP_SERVER
);
871 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_baseDN
), "");
872 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_bindDN
), "");
873 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_bindPW
), "");
874 gtk_spin_button_set_value(
875 GTK_SPIN_BUTTON( ldapedit
.spinbtn_port
), LDAPCTL_DFL_PORT
);
876 gtk_spin_button_set_value(
877 GTK_SPIN_BUTTON( ldapedit
.spinbtn_timeout
), LDAPCTL_DFL_TIMEOUT
);
878 gtk_spin_button_set_value(
879 GTK_SPIN_BUTTON( ldapedit
.spinbtn_maxentry
), LDAPCTL_DFL_TIMEOUT
);
881 GTK_ENTRY(ldapedit
.entry_criteria
), LDAPCTL_DFL_ATTR_LIST
);
882 gtk_spin_button_set_value(
883 GTK_SPIN_BUTTON(ldapedit
.spinbtn_queryage
), LDAPCTL_DFL_QUERY_AGE
);
884 gtk_toggle_button_set_active(
885 GTK_TOGGLE_BUTTON( ldapedit
.check_dynsearch
), TRUE
);
886 gtk_toggle_button_set_active(
887 GTK_TOGGLE_BUTTON( ldapedit
.check_matchoption
), FALSE
);
888 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
889 gtk_toggle_button_set_active(
890 GTK_TOGGLE_BUTTON( ldapedit
.enable_ssl
), FALSE
);
891 gtk_toggle_button_set_active(
892 GTK_TOGGLE_BUTTON( ldapedit
.enable_tls
), FALSE
);
897 * Load entry fields from server control data.
898 * \param server Server object.
900 static void edit_ldap_set_fields( LdapServer
*server
) {
904 if( ldapsvr_get_name( server
) )
905 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_name
),
906 ldapsvr_get_name( server
) );
908 ctl
= server
->control
;
911 GTK_ENTRY(ldapedit
.entry_server
), ctl
->hostName
);
914 GTK_ENTRY(ldapedit
.entry_baseDN
), ctl
->baseDN
);
917 GTK_ENTRY(ldapedit
.entry_bindDN
), ctl
->bindDN
);
919 pwd
= passwd_store_get(PWS_CORE
, "LDAP", ctl
->hostName
);
920 gtk_entry_set_text( GTK_ENTRY(ldapedit
.entry_bindPW
),
923 memset(pwd
, 0, strlen(pwd
));
927 gtk_spin_button_set_value(
928 GTK_SPIN_BUTTON(ldapedit
.spinbtn_timeout
), ctl
->timeOut
);
929 gtk_spin_button_set_value(
930 GTK_SPIN_BUTTON(ldapedit
.spinbtn_maxentry
), ctl
->maxEntries
);
931 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
932 gtk_toggle_button_set_active(
933 GTK_TOGGLE_BUTTON(ldapedit
.enable_tls
), ctl
->enableTLS
);
934 gtk_toggle_button_set_active(
935 GTK_TOGGLE_BUTTON(ldapedit
.enable_ssl
), ctl
->enableSSL
);
937 gtk_spin_button_set_value(
938 GTK_SPIN_BUTTON(ldapedit
.spinbtn_port
), ctl
->port
);
939 /* Format criteria */
940 crit
= editldap_build_criteria_list( ctl
);
942 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_criteria
), crit
);
946 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_criteria
), "" );
948 gtk_spin_button_set_value(
949 GTK_SPIN_BUTTON(ldapedit
.spinbtn_queryage
), ctl
->maxQueryAge
);
950 gtk_toggle_button_set_active(
951 GTK_TOGGLE_BUTTON( ldapedit
.check_dynsearch
), server
->searchFlag
);
952 gtk_toggle_button_set_active(
953 GTK_TOGGLE_BUTTON( ldapedit
.check_matchoption
),
954 ( ctl
->matchingOption
== LDAPCTL_MATCH_CONTAINS
) );
958 * Edit LDAP server datasource that appears addressbook.
959 * \param addrIndex Address index object.
960 * \param ads Data source adapter.
961 * \return Update data source adapter, or <code>NULL</code> if user cancelled
964 AdapterDSource
*addressbook_edit_ldap(
965 AddressIndex
*addrIndex
, AdapterDSource
*ads
)
967 static gboolean cancelled
;
968 gchar
*sName
, *sHost
, *sBase
, *sBind
, *sPass
, *sCrit
;
969 gint iPort
, iMaxE
, iTime
, iAge
;
970 gboolean bSrch
, bMatch
;
971 AddressDataSource
*ds
= NULL
;
972 LdapServer
*server
= NULL
;
973 LdapControl
*ctl
= NULL
;
974 gboolean fin
, ssl
= FALSE
, tls
= FALSE
;
976 if (!ldapedit
.window
)
977 addressbook_edit_ldap_create(&cancelled
);
978 gtk_notebook_set_current_page( GTK_NOTEBOOK(ldapedit
.notebook
), PAGE_BASIC
);
979 gtk_widget_grab_focus(ldapedit
.ok_btn
);
980 gtk_widget_grab_focus(ldapedit
.entry_name
);
981 gtk_widget_show(ldapedit
.window
);
982 manage_window_set_transient(GTK_WINDOW(ldapedit
.window
));
983 gtk_window_set_modal(GTK_WINDOW(ldapedit
.window
), TRUE
);
985 edit_ldap_status_show( "" );
987 ds
= ads
->dataSource
;
988 server
= ds
->rawDataSource
;
989 edit_ldap_set_fields( server
);
990 gtk_window_set_title(
991 GTK_WINDOW(ldapedit
.window
), _("Edit LDAP Server"));
994 edit_ldap_clear_fields();
995 gtk_window_set_title(
996 GTK_WINDOW(ldapedit
.window
), _("Add New LDAP Server"));
1000 gtk_widget_hide(ldapedit
.window
);
1001 gtk_window_set_modal(GTK_WINDOW(ldapedit
.window
), FALSE
);
1002 if (cancelled
== TRUE
) return NULL
;
1004 sName
= gtk_editable_get_chars(
1005 GTK_EDITABLE(ldapedit
.entry_name
), 0, -1 );
1006 sHost
= gtk_editable_get_chars(
1007 GTK_EDITABLE(ldapedit
.entry_server
), 0, -1 );
1008 sBase
= gtk_editable_get_chars(
1009 GTK_EDITABLE(ldapedit
.entry_baseDN
), 0, -1 );
1010 sCrit
= gtk_editable_get_chars(
1011 GTK_EDITABLE(ldapedit
.entry_criteria
), 0, -1 );
1012 sBind
= gtk_editable_get_chars(
1013 GTK_EDITABLE(ldapedit
.entry_bindDN
), 0, -1 );
1014 sPass
= gtk_editable_get_chars(
1015 GTK_EDITABLE(ldapedit
.entry_bindPW
), 0, -1 );
1016 iPort
= gtk_spin_button_get_value_as_int(
1017 GTK_SPIN_BUTTON( ldapedit
.spinbtn_port
) );
1018 iTime
= gtk_spin_button_get_value_as_int(
1019 GTK_SPIN_BUTTON( ldapedit
.spinbtn_timeout
) );
1020 iMaxE
= gtk_spin_button_get_value_as_int(
1021 GTK_SPIN_BUTTON( ldapedit
.spinbtn_maxentry
) );
1022 iAge
= gtk_spin_button_get_value_as_int(
1023 GTK_SPIN_BUTTON( ldapedit
.spinbtn_queryage
) );
1024 bSrch
= gtk_toggle_button_get_active(
1025 GTK_TOGGLE_BUTTON( ldapedit
.check_dynsearch
) );
1026 bMatch
= gtk_toggle_button_get_active(
1027 GTK_TOGGLE_BUTTON( ldapedit
.check_matchoption
) );
1028 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
1029 ssl
= gtk_toggle_button_get_active(
1030 GTK_TOGGLE_BUTTON( ldapedit
.enable_ssl
) );
1031 tls
= gtk_toggle_button_get_active(
1032 GTK_TOGGLE_BUTTON( ldapedit
.enable_tls
) );
1034 debug_print("saving server config:\nname: %s\nhost: %s\nbase: %s\ncriteria: %s\nbind: %s\nport: %d\ntime: %d\nmax_entries: %d\ntimeout: %d\ndynamic: %d\ncheck_match: %d\n",
1035 sName
, sHost
, sBase
, sCrit
, sBind
, iPort
, iTime
, iMaxE
, iAge
, bSrch
, bMatch
);
1037 if( *sName
== '\0' ) fin
= TRUE
;
1038 if( *sHost
== '\0' ) fin
= TRUE
;
1044 server
= ldapsvr_create();
1045 ds
= addrindex_index_add_datasource(
1046 addrIndex
, ADDR_IF_LDAP
, server
);
1047 ads
= addressbook_create_ds_adapter(
1048 ds
, ADDR_LDAP
, NULL
);
1050 ctl
= server
->control
;
1051 addressbook_ads_set_name( ads
, sName
);
1052 ldapsvr_set_name( server
, sName
);
1053 ldapsvr_set_search_flag( server
, bSrch
);
1054 ldapctl_set_host( ctl
, sHost
);
1055 ldapctl_set_base_dn( ctl
, sBase
);
1056 ldapctl_set_bind_dn( ctl
, sBind
);
1057 ldapctl_set_port( ctl
, iPort
);
1058 ldapctl_set_max_entries( ctl
, iMaxE
);
1059 ldapctl_set_timeout( ctl
, iTime
);
1060 ldapctl_set_max_query_age( ctl
, iAge
);
1061 ldapctl_set_tls( ctl
, tls
);
1062 ldapctl_set_ssl( ctl
, ssl
);
1063 ldapctl_set_matching_option(
1065 LDAPCTL_MATCH_CONTAINS
: LDAPCTL_MATCH_BEGINWITH
);
1067 addrindex_save_data(addrIndex
);
1069 passwd_store_set(PWS_CORE
, "LDAP", sHost
, sPass
, FALSE
);
1070 passwd_store_write_config();
1072 /* Save attributes */
1073 editldap_parse_criteria( sCrit
, ctl
);
1082 if (sPass
!= NULL
&& strlen(sPass
) > 0)
1083 memset(sPass
, 0, strlen(sPass
));
1089 #endif /* USE_LDAP */