cli_spoolss_notify.c [plain text]
#include "includes.h"
#include "rpc_parse.h"
#include "nterr.h"
extern pstring global_myname;
BOOL spoolss_disconnect_from_client( struct cli_state *cli)
{
cli_nt_session_close(cli);
cli_ulogoff(cli);
cli_shutdown(cli);
return True;
}
BOOL spoolss_connect_to_client( struct cli_state *cli, char *remote_machine)
{
ZERO_STRUCTP(cli);
if(cli_initialise(cli) == NULL) {
DEBUG(0,("connect_to_client: unable to initialize client connection.\n"));
return False;
}
if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine));
cli_shutdown(cli);
return False;
}
if (ismyip(cli->dest_ip)) {
DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
cli_shutdown(cli);
return False;
}
if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
cli_shutdown(cli);
return False;
}
if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request. Error was %s\n", remote_machine, cli_errstr(cli) ));
cli_shutdown(cli);
return False;
}
cli->protocol = PROTOCOL_NT1;
if (!cli_negprot(cli)) {
DEBUG(0,("connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
cli_shutdown(cli);
return False;
}
if (cli->protocol != PROTOCOL_NT1) {
DEBUG(0,("connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
cli_shutdown(cli);
return False;
}
if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
DEBUG(0,("connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
cli_shutdown(cli);
return False;
}
if (!(cli->sec_mode & 1)) {
DEBUG(0,("connect_to_client: machine %s isn't in user level security mode\n", remote_machine));
cli_shutdown(cli);
return False;
}
if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
DEBUG(0,("connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
cli_shutdown(cli);
return False;
}
if(cli_nt_session_open(cli, PIPE_SPOOLSS) == False) {
DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli)));
cli_nt_session_close(cli);
cli_ulogoff(cli);
cli_shutdown(cli);
return False;
}
return True;
}
BOOL cli_spoolss_reply_open_printer(struct cli_state *cli, char *printer, uint32 localprinter, uint32 type, WERROR *status, POLICY_HND *handle)
{
prs_struct rbuf;
prs_struct buf;
SPOOL_Q_REPLYOPENPRINTER q_s;
SPOOL_R_REPLYOPENPRINTER r_s;
prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
make_spoolss_q_replyopenprinter(&q_s, printer, localprinter, type);
if(!spoolss_io_q_replyopenprinter("", &q_s, &buf, 0)) {
DEBUG(0,("cli_spoolss_reply_open_printer: Error : failed to marshall NET_Q_SRV_PWSET struct.\n"));
prs_mem_free(&buf);
prs_mem_free(&rbuf);
return False;
}
if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYOPENPRINTER, &buf, &rbuf)) {
prs_mem_free(&buf);
prs_mem_free(&rbuf);
return False;
}
prs_mem_free(&buf);
if(!spoolss_io_r_replyopenprinter("", &r_s, &rbuf, 0)) {
prs_mem_free(&rbuf);
return False;
}
prs_mem_free(&rbuf);
memcpy(handle, &r_s.handle, sizeof(r_s.handle));
*status=r_s.status;
return True;
}
BOOL cli_spoolss_reply_rrpcn(struct cli_state *cli, POLICY_HND *handle,
uint32 change_low, uint32 change_high, WERROR *status)
{
prs_struct rbuf;
prs_struct buf;
SPOOL_Q_REPLY_RRPCN q_s;
SPOOL_R_REPLY_RRPCN r_s;
prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
make_spoolss_q_reply_rrpcn(&q_s, handle, change_low, change_high);
if(!spoolss_io_q_reply_rrpcn("", &q_s, &buf, 0)) {
DEBUG(0,("cli_spoolss_reply_rrpcn: Error : failed to marshall SPOOL_Q_REPLY_RRPCN struct.\n"));
prs_mem_free(&buf);
prs_mem_free(&rbuf);
return False;
}
if (!rpc_api_pipe_req(cli, SPOOLSS_RRPCN, &buf, &rbuf)) {
prs_mem_free(&buf);
prs_mem_free(&rbuf);
return False;
}
prs_mem_free(&buf);
if(!spoolss_io_r_reply_rrpcn("", &r_s, &rbuf, 0)) {
prs_mem_free(&rbuf);
return False;
}
prs_mem_free(&rbuf);
*status=r_s.status;
return True;
}
BOOL cli_spoolss_reply_close_printer(struct cli_state *cli, POLICY_HND *handle,
WERROR *status)
{
prs_struct rbuf;
prs_struct buf;
SPOOL_Q_REPLYCLOSEPRINTER q_s;
SPOOL_R_REPLYCLOSEPRINTER r_s;
prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
make_spoolss_q_reply_closeprinter(&q_s, handle);
if(!spoolss_io_q_replycloseprinter("", &q_s, &buf, 0)) {
DEBUG(0,("cli_spoolss_reply_close_printer: Error : failed to marshall SPOOL_Q_REPLY_CLOSEPRINTER struct.\n"));
prs_mem_free(&buf);
prs_mem_free(&rbuf);
return False;
}
if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYCLOSEPRINTER, &buf, &rbuf)) {
prs_mem_free(&buf);
prs_mem_free(&rbuf);
return False;
}
prs_mem_free(&buf);
if(!spoolss_io_r_replycloseprinter("", &r_s, &rbuf, 0)) {
prs_mem_free(&rbuf);
return False;
}
prs_mem_free(&rbuf);
*status=r_s.status;
return True;
}