{"id":147,"date":"2013-05-07T12:27:49","date_gmt":"2013-05-07T00:27:49","guid":{"rendered":"http:\/\/www.massey.ac.nz\/~fherbert\/?p=147"},"modified":"2013-05-07T20:14:29","modified_gmt":"2013-05-07T08:14:29","slug":"building-python-ldap-2-4-10-on-qnap-ts-210","status":"publish","type":"post","link":"https:\/\/www.herbert.org.nz\/?p=147","title":{"rendered":"Building python-ldap-2.4.10 on QNAP TS-210"},"content":{"rendered":"<p>I&#8217;m using ipkg to install some of the requirements, so check the QNAP site to see how to enable the use of this.<\/p>\n<p>The python-ldap module requires a compile of some modules so you need some headers. These can be installed via ipkg:<br \/>\n<code>ipkg install openldap-libs<\/code><br \/>\nThis installs the ldap(openldap-libs_2.3.43-2_arm.ipk) and sasl (cyrus-sasl-libs_2.1.23-2_arm.ipk) libs in \/opt\/lib and \/opt\/lib\/sasl2 and the header files in \/opt\/include and \/opt\/include\/sasl<\/p>\n<p>Download the python-ldap (Version 2.4.10 as of the time of writing this document) source from <a href=\"https:\/\/pypi.python.org\/pypi\/python-ldap\/\" target=\"_blank\">https:\/\/pypi.python.org\/pypi\/python-ldap\/<\/a> and extract to your qnap (I&#8217;m using \/share\/MD0_DATA\/lab\/)<\/p>\n<p>Edit setup.cfg in the extracted directory, and change the following two lines:<br \/>\n<code>library_dirs = \/opt\/openldap-RE24\/lib \/usr\/lib<br \/>\ninclude_dirs = \/opt\/openldap-RE24\/include \/usr\/include\/sasl \/usr\/include<\/code><\/p>\n<p>to be:<br \/>\n<code>library_dirs = \/opt\/lib \/opt\/lib\/sasl2<br \/>\ninclude_dirs = \/opt\/include \/opt\/include\/sasl<\/code><\/p>\n<p>Run : python setup.py build<\/p>\n<p>I had an error:<br \/>\n<code>\/opt\/bin\/gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DHAVE_SASL -DHAVE_TLS -DHAVE_LIBLDAP_R -DHAVE_LIBLDAP_R -DLDAPMODULE_VERSION=2.4.10 -IModules -I\/opt\/include -I\/opt\/include\/sasl -I\/opt\/include\/python2.5 -c Modules\/constants.c -o build\/temp.linux-armv5tel-2.5\/Modules\/constants.o<br \/>\nModules\/constants.c: In function 'LDAPinit_constants':<br \/>\nModules\/constants.c:155: error: 'LDAP_OPT_DIAGNOSTIC_MESSAGE' undeclared (first use in this function)<br \/>\nModules\/constants.c:155: error: (Each undeclared identifier is reported only once<br \/>\nModules\/constants.c:155: error: for each function it appears in.)<br \/>\nModules\/constants.c:365: error: 'LDAP_CONTROL_RELAX' undeclared (first use in this function)<br \/>\nerror: command '\/opt\/bin\/gcc' failed with exit status 1<\/code><\/p>\n<p>Turns out with version of python-ldap (2.4.x), OpenLDAP 2.4 client libs or newer are required. So off to find out where these are. I downloaded the ipkg&#8217;s mentioned above (openldap-libs and cyrus-sasl-libs) to try an figure how how to build the newest versions of these. Turns out the cyrus-sasl-libs haven&#8217;t been updated for a long time, the latest version is 2.1.25 and the one supplied in ipkg repo currently is 2.1.23-2. python-ldap 2.4.10 needs Cyrus SASL 2.1.x or newer so the supplied ipkg version is fine.<\/p>\n<p>Building openldap-2.4.35 (without slapd) to get the libraries:<br \/>\n<code>untar openldap-2.4.35.tar.gz<br \/>\ncd into openldap source<br \/>\nexport PATH=\/opt\/bin:$PATH<br \/>\n.\/configure --prefix=\/opt --disable-slapd<br \/>\nmake depend<br \/>\ncd libraries<br \/>\nmake<\/code><\/p>\n<p>Now you need to copy them into a directory structure to build the ipkg  &#8211; I found some instruction for this here <a href=\"http:\/\/www.oesf.org\/index.php?title=IPKG_Howto\" target=\"_blank\">http:\/\/www.oesf.org\/index.php?title=IPKG_Howto<\/a> (if you want to build the ipkg &#8211; if not you can just run make install from the libraries folder).<\/p>\n<p><code>mkdir -p \/share\/MD0_DATA\/lab\/ipkg_build\/openldap-libs\/ipkgroot\/opt\/include<br \/>\nmkdir -p \/share\/MD0_DATA\/lab\/ipkg_build\/openldap-libs\/ipkgroot\/opt\/lib<br \/>\n#(from the openldap libraries folder)<br \/>\ncp liblber\/.libs\/liblber-2.4.so.2.9.1 \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs\/ipkgroot\/opt\/lib\/<br \/>\ncp libldap\/.libs\/libldap-2.4.so.2.9.1 \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs\/ipkgroot\/opt\/lib\/<br \/>\ncp libldap_r\/.libs\/libldap_r-2.4.so.2.9.1 \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs\/ipkgroot\/opt\/lib\/<br \/>\n#create the links<br \/>\ncd \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs\/ipkgroot\/opt\/lib<br \/>\nln -s liblber-2.4.so.2.9.1 liblber-2.4.so.2<br \/>\nln -s liblber-2.4.so.2.9.1 liblber.so<br \/>\nln -s libldap-2.4.so.2.9.1 libldap-2.4.so.2<br \/>\nln -s libldap-2.4.so.2.9.1 libldap.so<br \/>\nln -s libldap_r-2.4.so.2.9.1 libldap_r-2.4.so.2<br \/>\nln -s libldap_r-2.4.so.2.9.1 libldap_r.so<\/p>\n<p># now the header files<br \/>\ncd into the openldap source folder<br \/>\ncd include<br \/>\ncp lber.h lber_types.h ldap.h ldap_cdefs.h ldap_features.h ldap_schema.h ldap_utf8.h slapi-plugin.h \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs\/ipkgroot\/opt\/include\/<\/p>\n<p># create the ipkg control file<br \/>\ncd \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs\/ipkgroot\/<br \/>\nmkdir CONTROL<br \/>\ncd CONTROL<br \/>\nvi control<br \/>\n# add the following:<br \/>\nPackage: openldap-libs<br \/>\nArchitecture: arm<br \/>\nPriority: optional<br \/>\nSection: net<br \/>\nVersion: 2.4.35<br \/>\nMaintainer: Your Name <your email address><br \/>\nSource: ftp:\/\/ftp.openldap.org\/pub\/OpenLDAP\/openldap-release\/openldap-2.4.35.tgz<br \/>\nDescription: Open Lightweight Directory Access Protocol<br \/>\nDepends: openssl, libdb, gdbm, cyrus-sasl-libs, psmisc<br \/>\nConflicts:<\/p>\n<p># save and quit the file<\/p>\n<p># now you need to compile the python modules:<br \/>\ncd \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs<\/p>\n<p># now create the ipkg<\/p>\n<p># make sure the permissions are correct:<br \/>\n# find all directories and make them readable by everyone<br \/>\nfind ipkgroot\/ -type d -exec chmod 755 '{}' \\;<br \/>\n# find all files and make them readable<br \/>\nfind ipkgroot\/ -type f -exec chmod og+r '{}' \\;<\/p>\n<p>ipkg-build.sh ipkgroot<br \/>\n<\/code><br \/>\nYou should now have a file named &#8216;openldap-libs_2.4.35_arm.ipk&#8217; in \/share\/MD0_DATA\/lab\/ipkg_builds\/openldap-libs<br \/>\nYou can install this using ipkg:<br \/>\n<code>ipkg install openldap-libs_2.4.35_arm.ipk<\/code><br \/>\nI&#8217;ve also uploaded this ipkg to <a href=\"http:\/\/www.massey.ac.nz\/~fherbert\/ipkg\/optware\/cs08q1armel\/cross\/unstable\/openldap-libs_2.4.35_arm.ipk\" target=\"_blank\">http:\/\/www.massey.ac.nz\/~fherbert\/ipkg\/optware\/cs08q1armel\/cross\/unstable\/openldap-libs_2.4.35_arm.ipk<\/a><\/p>\n<p>So now, back to building python-ldap. Change back into the python-ldap source directory and run &#8216;python setup.py build&#8217; and this time it built, Yay!<\/p>\n<p>Once the build is complete, you can either just run python setup.py install and you are done, or use create an ipkg.<\/p>\n<p><strong><\/p>\n<ul>\nCreating the python-ldap ipkg<\/ul>\n<p><\/strong><\/p>\n<p><code><br \/>\nmkdir -p \/share\/MD0_DATA\/lab\/ipkg_builds\/python-ldap\/ipkgroot\/opt\/lib\/python2.5\/site-packages<br \/>\ncd \/share\/MD0_DATA\/lab\/ipkg_builds\/python-ldap<br \/>\ncp -a python-ldap-2.4.10\/build\/lib.linux-armv5tel-2.5\/* ipkgroot\/opt\/lib\/python2.5\/site-packages\/<br \/>\n# now get the demos<br \/>\nmkdir -p ipkgroot\/opt\/share\/doc\/python-ldap-2.4.10<br \/>\ncp -a python-ldap-2.4.10\/Demo ipkgroot\/opt\/share\/doc\/python-ldap-2.4.10\/<br \/>\n# get the licence, readme and todo<br \/>\ncp -a python-ldap-2.4.10\/LICENCE python-ldap-2.4.10\/README python-ldap-2.4.10\/TODO ipkgroot\/opt\/share\/doc\/python-ldap-2.4.10\/<br \/>\n# finally the egg file<br \/>\ncp -a python-ldap-2.4.10\/Lib\/python_ldap.egg-info\/PKG-INFO ipkgroot\/opt\/lib\/python2.5\/site-packages\/python-ldap-2.4.10-py2.5.egg-info<\/p>\n<p># start python from the command line and enter:<\/p>\n<p>import compileall<br \/>\ncompileall.compile_dir('site-packages', force=True)<\/p>\n<p># This will go through the site-packages directory recursively and compile all the .py files.<\/p>\n<p># create the control file<br \/>\nmkdir ipkgroot\/CONTROL<br \/>\nvi ipkgroot\/CONTROL\/control<\/p>\n<p># add the following to that file<br \/>\nPackage: py25-python-ldap<br \/>\nArchitecture: arm<br \/>\nPriority: optional<br \/>\nSection: misc<br \/>\nVersion: 2.4.10<br \/>\nMaintainer: Your Name <you email address><br \/>\nSource: https:\/\/pypi.python.org\/packages\/source\/p\/python-ldap\/python-ldap-2.4.10.tar.gz<br \/>\nDescription: Provides an object-oriented API to access LDAP directory servers from Python programs. Mainly it wraps the OpenLDAP 2.x libs for that purpose. Additionally the package contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs, LDAPv3 schema, LDAPv3 extended operations and controls, etc.).<br \/>\nDepends: python25<br \/>\nConflicts:<\/p>\n<p># write and quit the file<br \/>\n# now create the ipkg<br \/>\n# make sure the permissions are correct:<br \/>\n# find all directories and make them readable by everyone<br \/>\nfind ipkgroot\/ -type d -exec chmod 755 '{}' \\;<br \/>\n# find all files and make them readable<br \/>\nfind ipkgroot\/ -type f -exec chmod og+r '{}' \\;<br \/>\nipkg-build.sh ipkgroot<br \/>\n<\/code><br \/>\nYou will now have py25-python-ldap_2.4.10_arm.ipk in you current directory which you can do whatever you like with.<br \/>\nI&#8217;ve also created packages for python 2.6 and 2.7, they are all available to download from here:<br \/>\n<a href=\"http:\/\/www.massey.ac.nz\/~fherbert\/ipkg\/optware\/cs08q1armel\/cross\/unstable\/py25-python-ldap_2.4.10_arm.ipk\" target=\"_blank\">py25-python-ldap_2.4.10_arm.ipk<\/a><br \/>\n<a href=\"http:\/\/www.massey.ac.nz\/~fherbert\/ipkg\/optware\/cs08q1armel\/cross\/unstable\/py26-python-ldap_2.4.10_arm.ipk\" target=\"_blank\">py26-python-ldap_2.4.10_arm.ipk<\/a><br \/>\n<a href=\"http:\/\/www.massey.ac.nz\/~fherbert\/ipkg\/optware\/cs08q1armel\/cross\/unstable\/py27-python-ldap_2.4.10_arm.ipk\" target=\"_blank\">py27-python-ldap_2.4.10_arm.ipk<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m using ipkg to install some of the requirements, so check the QNAP site to see how to enable the use of this. The python-ldap module requires a compile of some modules so you need some headers. These can be &hellip; <a href=\"https:\/\/www.herbert.org.nz\/?p=147\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[9],"tags":[],"class_list":["post-147","post","type-post","status-publish","format-standard","hentry","category-qnap"],"_links":{"self":[{"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=\/wp\/v2\/posts\/147","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=147"}],"version-history":[{"count":28,"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions"}],"predecessor-version":[{"id":180,"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=\/wp\/v2\/posts\/147\/revisions\/180"}],"wp:attachment":[{"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.herbert.org.nz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}