<rdar://problem/7252936> Add a new Services tab to control panel that lets you enable...
authorsherscher@apple.com <sherscher@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Mon, 28 Sep 2009 19:09:35 +0000 (19:09 +0000)
committersherscher@apple.com <sherscher@apple.com@214c2c4a-bf3b-4dcf-9390-e4dd3010487d>
Mon, 28 Sep 2009 19:09:35 +0000 (19:09 +0000)
git-svn-id: http://svn.macosforge.org/repository/mDNSResponder/trunk@6706 214c2c4a-bf3b-4dcf-9390-e4dd3010487d

mDNSWindows/RegNames.h
mDNSWindows/SystemService/Service.c
mDNSWindows/mDNSWin32.c

index 41a14ab..bc885d6 100644 (file)
@@ -35,6 +35,7 @@
 #      define kServiceManageLLRouting                          L"ManageLLRouting"
 #      define kServiceCacheEntryCount                          L"CacheEntryCount"
 #      define kServiceManageFirewall                           L"ManageFirewall"
+#      define kServiceAdvertisedServices                       L"Services"
 
 # else
 
index 35fed7e..af6347f 100644 (file)
@@ -102,9 +102,10 @@ static int                                                                                 gEventSources = 0;
 #define kWaitListDynDNSEvent                                           ( WAIT_OBJECT_0 + 4 )
 #define kWaitListFileShareEvent                                                ( WAIT_OBJECT_0 + 5 )
 #define kWaitListFirewallEvent                                         ( WAIT_OBJECT_0 + 6 )
-#define kWaitListSPSWakeupEvent                                                ( WAIT_OBJECT_0 + 7 )
-#define kWaitListSPSSleepEvent                                         ( WAIT_OBJECT_0 + 8 )
-#define        kWaitListFixedItemCount                                         9
+#define kWaitListAdvertisedServicesEvent                       ( WAIT_OBJECT_0 + 7 )
+#define kWaitListSPSWakeupEvent                                                ( WAIT_OBJECT_0 + 8 )
+#define kWaitListSPSSleepEvent                                         ( WAIT_OBJECT_0 + 9 )
+#define        kWaitListFixedItemCount                                         10
 
 
 #if 0
@@ -197,6 +198,8 @@ DEBUG_LOCAL HKEY                                            gFileSharingKey                         = NULL;
 DEBUG_LOCAL HANDLE                                             gFileSharingChangedEvent        = NULL; // File Sharing changed
 DEBUG_LOCAL HKEY                                               gFirewallKey                            = NULL;
 DEBUG_LOCAL HANDLE                                             gFirewallChangedEvent           = NULL; // Firewall changed
+DEBUG_LOCAL HKEY                                               gAdvertisedServicesKey          = NULL;
+DEBUG_LOCAL HANDLE                                             gAdvertisedServicesChangedEvent = NULL; // Advertised services changed
 DEBUG_LOCAL SERVICE_STATUS                             gServiceStatus;
 DEBUG_LOCAL SERVICE_STATUS_HANDLE              gServiceStatusHandle    = NULL;
 DEBUG_LOCAL HANDLE                                             gServiceEventSource             = NULL;
@@ -1392,6 +1395,21 @@ static OSStatus  ServiceSpecificRun( int argc, LPTSTR argv[] )
                                                check_noerr( err );
                                        }
                                }
+                               else if ( result == kWaitListAdvertisedServicesEvent )
+                               {
+                                       // Ultimately we'll want to manage multiple services, but right now the only service
+                                       // we'll be managing is SMB.
+
+                                       FileSharingDidChange( &gMDNSRecord );
+
+                                       // and reset the event handler
+
+                                       if ( ( gAdvertisedServicesKey != NULL ) && ( gAdvertisedServicesChangedEvent ) )
+                                       {
+                                               err = RegNotifyChangeKeyValue(gAdvertisedServicesKey, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, gAdvertisedServicesChangedEvent, TRUE);
+                                               check_noerr( err );
+                                       }
+                               }
                                else if ( result == kWaitListSPSWakeupEvent )
                                {
                                        __int64         temp;\r
@@ -1642,10 +1660,20 @@ mDNSlocal mStatus       SetupNotifications()
        require_noerr( err, exit );
 
        err = RegCreateKey( HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Services\\lanmanserver\\Shares"), &gFileSharingKey );
-       require_noerr( err, exit );
+       
+       // Just to make sure that initialization doesn't fail on some old OS
+       // that doesn't have this key, we'll only add the notification if
+       // the key exists.
 
-       err = RegNotifyChangeKeyValue( gFileSharingKey, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, gFileSharingChangedEvent, TRUE);
-       require_noerr( err, exit );
+       if ( !err )
+       {
+               err = RegNotifyChangeKeyValue( gFileSharingKey, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, gFileSharingChangedEvent, TRUE);
+               require_noerr( err, exit );
+       }
+       else
+       {
+               err = mStatus_NoError;
+       }
 
        // This will catch changes to the Windows firewall
 
@@ -1669,6 +1697,18 @@ mDNSlocal mStatus        SetupNotifications()
                err = mStatus_NoError;
        }
 
+       // This will catch all changes to advertised services configuration
+
+       gAdvertisedServicesChangedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
+       err = translate_errno( gAdvertisedServicesChangedEvent, (mStatus) GetLastError(), kUnknownErr );
+       require_noerr( err, exit );
+
+       err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode TEXT("\\Services"), &gAdvertisedServicesKey );
+       require_noerr( err, exit );
+
+       err = RegNotifyChangeKeyValue( gAdvertisedServicesKey, TRUE, REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_LAST_SET, gAdvertisedServicesChangedEvent, TRUE);
+       require_noerr( err, exit );
+
        gSPSWakeupEvent = CreateWaitableTimer( NULL, FALSE, NULL );
        err = translate_errno( gSPSWakeupEvent, (mStatus) GetLastError(), kUnknownErr );
        require_noerr( err, exit );
@@ -1767,6 +1807,18 @@ mDNSlocal mStatus        TearDownNotifications()
                gFirewallKey = NULL;
        }
 
+       if ( gAdvertisedServicesChangedEvent != NULL )
+       {
+               CloseHandle( gAdvertisedServicesChangedEvent );
+               gAdvertisedServicesChangedEvent = NULL;
+       }
+
+       if ( gAdvertisedServicesKey != NULL )
+       {
+               RegCloseKey( gAdvertisedServicesKey );
+               gAdvertisedServicesKey = NULL;
+       }
+
        if ( gSPSWakeupEvent )
        {
                CloseHandle( gSPSWakeupEvent );
@@ -1897,6 +1949,7 @@ mDNSlocal mStatus SetupWaitList( mDNS * const inMDNS, HANDLE **outWaitList, int
        *waitItemPtr++  =       gDdnsChangedEvent;
        *waitItemPtr++  =       gFileSharingChangedEvent;
        *waitItemPtr++  =       gFirewallChangedEvent;
+       *waitItemPtr++  =       gAdvertisedServicesChangedEvent;
        *waitItemPtr++  =       gSPSWakeupEvent;
        *waitItemPtr++  =       gSPSSleepEvent;
 
index 4eb14b6..a3097fe 100755 (executable)
@@ -4525,17 +4525,29 @@ CheckFileShares( mDNS * const m )
        DWORD                   entriesRead = 0;
        DWORD                   totalEntries = 0;
        DWORD                   resume = 0;
+       mDNSBool                advertise = mDNSfalse;
        mDNSBool                fileSharing = mDNSfalse;
        mDNSBool                printSharing = mDNSfalse;
        mDNSu8                  txtBuf[ 256 ];
        mDNSu8          *       txtPtr;
        size_t                  keyLen;
        size_t                  valLen;
+       HKEY                    key = NULL;
        NET_API_STATUS  res;
        mStatus                 err;
 
        check( m );
 
+       err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\Services\\SMB", &key );
+
+       if ( !err )
+       {
+               DWORD dwSize;
+
+               dwSize = sizeof( DWORD );
+               RegQueryValueEx( key, L"Advertise", NULL, NULL, (LPBYTE) &advertise, &dwSize );
+       }
+
        // We only want to enter this routine if either we haven't called mDNS_RegisterService()
        // or we called mDNS_DeregisterService() and our callback was invoked and told
        // that our service has been fully deregistered.
@@ -4582,7 +4594,7 @@ CheckFileShares( mDNS * const m )
                        }
                }
                
-               if ( !m->p->smbRegistered && fileSharing )
+               if ( !m->p->smbRegistered && advertise && fileSharing )
                {
                        domainname              type;
                        domainname              domain;
@@ -4639,7 +4651,7 @@ CheckFileShares( mDNS * const m )
                        m->p->smbFileSharing    = fileSharing;
                        m->p->smbPrintSharing   = printSharing;
                }
-               else if ( m->p->smbRegistered && ( ( m->p->smbFileSharing != fileSharing ) || ( m->p->smbPrintSharing != printSharing ) ) )
+               else if ( m->p->smbRegistered && ( !advertise || ( ( m->p->smbFileSharing != fileSharing ) || ( m->p->smbPrintSharing != printSharing ) ) ) )
                {
                        dlog( kDebugLevelTrace, DEBUG_NAME "deregistering smb type\n" );
                        
@@ -4655,7 +4667,10 @@ CheckFileShares( mDNS * const m )
 
 exit:
 
-       return;
+       if ( key )
+       {
+               RegCloseKey( key );
+       }
 }