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
|
/*++
Copyright (c) 1989 Microsoft Corporation
Module Name:
dbginit.c
Abstract:
Debug Subsystem Initialization
Author:
Mark Lucovsky (markl) 22-Jan-1990
Revision History:
--*/
#include "smsrvp.h"
static SID_IDENTIFIER_AUTHORITY WorldSidAuthority = SECURITY_WORLD_SID_AUTHORITY;
NTSTATUS
DbgpInit()
{
NTSTATUS st;
ANSI_STRING Name;
UNICODE_STRING UnicodeName;
OBJECT_ATTRIBUTES ObjA;
ULONG i;
ULONG Length;
PSID SeWorldSid;
PSECURITY_DESCRIPTOR SecurityDescriptor;
PACL Dacl;
//
// Initialize the application thread hash table
//
RtlInitializeCriticalSection(&DbgpHashTableLock);
for( i=0;i<DBGP_CLIENT_ID_HASHSIZE;i++) {
InitializeListHead(&DbgpAppThreadHashTable[i]);
InitializeListHead(&DbgpAppProcessHashTable[i]);
InitializeListHead(&DbgpUiHashTable[i]);
}
//
// create a security descriptor that allows all access
//
SeWorldSid = RtlAllocateHeap( RtlProcessHeap(), MAKE_TAG( DBG_TAG ), RtlLengthRequiredSid( 1 ) );
RtlInitializeSid( SeWorldSid, &WorldSidAuthority, 1 );
*(RtlSubAuthoritySid( SeWorldSid, 0 )) = SECURITY_WORLD_RID;
Length = SECURITY_DESCRIPTOR_MIN_LENGTH +
(ULONG)sizeof(ACL) +
(ULONG)sizeof(ACCESS_ALLOWED_ACE) +
RtlLengthSid( SeWorldSid );
SecurityDescriptor = RtlAllocateHeap( RtlProcessHeap(), MAKE_TAG( DBG_TAG ), Length);
ASSERT( SecurityDescriptor != NULL );
RtlCreateSecurityDescriptor(SecurityDescriptor, SECURITY_DESCRIPTOR_REVISION);
Dacl = (PACL)((PCHAR)SecurityDescriptor + SECURITY_DESCRIPTOR_MIN_LENGTH);
RtlCreateAcl( Dacl, Length - SECURITY_DESCRIPTOR_MIN_LENGTH, ACL_REVISION2);
RtlAddAccessAllowedAce (
Dacl,
ACL_REVISION2,
PORT_ALL_ACCESS,
SeWorldSid
);
RtlSetDaclSecurityDescriptor (
SecurityDescriptor,
TRUE,
Dacl,
FALSE
);
//
// Create ports for Subsystems to connect to and for
// user interfaces to connect to
//
RtlInitAnsiString( &Name, "\\DbgSsApiPort" );
st = RtlAnsiStringToUnicodeString( &UnicodeName, &Name, TRUE);
ASSERT(NT_SUCCESS(st));
InitializeObjectAttributes( &ObjA, &UnicodeName, 0, NULL,
SecurityDescriptor );
st = NtCreatePort(
&DbgpSsApiPort,
&ObjA,
0,
sizeof(DBGSS_APIMSG),
sizeof(DBGSS_APIMSG) * 32
);
RtlFreeUnicodeString(&UnicodeName);
ASSERT( NT_SUCCESS(st) );
RtlInitAnsiString( &Name, "\\DbgUiApiPort" );
st = RtlAnsiStringToUnicodeString( &UnicodeName, &Name, TRUE);
ASSERT(NT_SUCCESS(st));
InitializeObjectAttributes( &ObjA, &UnicodeName, 0, NULL,
SecurityDescriptor );
st = NtCreatePort(
&DbgpUiApiPort,
&ObjA,
sizeof(HANDLE),
sizeof(DBGUI_APIMSG),
sizeof(DBGUI_APIMSG) * 32
);
RtlFreeUnicodeString(&UnicodeName);
ASSERT( NT_SUCCESS(st) );
//
// Clean up security stuff
//
RtlFreeHeap( RtlProcessHeap(), 0, SeWorldSid );
RtlFreeHeap( RtlProcessHeap(), 0, SecurityDescriptor );
//
// Create Initial Set of Server Threads
//
st = RtlCreateUserThread(
NtCurrentProcess(),
NULL,
FALSE,
0L,
0L,
0L,
DbgpUiApiLoop,
NULL,
NULL,
NULL
);
ASSERT( NT_SUCCESS(st) );
st = RtlCreateUserThread(
NtCurrentProcess(),
NULL,
FALSE,
0L,
0L,
0L,
DbgpSsApiLoop,
NULL,
NULL,
NULL
);
ASSERT( NT_SUCCESS(st) );
return STATUS_SUCCESS;
}
|