sync with SAMBA_2_2
[Samba/gbeck.git] / source / libsmb / cli_netlogon.c
blob47b7c2f22ec66a96cf1859f31443b85a7598315e
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 NT Domain Authentication SMB / MSRPC client
5 Copyright (C) Andrew Tridgell 1994-2000
6 Copyright (C) Luke Kenneth Casson Leighton 1996-2000
7 Copyright (C) Tim Potter 2001
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
26 /* Opens a SMB connection to the netlogon pipe */
28 struct cli_state *cli_netlogon_initialise(struct cli_state *cli,
29 char *system_name,
30 struct ntuser_creds *creds)
32 struct in_addr dest_ip;
33 struct nmb_name calling, called;
34 fstring dest_host;
35 extern pstring global_myname;
36 struct ntuser_creds anon;
38 /* Initialise cli_state information */
40 if (!cli_initialise(cli)) {
41 return NULL;
44 if (!creds) {
45 ZERO_STRUCT(anon);
46 anon.pwd.null_pwd = 1;
47 creds = &anon;
50 cli_init_creds(cli, creds);
52 /* Establish a SMB connection */
54 if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
55 return NULL;
58 make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
59 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
61 if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
62 &called, "IPC$", "IPC", False, True)) {
63 return NULL;
66 /* Open a NT session thingy */
68 if (!cli_nt_session_open(cli, PIPE_NETLOGON)) {
69 cli_shutdown(cli);
70 return NULL;
73 return cli;
76 /* Shut down a SMB connection to the netlogon pipe */
78 void cli_netlogon_shutdown(struct cli_state *cli)
80 if (cli->fd != -1) cli_ulogoff(cli);
81 cli_shutdown(cli);
84 /* Logon Control 2 */
86 uint32 cli_netlogon_logon_ctrl2(struct cli_state *cli, TALLOC_CTX *mem_ctx,
87 uint32 query_level)
89 prs_struct qbuf, rbuf;
90 NET_Q_LOGON_CTRL2 q;
91 NET_R_LOGON_CTRL2 r;
92 uint32 result = NT_STATUS_UNSUCCESSFUL;
94 ZERO_STRUCT(q);
95 ZERO_STRUCT(r);
97 /* Initialise parse structures */
99 prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
100 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
102 /* Initialise input parameters */
104 init_net_q_logon_ctrl2(&q, cli->srv_name_slash, query_level);
106 /* Marshall data and send request */
108 if (!net_io_q_logon_ctrl2("", &q, &qbuf, 0) ||
109 !rpc_api_pipe_req(cli, NET_LOGON_CTRL2, &qbuf, &rbuf)) {
110 result = NT_STATUS_UNSUCCESSFUL;
111 goto done;
114 /* Unmarshall response */
116 if (!net_io_r_logon_ctrl2("", &r, &rbuf, 0)) {
117 result = NT_STATUS_UNSUCCESSFUL;
118 goto done;
121 result = r.status;
123 done:
124 prs_mem_free(&qbuf);
125 prs_mem_free(&rbuf);
127 return result;