Fix up 'net ads join' to delete and rejoin if the account already exists.
[ira/wip.git] / source3 / libsmb / cli_srvsvc.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 svrsvc pipe */
27
28 struct cli_state *cli_svrsvc_initialise(struct cli_state *cli, 
29                                         char *system_name,
30                                         struct ntuser_creds *creds)
31 {
32         return cli_pipe_initialise(cli, system_name, PIPE_SRVSVC, creds);
33 }
34
35 NTSTATUS cli_srvsvc_net_srv_get_info(struct cli_state *cli, 
36                                      TALLOC_CTX *mem_ctx,
37                                      uint32 switch_value, SRV_INFO_CTR *ctr)
38 {
39         prs_struct qbuf, rbuf;
40         SRV_Q_NET_SRV_GET_INFO q;
41         SRV_R_NET_SRV_GET_INFO r;
42         NTSTATUS result;
43
44         ZERO_STRUCT(q);
45         ZERO_STRUCT(r);
46
47         /* Initialise parse structures */
48
49         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
50         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
51
52         /* Initialise input parameters */
53
54         init_srv_q_net_srv_get_info(&q, cli->srv_name_slash, switch_value);
55
56         /* Marshall data and send request */
57
58         if (!srv_io_q_net_srv_get_info("", &q, &qbuf, 0) ||
59             !rpc_api_pipe_req(cli, SRV_NET_SRV_GET_INFO, &qbuf, &rbuf)) {
60                 result = NT_STATUS_UNSUCCESSFUL;
61                 goto done;
62         }
63
64         /* Unmarshall response */
65
66         r.ctr = ctr;
67
68         if (!srv_io_r_net_srv_get_info("", &r, &rbuf, 0)) {
69                 result = NT_STATUS_UNSUCCESSFUL;
70                 goto done;
71         }
72
73         result = r.status;
74
75  done:
76         prs_mem_free(&qbuf);
77         prs_mem_free(&rbuf);
78
79         return result;
80 }