merge of working dsrolegetprimdominfo() client code from APP_HEAD
[kamenim/samba.git] / source3 / rpc_client / cli_ds.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RPC pipe client
4    Copyright (C) Gerald Carter                        2002,
5    
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 2 of the License, or
9    (at your option) any later version.
10    
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.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /* implementations of client side DsXXX() functions */
24
25 NTSTATUS cli_ds_getprimarydominfo( struct cli_state *cli, TALLOC_CTX *mem_ctx, 
26                                                 uint16 level, DS_DOMINFO_CTR *ctr)
27 {
28         prs_struct qbuf, rbuf;
29         DS_Q_GETPRIMDOMINFO q;
30         DS_R_GETPRIMDOMINFO r;
31         NTSTATUS result;
32
33         ZERO_STRUCT(q);
34         ZERO_STRUCT(r);
35
36         /* Initialise parse structures */
37
38         prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
39         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
40         
41         q.level = level;
42         
43         if (!ds_io_q_getprimdominfo("", &q, &qbuf, 0) 
44                 || !rpc_api_pipe_req(cli, DS_GETPRIMDOMINFO, &qbuf, &rbuf)) 
45         {
46                 result = NT_STATUS_UNSUCCESSFUL;
47                 goto done;
48         }
49
50         /* Unmarshall response */
51
52         if (!ds_io_r_getprimdominfo("", &r, &rbuf, 0)) {
53                 result = NT_STATUS_UNSUCCESSFUL;
54                 goto done;
55         }
56         
57         memcpy( ctr, &r.info, sizeof(DS_DOMINFO_CTR) );
58         result = r.status;
59         
60 done:
61         return result;
62 }
63