diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-09-19 08:52:21 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2018-09-20 11:23:32 +0200 |
commit | f761b290f135957f47e1c9af71b4a81c76c32b48 (patch) | |
tree | 2b7d273db4ff2388867efec5ad432fa49cd4047e /mDNSResponder/mDNSShared | |
parent | mDNSResponder: Update to v576.30.4 (diff) | |
download | rtems-libbsd-f761b290f135957f47e1c9af71b4a81c76c32b48.tar.bz2 |
mDNSResponder: Update to v625.41.2
The sources can be obtained via:
https://opensource.apple.com/tarballs/mDNSResponder/mDNSResponder-625.41.2.tar.gz
Update #3522.
Diffstat (limited to 'mDNSResponder/mDNSShared')
-rw-r--r-- | mDNSResponder/mDNSShared/CommonServices.h | 6 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/DebugServices.c | 4 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/GenLinkedList.c | 9 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/PlatformCommon.c | 11 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dns-sd.1 | 2 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dns_sd.h | 47 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnsextd.8 | 2 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnsextd.c | 30 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnsextd_lexer.l | 7 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnsextd_parser.y | 33 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnssd_clientlib.c | 4 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnssd_clientstub.c | 70 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnssd_ipc.c | 4 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/dnssd_ipc.h | 6 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/mDNSDebug.c | 9 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/mDNSResponder.8 | 27 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/uds_daemon.c | 223 | ||||
-rw-r--r-- | mDNSResponder/mDNSShared/uds_daemon.h | 11 |
18 files changed, 280 insertions, 225 deletions
diff --git a/mDNSResponder/mDNSShared/CommonServices.h b/mDNSResponder/mDNSShared/CommonServices.h index 342479b9..7fceac02 100644 --- a/mDNSResponder/mDNSShared/CommonServices.h +++ b/mDNSResponder/mDNSShared/CommonServices.h @@ -834,6 +834,12 @@ typedef unsigned long int uintptr_t; #endif #endif +// Limits + +#if( !defined( UINT32_MAX ) ) + #define UINT32_MAX UINT32_C( 4294967295 ) +#endif + #if 0 #pragma mark == bool == #endif diff --git a/mDNSResponder/mDNSShared/DebugServices.c b/mDNSResponder/mDNSShared/DebugServices.c index 98f876a4..44305a5c 100644 --- a/mDNSResponder/mDNSShared/DebugServices.c +++ b/mDNSResponder/mDNSShared/DebugServices.c @@ -1746,8 +1746,8 @@ DEBUG_EXPORT const char * DebugGetErrorString( int_least32_t inErrorCode, char CaseErrorStringifyHardCode( -65548, mStatus_NameConflict ); CaseErrorStringifyHardCode( -65549, mStatus_Invalid ); CaseErrorStringifyHardCode( -65550, mStatus_GrowCache ); - CaseErrorStringifyHardCode( -65551, mStatus_BadInterfaceErr ); - CaseErrorStringifyHardCode( -65552, mStatus_Incompatible ); + CaseErrorStringifyHardCode( -65551, mStatus_Incompatible ); + CaseErrorStringifyHardCode( -65552, mStatus_BadInterfaceErr ); CaseErrorStringifyHardCode( -65791, mStatus_ConfigChanged ); CaseErrorStringifyHardCode( -65792, mStatus_MemFree ); diff --git a/mDNSResponder/mDNSShared/GenLinkedList.c b/mDNSResponder/mDNSShared/GenLinkedList.c index 45dbb7cb..1c6cb5be 100644 --- a/mDNSResponder/mDNSShared/GenLinkedList.c +++ b/mDNSResponder/mDNSShared/GenLinkedList.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2011 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - - File: GenLinkedList.c - - Contains: implementation of generic linked lists. - - Version: 1.0 - Tabs: 4 spaces */ #include "GenLinkedList.h" diff --git a/mDNSResponder/mDNSShared/PlatformCommon.c b/mDNSResponder/mDNSShared/PlatformCommon.c index d86a755a..4f844560 100644 --- a/mDNSResponder/mDNSShared/PlatformCommon.c +++ b/mDNSResponder/mDNSShared/PlatformCommon.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004-2015 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -190,10 +190,13 @@ mDNSexport void mDNSPlatformWriteLogMsg(const char *ident, const char *buffer, m if (ident && ident[0] && mDNSPlatformClockDivisor) syslog(syslog_level, "%8d.%03d: %s", (int)(t/1000), ms, buffer); else -#elif APPLE_OSX_mDNSResponder - mDNSPlatformLogToFile(syslog_level, buffer); +#endif + { +#if APPLE_OSX_mDNSResponder + mDNSPlatformLogToFile(syslog_level, buffer); #else - syslog(syslog_level, "%s", buffer); + syslog(syslog_level, "%s", buffer); #endif + } } } diff --git a/mDNSResponder/mDNSShared/dns-sd.1 b/mDNSResponder/mDNSShared/dns-sd.1 index 9d8323b9..d462ae20 100644 --- a/mDNSResponder/mDNSShared/dns-sd.1 +++ b/mDNSResponder/mDNSShared/dns-sd.1 @@ -1,6 +1,6 @@ .\" -*- tab-width: 4 -*- .\" -.\" Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved. +.\" Copyright (c) 2004-2012 Apple Inc. All Rights Reserved. .\" .\" Licensed under the Apache License, Version 2.0 (the "License"); .\" you may not use this file except in compliance with the License. diff --git a/mDNSResponder/mDNSShared/dns_sd.h b/mDNSResponder/mDNSShared/dns_sd.h index 38315273..cf32ea1e 100644 --- a/mDNSResponder/mDNSShared/dns_sd.h +++ b/mDNSResponder/mDNSShared/dns_sd.h @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2003-2013 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its + * 3. Neither the name of Apple Inc. ("Apple") nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * @@ -66,7 +66,7 @@ */ #ifndef _DNS_SD_H -#define _DNS_SD_H 5763004 +#define _DNS_SD_H 6254102 #ifdef __cplusplus extern "C" { @@ -497,12 +497,18 @@ enum * as the "serviceIndex". */ - kDNSServiceFlagsDenyExpensive = 0x20000000 + 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. */ + kDNSServiceFlagsPathEvaluationDone = 0x40000000 + /* + * This flag is meaningful for only Unicast DNS queries. + * When set, it indicates that Network PathEvaluation has already been performed. + */ + }; #define kDNSServiceOutputFlags (kDNSServiceFlagsValidate | kDNSServiceFlagsValidateOptional | kDNSServiceFlagsMoreComing | kDNSServiceFlagsAdd | kDNSServiceFlagsDefault) @@ -724,9 +730,8 @@ enum * DNS server." Normally, most clients will use 0 for interface index to * automatically get the default sensible behaviour. * - * If the client passes a positive interface index, then for multicast names that - * indicates to do the operation only on that one interface. For unicast names the - * interface index is ignored unless kDNSServiceFlagsForceMulticast is also set. + * If the client passes a positive interface index, then that indicates to do the + * operation only on that one specified interface. * * If the client passes kDNSServiceInterfaceIndexLocalOnly when registering * a service, then that service will be found *only* by other local clients @@ -2606,34 +2611,6 @@ DNSServiceErrorType DNSSD_API DNSServiceSleepKeepalive ); #endif -#ifdef APPLE_OSX_mDNSResponder -/* DNSServiceCreateDelegateConnection() - * - * Create a delegate connection to the daemon allowing efficient registration of - * multiple individual records. - * - * Parameters: - * - * sdRef: A pointer to an uninitialized DNSServiceRef. Deallocating - * the reference (via DNSServiceRefDeallocate()) severs the - * connection and deregisters all records registered on this connection. - * - * pid : Process ID of the delegate - * - * uuid: UUID of the delegate - * - * Note that only one of the two arguments (pid or uuid) can be specified. If pid - * is zero, uuid will be assumed to be a valid value; otherwise pid will be used. - * - * return value: Returns kDNSServiceErr_NoError on success, otherwise returns - * an error code indicating the specific failure that occurred (in which - * case the DNSServiceRef is not initialized). kDNSServiceErr_NotAuth is - * returned to indicate that the calling process does not have entitlements - * to use this API. - */ -DNSServiceErrorType DNSSD_API DNSServiceCreateDelegateConnection(DNSServiceRef *sdRef, int32_t pid, uuid_t uuid); -#endif - #ifdef __APPLE_API_PRIVATE #define kDNSServiceCompPrivateDNS "PrivateDNS" diff --git a/mDNSResponder/mDNSShared/dnsextd.8 b/mDNSResponder/mDNSShared/dnsextd.8 index 796caaba..6611c823 100644 --- a/mDNSResponder/mDNSShared/dnsextd.8 +++ b/mDNSResponder/mDNSShared/dnsextd.8 @@ -1,6 +1,6 @@ .\" -*- tab-width: 4 -*- .\" -.\" Copyright (c) 2004 Apple Computer, Inc. All Rights Reserved. +.\" Copyright (c) 2004, 2006, 2009 Apple Inc. All Rights Reserved. .\" .\" Licensed under the Apache License, Version 2.0 (the "License"); .\" you may not use this file except in compliance with the License. diff --git a/mDNSResponder/mDNSShared/dnsextd.c b/mDNSResponder/mDNSShared/dnsextd.c index aa06650a..7b8e67e6 100644 --- a/mDNSResponder/mDNSShared/dnsextd.c +++ b/mDNSResponder/mDNSShared/dnsextd.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2002-2015 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -560,6 +560,7 @@ mDNSlocal mDNSBool IsLLQRequest(PktMsg *pkt) ptr = LocateAdditionals(&pkt->msg, end); if (!ptr) goto end; + bzero(&lcr, sizeof(lcr)); // find last Additional info. for (i = 0; i < pkt->msg.h.numAdditionals; i++) { @@ -628,7 +629,6 @@ SetZone ) { domainname zname; - mDNSu8 QR_OP; const mDNSu8 * ptr = pkt->msg.data; mDNSBool exception = mDNSfalse; @@ -640,15 +640,13 @@ SetZone // Figure out what type of packet this is - QR_OP = ( mDNSu8 ) ( pkt->msg.h.flags.b[0] & kDNSFlag0_QROP_Mask ); - if ( IsQuery( pkt ) ) { DNSQuestion question; // It's a query - ptr = getQuestion( &pkt->msg, ptr, ( ( mDNSu8* ) &pkt->msg ) + pkt->len, NULL, &question ); + getQuestion( &pkt->msg, ptr, ( ( mDNSu8* ) &pkt->msg ) + pkt->len, NULL, &question ); AppendDomainName( &zname, &question.qname ); @@ -661,7 +659,7 @@ SetZone // It's an update. The format of the zone section is the same as the format for the question section // according to RFC 2136, so we'll just treat this as a question so we can get at the zone. - ptr = getQuestion( &pkt->msg, ptr, ( ( mDNSu8* ) &pkt->msg ) + pkt->len, NULL, &question ); + getQuestion( &pkt->msg, ptr, ( ( mDNSu8* ) &pkt->msg ) + pkt->len, NULL, &question ); AppendDomainName( &zname, &question.qname ); @@ -1373,8 +1371,7 @@ mDNSlocal void DeleteRecords(DaemonInfo *d, mDNSBool DeleteAll) // Add, delete, or refresh records in table based on contents of a successfully completed dynamic update mDNSlocal void UpdateLeaseTable(PktMsg *pkt, DaemonInfo *d, mDNSs32 lease) { - RRTableElem **rptr, *tmp; - int i, allocsize, bucket; + int i, allocsize; LargeCacheRecord lcr; ResourceRecord *rr = &lcr.r.resrec; const mDNSu8 *ptr, *end; @@ -1397,8 +1394,8 @@ mDNSlocal void UpdateLeaseTable(PktMsg *pkt, DaemonInfo *d, mDNSs32 lease) ptr = GetLargeResourceRecord(NULL, &pkt->msg, ptr, end, 0, kDNSRecordTypePacketAns, &lcr); if (!ptr || lcr.r.resrec.RecordType == kDNSRecordTypePacketNegative) { Log("UpdateLeaseTable: GetLargeResourceRecord failed"); goto cleanup; } - bucket = rr->namehash % d->nbuckets; - rptr = &d->table[bucket]; + int bucket = rr->namehash % d->nbuckets; + RRTableElem *tmp, **rptr = &d->table[bucket]; // handle deletions if (rr->rrtype == kDNSQType_ANY && !rr->rroriginalttl && rr->rrclass == kDNSQClass_ANY && !rr->rdlength) @@ -1444,7 +1441,6 @@ mDNSlocal void UpdateLeaseTable(PktMsg *pkt, DaemonInfo *d, mDNSs32 lease) { RehashTable(d); bucket = rr->namehash % d->nbuckets; - rptr = &d->table[bucket]; } if (gettimeofday(&tv, NULL)) { LogErr("UpdateLeaseTable", "gettimeofday"); goto cleanup; } allocsize = sizeof(RRTableElem); @@ -1475,12 +1471,11 @@ cleanup: // Replies are currently not signed !!!KRS change this mDNSlocal PktMsg *FormatLeaseReply(DaemonInfo *d, PktMsg *orig, mDNSu32 lease) { - PktMsg *reply; - mDNSu8 *ptr, *end; + PktMsg *const reply = malloc(sizeof(*reply)); + mDNSu8 *ptr; mDNSOpaque16 flags; - (void)d; //unused - reply = malloc(sizeof(*reply)); + if (!reply) { LogErr("FormatLeaseReply", "malloc"); return NULL; } flags.b[0] = kDNSFlag0_QR_Response | kDNSFlag0_OP_Update; flags.b[1] = 0; @@ -1488,9 +1483,7 @@ mDNSlocal PktMsg *FormatLeaseReply(DaemonInfo *d, PktMsg *orig, mDNSu32 lease) InitializeDNSMessage(&reply->msg.h, orig->msg.h.id, flags); reply->src.sin_addr.s_addr = zerov4Addr.NotAnInteger; // unused except for log messages reply->src.sin_family = AF_INET; - ptr = reply->msg.data; - end = (mDNSu8 *)&reply->msg + sizeof(DNSMessage); - ptr = putUpdateLease(&reply->msg, ptr, lease); + ptr = putUpdateLease(&reply->msg, reply->msg.data, lease); if (!ptr) { Log("FormatLeaseReply: putUpdateLease failed"); free(reply); return NULL; } reply->len = ptr - (mDNSu8 *)&reply->msg; HdrHToN(reply); @@ -2401,6 +2394,7 @@ mDNSlocal mDNSBool IsAuthorized( DaemonInfo * d, PktMsg * pkt, DomainAuthInfo ** HdrNToH(pkt); *key = NULL; + bzero(&lcr, sizeof(lcr)); if ( pkt->msg.h.numAdditionals ) { diff --git a/mDNSResponder/mDNSShared/dnsextd_lexer.l b/mDNSResponder/mDNSShared/dnsextd_lexer.l index 5cac1060..75df9697 100644 --- a/mDNSResponder/mDNSShared/dnsextd_lexer.l +++ b/mDNSResponder/mDNSShared/dnsextd_lexer.l @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2006-2011 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2006-2011 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,11 +23,6 @@ extern YYSTYPE yylval; -/* Mac OS X 10.4 has flex version 2.5.4, which doesn't define yylineno for us */ -/* Mac OS X 10.5 has flex version 2.5.33, which does define yylineno */ -#if YY_FLEX_MAJOR_VERSION <= 2 && YY_FLEX_MINOR_VERSION <= 5 && YY_FLEX_SUBMINOR_VERSION <= 4 -int yylineno = 1; -#endif #define YY_NO_INPUT 1 int yylex(void); diff --git a/mDNSResponder/mDNSShared/dnsextd_parser.y b/mDNSResponder/mDNSShared/dnsextd_parser.y index 18c5990f..24d62696 100644 --- a/mDNSResponder/mDNSShared/dnsextd_parser.y +++ b/mDNSResponder/mDNSShared/dnsextd_parser.y @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2006-2010 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,6 +76,7 @@ typedef struct ZoneSpec static StringListElem * g_stringList = NULL; +static StringListElem * g_addrList = NULL; static KeySpec * g_keys; static ZoneSpec * g_zones; static ZoneSpec g_zoneSpec; @@ -173,6 +174,22 @@ optionsstatement: | LISTEN_ON PORT NUMBER addresscontent { + mDNSIPPort listen_port = mDNSOpaque16fromIntVal( $3 ); + DaemonInfo* d = ( DaemonInfo* ) context; + d->addr.sin_port = ( listen_port.NotAnInteger) ? listen_port.NotAnInteger : UnicastDNSPort.NotAnInteger; + StringListElem* addr = g_addrList; + while (addr != NULL) + { + StringListElem* next; + // The first ipv4 address in {,} is used; the rest are ignored. + if (inet_pton( AF_INET, addr->string, &d->addr.sin_addr ) == 0) { + inet_pton( AF_INET, "127.0.0.1", &d->ns_addr.sin_addr ); + LogMsg("LISTEN_ON: An invalid ipv4 address, %s, detected.", addr->string); + } + next = addr->next; + free(addr); + addr = next; + } } | NAMESERVER ADDRESS networkaddress @@ -308,6 +325,20 @@ addressstatements: addressstatement: DOTTED_DECIMAL_ADDRESS { + StringListElem * elem; + + elem = ( StringListElem* ) malloc( sizeof( StringListElem ) ); + + if ( !elem ) + { + LogMsg("ERROR: memory allocation failure"); + YYABORT; + } + + elem->string = $1; + + elem->next = g_addrList; + g_addrList = elem; } ; diff --git a/mDNSResponder/mDNSShared/dnssd_clientlib.c b/mDNSResponder/mDNSShared/dnssd_clientlib.c index cca58853..cfc1d424 100644 --- a/mDNSResponder/mDNSShared/dnssd_clientlib.c +++ b/mDNSResponder/mDNSShared/dnssd_clientlib.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2004, Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004-2011 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its + * 3. Neither the name of Apple Inc. ("Apple") nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * diff --git a/mDNSResponder/mDNSShared/dnssd_clientstub.c b/mDNSResponder/mDNSShared/dnssd_clientstub.c index 5c1d02c4..5e151d08 100644 --- a/mDNSResponder/mDNSShared/dnssd_clientstub.c +++ b/mDNSResponder/mDNSShared/dnssd_clientstub.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its + * 3. Neither the name of Apple Inc. ("Apple") nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * @@ -29,14 +29,15 @@ #include <errno.h> #include <stdlib.h> +#include "dnssd_ipc.h" + #if APPLE_OSX_mDNSResponder #include <mach-o/dyld.h> #include <uuid/uuid.h> #include <TargetConditionals.h> +#include "dns_sd_private.h" #endif -#include "dnssd_ipc.h" - #if defined(_WIN32) #define _SSIZE_T @@ -74,7 +75,7 @@ static void syslog( int priority, const char * message, ...) va_start( args, message ); len = _vscprintf( message, args ) + 1; buffer = malloc( len * sizeof(char) ); - if ( buffer ) { vsprintf( buffer, message, args ); OutputDebugString( buffer ); free( buffer ); } + if ( buffer ) { vsnprintf( buffer, len, message, args ); OutputDebugString( buffer ); free( buffer ); } WSASetLastError( err ); } #else @@ -284,7 +285,7 @@ static int more_bytes(dnssd_sock_t sd) // two ints and not just one. int nfdbits = sizeof (int) * 8; int nints = (sd/nfdbits) + 1; - fs = (fd_set *)calloc(nints, sizeof(int)); + fs = (fd_set *)calloc(nints, (size_t)sizeof(int)); if (fs == NULL) { syslog(LOG_WARNING, "dnssd_clientstub more_bytes: malloc failed"); @@ -355,7 +356,7 @@ static ipc_msg_hdr *create_hdr(uint32_t op, size_t *len, char **data_start, int struct timeval tv; if (gettimeofday(&tv, NULL) < 0) { syslog(LOG_WARNING, "dnssd_clientstub create_hdr: gettimeofday failed %d %s", dnssd_errno, dnssd_strerror(dnssd_errno)); return NULL; } - sprintf(ctrl_path, "%s%d-%.3lx-%.6lu", CTL_PATH_PREFIX, (int)getpid(), + snprintf(ctrl_path, sizeof(ctrl_path), "%s%d-%.3lx-%.6lu", CTL_PATH_PREFIX, (int)getpid(), (unsigned long)(tv.tv_sec & 0xFFF), (unsigned long)(tv.tv_usec)); *len += strlen(ctrl_path) + 1; #else @@ -405,7 +406,11 @@ static void FreeDNSServiceOp(DNSServiceOp *x) // We don't use our DNSServiceRefValid macro here because if we're cleaning up after a socket() call failed // then sockfd could legitimately contain a failing value (e.g. dnssd_InvalidSocket) if ((x->sockfd ^ x->validator) != ValidatorBits) + { + static DNSServiceOp *op_were_not_going_to_free_but_we_need_to_fool_the_analyzer; syslog(LOG_WARNING, "dnssd_clientstub attempt to dispose invalid DNSServiceRef %p %08X %08X", x, x->sockfd, x->validator); + op_were_not_going_to_free_but_we_need_to_fool_the_analyzer = x; + } else { x->next = NULL; @@ -530,6 +535,11 @@ static DNSServiceErrorType ConnectToServer(DNSServiceRef *ref, DNSServiceFlags f char* uds_serverpath = getenv(MDNS_UDS_SERVERPATH_ENVVAR); if (uds_serverpath == NULL) uds_serverpath = MDNS_UDS_SERVERPATH; + else if (strlen(uds_serverpath) >= MAX_CTLPATH) + { + uds_serverpath = MDNS_UDS_SERVERPATH; + syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: using default path since env len is invalid"); + } #endif *ref = NULL; sdr->sockfd = socket(AF_DNSSD, SOCK_STREAM, 0); @@ -578,8 +588,10 @@ static DNSServiceErrorType ConnectToServer(DNSServiceRef *ref, DNSServiceFlags f } else { + #if !defined(USE_TCP_LOOPBACK) 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)); + #endif dnssd_close(sdr->sockfd); FreeDNSServiceOp(sdr); return kDNSServiceErr_ServiceNotRunning; @@ -597,21 +609,25 @@ static DNSServiceErrorType ConnectToServer(DNSServiceRef *ref, DNSServiceFlags f static DNSServiceErrorType deliver_request(ipc_msg_hdr *hdr, DNSServiceOp *sdr) { + if (!hdr) + { + syslog(LOG_WARNING, "dnssd_clientstub deliver_request: !hdr"); + return kDNSServiceErr_Unknown; + } + uint32_t datalen = hdr->datalen; // We take a copy here because we're going to convert hdr->datalen to network byte order #if defined(USE_TCP_LOOPBACK) || defined(USE_NAMED_ERROR_RETURN_SOCKET) char *const data = (char *)hdr + sizeof(ipc_msg_hdr); #endif dnssd_sock_t listenfd = dnssd_InvalidSocket, errsd = dnssd_InvalidSocket; DNSServiceErrorType err = kDNSServiceErr_Unknown; // Default for the "goto cleanup" cases - int MakeSeparateReturnSocket = 0; // Note: need to check hdr->op, not sdr->op. // hdr->op contains the code for the specific operation we're currently doing, whereas sdr->op // contains the original parent DNSServiceOp (e.g. for an add_record_request, hdr->op will be // add_record_request but the parent sdr->op will be connection_request or reg_service_request) - if (sdr->primary || - hdr->op == reg_record_request || hdr->op == add_record_request || hdr->op == update_record_request || hdr->op == remove_record_request) - MakeSeparateReturnSocket = 1; + const int MakeSeparateReturnSocket = (sdr->primary || + hdr->op == reg_record_request || hdr->op == add_record_request || hdr->op == update_record_request || hdr->op == remove_record_request); if (!DNSServiceRefValid(sdr)) { @@ -621,12 +637,6 @@ static DNSServiceErrorType deliver_request(ipc_msg_hdr *hdr, DNSServiceOp *sdr) return kDNSServiceErr_BadReference; } - if (!hdr) - { - syslog(LOG_WARNING, "dnssd_clientstub deliver_request: !hdr"); - return kDNSServiceErr_Unknown; - } - if (MakeSeparateReturnSocket) { #if defined(USE_TCP_LOOPBACK) @@ -1158,6 +1168,8 @@ DNSServiceErrorType DNSSD_API DNSServiceGetProperty(const char *property, void * put_string(property, &ptr); err = deliver_request(hdr, tmp); // Will free hdr for us + if (err) { DNSServiceRefDeallocate(tmp); return err; } + if (read_all(tmp->sockfd, (char*)&actualsize, (int)sizeof(actualsize)) < 0) { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_ServiceNotRunning; } @@ -1182,24 +1194,17 @@ DNSServiceErrorType DNSSD_API DNSServiceGetPID(const uint16_t srcport, int32_t * size_t len = sizeof(int32_t); DNSServiceErrorType err = ConnectToServer(&tmp, 0, getpid_request, NULL, NULL, NULL); - if (err) - return err; + if (err) return err; hdr = create_hdr(getpid_request, &len, &ptr, 0, tmp); - if (!hdr) - { - DNSServiceRefDeallocate(tmp); - return kDNSServiceErr_NoMemory; - } + if (!hdr) { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_NoMemory; } put_uint16(srcport, &ptr); err = deliver_request(hdr, tmp); // Will free hdr for us + if (err) { DNSServiceRefDeallocate(tmp); return err; } if (read_all(tmp->sockfd, (char*)pid, sizeof(int32_t)) < 0) - { - DNSServiceRefDeallocate(tmp); - return kDNSServiceErr_ServiceNotRunning; - } + { DNSServiceRefDeallocate(tmp); return kDNSServiceErr_ServiceNotRunning; } DNSServiceRefDeallocate(tmp); return kDNSServiceErr_NoError; @@ -1391,6 +1396,7 @@ static void handle_addrinfo_response(DNSServiceOp *const sdr, const CallbackHead rdlen = get_uint16(&data, end); rdata = get_rdata (&data, end, rdlen); ttl = get_uint32(&data, end); + (void)rrclass; // Unused // We only generate client callbacks for A and AAAA results (including NXDOMAIN results for // those types, if the client has requested those with the kDNSServiceFlagsReturnIntermediates). @@ -1613,13 +1619,7 @@ DNSServiceErrorType DNSSD_API DNSServiceRegister hdr = create_hdr(reg_service_request, &len, &ptr, (*sdRef)->primary ? 1 : 0, *sdRef); if (!hdr) { DNSServiceRefDeallocate(*sdRef); *sdRef = NULL; return kDNSServiceErr_NoMemory; } - - // If it is going over a shared connection, then don't set the IPC_FLAGS_NOREPLY - // as it affects all the operations over the shared connection. This is not - // a normal case and hence receiving the response back from the daemon and - // discarding it in ConnectionResponse is okay. - - if (!(flags & kDNSServiceFlagsShareConnection) && !callBack) hdr->ipc_flags |= IPC_FLAGS_NOREPLY; + if (!callBack) hdr->ipc_flags |= IPC_FLAGS_NOREPLY; put_flags(flags, &ptr); put_uint32(interfaceIndex, &ptr); diff --git a/mDNSResponder/mDNSShared/dnssd_ipc.c b/mDNSResponder/mDNSShared/dnssd_ipc.c index 6059eb39..0fd75824 100644 --- a/mDNSResponder/mDNSShared/dnssd_ipc.c +++ b/mDNSResponder/mDNSShared/dnssd_ipc.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2011 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its + * 3. Neither the name of Apple Inc. ("Apple") nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * diff --git a/mDNSResponder/mDNSShared/dnssd_ipc.h b/mDNSResponder/mDNSShared/dnssd_ipc.h index 609fa640..7dc64c5f 100644 --- a/mDNSResponder/mDNSShared/dnssd_ipc.h +++ b/mDNSResponder/mDNSShared/dnssd_ipc.h @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -10,7 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its + * 3. Neither the name of Apple Inc. ("Apple") nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * @@ -88,7 +88,7 @@ extern char *win32_strerror(int inErrorCode); # define MDNS_UDS_SERVERPATH_ENVVAR "DNSSD_UDS_PATH" # define LISTENQ 100 // longest legal control path length -# define MAX_CTLPATH 256 +# define MAX_CTLPATH (sizeof(((struct sockaddr_un*)0)->sun_path)) # define dnssd_sockaddr_t struct sockaddr_un #endif diff --git a/mDNSResponder/mDNSShared/mDNSDebug.c b/mDNSResponder/mDNSShared/mDNSDebug.c index 4f575c06..6c0781c3 100644 --- a/mDNSResponder/mDNSShared/mDNSDebug.c +++ b/mDNSResponder/mDNSShared/mDNSDebug.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2015 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - - File: mDNSDebug.c - - Contains: Implementation of debugging utilities. Requires a POSIX environment. - - Version: 1.0 - */ #include "mDNSDebug.h" diff --git a/mDNSResponder/mDNSShared/mDNSResponder.8 b/mDNSResponder/mDNSShared/mDNSResponder.8 index 48c1cf65..e9bd8e9b 100644 --- a/mDNSResponder/mDNSShared/mDNSResponder.8 +++ b/mDNSResponder/mDNSShared/mDNSResponder.8 @@ -1,6 +1,6 @@ .\" -*- tab-width: 4 -*- .\" -.\" Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved. +.\" Copyright (c) 2003-2012 Apple Inc. All Rights Reserved. .\" .\" Licensed under the Apache License, Version 2.0 (the "License"); .\" you may not use this file except in compliance with the License. @@ -80,9 +80,28 @@ A SIGINFO signal will dump a snapshot summary of the internal state to .Pa /var/log/system.log Ns : .Pp .Dl % sudo killall -INFO mDNSResponder +.Sh OPTIONAL ARGUMENTS +.Nm +accepts the following optional arguments: +.Bl -tag -width "AlwaysAppendSearchDomains" +.It Fl AlwaysAppendSearchDomains +Append search domains for multi-labeled Partially Qualified Domain Name as well as single-labeled Partially Qualified Domain Name. +This argument is not recommended because of the extra DNS traffic it generates and its adverse effect on battery life. +.It Fl NoMulticastAdvertisements +Prevent the system from advertising Bonjour services via Multicast DNS. +.El +.Pp +To cause +.Nm +to run with these optional arguments when it launches on OS X 10.11 (El Capitan) and later, set the +.Sy AlwaysAppendSearchDomains +or +.Sy NoMulticastAdvertisements +boolean keys to true in /Library/Preferences/com.apple.mDNSResponder.plist and reboot. +.Pp .Sh FILES -.Pa /usr/sbin/mDNSResponder \" Pathname -.\" +.Pa /usr/sbin/mDNSResponder +.Pa /Library/Preferences/com.apple.mDNSResponder.plist .Pp .Sh INFO .Pp @@ -112,5 +131,5 @@ daemon first appeared in Mac OS X 10.2 (Jaguar). Also available from the Darwin open source repository (though not officially supported by Apple) are .Nm -daemons for other platforms, including Mac OS 9, Microsoft Windows, +daemons for other platforms, including Microsoft Windows, Linux, FreeBSD, NetBSD, Solaris, and other POSIX systems. diff --git a/mDNSResponder/mDNSShared/uds_daemon.c b/mDNSResponder/mDNSShared/uds_daemon.c index 310df527..be89f319 100644 --- a/mDNSResponder/mDNSShared/uds_daemon.c +++ b/mDNSResponder/mDNSShared/uds_daemon.c @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2003-2013 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2015 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -171,6 +171,7 @@ struct request_state struct reply_state *replies; // corresponding (active) reply list req_termination_fn terminate; DNSServiceFlags flags; + mDNSu32 interfaceIndex; union { @@ -317,10 +318,8 @@ mDNSlocal char *AnonDataToString(const mDNSu8 *ad, int adlen, char *adstr, int a mDNSlocal void FatalError(char *errmsg) { - char* ptr = NULL; LogMsg("%s: %s", errmsg, dnssd_strerror(dnssd_errno)); - *ptr = 0; // On OS X abort() doesn't generate a crash log, but writing to zero does - abort(); // On platforms where writing to zero doesn't generate an exception, abort instead + abort(); } mDNSlocal mDNSu32 dnssd_htonl(mDNSu32 l) @@ -546,10 +545,20 @@ mDNSlocal reply_state *create_reply(const reply_op_t op, const size_t datalen, r // Append a reply to the list in a request object // If our request is sharing a connection, then we append our reply_state onto the primary's list +// If the request does not want asynchronous replies, then the reply is freed instead of being appended to any list. mDNSlocal void append_reply(request_state *req, reply_state *rep) { - request_state *r = req->primary ? req->primary : req; - reply_state **ptr = &r->replies; + request_state *r; + reply_state **ptr; + + if (req->no_reply) + { + freeL("reply_state/append_reply", rep); + return; + } + + r = req->primary ? req->primary : req; + ptr = &r->replies; while (*ptr) ptr = &(*ptr)->next; *ptr = rep; rep->next = NULL; @@ -662,6 +671,7 @@ mDNSlocal AuthRecord *read_rr_from_ipc_msg(request_state *request, int GetTTL, i AuthRecType artype; request->flags = flags; + request->interfaceIndex = interfaceIndex; if (str_err) { LogMsg("ERROR: read_rr_from_ipc_msg - get_string"); return NULL; } @@ -1066,7 +1076,7 @@ mDNSlocal void regrecord_callback(mDNS *const m, AuthRecord *rr, mStatus result) if (result != mStatus_MemFree) LogMsg("regrecord_callback: error %d received after parent termination", result); // We come here when the record is being deregistered either from DNSServiceRemoveRecord or connection_termination. - // If the record has been updated, we need to free the rdata. Everytime we call mDNS_Update, it calls update_callback + // If the record has been updated, we need to free the rdata. Every time we call mDNS_Update, it calls update_callback // with the old rdata (so that we can free it) and stores the new rdata in "rr->resrec.rdata". This means, we need // to free the latest rdata for which the update_callback was never called with. if (rr->resrec.rdata != &rr->rdatastorage) freeL("RData/regrecord_callback", rr->resrec.rdata); @@ -1149,11 +1159,12 @@ mDNSlocal void set_peer_pid(request_state *request) return; mDNSPlatformStrCopy(request->pid_name, proc.pbsi_comm); request->process_id = p; + debugf("set_peer_pid: Client PEERPID is %d %s", p, request->pid_name); #else // !LOCAL_PEERPID len = 0; + LogInfo("set_peer_pid: Not Supported on this version of OS"); if (request->sd < 0) return; - LogInfo("set_peer_pid: Not Supported on this version of OS"); #endif // LOCAL_PEERPID } @@ -1975,7 +1986,6 @@ mDNSlocal mDNSBool PreDefinedInterfaceIndex(mDNSu32 interfaceIndex) case kDNSServiceInterfaceIndexUnicast: case kDNSServiceInterfaceIndexP2P: return mDNStrue; - break; default: return mDNSfalse; } @@ -1989,6 +1999,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) domainname d, srv; mStatus err; char *AnonData = mDNSNULL; + const char *msgTXTData; DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); mDNSu32 interfaceIndex = get_uint32(&request->msgptr, request->msgend); @@ -2012,7 +2023,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) // If it's one of the specially defined inteface index values, just return an error. if (PreDefinedInterfaceIndex(interfaceIndex)) { - LogMsg("ERROR: handle_regservice_request: bad interfaceIndex %d", interfaceIndex); + LogInfo("handle_regservice_request: bad interfaceIndex %d", interfaceIndex); return(mStatus_BadParamErr); } @@ -2029,6 +2040,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) { LogMsg("ERROR: handle_regservice_request - Couldn't read name/regtype/domain"); return(mStatus_BadParamErr); } request->flags = flags; + request->interfaceIndex = interfaceIndex; request->u.servicereg.InterfaceID = InterfaceID; request->u.servicereg.instances = NULL; request->u.servicereg.txtlen = 0; @@ -2043,21 +2055,23 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) } request->u.servicereg.txtlen = get_uint16(&request->msgptr, request->msgend); + msgTXTData = get_rdata(&request->msgptr, request->msgend, request->u.servicereg.txtlen); + + if (!request->msgptr) { LogMsg("%3d: DNSServiceRegister(unreadable parameters)", request->sd); return(mStatus_BadParamErr); } + if (request->u.servicereg.txtlen) { request->u.servicereg.txtdata = mallocL("service_info txtdata", request->u.servicereg.txtlen); if (!request->u.servicereg.txtdata) FatalError("ERROR: handle_regservice_request - malloc"); - mDNSPlatformMemCopy(request->u.servicereg.txtdata, get_rdata(&request->msgptr, request->msgend, request->u.servicereg.txtlen), request->u.servicereg.txtlen); + mDNSPlatformMemCopy(request->u.servicereg.txtdata, msgTXTData, request->u.servicereg.txtlen); } - if (!request->msgptr) { LogMsg("%3d: DNSServiceRegister(unreadable parameters)", request->sd); return(mStatus_BadParamErr); } - // Check for sub-types after the service type request->u.servicereg.num_subtypes = ChopSubTypes(request->u.servicereg.type_as_string, &AnonData); // Note: Modifies regtype string to remove trailing subtypes if (request->u.servicereg.num_subtypes < 0) { LogMsg("ERROR: handle_regservice_request - ChopSubTypes failed %s", request->u.servicereg.type_as_string); - return(mStatus_BadParamErr); + goto bad_param; } if (AnonData) { @@ -2065,7 +2079,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) if (AnonDataLen > MAX_ANONYMOUS_DATA) { LogMsg("ERROR: handle_regservice_request: AnonDataLen %d", AnonDataLen); - return(mStatus_BadParamErr); + goto bad_param; } request->u.servicereg.AnonData = mDNStrue; } @@ -2076,7 +2090,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) // Don't try to construct "domainname t" until *after* ChopSubTypes has worked its magic if (!*request->u.servicereg.type_as_string || !MakeDomainNameFromDNSNameString(&request->u.servicereg.type, request->u.servicereg.type_as_string)) - { LogMsg("ERROR: handle_regservice_request - type_as_string bad %s", request->u.servicereg.type_as_string); return(mStatus_BadParamErr); } + { LogMsg("ERROR: handle_regservice_request - type_as_string bad %s", request->u.servicereg.type_as_string); goto bad_param; } if (!name[0]) { @@ -2092,7 +2106,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) name[newlen] = 0; } if (!MakeDomainLabelFromLiteralString(&request->u.servicereg.name, name)) - { LogMsg("ERROR: handle_regservice_request - name bad %s", name); return(mStatus_BadParamErr); } + { LogMsg("ERROR: handle_regservice_request - name bad %s", name); goto bad_param; } request->u.servicereg.autoname = mDNSfalse; } @@ -2100,7 +2114,7 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) { request->u.servicereg.default_domain = mDNSfalse; if (!MakeDomainNameFromDNSNameString(&d, domain)) - { LogMsg("ERROR: handle_regservice_request - domain bad %s", domain); return(mStatus_BadParamErr); } + { LogMsg("ERROR: handle_regservice_request - domain bad %s", domain); goto bad_param; } } else { @@ -2109,19 +2123,16 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) } // We don't allow the anonymous and the regular ones to coexist - if (!CheckForMixedRegistrations(&request->u.servicereg.type, &d, request->u.servicereg.AnonData)) - { - return(mStatus_BadParamErr); - } + if (!CheckForMixedRegistrations(&request->u.servicereg.type, &d, request->u.servicereg.AnonData)) { goto bad_param; } if (!ConstructServiceName(&srv, &request->u.servicereg.name, &request->u.servicereg.type, &d)) { LogMsg("ERROR: handle_regservice_request - Couldn't ConstructServiceName from, “%#s” “%##s” “%##s”", - request->u.servicereg.name.c, request->u.servicereg.type.c, d.c); return(mStatus_BadParamErr); + request->u.servicereg.name.c, request->u.servicereg.type.c, d.c); goto bad_param; } if (!MakeDomainNameFromDNSNameString(&request->u.servicereg.host, host)) - { LogMsg("ERROR: handle_regservice_request - host bad %s", host); return(mStatus_BadParamErr); } + { LogMsg("ERROR: handle_regservice_request - host bad %s", host); goto bad_param; } request->u.servicereg.autorename = (flags & kDNSServiceFlagsNoAutoRename ) == 0; request->u.servicereg.allowremotequery = (flags & kDNSServiceFlagsAllowRemoteQuery) != 0; @@ -2168,6 +2179,11 @@ mDNSlocal mStatus handle_regservice_request(request_state *request) } return(err); + +bad_param: + freeL("handle_regservice_request (txtdata)", request->u.servicereg.txtdata); + request->u.servicereg.txtdata = NULL; + return mStatus_BadParamErr; } // *************************************************************************** @@ -2455,9 +2471,13 @@ mDNSlocal void UpdateDeviceInfoRecord(mDNS *const m) { int num_autoname = 0; request_state *req; + + // Don't need to register the device info record for kDNSServiceInterfaceIndexLocalOnly registrations. for (req = all_requests; req; req = req->next) - if (req->terminate == regservice_termination_callback && req->u.servicereg.autoname) + { + if (req->terminate == regservice_termination_callback && req->u.servicereg.autoname && req->interfaceIndex != kDNSServiceInterfaceIndexLocalOnly) num_autoname++; + } // If DeviceInfo record is currently registered, see if we need to deregister it if (m->DeviceInfo.resrec.RecordType != kDNSRecordTypeUnregistered) @@ -2602,7 +2622,7 @@ mDNSlocal mStatus handle_browse_request(request_state *request) // If it's one of the specially defined inteface index values, just return an error. if (PreDefinedInterfaceIndex(interfaceIndex)) { - LogMsg("ERROR: handle_browse_request: bad interfaceIndex %d", interfaceIndex); + LogInfo("handle_browse_request: bad interfaceIndex %d", interfaceIndex); return(mStatus_BadParamErr); } @@ -2618,6 +2638,7 @@ mDNSlocal mStatus handle_browse_request(request_state *request) if (!request->msgptr) { LogMsg("%3d: DNSServiceBrowse(unreadable parameters)", request->sd); return(mStatus_BadParamErr); } request->flags = flags; + request->interfaceIndex = interfaceIndex; typedn.c[0] = 0; NumSubTypes = ChopSubTypes(regtype, &AnonData); // Note: Modifies regtype string to remove trailing subtypes if (NumSubTypes < 0 || NumSubTypes > 1) @@ -2800,7 +2821,7 @@ mDNSlocal mStatus handle_resolve_request(request_state *request) // If it's one of the specially defined inteface index values, just return an error. if (PreDefinedInterfaceIndex(interfaceIndex)) { - LogMsg("ERROR: handle_resolve_request: bad interfaceIndex %d", interfaceIndex); + LogInfo("handle_resolve_request: bad interfaceIndex %d", interfaceIndex); return(mStatus_BadParamErr); } @@ -2823,6 +2844,7 @@ mDNSlocal mStatus handle_resolve_request(request_state *request) mDNSPlatformMemZero(&request->u.resolve, sizeof(request->u.resolve)); request->flags = flags; + request->interfaceIndex = interfaceIndex; // format questions request->u.resolve.qsrv.InterfaceID = InterfaceID; @@ -2850,6 +2872,7 @@ mDNSlocal mStatus handle_resolve_request(request_state *request) request->u.resolve.qsrv.qnameOrig = mDNSNULL; request->u.resolve.qsrv.AnonInfo = mDNSNULL; request->u.resolve.qsrv.pid = request->process_id; + request->u.resolve.qsrv.euid = request->uid; request->u.resolve.qsrv.QuestionCallback = resolve_result_callback; request->u.resolve.qsrv.QuestionContext = request; @@ -2878,6 +2901,7 @@ mDNSlocal mStatus handle_resolve_request(request_state *request) request->u.resolve.qtxt.qnameOrig = mDNSNULL; request->u.resolve.qtxt.AnonInfo = mDNSNULL; request->u.resolve.qtxt.pid = request->process_id; + request->u.resolve.qtxt.euid = request->uid; request->u.resolve.qtxt.QuestionCallback = resolve_result_callback; request->u.resolve.qtxt.QuestionContext = request; @@ -3163,6 +3187,7 @@ mDNSlocal mStatus SendAdditionalQuery(DNSQuestion *q, request_state *request, mS q2->TimeoutQuestion = 0; q2->AnonInfo = mDNSNULL; q2->pid = request->process_id; + q2->euid = request->uid; } LogOperation("%3d: DNSServiceQueryRecord(%##s, %s) unicast", request->sd, q2->qname.c, DNSTypeName(q2->qtype)); err = mDNS_StartQuery(&mDNSStorage, q2); @@ -3342,15 +3367,16 @@ mDNSlocal void queryrecord_result_reply(mDNS *const m, request_state *req, DNSQu (x.cr_version == XUCRED_VERSION)) { struct sockaddr_storage addr; - const RDataBody2 *const rdb = (RDataBody2 *)answer->rdata->u.data; addr.ss_len = 0; if (answer->rrtype == kDNSType_A || answer->rrtype == kDNSType_AAAA) { if (answer->rrtype == kDNSType_A) { - struct sockaddr_in *sin = (struct sockaddr_in *)&addr; + struct sockaddr_in *const sin = (struct sockaddr_in *)&addr; sin->sin_port = 0; - if (!putRData(mDNSNULL, (mDNSu8 *)&sin->sin_addr, (mDNSu8 *)(&sin->sin_addr + sizeof(rdb->ipv4)), answer)) + // Instead of this stupid call to putRData it would be much simpler to just assign the value in the sensible way, like this: + // sin->sin_addr.s_addr = answer->rdata->u.ipv4.NotAnInteger; + if (!putRData(mDNSNULL, (mDNSu8 *)&sin->sin_addr, (mDNSu8 *)(&sin->sin_addr + sizeof(mDNSv4Addr)), answer)) LogMsg("queryrecord_result_reply: WCF AF_INET putRData failed"); else { @@ -3360,9 +3386,14 @@ mDNSlocal void queryrecord_result_reply(mDNS *const m, request_state *req, DNSQu } else if (answer->rrtype == kDNSType_AAAA) { - struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&addr; + struct sockaddr_in6 *const sin6 = (struct sockaddr_in6 *)&addr; sin6->sin6_port = 0; - if (!putRData(mDNSNULL, (mDNSu8 *)&sin6->sin6_addr, (mDNSu8 *)(&sin6->sin6_addr + sizeof(rdb->ipv6)), answer)) + // Instead of this stupid call to putRData it would be much simpler to just assign the value in the sensible way, like this: + // sin6->sin6_addr.__u6_addr.__u6_addr32[0] = answer->rdata->u.ipv6.l[0]; + // sin6->sin6_addr.__u6_addr.__u6_addr32[1] = answer->rdata->u.ipv6.l[1]; + // sin6->sin6_addr.__u6_addr.__u6_addr32[2] = answer->rdata->u.ipv6.l[2]; + // sin6->sin6_addr.__u6_addr.__u6_addr32[3] = answer->rdata->u.ipv6.l[3]; + if (!putRData(mDNSNULL, (mDNSu8 *)&sin6->sin6_addr, (mDNSu8 *)(&sin6->sin6_addr + sizeof(mDNSv6Addr)), answer)) LogMsg("queryrecord_result_reply: WCF AF_INET6 putRData failed"); else { @@ -3658,7 +3689,7 @@ mDNSlocal void queryrecord_termination_callback(request_state *request) mDNSlocal void SetQuestionPolicy(DNSQuestion *q, request_state *req) { int i; - + 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 @@ -3681,6 +3712,8 @@ mDNSlocal void SetQuestionPolicy(DNSQuestion *q, request_state *req) { q->pid = req->process_id; } + + //debugf("SetQuestionPolicy: q->euid[%d] q->pid[%d] uuid is valid : %s", q->euid, q->pid, req->validUUID ? "true" : "false"); } mDNSlocal mStatus handle_queryrecord_request(request_state *request) @@ -3699,9 +3732,11 @@ mDNSlocal mStatus handle_queryrecord_request(request_state *request) if (interfaceIndex && !InterfaceID) { // If it's one of the specially defined inteface index values, just return an error. - if (PreDefinedInterfaceIndex(interfaceIndex)) + // 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) { - LogMsg("ERROR: handle_queryrecord_request: bad interfaceIndex %d", interfaceIndex); + LogInfo("handle_queryrecord_request: bad interfaceIndex %d", interfaceIndex); return(mStatus_BadParamErr); } @@ -3719,6 +3754,7 @@ mDNSlocal mStatus handle_queryrecord_request(request_state *request) { LogMsg("%3d: DNSServiceQueryRecord(unreadable parameters)", request->sd); return(mStatus_BadParamErr); } request->flags = flags; + request->interfaceIndex = interfaceIndex; mDNSPlatformMemZero(&request->u.queryrecord, sizeof(request->u.queryrecord)); q->InterfaceID = InterfaceID; @@ -3788,12 +3824,14 @@ mDNSlocal mStatus handle_queryrecord_request(request_state *request) q->qnameOrig = mDNSNULL; SetQuestionPolicy(q, request); - LogOperation("%3d: DNSServiceQueryRecord(%X, %d, %##s, %s) START PID[%d](%s)", + LogOperation("%3d: DNSServiceQueryRecord(%X, %d, %##s, %s) START PID[%d](%s)", request->sd, flags, interfaceIndex, q->qname.c, DNSTypeName(q->qtype), request->process_id, request->pid_name); err = mDNS_StartQuery(&mDNSStorage, q); - if (err) + if (err) + { LogMsg("%3d: ERROR: DNSServiceQueryRecord %##s %s mDNS_StartQuery: %d", request->sd, q->qname.c, DNSTypeName(q->qtype), (int)err); + } else { request->terminate = queryrecord_termination_callback; @@ -3907,6 +3945,9 @@ mDNSlocal mStatus handle_enum_request(request_state *request) if (!request->msgptr) { LogMsg("%3d: DNSServiceEnumerateDomains(unreadable parameters)", request->sd); return(mStatus_BadParamErr); } + request->flags = flags; + request->interfaceIndex = interfaceIndex; + // mark which kind of enumeration we're doing so that we know what domain enumeration queries to stop request->u.enumeration.flags = reg; @@ -4080,7 +4121,7 @@ mDNSlocal void handle_connection_delegate_request(request_state *request) if (proc_pidinfo(request->process_id, PROC_PIDT_SHORTBSDINFO, 1, &proc, PROC_PIDT_SHORTBSDINFO_SIZE) == 0) return; mDNSPlatformStrCopy(request->pid_name, proc.pbsi_comm); - //LogMsg("handle_connection_delegate_request: process id %d, name %s", request->process_id, request->pid_name); + debugf("handle_connection_delegate_request: process id %d, name %s", request->process_id, request->pid_name); } #endif #ifdef LOCAL_PEEREUUID @@ -4114,7 +4155,7 @@ mDNSlocal void handle_getpid_request(request_state *request) const DNSQuestion *q = NULL; PIDInfo pi; - LogOperation("%3d: DNSServiceGetPID START", request->sd); + LogMsg("%3d: DNSServiceGetPID START", request->sd); for (req = all_requests; req; req=req->next) { @@ -4131,7 +4172,7 @@ mDNSlocal void handle_getpid_request(request_state *request) if (port == srcport) { pid = req->process_id; - LogInfo("DNSServiceGetPID: srcport %d, pid %d [%s] question %##s", htons(srcport), pid, req->pid_name, q->qname.c); + LogMsg("DNSServiceGetPID: srcport %d, pid %d [%s] question %##s", htons(srcport), pid, req->pid_name, q->qname.c); break; } } @@ -4150,7 +4191,7 @@ mDNSlocal void handle_getpid_request(request_state *request) #if APPLE_OSX_mDNSResponder pid = getpid(); #endif // APPLE_OSX_mDNSResponder - LogInfo("DNSServiceGetPID: srcport %d, pid %d [%s], question %##s", htons(srcport), pid, "_mDNSResponder", q->qname.c); + LogMsg("DNSServiceGetPID: srcport %d, pid %d [%s], question %##s", htons(srcport), pid, "_mDNSResponder", q->qname.c); break; } } @@ -4160,7 +4201,7 @@ mDNSlocal void handle_getpid_request(request_state *request) pi.err = 0; pi.pid = pid; send_all(request->sd, (const char *)&pi, sizeof(PIDInfo)); - LogOperation("%3d: DNSServiceGetPID STOP", request->sd); + LogMsg("%3d: DNSServiceGetPID STOP", request->sd); } // *************************************************************************** @@ -4258,6 +4299,8 @@ mDNSlocal mStatus handle_port_mapping_request(request_state *request) if (!(protocol & (kDNSServiceProtocol_UDP | kDNSServiceProtocol_TCP))) return(mStatus_BadParamErr); } + request->flags = flags; + request->interfaceIndex = interfaceIndex; request->u.pm.NATinfo.Protocol = !protocol ? NATOp_AddrRequest : (protocol == kDNSServiceProtocol_UDP) ? NATOp_MapUDP : NATOp_MapTCP; // u.pm.NATinfo.IntPort = already set above request->u.pm.NATinfo.RequestedPort = request->u.pm.ReqExt; @@ -4381,6 +4424,7 @@ mDNSlocal mStatus handle_addrinfo_request(request_state *request) domainname d; mStatus err = 0; mDNSs32 serviceIndex = -1; // default unscoped value for ServiceID is -1 + mDNSInterfaceID InterfaceID; DNSServiceFlags flags = get_flags(&request->msgptr, request->msgend); @@ -4398,7 +4442,7 @@ mDNSlocal mStatus handle_addrinfo_request(request_state *request) mDNSPlatformMemZero(&request->u.addrinfo, sizeof(request->u.addrinfo)); - mDNSInterfaceID InterfaceID = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex); + InterfaceID = mDNSPlatformInterfaceIDfromInterfaceIndex(&mDNSStorage, interfaceIndex); // The request is scoped to a specific interface index, but the // interface is not currently in our list. @@ -4407,7 +4451,7 @@ mDNSlocal mStatus handle_addrinfo_request(request_state *request) // If it's one of the specially defined inteface index values, just return an error. if (PreDefinedInterfaceIndex(interfaceIndex)) { - LogMsg("ERROR: handle_addrinfo_request: bad interfaceIndex %d", interfaceIndex); + LogInfo("handle_addrinfo_request: bad interfaceIndex %d", interfaceIndex); return(mStatus_BadParamErr); } @@ -4416,6 +4460,9 @@ mDNSlocal mStatus handle_addrinfo_request(request_state *request) InterfaceID = (mDNSInterfaceID)(uintptr_t)interfaceIndex; LogInfo("handle_addrinfo_request: query pending for interface index %d", interfaceIndex); } + + request->flags = flags; + request->interfaceIndex = interfaceIndex; request->u.addrinfo.interface_id = InterfaceID; request->u.addrinfo.flags = flags; request->u.addrinfo.protocol = get_uint32(&request->msgptr, request->msgend); @@ -4554,8 +4601,7 @@ mDNSlocal mStatus handle_addrinfo_request(request_state *request) } } - 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); + 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); return(err); } @@ -4660,12 +4706,10 @@ mDNSlocal void read_msg(request_state *req) #if !defined(_WIN32) cmsg = CMSG_FIRSTHDR(&msg); #if DEBUG_64BIT_SCM_RIGHTS - LogMsg("%3d: Expecting %d %d %d %d", req->sd, sizeof(cbuf), sizeof(cbuf), SOL_SOCKET, SCM_RIGHTS); - LogMsg("%3d: Got %d %d %d %d", req->sd, msg.msg_controllen, cmsg->cmsg_len, cmsg->cmsg_level, cmsg->cmsg_type); + LogMsg("%3d: Expecting %d %d %d %d", req->sd, sizeof(cbuf), sizeof(cbuf), SOL_SOCKET, SCM_RIGHTS); + LogMsg("%3d: Got %d %d %d %d", req->sd, msg.msg_controllen, cmsg ? cmsg->cmsg_len : -1, cmsg ? cmsg->cmsg_level : -1, cmsg ? cmsg->cmsg_type : -1); #endif // DEBUG_64BIT_SCM_RIGHTS - if (msg.msg_controllen != 0 && - cmsg->cmsg_level == SOL_SOCKET && - cmsg->cmsg_type == SCM_RIGHTS) + if (cmsg && cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) { #if APPLE_OSX_mDNSResponder // Strictly speaking BPF_fd belongs solely in the platform support layer, but because @@ -4685,7 +4729,7 @@ mDNSlocal void read_msg(request_state *req) #endif // DEBUG_64BIT_SCM_RIGHTS if (req->data_bytes < req->hdr.datalen) { - LogMsg("%3d: Client(PID [%d](%s)) sent error socket %d via SCM_RIGHTS with req->data_bytes %d < req->hdr.datalen %d", + LogMsg("%3d: Client(PID [%d](%s)) sent result code socket %d via SCM_RIGHTS with req->data_bytes %d < req->hdr.datalen %d", req->sd, req->process_id, req->pid_name, req->errsd, req->data_bytes, req->hdr.datalen); req->ts = t_error; return; @@ -4752,7 +4796,7 @@ mDNSlocal void read_msg(request_state *req) #if !defined(USE_TCP_LOOPBACK) got_errfd: #endif - LogOperation("%3d: Error socket %d created %08X %08X", req->sd, req->errsd, req->hdr.client_context.u32[1], req->hdr.client_context.u32[0]); + LogOperation("%3d: Result code socket %d created %08X %08X", req->sd, req->errsd, req->hdr.client_context.u32[1], req->hdr.client_context.u32[0]); #if defined(_WIN32) if (ioctlsocket(req->errsd, FIONBIO, &opt) != 0) #else @@ -4857,9 +4901,6 @@ mDNSlocal void request_callback(int fd, short filter, void *info) return; } - // check if client wants silent operation - if (req->hdr.ipc_flags & IPC_FLAGS_NOREPLY) req->no_reply = 1; - // If req->terminate is already set, this means this operation is sharing an existing connection if (req->terminate && !LightweightOp(req->hdr.op)) { @@ -4897,6 +4938,9 @@ mDNSlocal void request_callback(int fd, short filter, void *info) req = newreq; } + // Check if the request wants no asynchronous replies. + if (req->hdr.ipc_flags & IPC_FLAGS_NOREPLY) req->no_reply = 1; + // If we're shutting down, don't allow new client requests // We do allow "cancel" and "getproperty" during shutdown if (mDNSStorage.ShutdownTime && req->hdr.op != cancel_request && req->hdr.op != getproperty_request) @@ -4954,7 +4998,7 @@ mDNSlocal void request_callback(int fd, short filter, void *info) send_all(req->errsd, (const char *)&err_netorder, sizeof(err_netorder)); if (req->errsd != req->sd) { - LogOperation("%3d: Error socket %d closed %08X %08X (%d)", + LogOperation("%3d: Result code socket %d closed %08X %08X (%d)", req->sd, req->errsd, req->hdr.client_context.u32[1], req->hdr.client_context.u32[0], err); dnssd_close(req->errsd); req->errsd = req->sd; @@ -5019,11 +5063,14 @@ mDNSlocal void connect_callback(int fd, short filter, void *info) #if APPLE_OSX_mDNSResponder struct xucred x; socklen_t xucredlen = sizeof(x); - if (getsockopt(sd, 0, LOCAL_PEERCRED, &x, &xucredlen) >= 0 && x.cr_version == XUCRED_VERSION) request->uid = x.cr_uid; - else my_perror("ERROR: getsockopt, LOCAL_PEERCRED"); + if (getsockopt(sd, 0, LOCAL_PEERCRED, &x, &xucredlen) >= 0 && x.cr_version == XUCRED_VERSION) + request->uid = x.cr_uid; // save the effective userid of the client + else + my_perror("ERROR: getsockopt, LOCAL_PEERCRED"); + debugf("LOCAL_PEERCRED %d %u %u %d", xucredlen, x.cr_version, x.cr_uid, x.cr_ngroups); #endif // APPLE_OSX_mDNSResponder - LogOperation("%3d: Adding FD for uid %u", request->sd, request->uid); + LogOperation("%3d: connect_callback: Adding FD for uid %u", request->sd, request->uid); udsSupportAddFDToEventLoop(sd, request_callback, request, &request->platform_data); } } @@ -5064,7 +5111,7 @@ mDNSlocal mDNSBool uds_socket_setup(dnssd_sock_t skt) } else { - LogMsg("%3d: Listening for incoming Unix Domain Socket client requests", skt); + LogOperation("%3d: Listening for incoming Unix Domain Socket client requests", skt); mDNSStorage.uds_listener_skt = skt; } return mDNStrue; @@ -5244,8 +5291,8 @@ mDNSlocal void LogClientInfo(mDNS *const m, request_state *req) prefix, num_records, num_records != 1 ? "s" : "", num_ops, num_ops != 1 ? "s" : "", req->process_id, req->pid_name); for (p = req->u.reg_recs; p; p=p->next) - LogMsgNoIdent(" -> DNSServiceRegisterRecord %3d %s PID[%d](%s)", p->key, ARDisplayString(m, p->rr), - req->process_id, req->pid_name); + LogMsgNoIdent(" -> DNSServiceRegisterRecord 0x%08X %2d %3d %s PID[%d](%s)", + req->flags, req->interfaceIndex, p->key, ARDisplayString(m, p->rr), req->process_id, req->pid_name); for (r = req->next; r; r=r->next) if (r->primary == req) LogClientInfo(m, r); } else if (req->terminate == regservice_termination_callback) @@ -5253,32 +5300,34 @@ mDNSlocal void LogClientInfo(mDNS *const m, request_state *req) service_instance *ptr; char anonstr[256]; for (ptr = req->u.servicereg.instances; ptr; ptr = ptr->next) - LogMsgNoIdent("%s DNSServiceRegister %##s%s %u/%u PID[%d](%s)", - (ptr == req->u.servicereg.instances) ? prefix : " ", ptr->srs.RR_SRV.resrec.name->c, - AnonDataToString(ptr->srs.AnonData, 0, anonstr, sizeof(anonstr)), mDNSVal16(req->u.servicereg.port), - SRS_PORT(&ptr->srs), req->process_id, req->pid_name); + LogMsgNoIdent("%s DNSServiceRegister 0x%08X %2d %##s%s %u/%u PID[%d](%s)", + (ptr == req->u.servicereg.instances) ? prefix : " ", req->flags, req->interfaceIndex, ptr->srs.RR_SRV.resrec.name->c, + AnonDataToString(ptr->srs.AnonData, 0, anonstr, sizeof(anonstr)), mDNSVal16(req->u.servicereg.port), + SRS_PORT(&ptr->srs), req->process_id, req->pid_name); } else if (req->terminate == browse_termination_callback) { browser_t *blist; char anonstr[256]; for (blist = req->u.browser.browsers; blist; blist = blist->next) - LogMsgNoIdent("%s DNSServiceBrowse %##s%s PID[%d](%s)", - (blist == req->u.browser.browsers) ? prefix : " ",blist->q.qname.c, - AnonDataToString(req->u.browser.AnonData, 0, anonstr, sizeof(anonstr)), req->process_id, req->pid_name); + LogMsgNoIdent("%s DNSServiceBrowse 0x%08X %2d %##s%s PID[%d](%s)", + (blist == req->u.browser.browsers) ? prefix : " ", req->flags, req->interfaceIndex, blist->q.qname.c, + AnonDataToString(req->u.browser.AnonData, 0, anonstr, sizeof(anonstr)), req->process_id, req->pid_name); } else if (req->terminate == resolve_termination_callback) - LogMsgNoIdent("%s DNSServiceResolve %##s PID[%d](%s)", - prefix, req->u.resolve.qsrv.qname.c, req->process_id, req->pid_name); + LogMsgNoIdent("%s DNSServiceResolve 0x%08X %2d %##s PID[%d](%s)", + prefix, req->flags, req->interfaceIndex, req->u.resolve.qsrv.qname.c, req->process_id, req->pid_name); else if (req->terminate == queryrecord_termination_callback) - LogMsgNoIdent("%s DNSServiceQueryRecord %##s (%s) PID[%d](%s)", - prefix, req->u.queryrecord.q.qname.c, DNSTypeName(req->u.queryrecord.q.qtype), req->process_id, req->pid_name); + LogMsgNoIdent("%s DNSServiceQueryRecord 0x%08X %2d %##s (%s) PID[%d](%s)", + prefix, req->flags, req->interfaceIndex, req->u.queryrecord.q.qname.c, DNSTypeName(req->u.queryrecord.q.qtype), req->process_id, req->pid_name); else if (req->terminate == enum_termination_callback) - LogMsgNoIdent("%s DNSServiceEnumerateDomains %##s PID[%d](%s)", prefix, req->u.enumeration.q_all.qname.c, - req->process_id, req->pid_name); + LogMsgNoIdent("%s DNSServiceEnumerateDomains 0x%08X %2d %##s PID[%d](%s)", + prefix, req->flags, req->interfaceIndex, req->u.enumeration.q_all.qname.c, req->process_id, req->pid_name); else if (req->terminate == port_mapping_termination_callback) - LogMsgNoIdent("%s DNSServiceNATPortMapping %s%s Int %5d Req %5d Ext %.4a:%5d Req TTL %5d Granted TTL %5d PID[%d](%s)", + LogMsgNoIdent("%s DNSServiceNATPortMapping 0x%08X %2d %s%s Int %5d Req %5d Ext %.4a:%5d Req TTL %5d Granted TTL %5d PID[%d](%s)", prefix, + req->flags, + req->interfaceIndex, req->u.pm.NATinfo.Protocol & NATOp_MapTCP ? "TCP" : " ", req->u.pm.NATinfo.Protocol & NATOp_MapUDP ? "UDP" : " ", mDNSVal16(req->u.pm.NATinfo.IntPort), @@ -5289,7 +5338,8 @@ mDNSlocal void LogClientInfo(mDNS *const m, request_state *req) req->u.pm.NATinfo.Lifetime, req->process_id, req->pid_name); else if (req->terminate == addrinfo_termination_callback) - LogMsgNoIdent("%s DNSServiceGetAddrInfo %s%s %##s PID[%d](%s)", prefix, + LogMsgNoIdent("%s DNSServiceGetAddrInfo 0x%08X %2d %s%s %##s PID[%d](%s)", + prefix, req->flags, req->interfaceIndex, req->u.addrinfo.protocol & kDNSServiceProtocol_IPv4 ? "v4" : " ", req->u.addrinfo.protocol & kDNSServiceProtocol_IPv6 ? "v6" : " ", req->u.addrinfo.q4.qname.c, req->process_id, req->pid_name); @@ -5523,19 +5573,22 @@ mDNSlocal void LogOneAuthRecord(mDNS *const m, const AuthRecord *ar, mDNSs32 now char anstr[256]; if (AuthRecord_uDNS(ar)) { - LogMsgNoIdent("%7d %7d %7d %7d %s", + LogMsgNoIdent("%7d %7d %7d %7d %s %s", ar->ThisAPInterval / mDNSPlatformOneSecond, (ar->LastAPTime + ar->ThisAPInterval - now) / mDNSPlatformOneSecond, ar->expire ? (ar->expire - now) / mDNSPlatformOneSecond : 0, - ar->state, ARDisplayString(m, ar)); + ar->state, + ar->AllowRemoteQuery ? "☠" : " ", + ARDisplayString(m, ar)); } else { - LogMsgNoIdent("%7d %7d %7d %7s %s%s", + LogMsgNoIdent("%7d %7d %7d %7s %s %s%s", ar->ThisAPInterval / mDNSPlatformOneSecond, ar->AnnounceCount ? (ar->LastAPTime + ar->ThisAPInterval - now) / mDNSPlatformOneSecond : 0, ar->TimeExpire ? (ar->TimeExpire - now) / mDNSPlatformOneSecond : 0, ifname ? ifname : "ALL", + ar->AllowRemoteQuery ? "☠" : " ", ARDisplayString(m, ar), AnonInfoToString(ar->resrec.AnonInfo, anstr, sizeof(anstr))); } } @@ -5988,11 +6041,8 @@ foundparent:; LogMsgNoIdent("m->WABBrowseQueriesCount %d", m->WABBrowseQueriesCount); LogMsgNoIdent("m->WABLBrowseQueriesCount %d", m->WABLBrowseQueriesCount); LogMsgNoIdent("m->WABRegQueriesCount %d", m->WABRegQueriesCount); - LogMsgNoIdent("m->mDNSOppCaching %d", m->mDNSOppCaching); LogMsgNoIdent("m->AutoTargetServices %d", m->AutoTargetServices); -#define LogTimer(MSG,T) LogMsgNoIdent( MSG " %08X %11d %08X %11d", (T), (T), (T)-now, (T)-now) - LogMsgNoIdent(" ABS (hex) ABS (dec) REL (hex) REL (dec)"); LogMsgNoIdent("m->timenow %08X %11d", now, now); LogMsgNoIdent("m->timenow_adjust %08X %11d", m->timenow_adjust, m->timenow_adjust); @@ -6097,7 +6147,6 @@ mDNSlocal int send_msg(request_state *const req) { reply_state *const rep = req->replies; // Send the first waiting reply ssize_t nwriten; - if (req->no_reply) return(t_complete); ConvertHeaderBytes(rep->mhdr); nwriten = send(req->sd, (char *)&rep->mhdr + rep->nwriten, rep->totallen - rep->nwriten, 0); @@ -6159,7 +6208,7 @@ mDNSexport mDNSs32 udsserver_idle(mDNSs32 nextevent) } else if (result == t_terminated || result == t_error) { - LogMsg("%3d: Could not write data to clientPID[%d](%s) because of error - aborting connection", r->sd, r->process_id, r->pid_name); + LogMsg("%3d: Could not write data to client PID[%d](%s) because of error - aborting connection", r->sd, r->process_id, r->pid_name); LogClientInfo(&mDNSStorage, r); abort_request(r); } @@ -6215,7 +6264,7 @@ struct CompileTimeAssertionChecks_uds_daemon char sizecheck_request_state [(sizeof(request_state) <= 2000) ? 1 : -1]; char sizecheck_registered_record_entry[(sizeof(registered_record_entry) <= 60) ? 1 : -1]; char sizecheck_service_instance [(sizeof(service_instance) <= 6552) ? 1 : -1]; - char sizecheck_browser_t [(sizeof(browser_t) <= 1096) ? 1 : -1]; + char sizecheck_browser_t [(sizeof(browser_t) <= 1128) ? 1 : -1]; char sizecheck_reply_hdr [(sizeof(reply_hdr) <= 12) ? 1 : -1]; char sizecheck_reply_state [(sizeof(reply_state) <= 64) ? 1 : -1]; }; diff --git a/mDNSResponder/mDNSShared/uds_daemon.h b/mDNSResponder/mDNSShared/uds_daemon.h index ca361172..6cc9197d 100644 --- a/mDNSResponder/mDNSShared/uds_daemon.h +++ b/mDNSResponder/mDNSShared/uds_daemon.h @@ -1,6 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- * - * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2002-2013 Apple Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,13 +13,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - - File: uds_daemon.h - - Contains: Interfaces necessary to talk to uds_daemon.c. - - Version: 1.0 - */ #include "mDNSEmbeddedAPI.h" @@ -29,6 +22,8 @@ #define SRS_PORT(S) mDNSVal16((S)->RR_SRV.resrec.rdata->u.srv.port) +#define LogTimer(MSG,T) LogMsgNoIdent( MSG " %08X %11d %08X %11d", (T), (T), (T)-now, (T)-now) + extern int udsserver_init(dnssd_sock_t skts[], mDNSu32 count); extern mDNSs32 udsserver_idle(mDNSs32 nextevent); extern void udsserver_info(mDNS *const m); // print out info about current state |