]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/dirsvc.c
Merge changes from CUPS 1.4svn-r7386.
[thirdparty/cups.git] / scheduler / dirsvc.c
index 13ce3bfd8a24f8dd6bcdc43f291c4d192445f6a7..f9ee0232061e7c9a395a938c328e3d3888269e04 100644 (file)
@@ -33,6 +33,7 @@
  *   cupsdUpdateLDAPBrowse()    - Scan for new printers via LDAP...
  *   cupsdUpdateSLPBrowse()     - Get browsing information via SLP.
  *   dequote()                  - Remote quotes from a string.
+ *   get_hostconfig()           - Get an /etc/hostconfig service setting.
  *   is_local_queue()           - Determine whether the URI points at a local
  *                                queue.
  *   process_browse_data()      - Process new browse data.
@@ -87,6 +88,9 @@
  */
 
 static char    *dequote(char *d, const char *s, int dlen);
+#ifdef __APPLE__
+static int     get_hostconfig(const char *name);
+#endif /* __APPLE__ */
 static int     is_local_queue(const char *uri, char *host, int hostlen,
                               char *resource, int resourcelen);
 static void    process_browse_data(const char *uri, const char *host,
@@ -1624,6 +1628,58 @@ dequote(char       *d,                   /* I - Destination string */
 }
 
 
+#ifdef __APPLE__
+/*
+ * 'get_hostconfig()' - Get an /etc/hostconfig service setting.
+ */
+
+static int                             /* O - 1 for YES or AUTOMATIC, 0 for NO */
+get_hostconfig(const char *name)       /* I - Name of service */
+{
+  cups_file_t  *fp;                    /* Hostconfig file */
+  char         line[1024],             /* Line from file */
+               *ptr;                   /* Pointer to value */
+  int          state = 1;              /* State of service */
+
+
+ /*
+  * Try opening the /etc/hostconfig file; if we can't open it, assume that
+  * the service is enabled/auto.
+  */
+
+  if ((fp = cupsFileOpen("/etc/hostconfig", "r")) != NULL)
+  {
+   /*
+    * Read lines from the file until we find the service...
+    */
+
+    while (cupsFileGets(fp, line, sizeof(line)))
+    {
+      if (line[0] == '#' || (ptr = strchr(line, '=')) == NULL)
+        continue;
+
+      *ptr++ = '\0';
+
+      if (!strcasecmp(line, name))
+      {
+       /*
+        * Found the service, see if it is set to "-NO-"...
+       */
+
+       if (!strncasecmp(ptr, "-NO-", 4))
+         state = 0;
+        break;
+      }
+    }
+
+    cupsFileClose(fp);
+  }
+
+  return (state);
+}
+#endif /* __APPLE__ */
+
+
 /*
  * 'is_local_queue()' - Determine whether the URI points at a local queue.
  */
@@ -2448,10 +2504,12 @@ dnssdRegisterCallback(
     const char         *domain,        /* I - Domain. ".local" for now */
     void               *context)       /* I - User-defined context */
 {
-  (void)context;
+  cupsd_printer_t *p = (cupsd_printer_t *)context;
+                                       /* Current printer */
+
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG2, 
-                 "dnssdRegisterCallback(%s, %s)", name, regtype);
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdRegisterCallback(%s, %s) for %s",
+                  name, regtype, p->name);
 
   if (errorCode)
   {
@@ -2459,6 +2517,14 @@ dnssdRegisterCallback(
                    "DNSServiceRegister failed with error %d", (int)errorCode);
     return;
   }
+  else if (strcasecmp(name, p->reg_name))
+  {
+    cupsdLogMessage(CUPSD_LOG_INFO, "Using service name \"%s\" for \"%s\"",
+                    name, p->name);
+
+    cupsdSetString(&p->reg_name, name);
+    LastEvent |= CUPSD_EVENT_PRINTER_MODIFIED;
+  }
 }
 
 
@@ -2607,8 +2673,8 @@ dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
 
 
     cupsdLogMessage(CUPSD_LOG_DEBUG, 
-               "dnssdRegisterPrinter(%s) type, domain is \"%s\", \"%s\"",
-               p->name, regtype, domain ? domain : "(null)");
+                   "dnssdRegisterPrinter(%s) type, domain is \"%s\", \"%s\"",
+                   p->name, regtype, domain ? domain : "(null)");
 
     se = DNSServiceRegister(&p->dnssd_ipp_ref, 0, 0, name, regtype, 
                            domain, NULL, htons(port), txt_len, txt_record,
@@ -3861,6 +3927,16 @@ update_lpd(int onoff)                    /* - 1 = turn on, 0 = turn off */
   if (!LPDConfigFile)
     return;
 
+#ifdef __APPLE__
+ /*
+  * Allow /etc/hostconfig CUPS_LPD service setting to override cupsd.conf
+  * setting for backwards-compatibility.
+  */
+
+  if (onoff && !get_hostconfig("CUPS_LPD"))
+    onoff = 0;
+#endif /* __APPLE__ */
+
   if (!strncmp(LPDConfigFile, "xinetd:///", 10))
   {
    /*
@@ -3902,16 +3978,15 @@ update_lpd(int onoff)                   /* - 1 = turn on, 0 = turn off */
         snprintf(line, sizeof(line), "\tdisable = %s",
                 onoff ? "no" : "yes");
       }
-      else if (strstr(line, "disable ="))
-        continue;
-
-      cupsFilePrintf(nfp, "%s\n", line);
+      else if (!strstr(line, "disable ="))
+        cupsFilePrintf(nfp, "%s\n", line);
     }
 
     cupsFileClose(nfp);
     cupsFileClose(ofp);
     rename(newfile, LPDConfigFile + 9);
   }
+#ifdef __APPLE__
   else if (!strncmp(LPDConfigFile, "launchd:///", 11))
   {
    /*
@@ -3933,6 +4008,9 @@ update_lpd(int onoff)                     /* - 1 = turn on, 0 = turn off */
     cupsdStartProcess("/bin/launchctl", argv, envp, -1, -1, -1, -1, -1, 1,
                       NULL, &pid);
   }
+#endif /* __APPLE__ */
+  else
+    cupsdLogMessage(CUPSD_LOG_INFO, "Unknown LPDConfigFile scheme!");
 }
 
 
@@ -4028,27 +4106,8 @@ update_smb(int onoff)                    /* I - 1 = turn on, 0 = turn off */
     cupsFileClose(ofp);
     rename(newfile, SMBConfigFile + 8);
   }
-  else if (!strncmp(SMBConfigFile, "launchd:///", 11))
-  {
-   /*
-    * Enable/disable SMB via the launchctl command...
-    */
-
-    char       *argv[5],               /* Arguments for command */
-               *envp[MAX_ENV];         /* Environment for command */
-    int                pid;                    /* Process ID */
-
-
-    cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
-    argv[0] = (char *)"launchctl";
-    argv[1] = (char *)(onoff ? "load" : "unload");
-    argv[2] = (char *)"-w";
-    argv[3] = SMBConfigFile + 10;
-    argv[4] = NULL;
-
-    cupsdStartProcess("/bin/launchctl", argv, envp, -1, -1, -1, -1, -1, 1,
-                      NULL, &pid);
-  }
+  else
+    cupsdLogMessage(CUPSD_LOG_INFO, "Unknown SMBConfigFile scheme!");
 }