smbXsrv_session: Remove a "can't happen" NULL check
[Samba.git] / source3 / torture / test_tdb_validate.c
blob4768512e159dedd18d77a4d2c881d05919774e98
1 /*
2 * Unix SMB/CIFS implementation.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "source3/include/includes.h"
19 #include <tdb.h>
20 #include "source3/torture/proto.h"
21 #include "source3/lib/tdb_validate.h"
23 static int validate_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA value,
24 void *private_data)
26 struct tdb_validation_status *state = private_data;
27 state->success = false;
28 printf("validate_fn called\n");
29 return -1;
32 bool run_tdb_validate(int dummy)
34 const char tdb_name[] = "tdb_validate.tdb";
35 bool result = false;
36 struct tdb_context *tdb = NULL;
37 char buf[] = "data";
38 TDB_DATA data = { .dptr = (uint8_t *)buf, .dsize = sizeof(buf), };
39 int ret;
41 unlink(tdb_name);
43 tdb = tdb_open(tdb_name, 0, 0, O_CREAT|O_EXCL|O_RDWR, 0600);
44 if (tdb == NULL) {
45 perror("Could not open tdb");
46 goto done;
49 ret = tdb_store(tdb, data, data, 0);
50 if (ret == -1) {
51 perror("tdb_store failed");
52 goto done;
55 ret = tdb_validate(tdb, validate_fn);
56 if (ret == 0) {
57 fprintf(stderr,
58 "tdb_validate succeeded where it should have "
59 "failed\n");
60 goto done;
63 result = true;
64 done:
65 tdb_close(tdb);
66 unlink(tdb_name);
67 return result;