r6763: added functions in libcli/ldap/ to binary encode some NDR structures into
authorAndrew Tridgell <tridge@samba.org>
Fri, 13 May 2005 06:07:53 +0000 (06:07 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:16:42 +0000 (13:16 -0500)
ldap friendly filter strings

source/libcli/ldap/config.mk
source/libcli/ldap/ldap.c
source/libcli/ldap/ldap.h
source/libcli/ldap/ldap_ndr.c [new file with mode: 0644]

index 87bfdfdbba5fc57585f6a02b3f5b2e00ca1937a3..888590ec5ef306479f553bbff142aa348f87f2b8 100644 (file)
@@ -3,7 +3,8 @@
 [SUBSYSTEM::LIBCLI_LDAP]
 ADD_OBJ_FILES = libcli/ldap/ldap.o \
                libcli/ldap/ldap_client.o \
-               libcli/ldap/ldap_ldif.o
+               libcli/ldap/ldap_ldif.o \
+               libcli/ldap/ldap_ndr.o
 NOPROTO=YES
 # End SUBSYSTEM LIBCLI_LDAP
 #################################
index 9a8a7bb589cfeb96c17ecefd1dd851b4e1324b1a..cc7f1a10bcce00e38a4f1f08a2cff40a738f4146 100644 (file)
@@ -144,7 +144,7 @@ static struct ldap_val ldap_binary_decode(TALLOC_CTX *mem_ctx, const char *str)
    encode a blob as a RFC2254 binary string, escaping any
    non-printable or '\' characters
 */
-static const char *ldap_binary_encode(TALLOC_CTX *mem_ctx, DATA_BLOB blob)
+const char *ldap_binary_encode(TALLOC_CTX *mem_ctx, DATA_BLOB blob)
 {
        int i;
        char *ret;
@@ -1345,3 +1345,6 @@ struct ldap_parse_tree *ldap_parse_filter_string(TALLOC_CTX *mem_ctx,
 {
        return ldap_parse_filter(mem_ctx, &s);
 }
+
+
+
index 63d79628a9c6bd78455c6de97f75494c6f055fda..8d4294cf76442e616df5d1ffdeb9fd413c67f8fa 100644 (file)
@@ -325,6 +325,7 @@ BOOL ldap_parse_basic_url(TALLOC_CTX *mem_ctx, const char *url,
                          char **host, uint16_t *port, BOOL *ldaps);
 struct ldap_parse_tree *ldap_parse_filter_string(TALLOC_CTX *mem_ctx,
                                                 const char *s);
+const char *ldap_binary_encode(TALLOC_CTX *mem_ctx, DATA_BLOB blob);
 
 /* The following definitions come from libcli/ldap/ldap_client.c  */
 
@@ -378,4 +379,10 @@ BOOL add_mod_to_array_talloc(TALLOC_CTX *mem_ctx,
                                    int *num_mods);
 struct ldap_message *ldap_ldif2msg(TALLOC_CTX *mem_ctx, const char *s);
 
+/* The following definitions come from libcli/ldap/ldap_ndr.c  */
+
+const char *ldap_encode_ndr_uint32(TALLOC_CTX *mem_ctx, uint32_t value);
+const char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid);
+const char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, struct GUID *guid);
+
 #endif
diff --git a/source/libcli/ldap/ldap_ndr.c b/source/libcli/ldap/ldap_ndr.c
new file mode 100644 (file)
index 0000000..45d9b27
--- /dev/null
@@ -0,0 +1,76 @@
+/* 
+   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 2 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, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   
+*/
+
+#include "includes.h"
+#include "libcli/ldap/ldap.h"
+#include "librpc/gen_ndr/ndr_security.h"
+
+/*
+  encode a NDR uint32 as a ldap filter element
+*/
+const char *ldap_encode_ndr_uint32(TALLOC_CTX *mem_ctx, uint32_t value)
+{
+       uint8_t buf[4];
+       DATA_BLOB blob;
+       SIVAL(buf, 0, value);
+       blob.data = buf;
+       blob.length = 4;
+       return ldap_binary_encode(mem_ctx, blob);
+}
+
+/*
+  encode a NDR dom_sid as a ldap filter element
+*/
+const char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, struct dom_sid *sid)
+{
+       DATA_BLOB blob;
+       NTSTATUS status;
+       const char *ret;
+       status = ndr_push_struct_blob(&blob, mem_ctx, sid, 
+                                     (ndr_push_flags_fn_t)ndr_push_dom_sid);
+       if (!NT_STATUS_IS_OK(status)) {
+               return NULL;
+       }
+       ret = ldap_binary_encode(mem_ctx, blob);
+       data_blob_free(&blob);
+       return ret;
+}
+
+
+/*
+  encode a NDR GUID as a ldap filter element
+*/
+const char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, struct GUID *guid)
+{
+       DATA_BLOB blob;
+       NTSTATUS status;
+       const char *ret;
+       status = ndr_push_struct_blob(&blob, mem_ctx, guid, 
+                                     (ndr_push_flags_fn_t)ndr_push_GUID);
+       if (!NT_STATUS_IS_OK(status)) {
+               return NULL;
+       }
+       ret = ldap_binary_encode(mem_ctx, blob);
+       data_blob_free(&blob);
+       return ret;
+}