• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include <windows.h>
19 #include <DebugServices.h>
20 
DllMain(HANDLE inModule,DWORD inReason,LPVOID inReserved)21 BOOL APIENTRY	DllMain( HANDLE inModule, DWORD inReason, LPVOID inReserved )
22 {
23 	(void) inModule;
24 	(void) inReserved;
25 
26 	switch( inReason )
27 	{
28 		case DLL_PROCESS_ATTACH:
29 		case DLL_THREAD_ATTACH:
30 		case DLL_THREAD_DETACH:
31 		case DLL_PROCESS_DETACH:
32 			break;
33 	}
34     return( TRUE );
35 }
36 
37 
38 BOOL
IsSystemServiceDisabled()39 IsSystemServiceDisabled()
40 {
41 	ENUM_SERVICE_STATUS	*	lpService = NULL;
42 	SC_HANDLE					sc;
43 	BOOL							ret = FALSE;
44 	BOOL							ok;
45 	DWORD							bytesNeeded = 0;
46 	DWORD							srvCount;
47 	DWORD							resumeHandle = 0;
48 	DWORD							srvType;
49 	DWORD							srvState;
50 	DWORD							dwBytes = 0;
51 	DWORD							i;
52 	OSStatus						err;
53 
54 	sc = OpenSCManager( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE );
55 	err = translate_errno( sc, GetLastError(), kUnknownErr );
56 	require_noerr( err, exit );
57 
58 	srvType		=	SERVICE_WIN32;
59 	srvState		=	SERVICE_STATE_ALL;
60 
61 	for ( ;; )
62 	{
63 		// Call EnumServicesStatus using the handle returned by OpenSCManager
64 
65 		ok = EnumServicesStatus ( sc, srvType, srvState, lpService, dwBytes, &bytesNeeded, &srvCount, &resumeHandle );
66 
67 		if ( ok || ( GetLastError() != ERROR_MORE_DATA ) )
68 		{
69 			break;
70 		}
71 
72 		if ( lpService )
73 		{
74 			free( lpService );
75 		}
76 
77 		dwBytes = bytesNeeded;
78 
79 		lpService = ( ENUM_SERVICE_STATUS* ) malloc( dwBytes );
80 		require_action( lpService, exit, ret = FALSE );
81 	}
82 
83 	err = translate_errno( ok, GetLastError(), kUnknownErr );
84 	require_noerr( err, exit );
85 
86 	for ( i = 0; i < srvCount; i++ )
87 	{
88 		if ( strcmp( lpService[i].lpServiceName, "Bonjour Service" ) == 0 )
89 		{
90 			if ( ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_PAUSED ) || ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_STOPPED ) )
91 			{
92 				ret = TRUE;
93 			}
94 
95 			break;
96 		}
97 	}
98 
99 exit:
100 
101 	if ( lpService )
102 	{
103 		free( lpService );
104 	}
105 
106 	if ( sc )
107 	{
108 		CloseServiceHandle ( sc );
109 	}
110 
111 	return ret;
112 }
113