2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Largely rewritten by Jeremy Allison 2005.
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/>.
21 #include "../librpc/gen_ndr/ndr_schannel.h"
22 #include "../librpc/gen_ndr/ndr_netlogon.h"
23 #include "../libcli/auth/schannel.h"
24 #include "rpc_client/cli_netlogon.h"
25 #include "rpc_client/cli_pipe.h"
26 #include "librpc/rpc/dcerpc.h"
28 #include "libsmb/libsmb.h"
29 #include "../libcli/smb/smbXcli_base.h"
30 #include "libcli/auth/netlogon_creds_cli.h"
33 #define DBGC_CLASS DBGC_RPC_CLI
35 /****************************************************************************
36 Open a named pipe to an SMB server and bind using schannel (bind type 68).
37 Fetch the session key ourselves using a temporary netlogon pipe.
38 ****************************************************************************/
40 NTSTATUS
cli_rpc_pipe_open_schannel(struct cli_state
*cli
,
41 struct messaging_context
*msg_ctx
,
42 const struct ndr_interface_table
*table
,
43 enum dcerpc_transport_t transport
,
45 const char *remote_name
,
46 const struct sockaddr_storage
*remote_sockaddr
,
47 struct rpc_pipe_client
**presult
,
49 struct netlogon_creds_cli_context
**pcreds
)
51 TALLOC_CTX
*frame
= talloc_stackframe();
52 struct rpc_pipe_client
*result
= NULL
;
54 struct cli_credentials
*cli_creds
= NULL
;
55 struct netlogon_creds_cli_context
*netlogon_creds
= NULL
;
56 struct netlogon_creds_CredentialState
*creds
= NULL
;
57 uint32_t netlogon_flags
;
59 status
= pdb_get_trust_credentials(domain
, NULL
,
61 if (!NT_STATUS_IS_OK(status
)) {
66 status
= rpccli_create_netlogon_creds_ctx(cli_creds
,
71 if (!NT_STATUS_IS_OK(status
)) {
76 if (table
== &ndr_table_netlogon
) {
77 status
= rpccli_connect_netlogon(cli
,
82 false, /* force_reauth */
85 if (!NT_STATUS_IS_OK(status
)) {
92 status
= rpccli_setup_netlogon_creds(cli
,
97 false, /* force_reauth */
99 if (!NT_STATUS_IS_OK(status
)) {
104 status
= netlogon_creds_cli_get(netlogon_creds
, frame
, &creds
);
105 if (!NT_STATUS_IS_OK(status
)) {
110 netlogon_flags
= creds
->negotiate_flags
;
113 if (netlogon_flags
& NETLOGON_NEG_AUTHENTICATED_RPC
) {
114 status
= cli_rpc_pipe_open_schannel_with_creds(cli
, table
,
120 if (!NT_STATUS_IS_OK(status
)) {
125 status
= cli_rpc_pipe_open_noauth(cli
, table
, &result
);
126 if (!NT_STATUS_IS_OK(status
)) {
134 if (pcreds
!= NULL
) {
135 *pcreds
= talloc_move(mem_ctx
, &netlogon_creds
);