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 mgu_free_dlist( baseDN
);
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_widget_set_size_request(window
, 450, -1);
335 gtk_container_set_border_width(GTK_CONTAINER(window
), 0);
336 gtk_window_set_title(GTK_WINDOW(window
), _("Edit LDAP Server"));
337 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
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_widget_set_size_request (spinbtn_port
, 64, -1);
467 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_port
), TRUE
);
469 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
470 enable_tls_checkbtn
= gtk_check_button_new_with_label(_("STARTTLS"));
471 enable_ssl_checkbtn
= gtk_check_button_new_with_label(_("SSL/TLS"));
472 SET_TOGGLE_SENSITIVITY_REVERSE(enable_tls_checkbtn
, enable_ssl_checkbtn
);
473 SET_TOGGLE_SENSITIVITY_REVERSE(enable_ssl_checkbtn
, enable_tls_checkbtn
);
474 CLAWS_SET_TIP(enable_tls_checkbtn
, _(
475 "Enable secure connection to the LDAP server via STARTTLS. "
476 "Connection starts unencrypted and is secured by STARTTLS command. "
477 "If connection fails, be sure to check the correct "
478 "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ));
479 CLAWS_SET_TIP(enable_ssl_checkbtn
, _(
480 "Enable secure connection to the LDAP server via SSL/TLS. "
481 "If connection fails, be sure to check the correct "
482 "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ));
484 gtk_box_pack_start (GTK_BOX (hbox_spin
), enable_tls_checkbtn
, TRUE
, FALSE
, 0);
485 gtk_box_pack_start (GTK_BOX (hbox_spin
), enable_ssl_checkbtn
, TRUE
, FALSE
, 0);
488 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
489 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
491 CLAWS_SET_TIP(spinbtn_port
, _(
492 "The port number that the server listens on. Port 389 is " \
495 check_btn
= gtk_button_new_with_label( _(" Check Server "));
496 gtk_table_attach(GTK_TABLE(table
), check_btn
, 2, 3, top
, (top
+ 1), GTK_FILL
, 0, 3, 0);
498 CLAWS_SET_TIP(check_btn
, _(
499 "Press this button to test the connection to the server." ));
503 label
= gtk_label_new(_("Search Base"));
504 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
505 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
507 entry_baseDN
= gtk_entry_new();
508 gtk_table_attach(GTK_TABLE(table
), entry_baseDN
, 1, 2, top
, (top
+ 1),
509 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
511 CLAWS_SET_TIP(entry_baseDN
, _(
512 "This specifies the name of the directory to be searched " \
513 "on the server. Examples include:\n" \
514 " dc=claws-mail,dc=org\n" \
515 " ou=people,dc=domainname,dc=com\n" \
516 " o=Organization Name,c=Country\n"
519 lookdn_btn
= gtkut_get_browse_file_btn(_("_Browse"));
520 gtk_table_attach(GTK_TABLE(table
), lookdn_btn
, 2, 3, top
, (top
+ 1), GTK_FILL
, 0, 3, 0);
522 CLAWS_SET_TIP(lookdn_btn
, _(
523 "Press this button to lookup the name of available " \
524 "directory names on the server." ));
526 /* Signal handlers */
527 g_signal_connect(G_OBJECT(check_btn
), "clicked",
528 G_CALLBACK(edit_ldap_server_check
), NULL
);
529 g_signal_connect(G_OBJECT(lookdn_btn
), "clicked",
530 G_CALLBACK(edit_ldap_basedn_select
), NULL
);
533 gtk_widget_show_all(vbox
);
535 ldapedit
.entry_name
= entry_name
;
536 ldapedit
.entry_server
= entry_server
;
537 ldapedit
.spinbtn_port
= spinbtn_port
;
538 ldapedit
.entry_baseDN
= entry_baseDN
;
539 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
540 ldapedit
.enable_ssl
= enable_ssl_checkbtn
;
541 ldapedit
.enable_tls
= enable_tls_checkbtn
;
543 g_signal_connect(G_OBJECT(enable_ssl_checkbtn
), "toggled", \
544 G_CALLBACK(editldap_update_port
), NULL
);
548 static void addressbook_edit_ldap_page_search( gint pageNum
, gchar
*pageLbl
) {
552 GtkWidget
*entry_criteria
;
553 GtkWidget
*hbox_spin
;
554 GtkAdjustment
*spinbtn_queryage_adj
;
555 GtkWidget
*spinbtn_queryage
;
556 GtkWidget
*check_dynsearch
;
557 GtkWidget
*check_matchoption
;
558 GtkWidget
*reset_btn
;
561 vbox
= gtk_vbox_new( FALSE
, 8 );
562 gtk_widget_show( vbox
);
563 gtk_container_add( GTK_CONTAINER( ldapedit
.notebook
), vbox
);
565 label
= gtk_label_new( pageLbl
);
566 gtk_widget_show( label
);
567 gtk_notebook_set_tab_label(
568 GTK_NOTEBOOK( ldapedit
.notebook
),
569 gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit
.notebook
), pageNum
), label
);
571 table
= gtk_table_new( LDAPEDIT_TABLE_ROWS
, LDAPEDIT_TABLE_COLS
, FALSE
);
572 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
573 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
574 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
575 gtk_table_set_col_spacings(GTK_TABLE(table
), 8);
579 label
= gtk_label_new(_("Search Attributes"));
580 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
581 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
583 entry_criteria
= gtk_entry_new();
584 gtk_table_attach(GTK_TABLE(table
), entry_criteria
, 1, 2, top
, (top
+ 1),
585 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
587 CLAWS_SET_TIP(entry_criteria
, _(
588 "A list of LDAP attribute names that should be searched " \
589 "when attempting to find a name or address." ));
591 reset_btn
= gtk_button_new_with_label( _(" Defaults "));
592 gtk_table_attach(GTK_TABLE(table
), reset_btn
, 2, 3, top
, (top
+ 1), GTK_FILL
, 0, 3, 0);
594 CLAWS_SET_TIP(reset_btn
, _(
595 "This resets the attribute names to a default value " \
596 "that should find most names and addresses during a " \
597 "name or address search process." ));
601 label
= gtk_label_new(_("Max Query Age (secs)"));
602 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
603 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
605 hbox_spin
= gtk_hbox_new (FALSE
, 8);
606 spinbtn_queryage_adj
= GTK_ADJUSTMENT(gtk_adjustment_new(
607 LDAPCTL_DFL_QUERY_AGE
, 1, LDAPCTL_MAX_QUERY_AGE
, 10, 1000, 0 ));
608 spinbtn_queryage
= gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_queryage_adj
), 1, 0);
609 gtk_box_pack_start (GTK_BOX (hbox_spin
), spinbtn_queryage
, FALSE
, FALSE
, 0);
610 gtk_widget_set_size_request (spinbtn_queryage
, 64, -1);
611 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_queryage
), TRUE
);
612 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
613 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
615 CLAWS_SET_TIP(spinbtn_queryage
, _(
616 "This defines the maximum period of time (in seconds) that " \
617 "an address search result is valid for address completion " \
618 "purposes. Search results are stored in a cache until this " \
619 "period of time has passed and then retired. This will " \
620 "improve the response time when attempting to search for " \
621 "the same name or address on subsequent address completion " \
622 "requests. The cache will be searched in preference to " \
623 "performing a new server search request. The default value " \
624 "of 600 seconds (10 minutes), should be sufficient for most " \
625 "servers. A larger value will reduce the search time for " \
626 "subsequent searches. This is useful for servers that have " \
627 "slow response times at the expense of more memory to cache " \
632 check_dynsearch
= gtk_check_button_new_with_label(
633 _("Include server in dynamic search") );
634 gtk_table_attach(GTK_TABLE(table
), check_dynsearch
, 1, 3, top
, (top
+ 1),
635 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
637 CLAWS_SET_TIP(check_dynsearch
, _(
638 "Check this option to include this server for dynamic " \
639 "searches when using address completion." ));
643 check_matchoption
= gtk_check_button_new_with_label(
644 _("Match names 'containing' search term") );
645 gtk_table_attach(GTK_TABLE(table
), check_matchoption
, 1, 3, top
, (top
+ 1),
646 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
648 CLAWS_SET_TIP(check_matchoption
, _(
649 "Searches for names and addresses can be performed either " \
650 "using \"begins-with\" or \"contains\" search term. Check " \
651 "this option to perform a \"contains\" search; this type of " \
652 "search usually takes longer to complete. Note that for " \
653 "performance reasons, address completion uses " \
654 "\"begins-with\" for all searches against other address " \
658 /* Signal handlers */
659 g_signal_connect(G_OBJECT(reset_btn
), "clicked",
660 G_CALLBACK(edit_ldap_search_reset
), NULL
);
663 gtk_widget_show_all(vbox
);
665 ldapedit
.entry_criteria
= entry_criteria
;
666 ldapedit
.spinbtn_queryage
= spinbtn_queryage
;
667 ldapedit
.check_dynsearch
= check_dynsearch
;
668 ldapedit
.check_matchoption
= check_matchoption
;
671 static void addressbook_edit_ldap_page_extended( gint pageNum
, gchar
*pageLbl
) {
675 GtkWidget
*entry_bindDN
;
676 GtkWidget
*entry_bindPW
;
677 GtkWidget
*hbox_spin
;
678 GtkAdjustment
*spinbtn_timeout_adj
;
679 GtkWidget
*spinbtn_timeout
;
680 GtkAdjustment
*spinbtn_maxentry_adj
;
681 GtkWidget
*spinbtn_maxentry
;
684 vbox
= gtk_vbox_new( FALSE
, 8 );
685 gtk_widget_show( vbox
);
686 gtk_container_add( GTK_CONTAINER( ldapedit
.notebook
), vbox
);
688 label
= gtk_label_new( pageLbl
);
689 gtk_widget_show( label
);
690 gtk_notebook_set_tab_label(
691 GTK_NOTEBOOK( ldapedit
.notebook
),
692 gtk_notebook_get_nth_page( GTK_NOTEBOOK( ldapedit
.notebook
), pageNum
), label
);
694 table
= gtk_table_new( LDAPEDIT_TABLE_ROWS
, LDAPEDIT_TABLE_COLS
, FALSE
);
695 gtk_box_pack_start(GTK_BOX(vbox
), table
, FALSE
, FALSE
, 0);
696 gtk_container_set_border_width( GTK_CONTAINER(table
), 8 );
697 gtk_table_set_row_spacings(GTK_TABLE(table
), 8);
698 gtk_table_set_col_spacings(GTK_TABLE(table
), 8);
702 label
= gtk_label_new(_("Bind DN"));
703 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
704 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
706 entry_bindDN
= gtk_entry_new();
707 gtk_table_attach(GTK_TABLE(table
), entry_bindDN
, 1, 2, top
, (top
+ 1),
708 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
710 CLAWS_SET_TIP(entry_bindDN
, _(
711 "The LDAP user account name to be used to connect to the server. " \
712 "This is usually only used for protected servers. This name " \
713 "is typically formatted as: \"cn=user,dc=claws-mail,dc=org\". " \
714 "This is usually left empty when performing a search." ));
718 label
= gtk_label_new(_("Bind Password"));
719 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
720 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
722 entry_bindPW
= gtk_entry_new();
723 gtk_table_attach(GTK_TABLE(table
), entry_bindPW
, 1, 2, top
, (top
+ 1),
724 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
725 gtk_entry_set_visibility(GTK_ENTRY(entry_bindPW
), FALSE
);
727 CLAWS_SET_TIP(entry_bindPW
, _(
728 "The password to be used when connecting as the \"Bind DN\" " \
733 label
= gtk_label_new(_("Timeout (secs)"));
734 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
735 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
737 hbox_spin
= gtk_hbox_new (FALSE
, 8);
738 spinbtn_timeout_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 300, 1, 10, 0));
739 spinbtn_timeout
= gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_timeout_adj
), 1, 0);
740 gtk_box_pack_start (GTK_BOX (hbox_spin
), spinbtn_timeout
, FALSE
, FALSE
, 0);
741 gtk_widget_set_size_request (spinbtn_timeout
, 64, -1);
742 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_timeout
), TRUE
);
743 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
744 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
746 CLAWS_SET_TIP(spinbtn_timeout
, _(
747 "The timeout period in seconds." ));
751 label
= gtk_label_new(_("Maximum Entries"));
752 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, top
, (top
+ 1), GTK_FILL
, 0, 0, 0);
753 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
755 hbox_spin
= gtk_hbox_new (FALSE
, 8);
756 spinbtn_maxentry_adj
= GTK_ADJUSTMENT(gtk_adjustment_new (0, 0, 500, 1, 10, 0));
757 spinbtn_maxentry
= gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_maxentry_adj
), 1, 0);
758 gtk_box_pack_start (GTK_BOX (hbox_spin
), spinbtn_maxentry
, FALSE
, FALSE
, 0);
759 gtk_widget_set_size_request (spinbtn_maxentry
, 64, -1);
760 gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_maxentry
), TRUE
);
761 gtk_table_attach(GTK_TABLE(table
), hbox_spin
, 1, 2, top
, (top
+ 1),
762 GTK_EXPAND
|GTK_SHRINK
|GTK_FILL
, 0, 0, 0);
764 CLAWS_SET_TIP(spinbtn_maxentry
, _(
765 "The maximum number of entries that should be returned " \
766 "in the search result." ));
769 gtk_widget_show_all(vbox
);
771 ldapedit
.entry_bindDN
= entry_bindDN
;
772 ldapedit
.entry_bindPW
= entry_bindPW
;
773 ldapedit
.spinbtn_timeout
= spinbtn_timeout
;
774 ldapedit
.spinbtn_maxentry
= spinbtn_maxentry
;
777 static void addressbook_edit_ldap_create( gboolean
*cancelled
) {
779 addressbook_edit_ldap_dialog_create( cancelled
);
780 addressbook_edit_ldap_page_basic( page
++, _( "Basic" ) );
781 addressbook_edit_ldap_page_search( page
++, _( "Search" ) );
782 addressbook_edit_ldap_page_extended( page
++, _( "Extended" ) );
783 gtk_widget_show_all( ldapedit
.window
);
787 * Format criteria list for display.
788 * \param ctl Control object.
789 * \return Formatted string, or <i>NULL</i> if no attributes found.
791 static gchar
*editldap_build_criteria_list( const LdapControl
*ctl
) {
796 node
= ldapctl_get_criteria_list( ctl
);
798 gchar
*attr
= node
->data
;
800 tmp
= g_strdup_printf( "%s, %s", str
, attr
);
806 str
= g_strdup( attr
);
808 node
= g_list_next( node
);
815 * Parse out individual attribute names from criteria string.
816 * \param criteria Criteria string.
817 * \ctl Control object.
819 static void editldap_parse_criteria( gchar
*criteria
, LdapControl
*ctl
) {
824 /* Replace delimiters with spaces */
827 if( *ptr
== ',' || *ptr
== ';' || *ptr
== '|' )
833 ldapctl_criteria_list_clear( ctl
);
834 splitStr
= g_strsplit( criteria
, " ", 0 );
839 ldapctl_criteria_list_add( ctl
, splitStr
[i
] );
847 g_strfreev( splitStr
);
851 * Clear entry fields to reasonable defaults (for a new server entry).
853 static void edit_ldap_clear_fields(void) {
855 GTK_ENTRY(ldapedit
.entry_name
), ADDRESSBOOK_GUESS_LDAP_NAME
);
857 GTK_ENTRY(ldapedit
.entry_server
), ADDRESSBOOK_GUESS_LDAP_SERVER
);
858 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_baseDN
), "");
859 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_bindDN
), "");
860 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_bindPW
), "");
861 gtk_spin_button_set_value(
862 GTK_SPIN_BUTTON( ldapedit
.spinbtn_port
), LDAPCTL_DFL_PORT
);
863 gtk_spin_button_set_value(
864 GTK_SPIN_BUTTON( ldapedit
.spinbtn_timeout
), LDAPCTL_DFL_TIMEOUT
);
865 gtk_spin_button_set_value(
866 GTK_SPIN_BUTTON( ldapedit
.spinbtn_maxentry
), LDAPCTL_DFL_TIMEOUT
);
868 GTK_ENTRY(ldapedit
.entry_criteria
), LDAPCTL_DFL_ATTR_LIST
);
869 gtk_spin_button_set_value(
870 GTK_SPIN_BUTTON(ldapedit
.spinbtn_queryage
), LDAPCTL_DFL_QUERY_AGE
);
871 gtk_toggle_button_set_active(
872 GTK_TOGGLE_BUTTON( ldapedit
.check_dynsearch
), TRUE
);
873 gtk_toggle_button_set_active(
874 GTK_TOGGLE_BUTTON( ldapedit
.check_matchoption
), FALSE
);
875 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
876 gtk_toggle_button_set_active(
877 GTK_TOGGLE_BUTTON( ldapedit
.enable_ssl
), FALSE
);
878 gtk_toggle_button_set_active(
879 GTK_TOGGLE_BUTTON( ldapedit
.enable_tls
), FALSE
);
884 * Load entry fields from server control data.
885 * \param server Server object.
887 static void edit_ldap_set_fields( LdapServer
*server
) {
891 if( ldapsvr_get_name( server
) )
892 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_name
),
893 ldapsvr_get_name( server
) );
895 ctl
= server
->control
;
898 GTK_ENTRY(ldapedit
.entry_server
), ctl
->hostName
);
901 GTK_ENTRY(ldapedit
.entry_baseDN
), ctl
->baseDN
);
904 GTK_ENTRY(ldapedit
.entry_bindDN
), ctl
->bindDN
);
905 gtk_entry_set_text( GTK_ENTRY(ldapedit
.entry_bindPW
),
906 passwd_store_get(PWS_CORE
, "LDAP", ctl
->hostName
));
907 gtk_spin_button_set_value(
908 GTK_SPIN_BUTTON(ldapedit
.spinbtn_timeout
), ctl
->timeOut
);
909 gtk_spin_button_set_value(
910 GTK_SPIN_BUTTON(ldapedit
.spinbtn_maxentry
), ctl
->maxEntries
);
911 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
912 gtk_toggle_button_set_active(
913 GTK_TOGGLE_BUTTON(ldapedit
.enable_tls
), ctl
->enableTLS
);
914 gtk_toggle_button_set_active(
915 GTK_TOGGLE_BUTTON(ldapedit
.enable_ssl
), ctl
->enableSSL
);
917 gtk_spin_button_set_value(
918 GTK_SPIN_BUTTON(ldapedit
.spinbtn_port
), ctl
->port
);
919 /* Format criteria */
920 crit
= editldap_build_criteria_list( ctl
);
922 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_criteria
), crit
);
926 gtk_entry_set_text(GTK_ENTRY(ldapedit
.entry_criteria
), "" );
928 gtk_spin_button_set_value(
929 GTK_SPIN_BUTTON(ldapedit
.spinbtn_queryage
), ctl
->maxQueryAge
);
930 gtk_toggle_button_set_active(
931 GTK_TOGGLE_BUTTON( ldapedit
.check_dynsearch
), server
->searchFlag
);
932 gtk_toggle_button_set_active(
933 GTK_TOGGLE_BUTTON( ldapedit
.check_matchoption
),
934 ( ctl
->matchingOption
== LDAPCTL_MATCH_CONTAINS
) );
938 * Edit LDAP server datasource that appears addressbook.
939 * \param addrIndex Address index object.
940 * \param ads Data source adapter.
941 * \return Update data source adapter, or <code>NULL</code> if user cancelled
944 AdapterDSource
*addressbook_edit_ldap(
945 AddressIndex
*addrIndex
, AdapterDSource
*ads
)
947 static gboolean cancelled
;
948 gchar
*sName
, *sHost
, *sBase
, *sBind
, *sPass
, *sCrit
;
949 gint iPort
, iMaxE
, iTime
, iAge
;
950 gboolean bSrch
, bMatch
;
951 AddressDataSource
*ds
= NULL
;
952 LdapServer
*server
= NULL
;
953 LdapControl
*ctl
= NULL
;
954 gboolean fin
, ssl
= FALSE
, tls
= FALSE
;
956 if (!ldapedit
.window
)
957 addressbook_edit_ldap_create(&cancelled
);
958 gtk_notebook_set_current_page( GTK_NOTEBOOK(ldapedit
.notebook
), PAGE_BASIC
);
959 gtk_widget_grab_focus(ldapedit
.ok_btn
);
960 gtk_widget_grab_focus(ldapedit
.entry_name
);
961 gtk_widget_show(ldapedit
.window
);
962 manage_window_set_transient(GTK_WINDOW(ldapedit
.window
));
963 gtk_window_set_modal(GTK_WINDOW(ldapedit
.window
), TRUE
);
965 edit_ldap_status_show( "" );
967 ds
= ads
->dataSource
;
968 server
= ds
->rawDataSource
;
969 edit_ldap_set_fields( server
);
970 gtk_window_set_title(
971 GTK_WINDOW(ldapedit
.window
), _("Edit LDAP Server"));
974 edit_ldap_clear_fields();
975 gtk_window_set_title(
976 GTK_WINDOW(ldapedit
.window
), _("Add New LDAP Server"));
980 gtk_widget_hide(ldapedit
.window
);
981 gtk_window_set_modal(GTK_WINDOW(ldapedit
.window
), FALSE
);
982 if (cancelled
== TRUE
) return NULL
;
984 sName
= gtk_editable_get_chars(
985 GTK_EDITABLE(ldapedit
.entry_name
), 0, -1 );
986 sHost
= gtk_editable_get_chars(
987 GTK_EDITABLE(ldapedit
.entry_server
), 0, -1 );
988 sBase
= gtk_editable_get_chars(
989 GTK_EDITABLE(ldapedit
.entry_baseDN
), 0, -1 );
990 sCrit
= gtk_editable_get_chars(
991 GTK_EDITABLE(ldapedit
.entry_criteria
), 0, -1 );
992 sBind
= gtk_editable_get_chars(
993 GTK_EDITABLE(ldapedit
.entry_bindDN
), 0, -1 );
994 sPass
= gtk_editable_get_chars(
995 GTK_EDITABLE(ldapedit
.entry_bindPW
), 0, -1 );
996 iPort
= gtk_spin_button_get_value_as_int(
997 GTK_SPIN_BUTTON( ldapedit
.spinbtn_port
) );
998 iTime
= gtk_spin_button_get_value_as_int(
999 GTK_SPIN_BUTTON( ldapedit
.spinbtn_timeout
) );
1000 iMaxE
= gtk_spin_button_get_value_as_int(
1001 GTK_SPIN_BUTTON( ldapedit
.spinbtn_maxentry
) );
1002 iAge
= gtk_spin_button_get_value_as_int(
1003 GTK_SPIN_BUTTON( ldapedit
.spinbtn_queryage
) );
1004 bSrch
= gtk_toggle_button_get_active(
1005 GTK_TOGGLE_BUTTON( ldapedit
.check_dynsearch
) );
1006 bMatch
= gtk_toggle_button_get_active(
1007 GTK_TOGGLE_BUTTON( ldapedit
.check_matchoption
) );
1008 #if (defined USE_LDAP_TLS || defined G_OS_WIN32)
1009 ssl
= gtk_toggle_button_get_active(
1010 GTK_TOGGLE_BUTTON( ldapedit
.enable_ssl
) );
1011 tls
= gtk_toggle_button_get_active(
1012 GTK_TOGGLE_BUTTON( ldapedit
.enable_tls
) );
1014 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",
1015 sName
, sHost
, sBase
, sCrit
, sBind
, iPort
, iTime
, iMaxE
, iAge
, bSrch
, bMatch
);
1017 if( *sName
== '\0' ) fin
= TRUE
;
1018 if( *sHost
== '\0' ) fin
= TRUE
;
1024 server
= ldapsvr_create();
1025 ds
= addrindex_index_add_datasource(
1026 addrIndex
, ADDR_IF_LDAP
, server
);
1027 ads
= addressbook_create_ds_adapter(
1028 ds
, ADDR_LDAP
, NULL
);
1030 ctl
= server
->control
;
1031 addressbook_ads_set_name( ads
, sName
);
1032 ldapsvr_set_name( server
, sName
);
1033 ldapsvr_set_search_flag( server
, bSrch
);
1034 ldapctl_set_host( ctl
, sHost
);
1035 ldapctl_set_base_dn( ctl
, sBase
);
1036 ldapctl_set_bind_dn( ctl
, sBind
);
1037 ldapctl_set_port( ctl
, iPort
);
1038 ldapctl_set_max_entries( ctl
, iMaxE
);
1039 ldapctl_set_timeout( ctl
, iTime
);
1040 ldapctl_set_max_query_age( ctl
, iAge
);
1041 ldapctl_set_tls( ctl
, tls
);
1042 ldapctl_set_ssl( ctl
, ssl
);
1043 ldapctl_set_matching_option(
1045 LDAPCTL_MATCH_CONTAINS
: LDAPCTL_MATCH_BEGINWITH
);
1047 addrindex_save_data(addrIndex
);
1049 passwd_store_set(PWS_CORE
, "LDAP", sHost
, sPass
, FALSE
);
1050 passwd_store_write_config();
1052 /* Save attributes */
1053 editldap_parse_criteria( sCrit
, ctl
);
1062 if (sPass
!= NULL
&& strlen(sPass
) > 0)
1063 memset(sPass
, 0, strlen(sPass
));
1069 #endif /* USE_LDAP */