diff options
Diffstat (limited to 'source3/libsmb/cli_spoolss.c')
-rw-r--r-- | source3/libsmb/cli_spoolss.c | 118 |
1 files changed, 64 insertions, 54 deletions
diff --git a/source3/libsmb/cli_spoolss.c b/source3/libsmb/cli_spoolss.c index e1f624053c..b828640c3b 100644 --- a/source3/libsmb/cli_spoolss.c +++ b/source3/libsmb/cli_spoolss.c @@ -687,24 +687,36 @@ done: return result; } -/********************************************************************** - * Get installed printer drivers for a given printer +/** Get installed printer drivers for a given printer + * + * @param cli Pointer to client state structure which is open + * on the SPOOLSS pipe. + * + * @param mem_ctx Pointer to an initialised talloc context. + * + * @param offered Buffer size offered in the request. + * @param needed Number of bytes needed to complete the request. + * may be NULL. + * + * @param pol Pointer to an open policy handle for the printer + * opened with cli_spoolss_open_printer_ex(). + * @param level Requested information level. + * @param env The print environment or archictecture. This is + * "Windows NT x86" for NT4. + * @param ctr Returned printer driver information. */ -NTSTATUS cli_spoolss_getprinterdriver ( - struct cli_state *cli, - TALLOC_CTX *mem_ctx, - POLICY_HND *pol, - uint32 level, - char* env, - PRINTER_DRIVER_CTR *ctr -) + +WERROR cli_spoolss_getprinterdriver(struct cli_state *cli, + TALLOC_CTX *mem_ctx, + uint32 offered, uint32 *needed, + POLICY_HND *pol, uint32 level, + char *env, PRINTER_DRIVER_CTR *ctr) { prs_struct qbuf, rbuf; SPOOL_Q_GETPRINTERDRIVER2 q; SPOOL_R_GETPRINTERDRIVER2 r; NEW_BUFFER buffer; - uint32 needed = 1024; - NTSTATUS result; + WERROR result = W_ERROR(ERRgeneral); fstring server; ZERO_STRUCT(q); @@ -713,57 +725,55 @@ NTSTATUS cli_spoolss_getprinterdriver ( fstrcpy (server, cli->desthost); strupper (server); - do - { - /* Initialise input parameters */ + /* Initialise input parameters */ - init_buffer(&buffer, needed, mem_ctx); + init_buffer(&buffer, offered, mem_ctx); - prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); - prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL); + prs_init(&rbuf, 0, mem_ctx, UNMARSHALL); + make_spoolss_q_getprinterdriver2(&q, pol, env, level, 2, 2, + &buffer, offered); - /* write the request */ - make_spoolss_q_getprinterdriver2(&q, pol, env, level, 2, 2, &buffer, needed); + /* Marshall data and send request */ - /* Marshall data and send request */ - if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) || - !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf)) - { - result = NT_STATUS_UNSUCCESSFUL; - goto done; - } + if (!spoolss_io_q_getprinterdriver2 ("", &q, &qbuf, 0) || + !rpc_api_pipe_req (cli, SPOOLSS_GETPRINTERDRIVER2, &qbuf, &rbuf)) + goto done; - /* Unmarshall response */ - if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) - { - needed = r.needed; - } - - /* Return output parameters */ - result = werror_to_ntstatus(r.status); - if (NT_STATUS_IS_OK(result)) - { - switch (level) - { - case 1: - decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1); - break; - case 2: - decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2); - break; - case 3: - decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3); - break; - } - } + /* Unmarshall response */ - done: - prs_mem_free(&qbuf); - prs_mem_free(&rbuf); + if (spoolss_io_r_getprinterdriver2 ("", &r, &rbuf, 0)) { + if (needed) + *needed = r.needed; + } - } while (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_BUFFER_TOO_SMALL)); + result = r.status; + + /* Return output parameters */ + + if (!W_ERROR_IS_OK(result)) + goto done; + + if (!ctr) + goto done; + + switch (level) { + case 1: + decode_printer_driver_1(mem_ctx, r.buffer, 1, &ctr->info1); + break; + case 2: + decode_printer_driver_2(mem_ctx, r.buffer, 1, &ctr->info2); + break; + case 3: + decode_printer_driver_3(mem_ctx, r.buffer, 1, &ctr->info3); + break; + } + done: + prs_mem_free(&qbuf); + prs_mem_free(&rbuf); + return result; } |