Added stubs for SRVSVC and NETLOGON rpcclient commands.
[samba.git] / source / libsmb / cli_netlogon.c
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
8    
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.
13    
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.
18    
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.
22 */
23
24 #include "includes.h"
25
26 /* Opens a SMB connection to the netlogon pipe */
27
28 struct cli_state *cli_netlogon_initialise(struct cli_state *cli, 
29                                           char *system_name,
30                                           struct ntuser_creds *creds)
31 {
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;
37
38         /* Initialise cli_state information */
39
40         if (!cli_initialise(cli)) {
41                 return NULL;
42         }
43
44         if (!creds) {
45                 ZERO_STRUCT(anon);
46                 anon.pwd.null_pwd = 1;
47                 creds = &anon;
48         }
49
50         cli_init_creds(cli, creds);
51
52         /* Establish a SMB connection */
53
54         if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
55                 return NULL;
56         }
57
58         make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
59         make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
60
61         if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling, 
62                                       &called, "IPC$", "IPC", False, True)) {
63                 return NULL;
64         }
65
66         /* Open a NT session thingy */
67
68         if (!cli_nt_session_open(cli, PIPE_NETLOGON)) {
69                 cli_shutdown(cli);
70                 return NULL;
71         }
72
73         return cli;
74 }
75
76 /* Shut down a SMB connection to the netlogon pipe */
77
78 void cli_netlogon_shutdown(struct cli_state *cli)
79 {
80         if (cli->fd != -1) cli_ulogoff(cli);
81         cli_shutdown(cli);
82 }
83
84 /***************************************************************************
85 Synchronise SAM Database (requires SEC_CHAN_BDC).
86 ****************************************************************************/
87 BOOL cli_net_sam_sync(struct cli_state *cli, TALLOC_CTX *mem_ctx,
88                       char *srv_name, uint32 database_id, uint32 *num_deltas, 
89                       SAM_DELTA_HDR *hdr_deltas, SAM_DELTA_CTR *deltas)
90 {
91         prs_struct qbuf, rbuf;
92         NET_Q_SAM_SYNC q;
93         NET_R_SAM_SYNC r;
94         uint32 result = NT_STATUS_UNSUCCESSFUL;
95         DOM_CRED new_clnt_cred;
96         uint8 sess_key[16];
97
98         ZERO_STRUCT(q);
99         ZERO_STRUCT(r);
100
101         /* Initialise parse structures */
102
103         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
104         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
105
106         /* Initialise input parameters */
107
108         init_q_sam_sync(&q, srv_name, cli->clnt_name_slash, &new_clnt_cred, 
109                         database_id);
110
111         /* Marshall data and send request */
112
113         if (!net_io_q_sam_sync("", &q, &qbuf, 0) ||
114             !rpc_api_pipe_req(cli, NET_SAM_SYNC, &qbuf, &rbuf)) {
115                 goto done;
116         }
117
118         r.hdr_deltas = hdr_deltas;
119         r.deltas = deltas;
120
121         if (!net_io_r_sam_sync("", sess_key, &r, &rbuf, 0)) {
122                 goto done;
123         }
124
125         if ((result = r.status) != NT_STATUS_NOPROBLEMO) {
126                 goto done;
127         }
128
129 #if 0
130                 /* Update the credentials. */
131                 if (ok && !cli_con_deal_with_creds(con, &(r_s.srv_creds)))
132                 {
133                         *num_deltas = r_s.num_deltas2;
134                 }
135 #endif
136
137  done:
138         prs_mem_free(&rbuf);
139         prs_mem_free(&qbuf);
140
141         return result;
142 }