r12607: fix the build
[abartlet/samba.git/.git] / source4 / libcli / ldap / ldap_msg.c
1 /* 
2    Unix SMB/CIFS mplementation.
3
4    LDAP protocol helper functions for SAMBA
5    
6    Copyright (C) Andrew Tridgell  2005
7    Copyright (C) Volker Lendecke 2004
8     
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22    
23 */
24
25 #include "includes.h"
26 #include "libcli/ldap/ldap.h"
27 #include "libcli/ldap/ldap_client.h"
28
29
30 struct ldap_message *new_ldap_message(TALLOC_CTX *mem_ctx)
31 {
32         return talloc(mem_ctx, struct ldap_message);
33 }
34
35
36 BOOL add_value_to_attrib(TALLOC_CTX *mem_ctx, struct ldb_val *value,
37                          struct ldb_message_element *attrib)
38 {
39         attrib->values = talloc_realloc(mem_ctx, 
40                                           attrib->values,
41                                           DATA_BLOB,
42                                           attrib->num_values+1);
43         if (attrib->values == NULL)
44                 return False;
45
46         attrib->values[attrib->num_values].data = talloc_steal(attrib->values, 
47                                                                value->data);
48         attrib->values[attrib->num_values].length = value->length;
49         attrib->num_values += 1;
50         return True;
51 }
52
53 BOOL add_attrib_to_array_talloc(TALLOC_CTX *mem_ctx,
54                                        const struct ldb_message_element *attrib,
55                                        struct ldb_message_element **attribs,
56                                        int *num_attribs)
57 {
58         *attribs = talloc_realloc(mem_ctx,
59                                     *attribs,
60                                     struct ldb_message_element,
61                                     *num_attribs+1);
62
63         if (*attribs == NULL)
64                 return False;
65
66         (*attribs)[*num_attribs] = *attrib;
67         talloc_steal(*attribs, attrib->values);
68         talloc_steal(*attribs, attrib->name);
69         *num_attribs += 1;
70         return True;
71 }
72
73 BOOL add_mod_to_array_talloc(TALLOC_CTX *mem_ctx,
74                                     struct ldap_mod *mod,
75                                     struct ldap_mod **mods,
76                                     int *num_mods)
77 {
78         *mods = talloc_realloc(mem_ctx, *mods, struct ldap_mod, (*num_mods)+1);
79
80         if (*mods == NULL)
81                 return False;
82
83         (*mods)[*num_mods] = *mod;
84         *num_mods += 1;
85         return True;
86 }
87