Changed enumports to show printernames as ports. In line with 'the grand plan' :-)
authorJeremy Allison <jra@samba.org>
Thu, 22 Jun 2000 23:59:22 +0000 (23:59 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 22 Jun 2000 23:59:22 +0000 (23:59 +0000)
Gerald & I discussed with HP. More changes to follow.
Jeremy.

source/include/proto.h
source/param/loadparm.c
source/rpc_server/srv_spoolss_nt.c

index be901b3cf302719e27afccf1018f24571ad74189..deb0ea2704e807b9de6e57ef765663f2a04c5c02 100644 (file)
@@ -1398,7 +1398,6 @@ char *lp_lppausecommand(int );
 char *lp_lpresumecommand(int );
 char *lp_queuepausecommand(int );
 char *lp_queueresumecommand(int );
-char *lp_printername(int );
 char *lp_driverfile(int );
 char *lp_printerdriver(int );
 char *lp_hostsallow(int );
@@ -1507,6 +1506,7 @@ int lp_security_mask(int snum);
 int lp_force_security_mode(int snum);
 int lp_dir_security_mask(int snum);
 int lp_force_dir_security_mode(int snum);
+char *lp_printername(int snum);
 
 /*The following definitions come from  param/params.c  */
 
index 0bcb63984b32c7d465f9c2be3f03b6155f8a5887..57db8f0e876051cc58eeca838b4d3c722b7c4ca8 100644 (file)
@@ -1476,7 +1476,7 @@ FN_LOCAL_STRING(lp_lppausecommand, szLppausecommand)
 FN_LOCAL_STRING(lp_lpresumecommand, szLpresumecommand)
 FN_LOCAL_STRING(lp_queuepausecommand, szQueuepausecommand)
 FN_LOCAL_STRING(lp_queueresumecommand, szQueueresumecommand)
-FN_LOCAL_STRING(lp_printername, szPrintername)
+static FN_LOCAL_STRING(_lp_printername, szPrintername)
 FN_LOCAL_STRING(lp_driverfile, szDriverFile)
 FN_LOCAL_STRING(lp_printerdriver, szPrinterDriver)
 FN_LOCAL_STRING(lp_hostsallow, szHostsallow)
@@ -1958,14 +1958,17 @@ static BOOL service_ok(int iService)
 
        /* The [printers] entry MUST be printable. I'm all for flexibility, but */
        /* I can't see why you'd want a non-printable printer service...        */
-       if (strwicmp(iSERVICE(iService).szService, PRINTERS_NAME) == 0)
-               if (!iSERVICE(iService).bPrint_ok)
-               {
+       if (strwicmp(iSERVICE(iService).szService, PRINTERS_NAME) == 0) {
+               if (!iSERVICE(iService).bPrint_ok) {
                        DEBUG(0,
                              ("WARNING: [%s] service MUST be printable!\n",
                               iSERVICE(iService).szService));
                        iSERVICE(iService).bPrint_ok = True;
                }
+               /* [printers] service must also be non-browsable. */
+               if (iSERVICE(iService).bBrowseable)
+                       iSERVICE(iService).bBrowseable = False;
+       }
 
        if (iSERVICE(iService).szPath[0] == '\0' &&
            strwicmp(iSERVICE(iService).szService, HOMES_NAME) != 0)
@@ -3472,3 +3475,11 @@ int lp_force_dir_security_mode(int snum)
        return val;
 }
 
+char *lp_printername(int snum)
+{
+       char *ret = _lp_printername(snum);
+       if (ret == NULL || (ret != NULL && *ret == '\0'))
+               ret = lp_servicename(snum);
+
+       return ret;
+}
index dc4932fdfcfb9c72d882764bbb72f9f44fccea63..b8b25a1ecbadc57ebbfb7bb7aacca6284bc013f4 100644 (file)
@@ -3653,16 +3653,16 @@ uint32 _new_spoolss_enumforms( const POLICY_HND *handle, uint32 level,
 ****************************************************************************/
 static void fill_port_1(PORT_INFO_1 *port, char *name)
 {
-       init_unistr(&(port->port_name), name);
+       init_unistr(&port->port_name, name);
 }
 
 /****************************************************************************
 ****************************************************************************/
 static void fill_port_2(PORT_INFO_2 *port, char *name)
 {
-       init_unistr(&(port->port_name), name);
-       init_unistr(&(port->monitor_name), "Moniteur Local");
-       init_unistr(&(port->description), "Local Port");
+       init_unistr(&port->port_name, name);
+       init_unistr(&port->monitor_name, "Local Monitor");
+       init_unistr(&port->description, "Local Port");
 #define PORT_TYPE_WRITE 1
        port->port_type=PORT_TYPE_WRITE;
        port->reserved=0x0;     
@@ -3688,16 +3688,36 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need
        
        for (snum=0; snum<n_services; snum++) {
                if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
+                       /*
+                        * Ensure this port name is unique.
+                        */
+                       int j;
+
+                       DEBUG(10,("enumports_level_1: port name %s\n", PRINTERNAME(snum)));
+
+                       for(j = 0; j < i; j++) {
+                               fstring port_name;
+                               unistr_to_dos(port_name, (const char *)&ports[j].port_name.buffer[0], sizeof(port_name));
+
+                               if (strequal(port_name, PRINTERNAME(snum)))
+                                       break;
+                       }
+
+                       if (j < i)
+                               continue;
+
                        DEBUGADD(6,("Filling port number [%d]\n", i));
-                       fill_port_1(&(ports[i]), lp_servicename(snum));
+                       fill_port_1(&ports[i], PRINTERNAME(snum));
                        i++;
                }
        }
 
+       *returned = i;
+
        /* check the required size. */
        for (i=0; i<*returned; i++) {
                DEBUGADD(6,("adding port [%d]'s size\n", i));
-               *needed += spoolss_size_port_info_1(&(ports[i]));
+               *needed += spoolss_size_port_info_1(&ports[i]);
        }
                
        if (!alloc_buffer_size(buffer, *needed)) {
@@ -3708,7 +3728,7 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need
        /* fill the buffer with the ports structures */
        for (i=0; i<*returned; i++) {
                DEBUGADD(6,("adding port [%d] to buffer\n", i));
-               new_smb_io_port_1("", buffer, &(ports[i]), 0);
+               new_smb_io_port_1("", buffer, &ports[i], 0);
        }
 
        safe_free(ports);
@@ -3721,10 +3741,10 @@ static uint32 enumports_level_1(NEW_BUFFER *buffer, uint32 offered, uint32 *need
                return NT_STATUS_NO_PROBLEMO;
 }
 
-
 /****************************************************************************
  enumports level 2.
 ****************************************************************************/
+
 static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
 {
        int n_services=lp_numservices();
@@ -3742,16 +3762,36 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need
        
        for (snum=0; snum<n_services; snum++) {
                if ( lp_browseable(snum) && lp_snum_ok(snum) && lp_print_ok(snum) ) {
+                       /*
+                        * Ensure this port name is unique.
+                        */
+                       int j;
+
+                       DEBUG(10,("enumports_level_2: port name %s\n", PRINTERNAME(snum)));
+
+                       for(j = 0; j < i; j++) {
+                               fstring port_name;
+                               unistr_to_dos(port_name, (const char *)&ports[j].port_name.buffer[0], sizeof(port_name));
+
+                               if (strequal(port_name, PRINTERNAME(snum)))
+                                       break;
+                       }
+
+                       if (j < i)
+                               continue;
+
                        DEBUGADD(6,("Filling port number [%d]\n", i));
-                       fill_port_2(&(ports[i]), lp_servicename(snum));
+                       fill_port_2(&ports[i], PRINTERNAME(snum));
                        i++;
                }
        }
 
+       *returned = i;
+
        /* check the required size. */
        for (i=0; i<*returned; i++) {
                DEBUGADD(6,("adding port [%d]'s size\n", i));
-               *needed += spoolss_size_port_info_2(&(ports[i]));
+               *needed += spoolss_size_port_info_2(&ports[i]);
        }
                
        if (!alloc_buffer_size(buffer, *needed)) {
@@ -3762,7 +3802,7 @@ static uint32 enumports_level_2(NEW_BUFFER *buffer, uint32 offered, uint32 *need
        /* fill the buffer with the ports structures */
        for (i=0; i<*returned; i++) {
                DEBUGADD(6,("adding port [%d] to buffer\n", i));
-               new_smb_io_port_2("", buffer, &(ports[i]), 0);
+               new_smb_io_port_2("", buffer, &ports[i], 0);
        }
 
        safe_free(ports);