CVE-2013-4408:s3:ctdb_conn: add some length verification to ctdb_packet_more()
[Samba.git] / lib / ntdb / test / api-add-remove-flags.c
blobc5a3f421fc99c627d12bdd9c79808510d64493c6
1 #include "private.h" // for ntdb_context
2 #include "ntdb.h"
3 #include "tap-interface.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include "logging.h"
9 int main(int argc, char *argv[])
11 unsigned int i;
12 struct ntdb_context *ntdb;
13 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
14 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
15 NTDB_NOMMAP|NTDB_CONVERT };
17 plan_tests(87);
18 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
19 ntdb = ntdb_open("run-add-remove-flags.ntdb",
20 flags[i]|MAYBE_NOSYNC,
21 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
22 ok1(ntdb);
23 if (!ntdb)
24 continue;
26 ok1(ntdb_get_flags(ntdb) == ntdb->flags);
27 tap_log_messages = 0;
28 ntdb_add_flag(ntdb, NTDB_NOLOCK);
29 if (flags[i] & NTDB_INTERNAL)
30 ok1(tap_log_messages == 1);
31 else {
32 ok1(tap_log_messages == 0);
33 ok1(ntdb_get_flags(ntdb) & NTDB_NOLOCK);
36 tap_log_messages = 0;
37 ntdb_add_flag(ntdb, NTDB_NOMMAP);
38 if (flags[i] & NTDB_INTERNAL)
39 ok1(tap_log_messages == 1);
40 else {
41 ok1(tap_log_messages == 0);
42 ok1(ntdb_get_flags(ntdb) & NTDB_NOMMAP);
43 ok1(ntdb->file->map_ptr == NULL);
46 tap_log_messages = 0;
47 ntdb_add_flag(ntdb, NTDB_NOSYNC);
48 if (flags[i] & NTDB_INTERNAL)
49 ok1(tap_log_messages == 1);
50 else {
51 ok1(tap_log_messages == 0);
52 ok1(ntdb_get_flags(ntdb) & NTDB_NOSYNC);
55 ok1(ntdb_get_flags(ntdb) == ntdb->flags);
57 tap_log_messages = 0;
58 ntdb_remove_flag(ntdb, NTDB_NOLOCK);
59 if (flags[i] & NTDB_INTERNAL)
60 ok1(tap_log_messages == 1);
61 else {
62 ok1(tap_log_messages == 0);
63 ok1(!(ntdb_get_flags(ntdb) & NTDB_NOLOCK));
66 tap_log_messages = 0;
67 ntdb_remove_flag(ntdb, NTDB_NOMMAP);
68 if (flags[i] & NTDB_INTERNAL)
69 ok1(tap_log_messages == 1);
70 else {
71 ok1(tap_log_messages == 0);
72 ok1(!(ntdb_get_flags(ntdb) & NTDB_NOMMAP));
73 ok1(ntdb->file->map_ptr != NULL);
76 tap_log_messages = 0;
77 ntdb_remove_flag(ntdb, NTDB_NOSYNC);
78 if (flags[i] & NTDB_INTERNAL)
79 ok1(tap_log_messages == 1);
80 else {
81 ok1(tap_log_messages == 0);
82 ok1(!(ntdb_get_flags(ntdb) & NTDB_NOSYNC));
85 ntdb_close(ntdb);
88 ok1(tap_log_messages == 0);
89 return exit_status();