]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/DLL/dllmain.c
mDNSResponder-108.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / DLL / dllmain.c
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: dllmain.c,v $
26 Revision 1.3 2005/07/07 19:18:29 shersche
27 Fix error in previous checkin, change SystemServiceIsDisabled() to IsSystemServiceDisabled()
28
29 Revision 1.2 2005/06/30 17:55:35 shersche
30 <rdar://problem/4096913> Implement ISSystemServiceDisabled(). This is used to determine how long we should wait to connect to the system service.
31
32 Revision 1.1 2004/06/18 03:55:11 rpantos
33 Move DLL up to main level; additional integration from Scott.
34
35 Revision 1.1 2004/02/21 04:16:50 bradley
36 DLL wrapper for DNS-SD API.
37
38 */
39
40 #include <windows.h>
41 #include <DebugServices.h>
42
43 BOOL APIENTRY DllMain( HANDLE inModule, DWORD inReason, LPVOID inReserved )
44 {
45 (void) inModule;
46 (void) inReserved;
47
48 switch( inReason )
49 {
50 case DLL_PROCESS_ATTACH:
51 case DLL_THREAD_ATTACH:
52 case DLL_THREAD_DETACH:
53 case DLL_PROCESS_DETACH:
54 break;
55 }
56 return( TRUE );
57 }
58
59
60 BOOL
61 IsSystemServiceDisabled()
62 {
63 ENUM_SERVICE_STATUS * lpService = NULL;
64 SC_HANDLE sc;
65 BOOL ret = FALSE;
66 BOOL ok;
67 DWORD bytesNeeded = 0;
68 DWORD srvCount;
69 DWORD resumeHandle = 0;
70 DWORD srvType;
71 DWORD srvState;
72 DWORD dwBytes = 0;
73 DWORD i;
74 OSStatus err;
75
76 sc = OpenSCManager( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE );
77 err = translate_errno( sc, GetLastError(), kUnknownErr );
78 require_noerr( err, exit );
79
80 srvType = SERVICE_WIN32;
81 srvState = SERVICE_STATE_ALL;
82
83 for ( ;; )
84 {
85 // Call EnumServicesStatus using the handle returned by OpenSCManager
86
87 ok = EnumServicesStatus ( sc, srvType, srvState, lpService, dwBytes, &bytesNeeded, &srvCount, &resumeHandle );
88
89 if ( ok || ( GetLastError() != ERROR_MORE_DATA ) )
90 {
91 break;
92 }
93
94 if ( lpService )
95 {
96 free( lpService );
97 }
98
99 dwBytes = bytesNeeded;
100
101 lpService = ( ENUM_SERVICE_STATUS* ) malloc( dwBytes );
102 require_action( lpService, exit, ret = FALSE );
103 }
104
105 err = translate_errno( ok, GetLastError(), kUnknownErr );
106 require_noerr( err, exit );
107
108 for ( i = 0; i < srvCount; i++ )
109 {
110 if ( strcmp( lpService[i].lpServiceName, "Bonjour Service" ) == 0 )
111 {
112 if ( ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_PAUSED ) || ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_STOPPED ) )
113 {
114 ret = TRUE;
115 }
116
117 break;
118 }
119 }
120
121 exit:
122
123 if ( lpService )
124 {
125 free( lpService );
126 }
127
128 if ( sc )
129 {
130 CloseServiceHandle ( sc );
131 }
132
133 return ret;
134 }