~lefteris-nikoltsios/+junk/samba-lp1016895

« back to all changes in this revision

Viewing changes to source4/lib/ldb/common/attrib_handlers.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:
2
2
   ldb database library
3
3
 
4
4
   Copyright (C) Andrew Tridgell  2005
 
5
   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006-2009
5
6
 
6
7
     ** NOTE! The following LGPL license applies to the ldb
7
8
     ** library. This does NOT imply that all of Samba is released
54
55
                            const struct ldb_val *in, struct ldb_val *out)
55
56
{
56
57
        char *s, *t;
57
 
        int l;
 
58
        size_t l;
58
59
 
59
60
        if (!in || !out || !(in->data)) {
60
61
                return -1;
99
100
        return 0;
100
101
}
101
102
 
 
103
/* length limited conversion of a ldb_val to a int32_t */
 
104
static int val_to_int64(const struct ldb_val *in, int64_t *v)
 
105
{
 
106
        char *end;
 
107
        char buf[64];
 
108
 
 
109
        /* make sure we don't read past the end of the data */
 
110
        if (in->length > sizeof(buf)-1) {
 
111
                return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 
112
        }
 
113
        strncpy(buf, (char *)in->data, in->length);
 
114
        buf[in->length] = 0;
 
115
 
 
116
        /* We've to use "strtoll" here to have the intended overflows.
 
117
         * Otherwise we may get "LONG_MAX" and the conversion is wrong. */
 
118
        *v = (int64_t) strtoll(buf, &end, 0);
 
119
        if (*end != 0) {
 
120
                return LDB_ERR_INVALID_ATTRIBUTE_SYNTAX;
 
121
        }
 
122
        return LDB_SUCCESS;
 
123
}
102
124
 
103
125
 
104
126
/*
108
130
static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx,
109
131
                                    const struct ldb_val *in, struct ldb_val *out)
110
132
{
111
 
        char *end;
112
 
        long long i = strtoll((char *)in->data, &end, 0);
113
 
        if (*end != 0) {
114
 
                return -1;
 
133
        int64_t i;
 
134
        int ret;
 
135
 
 
136
        ret = val_to_int64(in, &i);
 
137
        if (ret != LDB_SUCCESS) {
 
138
                return ret;
115
139
        }
116
 
        out->data = (uint8_t *)talloc_asprintf(mem_ctx, "%lld", i);
 
140
        out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%lld", (long long)i);
117
141
        if (out->data == NULL) {
118
 
                return -1;
 
142
                ldb_oom(ldb);
 
143
                return LDB_ERR_OPERATIONS_ERROR;
119
144
        }
120
145
        out->length = strlen((char *)out->data);
121
146
        return 0;
127
152
static int ldb_comparison_Integer(struct ldb_context *ldb, void *mem_ctx,
128
153
                                  const struct ldb_val *v1, const struct ldb_val *v2)
129
154
{
130
 
        return strtoll((char *)v1->data, NULL, 0) - strtoll((char *)v2->data, NULL, 0);
 
155
        int64_t i1=0, i2=0;
 
156
        val_to_int64(v1, &i1);
 
157
        val_to_int64(v2, &i2);
 
158
        if (i1 == i2) return 0;
 
159
        return i1 > i2? 1 : -1;
131
160
}
132
161
 
133
162
/*
240
269
                 * options but to do a binary compare */
241
270
                talloc_free(b1);
242
271
                talloc_free(b2);
243
 
                if (memcmp(s1, s2, MIN(n1, n2)) == 0) {
 
272
                ret = memcmp(s1, s2, MIN(n1, n2));
 
273
                if (ret == 0) {
244
274
                        if (n1 == n2) return 0;
245
275
                        if (n1 > n2) {
246
276
                                return (int)toupper(s1[n2]);
248
278
                                return -(int)toupper(s2[n1]);
249
279
                        }
250
280
                }
 
281
                return ret;
251
282
        }
252
283
 
253
284
        u1 = b1;
337
368
static int ldb_comparison_utctime(struct ldb_context *ldb, void *mem_ctx,
338
369
                                  const struct ldb_val *v1, const struct ldb_val *v2)
339
370
{
340
 
        time_t t1, t2;
341
 
        t1 = ldb_string_to_time((char *)v1->data);
342
 
        t2 = ldb_string_to_time((char *)v2->data);
343
 
        return (int)t2 - (int)t1;
 
371
        time_t t1=0, t2=0;
 
372
        ldb_val_to_time(v1, &t1);
 
373
        ldb_val_to_time(v2, &t2);
 
374
        if (t1 == t2) return 0;
 
375
        return t1 > t2? 1 : -1;
344
376
}
345
377
 
346
378
/*
349
381
static int ldb_canonicalise_utctime(struct ldb_context *ldb, void *mem_ctx,
350
382
                                    const struct ldb_val *in, struct ldb_val *out)
351
383
{
352
 
        time_t t = ldb_string_to_time((char *)in->data);
 
384
        time_t t;
 
385
        int ret;
 
386
        ret = ldb_val_to_time(in, &t);
 
387
        if (ret != LDB_SUCCESS) {
 
388
                return ret;
 
389
        }
353
390
        out->data = (uint8_t *)ldb_timestring(mem_ctx, t);
354
391
        if (out->data == NULL) {
355
 
                return -1;
 
392
                ldb_oom(ldb);
 
393
                return LDB_ERR_OPERATIONS_ERROR;
356
394
        }
357
395
        out->length = strlen((char *)out->data);
358
396
        return 0;
420
458
const struct ldb_schema_syntax *ldb_standard_syntax_by_name(struct ldb_context *ldb,
421
459
                                                            const char *syntax)
422
460
{
423
 
        int i;
 
461
        unsigned int i;
424
462
        unsigned num_handlers = sizeof(ldb_standard_syntaxes)/sizeof(ldb_standard_syntaxes[0]);
425
463
        /* TODO: should be replaced with a binary search */
426
464
        for (i=0;i<num_handlers;i++) {
430
468
        }
431
469
        return NULL;
432
470
}
 
471
 
 
472
int ldb_any_comparison(struct ldb_context *ldb, void *mem_ctx, 
 
473
                       ldb_attr_handler_t canonicalise_fn, 
 
474
                       const struct ldb_val *v1,
 
475
                       const struct ldb_val *v2)
 
476
{
 
477
        int ret, ret1, ret2;
 
478
        struct ldb_val v1_canon, v2_canon;
 
479
        TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
 
480
 
 
481
        /* I could try and bail if tmp_ctx was NULL, but what return
 
482
         * value would I use?
 
483
         *
 
484
         * It seems easier to continue on the NULL context 
 
485
         */
 
486
        ret1 = canonicalise_fn(ldb, tmp_ctx, v1, &v1_canon);
 
487
        ret2 = canonicalise_fn(ldb, tmp_ctx, v2, &v2_canon);
 
488
 
 
489
        if (ret1 == LDB_SUCCESS && ret2 == LDB_SUCCESS) {
 
490
                ret = ldb_comparison_binary(ldb, mem_ctx, &v1_canon, &v2_canon);
 
491
        } else {
 
492
                ret = ldb_comparison_binary(ldb, mem_ctx, v1, v2);
 
493
        }
 
494
        talloc_free(tmp_ctx);
 
495
        return ret;
 
496
}