s3-autconf Move nmbd socket directory to PREFIX/var/nmbd
[Samba.git] / libcli / ldap / ldap_ndr.c
blobf77a6f2c3d2c5197c5bceb6871602a8f668c7b3f
1 /*
2 Unix SMB/CIFS mplementation.
4 wrap/unwrap NDR encoded elements for ldap calls
6 Copyright (C) Andrew Tridgell 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #if _SAMBA_BUILD_ == 3
25 #include "lib/ldb_compat.h"
26 #else
27 #include <ldb.h>
28 #endif
29 #include "librpc/gen_ndr/ndr_security.h"
30 #include "librpc/gen_ndr/ndr_misc.h"
31 #include "libcli/ldap/ldap_ndr.h"
34 encode a NDR uint32 as a ldap filter element
36 char *ldap_encode_ndr_uint32(TALLOC_CTX *mem_ctx, uint32_t value)
38 uint8_t buf[4];
39 struct ldb_val val;
40 SIVAL(buf, 0, value);
41 val.data = buf;
42 val.length = 4;
43 return ldb_binary_encode(mem_ctx, val);
47 encode a NDR dom_sid as a ldap filter element
49 char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
51 DATA_BLOB blob;
52 enum ndr_err_code ndr_err;
53 char *ret;
54 ndr_err = ndr_push_struct_blob(&blob, mem_ctx, sid,
55 (ndr_push_flags_fn_t)ndr_push_dom_sid);
56 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
57 return NULL;
59 ret = ldb_binary_encode(mem_ctx, blob);
60 data_blob_free(&blob);
61 return ret;
66 encode a NDR GUID as a ldap filter element
68 char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, const struct GUID *guid)
70 DATA_BLOB blob;
71 NTSTATUS status;
72 char *ret;
73 status = GUID_to_ndr_blob(guid, mem_ctx, &blob);
74 if (!NT_STATUS_IS_OK(status)) {
75 return NULL;
77 ret = ldb_binary_encode(mem_ctx, blob);
78 data_blob_free(&blob);
79 return ret;
83 decode a NDR GUID from a ldap filter element
85 NTSTATUS ldap_decode_ndr_GUID(TALLOC_CTX *mem_ctx, struct ldb_val val, struct GUID *guid)
87 DATA_BLOB blob;
88 enum ndr_err_code ndr_err;
90 blob.data = val.data;
91 blob.length = val.length;
92 ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, guid,
93 (ndr_pull_flags_fn_t)ndr_pull_GUID);
94 talloc_free(val.data);
95 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
96 return ndr_map_error2ntstatus(ndr_err);
98 return NT_STATUS_OK;