summaryrefslogtreecommitdiffstats
path: root/ipa_server/conn.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-24 19:56:07 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-24 19:56:07 +0000
commit63a26bd604c3d1421d07fe8737953101409e0fad (patch)
tree3515ec30858e980f62bc94512644b12418b48a74 /ipa_server/conn.py
parentf8bb60f02dc3cbb48c2cc6305e095e6936f5a0d6 (diff)
downloadfreeipa-63a26bd604c3d1421d07fe8737953101409e0fad.tar.gz
freeipa-63a26bd604c3d1421d07fe8737953101409e0fad.tar.xz
freeipa-63a26bd604c3d1421d07fe8737953101409e0fad.zip
345: Moved server code from Rob into ipa_server/ package
Diffstat (limited to 'ipa_server/conn.py')
-rw-r--r--ipa_server/conn.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/ipa_server/conn.py b/ipa_server/conn.py
new file mode 100644
index 000000000..f8f5306fa
--- /dev/null
+++ b/ipa_server/conn.py
@@ -0,0 +1,72 @@
+# Authors: Rob Crittenden <rcritten@redhat.com>
+#
+# Copyright (C) 2008 Red Hat
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2 only
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+import krbV
+import threading
+import ldap
+import ldap.dn
+from ipalib import ipaldap
+
+context = threading.local()
+
+class IPAConn:
+ def __init__(self, host, port, krbccache, debug=None):
+ self._conn = None
+
+ # Save the arguments
+ self._host = host
+ self._port = port
+ self._krbccache = krbccache
+ self._debug = debug
+
+ self._ctx = krbV.default_context()
+
+ ccache = krbV.CCache(name=krbccache, context=self._ctx)
+ cprinc = ccache.principal()
+
+ self._conn = ipaldap.IPAdmin(host,port,None,None,None,debug)
+
+ # This will bind the connection
+ try:
+ self._conn.set_krbccache(krbccache, cprinc.name)
+ except ldap.UNWILLING_TO_PERFORM, e:
+ raise e
+ except Exception, e:
+ raise e
+
+ def __del__(self):
+ # take no chances on unreleased connections
+ self.releaseConn()
+
+ def getConn(self):
+ return self._conn
+
+ def releaseConn(self):
+ if self._conn is None:
+ return
+
+ self._conn.unbind_s()
+ self._conn = None
+
+ return
+
+if __name__ == "__main__":
+ ipaconn = IPAConn("localhost", 389, "FILE:/tmp/krb5cc_500")
+ x = ipaconn.getConn().getEntry("dc=example,dc=com", ldap.SCOPE_SUBTREE, "uid=admin", ["cn"])
+ print "%s" % x