s3-spoolss: more AddPrinter{Ex} checks.
authorGünther Deschner <gd@samba.org>
Thu, 18 Feb 2010 00:58:56 +0000 (01:58 +0100)
committerGünther Deschner <gd@samba.org>
Thu, 18 Feb 2010 01:19:42 +0000 (02:19 +0100)
Windows will allow to add a non-shared printer that is returned by EnumPrinters.
Samba has no notion of non-shared local printers yet, so just make sure to
behave like we do elsewhere: a printer autoloaded by samba or added to samba is
shared.

Guenther

source3/rpc_server/srv_spoolss_nt.c

index 66eb59bd40f582cb57c346dfb0bcb09cec234838..49ca8c2c2be42e06217e15797bccef5141f2617d 100644 (file)
@@ -7136,6 +7136,15 @@ static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
                return WERR_NOMEM;
        }
 
+       /* samba does not have a concept of local, non-shared printers yet, so
+        * make sure we always setup sharename - gd */
+       if ((printer->info_2->sharename[0] == '\0') && (printer->info_2->printername != '\0')) {
+               DEBUG(5, ("spoolss_addprinterex_level_2: "
+                       "no sharename has been set, setting printername %s as sharename\n",
+                       printer->info_2->printername));
+               fstrcpy(printer->info_2->sharename, printer->info_2->printername);
+       }
+
        /* check to see if the printer already exists */
 
        if ((snum = print_queue_snum(printer->info_2->sharename)) != -1) {
@@ -7145,6 +7154,15 @@ static WERROR spoolss_addprinterex_level_2(pipes_struct *p,
                return WERR_PRINTER_ALREADY_EXISTS;
        }
 
+       if (!lp_force_printername(GLOBAL_SECTION_SNUM)) {
+               if ((snum = print_queue_snum(printer->info_2->printername)) != -1) {
+                       DEBUG(5, ("spoolss_addprinterex_level_2: Attempted to add a printer named [%s] when one already existed!\n",
+                               printer->info_2->printername));
+                       free_a_printer(&printer, 2);
+                       return WERR_PRINTER_ALREADY_EXISTS;
+               }
+       }
+
        /* validate printer info struct */
        if (!info_ctr->info.info2->printername ||
            strlen(info_ctr->info.info2->printername) == 0) {