Apply missed changes 14/270714/1
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 8 Feb 2022 04:09:32 +0000 (13:09 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 8 Feb 2022 04:09:39 +0000 (13:09 +0900)
Change-Id: I01fbb8d42982783e79c2e17b28de00d5bb8450e4

Clients/Makefile
mDNSCore/mDNS.c
mDNSPosix/Makefile
mDNSShared/mDNSDebug.c
mDNSShared/uds_daemon.c
mdnsd.service
mdnsd.socket [new file with mode: 0644]
packaging/mdnsresponder.spec
pkgconfig/lib/dns_sd.pc.in
pkgconfig/lib64/dns_sd.pc.in

index 383af31..22eb506 100755 (executable)
 # If /usr/lib/libSystem.dylib exists, then we're on OS X, so we don't need also to link the "dns_sd" shared library
 ifneq "$(wildcard /usr/lib/libSystem.dylib)" ""
 TARGETS = build/dns-sd build/dns-sd64
-LIBS =
+LIBS = -pie
 else
 TARGETS = build/dns-sd
-LIBS = -L../mDNSPosix/build/prod/ -ldns_sd
+LIBS = -L../mDNSPosix/build/prod/ -ldns_sd -pie
 endif
 
 all: $(TARGETS)
@@ -46,10 +46,10 @@ build:
        mkdir build
 
 build/dns-sd: build dns-sd.c ClientCommon.c
-       $(CC) $(filter %.c %.o, $+) $(LIBS) -I../mDNSShared -Wall -o $@
+       $(CC) $(filter %.c %.o, $+) $(LIBS) -I../mDNSShared -Wall -o $@ -fPIE
 
 build/dns-sd64: build dns-sd.c ClientCommon.c
-       $(CC) $(filter %.c %.o, $+) $(LIBS) -I../mDNSShared -Wall -o $@ -m64
+       $(CC) $(filter %.c %.o, $+) $(LIBS) -I../mDNSShared -Wall -o $@ -m64 -fPIE
 
 # Note, we can make a 'fat' version of dns-sd using 'lipo', as shown below, but we
 # don't, because we don't want or need a 'fat' version of dns-sd, because it will
index 0788ab6..e92639a 100755 (executable)
@@ -4593,14 +4593,14 @@ mDNSexport void ReleaseCacheRecord(mDNS *const m, CacheRecord *r)
     // (which is handled below) and in that case it should be freed here.
     if (r->resrec.name && cg && r->resrec.name != cg->name)
     {
-        debugf("ReleaseCacheRecord: freeing %##s (%s)", r->resrec.name->c, DNSTypeName(r->resrec.rrtype));
+        LogMsg("ReleaseCacheRecord: freeing %##s (%s)", r->resrec.name->c, DNSTypeName(r->resrec.rrtype));
         mDNSPlatformMemFree((void *)r->resrec.name);
     }
     r->resrec.name = mDNSNULL;
 
     if (r->resrec.AnonInfo)
     {
-        debugf("ReleaseCacheRecord: freeing AnonInfo for %##s (%s)", r->resrec.name->c, DNSTypeName(r->resrec.rrtype));
+        LogMsg("ReleaseCacheRecord: freeing AnonInfo for %##s (%s)", r->resrec.name->c, DNSTypeName(r->resrec.rrtype));
         FreeAnonInfo((void *)r->resrec.AnonInfo);
     }
     r->resrec.AnonInfo = mDNSNULL;
@@ -4657,6 +4657,7 @@ mDNSlocal void CheckCacheExpiration(mDNS *const m, const mDNSu32 slot, CacheGrou
                 CacheRecordRmv(m, rr);
                 m->rrcache_active--;
             }
+            LogMsg("ReleaseCacheRecord rr [%p]", rr);
             ReleaseCacheRecord(m, rr);
         }
         else                            // else, not expired; see if we need to query
@@ -5341,7 +5342,7 @@ mDNSexport mDNSs32 mDNS_Execute(mDNS *const m)
                     m->rrcache_nextcheck[slot] = m->timenow + FutureTime;
                     while (*cp)
                     {
-                        debugf("m->NextCacheCheck %4d Slot %3d %##s", numchecked, slot, *cp ? (*cp)->name : (domainname*)"\x04NULL");
+                        LogMsg("m->NextCacheCheck %4d Slot %3d %##s", numchecked, slot, *cp ? (*cp)->name : (domainname*)"\x04NULL");
                         numchecked++;
                         CheckCacheExpiration(m, slot, *cp);
                         if ((*cp)->members) cp=&(*cp)->next;
@@ -5353,7 +5354,7 @@ mDNSexport mDNSs32 mDNS_Execute(mDNS *const m)
                 if (m->NextCacheCheck - m->rrcache_nextcheck[slot] > 0)
                     m->NextCacheCheck = m->rrcache_nextcheck[slot];
             }
-            debugf("m->NextCacheCheck %4d checked, next in %d", numchecked, m->NextCacheCheck - m->timenow);
+            LogMsg("m->NextCacheCheck %4d checked, next in %d", numchecked, m->NextCacheCheck - m->timenow);
         }
 
         if (m->timenow - m->NextScheduledSPS >= 0)
index ede1196..b5dd368 100755 (executable)
@@ -48,7 +48,7 @@
 
 #############################################################################
 
-LIBVERS = 765.50.9
+LIBVERS = 878.70.2
 
 COREDIR = ../mDNSCore
 SHAREDDIR ?= ../mDNSShared
@@ -161,7 +161,7 @@ ifeq ($(os),tizen)
 CFLAGS_OS = -D_GNU_SOURCE -DHAVE_IPV6 -DNOT_HAVE_SA_LEN -DUSES_NETLINK -DHAVE_LINUX -DTARGET_OS_LINUX -DTIZEN_EXT -DCONFIG_DISABLE_REUSEPORT -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fPIE
 CFLAGS_ASLR = -fPIE
 LINKOPTS_ASLR = -pie
-LINKOPTS = -Wl,-z,relro
+LINKOPTS = -Wl,-z,relro,-ldlog,-lsystemd
 LD = $(CC) -shared
 FLEXFLAGS_OS = -l
 INSTBASE = $(DESTDIR)/usr
index 5e9aadc..6d6f79b 100644 (file)
 
 #include <stdio.h>
 
+#if defined TIZEN_EXT
+#include <dlog/dlog.h>
+#define LOG_TAG "MDNSRESPONDER"
+#endif
+
 #if defined(WIN32) || defined(EFI32) || defined(EFI64) || defined(EFIX64)
 // Need to add Windows/EFI syslog support here
 #define LOG_PID 0x01
@@ -61,6 +66,10 @@ mDNSlocal void LogMsgWithLevelv(mDNSLogLevel_t logLevel, const char *format, va_
     char buffer[512];
     buffer[mDNS_vsnprintf((char *)buffer, sizeof(buffer), format, ptr)] = 0;
     mDNSPlatformWriteLogMsg(ProgramName, buffer, logLevel);
+
+#if defined TIZEN_EXT
+    dlog_print(DLOG_INFO, LOG_TAG, buffer);
+#endif
 }
 
 #define LOG_HELPER_BODY(L) \
index 946ad16..e13cae2 100644 (file)
@@ -78,6 +78,10 @@ int WCFNameResolvesToName(WCFConnection *conn, char* fromName, char* toName, uid
 #define NO_WCF 1
 #endif // APPLE_OSX_mDNSResponder
 
+#if defined TIZEN_EXT
+#include <systemd/sd-daemon.h>
+#endif
+
 // User IDs 0-500 are system-wide processes, not actual users in the usual sense
 // User IDs for real user accounts start at 501 and count up from there
 #define SystemUID(X) ((X) <= 500)
@@ -1849,7 +1853,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request)
     mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
     mDNSInterfaceID InterfaceID;
 
-    // Map kDNSServiceInterfaceIndexP2P to kDNSServiceInterfaceIndexAny with the 
+    // Map kDNSServiceInterfaceIndexP2P to kDNSServiceInterfaceIndexAny with the
     // kDNSServiceFlagsIncludeP2P flag set.
     if (interfaceIndex == kDNSServiceInterfaceIndexP2P)
     {
@@ -1860,7 +1864,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request)
 
     InterfaceID = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex);
 
-    // The registration is scoped to a specific interface index, but the 
+    // The registration is scoped to a specific interface index, but the
     // interface is not currently in our list.
     if (interfaceIndex && !InterfaceID)
     {
@@ -2013,7 +2017,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request)
     request->terminate = regservice_termination_callback;
 
     err = register_service_instance(request, &d);
-    
+
 #if TARGET_OS_EMBEDDED
     ++curr_num_regservices;
     if (curr_num_regservices > max_num_regservices)
@@ -2102,7 +2106,7 @@ mDNSlocal void SetQuestionPolicy(DNSQuestion *q, request_state *req)
     q->euid = req->uid;
     // The policy is either based on pid or UUID. Pass a zero pid
     // to the "core" if the UUID is valid. If we always pass the pid,
-    // then the "core" needs to determine whether the uuid is valid 
+    // then the "core" needs to determine whether the uuid is valid
     // by examining all the 16 bytes at the time of the policy
     // check and also when setting the delegate socket option. Also, it
     // requires that we zero out the uuid wherever the question is
@@ -2516,7 +2520,7 @@ mDNSlocal mStatus handle_browse_request(request_state *request)
     mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
     mDNSInterfaceID InterfaceID = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex);
 
-    // The browse is scoped to a specific interface index, but the 
+    // The browse is scoped to a specific interface index, but the
     // interface is not currently in our list.
     if (interfaceIndex && !InterfaceID)
     {
@@ -2639,7 +2643,7 @@ mDNSlocal void resolve_result_callback(mDNS *const m, DNSQuestion *question, con
         (answer->RecordType == kDNSRecordTypePacketNegative) ? kDNSServiceErr_NoSuchRecord : kDNSServiceErr_NoError;
     (void)m; // Unused
 
-    LogOperation("%3d: DNSServiceResolve(%##s) %s interface %d: %s", 
+    LogOperation("%3d: DNSServiceResolve(%##s) %s interface %d: %s",
         req->sd, question->qname.c, AddRecord ? "ADD" : "RMV",
         mDNSPlatformInterfaceIndexfromInterfaceID(m, answer->InterfaceID, mDNSfalse), RRDisplayString(m, answer));
 
@@ -2722,7 +2726,7 @@ mDNSlocal mStatus handle_resolve_request(request_state *request)
 
     InterfaceID = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex);
 
-    // The operation is scoped to a specific interface index, but the 
+    // The operation is scoped to a specific interface index, but the
     // interface is not currently in our list.
     if (interfaceIndex && !InterfaceID)
     {
@@ -2757,7 +2761,7 @@ mDNSlocal mStatus handle_resolve_request(request_state *request)
     {
         flags |= (kDNSServiceFlagsAutoTrigger | kDNSServiceFlagsIncludeAWDL);
         LogInfo("handle_resolve_request: request promoted to use kDNSServiceFlagsAutoTrigger");
-    } 
+    }
 #endif // APPLE_OSX_mDNSResponder && ENABLE_BLE_TRIGGERED_BONJOUR
 
     request->flags = flags;
@@ -3613,7 +3617,7 @@ mDNSlocal mStatus handle_queryrecord_request(request_state *request)
     mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend);
     mDNSInterfaceID InterfaceID = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex);
 
-    // The request is scoped to a specific interface index, but the 
+    // The request is scoped to a specific interface index, but the
     // interface is not currently in our list.
     if (interfaceIndex && !InterfaceID)
     {
@@ -3621,7 +3625,7 @@ mDNSlocal mStatus handle_queryrecord_request(request_state *request)
             LogMsg("handle_queryrecord_request: interfaceIndex %d is currently inactive requested by client[%d][%s]",
                     interfaceIndex, request->process_id, request->pid_name);
         // If it's one of the specially defined inteface index values, just return an error.
-        // Also, caller should return an error immediately if lo0 (index 1) is not configured 
+        // Also, caller should return an error immediately if lo0 (index 1) is not configured
         // into the current active interfaces.  See background in Radar 21967160.
         if (PreDefinedInterfaceIndex(interfaceIndex) || interfaceIndex == 1)
         {
@@ -3687,7 +3691,7 @@ mDNSlocal mStatus handle_queryrecord_request(request_state *request)
     // we only deal with FQDNs. Hence, we cannot look at qname to figure out whether we should
     // append search domains or not.  So, we record that information in AppendSearchDomains.
     //
-    // We append search domains only for queries that are a single label. If overriden using command line 
+    // We append search domains only for queries that are a single label. If overriden using command line
     // argument "AlwaysAppendSearchDomains", then we do it for any query which is not fully qualified.
     // For DNSSEC questions, append search domains only if kDNSServiceFlagsValidateOptional is set.
 
@@ -3916,7 +3920,7 @@ mDNSlocal mStatus handle_reconfirm_request(request_state *request)
             "%3d: DNSServiceReconfirmRecord(%s) interface %d initiated PID[%d](%s)" :
             "%3d: DNSServiceReconfirmRecord(%s) interface %d failed PID[%d](%s) status %d",
             request->sd, RRDisplayString(&mDNSStorage, &rr->resrec),
-            mDNSPlatformInterfaceIndexfromInterfaceID(&mDNSStorage, rr->resrec.InterfaceID, mDNSfalse), 
+            mDNSPlatformInterfaceIndexfromInterfaceID(&mDNSStorage, rr->resrec.InterfaceID, mDNSfalse),
             request->process_id, request->pid_name, status);
         freeL("AuthRecord/handle_reconfirm_request", rr);
     }
@@ -4378,7 +4382,7 @@ mDNSlocal mStatus handle_addrinfo_request(request_state *request)
 
     InterfaceID = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex);
 
-    // The request is scoped to a specific interface index, but the 
+    // The request is scoped to a specific interface index, but the
     // interface is not currently in our list.
     if (interfaceIndex && !InterfaceID)
     {
@@ -4460,7 +4464,7 @@ mDNSlocal mStatus handle_addrinfo_request(request_state *request)
 
     hostnameLen = strlen(hostname);
 
-    LogOperation("%3d: DNSServiceGetAddrInfo(%X, %d, %d, %##s) START PID[%d](%s)", 
+    LogOperation("%3d: DNSServiceGetAddrInfo(%X, %d, %d, %##s) START PID[%d](%s)",
         request->sd, flags, interfaceIndex, request->u.addrinfo.protocol, d.c, request->process_id, request->pid_name);
 
     if (request->u.addrinfo.protocol & kDNSServiceProtocol_IPv6)
@@ -5098,7 +5102,21 @@ mDNSexport int udsserver_init(dnssd_sock_t skts[], mDNSu32 count)
     }
     else
     {
+#if defined TIZEN_EXT
+               int fds = sd_listen_fds(1);
+               if (fds <= 0) {
+                       my_perror("ERROR: no listen sockets");
+                       goto error;
+               }
+               for (i = 0; i < fds; i++) {
+                       if (sd_is_socket_unix(i + SD_LISTEN_FDS_START, SOCK_STREAM, 1, boundPath, 0) >= 0) {
+                               listenfd = i + SD_LISTEN_FDS_START;
+                               break;
+                       }
+               }
+#else
         listenfd = socket(AF_DNSSD, SOCK_STREAM, 0);
+#endif
         if (!dnssd_SocketValid(listenfd))
         {
             my_perror("ERROR: socket(AF_DNSSD, SOCK_STREAM, 0); failed");
@@ -5121,6 +5139,7 @@ mDNSexport int udsserver_init(dnssd_sock_t skts[], mDNSu32 count)
         }
         #else
         {
+#ifndef TIZEN_EXT
             mode_t mask = umask(0);
             unlink(boundPath);  // OK if this fails
             laddr.sun_family = AF_LOCAL;
@@ -5142,6 +5161,7 @@ mDNSexport int udsserver_init(dnssd_sock_t skts[], mDNSu32 count)
                 my_perror("ERROR: bind(listenfd, (struct sockaddr *) &laddr, sizeof(laddr)); failed");
                 goto error;
             }
+#endif
         }
         #endif
 
@@ -5210,7 +5230,7 @@ mDNSexport int udsserver_exit(void)
     if (dnssd_SocketValid(listenfd))
     {
         dnssd_close(listenfd);
-#if !defined(USE_TCP_LOOPBACK)
+#if !defined(USE_TCP_LOOPBACK) && !defined(TIZEN_EXT)
         // Currently, we're unable to remove /var/run/mdnsd because we've changed to userid "nobody"
         // to give up unnecessary privilege, but we need to be root to remove this Unix Domain Socket.
         // It would be nice if we could find a solution to this problem
@@ -5846,7 +5866,7 @@ mDNSexport void udsserver_info()
 foundparent:;
         }
     }
-    
+
     LogMsgNoIdent("-------- NAT Traversals --------");
     LogMsgNoIdent("ExtAddress %.4a Retry %d Interval %d",
                   &m->ExtAddress,
index 0074c96..3bd50b2 100644 (file)
@@ -2,8 +2,14 @@
 Description=DNS Service Discovery mDNSResponder
 
 [Service]
+User=network_fw
+Group=network_fw
 Type=simple
+SmackProcessLabel=System
 ExecStart=/usr/sbin/mdnsd -debug
+#Restart=on-failure
+Capabilities=cap_net_raw,cap_net_admin=i
+SecureBits=keep-caps
 
 [Install]
 WantedBy=multi-user.target
diff --git a/mdnsd.socket b/mdnsd.socket
new file mode 100644 (file)
index 0000000..31be9ff
--- /dev/null
@@ -0,0 +1,6 @@
+[Socket]
+ListenStream=/run/mdnsd
+SocketMode=0777
+
+[Install]
+WantedBy=sockets.target
index 10635c6..83ae1e1 100755 (executable)
@@ -1,14 +1,17 @@
 Name:       mdnsresponder
 Summary:    DNS Service Discovery service with dns-sd library
 Version:    878.70.2
-Release:    1
+Release:    2
 Group:      System/Network
 License:    Apache-2.0 or BSD-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1001:    mdnsresponder.manifest
 Source1002:    libdns_sd.manifest
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(libsystemd)
 BuildRequires: bison
 BuildRequires: flex
+
 Requires(post):        /sbin/ldconfig
 Requires(postun):      /sbin/ldconfig
 
@@ -47,6 +50,12 @@ CONFIG_TIZEN_64BIT=y; export CONFIG_TIZEN_64BIT
 %endif
 
 cd mDNSPosix
+#You should check below before change make flags or Makefile
+mkdir -p objects/prod
+mkdir -p build/prod
+make os=tizen %{?_smp_mflags}
+
+cd ../Clients
 make os=tizen %{?_smp_mflags}
 
 %install
@@ -58,12 +67,7 @@ mkdir -p %{buildroot}%{_bindir}/
 mkdir -p %{buildroot}%{_libdir}/
 mkdir -p %{buildroot}%{_libdir}/pkgconfig/
 
-#mkdir -p %{buildroot}%{_libdir}/systemd/system/
-#cp mdnsd.service %{buildroot}%{_libdir}/systemd/system/mdnsd.service
-#mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/
-#ln -s mdnsd.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/mdnsd.service
-
-cp mdnsresponder-server.sh.in %{buildroot}%{_bindir}/mdnsresponder-server.sh
+cp Clients/build/dns-sd %{buildroot}%{_bindir}/dns-sd
 
 mkdir -p %{buildroot}%{_includedir}/
 %if "%{?_lib}" == "lib64"
@@ -71,24 +75,18 @@ CONFIG_TIZEN_64BIT=y; export CONFIG_TIZEN_64BIT
 %endif
 cd mDNSPosix
 make install os=tizen DESTDIR=%{buildroot} LIBDIR=/%{?_lib}
-ln -sf %{_libdir}/libdns_sd.so.%{version} %{buildroot}%{_libdir}/libdns_sd.so.765
+strip --strip-unneeded %{buildroot}%{_libdir}/libdns_sd.so.%{version}
+ln -sf %{_libdir}/libdns_sd.so.%{version} %{buildroot}%{_libdir}/libdns_sd.so.878
 ln -sf %{_libdir}/libdns_sd.so.%{version} %{buildroot}%{_libdir}/libdns_sd.so
 
-%post
-chmod 755 %{_bindir}/mdnsresponder-server.sh
-#systemctl daemon-reload
-
-#if [ $1 = 1 ]; then
-#    systemctl enable mdnsd.service
-#fi
+cd ..
+mkdir -p %{buildroot}%{_unitdir}
+cp mdnsd.service %{buildroot}%{_unitdir}
+mkdir -p %{buildroot}%{_unitdir}/sockets.target.wants
+ln -s ../mdnsd.socket %{buildroot}%{_unitdir}/sockets.target.wants/
+cp mdnsd.socket %{buildroot}%{_unitdir}
 
-#systemctl restart mdnsd.service
-
-#%preun
-#if [ $1 = 0 ]; then
-#    # unistall
-#    systemctl stop mdnsd.service
-#fi
+%post
 
 %post -n libdns_sd -p /sbin/ldconfig
 
@@ -98,9 +96,10 @@ chmod 755 %{_bindir}/mdnsresponder-server.sh
 %manifest mdnsresponder.manifest
 %license LICENSE
 %attr(755,root,root) %{_sbindir}/mdnsd
-%attr(-,root,root) %{_bindir}/mdnsresponder-server.sh
-#%attr(-,root,root) %{_libdir}/systemd/system/mdnsd.service
-#%attr(-,root,root) %{_libdir}/systemd/system/multi-user.target.wants/mdnsd.service
+%attr(-,root,root) %{_bindir}/dns-sd
+%{_unitdir}/mdnsd.service
+%{_unitdir}/mdnsd.socket
+%{_unitdir}/sockets.target.wants/mdnsd.socket
 
 %files devel
 %{_includedir}/*.h
index 7542d7f..cca7b7d 100755 (executable)
@@ -5,7 +5,7 @@ includedir=/usr/include/
 
 Name: dns_sd
 Description: @PACKAGE_DESCRIPTION@
-Version: 765.50.9
+Version: 878.70.2
 Requires: glib-2.0
 Libs: -L${libdir} -ldns_sd
 Cflags: -I${includedir}
index 1c96623..cf723ea 100755 (executable)
@@ -8,7 +8,7 @@ includedir=/usr/include/
 
 Name: dns_sd
 Description: @PACKAGE_DESCRIPTION@
-Version: 765.50.9
+Version: 878.70.2
 Requires: glib-2.0
 Libs: -L${libdir} -ldns_sd
 Cflags: -I${includedir}