~ubuntu-branches/ubuntu/vivid/samba/vivid

« back to all changes in this revision

Viewing changes to source3/lib/tldap_util.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2011-12-21 13:18:04 UTC
  • mfrom: (0.39.21 sid)
  • Revision ID: package-import@ubuntu.com-20111221131804-xtlr39wx6njehxxr
Tags: 2:3.6.1-3ubuntu1
* Merge from Debian testing.  Remaining changes:
  + debian/patches/VERSION.patch:
    - set SAMBA_VERSION_SUFFIX to Ubuntu.
  + debian/patches/error-trans.fix-276472:
    - Add the translation of Unix Error code -ENOTSUP to NT Error Code
    - NT_STATUS_NOT_SUPPORTED to prevent the Permission denied error.
  + debian/smb.conf:
    - add "(Samba, Ubuntu)" to server string.
    - comment out the default [homes] share, and add a comment about
      "valid users = %S" to show users how to restrict access to
      \\server\username to only username.
    - Set 'usershare allow guests', so that usershare admins are 
      allowed to create public shares in addition to authenticated
      ones.
    - add map to guest = Bad user, maps bad username to guest access.
  + debian/samba-common.config:
    - Do not change priority to high if dhclient3 is installed.
    - Use priority medium instead of high for the workgroup question.
  + debian/control:
    - Don't build against or suggest ctdb.
    - Add dependency on samba-common-bin to samba.
  + Add ufw integration:
    - Created debian/samba.ufw.profile
    - debian/rules, debian/samba.dirs, debian/samba.files: install
      profile
    - debian/control: have samba suggest ufw
  + Add apport hook:
    - Created debian/source_samba.py.
    - debian/rules, debian/samba.dirs, debian/samba-common-bin.files: install
  + Switch to upstart:
    - Add debian/samba.{nmbd,smbd}.upstart.
  + debian/samba.logrotate, debian/samba-common.dhcp, debian/samba.if-up:
    - Make them upstart compatible
  + debian/samba.postinst: 
    - Avoid scary pdbedit warnings on first import.
  + debian/samba-common.postinst: Add more informative error message for
    the case where smb.conf was manually deleted
  + debian/patches/fix-debuglevel-name-conflict.patch: don't use 'debug_level'
    as a global variable name in an NSS module 
  + Dropped:
    - debian/patches/error-trans.fix-276472
    - debian/patches/fix-debuglevel-name-conflict.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
*/
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
        }
31
36
 
51
56
        if (attribute == NULL) {
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
        }
57
62
        if (num_values != 1) {
103
108
}
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);
109
114
        int i;
128
133
        return true;
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;
136
142
        struct tldap_mod *mods = *pmods;
144
150
                return false;
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++) {
150
156
                if ((mods[i].mod_op == mod_op)
166
172
        }
167
173
 
168
174
        if ((num_newvals != 0)
169
 
            && !tldap_add_blob_vals(mods, mod, num_newvals, newvals)) {
 
175
            && !tldap_add_blob_vals(mods, mod, newvals, num_newvals)) {
170
176
                return false;
171
177
        }
172
178
 
173
 
        if (i == num_mods) {
 
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);
176
182
                if (mods == NULL) {
180
186
        }
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
{
189
197
        DATA_BLOB utf8;
195
203
                return false;
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;
201
210
}
202
211
 
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,
208
217
                                                      const DATA_BLOB *d2))
212
221
        DATA_BLOB oldval = data_blob_null;
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) {
218
227
                        /* can't change multivalue attributes atm */
228
237
                /* Believe it or not, but LDAP will deny a delete and
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;
234
243
        }
242
251
                 * Novell NDS. In NDS you have to first remove attribute and
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
                }
251
261
        }
255
265
           the old value, should it exist. */
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, pnum_mods, pmods,
 
283
        return tldap_make_mod_blob_int(existing, mem_ctx, pmods, pnum_mods,
274
284
                                       attrib, newval, data_blob_cmp);
275
285
}
276
286
 
298
308
}
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
{
304
314
        va_list ap;
318
328
        if (blob.length != 0) {
319
329
                blob.data = CONST_DISCARD(uint8_t *, newval);
320
330
        }
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,
322
332
                                      attrib, blob, compare_utf8_blobs);
323
333
        TALLOC_FREE(newval);
324
334
        return ret;
329
339
        const char *ld_error = NULL;
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),
335
347
                              ld_error ? ld_error : "unknown");
539
551
        int i, num_values;
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
        }
545
557
        for (i=0; i<num_values; i++) {