summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-01-07 03:33:46 +0000
committerTim Potter <tpot@samba.org>2002-01-07 03:33:46 +0000
commit9a02c6b4e8dcdd8bb6f2d394b1c5e9110c11a7a9 (patch)
treed2644bb8f7e680d7645577121df8cca6d9984e2e
parent0094af05edc7a2fcfd672f6fb0d930b5906482a0 (diff)
downloadsamba-9a02c6b4e8dcdd8bb6f2d394b1c5e9110c11a7a9.tar.gz
samba-9a02c6b4e8dcdd8bb6f2d394b1c5e9110c11a7a9.tar.bz2
samba-9a02c6b4e8dcdd8bb6f2d394b1c5e9110c11a7a9.zip
Converted getprinterdriver to WERROR - it always returns dos error 6
(invalid handle) though. )-: (This used to be commit 7bfd1f35e4e194f8a2f07046e4a6c005c256c05b)
-rw-r--r--source3/libsmb/cli_spoolss.c118
-rw-r--r--source3/rpcclient/cmd_spoolss.c28
2 files changed, 81 insertions, 65 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;
}
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index a945e11722..ed65632344 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -663,7 +663,7 @@ static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli,
/* Open a printer handle */
werror = cli_spoolss_open_printer_ex(cli, mem_ctx, printername, "",
- MAXIMUM_ALLOWED_ACCESS,
+ PRINTER_ACCESS_USE,
servername, user, &pol);
result = werror_to_ntstatus(werror);
@@ -676,19 +676,25 @@ static NTSTATUS cmd_spoolss_getdriver(struct cli_state *cli,
opened_hnd = True;
/* loop through and print driver info level for each architecture */
- for (i=0; archi_table[i].long_archi!=NULL; i++)
- {
- result = cli_spoolss_getprinterdriver(cli, mem_ctx, &pol, info_level,
- archi_table[i].long_archi, &ctr);
- if (!NT_STATUS_IS_OK(result)) {
- continue;
- }
+ for (i=0; archi_table[i].long_archi!=NULL; i++) {
+ uint32 needed;
+
+ werror = cli_spoolss_getprinterdriver(
+ cli, mem_ctx, 0, &needed, &pol, info_level,
+ archi_table[i].long_archi, &ctr);
+
+ if (W_ERROR_V(werror) == ERRinsufficientbuffer)
+ werror = cli_spoolss_getprinterdriver(
+ cli, mem_ctx, needed, NULL, &pol, info_level,
+ archi_table[i].long_archi, &ctr);
+
+ if (!W_ERROR_IS_OK(werror))
+ continue;
printf ("\n[%s]\n", archi_table[i].long_archi);
- switch (info_level)
- {
-
+
+ switch (info_level) {
case 1:
display_print_driver_1 (ctr.info1);
break;