lib: Align an integer type
[vlendec/samba-autobuild/.git] / source3 / rpc_server / rpc_config.c
1 /*
2    Unix SMB/Netbios implementation.
3    Generic infrastructure for RPC Daemons
4    Copyright (C) Simo Sorce 2011
5    Copyright (C) Andreas Schneider 2011
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "rpc_server/rpc_config.h"
23 #include "rpc_server/rpc_server.h"
24 #include "lib/param/param.h"
25 #include "librpc/rpc/dcesrv_core.h"
26 #include "lib/global_contexts.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_RPC_SRV
30
31 static struct dcesrv_context_callbacks srv_callbacks = {
32         .log.successful_authz = dcesrv_log_successful_authz,
33         .auth.gensec_prepare = dcesrv_auth_gensec_prepare,
34         .auth.become_root = become_root,
35         .auth.unbecome_root = unbecome_root,
36         .assoc_group.find = dcesrv_assoc_group_find,
37 };
38
39 static struct dcesrv_context *global_dcesrv_ctx = NULL;
40
41 struct dcesrv_context *global_dcesrv_context(void)
42 {
43         NTSTATUS status;
44
45         if (global_dcesrv_ctx == NULL) {
46                 struct loadparm_context *lp_ctx = NULL;
47
48                 DBG_INFO("Initializing DCE/RPC server context\n");
49
50                 lp_ctx = loadparm_init_s3(NULL, loadparm_s3_helpers());
51                 if (lp_ctx == NULL) {
52                         smb_panic("No memory");
53                 }
54
55                 /*
56                  * Note we MUST use the NULL context here, not the
57                  * autofree context, to avoid side effects in forked
58                  * children exiting.
59                  */
60                 status = dcesrv_init_context(global_event_context(),
61                                              lp_ctx,
62                                              &srv_callbacks,
63                                              &global_dcesrv_ctx);
64                 if (!NT_STATUS_IS_OK(status)) {
65                         smb_panic("Failed to init DCE/RPC context");
66                 }
67
68                 talloc_steal(global_dcesrv_ctx, lp_ctx);
69         }
70
71         return global_dcesrv_ctx;
72 }
73
74 void global_dcesrv_context_free(void)
75 {
76         TALLOC_FREE(global_dcesrv_ctx);
77 }