s3/doc: document the ignore system acls option of vfs_acl_xattr and vfs_acl_tdb
[Samba/gebeck_regimport.git] / lib / tdb2 / test / run-05-readonly-open.c
blob80eb56759b703b95b866424b43e3c69b830af97c
1 #include <ccan/failtest/failtest_override.h>
2 #include "tdb2-source.h"
3 #include <ccan/tap/tap.h>
4 #include <ccan/failtest/failtest.h>
5 #include "logging.h"
6 #include "failtest_helper.h"
8 int main(int argc, char *argv[])
10 unsigned int i;
11 struct tdb_context *tdb;
12 int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
13 TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT,
14 TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1,
15 TDB_CONVERT|TDB_VERSION1,
16 TDB_NOMMAP|TDB_CONVERT|TDB_VERSION1 };
17 struct tdb_data key = tdb_mkdata("key", 3);
18 struct tdb_data data = tdb_mkdata("data", 4), d;
19 union tdb_attribute seed_attr;
20 unsigned int msgs = 0;
22 failtest_init(argc, argv);
23 failtest_hook = block_repeat_failures;
24 failtest_exit_check = exit_check_log;
26 seed_attr.base.attr = TDB_ATTRIBUTE_SEED;
27 seed_attr.base.next = &tap_log_attr;
28 seed_attr.seed.seed = 0;
30 failtest_suppress = true;
31 plan_tests(sizeof(flags) / sizeof(flags[0]) * 11);
32 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
33 tdb = tdb_open("run-05-readonly-open.tdb", flags[i],
34 O_RDWR|O_CREAT|O_TRUNC, 0600,
35 flags[i] & TDB_VERSION1
36 ? &tap_log_attr : &seed_attr);
37 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
38 tdb_close(tdb);
40 failtest_suppress = false;
41 tdb = tdb_open("run-05-readonly-open.tdb", flags[i],
42 O_RDONLY, 0600, &tap_log_attr);
43 if (!ok1(tdb))
44 break;
45 ok1(tap_log_messages == msgs);
46 /* Fetch should succeed, stores should fail. */
47 if (!ok1(tdb_fetch(tdb, key, &d) == 0))
48 goto fail;
49 ok1(tdb_deq(d, data));
50 free(d.dptr);
51 if (!ok1(tdb_store(tdb, key, data, TDB_MODIFY)
52 == TDB_ERR_RDONLY))
53 goto fail;
54 ok1(tap_log_messages == ++msgs);
55 if (!ok1(tdb_store(tdb, key, data, TDB_INSERT)
56 == TDB_ERR_RDONLY))
57 goto fail;
58 ok1(tap_log_messages == ++msgs);
59 failtest_suppress = true;
60 ok1(tdb_check(tdb, NULL, NULL) == 0);
61 tdb_close(tdb);
62 ok1(tap_log_messages == msgs);
63 /* SIGH: failtest bug, it doesn't save the tdb file because
64 * we have it read-only. If we go around again, it gets
65 * changed underneath us and things get screwy. */
66 if (failtest_has_failed())
67 break;
69 failtest_exit(exit_status());
71 fail:
72 failtest_suppress = true;
73 tdb_close(tdb);
74 failtest_exit(exit_status());