Debian packaging updates from Eloy
[Samba.git] / source / libsmb / cli_pipe_util.c
blob9521d817fa5cbcd44e38624f641f00542030f91a
1 /*
2 Unix SMB/Netbios implementation.
3 Version 2.2
4 RPC pipe client utility functions
5 Copyright (C) Tim Potter 2001,
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 /* Opens a SMB connection to a named pipe */
26 struct cli_state *cli_pipe_initialise(struct cli_state *cli, char *system_name,
27 char *pipe_name,
28 struct ntuser_creds *creds)
30 struct in_addr dest_ip;
31 struct nmb_name calling, called;
32 fstring dest_host;
33 extern pstring global_myname;
34 struct ntuser_creds anon;
36 /* Initialise cli_state information */
38 if (!cli_initialise(cli)) {
39 return NULL;
42 if (!creds) {
43 ZERO_STRUCT(anon);
44 anon.pwd.null_pwd = 1;
45 creds = &anon;
48 cli_init_creds(cli, creds);
50 /* Establish a SMB connection */
52 if (!resolve_srv_name(system_name, dest_host, &dest_ip)) {
53 return NULL;
56 make_nmb_name(&called, dns_to_netbios_name(dest_host), 0x20);
57 make_nmb_name(&calling, dns_to_netbios_name(global_myname), 0);
59 if (!cli_establish_connection(cli, dest_host, &dest_ip, &calling,
60 &called, "IPC$", "IPC", False, True)) {
61 return NULL;
64 /* Open a NT session thingy */
66 if (!cli_nt_session_open(cli, pipe_name)) {
67 cli_shutdown(cli);
68 return NULL;
71 return cli;
74 /* Shut down a SMB connection to the SAMR pipe */
76 void cli_pipe_shutdown(struct cli_state *cli)
78 if (cli->fd != -1) cli_ulogoff(cli);
79 cli_shutdown(cli);