summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/ldap/resourceldap.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp
index 1c54f63..55c43af 100644
--- a/kabc/plugins/ldap/resourceldap.cpp
+++ b/kabc/plugins/ldap/resourceldap.cpp
@@ -1,143 +1,143 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <kdebug.h> 28#include <kdebug.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klineedit.h> 30#include <klineedit.h>
31#include <klocale.h> 31#include <klocale.h>
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kstringhandler.h> 33#include <kstringhandler.h>
34 34
35#include <stdlib.h> 35#include <stdlib.h>
36 36
37#include "resourceldap.h" 37#include "resourceldap.h"
38#include "resourceldapconfig.h" 38#include "resourceldapconfig.h"
39 39
40using namespace KABC; 40using namespace KABC;
41 41
42extern "C" 42extern "C"
43{ 43{
44 void *init_kabc_ldap() 44//US void *init_kabc_ldap()
45 void *init_microkabc_ldap()
45 { 46 {
46 qDebug("resourceldap.cpp : init_kabc_ldap has to be changed"); 47 return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig>();
47//US return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig>();
48 } 48 }
49} 49}
50 50
51void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); 51void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value );
52 52
53 53
54ResourceLDAP::ResourceLDAP( const KConfig *config ) 54ResourceLDAP::ResourceLDAP( const KConfig *config )
55 : Resource( config ), mPort( 389 ), mLdap( 0 ) 55 : Resource( config ), mPort( 389 ), mLdap( 0 )
56{ 56{
57 KConfig *cfg = (KConfig *)config; 57 KConfig *cfg = (KConfig *)config;
58 if ( cfg ) { 58 if ( cfg ) {
59 mUser = cfg->readEntry( "LdapUser" ); 59 mUser = cfg->readEntry( "LdapUser" );
60 mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); 60 mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) );
61 mDn = cfg->readEntry( "LdapDn" ); 61 mDn = cfg->readEntry( "LdapDn" );
62 mHost = cfg->readEntry( "LdapHost" ); 62 mHost = cfg->readEntry( "LdapHost" );
63 mPort = cfg->readNumEntry( "LdapPort", 389 ); 63 mPort = cfg->readNumEntry( "LdapPort", 389 );
64 mFilter = cfg->readEntry( "LdapFilter" ); 64 mFilter = cfg->readEntry( "LdapFilter" );
65 mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); 65 mAnonymous = cfg->readBoolEntry( "LdapAnonymous" );
66 66
67 QStringList attributes = cfg->readListEntry( "LdapAttributes" ); 67 QStringList attributes = cfg->readListEntry( "LdapAttributes" );
68 for ( uint pos = 0; pos < attributes.count(); pos += 2 ) 68 for ( uint pos = 0; pos < attributes.count(); pos += 2 )
69 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); 69 mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] );
70 } 70 }
71 71
72 /** 72 /**
73 If you want to add new attributes, append them here, add a 73 If you want to add new attributes, append them here, add a
74 translation string in the ctor of AttributesDialog and 74 translation string in the ctor of AttributesDialog and
75 handle them in the load() method below. 75 handle them in the load() method below.
76 These are the default values from 76 These are the default values from
77 */ 77 */
78 if ( mAttributes.count() == 0 ) { 78 if ( mAttributes.count() == 0 ) {
79 mAttributes.insert( "commonName", "cn" ); 79 mAttributes.insert( "commonName", "cn" );
80 mAttributes.insert( "formattedName", "displayName" ); 80 mAttributes.insert( "formattedName", "displayName" );
81 mAttributes.insert( "familyName", "sn" ); 81 mAttributes.insert( "familyName", "sn" );
82 mAttributes.insert( "givenName", "givenName" ); 82 mAttributes.insert( "givenName", "givenName" );
83 mAttributes.insert( "mail", "mail" ); 83 mAttributes.insert( "mail", "mail" );
84 mAttributes.insert( "mailAlias", "" ); 84 mAttributes.insert( "mailAlias", "" );
85 mAttributes.insert( "phoneNumber", "telephoneNumber" ); 85 mAttributes.insert( "phoneNumber", "telephoneNumber" );
86 mAttributes.insert( "uid", "uid" ); 86 mAttributes.insert( "uid", "uid" );
87 } 87 }
88} 88}
89 89
90void ResourceLDAP::writeConfig( KConfig *config ) 90void ResourceLDAP::writeConfig( KConfig *config )
91{ 91{
92 Resource::writeConfig( config ); 92 Resource::writeConfig( config );
93 93
94 config->writeEntry( "LdapUser", mUser ); 94 config->writeEntry( "LdapUser", mUser );
95 config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) ); 95 config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) );
96 config->writeEntry( "LdapDn", mDn ); 96 config->writeEntry( "LdapDn", mDn );
97 config->writeEntry( "LdapHost", mHost ); 97 config->writeEntry( "LdapHost", mHost );
98 config->writeEntry( "LdapPort", mPort ); 98 config->writeEntry( "LdapPort", mPort );
99 config->writeEntry( "LdapFilter", mFilter ); 99 config->writeEntry( "LdapFilter", mFilter );
100 config->writeEntry( "LdapAnonymous", mAnonymous ); 100 config->writeEntry( "LdapAnonymous", mAnonymous );
101 101
102 QStringList attributes; 102 QStringList attributes;
103 QMap<QString, QString>::Iterator it; 103 QMap<QString, QString>::Iterator it;
104 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) 104 for ( it = mAttributes.begin(); it != mAttributes.end(); ++it )
105 attributes << it.key() << it.data(); 105 attributes << it.key() << it.data();
106 106
107 config->writeEntry( "LdapAttributes", attributes ); 107 config->writeEntry( "LdapAttributes", attributes );
108} 108}
109 109
110Ticket *ResourceLDAP::requestSaveTicket() 110Ticket *ResourceLDAP::requestSaveTicket()
111{ 111{
112 if ( !addressBook() ) { 112 if ( !addressBook() ) {
113 kdDebug(5700) << "no addressbook" << endl; 113 kdDebug(5700) << "no addressbook" << endl;
114 return 0; 114 return 0;
115 } 115 }
116 116
117 return createTicket( this ); 117 return createTicket( this );
118} 118}
119 119
120bool ResourceLDAP::doOpen() 120bool ResourceLDAP::doOpen()
121{ 121{
122 if ( mLdap ) 122 if ( mLdap )
123 return false; 123 return false;
124 124
125 if ( !mPort ) 125 if ( !mPort )
126 mPort = 389; 126 mPort = 389;
127 127
128 mLdap = ldap_init( mHost.local8Bit(), mPort ); 128 mLdap = ldap_init( mHost.local8Bit(), mPort );
129 if ( !mLdap ) { 129 if ( !mLdap ) {
130 addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); 130 addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) );
131 return false; 131 return false;
132 } 132 }
133 133
134 if ( !mUser.isEmpty() && !mAnonymous ) { 134 if ( !mUser.isEmpty() && !mAnonymous ) {
135 if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { 135 if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) {
136 addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); 136 addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) );
137 return false; 137 return false;
138 } 138 }
139 139
140 kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; 140 kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl;
141 } else { 141 } else {
142 if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { 142 if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) {
143 addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); 143 addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) );