summaryrefslogtreecommitdiff
path: root/source3/rpcclient
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-01-06 09:03:48 +0000
committerTim Potter <tpot@samba.org>2002-01-06 09:03:48 +0000
commit2f25e5118fde9be14275e9ffb1edb210d231dac3 (patch)
tree3beacd41b54b8891da231f74357e33622484c3c6 /source3/rpcclient
parentb77eec91dc6b6df63dcff57fe465f0b4eb73d7a1 (diff)
downloadsamba-2f25e5118fde9be14275e9ffb1edb210d231dac3.tar.gz
samba-2f25e5118fde9be14275e9ffb1edb210d231dac3.tar.bz2
samba-2f25e5118fde9be14275e9ffb1edb210d231dac3.zip
Converted enumprinters and enumports cmd functions to use WERROR
values returned from cli functions. They are converted to NTSTATUS codes using the error map functions. Do buffer size loop checks by setting offered = 0 and using the return value of needed in the next call. (This used to be commit 4efbdda3fcfd1fad2f2b8909d250735382497836)
Diffstat (limited to 'source3/rpcclient')
-rw-r--r--source3/rpcclient/cmd_spoolss.c71
1 files changed, 39 insertions, 32 deletions
diff --git a/source3/rpcclient/cmd_spoolss.c b/source3/rpcclient/cmd_spoolss.c
index 7daa336cc6..a945e11722 100644
--- a/source3/rpcclient/cmd_spoolss.c
+++ b/source3/rpcclient/cmd_spoolss.c
@@ -298,11 +298,10 @@ static NTSTATUS cmd_spoolss_enum_printers(struct cli_state *cli,
TALLOC_CTX *mem_ctx,
int argc, char **argv)
{
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
+ WERROR result;
uint32 info_level = 1;
PRINTER_INFO_CTR ctr;
- int returned;
- uint32 i = 0;
+ uint32 i = 0, num_printers, needed;
if (argc > 2)
{
@@ -316,35 +315,38 @@ static NTSTATUS cmd_spoolss_enum_printers(struct cli_state *cli,
/* Enumerate printers -- Should we enumerate types other
than PRINTER_ENUM_LOCAL? Maybe accept as a parameter? --jerry */
+
ZERO_STRUCT(ctr);
- result = cli_spoolss_enum_printers(cli, mem_ctx, PRINTER_ENUM_LOCAL,
- info_level, &returned, &ctr);
- if (NT_STATUS_IS_OK(result))
- {
- if (!returned)
+ result = cli_spoolss_enum_printers(
+ cli, mem_ctx, 0, &needed, PRINTER_ENUM_LOCAL,
+ info_level, &num_printers, &ctr);
+
+ if (W_ERROR_V(result) == ERRinsufficientbuffer)
+ result = cli_spoolss_enum_printers(
+ cli, mem_ctx, needed, NULL, PRINTER_ENUM_LOCAL,
+ info_level, &num_printers, &ctr);
+
+ if (W_ERROR_IS_OK(result)) {
+ if (!num_printers)
printf ("No Printers printers returned.\n");
switch(info_level) {
case 0:
- for (i=0; i<returned; i++) {
- display_print_info_0(&(ctr.printers_0[i]));
- }
+ for (i=0; i < num_printers; i++)
+ display_print_info_0(&ctr.printers_0[i]);
break;
case 1:
- for (i=0; i<returned; i++) {
- display_print_info_1(&(ctr.printers_1[i]));
- }
+ for (i=0; i < num_printers; i++)
+ display_print_info_1(&ctr.printers_1[i]);
break;
case 2:
- for (i=0; i<returned; i++) {
- display_print_info_2(&(ctr.printers_2[i]));
- }
+ for (i=0; i < num_printers; i++)
+ display_print_info_2(&ctr.printers_2[i]);
break;
case 3:
- for (i=0; i<returned; i++) {
- display_print_info_3(&(ctr.printers_3[i]));
- }
+ for (i=0; i < num_printers; i++)
+ display_print_info_3(&ctr.printers_3[i]);
break;
default:
printf("unknown info level %d\n", info_level);
@@ -352,7 +354,7 @@ static NTSTATUS cmd_spoolss_enum_printers(struct cli_state *cli,
}
}
- return result;
+ return werror_to_ntstatus(result);
}
/****************************************************************************
@@ -389,11 +391,11 @@ static void display_port_info_2(PORT_INFO_2 *i2)
/* Enumerate ports */
static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli,
- TALLOC_CTX *mem_ctx,
- int argc, char **argv)
+ TALLOC_CTX *mem_ctx, int argc,
+ char **argv)
{
- NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
- uint32 info_level = 1;
+ WERROR result;
+ uint32 needed, info_level = 1;
PORT_INFO_CTR ctr;
int returned;
@@ -402,23 +404,28 @@ static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli,
return NT_STATUS_OK;
}
- if (argc == 2) {
+ if (argc == 2)
info_level = atoi(argv[1]);
- }
/* Enumerate ports */
+
ZERO_STRUCT(ctr);
- result = cli_spoolss_enum_ports(cli, mem_ctx, info_level, &returned, &ctr);
+ result = cli_spoolss_enum_ports(cli, mem_ctx, 0, &needed, info_level,
+ &returned, &ctr);
- if (NT_STATUS_IS_OK(result)) {
+ if (W_ERROR_V(result) == ERRinsufficientbuffer)
+ result = cli_spoolss_enum_ports(cli, mem_ctx, needed, NULL,
+ info_level, &returned, &ctr);
+
+ if (W_ERROR_IS_OK(result)) {
int i;
for (i = 0; i < returned; i++) {
switch (info_level) {
case 1:
display_port_info_1(&ctr.port.info_1[i]);
- break;
+ break;
case 2:
display_port_info_2(&ctr.port.info_2[i]);
break;
@@ -428,8 +435,8 @@ static NTSTATUS cmd_spoolss_enum_ports(struct cli_state *cli,
}
}
}
-
- return result;
+
+ return werror_to_ntstatus(result);
}
/***********************************************************************