00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <iostream>
00023
00024 #include "kconfigldapbackend.h"
00025 #include "kconfigdata.h"
00026 #include "kuser.h"
00027 #include "xldaplite.h"
00028
00029 KConfigLDAPBackEnd::KConfigLDAPBackEnd( KConfigBase *config,
00030 const QString &fileName,
00031 const char * resType,
00032 bool useKDEGlobals )
00033
00034 : KConfigBackEnd(config, fileName, resType, useKDEGlobals)
00035
00036 {
00037 _fileImmutable = false;
00038 }
00039
00040
00041
00042
00043 KConfigLDAPBackEnd::~KConfigLDAPBackEnd()
00044 {
00045 }
00046
00047
00048
00049 bool KConfigLDAPBackEnd::parseConfigFiles()
00050 {
00051
00052 if (mfileName.isEmpty())
00053 return false;
00054
00055
00056 if ( mfileName == "kdebugrc"
00057 || mfileName == "kconf_updaterc"
00058 || mfileName == "kdedrc"
00059 || mfileName == "kdeinitrc"
00060 || mfileName == "kbuildsycocarc"
00061 || mfileName.startsWith( "/" ) )
00062 return false;
00063
00064
00065 xLDAPconnection ldap;
00066 if (!ldap.connect()) return false;
00067
00068
00069 KUser user;
00070 QString basedn = QString( "cn=%1,ou=default,ou=KDEConfig,%2" ).arg( mfileName ).arg( ldap.base() );
00071 QStringList profiles( basedn );
00072
00073
00074 basedn = QString("uid=%1,ou=People,%2").arg(user.loginName()).arg(ldap.base());
00075 char *attrs[] = { "kdeConfigEntry", 0 };
00076 xLDAPquery query( ldap, "(objectClass=posixAccount)", basedn, attrs );
00077
00078 for ( xLDAPiterator section(query); section; ++section )
00079 {
00080 for ( xLDAPattribute gattr(section); gattr; ++gattr )
00081 {
00082 basedn = QString( "cn=%1,%2" ).arg( mfileName ).arg( gattr.firstValue() );
00083 profiles.push_front( basedn );
00084 }
00085 }
00086
00087 for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it )
00088 {
00089
00090 xLDAPquery filequery( ldap, "(objectClass=appConfig)", *it );
00091 for ( xLDAPiterator section( filequery ); section; ++section )
00092 {
00093 for ( xLDAPattribute gattr(section); gattr; ++gattr )
00094 {
00095 if (!strcmp(gattr.attribute(), "immutable"))
00096 setFileImmutable(0 == strcmp(gattr.firstValue(), "TRUE"));
00097 }
00098 }
00099
00100 xLDAPquery query( ldap, "(objectClass=appConfigSection)", *it );
00101
00102
00103
00104 for ( xLDAPiterator section(query); section; ++section )
00105 {
00106 QCString aCurrentGroup = "<default>";
00107 bool groupimmutable = false;
00108
00109 for ( xLDAPattribute gattr(section); gattr; ++gattr )
00110 {
00111
00112 if (!strcmp(gattr.attribute(), "cn"))
00113 aCurrentGroup = gattr.firstValue();
00114 else if (!strcmp(gattr.attribute(), "immutable"))
00115 {
00116 if ( getFileImmutable() )
00117 groupimmutable = true;
00118 else
00119 groupimmutable = (0 == strcmp(gattr.firstValue(), "TRUE"));
00120 }
00121 if ( groupimmutable )
00122 setGroupImmutable( aCurrentGroup, true );
00123 }
00124
00125
00126 if (aCurrentGroup == "KDE Desktop Entry")
00127 aCurrentGroup = "Desktop Entry";
00128
00129 KEntryKey groupKey(aCurrentGroup, 0);
00130 KEntry entry = pConfig->lookupData(groupKey);
00131 bool groupSkip = entry.bImmutable;
00132
00133 if (groupSkip)
00134 continue;
00135
00136 entry.bImmutable |= groupimmutable;
00137 pConfig->putData(groupKey, entry, false);
00138
00139
00140
00141 for ( xLDAPattribute attr(section); attr; ++attr )
00142 {
00143 if (strcmp(attr.attribute(), "appconfigentry")) continue;
00144 for ( char* cattr = (char*) attr.firstValue();
00145 cattr;
00146 cattr = (char*) attr.nextValue() )
00147 {
00148 QCString cattribute((const char*) cattr);
00149 cattr = cattribute.data();
00150 char* ceq = (char*) strchr(cattr, '=');
00151 if (!ceq)
00152 continue;
00153
00154 *ceq = 0;
00155 char* cvalue = ++ceq;
00156
00157
00158 KEntryKey aEntryKey(aCurrentGroup, cattr);
00159 aEntryKey.bLocal = false;
00160 aEntryKey.bDefault = false;
00161
00162
00163
00164 KEntry aEntry;
00165 aEntry.mValue = cvalue;
00166 aEntry.bGlobal = true;
00167 aEntry.bImmutable = false;
00168 aEntry.bDeleted = false;
00169 aEntry.bExpand = false;
00170 aEntry.bNLS = false;
00171
00172 pConfig->putData( aEntryKey,
00173 aEntry,
00174 false );
00175 }
00176 }
00177 }
00178 }
00179
00180 return true;
00181 }
00182
00183
00184
00185 void KConfigLDAPBackEnd::sync(bool bMerge)
00186 {
00187
00188 }
00189
00190
00191
00192 void KConfigLDAPBackEnd::virtual_hook(int id, void* data)
00193 {
00194 KConfigBackEnd::virtual_hook( id, data );
00195 }
00196