summaryrefslogtreecommitdiff
path: root/libcli
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2009-02-24 12:50:43 +0100
committerStefan Metzmacher <metze@samba.org>2009-02-24 17:55:40 +0100
commit18b30e5646d7a484c1714eac9b9ce1f8c1a8241a (patch)
tree378d1ebe074f898e28a70f210ec1033ab4ebbd9c /libcli
parent7aaec963c1764869b042240fb5b5d6a339ee052b (diff)
downloadsamba-18b30e5646d7a484c1714eac9b9ce1f8c1a8241a.tar.gz
samba-18b30e5646d7a484c1714eac9b9ce1f8c1a8241a.tar.bz2
samba-18b30e5646d7a484c1714eac9b9ce1f8c1a8241a.zip
libcli/ldap: move ldap_ndr from source4/ to toplevel
metze
Diffstat (limited to 'libcli')
-rw-r--r--libcli/ldap/config.mk10
-rw-r--r--libcli/ldap/ldap_ndr.c96
-rw-r--r--libcli/ldap/ldap_ndr.h12
3 files changed, 117 insertions, 1 deletions
diff --git a/libcli/ldap/config.mk b/libcli/ldap/config.mk
index 02397cb43a..22cad8cfbc 100644
--- a/libcli/ldap/config.mk
+++ b/libcli/ldap/config.mk
@@ -1,7 +1,15 @@
[SUBSYSTEM::LIBCLI_LDAP_MESSAGE]
PUBLIC_DEPENDENCIES = LIBSAMBA-ERRORS LIBTALLOC LIBLDB
-PRIVATE_DEPENDENCIES = ASN1_UTIL
+PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL ASN1_UTIL
LIBCLI_LDAP_MESSAGE_OBJ_FILES = $(addprefix ../libcli/ldap/, \
ldap_message.o)
PUBLIC_HEADERS += ../libcli/ldap/ldap_message.h ../libcli/ldap/ldap_errors.h
+
+[SUBSYSTEM::LIBCLI_LDAP_NDR]
+PUBLIC_DEPENDENCIES = LIBSAMBA-ERRORS LIBTALLOC
+PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL LIBLDB NDR_MISC NDR_SECURITY
+
+LIBCLI_LDAP_NDR_OBJ_FILES = ../libcli/ldap/ldap_ndr.o
+PUBLIC_HEADERS += ../libcli/ldap/ldap_ndr.h
+
diff --git a/libcli/ldap/ldap_ndr.c b/libcli/ldap/ldap_ndr.c
new file mode 100644
index 0000000000..dd820ff8d5
--- /dev/null
+++ b/libcli/ldap/ldap_ndr.c
@@ -0,0 +1,96 @@
+/*
+ Unix SMB/CIFS mplementation.
+
+ wrap/unwrap NDR encoded elements for ldap calls
+
+ Copyright (C) Andrew Tridgell 2005
+
+ 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; either version 3 of the License, or
+ (at your option) any later version.
+
+ 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, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "includes.h"
+#include "lib/ldb/include/ldb.h"
+#include "librpc/gen_ndr/ndr_security.h"
+#include "librpc/gen_ndr/ndr_misc.h"
+#include "libcli/ldap/ldap_ndr.h"
+
+/*
+ encode a NDR uint32 as a ldap filter element
+*/
+char *ldap_encode_ndr_uint32(TALLOC_CTX *mem_ctx, uint32_t value)
+{
+ uint8_t buf[4];
+ struct ldb_val val;
+ SIVAL(buf, 0, value);
+ val.data = buf;
+ val.length = 4;
+ return ldb_binary_encode(mem_ctx, val);
+}
+
+/*
+ encode a NDR dom_sid as a ldap filter element
+*/
+char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
+{
+ DATA_BLOB blob;
+ enum ndr_err_code ndr_err;
+ char *ret;
+ ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, sid,
+ (ndr_push_flags_fn_t)ndr_push_dom_sid);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ return NULL;
+ }
+ ret = ldb_binary_encode(mem_ctx, blob);
+ data_blob_free(&blob);
+ return ret;
+}
+
+
+/*
+ encode a NDR GUID as a ldap filter element
+*/
+char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, struct GUID *guid)
+{
+ DATA_BLOB blob;
+ enum ndr_err_code ndr_err;
+ char *ret;
+ ndr_err = ndr_push_struct_blob(&blob, mem_ctx, NULL, guid,
+ (ndr_push_flags_fn_t)ndr_push_GUID);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ return NULL;
+ }
+ ret = ldb_binary_encode(mem_ctx, blob);
+ data_blob_free(&blob);
+ return ret;
+}
+
+/*
+ decode a NDR GUID from a ldap filter element
+*/
+NTSTATUS ldap_decode_ndr_GUID(TALLOC_CTX *mem_ctx, struct ldb_val val, struct GUID *guid)
+{
+ DATA_BLOB blob;
+ enum ndr_err_code ndr_err;
+
+ blob.data = val.data;
+ blob.length = val.length;
+ ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, guid,
+ (ndr_pull_flags_fn_t)ndr_pull_GUID);
+ talloc_free(val.data);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ return ndr_map_error2ntstatus(ndr_err);
+ }
+ return NT_STATUS_OK;
+}
diff --git a/libcli/ldap/ldap_ndr.h b/libcli/ldap/ldap_ndr.h
new file mode 100644
index 0000000000..ee1f702c78
--- /dev/null
+++ b/libcli/ldap/ldap_ndr.h
@@ -0,0 +1,12 @@
+#ifndef __LIBCLI_LDAP_LDAP_NDR_H__
+#define __LIBCLI_LDAP_LDAP_NDR_H__
+
+#include "librpc/gen_ndr/ndr_misc.h"
+
+char *ldap_encode_ndr_uint32(TALLOC_CTX *mem_ctx, uint32_t value);
+char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid);
+char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, struct GUID *guid);
+NTSTATUS ldap_decode_ndr_GUID(TALLOC_CTX *mem_ctx, struct ldb_val val, struct GUID *guid);
+
+#endif /* __LIBCLI_LDAP_LDAP_NDR_H__ */
+