Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source3/lib/tldap_util.c

    r414 r745  
    1919
    2020#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"
    2126
    2227bool tldap_entry_values(struct tldap_message *msg, const char *attribute,
    23                         int *num_values, DATA_BLOB **values)
     28                        DATA_BLOB **values, int *num_values)
    2429{
    2530        struct tldap_attribute *attributes;
    2631        int i, num_attributes;
    2732
    28         if (!tldap_entry_attributes(msg, &num_attributes, &attributes)) {
     33        if (!tldap_entry_attributes(msg, &attributes, &num_attributes)) {
    2934                return false;
    3035        }
     
    5257                return NULL;
    5358        }
    54         if (!tldap_entry_values(msg, attribute, &num_values, &values)) {
     59        if (!tldap_entry_values(msg, attribute, &values, &num_values)) {
    5560                return NULL;
    5661        }
     
    104109
    105110static 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)
    107112{
    108113        int num_values = talloc_array_length(mod->values);
     
    129134}
    130135
    131 bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
     136bool tldap_add_mod_blobs(TALLOC_CTX *mem_ctx,
     137                         struct tldap_mod **pmods, int *pnum_mods,
    132138                         int mod_op, const char *attrib,
    133                          int num_newvals, DATA_BLOB *newvals)
     139                         DATA_BLOB *newvals, int num_newvals)
    134140{
    135141        struct tldap_mod new_mod;
     
    145151        }
    146152
    147         num_mods = talloc_array_length(mods);
     153        num_mods = *pnum_mods;
    148154
    149155        for (i=0; i<num_mods; i++) {
     
    167173
    168174        if ((num_newvals != 0)
    169             && !tldap_add_blob_vals(mods, mod, num_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)) {
    174180                mods = talloc_realloc(talloc_tos(), mods, struct tldap_mod,
    175181                                      num_mods+1);
     
    181187
    182188        *pmods = mods;
     189        *pnum_mods += 1;
    183190        return true;
    184191}
    185192
    186 bool tldap_add_mod_str(TALLOC_CTX *mem_ctx, struct tldap_mod **pmods,
     193bool tldap_add_mod_str(TALLOC_CTX *mem_ctx,
     194                       struct tldap_mod **pmods, int *pnum_mods,
    187195                       int mod_op, const char *attrib, const char *str)
    188196{
     
    196204        }
    197205
    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);
    199208        TALLOC_FREE(utf8.data);
    200209        return ret;
     
    203212static bool tldap_make_mod_blob_int(struct tldap_message *existing,
    204213                                    TALLOC_CTX *mem_ctx,
    205                                     int *pnum_mods, struct tldap_mod **pmods,
     214                                    struct tldap_mod **pmods, int *pnum_mods,
    206215                                    const char *attrib, DATA_BLOB newval,
    207216                                    int (*comparison)(const DATA_BLOB *d1,
     
    213222
    214223        if ((existing != NULL)
    215             && tldap_entry_values(existing, attrib, &num_values, &values)) {
     224            && tldap_entry_values(existing, attrib, &values, &num_values)) {
    216225
    217226                if (num_values > 1) {
     
    229238                   an add at the same time if the values are the
    230239                   same... */
    231                 DEBUG(10,("smbldap_make_mod_blob: attribute |%s| not "
     240                DEBUG(10,("tldap_make_mod_blob_int: attribute |%s| not "
    232241                          "changed.\n", attrib));
    233242                return true;
     
    243252                 * then you could add new value */
    244253
    245                 DEBUG(10, ("smbldap_make_mod_blob: deleting attribute |%s|\n",
     254                DEBUG(10, ("tldap_make_mod_blob_int: deleting attribute |%s|\n",
    246255                           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)) {
    249259                        return false;
    250260                }
     
    256266
    257267        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 "
    259269                           "%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)) {
    262273                        return false;
    263274                }
    264275        }
    265         *pnum_mods = talloc_array_length(*pmods);
    266276        return true;
    267277}
    268278
    269279bool 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,
    271281                         const char *attrib, DATA_BLOB newval)
    272282{
    273         return tldap_make_mod_blob_int(existing, mem_ctx, pnum_mods, pmods,
     283        return tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods,
    274284                                       attrib, newval, data_blob_cmp);
    275285}
     
    299309
    300310bool 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,
    302312                        const char *attrib, const char *fmt, ...)
    303313{
     
    319329                blob.data = CONST_DISCARD(uint8_t *, newval);
    320330        }
    321         ret = tldap_make_mod_blob_int(existing, mem_ctx, pnum_mods, pmods,
     331        ret = tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods,
    322332                                      attrib, blob, compare_utf8_blobs);
    323333        TALLOC_FREE(newval);
     
    330340        char *res;
    331341
    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        }
    333345        res = talloc_asprintf(mem_ctx, "LDAP error %d (%s), %s", rc,
    334346                              tldap_err2string(rc),
     
    540552        DATA_BLOB *values;
    541553
    542         if (!tldap_entry_values(msg, attribute, &num_values, &values)) {
     554        if (!tldap_entry_values(msg, attribute, &values, &num_values)) {
    543555                return false;
    544556        }
Note: See TracChangeset for help on using the changeset viewer.