int LDAPProtocol::asyncSearch( LDAPUrl &usrc ) { char **attrs = 0; int msgid; LDAPControl **serverctrls = 0, **clientctrls = 0; int count = usrc.attributes().count(); if ( count > 0 ) { attrs = static_cast<char**>( malloc((count+1) * sizeof(char*)) ); for (int i=0; i<count; i++) attrs[i] = strdup( (*usrc.attributes().at(i)).utf8() ); attrs[count] = 0; } int retval, scope = LDAP_SCOPE_BASE; switch ( usrc.scope() ) { case LDAPUrl::Base: scope = LDAP_SCOPE_BASE; break; case LDAPUrl::One: scope = LDAP_SCOPE_ONELEVEL; break; case LDAPUrl::Sub: scope = LDAP_SCOPE_SUBTREE; break; } controlsFromMetaData( &serverctrls, &clientctrls ); kdDebug(7125) << "asyncSearch() dn=\"" << usrc.dn() << "\" scope=" << usrc.scope() << " filter=\"" << usrc.filter() << "\" attrs=" << usrc.attributes() << endl; retval = ldap_search_ext( mLDAP, usrc.dn().utf8(), scope, usrc.filter().isEmpty() ? TQCString() : usrc.filter().utf8(), attrs, 0, serverctrls, clientctrls, 0, mSizeLimit, &msgid ); ldap_controls_free( serverctrls ); ldap_controls_free( clientctrls ); // free the attributes list again if ( count > 0 ) { for ( int i=0; i<count; i++ ) free( attrs[i] ); free(attrs); } if ( retval == 0 ) retval = msgid; return retval; }
void LDAPProtocol::LDAPEntry2UDSEntry( const TQString &dn, UDSEntry &entry, const LDAPUrl &usrc, bool dir ) { UDSAtom atom; int pos; entry.clear(); atom.m_uds = UDS_NAME; atom.m_long = 0; TQString name = dn; if ( (pos = name.find(",")) > 0 ) name = name.left( pos ); if ( (pos = name.find("=")) > 0 ) name.remove( 0, pos+1 ); name.replace(' ', "_"); if ( !dir ) name += ".ldif"; atom.m_str = name; entry.append( atom ); // the file type atom.m_uds = UDS_FILE_TYPE; atom.m_str = ""; atom.m_long = dir ? S_IFDIR : S_IFREG; entry.append( atom ); // the mimetype if (!dir) { atom.m_uds = UDS_MIME_TYPE; atom.m_long = 0; atom.m_str = "text/plain"; entry.append( atom ); } atom.m_uds = UDS_ACCESS; atom.m_long = dir ? 0500 : 0400; entry.append( atom ); // the url atom.m_uds = UDS_URL; atom.m_long = 0; LDAPUrl url; url=usrc; url.setPath("/"+dn); url.setScope( dir ? LDAPUrl::One : LDAPUrl::Base ); atom.m_str = url.prettyURL(); entry.append( atom ); }
void LDAPProtocol::changeCheck( LDAPUrl &url ) { bool critical; bool tls = ( url.hasExtension( "x-tls" ) ); int ver = 3; if ( url.hasExtension( "x-ver" ) ) ver = url.extension( "x-ver", critical).toInt(); bool authSASL = url.hasExtension( "x-sasl" ); TQString mech; if ( url.hasExtension( "x-mech" ) ) mech = url.extension( "x-mech", critical).upper(); TQString realm; if ( url.hasExtension( "x-realm" ) ) mech = url.extension( "x-realm", critical).upper(); TQString bindname; if ( url.hasExtension( "bindname" ) ) bindname = url.extension( "bindname", critical).upper(); int timelimit = 0; if ( url.hasExtension( "x-timelimit" ) ) timelimit = url.extension( "x-timelimit", critical).toInt(); int sizelimit = 0; if ( url.hasExtension( "x-sizelimit" ) ) sizelimit = url.extension( "x-sizelimit", critical).toInt(); if ( !authSASL && bindname.isEmpty() ) bindname = mUser; if ( tls != mTLS || ver != mVer || authSASL != mAuthSASL || mech != mMech || mRealm != realm || mBindName != bindname || mTimeLimit != timelimit || mSizeLimit != sizelimit ) { closeConnection(); mTLS = tls; mVer = ver; mAuthSASL = authSASL; mMech = mech; mRealm = realm; mBindName = bindname; mTimeLimit = timelimit; mSizeLimit = sizelimit; kdDebug(7125) << "parameters changed: tls = " << mTLS << " version: " << mVer << "SASLauth: " << mAuthSASL << endl; openConnection(); if ( mAuthSASL ) { url.setUser( mUser ); } else { url.setUser( mBindName ); } } else { if ( !mLDAP ) openConnection(); } }
void LdapClient::startQuery( const QString& filter ) { cancelQuery(); LDAPUrl url; url.setProtocol( "ldap" ); url.setUser( d->bindDN ); url.setPass( d->pwdBindDN ); url.setHost( mHost ); url.setPort( mPort.toUInt() ); url.setDn( mBase ); url.setAttributes( mAttrs ); url.setScope( mScope == "one" ? LDAPUrl::One : LDAPUrl::Sub ); url.setFilter( "("+filter+")" ); kdDebug(5700) << "Doing query: " << url.prettyURL() << endl; startParseLDIF(); mActive = true; mJob = KIO::get( url, false, false ); connect( mJob, SIGNAL( data( KIO::Job*, const QByteArray& ) ), this, SLOT( slotData( KIO::Job*, const QByteArray& ) ) ); connect( mJob, SIGNAL( infoMessage( KIO::Job*, const QString& ) ), this, SLOT( slotInfoMessage( KIO::Job*, const QString& ) ) ); connect( mJob, SIGNAL( result( KIO::Job* ) ), this, SLOT( slotDone() ) ); }