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

« back to all changes in this revision

Viewing changes to lib/talloc/testsuite.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:
25
25
 
26
26
#include "replace.h"
27
27
#include "system/time.h"
28
 
#include "talloc.h"
 
28
#include <talloc.h>
 
29
 
 
30
#include "talloc_testsuite.h"
29
31
 
30
32
static struct timeval timeval_current(void)
31
33
{
101
103
 
102
104
static unsigned int test_abort_count;
103
105
 
 
106
#if 0
104
107
static void test_abort_fn(const char *reason)
105
108
{
106
109
        printf("# test_abort_fn(%s)\n", reason);
112
115
        test_abort_count = 0;
113
116
        talloc_set_abort_fn(test_abort_fn);
114
117
}
 
118
#endif
115
119
 
116
120
static void test_abort_stop(void)
117
121
{
1119
1123
{
1120
1124
        void *pool;
1121
1125
        void *p1, *p2, *p3, *p4;
 
1126
        void *p2_2;
1122
1127
 
1123
1128
        pool = talloc_pool(NULL, 1024);
1124
1129
 
1125
1130
        p1 = talloc_size(pool, 80);
 
1131
        memset(p1, 0x11, talloc_get_size(p1));
1126
1132
        p2 = talloc_size(pool, 20);
 
1133
        memset(p2, 0x11, talloc_get_size(p2));
1127
1134
        p3 = talloc_size(p1, 50);
 
1135
        memset(p3, 0x11, talloc_get_size(p3));
1128
1136
        p4 = talloc_size(p3, 1000);
1129
 
 
1130
 
        talloc_free(pool);
1131
 
 
1132
 
        return true;
1133
 
}
 
1137
        memset(p4, 0x11, talloc_get_size(p4));
 
1138
 
 
1139
#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
 
1140
        p2_2 = talloc_realloc_size(pool, p2, 20+1);
 
1141
        torture_assert("pool realloc 20+1", p2_2 == p2, "failed: pointer changed");
 
1142
        memset(p2, 0x11, talloc_get_size(p2));
 
1143
        p2_2 = talloc_realloc_size(pool, p2, 20-1);
 
1144
        torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
 
1145
        memset(p2, 0x11, talloc_get_size(p2));
 
1146
        p2_2 = talloc_realloc_size(pool, p2, 20-1);
 
1147
        torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
 
1148
        memset(p2, 0x11, talloc_get_size(p2));
 
1149
 
 
1150
        talloc_free(p3);
 
1151
 
 
1152
        /* this should reclaim the memory of p4 and p3 */
 
1153
        p2_2 = talloc_realloc_size(pool, p2, 400);
 
1154
        torture_assert("pool realloc 400", p2_2 == p2, "failed: pointer changed");
 
1155
        memset(p2, 0x11, talloc_get_size(p2));
 
1156
 
 
1157
        talloc_free(p1);
 
1158
 
 
1159
        /* this should reclaim the memory of p1 */
 
1160
        p2_2 = talloc_realloc_size(pool, p2, 800);
 
1161
        torture_assert("pool realloc 800", p2_2 == p1, "failed: pointer not changed");
 
1162
        p2 = p2_2;
 
1163
        memset(p2, 0x11, talloc_get_size(p2));
 
1164
 
 
1165
        /* this should do a malloc */
 
1166
        p2_2 = talloc_realloc_size(pool, p2, 1800);
 
1167
        torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
 
1168
        p2 = p2_2;
 
1169
        memset(p2, 0x11, talloc_get_size(p2));
 
1170
 
 
1171
        /* this should reclaim the memory from the pool */
 
1172
        p3 = talloc_size(pool, 80);
 
1173
        torture_assert("pool alloc 80", p3 == p1, "failed: pointer changed");
 
1174
        memset(p3, 0x11, talloc_get_size(p3));
 
1175
 
 
1176
        talloc_free(p2);
 
1177
        talloc_free(p3);
 
1178
 
 
1179
        p1 = talloc_size(pool, 80);
 
1180
        memset(p1, 0x11, talloc_get_size(p1));
 
1181
        p2 = talloc_size(pool, 20);
 
1182
        memset(p2, 0x11, talloc_get_size(p2));
 
1183
 
 
1184
        talloc_free(p1);
 
1185
 
 
1186
        p2_2 = talloc_realloc_size(pool, p2, 20-1);
 
1187
        torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
 
1188
        memset(p2, 0x11, talloc_get_size(p2));
 
1189
        p2_2 = talloc_realloc_size(pool, p2, 20-1);
 
1190
        torture_assert("pool realloc 20-1", p2_2 == p2, "failed: pointer changed");
 
1191
        memset(p2, 0x11, talloc_get_size(p2));
 
1192
 
 
1193
        /* this should do a malloc */
 
1194
        p2_2 = talloc_realloc_size(pool, p2, 1800);
 
1195
        torture_assert("pool realloc 1800", p2_2 != p2, "failed: pointer not changed");
 
1196
        p2 = p2_2;
 
1197
        memset(p2, 0x11, talloc_get_size(p2));
 
1198
 
 
1199
        /* this should reclaim the memory from the pool */
 
1200
        p3 = talloc_size(pool, 800);
 
1201
        torture_assert("pool alloc 800", p3 == p1, "failed: pointer changed");
 
1202
        memset(p3, 0x11, talloc_get_size(p3));
 
1203
 
 
1204
#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
 
1205
 
 
1206
        talloc_free(pool);
 
1207
 
 
1208
        return true;
 
1209
}
 
1210
 
 
1211
static bool test_pool_steal(void)
 
1212
{
 
1213
        void *root;
 
1214
        void *pool;
 
1215
        void *p1, *p2;
 
1216
        void *p1_2, *p2_2;
 
1217
        size_t hdr;
 
1218
        size_t ofs1, ofs2;
 
1219
 
 
1220
        root = talloc_new(NULL);
 
1221
        pool = talloc_pool(root, 1024);
 
1222
 
 
1223
        p1 = talloc_size(pool, 4 * 16);
 
1224
        torture_assert("pool allocate 4 * 16", p1 != NULL, "failed ");
 
1225
        memset(p1, 0x11, talloc_get_size(p1));
 
1226
        p2 = talloc_size(pool, 4 * 16);
 
1227
        torture_assert("pool allocate 4 * 16", p2 > p1, "failed: !(p2 > p1) ");
 
1228
        memset(p2, 0x11, talloc_get_size(p2));
 
1229
 
 
1230
        ofs1 = PTR_DIFF(p2, p1);
 
1231
        hdr = ofs1 - talloc_get_size(p1);
 
1232
 
 
1233
        talloc_steal(root, p1);
 
1234
        talloc_steal(root, p2);
 
1235
 
 
1236
        talloc_free(pool);
 
1237
 
 
1238
        p1_2 = p1;
 
1239
 
 
1240
#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
 
1241
        p1_2 = talloc_realloc_size(root, p1, 5 * 16);
 
1242
        torture_assert("pool realloc 5 * 16", p1_2 > p2, "failed: pointer not changed");
 
1243
        memset(p1_2, 0x11, talloc_get_size(p1_2));
 
1244
        ofs1 = PTR_DIFF(p1_2, p2);
 
1245
        ofs2 = talloc_get_size(p2) + hdr;
 
1246
 
 
1247
        torture_assert("pool realloc ", ofs1 == ofs2, "failed: pointer offset unexpected");
 
1248
 
 
1249
        p2_2 = talloc_realloc_size(root, p2, 3 * 16);
 
1250
        torture_assert("pool realloc 5 * 16", p2_2 == p2, "failed: pointer changed");
 
1251
        memset(p2_2, 0x11, talloc_get_size(p2_2));
 
1252
#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
 
1253
 
 
1254
        talloc_free(p1_2);
 
1255
 
 
1256
        p2_2 = p2;
 
1257
 
 
1258
#if 1 /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
 
1259
        /* now we should reclaim the full pool */
 
1260
        p2_2 = talloc_realloc_size(root, p2, 8 * 16);
 
1261
        torture_assert("pool realloc 8 * 16", p2_2 == p1, "failed: pointer not expected");
 
1262
        p2 = p2_2;
 
1263
        memset(p2_2, 0x11, talloc_get_size(p2_2));
 
1264
 
 
1265
        /* now we malloc and free the full pool space */
 
1266
        p2_2 = talloc_realloc_size(root, p2, 2 * 1024);
 
1267
        torture_assert("pool realloc 2 * 1024", p2_2 != p1, "failed: pointer not expected");
 
1268
        memset(p2_2, 0x11, talloc_get_size(p2_2));
 
1269
 
 
1270
#endif /* this relies on ALWAYS_REALLOC == 0 in talloc.c */
 
1271
 
 
1272
        talloc_free(p2_2);
 
1273
 
 
1274
        talloc_free(root);
 
1275
 
 
1276
        return true;
 
1277
}
 
1278
 
 
1279
static bool test_free_ref_null_context(void)
 
1280
{
 
1281
        void *p1, *p2, *p3;
 
1282
        int ret;
 
1283
 
 
1284
        talloc_disable_null_tracking();
 
1285
        p1 = talloc_new(NULL);
 
1286
        p2 = talloc_new(NULL);
 
1287
 
 
1288
        p3 = talloc_reference(p2, p1);
 
1289
        torture_assert("reference", p3 == p1, "failed: reference on null");
 
1290
 
 
1291
        ret = talloc_free(p1);
 
1292
        torture_assert("ref free with null parent", ret == 0, "failed: free with null parent");
 
1293
        talloc_free(p2);
 
1294
 
 
1295
        talloc_enable_null_tracking_no_autofree();
 
1296
        p1 = talloc_new(NULL);
 
1297
        p2 = talloc_new(NULL);
 
1298
 
 
1299
        p3 = talloc_reference(p2, p1);
 
1300
        torture_assert("reference", p3 == p1, "failed: reference on null");
 
1301
 
 
1302
        ret = talloc_free(p1);
 
1303
        torture_assert("ref free with null tracked parent", ret == 0, "failed: free with null parent");
 
1304
        talloc_free(p2);
 
1305
 
 
1306
        return true;
 
1307
}
 
1308
 
 
1309
static bool test_rusty(void)
 
1310
{
 
1311
        void *root;
 
1312
        const char *p1;
 
1313
 
 
1314
        talloc_enable_null_tracking();
 
1315
        root = talloc_new(NULL);
 
1316
        p1 = talloc_strdup(root, "foo");
 
1317
        talloc_increase_ref_count(p1);
 
1318
        talloc_report_full(root, stdout);
 
1319
        talloc_free(root);
 
1320
        CHECK_BLOCKS("null_context", NULL, 2);
 
1321
        return true;
 
1322
}
 
1323
 
 
1324
static bool test_free_children(void)
 
1325
{
 
1326
        void *root;
 
1327
        const char *p1, *p2, *name, *name2;
 
1328
 
 
1329
        talloc_enable_null_tracking();
 
1330
        root = talloc_new(NULL);
 
1331
        p1 = talloc_strdup(root, "foo1");
 
1332
        p2 = talloc_strdup(p1, "foo2");
 
1333
 
 
1334
        talloc_set_name(p1, "%s", "testname");
 
1335
        talloc_free_children(p1);
 
1336
        /* check its still a valid talloc ptr */
 
1337
        talloc_get_size(talloc_get_name(p1));
 
1338
        if (strcmp(talloc_get_name(p1), "testname") != 0) {
 
1339
                return false;
 
1340
        }
 
1341
 
 
1342
        talloc_set_name(p1, "%s", "testname");
 
1343
        name = talloc_get_name(p1);
 
1344
        talloc_free_children(p1);
 
1345
        /* check its still a valid talloc ptr */
 
1346
        talloc_get_size(talloc_get_name(p1));
 
1347
        torture_assert("name", name == talloc_get_name(p1), "name ptr changed");
 
1348
        torture_assert("namecheck", strcmp(talloc_get_name(p1), "testname") == 0,
 
1349
                       "wrong name");
 
1350
        CHECK_BLOCKS("name1", p1, 2);
 
1351
 
 
1352
        /* note that this does not free the old child name */
 
1353
        talloc_set_name_const(p1, "testname2");
 
1354
        name2 = talloc_get_name(p1);
 
1355
        /* but this does */
 
1356
        talloc_free_children(p1);
 
1357
        torture_assert("namecheck", strcmp(talloc_get_name(p1), "testname2") == 0,
 
1358
                       "wrong name");
 
1359
        CHECK_BLOCKS("name1", p1, 1);
 
1360
 
 
1361
        talloc_report_full(root, stdout);
 
1362
        talloc_free(root);
 
1363
        return true;
 
1364
}
 
1365
 
1134
1366
 
1135
1367
static void test_reset(void)
1136
1368
{
1140
1372
        talloc_enable_null_tracking_no_autofree();
1141
1373
}
1142
1374
 
1143
 
struct torture_context;
1144
1375
bool torture_local_talloc(struct torture_context *tctx)
1145
1376
{
1146
1377
        bool ret = true;
1185
1416
        ret &= test_talloc_free_in_destructor();
1186
1417
        test_reset();
1187
1418
        ret &= test_pool();
 
1419
        test_reset();
 
1420
        ret &= test_pool_steal();
 
1421
        test_reset();
 
1422
        ret &= test_free_ref_null_context();
 
1423
        test_reset();
 
1424
        ret &= test_rusty();
 
1425
        test_reset();
 
1426
        ret &= test_free_children();
1188
1427
 
1189
1428
        if (ret) {
1190
1429
                test_reset();
1194
1433
        ret &= test_autofree();
1195
1434
 
1196
1435
        test_reset();
1197
 
 
 
1436
        talloc_disable_null_tracking();
1198
1437
        return ret;
1199
1438
}