Removed version number from file header.
[metze/samba/wip.git] / source3 / libsmb / cli_pipe_util.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RPC pipe client utility functions
4    Copyright (C) Tim Potter                        2001,
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 /** \defgroup rpc_client RPC Client routines
24  */
25
26 /* Opens a SMB connection to a named pipe */
27
28 struct cli_state *cli_pipe_initialise(struct cli_state *cli, char *system_name,
29                                       char *pipe_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_name)) {
69                 cli_shutdown(cli);
70                 return NULL;
71         }
72
73         return cli;
74 }
75
76 /* Shut down a SMB connection to the SAMR pipe */
77
78 void cli_pipe_shutdown(struct cli_state *cli)
79 {
80         if (cli->fd != -1) cli_ulogoff(cli);
81         cli_shutdown(cli);
82 }