r3324 - in trunk/libmnetutil: . include include/libmnetutil source tests

mikma at minisip.org mikma at minisip.org
Thu Jun 14 19:53:17 CEST 2007


Author: mikma
Date: 2007-06-14 19:53:17 +0200 (Thu, 14 Jun 2007)
New Revision: 3324

Added:
   trunk/libmnetutil/tests/001_ldap.cxx
Modified:
   trunk/libmnetutil/Makefile.am
   trunk/libmnetutil/include/Makefile.am
   trunk/libmnetutil/include/libmnetutil/LdapConnection.h
   trunk/libmnetutil/include/libmnetutil/LdapCredentials.h
   trunk/libmnetutil/source/LdapConnection.cxx
   trunk/libmnetutil/tests/Makefile.am
Log:
* libmcrypto can't be used in libmnetutil because of library dependencies.
* Fix LdapConnection::LdapConnection(std::string host), and implement
  init for code reuse.
* Support anonymous LDAP bind.
* Disable unavailable LdapDownloader.



Modified: trunk/libmnetutil/Makefile.am
===================================================================
--- trunk/libmnetutil/Makefile.am	2007-06-14 15:03:28 UTC (rev 3323)
+++ trunk/libmnetutil/Makefile.am	2007-06-14 17:53:17 UTC (rev 3324)
@@ -38,8 +38,8 @@
 		    source/LdapConnection.cxx \
                     source/LdapEntry.cxx \
                     source/LdapException.cxx \
-		    source/LdapUrl.cxx \
-		    source/LdapDownloader.cxx
+		    source/LdapUrl.cxx
+# 		    source/LdapDownloader.cxx
 endif
 
 mnetutil_src = \

Modified: trunk/libmnetutil/include/Makefile.am
===================================================================
--- trunk/libmnetutil/include/Makefile.am	2007-06-14 15:03:28 UTC (rev 3323)
+++ trunk/libmnetutil/include/Makefile.am	2007-06-14 17:53:17 UTC (rev 3324)
@@ -6,8 +6,8 @@
 			libmnetutil/LdapDirectoryLocator.h \
 			libmnetutil/LdapEntry.h \
 			libmnetutil/LdapException.h \
-			libmnetutil/LdapUrl.h \
-			libmnetutil/LdapDownloader.h
+			libmnetutil/LdapUrl.h
+# 			libmnetutil/LdapDownloader.h
 endif
 
 pkginclude_HEADERS =    \

Modified: trunk/libmnetutil/include/libmnetutil/LdapConnection.h
===================================================================
--- trunk/libmnetutil/include/libmnetutil/LdapConnection.h	2007-06-14 15:03:28 UTC (rev 3323)
+++ trunk/libmnetutil/include/libmnetutil/LdapConnection.h	2007-06-14 17:53:17 UTC (rev 3324)
@@ -107,6 +107,8 @@
 		 */
 		bool			isBound;
 
+	protected:
+		void init(std::string host, int32_t port, MRef<LdapCredentials*> cred);
 };
 
 #endif

Modified: trunk/libmnetutil/include/libmnetutil/LdapCredentials.h
===================================================================
--- trunk/libmnetutil/include/libmnetutil/LdapCredentials.h	2007-06-14 15:03:28 UTC (rev 3323)
+++ trunk/libmnetutil/include/libmnetutil/LdapCredentials.h	2007-06-14 17:53:17 UTC (rev 3324)
@@ -22,7 +22,7 @@
 #include<libmnetutil/libmnetutil_config.h>
 
 #include <libmutil/MemObject.h>
-#include <libmcrypto/cert.h>
+// #include <libmcrypto/cert.h>
 
 #include <string>
 
@@ -33,7 +33,7 @@
  */
 class LdapCredentials : public MObject {
 	public:
-		MRef<certificate*> cert;
+// 		MRef<certificate*> cert;
 		std::string username;
 		std::string password;
 

Modified: trunk/libmnetutil/source/LdapConnection.cxx
===================================================================
--- trunk/libmnetutil/source/LdapConnection.cxx	2007-06-14 15:03:28 UTC (rev 3323)
+++ trunk/libmnetutil/source/LdapConnection.cxx	2007-06-14 17:53:17 UTC (rev 3324)
@@ -1,18 +1,24 @@
 #include <libmnetutil/LdapConnection.h>
 
-LdapConnection::LdapConnection(std::string host, int32_t port) : hostname(host), port(port), ld(NULL), isBound(false) {
+LdapConnection::LdapConnection(std::string host, int32_t port) {
+	init(host, port, NULL);
 }
-LdapConnection::LdapConnection(std::string host) : hostname(host), port(LDAP_PORT), ld(NULL), isBound(false) {
+LdapConnection::LdapConnection(std::string host) {
+	init(host, LDAP_PORT, NULL);
 }
-LdapConnection::LdapConnection(std::string host, int32_t port, MRef<LdapCredentials*> cred) : hostname(host), port(port), ld(NULL), isBound(false) {
-	setCredentials(cred);
-	try {
-		connect();
-	} catch (LdapException & e) {
-		//std::cerr << e.what() << std::endl;
-	}
+LdapConnection::LdapConnection(std::string host, int32_t port, MRef<LdapCredentials*> cred) {
+	init(host, port, cred);
 }
-LdapConnection::LdapConnection(std::string host, MRef<LdapCredentials*> cred) : hostname(host), port(LDAP_PORT), ld(NULL), isBound(false) {
+LdapConnection::LdapConnection(std::string host, MRef<LdapCredentials*> cred) {
+	init(host, LDAP_PORT, cred);
+}
+
+void LdapConnection::init(std::string host, int aPort, MRef<LdapCredentials*> aCred){
+	hostname = host;
+	port = aPort;
+	cred = aCred;
+	ld = NULL;
+	isBound = false;
 	setCredentials(cred);
 	try {
 		connect();
@@ -47,9 +53,6 @@
 	if (isConnected()) {
 		disconnect();
 	}
-	if (cred.isNull()) {
-		throw LdapException("Could not connect since no credentials have been specified");
-	}
 
 	// Initialize LDAP library and open connection
 	if ((ld = ldap_init(hostname.c_str(), port)) == NULL ) {
@@ -62,7 +65,15 @@
 	}
 
 	// Create LDAP bind
-	if (ldap_bind_s(ld, cred->username.c_str(), cred->password.c_str(), auth_method) != LDAP_SUCCESS) {
+	const char *user = NULL;
+	const char *pass = NULL;
+
+	if (cred) {
+		user = cred->username.c_str();
+		pass = cred->password.c_str();
+	}
+
+	if (ldap_bind_s(ld, user, pass, auth_method) != LDAP_SUCCESS) {
 		throw LdapException("Could not bind to connected server");
 	}
 

Added: trunk/libmnetutil/tests/001_ldap.cxx
===================================================================
--- trunk/libmnetutil/tests/001_ldap.cxx	                        (rev 0)
+++ trunk/libmnetutil/tests/001_ldap.cxx	2007-06-14 17:53:17 UTC (rev 3324)
@@ -0,0 +1,42 @@
+#include <libmnetutil/LdapConnection.h>
+
+using namespace std;
+
+int main(int argc, char *argv[])
+{
+	if( argc != 3 ){
+		cerr << "Usage: " << argv[0] << " <ldap server> <base dn>" << endl;
+		return 1;
+	}
+
+	const char *server_name = argv[1];
+	const char *base_dn = argv[2];
+
+	MRef<LdapConnection*> conn = new LdapConnection(server_name);
+
+	std::vector<MRef<LdapEntry*> > entries;
+	vector<string> attrs;
+	entries = conn->find(base_dn, "(objectclass=*)", attrs);
+	
+	std::vector<MRef<LdapEntry*> >::iterator i;
+	for (i = entries.begin(); i != entries.end(); i++) {
+		MRef<LdapEntry*> entry = *i;
+
+		vector<string> attrs = entry->getAttrNames();
+		vector<string>::iterator j;
+
+		for (j = attrs.begin(); j != attrs.end(); j++) {
+			const string &attr_name = *j;
+
+			vector<string> values = entry->getAttrValuesStrings(attr_name);
+			vector<string>::iterator k;
+
+			for (k = values.begin(); k != values.end(); k++) {
+				const string &value = *k;
+				cout << attr_name << ":" << value << endl;
+			}
+		}
+	}
+	
+	return 0;
+}


Property changes on: trunk/libmnetutil/tests/001_ldap.cxx
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: trunk/libmnetutil/tests/Makefile.am
===================================================================
--- trunk/libmnetutil/tests/Makefile.am	2007-06-14 15:03:28 UTC (rev 3323)
+++ trunk/libmnetutil/tests/Makefile.am	2007-06-14 17:53:17 UTC (rev 3324)
@@ -1,10 +1,16 @@
 AM_CPPFLAGS = -I$(top_srcdir)/include $(MINISIP_CFLAGS)
 AM_LDFLAGS = -L$(top_srcdir) $(MINISIP_LIBS)
-LIBADD = libmnetutil.la
+LDADD = ../libmnetutil.la
 
 MINISIP_TESTS = \
 	000_compile
 
+if ENABLE_LDAP
+MINISIP_TESTS += \
+	001_ldap
+endif
+
+
 TESTS = $(MINISIP_TESTS)
 noinst_PROGRAMS = $(MINISIP_TESTS)
 



More information about the Minisip-devel mailing list