summaryrefslogtreecommitdiffstats
path: root/private/nw/service/nwsvc/nwsvc.c
blob: 5486f0983f21a2db714345bccc83d7b2b3d652d4 (plain) (blame)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*++

Copyright (c) 1993  Microsoft Corporation

Module Name:

    nwsvc.c

Abstract:

    This is the main module of the NetWare services process shared by
    NetWare services.

Author:

    Rita Wong   (ritaw)    26-Feb-1993

Environment:

    User Mode - Win32

Revision History:

--*/

#ifndef UNICODE
#define UNICODE
#endif

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>

#include <nwrpcp.h>
#include <nwsvc.h>

//
// Service entry points -- thunks to real service entry points.
//

VOID
StartWorkstation(
    IN DWORD argc,
    IN LPWSTR argv[]
    );

//
// Local function used by the above to load and invoke a service DLL.
//
VOID
NwsvcStartService(
    IN LPWSTR DllName,
    IN DWORD argc,
    IN LPWSTR argv[]
    );


//
// To pass RPC utility function pointers to DLLs so that global data
// for this process can be updated from within the DLLs.
//
NWSVC_GLOBAL_DATA GlobalData;

//
// Dispatch table for all services.
// Add new service entries here and in the DLL name list.
//
SERVICE_TABLE_ENTRYW NwServiceDispatchTable[] = {
                        { NW_WORKSTATION_SERVICE,  StartWorkstation },
                        { NULL,                    NULL             }
                        };

//
// DLL names for all services.
//
#define WORKSTATION_DLL TEXT("nwwks.dll")


VOID _CRTAPI1
main(
    VOID
    )
/*++

Routine Description:

    This is the main function of the NetWare services process.
    It does process-wide initialization and relinquishes the main
    thread to the service controller to become the control
    dispatch thread.

Arguments:

    None.

Return Value:

    None.

--*/
{
    //
    // Initialize process-wide RPC data so that all services in this
    // process share the same RPC server.
    //
    RpcpInitRpcServer();

    //
    // Each of the following routines alters global data in this process.
    // This data has to be made accessible from each service DLL.
    //
    GlobalData.StartRpcServer = RpcpStartRpcServer;
    GlobalData.StopRpcServer = RpcpStopRpcServer;

    //
    // Become the dispatch thread.
    //
    (void) StartServiceCtrlDispatcherW(NwServiceDispatchTable);
}


VOID
StartWorkstation (
    IN DWORD argc,
    IN LPWSTR argv[]
    )

/*++

Routine Description:

    This is the thunk routine for the Workstation service.  It loads the
    DLL that contains the service and calls its main routine.

Arguments:

    argc, argv - Passed through to the service

Return Value:

    None.

--*/

{
    //
    // Call NwsvcStartService to load and run the service.
    //

    NwsvcStartService( WORKSTATION_DLL, argc, argv );

} // StartWorkstation



VOID
NwsvcStartService(
    IN LPWSTR DllName,
    IN DWORD argc,
    IN LPWSTR argv[]
    )

/*++

Routine Description:

    This routine loads the DLL that contains a service and calls its
    main routine.

Arguments:

    DllName - name of the DLL

    argc, argv - Passed through to the service

Return Value:

    None.

--*/

{
    HMODULE dllHandle;
    PNWSVC_SERVICE_DLL_ENTRY serviceEntry;
    BOOL ok;


    //
    // Load the DLL that contains the service.
    //
    dllHandle = LoadLibraryW(DllName);

    if (dllHandle == NULL) {
        KdPrint(("NVSVC: Failed to load DLL %ws: %lu\n", DllName, GetLastError()));
        return;
    }

    //
    // Get the address of the service's main entry point.  This
    // entry point has a well-known name.
    //
    serviceEntry = (PNWSVC_SERVICE_DLL_ENTRY) GetProcAddress(
                                                  dllHandle,
                                                  NWSVC_ENTRY_POINT_STRING
                                                  );
    if (serviceEntry == NULL) {
        KdPrint(("NWSVC: Can't find entry %s in DLL %ws: %lu\n",
                 NWSVC_ENTRY_POINT_STRING, DllName, GetLastError()));
        return;
    }

    //
    // Call the service's main entry point.  This call doesn't return
    // until the service exits.
    //
    serviceEntry(argc, argv, &GlobalData);


    //
    // Unload the DLL.
    //
    ok = FreeLibrary( dllHandle );
    if (! ok) {
        KdPrint(("NWSVC: Can't unload DLL %ws: %lu\n", DllName, GetLastError()));
    }

    return;

} // NwsvcStartService