Converted getprinterdriver to WERROR - it always returns dos error 6
authorTim Potter <tpot@samba.org>
Mon, 7 Jan 2002 03:33:46 +0000 (03:33 +0000)
committerTim Potter <tpot@samba.org>
Mon, 7 Jan 2002 03:33:46 +0000 (03:33 +0000)
(invalid handle) though.  )-:
(This used to be commit 7bfd1f35e4e194f8a2f07046e4a6c005c256c05b)

source3/libsmb/cli_spoolss.c
source3/rpcclient/cmd_spoolss.c

index e1f624053ca692a98c13a10425b93c8d8fd0e97f..b828640c3bb208958b7c61c2ab5611ccca315eb7 100644 (file)
@@ -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;  
 }
 
index a945e117225e7ebbc4a0a4a98dd38f83a69a5a45..ed656323440f0debbda849cc3840eea705ef0319 100644 (file)
@@ -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;