dcesrv_core: Add dcesrv_context_set_callbacks()
[Samba.git] / testsuite / unittests / test_sambafs_srv_pipe.c
blob75797c9bcee318e1102b71580c9d890e575644c8
1 #include <errno.h>
2 #include <stdarg.h>
3 #include <stddef.h>
4 #include <setjmp.h>
5 #include <stdint.h>
6 #include <unistd.h>
7 #include <sys/stat.h>
8 #include <cmocka.h>
10 #include "include/config.h"
11 #include "librpc/gen_ndr/ndr_samr.h"
12 #include "librpc/gen_ndr/ndr_samr_scompat.h"
13 #include "source3/rpc_server/srv_pipe.h"
14 #include "librpc/rpc/rpc_common.h"
15 #include "librpc/rpc/dcesrv_core.h"
16 #include "talloc.h"
18 struct test_state {
19 TALLOC_CTX *mem_ctx;
20 struct loadparm_context *lp_ctx;
21 struct dcesrv_context *dce_ctx;
24 static struct dcesrv_context_callbacks srv_callbacks = {
25 .log.successful_authz = NULL,
28 static int setup_samr(void **state)
30 TALLOC_CTX *mem_ctx;
31 struct test_state *s;
32 const struct dcesrv_endpoint_server *ep_server;
33 NTSTATUS status;
35 mem_ctx = talloc_new(NULL);
36 assert_non_null(mem_ctx);
38 s = talloc_zero(mem_ctx, struct test_state);
39 assert_non_null(s);
41 s->mem_ctx = mem_ctx;
43 ep_server = samr_get_ep_server();
44 assert_non_null(ep_server);
46 status = dcerpc_register_ep_server(ep_server);
47 assert_true(NT_STATUS_IS_OK(status));
49 status = dcesrv_init_context(s, NULL, &srv_callbacks, &s->dce_ctx);
50 assert_true(NT_STATUS_IS_OK(status));
52 status = dcesrv_init_ep_server(s->dce_ctx, "samr");
53 assert_true(NT_STATUS_IS_OK(status));
55 *state = s;
57 return 0;
60 static int teardown_samr(void **state)
62 struct test_state *s = talloc_get_type_abort(*state,
63 struct test_state);
65 unsetenv("UNITTEST_DUMMY_MODULE_LOADED");
67 dcesrv_shutdown_ep_server(s->dce_ctx, "samr");
69 talloc_free(s->mem_ctx);
71 return 0;
74 static void test_is_known_pipename(void **state)
76 struct test_state *s = talloc_get_type_abort(*state,
77 struct test_state);
78 struct dcesrv_endpoint *ep;
79 char dummy_module_path[4096] = {0};
80 const char *module_env;
81 NTSTATUS status;
83 status = is_known_pipename(s->dce_ctx, "samr", &ep);
84 assert_true(NT_STATUS_IS_OK(status));
86 status = is_known_pipename(s->dce_ctx, "SAMR", &ep);
87 assert_true(NT_STATUS_IS_OK(status));
89 snprintf(dummy_module_path,
90 sizeof(dummy_module_path),
91 "%s/bin/modules/rpc/test_dummy_module.so",
92 SRCDIR);
94 status = is_known_pipename(s->dce_ctx, dummy_module_path, &ep);
95 assert_false(NT_STATUS_IS_OK(status));
97 module_env = getenv("UNITTEST_DUMMY_MODULE_LOADED");
98 assert_null(module_env);
101 int main(void) {
102 const struct CMUnitTest tests[] = {
103 cmocka_unit_test_setup_teardown(test_is_known_pipename,
104 setup_samr,
105 teardown_samr),
108 cmocka_set_message_output(CM_OUTPUT_SUBUNIT);
109 return cmocka_run_group_tests(tests, NULL, NULL);