summaryrefslogblamecommitdiffstats
path: root/private/sdktools/wintueor/missy/global.c
blob: b5687bd568098ca61113506bd1947b50a9c1ec7d (plain) (tree)
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430













































































































































































































































































































































































































































                                                                                                       
/*++

Copyright (c) 1994  Microsoft Corporation

Module Name:

    global.c

Abstract:

    This module contains the global variables for the Microsoft
    Standard Smedly.

Author:

    Jim Kelly (JimK) 22-Mar-1995

Revision History:

--*/

#include "Missyp.h"





///////////////////////////////////////////////////////////////////////
//                                                                   //
//  Local Function Prototypes                                        //
//                                                                   //
///////////////////////////////////////////////////////////////////////





///////////////////////////////////////////////////////////////////////
//                                                                   //
//  Global Variables                                                 //
//                                                                   //
///////////////////////////////////////////////////////////////////////

//
// Handle to the Security Manager module
//
HINSTANCE
    MissypSecMgrhInstance;

//
// Handle to our own module
//

HINSTANCE
    MissyphInstance;


//
// Indicates whether or not a report file is currently active
// 

BOOL
    MissypReportFileActive = FALSE;


//
// Well known sids that we use
//

PSID
    MissypWorldSid,
    MissypAccountOpsSid,
    MissypBackupOpsSid,
    MissypPrintOpsSid,
    MissypServerOpsSid,
    MissypAdminsSid;


//
// Grouping of well-known sids by type
//

MISSYP_ACCOUNTS
    MissypAnyoneSids,
    MissypOperatorSids,
    MissypOpersAndAdminsSids,
    MissypAdminsSids;


//
// Control information received from the security manager.
//     MissypSecMgr is just a shorter way to reference the
//     dispatch routines.
//
//     The information pointed to by these variables is READ ONLY!
//

PSECMGR_CONTROL
    MissypSecMgrControl;

PSECMGR_DISPATCH_TABLE
    MissypSecMgr;


//
// This is the control information about Missy that is returned
// to the security manager.  Once built, this structure is READ ONLY.
//

SECMGR_SMEDLY_CONTROL
    MissypControl;



//
// Type of product installed and running on this machine
//

NT_PRODUCT_TYPE
    MissypProductType;


///////////////////////////////////////////////////////////////////////
//                                                                   //
//  Externally callable functions                                    //
//                                                                   //
///////////////////////////////////////////////////////////////////////

BOOL
MissypGlobalInitialize(
    IN  PSECMGR_CONTROL             SecMgrControl
    )

/*++
Routine Description:

    This function is called to initialize the global variables.
    This is done during DLL initialization.  As such, this routine
    also does some degree of sanity checking of revision levels.


Arguments

    SecMgrControl - Points to a Security Manager control block
        for use by the smedly.  This block will not change once
        smedly has returned, and therefore, it may be referenced
        directly in the future (rather than having to copy it).


Return Values:

    TRUE - The call completed successfully.

    FALSE - Something went wrong.  GetLastError() contains
        details on the exact cause of the error.  Possible
        values include:

                ERROR_UNKNOWN_REVISION

--*/
{
    NTSTATUS
        NtStatus;

    ULONG
        Index,
        AreaIndex;

    BOOLEAN
        IgnoreBoolean;

    SID_IDENTIFIER_AUTHORITY
        WorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY,
        NtAuthority = SECURITY_NT_AUTHORITY;

    //
    // Check the major revision level.  If it isn't the same as
    // our revision, then we don't support it.
    //

    if (SecMgrControl->Revision.Major != SECMGR_REVISION_MAJOR_1) {
        SetLastError( ERROR_UNKNOWN_REVISION );
        return(FALSE);
    }

    //
    // Save a pointer to the security manager control.
    // Also save a pointer to the security manager's dispatch table
    // to make calling them easier and faster.
    //

    MissypSecMgrControl = SecMgrControl;
    MissypSecMgr = MissypSecMgrControl->Api;


    //
    // Save a copy of the security manager's hInstance for quick reference
    //

    MissypSecMgrhInstance = SecMgrControl->hInstance;

    //
    // Get the product type
    //
    
    IgnoreBoolean = RtlGetNtProductType( &MissypProductType );
    ASSERT(IgnoreBoolean == TRUE);



    //
    // Initialize the sids
    //


    NtStatus = RtlAllocateAndInitializeSid(
                   &WorldSidAuthority,
                   1,
                   SECURITY_WORLD_RID,
                   0, 0, 0, 0, 0, 0, 0,
                   &MissypWorldSid
                   );
    if (!NT_SUCCESS(NtStatus)) {
        KdPrint(("SecMgr: Failed to initialize world sid, status = 0x%lx", NtStatus));
        return(FALSE);
    }


    NtStatus = RtlAllocateAndInitializeSid(
                   &NtAuthority,
                   2,
                   SECURITY_BUILTIN_DOMAIN_RID,
                   DOMAIN_ALIAS_RID_ACCOUNT_OPS,
                   0, 0, 0, 0, 0, 0,
                   &MissypAccountOpsSid
                   );
    if (!NT_SUCCESS(NtStatus)) {
        KdPrint(("SecMgr: Failed to initialize admin AcountOps sid, status = 0x%lx", NtStatus));
        return(FALSE);
    }

    NtStatus = RtlAllocateAndInitializeSid(
                   &NtAuthority,
                   2,
                   SECURITY_BUILTIN_DOMAIN_RID,
                   DOMAIN_ALIAS_RID_SYSTEM_OPS,
                   0, 0, 0, 0, 0, 0,
                   &MissypServerOpsSid
                   );
    if (!NT_SUCCESS(NtStatus)) {
        KdPrint(("SecMgr: Failed to initialize admin ServerOps sid, status = 0x%lx", NtStatus));
        return(FALSE);
    }

    NtStatus = RtlAllocateAndInitializeSid(
                   &NtAuthority,
                   2,
                   SECURITY_BUILTIN_DOMAIN_RID,
                   DOMAIN_ALIAS_RID_PRINT_OPS,
                   0, 0, 0, 0, 0, 0,
                   &MissypPrintOpsSid
                   );
    if (!NT_SUCCESS(NtStatus)) {
        KdPrint(("SecMgr: Failed to initialize admin PrintOps sid, status = 0x%lx", NtStatus));
        return(FALSE);
    }

    NtStatus = RtlAllocateAndInitializeSid(
                   &NtAuthority,
                   2,
                   SECURITY_BUILTIN_DOMAIN_RID,
                   DOMAIN_ALIAS_RID_BACKUP_OPS,
                   0, 0, 0, 0, 0, 0,
                   &MissypBackupOpsSid
                   );
    if (!NT_SUCCESS(NtStatus)) {
        KdPrint(("SecMgr: Failed to initialize admin BackupOps sid, status = 0x%lx", NtStatus));
        return(FALSE);
    }

    NtStatus = RtlAllocateAndInitializeSid(
                   &NtAuthority,
                   2,
                   SECURITY_BUILTIN_DOMAIN_RID,
                   DOMAIN_ALIAS_RID_ADMINS,
                   0, 0, 0, 0, 0, 0,
                   &MissypAdminsSid
                   );
    if (!NT_SUCCESS(NtStatus)) {
        KdPrint(("SecMgr: Failed to initialize admin alias sid, status = 0x%lx", NtStatus));
        return(FALSE);
    }


    //
    // Group the sids by type
    //

    Index=0;
    MissypAnyoneSids.Sid[Index++] = MissypWorldSid;
    MissypAnyoneSids.Accounts = Index;
    ASSERT(Index < MISSYP_MAX_WELL_KNOWN_ACCOUNTS);

    Index=0;
    MissypOperatorSids.Sid[Index++] = MissypAccountOpsSid;
    MissypOperatorSids.Sid[Index++] = MissypBackupOpsSid;
    MissypOperatorSids.Sid[Index++] = MissypPrintOpsSid;
    MissypOperatorSids.Sid[Index++] = MissypServerOpsSid;
    MissypOperatorSids.Accounts = Index;
    ASSERT(Index < MISSYP_MAX_WELL_KNOWN_ACCOUNTS);

    Index=0;
    MissypOpersAndAdminsSids.Sid[Index++] = MissypAccountOpsSid;
    MissypOpersAndAdminsSids.Sid[Index++] = MissypBackupOpsSid;
    MissypOpersAndAdminsSids.Sid[Index++] = MissypPrintOpsSid;
    MissypOpersAndAdminsSids.Sid[Index++] = MissypServerOpsSid;
    MissypOpersAndAdminsSids.Sid[Index++] = MissypAdminsSid;
    MissypOpersAndAdminsSids.Accounts = Index;
    ASSERT(Index < MISSYP_MAX_WELL_KNOWN_ACCOUNTS);

    Index=0;
    MissypAdminsSids.Sid[Index++] = MissypAdminsSid;
    MissypAdminsSids.Accounts = Index;
    ASSERT(Index < MISSYP_MAX_WELL_KNOWN_ACCOUNTS);


    //
    // Initialize our smedly control block with no areas in it.
    // The area/item information will be added by the initialization
    // routine of each area.
    //

    //
    // Revision
    //

    MissypControl.Revision.Major = SECMGR_REVISION_MAJOR_1;
    MissypControl.Revision.Minor = SECMGR_REVISION_MINOR_0;

    MissypControl.Api = (PSECMGR_SMEDLY_DISPATCH_TABLE)
                         LocalAlloc( LPTR, sizeof(SECMGR_SMEDLY_DISPATCH_TABLE) );
    if (MissypControl.Api == NULL) {
        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
        return(FALSE);
    }


    //
    // Dispatch table
    //

    MissypControl.Api->InvokeArea           = MissyInvokeArea;
    MissypControl.Api->InvokeItem           = MissyInvokeItem;
    MissypControl.Api->NewSecurityLevel     = MissyNewSecurityLevel;
    MissypControl.Api->ReportFileChange     = MissyReportFileChange;
    MissypControl.Api->GenerateProfile      = MissyGenerateProfile;
    MissypControl.Api->ApplyProfile         = MissyApplyProfile;


    //
    // control flags
    //

    MissypControl.Flags = 0;        // Don't support reporting or profiles yet


    //
    // build up the control structure for the areas we support
    //

    MissypControl.AreaCount = MISSYP_AREA_COUNT;
    MissypControl.Areas = (PSECMGR_AREA_DESCRIPTOR)
                           LocalAlloc( LPTR, MissypControl.AreaCount * sizeof(SECMGR_AREA_DESCRIPTOR));
    
    if (MissypControl.Areas == NULL) {
        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
        return(FALSE);
    }

    //
    // System Access area
    //

    AreaIndex = 0;
    if (!MissypSysAccInitialize( AreaIndex )) {
        return(FALSE);
    }

    //
    // Auditing area
    //

    AreaIndex++;
    if (!MissypAuditInitialize( AreaIndex )) {
        return(FALSE);
    }

    //
    // File System area
    //

    AreaIndex++;
    if (!MissypFileSysInitialize( AreaIndex )) {
        return(FALSE);
    }


    //
    // Configuration area
    //

    AreaIndex++;
    if (!MissypConfigInitialize( AreaIndex )) {
        return(FALSE);
    }

    ASSERT(AreaIndex < MISSYP_AREA_COUNT);



}


///////////////////////////////////////////////////////////////////////
//                                                                   //
//  Locally callable functions                                       //
//                                                                   //
///////////////////////////////////////////////////////////////////////