ctdb-server: Remove duplicate logic
[samba4-gss.git] / source3 / rpc_server / rpcd_witness.c
blob9dcf180c5482ccd7e326b76dd335c18612fbd7b0
1 /*
2 * Unix SMB/CIFS implementation.
4 * Copyright (C) 2023 Stefan Metzmacher
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "rpc_worker.h"
22 #include "librpc/gen_ndr/ndr_witness.h"
23 #include "librpc/gen_ndr/ndr_witness_scompat.h"
25 static size_t witness_interfaces(
26 const struct ndr_interface_table ***pifaces,
27 void *private_data)
29 static const struct ndr_interface_table *ifaces[] = {
30 &ndr_table_witness,
33 if (!lp_clustering()) {
35 * Without clustering there's no need for witness.
37 *pifaces = NULL;
38 return 0;
41 *pifaces = ifaces;
42 return ARRAY_SIZE(ifaces);
45 static NTSTATUS witness_servers(
46 struct dcesrv_context *dce_ctx,
47 const struct dcesrv_endpoint_server ***_ep_servers,
48 size_t *_num_ep_servers,
49 void *private_data)
51 static const struct dcesrv_endpoint_server *ep_servers[1] = { NULL };
52 char *principal = NULL;
53 NTSTATUS status;
55 if (!lp_clustering()) {
57 * Without clustering there's no need for witness.
59 *_ep_servers = NULL;
60 *_num_ep_servers = 0;
61 return NT_STATUS_OK;
64 principal = talloc_asprintf(talloc_tos(),
65 "cifs/%s",
66 lp_netbios_name());
67 if (principal == NULL) {
68 return NT_STATUS_NO_MEMORY;
71 status = dcesrv_auth_type_principal_register(dce_ctx,
72 DCERPC_AUTH_TYPE_NTLMSSP,
73 principal);
74 if (!NT_STATUS_IS_OK(status)) {
75 return status;
77 status = dcesrv_auth_type_principal_register(dce_ctx,
78 DCERPC_AUTH_TYPE_SPNEGO,
79 principal);
80 if (!NT_STATUS_IS_OK(status)) {
81 return status;
83 if (lp_security() == SEC_ADS) {
84 status = dcesrv_auth_type_principal_register(dce_ctx,
85 DCERPC_AUTH_TYPE_KRB5,
86 principal);
87 if (!NT_STATUS_IS_OK(status)) {
88 return status;
92 TALLOC_FREE(principal);
95 * We prefer NDR64 for witness,
96 * as it's a very simple protocol and
97 * we support it from the beginning,
98 * which means it's well tested.
100 dce_ctx->preferred_transfer = &ndr_transfer_syntax_ndr64;
102 ep_servers[0] = witness_get_ep_server();
104 *_ep_servers = ep_servers;
105 *_num_ep_servers = ARRAY_SIZE(ep_servers);
106 return NT_STATUS_OK;
109 int main(int argc, const char *argv[])
111 return rpc_worker_main(
112 argc,
113 argv,
114 "rpcd_witness",
117 witness_interfaces,
118 witness_servers,
119 NULL);