diff options
Diffstat (limited to 'mDNSResponder/mDNSShared')
-rw-r--r-- | mDNSResponder/mDNSShared/dns_sd.h | 71 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnssd_clientstub.c | 29 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnssd_ipc.h | 1 |
3 files changed, 56 insertions, 45 deletions
diff --git a/mDNSResponder/mDNSShared/dns_sd.h b/mDNSResponder/mDNSShared/dns_sd.h index 99373de6..32945b7b 100644 --- a/mDNSResponder/mDNSShared/dns_sd.h +++ b/mDNSResponder/mDNSShared/dns_sd.h @@ -54,19 +54,8 @@ * for the local network. */ - -/* _DNS_SD_H contains the mDNSResponder version number for this header file, formatted as follows: - * Major part of the build number * 10000 + - * minor part of the build number * 100 - * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as - * version 1080400. This allows C code to do simple greater-than and less-than comparisons: - * e.g. an application that requires the DNSServiceGetProperty() call (new in mDNSResponder-126) can check: - * - * #if _DNS_SD_H+0 >= 1260000 - * ... some C code that calls DNSServiceGetProperty() ... - * #endif - * - * The version defined in this header file symbol allows for compile-time +/* _DNS_SD_H contains the API version number for this header file + * The API version defined in this header file symbol allows for compile-time * checking, so that C code building with earlier versions of the header file * can avoid compile errors trying to use functions that aren't even defined * in those earlier versions. Similar checks may also be performed at run-time: @@ -77,7 +66,7 @@ */ #ifndef _DNS_SD_H -#define _DNS_SD_H 5440000 +#define _DNS_SD_H 5610101 #ifdef __cplusplus extern "C" { @@ -291,6 +280,7 @@ enum * ... * DNSServiceRefDeallocate(BrowseRef); // Terminate the browse operation * DNSServiceRefDeallocate(MainRef); // Terminate the shared connection + * Also see Point 4.(Don't Double-Deallocate if the MainRef has been Deallocated) in Notes below: * * Notes: * @@ -328,7 +318,7 @@ enum * DNSServiceRef's created by other calls like DNSServiceBrowse() or DNSServiceResolve() * cannot be shared by copying them and using kDNSServiceFlagsShareConnection. * - * 4. Don't Double-Deallocate + * 4. Don't Double-Deallocate if the MainRef has been Deallocated * Calling DNSServiceRefDeallocate(ref) for a particular operation's DNSServiceRef terminates * just that operation. Calling DNSServiceRefDeallocate(ref) for the main shared DNSServiceRef * (the parent DNSServiceRef, originally created by DNSServiceCreateConnection(&ref)) @@ -380,8 +370,7 @@ enum kDNSServiceFlagsBackgroundTrafficClass = 0x80000, /* - * This flag is meaningful in DNSServiceBrowse, DNSServiceGetAddrInfo, DNSServiceQueryRecord, - * and DNSServiceResolve. When set, it uses the background traffic + * This flag is meaningful for Unicast DNS queries. When set, it uses the background traffic * class for packets that service the request. */ @@ -495,6 +484,25 @@ enum * is only set in the callbacks and kDNSServiceFlagsThresholdOne is only set on * input to a DNSServiceBrowse call. */ + kDNSServiceFlagsDenyCellular = 0x8000000, + /* + * This flag is meaningful only for Unicast DNS queries. When set, the kernel will restrict + * DNS resolutions on the cellular interface for that request. + */ + + kDNSServiceFlagsServiceIndex = 0x10000000, + /* + * This flag is meaningful only for DNSServiceGetAddrInfo() for Unicast DNS queries. + * When set, DNSServiceGetAddrInfo() will interpret the "interfaceIndex" argument of the call + * as the "serviceIndex". + */ + + kDNSServiceFlagsDenyExpensive = 0x20000000 + /* + * This flag is meaningful only for Unicast DNS queries. When set, the kernel will restrict + * DNS resolutions on interfaces defined as expensive for that request. + */ + }; #define kDNSServiceOutputFlags (kDNSServiceFlagsValidate | kDNSServiceFlagsValidateOptional | kDNSServiceFlagsMoreComing | kDNSServiceFlagsAdd | kDNSServiceFlagsDefault) @@ -804,22 +812,18 @@ DNSServiceErrorType DNSSD_API DNSServiceGetProperty * When requesting kDNSServiceProperty_DaemonVersion, the result pointer must point * to a 32-bit unsigned integer, and the size parameter must be set to sizeof(uint32_t). * - * On return, the 32-bit unsigned integer contains the version number, formatted as follows: - * Major part of the build number * 10000 + - * minor part of the build number * 100 - * - * For example, Mac OS X 10.4.9 has mDNSResponder-108.4, which would be represented as - * version 1080400. This allows applications to do simple greater-than and less-than comparisons: - * e.g. an application that requires at least mDNSResponder-108.4 can check: + * On return, the 32-bit unsigned integer contains the API version number * + * For example, Mac OS X 10.4.9 has API version 1080400. + * This allows applications to do simple greater-than and less-than comparisons: + * e.g. an application that requires at least API version 1080400 can check: * if (version >= 1080400) ... * * Example usage: - * * uint32_t version; * uint32_t size = sizeof(version); * DNSServiceErrorType err = DNSServiceGetProperty(kDNSServiceProperty_DaemonVersion, &version, &size); - * if (!err) printf("Bonjour version is %d.%d\n", version / 10000, version / 100 % 100); + * if (!err) printf("DNS_SD API version is %d.%d\n", version / 10000, version / 100 % 100); */ #define kDNSServiceProperty_DaemonVersion "DaemonVersion" @@ -831,10 +835,10 @@ DNSServiceErrorType DNSSD_API DNSServiceGetProperty /* DNSServiceGetPID() Parameters: * * srcport: Source port (in network byte order) of the UDP socket that was created by - * mDNSResponder to send the DNS query on the wire. + * the daemon to send the DNS query on the wire. * * pid: Process ID of the application that started the name resolution which triggered - * mDNSResponder to send the query on the wire. The value can be -1 if the srcport + * the daemon to send the query on the wire. The value can be -1 if the srcport * cannot be mapped. * * return value: Returns kDNSServiceErr_NoError on success, or kDNSServiceErr_ServiceNotRunning @@ -857,7 +861,7 @@ DNSServiceErrorType DNSSD_API DNSServiceGetPID * * Access underlying Unix domain socket for an initialized DNSServiceRef. * The DNS Service Discovery implementation uses this socket to communicate between the client and - * the mDNSResponder daemon. The application MUST NOT directly read from or write to this socket. + * the daemon. The application MUST NOT directly read from or write to this socket. * Access to the socket is provided so that it can be used as a kqueue event source, a CFRunLoop * event source, in a select() loop, etc. When the underlying event management subsystem (kqueue/ * select/CFRunLoop etc.) indicates to the client that data is available for reading on the @@ -867,6 +871,8 @@ DNSServiceErrorType DNSSD_API DNSServiceGetPID * a client can choose to fork a thread and have it loop calling "DNSServiceProcessResult(ref);" * If DNSServiceProcessResult() is called when no data is available for reading on the socket, it * will block until data does become available, and then process the data and return to the caller. + * The application is reponsible for checking the return value of DNSServiceProcessResult() to determine + * if the socket is valid and if it should continue to process data on the socket. * When data arrives on the socket, the client is responsible for calling DNSServiceProcessResult(ref) * in a timely fashion -- if the client allows a large backlog of data to build up the daemon * may terminate the connection. @@ -1749,10 +1755,7 @@ typedef void (DNSSD_API *DNSServiceGetAddrInfoReply) * begins and will last indefinitely until the client terminates the query * by passing this DNSServiceRef to DNSServiceRefDeallocate(). * - * flags: kDNSServiceFlagsForceMulticast or kDNSServiceFlagsLongLivedQuery. - * Pass kDNSServiceFlagsLongLivedQuery to create a "long-lived" unicast - * query to a unicast DNS server that implements the protocol. This flag - * has no effect on link-local multicast queries. + * flags: kDNSServiceFlagsForceMulticast * * interfaceIndex: The interface on which to issue the query. Passing 0 causes the query to be * sent on all active interfaces via Multicast or the primary interface via Unicast. @@ -2551,7 +2554,7 @@ DNSServiceErrorType DNSSD_API TXTRecordGetItemAtIndex * If there is any error during the processing of events, the application callback will * be called with an error code. For shared connections, each subordinate DNSServiceRef * will get its own error callback. Currently these error callbacks only happen - * if the mDNSResponder daemon is manually terminated or crashes, and the error + * if the daemon is manually terminated or crashes, and the error * code in this case is kDNSServiceErr_ServiceNotRunning. The application must call * DNSServiceRefDeallocate to free the DNSServiceRef when it gets such an error code. * These error callbacks are rare and should not normally happen on customer machines, diff --git a/mDNSResponder/mDNSShared/dnssd_clientstub.c b/mDNSResponder/mDNSShared/dnssd_clientstub.c index d21658fa..e8b46d86 100644 --- a/mDNSResponder/mDNSShared/dnssd_clientstub.c +++ b/mDNSResponder/mDNSShared/dnssd_clientstub.c @@ -37,8 +37,6 @@ #include "dnssd_ipc.h" -static int gDaemonErr = kDNSServiceErr_NoError; - #if defined(_WIN32) #define _SSIZE_T @@ -308,6 +306,8 @@ static int more_bytes(dnssd_sock_t sd) // the next operation on this socket(recv/accept) is blocked since we depend on TCP to communicate with the system service. static int set_waitlimit(dnssd_sock_t sock, int timeout) { + int gDaemonErr = kDNSServiceErr_NoError; + // To prevent stack corruption since select does not work with timeout if fds > FD_SETSIZE(1024) if (!gDaemonErr && sock < FD_SETSIZE) { @@ -526,6 +526,11 @@ static DNSServiceErrorType ConnectToServer(DNSServiceRef *ref, DNSServiceFlags f #ifdef SO_NOSIGPIPE const unsigned long optval = 1; #endif + #ifndef USE_TCP_LOOPBACK + char* uds_serverpath = getenv(MDNS_UDS_SERVERPATH_ENVVAR); + if (uds_serverpath == NULL) + uds_serverpath = MDNS_UDS_SERVERPATH; + #endif *ref = NULL; sdr->sockfd = socket(AF_DNSSD, SOCK_STREAM, 0); sdr->validator = sdr->sockfd ^ ValidatorBits; @@ -546,7 +551,7 @@ static DNSServiceErrorType ConnectToServer(DNSServiceRef *ref, DNSServiceFlags f saddr.sin_port = htons(MDNS_TCP_SERVERPORT); #else saddr.sun_family = AF_LOCAL; - strcpy(saddr.sun_path, MDNS_UDS_SERVERPATH); + strcpy(saddr.sun_path, uds_serverpath); #if !defined(__ppc__) && defined(SO_DEFUNCTOK) { int defunct = 1; @@ -573,8 +578,8 @@ static DNSServiceErrorType ConnectToServer(DNSServiceRef *ref, DNSServiceFlags f } else { - syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: connect() failed Socket:%d Err:%d Errno:%d %s", - sdr->sockfd, err, dnssd_errno, dnssd_strerror(dnssd_errno)); + syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: connect() failed path:%s Socket:%d Err:%d Errno:%d %s", + uds_serverpath, sdr->sockfd, err, dnssd_errno, dnssd_strerror(dnssd_errno)); dnssd_close(sdr->sockfd); FreeDNSServiceOp(sdr); return kDNSServiceErr_ServiceNotRunning; @@ -1224,11 +1229,11 @@ fail: syslog(LOG_WARNING, "dnssd_clientstub handle_resolve_response: error reading result from daemon"); } -#if APPLE_OSX_mDNSResponder +#if TARGET_OS_EMBEDDED static int32_t libSystemVersion = 0; -// Return true if the application linked against a version of libsystem where P2P +// Return true if the iOS application linked against a version of libsystem where P2P // interfaces were included by default when using kDNSServiceInterfaceIndexAny. // Using 160.0.0 == 0xa00000 as the version threshold. static int includeP2PWithIndexAny() @@ -1242,15 +1247,15 @@ static int includeP2PWithIndexAny() return 0; } -#else // APPLE_OSX_mDNSResponder +#else // TARGET_OS_EMBEDDED -// always return false for non Apple platforms +// always return false for non iOS platforms static int includeP2PWithIndexAny() { return 0; } -#endif // APPLE_OSX_mDNSResponder +#endif // TARGET_OS_EMBEDDED DNSServiceErrorType DNSSD_API DNSServiceResolve ( @@ -1772,7 +1777,8 @@ DNSServiceErrorType DNSSD_API DNSServiceCreateDelegateConnection(DNSServiceRef * } if (pid && setsockopt((*sdRef)->sockfd, SOL_SOCKET, SO_DELEGATED, &pid, sizeof(pid)) == -1) - { + { + syslog(LOG_WARNING, "dnssdclientstub: Could not setsockopt() for PID[%d], no entitlements or process(pid) invalid errno:%d (%s)", pid, errno, strerror(errno)); // Free the hdr in case we return before calling deliver_request() if (hdr) free(hdr); @@ -1783,6 +1789,7 @@ DNSServiceErrorType DNSSD_API DNSServiceCreateDelegateConnection(DNSServiceRef * if (!pid && setsockopt((*sdRef)->sockfd, SOL_SOCKET, SO_DELEGATED_UUID, uuid, sizeof(uuid_t)) == -1) { + syslog(LOG_WARNING, "dnssdclientstub: Could not setsockopt() for UUID, no entitlements or process(uuid) invalid errno:%d (%s) ", errno, strerror(errno)); // Free the hdr in case we return before calling deliver_request() if (hdr) free(hdr); diff --git a/mDNSResponder/mDNSShared/dnssd_ipc.h b/mDNSResponder/mDNSShared/dnssd_ipc.h index 360d703f..609fa640 100644 --- a/mDNSResponder/mDNSShared/dnssd_ipc.h +++ b/mDNSResponder/mDNSShared/dnssd_ipc.h @@ -85,6 +85,7 @@ extern char *win32_strerror(int inErrorCode); # ifndef MDNS_UDS_SERVERPATH # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder" # endif +# define MDNS_UDS_SERVERPATH_ENVVAR "DNSSD_UDS_PATH" # define LISTENQ 100 // longest legal control path length # define MAX_CTLPATH 256 |