diff options
Diffstat (limited to 'source3/rpc_client/msrpc_spoolss.c')
-rw-r--r-- | source3/rpc_client/msrpc_spoolss.c | 200 |
1 files changed, 149 insertions, 51 deletions
diff --git a/source3/rpc_client/msrpc_spoolss.c b/source3/rpc_client/msrpc_spoolss.c index 3540ebbafc..671be00bc0 100644 --- a/source3/rpc_client/msrpc_spoolss.c +++ b/source3/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; } |