an attempt to get the handling of fields in printer info structures
authorAndrew Tridgell <tridge@samba.org>
Wed, 8 Nov 2000 03:12:16 +0000 (03:12 +0000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 8 Nov 2000 03:12:16 +0000 (03:12 +0000)
consistent. Still working with Jeremy on this, there is probably more
to be done
(This used to be commit c4bb9c598cf9781d48bc123a8cbbed9c2049bf89)

source3/printing/nt_printing.c
source3/rpc_server/srv_spoolss_nt.c

index c70a6891d4794f39d779e4070417a188d5faf9ff..3712cfbb1447ca0527c712d71d7e840c4317f415 100644 (file)
@@ -1431,9 +1431,8 @@ NT_DEVICEMODE *construct_nt_devicemode(const fstring default_devicename)
 
        ZERO_STRUCTP(nt_devmode);
 
-       snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, default_devicename);
-       fstrcpy(nt_devmode->devicename, adevice);
-       
+       safe_strcpy(adevice, default_devicename, sizeof(adevice));
+       fstrcpy(nt_devmode->devicename, adevice);       
        
        fstrcpy(nt_devmode->formname, "Letter");
 
@@ -1663,8 +1662,10 @@ static uint32 get_a_printer_2_default(NT_PRINTER_INFO_LEVEL_2 **info_ptr, fstrin
 
        snum = lp_servicenumber(sharename);
 
-       fstrcpy(info.servername, global_myname);
-       fstrcpy(info.printername, sharename);
+       slprintf(info.servername, sizeof(info.servername), "\\\\%s", global_myname);
+       slprintf(info.printername, sizeof(info.printername), "\\\\%s\\%s", 
+                global_myname, sharename);
+       fstrcpy(info.sharename, sharename);
        fstrcpy(info.portname, SAMBA_PRINTER_PORT_NAME);
        fstrcpy(info.drivername, lp_printerdriver(snum));
        pstrcpy(info.comment, "");
index 67b29bdbcf84339805e77c5adf4306705e351d51..86c97b33ef7eec9afc154439a667ced649970c6d 100644 (file)
@@ -1103,12 +1103,19 @@ static void spoolss_notify_server_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, p
 static void spoolss_notify_printer_name(int snum, SPOOL_NOTIFY_INFO_DATA *data, print_queue_struct *queue,
                                                                                NT_PRINTER_INFO_LEVEL *printer)
 {
+       /* the notify name should not contain the \\server\ part */
+       char *p = strrchr(printer->info_2->printername, '\\');
+       if (!p) {
+               p = printer->info_2->printername;
+       } else {
+               p++;
+       }
 /*
        data->notify_data.data.length=strlen(lp_servicename(snum));
        dos_PutUniCode(data->notify_data.data.string, lp_servicename(snum), sizeof(data->notify_data.data.string), True);
 */
        data->notify_data.data.length=(uint32)((dos_PutUniCode((char *)data->notify_data.data.string,
-                               printer->info_2->printername, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16));
+                               p, sizeof(data->notify_data.data.string), True) - sizeof(uint16))/sizeof(uint16));
 }
 
 /*******************************************************************
@@ -1871,8 +1878,7 @@ static BOOL construct_printer_info_0(PRINTER_INFO_0 *printer, int snum, fstring
         */
        global_counter=session_counter->counter;
        
-       /* the description and the name are of the form \\server\share */
-       slprintf(chaine,sizeof(chaine)-1,"\\\\%s\\%s",servername, ntprinter->info_2->printername);
+       pstrcpy(chaine,ntprinter->info_2->printername);
 
        init_unistr(&printer->printername, chaine);
        
@@ -2013,7 +2019,7 @@ static DEVICEMODE *construct_dev_mode(int snum, char *servername)
 
        DEBUGADD(8,("loading DEVICEMODE\n"));
 
-       snprintf(adevice, sizeof(adevice), "\\\\%s\\%s", global_myname, printer->info_2->printername);
+       safe_strcpy(adevice, printer->info_2->printername, sizeof(adevice));
        init_unistr(&devmode->devicename, adevice);
 
        snprintf(aform, sizeof(aform), ntdevmode->formname);
@@ -3433,50 +3439,25 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level,
 
 /********************************************************************
  Do Samba sanity checks on a printer info struct.
+ this has changed purpose: it now "canonicalises" printer
+ info from a client rather than just checking it is correct
  ********************************************************************/
 
 static BOOL check_printer_ok(NT_PRINTER_INFO_LEVEL_2 *info, int snum)
 {
-       /*
-        * Ensure that this printer is shared under the correct name
-        * as this is what Samba insists upon.
-        */
-
-       if (!(info->attributes & (PRINTER_ATTRIBUTE_SHARED|PRINTER_ATTRIBUTE_NETWORK))) {
-               DEBUG(10,("check_printer_ok: SHARED/NETWORK check failed (%x).\n",
-                                                       (unsigned int)info->attributes ));
-               return False;
-       }
-
-       if (!(info->attributes & PRINTER_ATTRIBUTE_RAW_ONLY)) {
-               /* NT forgets to set the raw attribute but sends the correct type. */
-               if (strequal(info->datatype, "RAW"))
-                       info->attributes |= PRINTER_ATTRIBUTE_RAW_ONLY;
-               else {
-                       DEBUG(10,("check_printer_ok: RAW check failed (%x).\n", (unsigned int)info->attributes ));
-                       return False;
-               }
-       }
-
-       /*
-        * Sometimes the NT client doesn't set the sharename, but
-        * includes the sharename in the printername. This could
-        * cause SETPRINTER to fail which causes problems with the
-        * client getting confused between local/remote printers...
-        */
-        
-       if (*info->sharename == '\0') {
-               char *p = strrchr(info->printername, '\\');
-               if (p)
-                       fstrcpy(info->sharename, p+1);
-       }
-
-       if (!strequal(info->sharename, lp_servicename(snum))) {
-               DEBUG(10,("check_printer_ok: NAME check failed (%s) (%s).\n",
-                                       info->sharename, lp_servicename(snum)));
-               return False;
-       }
+       DEBUG(5,("check_printer_ok: servername=%s printername=%s sharename=%s portname=%s drivername=%s comment=%s location=%s\n",
+                info->servername, info->printername, info->sharename, info->portname, info->drivername, info->comment, info->location));
 
+       /* we force some elements to "correct" values */
+       slprintf(info->servername, sizeof(info->servername), "\\\\%s", global_myname);
+       slprintf(info->printername, sizeof(info->printername), "\\\\%s\\%s", 
+                global_myname, lp_servicename(snum));
+       fstrcpy(info->sharename, lp_servicename(snum));
+       info->attributes = PRINTER_ATTRIBUTE_SHARED   \
+               | PRINTER_ATTRIBUTE_LOCAL  \
+               | PRINTER_ATTRIBUTE_RAW_ONLY \
+               | PRINTER_ATTRIBUTE_QUEUED ;  
+       
        return True;
 }