diff options
Diffstat (limited to 'source/rpc_client')
-rw-r--r-- | source/rpc_client/cli_spoolss.c | 137 | ||||
-rw-r--r-- | source/rpc_client/msrpc_spoolss.c | 200 |
2 files changed, 250 insertions, 87 deletions
diff --git a/source/rpc_client/cli_spoolss.c b/source/rpc_client/cli_spoolss.c index 3e12454cb25..5dda49b4b57 100644 --- a/source/rpc_client/cli_spoolss.c +++ b/source/rpc_client/cli_spoolss.c @@ -32,24 +32,23 @@ extern int DEBUGLEVEL; /**************************************************************************** do a SPOOLSS Enum Printer Drivers ****************************************************************************/ -uint32 spoolss_enum_printerdrivers(const char * srv_name, - const char *environment, - uint32 level, - NEW_BUFFER *buffer, uint32 offered, - uint32 *needed, uint32 *returned) +uint32 spoolss_enum_printerdrivers(const char *srv_name, const char *environment, + uint32 level, NEW_BUFFER *buffer, uint32 offered, + uint32 *needed, uint32 *returned) { prs_struct rbuf; prs_struct buf; SPOOL_Q_ENUMPRINTERDRIVERS q_o; SPOOL_R_ENUMPRINTERDRIVERS r_o; + TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs); struct cli_connection *con = NULL; if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con)) return False; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, ctx, MARSHALL); + prs_init(&rbuf, 0, 4, ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */ @@ -108,14 +107,15 @@ uint32 spoolss_enum_printers(uint32 flags, fstring srv_name, uint32 level, prs_struct buf; SPOOL_Q_ENUMPRINTERS q_o; SPOOL_R_ENUMPRINTERS r_o; + TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs); struct cli_connection *con = NULL; if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con)) return False; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, ctx, MARSHALL); + prs_init(&rbuf, 0, 4, ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */ @@ -172,14 +172,15 @@ uint32 spoolss_enum_ports(fstring srv_name, uint32 level, prs_struct buf; SPOOL_Q_ENUMPORTS q_o; SPOOL_R_ENUMPORTS r_o; + TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs); struct cli_connection *con = NULL; if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con)) return False; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, ctx, MARSHALL); + prs_init(&rbuf, 0, 4, ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUMPORTS */ @@ -236,12 +237,13 @@ uint32 spoolss_enum_jobs(const POLICY_HND *hnd, uint32 firstjob, uint32 numofjob prs_struct buf; SPOOL_Q_ENUMJOBS q_o; SPOOL_R_ENUMJOBS r_o; + TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs); if (hnd == NULL) return NT_STATUS_INVALID_PARAMETER; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, ctx, MARSHALL); + prs_init(&rbuf, 0, 4, ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */ @@ -283,20 +285,26 @@ uint32 spoolss_enum_jobs(const POLICY_HND *hnd, uint32 firstjob, uint32 numofjob do a SPOOLSS Enum printer datas ****************************************************************************/ uint32 spoolss_enum_printerdata(const POLICY_HND *hnd, uint32 idx, - uint32 *valuelen, uint16 *value, uint32 *rvaluelen, - uint32 *type, - uint32 *datalen, uint8 *data, uint32 *rdatalen) + uint32 *valuelen, uint16 *value, uint32 *rvaluelen, + uint32 *type, uint32 *datalen, uint8 *data, + uint32 *rdatalen) { prs_struct rbuf; prs_struct buf; SPOOL_Q_ENUMPRINTERDATA q_o; SPOOL_R_ENUMPRINTERDATA r_o; - + TALLOC_CTX *mem_ctx = NULL; + if (hnd == NULL) return NT_STATUS_INVALID_PARAMETER; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n")); + return False; + } + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, 4, mem_ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUMPRINTERDATA*/ @@ -333,6 +341,8 @@ uint32 spoolss_enum_printerdata(const POLICY_HND *hnd, uint32 idx, prs_mem_free(&rbuf); prs_mem_free(&buf ); + if (mem_ctx) + talloc_destroy(mem_ctx); return r_o.status; } @@ -348,12 +358,13 @@ uint32 spoolss_getprinter(const POLICY_HND *hnd, uint32 level, prs_struct buf; SPOOL_Q_GETPRINTER q_o; SPOOL_R_GETPRINTER r_o; + TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs); if (hnd == NULL) return NT_STATUS_INVALID_PARAMETER; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, ctx, MARSHALL); + prs_init(&rbuf, 0, 4, ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */ @@ -403,12 +414,13 @@ uint32 spoolss_getprinterdriver(const POLICY_HND *hnd, prs_struct buf; SPOOL_Q_GETPRINTERDRIVER2 q_o; SPOOL_R_GETPRINTERDRIVER2 r_o; + TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs); if (hnd == NULL) return NT_STATUS_INVALID_PARAMETER; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, ctx, MARSHALL); + prs_init(&rbuf, 0, 4, ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */ @@ -462,9 +474,9 @@ BOOL spoolss_open_printer_ex( const char *printername, BOOL valid_pol = False; fstring srv_name; char *s = NULL; - struct cli_connection *con = NULL; - + TALLOC_CTX *mem_ctx = NULL; + memset(srv_name, 0, sizeof(srv_name)); fstrcpy(srv_name, printername); @@ -475,10 +487,16 @@ BOOL spoolss_open_printer_ex( const char *printername, if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con)) return False; - if (hnd == NULL) return False; + if (hnd == NULL) + return False; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n")); + return False; + } + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, 4, mem_ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_OPENPRINTEREX */ @@ -517,11 +535,44 @@ BOOL spoolss_open_printer_ex( const char *printername, prs_mem_free(&rbuf); prs_mem_free(&buf ); + if (mem_ctx) + talloc_destroy(mem_ctx); return valid_pol; } /**************************************************************************** + do a SPOOLSS AddPrinterEx() + **ALWAYS** uses as PRINTER_INFO level 2 struct +****************************************************************************/ +BOOL spoolss_addprinterex(POLICY_HND *hnd, PRINTER_INFO_2 *info2) +{ +#if 0 + prs_struct rbuf; + prs_struct buf; + SPOOL_Q_ADDPRINTEREX q_o; + BOOL valid_pol = False; + fstring srv_name; + char *s = NULL; + struct cli_connection *con = NULL; + + + memset(srv_name, 0, sizeof(srv_name)); + unistr_to_ascii(srv_name, info2->servername.buffer, sizeof(srv_name)); + + if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con)) + return False; + + if (hnd == NULL) return False; + + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); + prs_init(&rbuf, 0, 4, UNMARSHALL); +#endif + + return True; +} + +/**************************************************************************** do a SPOOL Close ****************************************************************************/ BOOL spoolss_closeprinter(POLICY_HND *hnd) @@ -530,14 +581,19 @@ BOOL spoolss_closeprinter(POLICY_HND *hnd) prs_struct buf; SPOOL_Q_CLOSEPRINTER q_c; BOOL valid_close = False; - + TALLOC_CTX *mem_ctx = NULL; + if (hnd == NULL) return False; /* create and send a MSRPC command with api SPOOLSS_CLOSEPRINTER */ - - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n")); + return False; + } + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, 4, mem_ctx, UNMARSHALL); DEBUG(4,("SPOOL Close Printer\n")); @@ -563,6 +619,8 @@ BOOL spoolss_closeprinter(POLICY_HND *hnd) prs_mem_free(&rbuf); prs_mem_free(&buf ); + if (mem_ctx) + talloc_destroy(mem_ctx); /* disassociate with the cli_connection */ RpcHndList_del_connection(hnd); @@ -584,12 +642,18 @@ uint32 spoolss_getprinterdata(const POLICY_HND *hnd, const UNISTR2 *valuename, prs_struct buf; SPOOL_Q_GETPRINTERDATA q_o; SPOOL_R_GETPRINTERDATA r_o; + TALLOC_CTX *mem_ctx = NULL; if (hnd == NULL) return NT_STATUS_INVALID_PARAMETER; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n")); + return False; + } + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, 4, mem_ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_GETPRINTERDATA */ @@ -638,14 +702,15 @@ uint32 spoolss_getprinterdriverdir(fstring srv_name, fstring env_name, uint32 le prs_struct buf; SPOOL_Q_GETPRINTERDRIVERDIR q_o; SPOOL_R_GETPRINTERDRIVERDIR r_o; + TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs); struct cli_connection *con = NULL; if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con)) return False; - prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL); - prs_init(&rbuf, 0, 4, UNMARSHALL); + prs_init(&buf , MAX_PDU_FRAG_LEN, 4, ctx, MARSHALL); + prs_init(&rbuf, 0, 4, ctx, UNMARSHALL); /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */ diff --git a/source/rpc_client/msrpc_spoolss.c b/source/rpc_client/msrpc_spoolss.c index 3540ebbafc5..671be00bc06 100644 --- a/source/rpc_client/msrpc_spoolss.c +++ b/source/rpc_client/msrpc_spoolss.c @@ -38,12 +38,12 @@ extern struct user_creds *usr_creds; /******************************************************************** initialize a spoolss NEW_BUFFER. ********************************************************************/ -static void init_buffer(NEW_BUFFER *buffer, uint32 size) +void init_buffer(NEW_BUFFER *buffer, uint32 size, TALLOC_CTX *ctx) { buffer->ptr = (size!=0)? 1:0; buffer->size=size; buffer->string_at_end=size; - prs_init(&buffer->prs, size, 4, MARSHALL); + prs_init(&buffer->prs, size, 4, ctx, MARSHALL); buffer->struct_start = prs_offset(&buffer->prs); } @@ -181,49 +181,47 @@ static void decode_printerdriverdir_info_1(NEW_BUFFER *buffer, DRIVER_DIRECTORY_ /* *info=inf;*/ } - /********************************************************************** - Decode a PORT_INFO_2 struct from a NEW_BUFFER + Decode a PORT_INFO_1 struct from a NEW_BUFFER **********************************************************************/ -void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned, - PORT_INFO_2 **info) +void decode_port_info_1(NEW_BUFFER *buffer, uint32 returned, + PORT_INFO_1 **info) { uint32 i; - PORT_INFO_2 *inf; + PORT_INFO_1 *inf; - inf=(PORT_INFO_2*)malloc(returned*sizeof(PORT_INFO_2)); + inf=(PORT_INFO_1*)malloc(returned*sizeof(PORT_INFO_1)); prs_set_offset(&buffer->prs, 0); for (i=0; i<returned; i++) { - new_smb_io_port_info_2("", buffer, &(inf[i]), 0); + new_smb_io_port_info_1("", buffer, &(inf[i]), 0); } *info=inf; } /********************************************************************** - Decode a PORT_INFO_1 struct from a NEW_BUFFER + Decode a PORT_INFO_2 struct from a NEW_BUFFER **********************************************************************/ -void decode_port_info_1(NEW_BUFFER *buffer, uint32 returned, - PORT_INFO_1 **info) +void decode_port_info_2(NEW_BUFFER *buffer, uint32 returned, + PORT_INFO_2 **info) { uint32 i; - PORT_INFO_1 *inf; + PORT_INFO_2 *inf; - inf=(PORT_INFO_1*)malloc(returned*sizeof(PORT_INFO_1)); + inf=(PORT_INFO_2*)malloc(returned*sizeof(PORT_INFO_2)); prs_set_offset(&buffer->prs, 0); for (i=0; i<returned; i++) { - /* WRITEME!!!! yet to be written --jerry */ - /* new_smb_io_port_info_1("", buffer, &(inf[i]), 0); */ - ;; + new_smb_io_port_info_2("", buffer, &(inf[i]), 0); } *info=inf; } + /**************************************************************************** nt spoolss query ****************************************************************************/ @@ -234,15 +232,21 @@ BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags, NEW_BUFFER buffer; uint32 needed; uint32 returned; + TALLOC_CTX *mem_ctx = NULL; - init_buffer(&buffer, 0); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enum_printers: talloc_init failed!\n")); + return False; + } + init_buffer(&buffer, 0, mem_ctx); /* send a NULL buffer first */ status=spoolss_enum_printers(flags, srv_name, level, &buffer, 0, &needed, &returned); if (status==ERROR_INSUFFICIENT_BUFFER) { - init_buffer(&buffer, needed); + init_buffer(&buffer, needed, mem_ctx); status=spoolss_enum_printers(flags, srv_name, level, &buffer, needed, &needed, &returned); } @@ -250,7 +254,11 @@ BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags, report(out_hnd, "\tstatus:[%d (%x)]\n", status, status); if (status!=NT_STATUS_NO_PROBLEMO) + { + if (mem_ctx) + talloc_destroy(mem_ctx); return False; + } /* is there anything to process? */ if (returned != 0) @@ -272,6 +280,9 @@ BOOL msrpc_spoolss_enum_printers(char* srv_name, uint32 flags, display_printer_info_ctr(out_hnd, ACTION_FOOTER , level, returned, ctr); } + if (mem_ctx) + talloc_destroy(mem_ctx); + return True; } @@ -285,15 +296,22 @@ BOOL msrpc_spoolss_enum_ports(char* srv_name, NEW_BUFFER buffer; uint32 needed; uint32 returned; + TALLOC_CTX *mem_ctx = NULL; + + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enum_ports: talloc_init failed!\n")); + return False; + } - init_buffer(&buffer, 0); + init_buffer(&buffer, 0, mem_ctx); /* send a NULL buffer first */ status=spoolss_enum_ports(srv_name, level, &buffer, 0, &needed, &returned); if (status==ERROR_INSUFFICIENT_BUFFER) { - init_buffer(&buffer, needed); + init_buffer(&buffer, needed, mem_ctx); status=spoolss_enum_ports(srv_name, level, &buffer, needed, &needed, &returned); } @@ -301,7 +319,11 @@ BOOL msrpc_spoolss_enum_ports(char* srv_name, report(out_hnd, "\tstatus:[%d (%x)]\n", status, status); if (status!=NT_STATUS_NO_PROBLEMO) + { + if (mem_ctx) + talloc_destroy(mem_ctx); return False; + } /* is there anything to process? */ if (returned != 0) @@ -322,6 +344,10 @@ BOOL msrpc_spoolss_enum_ports(char* srv_name, display_port_info_ctr(out_hnd, ACTION_ENUMERATE, level, returned, ctr); display_port_info_ctr(out_hnd, ACTION_FOOTER , level, returned, ctr); } + if (mem_ctx) + talloc_destroy(mem_ctx); + + return True; } @@ -343,7 +369,8 @@ uint32 msrpc_spoolss_getprinterdata( const char* printer_name, uint32 size; char *data; UNISTR2 uni_val_name; - + TALLOC_CTX *mem_ctx = NULL; + DEBUG(4,("spoolgetdata - printer: %s server: %s user: %s value: %s\n", printer_name, station, user_name, value_name)); @@ -355,22 +382,33 @@ uint32 msrpc_spoolss_getprinterdata( const char* printer_name, init_unistr2(&uni_val_name, value_name, 0); size = 0; - init_buffer(buffer, size); data = NULL; + + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_getprinterdata: talloc_init failed!\n")); + return False; + } + init_buffer(buffer, size, mem_ctx); + status = spoolss_getprinterdata(&hnd, &uni_val_name, size, type, &size, data, &needed); if (status == ERROR_INSUFFICIENT_BUFFER) { size = needed; - init_buffer(buffer, size); + init_buffer(buffer, size, mem_ctx); data = prs_data_p(&buffer->prs); status = spoolss_getprinterdata(&hnd, &uni_val_name, size, type, &size, data, &needed); } + + if (mem_ctx) + talloc_destroy(mem_ctx); - if (status != NT_STATUS_NO_PROBLEMO) { + if (status != NT_STATUS_NO_PROBLEMO) + { if (!spoolss_closeprinter(&hnd)) return NT_STATUS_ACCESS_DENIED; return status; @@ -399,22 +437,33 @@ BOOL msrpc_spoolss_enum_jobs( const char* printer_name, uint32 returned; uint32 firstjob=0; uint32 numofjobs=0xffff; - + TALLOC_CTX *mem_ctx = NULL; + DEBUG(4,("spoolopen - printer: %s server: %s user: %s\n", printer_name, station, user_name)); if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name, &hnd)) return False; - init_buffer(&buffer, 0); - status = spoolss_enum_jobs(&hnd, firstjob, numofjobs, level, &buffer, 0, &needed, &returned); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n")); + return False; + } + init_buffer(&buffer, 0, mem_ctx); + status = spoolss_enum_jobs(&hnd, firstjob, numofjobs, level, + &buffer, 0, &needed, &returned); if (status == ERROR_INSUFFICIENT_BUFFER) { - init_buffer(&buffer, needed); - status = spoolss_enum_jobs( &hnd, firstjob, numofjobs, level, &buffer, needed, &needed, &returned); + init_buffer(&buffer, needed, mem_ctx); + status = spoolss_enum_jobs( &hnd, firstjob, numofjobs, level, + &buffer, needed, &needed, &returned); } + if (mem_ctx) + talloc_destroy(mem_ctx); + if (status!=NT_STATUS_NO_PROBLEMO) { if (!spoolss_closeprinter(&hnd)) return False; @@ -446,8 +495,8 @@ BOOL msrpc_spoolss_enum_printerdata( const char* printer_name, uint32 rdatalen; uint32 maxvaluelen; uint32 maxdatalen; - - DEBUG(4,("spoolenum_printerdata - printer: %s\n", printer_name)); + + DEBUG(4,("msrpc_spoolss_enum_printerdata - printer: %s\n", printer_name)); if(!spoolss_open_printer_ex( printer_name, 0, 0, station, user_name, &hnd)) return False; @@ -519,25 +568,35 @@ BOOL msrpc_spoolss_getprinter( const char* printer_name, const uint32 level, uint32 status=0; NEW_BUFFER buffer; uint32 needed=1000; - + TALLOC_CTX *mem_ctx = NULL; + DEBUG(4,("spoolenum_getprinter - printer: %s\n", printer_name)); if(!spoolss_open_printer_ex( printer_name, "", PRINTER_ALL_ACCESS, station, user_name, &hnd)) return False; - init_buffer(&buffer, needed); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_getprinter: talloc_init failed!\n")); + return False; + } + init_buffer(&buffer, needed, mem_ctx); status = spoolss_getprinter(&hnd, level, &buffer, needed, &needed); if (status==ERROR_INSUFFICIENT_BUFFER) { - init_buffer(&buffer, needed); + init_buffer(&buffer, needed, mem_ctx); status = spoolss_getprinter(&hnd, level, &buffer, needed, &needed); } report(out_hnd, "\tstatus:[%d (%x)]\n", status, status); if (status!=NT_STATUS_NO_PROBLEMO) + { + if (mem_ctx) + talloc_destroy(mem_ctx); return False; + } switch (level) { case 0: @@ -558,6 +617,9 @@ BOOL msrpc_spoolss_getprinter( const char* printer_name, const uint32 level, display_printer_info_ctr(out_hnd, ACTION_ENUMERATE, level, 1, ctr); display_printer_info_ctr(out_hnd, ACTION_FOOTER , level, 1, ctr); + if (mem_ctx) + talloc_destroy(mem_ctx); + if (status!=NT_STATUS_NO_PROBLEMO) { if (!spoolss_closeprinter(&hnd)) return False; @@ -579,25 +641,35 @@ BOOL msrpc_spoolss_getprinterdriver( const char* printer_name, uint32 status=0; NEW_BUFFER buffer; uint32 needed; - - DEBUG(4,("spoolenum_getprinterdriver - printer: %s\n", printer_name)); + TALLOC_CTX *mem_ctx = NULL; + + DEBUG(4,("msrpc_spoolss_enum_getprinterdriver - printer: %s\n", printer_name)); if(!spoolss_open_printer_ex( printer_name, "", PRINTER_ALL_ACCESS, station, user_name, &hnd)) return False; - init_buffer(&buffer, 0); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_getprinterdriver: talloc_init failed!\n")); + return False; + } + init_buffer(&buffer, 0, mem_ctx); status = spoolss_getprinterdriver(&hnd, environment, level, &buffer, 0, &needed); if (status==ERROR_INSUFFICIENT_BUFFER) { - init_buffer(&buffer, needed); + init_buffer(&buffer, needed, mem_ctx); status = spoolss_getprinterdriver(&hnd, environment, level, &buffer, needed, &needed); } report(out_hnd, "\tstatus:[%d (%x)]\n", status, status); if (status!=NT_STATUS_NO_PROBLEMO) + { + if (mem_ctx) + talloc_destroy(mem_ctx); return False; + } switch (level) { case 1: @@ -615,6 +687,9 @@ BOOL msrpc_spoolss_getprinterdriver( const char* printer_name, display_printer_driver_ctr(out_hnd, ACTION_ENUMERATE, level, 1, ctr); display_printer_driver_ctr(out_hnd, ACTION_FOOTER , level, 1, ctr); + if (mem_ctx) + talloc_destroy(mem_ctx); + if (status!=NT_STATUS_NO_PROBLEMO) { if (!spoolss_closeprinter(&hnd)) return False; @@ -635,17 +710,23 @@ BOOL msrpc_spoolss_enumprinterdrivers( const char* srv_name, NEW_BUFFER buffer; uint32 needed; uint32 returned; + TALLOC_CTX *mem_ctx = NULL; + + DEBUG(4,("msrpc_spoolss_enum_enumprinterdrivers - server: %s\n", srv_name)); - DEBUG(4,("spoolenum_enumprinterdrivers - server: %s\n", srv_name)); - - init_buffer(&buffer, 0); + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_enumprinterdrivers: talloc_init failed!\n")); + return False; + } + init_buffer(&buffer, 0, mem_ctx); status = spoolss_enum_printerdrivers(srv_name, environment, level, &buffer, 0, &needed, &returned); if (status == ERROR_INSUFFICIENT_BUFFER) { - init_buffer(&buffer, needed); + init_buffer(&buffer, needed, mem_ctx); status = spoolss_enum_printerdrivers( srv_name, environment, level, &buffer, needed, &needed, &returned); } @@ -653,7 +734,11 @@ BOOL msrpc_spoolss_enumprinterdrivers( const char* srv_name, report(out_hnd, "\tstatus:[%d (%x)]\n", status, status); if (status!=NT_STATUS_NO_PROBLEMO) + { + if (mem_ctx) + talloc_destroy(mem_ctx); return False; + } switch (level) { @@ -678,6 +763,9 @@ BOOL msrpc_spoolss_enumprinterdrivers( const char* srv_name, display_printer_driver_ctr(out_hnd, ACTION_ENUMERATE, level, returned, ctr); display_printer_driver_ctr(out_hnd, ACTION_FOOTER , level, returned, ctr); + if (mem_ctx) + talloc_destroy(mem_ctx); + return True; } @@ -688,26 +776,32 @@ BOOL msrpc_spoolss_getprinterdriverdir(char* srv_name, char* env_name, uint32 le { uint32 status; NEW_BUFFER buffer; - uint32 needed = 502; - - init_buffer(&buffer, 0); + uint32 needed; + TALLOC_CTX *mem_ctx = NULL; + + if ((mem_ctx=talloc_init()) == NULL) + { + DEBUG(0,("msrpc_spoolss_getprinterdriverdir: talloc_init failed!\n")); + return False; + } + init_buffer(&buffer, 0, mem_ctx); -#if 0 /* JERRY */ /* send a NULL buffer first */ status=spoolss_getprinterdriverdir(srv_name, env_name, level, &buffer, 0, &needed); if (status==ERROR_INSUFFICIENT_BUFFER) { -#endif - init_buffer(&buffer, needed); + init_buffer(&buffer, needed, mem_ctx); status=spoolss_getprinterdriverdir(srv_name, env_name, level, &buffer, needed, &needed); -#if 0 } -#endif report(out_hnd, "\tstatus:[%d (%x)]\n", status, status); if (status!=NT_STATUS_NO_PROBLEMO) + { + if (mem_ctx) + talloc_destroy(mem_ctx); return False; + } switch (level) { case 1: @@ -718,6 +812,10 @@ BOOL msrpc_spoolss_getprinterdriverdir(char* srv_name, char* env_name, uint32 le display_printerdriverdir_info_ctr(out_hnd, ACTION_HEADER , level, ctr); display_printerdriverdir_info_ctr(out_hnd, ACTION_ENUMERATE, level, ctr); display_printerdriverdir_info_ctr(out_hnd, ACTION_FOOTER , level, ctr); + + if (mem_ctx) + talloc_destroy(mem_ctx); + return True; } |