~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source4/dsdb/samdb/ldb_modules/extended_dn_in.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:
30
30
 */
31
31
 
32
32
#include "includes.h"
33
 
#include "ldb/include/ldb.h"
34
 
#include "ldb/include/ldb_errors.h"
35
 
#include "ldb/include/ldb_module.h"
 
33
#include <ldb.h>
 
34
#include <ldb_errors.h>
 
35
#include <ldb_module.h>
 
36
 
 
37
/*
 
38
  TODO: if relax is not set then we need to reject the fancy RMD_* and
 
39
  DELETED extended DN codes
 
40
 */
36
41
 
37
42
/* search */
38
43
struct extended_search_context {
80
85
        struct ldb_request *down_req;
81
86
        struct ldb_message_element *el;
82
87
        int ret;
83
 
        size_t i;
 
88
        unsigned int i;
84
89
        size_t wkn_len = 0;
85
90
        char *valstr = NULL;
86
91
        const char *found = NULL;
151
156
 
152
157
                if (!ac->basedn) {
153
158
                        const char *str = talloc_asprintf(req, "Base-DN '%s' not found",
154
 
                                                          ldb_dn_get_linearized(ac->req->op.search.base));
 
159
                                                          ldb_dn_get_extended_linearized(req, ac->req->op.search.base, 1));
155
160
                        ldb_set_errstring(ldb_module_get_ctx(ac->module), str);
156
161
                        return ldb_module_done(ac->req, NULL, NULL,
157
162
                                               LDB_ERR_NO_SUCH_OBJECT);
168
173
                                                      ac->req->controls,
169
174
                                                      ac, extended_final_callback, 
170
175
                                                      ac->req);
 
176
                        LDB_REQ_SET_LOCATION(down_req);
171
177
                        break;
172
178
                case LDB_ADD:
173
179
                {
186
192
                                                ac->req->controls,
187
193
                                                ac, extended_final_callback, 
188
194
                                                ac->req);
 
195
                        LDB_REQ_SET_LOCATION(down_req);
189
196
                        break;
190
197
                }
191
198
                case LDB_MODIFY:
205
212
                                                ac->req->controls,
206
213
                                                ac, extended_final_callback, 
207
214
                                                ac->req);
 
215
                        LDB_REQ_SET_LOCATION(down_req);
208
216
                        break;
209
217
                }
210
218
                case LDB_DELETE:
214
222
                                                ac->req->controls,
215
223
                                                ac, extended_final_callback, 
216
224
                                                ac->req);
 
225
                        LDB_REQ_SET_LOCATION(down_req);
217
226
                        break;
218
227
                case LDB_RENAME:
219
228
                        ret = ldb_build_rename_req(&down_req,
223
232
                                                   ac->req->controls,
224
233
                                                   ac, extended_final_callback, 
225
234
                                                   ac->req);
 
235
                        LDB_REQ_SET_LOCATION(down_req);
226
236
                        break;
227
237
                default:
228
238
                        return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
263
273
        } else {
264
274
                /* It looks like we need to map the DN */
265
275
                const struct ldb_val *sid_val, *guid_val, *wkguid_val;
 
276
                int num_components = ldb_dn_get_comp_num(dn);
 
277
                int num_ex_components = ldb_dn_get_extended_comp_num(dn);
 
278
 
 
279
                /*
 
280
                  windows ldap searchs don't allow a baseDN with more
 
281
                  than one extended component, or an extended
 
282
                  component and a string DN
 
283
 
 
284
                  We only enforce this over ldap, not for internal
 
285
                  use, as there are just too many places where we
 
286
                  internally want to use a DN that has come from a
 
287
                  search with extended DN enabled, or comes from a DRS
 
288
                  naming context.
 
289
 
 
290
                  Enforcing this would also make debugging samba much
 
291
                  harder, as we'd need to use ldb_dn_minimise() in a
 
292
                  lot of places, and that would lose the DN string
 
293
                  which is so useful for working out what a request is
 
294
                  for
 
295
                 */
 
296
                if ((num_components != 0 || num_ex_components != 1) &&
 
297
                    ldb_req_is_untrusted(req)) {
 
298
                        return ldb_error(ldb_module_get_ctx(module),
 
299
                                         LDB_ERR_INVALID_DN_SYNTAX, "invalid number of DN components");
 
300
                }
266
301
 
267
302
                sid_val = ldb_dn_get_extended_component(dn, "SID");
268
303
                guid_val = ldb_dn_get_extended_component(dn, "GUID");
274
309
                        base_dn_filter = talloc_asprintf(req, "(objectSid=%s)", 
275
310
                                                         ldb_binary_encode(req, *sid_val));
276
311
                        if (!base_dn_filter) {
277
 
                                ldb_oom(ldb_module_get_ctx(module));
278
 
                                return LDB_ERR_OPERATIONS_ERROR;
 
312
                                return ldb_oom(ldb_module_get_ctx(module));
279
313
                        }
280
314
                        base_dn_scope = LDB_SCOPE_SUBTREE;
281
315
                        base_dn_attrs = no_attr;
287
321
                        base_dn_filter = talloc_asprintf(req, "(objectGUID=%s)", 
288
322
                                                         ldb_binary_encode(req, *guid_val));
289
323
                        if (!base_dn_filter) {
290
 
                                ldb_oom(ldb_module_get_ctx(module));
291
 
                                return LDB_ERR_OPERATIONS_ERROR;
 
324
                                return ldb_oom(ldb_module_get_ctx(module));
292
325
                        }
293
326
                        base_dn_scope = LDB_SCOPE_SUBTREE;
294
327
                        base_dn_attrs = no_attr;
303
336
 
304
337
                        p = strchr(wkguid_dup, ',');
305
338
                        if (!p) {
306
 
                                return LDB_ERR_INVALID_DN_SYNTAX;
 
339
                                return ldb_error(ldb_module_get_ctx(module), LDB_ERR_INVALID_DN_SYNTAX,
 
340
                                                 "Invalid WKGUID format");
307
341
                        }
308
342
 
309
343
                        p[0] = '\0';
311
345
 
312
346
                        wellknown_object = talloc_asprintf(req, "B:32:%s:", wkguid_dup);
313
347
                        if (!wellknown_object) {
314
 
                                ldb_oom(ldb_module_get_ctx(module));
315
 
                                return LDB_ERR_OPERATIONS_ERROR;
 
348
                                return ldb_oom(ldb_module_get_ctx(module));
316
349
                        }
317
350
 
318
351
                        tail_str = p;
320
353
                        base_dn = ldb_dn_new(req, ldb_module_get_ctx(module), tail_str);
321
354
                        talloc_free(wkguid_dup);
322
355
                        if (!base_dn) {
323
 
                                ldb_oom(ldb_module_get_ctx(module));
324
 
                                return LDB_ERR_OPERATIONS_ERROR;
 
356
                                return ldb_oom(ldb_module_get_ctx(module));
325
357
                        }
326
358
                        base_dn_filter = talloc_strdup(req, "(objectClass=*)");
327
359
                        if (!base_dn_filter) {
328
 
                                ldb_oom(ldb_module_get_ctx(module));
329
 
                                return LDB_ERR_OPERATIONS_ERROR;
 
360
                                return ldb_oom(ldb_module_get_ctx(module));
330
361
                        }
331
362
                        base_dn_scope = LDB_SCOPE_BASE;
332
363
                        base_dn_attrs = wkattr;
333
364
                } else {
334
 
                        return LDB_ERR_INVALID_DN_SYNTAX;
 
365
                        return ldb_error(ldb_module_get_ctx(module), LDB_ERR_INVALID_DN_SYNTAX,
 
366
                                         "Invalid extended DN component");
335
367
                }
336
368
 
337
369
                ac = talloc_zero(req, struct extended_search_context);
338
370
                if (ac == NULL) {
339
 
                        ldb_oom(ldb_module_get_ctx(module));
340
 
                        return LDB_ERR_OPERATIONS_ERROR;
 
371
                        return ldb_oom(ldb_module_get_ctx(module));
341
372
                }
342
373
                
343
374
                ac->module = module;
354
385
                                           base_dn_scope,
355
386
                                           base_dn_filter,
356
387
                                           base_dn_attrs,
357
 
                                           NULL,
 
388
                                           req->controls,
358
389
                                           ac, extended_base_callback,
359
390
                                           req);
 
391
                LDB_REQ_SET_LOCATION(down_req);
360
392
                if (ret != LDB_SUCCESS) {
361
 
                        return LDB_ERR_OPERATIONS_ERROR;
 
393
                        return ldb_operr(ldb_module_get_ctx(module));
362
394
                }
363
395
 
364
396
                if (all_partitions) {
365
397
                        struct ldb_search_options_control *control;
366
398
                        control = talloc(down_req, struct ldb_search_options_control);
367
399
                        control->search_options = 2;
368
 
                        ret = ldb_request_add_control(down_req,
 
400
                        ret = ldb_request_replace_control(down_req,
369
401
                                                      LDB_CONTROL_SEARCH_OPTIONS_OID,
370
402
                                                      true, control);
371
403
                        if (ret != LDB_SUCCESS) {
399
431
        return extended_dn_in_fix(module, req, req->op.rename.olddn);
400
432
}
401
433
 
402
 
_PUBLIC_ const struct ldb_module_ops ldb_extended_dn_in_module_ops = {
 
434
static const struct ldb_module_ops ldb_extended_dn_in_module_ops = {
403
435
        .name              = "extended_dn_in",
404
436
        .search            = extended_dn_in_search,
405
437
        .modify            = extended_dn_in_modify,
406
438
        .del               = extended_dn_in_del,
407
439
        .rename            = extended_dn_in_rename,
408
440
};
 
441
 
 
442
int ldb_extended_dn_in_module_init(const char *version)
 
443
{
 
444
        LDB_MODULE_CHECK_VERSION(version);
 
445
        return ldb_register_module(&ldb_extended_dn_in_module_ops);
 
446
}