Changeset 745 for trunk/server/source3/lib/tldap_util.c
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source3/lib/tldap_util.c
r414 r745 19 19 20 20 #include "includes.h" 21 #include "tldap.h" 22 #include "tldap_util.h" 23 #include "../libcli/security/security.h" 24 #include "../lib/util/asn1.h" 25 #include "../librpc/ndr/libndr.h" 21 26 22 27 bool tldap_entry_values(struct tldap_message *msg, const char *attribute, 23 int *num_values, DATA_BLOB **values)28 DATA_BLOB **values, int *num_values) 24 29 { 25 30 struct tldap_attribute *attributes; 26 31 int i, num_attributes; 27 32 28 if (!tldap_entry_attributes(msg, & num_attributes, &attributes)) {33 if (!tldap_entry_attributes(msg, &attributes, &num_attributes)) { 29 34 return false; 30 35 } … … 52 57 return NULL; 53 58 } 54 if (!tldap_entry_values(msg, attribute, & num_values, &values)) {59 if (!tldap_entry_values(msg, attribute, &values, &num_values)) { 55 60 return NULL; 56 61 } … … 104 109 105 110 static bool tldap_add_blob_vals(TALLOC_CTX *mem_ctx, struct tldap_mod *mod, 106 int num_newvals, DATA_BLOB *newvals)111 DATA_BLOB *newvals, int num_newvals) 107 112 { 108 113 int num_values = talloc_array_length(mod->values); … … 129 134 } 130 135 131 bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods, 136 bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, 137 struct tldap_mod **pmods, int *pnum_mods, 132 138 int mod_op, const char *attrib, 133 int num_newvals, DATA_BLOB *newvals)139 DATA_BLOB *newvals, int num_newvals) 134 140 { 135 141 struct tldap_mod new_mod; … … 145 151 } 146 152 147 num_mods = talloc_array_length(mods);153 num_mods = *pnum_mods; 148 154 149 155 for (i=0; i<num_mods; i++) { … … 167 173 168 174 if ((num_newvals != 0) 169 && !tldap_add_blob_vals(mods, mod, n um_newvals,newvals)) {170 return false; 171 } 172 173 if ( i == num_mods) {175 && !tldap_add_blob_vals(mods, mod, newvals, num_newvals)) { 176 return false; 177 } 178 179 if ((i == num_mods) && (talloc_array_length(mods) < num_mods + 1)) { 174 180 mods = talloc_realloc(talloc_tos(), mods, struct tldap_mod, 175 181 num_mods+1); … … 181 187 182 188 *pmods = mods; 189 *pnum_mods += 1; 183 190 return true; 184 191 } 185 192 186 bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods, 193 bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, 194 struct tldap_mod **pmods, int *pnum_mods, 187 195 int mod_op, const char *attrib, const char *str) 188 196 { … … 196 204 } 197 205 198 ret = tldap_add_mod_blobs(mem_ctx, pmods, mod_op, attrib, 1, &utf8); 206 ret = tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods, mod_op, attrib, 207 &utf8, 1); 199 208 TALLOC_FREE(utf8.data); 200 209 return ret; … … 203 212 static bool tldap_make_mod_blob_int(struct tldap_message *existing, 204 213 TALLOC_CTX *mem_ctx, 205 int *pnum_mods, struct tldap_mod **pmods,214 struct tldap_mod **pmods, int *pnum_mods, 206 215 const char *attrib, DATA_BLOB newval, 207 216 int (*comparison)(const DATA_BLOB *d1, … … 213 222 214 223 if ((existing != NULL) 215 && tldap_entry_values(existing, attrib, & num_values, &values)) {224 && tldap_entry_values(existing, attrib, &values, &num_values)) { 216 225 217 226 if (num_values > 1) { … … 229 238 an add at the same time if the values are the 230 239 same... */ 231 DEBUG(10,(" smbldap_make_mod_blob: attribute |%s| not "240 DEBUG(10,("tldap_make_mod_blob_int: attribute |%s| not " 232 241 "changed.\n", attrib)); 233 242 return true; … … 243 252 * then you could add new value */ 244 253 245 DEBUG(10, (" smbldap_make_mod_blob: deleting attribute |%s|\n",254 DEBUG(10, ("tldap_make_mod_blob_int: deleting attribute |%s|\n", 246 255 attrib)); 247 if (!tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_DELETE, 248 attrib, 1, &oldval)) { 256 if (!tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods, 257 TLDAP_MOD_DELETE, 258 attrib, &oldval, 1)) { 249 259 return false; 250 260 } … … 256 266 257 267 if (newval.data != NULL) { 258 DEBUG(10, (" smbldap_make_mod: adding attribute |%s| value len "268 DEBUG(10, ("tldap_make_mod_blob_int: adding attribute |%s| value len " 259 269 "%d\n", attrib, (int)newval.length)); 260 if (!tldap_add_mod_blobs(mem_ctx, pmods, TLDAP_MOD_ADD, 261 attrib, 1, &newval)) { 270 if (!tldap_add_mod_blobs(mem_ctx, pmods, pnum_mods, 271 TLDAP_MOD_ADD, 272 attrib, &newval, 1)) { 262 273 return false; 263 274 } 264 275 } 265 *pnum_mods = talloc_array_length(*pmods);266 276 return true; 267 277 } 268 278 269 279 bool tldap_make_mod_blob(struct tldap_message *existing, TALLOC_CTX *mem_ctx, 270 int *pnum_mods, struct tldap_mod **pmods,280 struct tldap_mod **pmods, int *pnum_mods, 271 281 const char *attrib, DATA_BLOB newval) 272 282 { 273 return tldap_make_mod_blob_int(existing, mem_ctx, p num_mods, pmods,283 return tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods, 274 284 attrib, newval, data_blob_cmp); 275 285 } … … 299 309 300 310 bool tldap_make_mod_fmt(struct tldap_message *existing, TALLOC_CTX *mem_ctx, 301 int *pnum_mods, struct tldap_mod **pmods,311 struct tldap_mod **pmods, int *pnum_mods, 302 312 const char *attrib, const char *fmt, ...) 303 313 { … … 319 329 blob.data = CONST_DISCARD(uint8_t *, newval); 320 330 } 321 ret = tldap_make_mod_blob_int(existing, mem_ctx, p num_mods, pmods,331 ret = tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods, 322 332 attrib, blob, compare_utf8_blobs); 323 333 TALLOC_FREE(newval); … … 330 340 char *res; 331 341 332 ld_error = tldap_msg_diagnosticmessage(tldap_ctx_lastmsg(ld)); 342 if (ld != NULL) { 343 ld_error = tldap_msg_diagnosticmessage(tldap_ctx_lastmsg(ld)); 344 } 333 345 res = talloc_asprintf(mem_ctx, "LDAP error %d (%s), %s", rc, 334 346 tldap_err2string(rc), … … 540 552 DATA_BLOB *values; 541 553 542 if (!tldap_entry_values(msg, attribute, & num_values, &values)) {554 if (!tldap_entry_values(msg, attribute, &values, &num_values)) { 543 555 return false; 544 556 }
Note:
See TracChangeset
for help on using the changeset viewer.