Coverage Report

Created: 2026-04-01 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/samba/libcli/ldap/ldap_ndr.c
Line
Count
Source
1
/* 
2
   Unix SMB/CIFS implementation.
3
4
   wrap/unwrap NDR encoded elements for ldap calls
5
   
6
   Copyright (C) Andrew Tridgell  2005
7
    
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.
12
   
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.
17
   
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/>.
20
   
21
*/
22
23
#include "includes.h"
24
#include <ldb.h>
25
#include "librpc/gen_ndr/ndr_security.h"
26
#include "librpc/gen_ndr/ndr_misc.h"
27
#include "libcli/ldap/ldap_ndr.h"
28
29
/*
30
  encode a NDR uint32 as a ldap filter element
31
*/
32
char *ldap_encode_ndr_uint32(TALLOC_CTX *mem_ctx, uint32_t value)
33
0
{
34
0
  uint8_t buf[4];
35
0
  struct ldb_val val;
36
0
  SIVAL(buf, 0, value);
37
0
  val.data = buf;
38
0
  val.length = 4;
39
0
  return ldb_binary_encode(mem_ctx, val);
40
0
}
41
42
/*
43
  encode a NDR dom_sid as a ldap filter element
44
*/
45
char *ldap_encode_ndr_dom_sid(TALLOC_CTX *mem_ctx, const struct dom_sid *sid)
46
0
{
47
0
  uint8_t buf[ndr_size_dom_sid(sid, 0)];
48
0
  DATA_BLOB blob = {.data = buf, .length = sizeof(buf)};
49
0
  enum ndr_err_code ndr_err;
50
0
  char *ret;
51
52
0
  ndr_err = ndr_push_struct_into_fixed_blob(
53
0
    &blob, sid, (ndr_push_flags_fn_t)ndr_push_dom_sid);
54
0
  if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
55
0
    return NULL;
56
0
  }
57
0
  ret = ldb_binary_encode(mem_ctx, blob);
58
0
  return ret;
59
0
}
60
61
62
/*
63
  encode a NDR GUID as a ldap filter element
64
*/
65
char *ldap_encode_ndr_GUID(TALLOC_CTX *mem_ctx, const struct GUID *guid)
66
0
{
67
0
  struct GUID_ndr_buf buf = { .buf = {0}, };
68
0
  DATA_BLOB blob = { .data = buf.buf, .length = sizeof(buf.buf), };
69
0
  char *ret;
70
0
  GUID_to_ndr_buf(guid, &buf);
71
0
  ret = ldb_binary_encode(mem_ctx, blob);
72
0
  return ret;
73
0
}
74
75
/*
76
  decode a NDR GUID from a ldap filter element
77
*/
78
NTSTATUS ldap_decode_ndr_GUID(TALLOC_CTX *mem_ctx, struct ldb_val val, struct GUID *guid)
79
0
{
80
0
  DATA_BLOB blob;
81
0
  enum ndr_err_code ndr_err;
82
83
0
  blob.data = val.data;
84
0
  blob.length = val.length;
85
0
  ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, guid,
86
0
               (ndr_pull_flags_fn_t)ndr_pull_GUID);
87
0
  talloc_free(val.data);
88
0
  if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
89
0
    return ndr_map_error2ntstatus(ndr_err);
90
0
  }
91
0
  return NT_STATUS_OK;
92
0
}