summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-02-19 02:12:01 +0000
committerTim Potter <tpot@samba.org>2002-02-19 02:12:01 +0000
commit902cc03807f83167ff9a1d93a09844b27eba6ada (patch)
tree0e9ed48e6409830fc72321627e0e8d6d612cb288
parent25d8d308c8ea6e08bafced33eb2d3e348ec98704 (diff)
downloadsamba-902cc03807f83167ff9a1d93a09844b27eba6ada.tar.gz
samba-902cc03807f83167ff9a1d93a09844b27eba6ada.tar.bz2
samba-902cc03807f83167ff9a1d93a09844b27eba6ada.zip
Converted {cmd,cli}_spoolss_getprinter() to WERROR and offered/neede.
(This used to be commit fccfa034e92bca145b8e0639e405f6af5bb1a50b)
-rw-r--r--source3/libsmb/cli_spoolss.c94
-rw-r--r--source3/rpcclient/cmd_spoolss.c37
2 files changed, 68 insertions, 63 deletions
diff --git a/source3/libsmb/cli_spoolss.c b/source3/libsmb/cli_spoolss.c
index 181852ef7f..661543ebfa 100644
--- a/source3/libsmb/cli_spoolss.c
+++ b/source3/libsmb/cli_spoolss.c
@@ -582,71 +582,67 @@ WERROR cli_spoolss_enum_ports(struct cli_state *cli, TALLOC_CTX *mem_ctx,
}
/* Get printer info */
-NTSTATUS cli_spoolss_getprinter(
- struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
- POLICY_HND *pol,
- uint32 level,
- PRINTER_INFO_CTR *ctr
-)
+WERROR cli_spoolss_getprinter(struct cli_state *cli, TALLOC_CTX *mem_ctx,
+ uint32 offered, uint32 *needed,
+ POLICY_HND *pol, uint32 level,
+ PRINTER_INFO_CTR *ctr)
{
prs_struct qbuf, rbuf;
SPOOL_Q_GETPRINTER q;
SPOOL_R_GETPRINTER r;
NEW_BUFFER buffer;
- uint32 needed = 100;
- NTSTATUS result;
+ WERROR result = W_ERROR(ERRgeneral);
ZERO_STRUCT(q);
ZERO_STRUCT(r);
- do {
- /* Initialise input parameters */
+ /* Initialise input parameters */
+
+ init_buffer(&buffer, offered, mem_ctx);
+
+ prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
+ prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
- init_buffer(&buffer, needed, mem_ctx);
+ make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, offered);
+
+ /* Marshall data and send request */
- prs_init(&qbuf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
- prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
+ if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) ||
+ !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTER, &qbuf, &rbuf))
+ goto done;
- make_spoolss_q_getprinter(mem_ctx, &q, pol, level, &buffer, needed);
+ /* Unmarshall response */
- /* Marshall data and send request */
- if (!spoolss_io_q_getprinter("", &q, &qbuf, 0) ||
- !rpc_api_pipe_req(cli, SPOOLSS_GETPRINTER, &qbuf, &rbuf))
- {
- result = NT_STATUS_UNSUCCESSFUL;
- goto done;
- }
+ if (!spoolss_io_r_getprinter("", &r, &rbuf, 0))
+ goto done;
- /* Unmarshall response */
- if (spoolss_io_r_getprinter("", &r, &rbuf, 0)) {
- needed = r.needed;
- }
-
- /* Return output parameters */
- result = werror_to_ntstatus(r.status);
- if (NT_STATUS_IS_OK(result)) {
- switch (level) {
- case 0:
- decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0);
- break;
- case 1:
- decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1);
- break;
- case 2:
- decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2);
- break;
- case 3:
- decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3);
- break;
- }
- }
+ if (needed)
+ *needed = r.needed;
+
+ /* Return output parameters */
- done:
- prs_mem_free(&qbuf);
- prs_mem_free(&rbuf);
+ result = r.status;
- } while (NT_STATUS_V(result) == NT_STATUS_V(NT_STATUS_BUFFER_TOO_SMALL));
+ if (NT_STATUS_IS_OK(result)) {
+ switch (level) {
+ case 0:
+ decode_printer_info_0(mem_ctx, r.buffer, 1, &ctr->printers_0);
+ break;
+ case 1:
+ decode_printer_info_1(mem_ctx, r.buffer, 1, &ctr->printers_1);
+ break;
+ case 2:
+ decode_printer_info_2(mem_ctx, r.buffer, 1, &ctr->printers_2);
+ break;
+ case 3:
+ decode_printer_info_3(mem_ctx, r.buffer, 1, &ctr->printers_3);
+ 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 49d8b3e6b6..a556783368 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -353,7 +353,7 @@ static NTSTATUS cmd_spoolss_enum_printers(struct cli_state *cli,
}
}
- return werror_to_ntstatus(result);
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/****************************************************************************
@@ -435,7 +435,7 @@ static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli,
}
}
- return werror_to_ntstatus(result);
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/***********************************************************************
@@ -446,14 +446,14 @@ static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli,
int argc, char **argv)
{
POLICY_HND pol;
- WERROR werror;
- NTSTATUS result;
+ WERROR result;
uint32 info_level = 1;
BOOL opened_hnd = False;
PRINTER_INFO_CTR ctr;
fstring printername,
servername,
user;
+ uint32 needed;
if (argc == 1 || argc > 3) {
printf("Usage: %s <printername> [level]\n", argv[0]);
@@ -472,22 +472,25 @@ static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli,
/* get a printer handle */
- werror = cli_spoolss_open_printer_ex(cli, mem_ctx, printername,
+ result = cli_spoolss_open_printer_ex(cli, mem_ctx, printername,
"", MAXIMUM_ALLOWED_ACCESS,
servername, user, &pol);
- result = W_ERROR_IS_OK(werror) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
-
- if (!NT_STATUS_IS_OK(result))
+ if (!W_ERROR_IS_OK(result))
goto done;
opened_hnd = True;
/* Get printer info */
- result = cli_spoolss_getprinter(cli, mem_ctx, &pol, info_level, &ctr);
+ result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed,
+ &pol, info_level, &ctr);
- if (!NT_STATUS_IS_OK(result))
+ if (W_ERROR_V(result) == ERRinsufficientbuffer)
+ result = cli_spoolss_getprinter(
+ cli, mem_ctx, needed, NULL, &pol, info_level, &ctr);
+
+ if (!W_ERROR_IS_OK(result))
goto done;
/* Display printer info */
@@ -514,7 +517,7 @@ static NTSTATUS cmd_spoolss_getprinter(struct cli_state *cli,
if (opened_hnd)
cli_spoolss_close_printer(cli, mem_ctx, &pol);
- return result;
+ return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
}
/****************************************************************************
@@ -1073,6 +1076,7 @@ static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli,
fstring servername,
printername,
user;
+ uint32 needed;
/* parse the command arguements */
if (argc != 3)
@@ -1092,7 +1096,7 @@ static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli,
MAXIMUM_ALLOWED_ACCESS,
servername, user, &pol);
- nt_status = werror_to_ntstatus(result);
+ nt_status = W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL;
if (!NT_STATUS_IS_OK(nt_status))
goto done;
@@ -1104,9 +1108,14 @@ static NTSTATUS cmd_spoolss_setdriver(struct cli_state *cli,
ZERO_STRUCT (info2);
ctr.printers_2 = &info2;
- nt_status = cli_spoolss_getprinter(cli, mem_ctx, &pol, level, &ctr);
+ result = cli_spoolss_getprinter(cli, mem_ctx, 0, &needed,
+ &pol, level, &ctr);
- if (!NT_STATUS_IS_OK(nt_status)) {
+ if (W_ERROR_V(result) == ERRinsufficientbuffer)
+ result = cli_spoolss_getprinter(
+ cli, mem_ctx, needed, NULL, &pol, level, &ctr);
+
+ if (!W_ERROR_IS_OK(result)) {
printf ("Unable to retrieve printer information!\n");
goto done;
}