This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.
[kai/samba-autobuild/.git] / source / libsmb / cli_wkssvc.c
1 /* 
2    Unix SMB/CIFS implementation.
3    NT Domain Authentication SMB / MSRPC client
4    Copyright (C) Andrew Tridgell 1994-2000
5    Copyright (C) Luke Kenneth Casson Leighton 1996-2000
6    Copyright (C) Tim Potter 2001
7    Copytight (C) Rafal Szczesniak 2002
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 /**
27  * Opens a SMB connection to the wkssvc pipe
28  *
29  * @param cli client structure (not yet initialised)
30  * @param system_name called rpc server name
31  * @param creds user credentials
32  *
33  * @return client structure with opened pipe
34  **/
35
36 struct cli_state *cli_wkssvc_initialise(struct cli_state *cli, 
37                                         char *system_name,
38                                         struct ntuser_creds *creds)
39 {
40         return cli_pipe_initialise(cli, system_name, PIPE_WKSSVC, creds);
41 }
42
43
44 /**
45  * WksQueryInfo rpc call (like query for server's capabilities)
46  *
47  * @param initialised client structure with \PIPE\wkssvc opened
48  * @param mem_ctx memory context assigned to this rpc binding
49  * @param wks100 WksQueryInfo structure
50  *
51  * @return NTSTATUS of rpc call
52  */
53  
54 NTSTATUS cli_wks_query_info(struct cli_state *cli, TALLOC_CTX *mem_ctx,
55                             WKS_INFO_100 *wks100)
56 {
57         prs_struct buf;
58         prs_struct rbuf;
59         WKS_Q_QUERY_INFO q_o;
60         WKS_R_QUERY_INFO r_o;
61         NTSTATUS nt_status;
62
63         if (cli == NULL || wks100 == NULL)
64                 return NT_STATUS_UNSUCCESSFUL;
65
66         /* init rpc parse structures */
67         prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
68         prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
69
70         DEBUG(4, ("WksQueryInfo\n"));
71         
72         /* init query structure with rpc call arguments */
73         init_wks_q_query_info(&q_o, cli->desthost, 100);
74         
75         /* marshall data */
76         if (!wks_io_q_query_info("", &q_o, &buf, 0)) {
77                 prs_mem_free(&buf);
78                 prs_mem_free(&rbuf);
79                 return NT_STATUS_UNSUCCESSFUL;
80         }
81         
82         /* actual rpc call over \PIPE\wkssvc */
83         if (!rpc_api_pipe_req(cli, WKS_QUERY_INFO, &buf, &rbuf)) {
84                 prs_mem_free(&buf);
85                 prs_mem_free(&rbuf);
86                 return NT_STATUS_UNSUCCESSFUL;
87         }
88         
89         prs_mem_free(&buf);
90
91         r_o.wks100 = wks100;
92
93         /* get call results from response buffer */
94         if (!wks_io_r_query_info("", &r_o, &rbuf, 0)) {
95                 prs_mem_free(&rbuf);
96                 return NT_STATUS_UNSUCCESSFUL;
97         }
98         
99         /* check returnet status code */
100         if (NT_STATUS_IS_ERR(r_o.status)) {
101                 /* report the error */
102                 DEBUG(0,("WKS_R_QUERY_INFO: %s\n", nt_errstr(r_o.status)));
103                 prs_mem_free(&rbuf);
104                 return r_o.status;
105         }
106         
107         /* do clean up */
108         prs_mem_free(&rbuf);
109         
110         return nt_status;
111 }
112