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