s3-lanman: fix api_DosPrintQGetInfo().
authorGünther Deschner <gd@samba.org>
Thu, 29 Apr 2010 11:27:58 +0000 (13:27 +0200)
committerGünther Deschner <gd@samba.org>
Thu, 29 Apr 2010 11:47:33 +0000 (13:47 +0200)
Found by torture test.

Guenther

source3/smbd/lanman.c

index b44eb4031c83000aef863c90187bb91fbbcccd6c..1a5d9e89f3246d5174f1fd78e6d950b6619979d1 100644 (file)
@@ -660,6 +660,20 @@ static void fill_printq_info_52(struct spoolss_DriverInfo3 *driver,
 
 }
 
+static const char *strip_unc(const char *unc)
+{
+       char *p;
+
+       if (unc == NULL) {
+               return NULL;
+       }
+
+       if ((p = strrchr(unc, '\\')) != NULL) {
+               return p+1;
+       }
+
+       return unc;
+}
 
 static void fill_printq_info(int uLevel,
                             struct pack_desc* desc,
@@ -672,12 +686,12 @@ static void fill_printq_info(int uLevel,
        case 0:
        case 1:
        case 2:
-               PACKS(desc,"B13", printer_info->printername);
+               PACKS(desc,"B13", strip_unc(printer_info->printername));
                break;
        case 3:
        case 4:
        case 5:
-               PACKS(desc,"z", printer_info->printername);
+               PACKS(desc,"z", strip_unc(printer_info->printername));
                break;
        case 51:
                PACKI(desc,"K", printq_spoolss_status(printer_info->status));
@@ -691,7 +705,7 @@ static void fill_printq_info(int uLevel,
                PACKI(desc,"W",0);              /* until time */
                PACKS(desc,"z","");             /* pSepFile */
                PACKS(desc,"z","lpd");  /* pPrProc */
-               PACKS(desc,"z", printer_info->printername); /* pDestinations */
+               PACKS(desc,"z", strip_unc(printer_info->printername)); /* pDestinations */
                PACKS(desc,"z","");             /* pParms */
                if (printer_info->printername == NULL) {
                        PACKS(desc,"z","UNKNOWN PRINTER");
@@ -716,7 +730,7 @@ static void fill_printq_info(int uLevel,
                   Win9X/ME printer comments. */
                PACKI(desc,"W", printq_spoolss_status(printer_info->status)); /* fsStatus */
                PACKI(desc,(uLevel == 3 ? "W" : "N"),count);    /* cJobs */
-               PACKS(desc,"z", printer_info->printername); /* pszPrinters */
+               PACKS(desc,"z", strip_unc(printer_info->printername)); /* pszPrinters */
                PACKS(desc,"z", printer_info->drivername);              /* pszDriverName */
                PackDriverData(desc);   /* pDriverData */
        }
@@ -841,6 +855,16 @@ static bool api_DosPrintQGetInfo(connection_struct *conn, uint16 vuid,
                goto out;
        }
 
+       werr = rpccli_spoolss_getprinter(cli, mem_ctx,
+                                        &handle,
+                                        2,
+                                        0,
+                                        &printer_info);
+       if (!W_ERROR_IS_OK(werr)) {
+               desc.errcode = W_ERROR_V(werr);
+               goto out;
+       }
+
        if (uLevel==52) {
                uint32_t server_major_version;
                uint32_t server_minor_version;