1From 5c3e5a3996ea2215a4ad30dea4c953e4a10a2e4d Mon Sep 17 00:00:00 2001 2From: cai-zihua <caizihua1@huawei.com> 3Date: Thu, 11 Jul 2024 15:25:04 +0800 4Subject: [PATCH] 2 5 6Change-Id: I21ab06577dff0ce7e2fc2af8bde7ac83080c9ee8 7--- 8 cups-2.4.0/cups/http-addr.c | 38 ++++++++++++++++++------------------- 9 cups-2.4.0/scheduler/conf.c | 19 +++++++++++++++++++ 10 2 files changed, 38 insertions(+), 19 deletions(-) 11 12diff --git a/cups-2.4.0/cups/http-addr.c b/cups-2.4.0/cups/http-addr.c 13index 114a6449..c07f092f 100644 14--- a/cups-2.4.0/cups/http-addr.c 15+++ b/cups-2.4.0/cups/http-addr.c 16@@ -205,28 +205,28 @@ httpAddrListen(http_addr_t *addr, /* I - Address to bind to */ 17 /* 18 * Remove any existing domain socket file... 19 */ 20+ if ((status = unlink(addr->un.sun_path)) < 0) 21+ { 22+ DEBUG_printf(("1httpAddrListen: Unable to unlink \"%s\": %s", addr->un.sun_path, strerror(errno))); 23 24- unlink(addr->un.sun_path); 25- 26- /* 27- * Save the current umask and set it to 0 so that all users can access 28- * the domain socket... 29- */ 30- 31- mask = umask(0); 32- 33- /* 34- * Bind the domain socket... 35- */ 36- 37- status = bind(fd, (struct sockaddr *)addr, (socklen_t)httpAddrLength(addr)); 38+ if (errno == ENOENT) 39+ status = 0; 40+ } 41 42- /* 43- * Restore the umask and fix permissions... 44- */ 45+ if (!status) 46+ { 47+ // Save the current umask and set it to 0 so that all users can access 48+ // the domain socket... 49+ mask = umask(0); 50+ // Bind the domain socket... 51+ if ((status = bind(fd, (struct sockaddr *)addr, (socklen_t)httpAddrLength(addr))) < 0) 52+ { 53+ DEBUG_printf(("1httpAddrListen: Unable to bind domain socket \"%s\": %s", addr->un.sun_path, strerror(errno))); 54+ } 55 56- umask(mask); 57- chmod(addr->un.sun_path, 0140777); 58+ // Restore the umask... 59+ umask(mask); 60+ } 61 } 62 else 63 #endif /* AF_LOCAL */ 64diff --git a/cups-2.4.0/scheduler/conf.c b/cups-2.4.0/scheduler/conf.c 65index e44736b7..a5ba6cba 100644 66--- a/cups-2.4.0/scheduler/conf.c 67+++ b/cups-2.4.0/scheduler/conf.c 68@@ -3073,6 +3073,25 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */ 69 70 cupsd_listener_t *lis; /* New listeners array */ 71 72+ /* 73+ * If we are launched on-demand, do not use domain sockets from the config 74+ * file. Also check that the domain socket path is not too long... 75+ */ 76+ 77+#ifdef HAVE_ONDEMAND 78+ if (*value == '/' && OnDemand) 79+ { 80+ if (strcmp(value, CUPS_DEFAULT_DOMAINSOCKET)) 81+ cupsdLogMessage(CUPSD_LOG_INFO, "Ignoring %s address %s at line %d - only using domain socket from launchd/systemd.", line, value, linenum); 82+ continue; 83+ } 84+#endif // HAVE_ONDEMAND 85+ 86+ if (*value == '/' && strlen(value) > (sizeof(addr->addr.un.sun_path) - 1)) 87+ { 88+ cupsdLogMessage(CUPSD_LOG_INFO, "Ignoring %s address %s at line %d - too long.", line, value, linenum); 89+ continue; 90+ } 91 92 /* 93 * Get the address list... 94-- 952.25.1 96 97