s4:dsdb/subtree_delete: do the recursive delete AS_SYSTEM/TRUSTED (bug #7711)
[Samba/gebeck_regimport.git] / lib / ntdb / test / api-95-read-only-during-parse.c
blob8252b812d22c843dd0a46b09696c9af0d487c86c
1 /* Make sure write operations fail during ntdb_parse(). */
2 #include "config.h"
3 #include "ntdb.h"
4 #include "tap-interface.h"
5 #include <sys/types.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 #include "logging.h"
10 static struct ntdb_context *ntdb;
12 /* We could get either of these. */
13 static bool xfail(enum NTDB_ERROR ecode)
15 return ecode == NTDB_ERR_RDONLY || ecode == NTDB_ERR_LOCK;
18 static enum NTDB_ERROR parse(NTDB_DATA key, NTDB_DATA data,
19 NTDB_DATA *expected)
21 NTDB_DATA add = ntdb_mkdata("another", strlen("another"));
23 if (!ntdb_deq(data, *expected)) {
24 return NTDB_ERR_EINVAL;
27 /* These should all fail.*/
28 if (!xfail(ntdb_store(ntdb, add, add, NTDB_INSERT))) {
29 return NTDB_ERR_EINVAL;
31 tap_log_messages--;
33 if (!xfail(ntdb_append(ntdb, key, add))) {
34 return NTDB_ERR_EINVAL;
36 tap_log_messages--;
38 if (!xfail(ntdb_delete(ntdb, key))) {
39 return NTDB_ERR_EINVAL;
41 tap_log_messages--;
43 if (!xfail(ntdb_transaction_start(ntdb))) {
44 return NTDB_ERR_EINVAL;
46 tap_log_messages--;
48 if (!xfail(ntdb_chainlock(ntdb, key))) {
49 return NTDB_ERR_EINVAL;
51 tap_log_messages--;
53 if (!xfail(ntdb_lockall(ntdb))) {
54 return NTDB_ERR_EINVAL;
56 tap_log_messages--;
58 if (!xfail(ntdb_wipe_all(ntdb))) {
59 return NTDB_ERR_EINVAL;
61 tap_log_messages--;
63 if (!xfail(ntdb_repack(ntdb))) {
64 return NTDB_ERR_EINVAL;
66 tap_log_messages--;
68 /* Access the record one more time. */
69 if (!ntdb_deq(data, *expected)) {
70 return NTDB_ERR_EINVAL;
73 return NTDB_SUCCESS;
76 int main(int argc, char *argv[])
78 unsigned int i;
79 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP, NTDB_CONVERT };
80 NTDB_DATA key = ntdb_mkdata("hello", 5), data = ntdb_mkdata("world", 5);
82 plan_tests(sizeof(flags) / sizeof(flags[0]) * 2 + 1);
83 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
84 ntdb = ntdb_open("api-95-read-only-during-parse.ntdb",
85 flags[i]|MAYBE_NOSYNC,
86 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
87 ok1(ntdb_store(ntdb, key, data, NTDB_INSERT) == NTDB_SUCCESS);
88 ok1(ntdb_parse_record(ntdb, key, parse, &data) == NTDB_SUCCESS);
89 ntdb_close(ntdb);
92 ok1(tap_log_messages == 0);
93 return exit_status();