summaryrefslogtreecommitdiff
path: root/sd/source/ui/remotecontrol/mDNSResponder/dllmain.c
blob: ce3fce554037bc7f1458ce4d35d1050f3e05a64b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* -*- Mode: C; tab-width: 4 -*-
 *
 * Copyright (c) 2004 Apple Computer, 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.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * 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.
 */

// #include <windows.h>
#include <DebugServices.h>
#include <stdlib.h>

BOOL APIENTRY    DllMain( HANDLE inModule, DWORD inReason, LPVOID inReserved )
{
    (void) inModule;
    (void) inReserved;

    switch( inReason )
    {
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
    }
    return( TRUE );
}


BOOL
IsSystemServiceDisabled()
{
    ENUM_SERVICE_STATUS    *    lpService = NULL;
    SC_HANDLE                    sc;
    BOOL                            ret = FALSE;
    BOOL                            ok;
    DWORD                            bytesNeeded = 0;
    DWORD                            srvCount;
    DWORD                            resumeHandle = 0;
    DWORD                            srvType;
    DWORD                            srvState;
    DWORD                            dwBytes = 0;
    DWORD                            i;
    OSStatus                        err;

    sc = OpenSCManager( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE );
    err = translate_errno( sc, GetLastError(), kUnknownErr );
    require_noerr( err, exit );

    srvType        =    SERVICE_WIN32;
    srvState        =    SERVICE_STATE_ALL;

    for ( ;; )
    {
        // Call EnumServicesStatus using the handle returned by OpenSCManager

        ok = EnumServicesStatus ( sc, srvType, srvState, lpService, dwBytes, &bytesNeeded, &srvCount, &resumeHandle );

        if ( ok || ( GetLastError() != ERROR_MORE_DATA ) )
        {
            break;
        }

        if ( lpService )
        {
            free( lpService );
        }

        dwBytes = bytesNeeded;

        lpService = ( ENUM_SERVICE_STATUS* ) malloc( dwBytes );
        require_action( lpService, exit, ret = FALSE );
    }

    err = translate_errno( ok, GetLastError(), kUnknownErr );
    require_noerr( err, exit );

    for ( i = 0; i < srvCount; i++ )
    {
        if ( strcmp( lpService[i].lpServiceName, "Bonjour Service" ) == 0 )
        {
            if ( ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_PAUSED ) || ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_STOPPED ) )
            {
                ret = TRUE;
            }

            break;
        }
    }

exit:

    if ( lpService )
    {
        free( lpService );
    }

    if ( sc )
    {
        CloseServiceHandle ( sc );
    }

    return ret;
}