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
|
/*++
Copyright (c) 1991 Microsoft Corporation
Module Name:
msgalias.c
Abstract:
This file contains routines for adding and deleting message aliases
when a user logs on/off.
Author:
Dan Lafferty (danl) 21-Aug-1992
Environment:
User Mode -Win32
Revision History:
21-Aug-1992 danl
created
--*/
#include "precomp.h"
#pragma hdrstop
#define LPTSTR LPWSTR
VOID
DeleteMsgAliases(
VOID
)
/*++
Routine Description:
This function removes all message aliases except the ComputerName.
Arguments:
none
Return Value:
none
--*/
{
DWORD status;
LPMSG_INFO_0 InfoStruct;
DWORD entriesRead;
DWORD totalEntries;
DWORD resumeHandle = 0;
DWORD i;
WCHAR ComputerName[MAX_COMPUTERNAME_LENGTH + 1];
LPWSTR NewServerName = NULL;
DWORD bufLen = MAX_COMPUTERNAME_LENGTH + 1;
HANDLE dllHandle;
PMSG_NAME_DEL NetMessageNameDel = NULL;
PMSG_NAME_ENUM NetMessageNameEnum = NULL;
//
// Get the computer name
//
if (!GetComputerNameW(ComputerName,&bufLen)) {
DebugLog((DEB_ERROR, "failed to obtain the computername"));
}
//
// Get the address of the functions we need from netapi32.dll
//
dllHandle = LoadLibraryW(L"netapi32.dll");
if (dllHandle == NULL) {
return;
}
NetMessageNameEnum = (PMSG_NAME_ENUM) GetProcAddress(
dllHandle,
"NetMessageNameEnum");
if (NetMessageNameEnum == NULL) {
FreeLibrary(dllHandle);
return;
}
NetMessageNameDel = (PMSG_NAME_DEL) GetProcAddress(
dllHandle,
"NetMessageNameDel");
if (NetMessageNameDel == NULL) {
FreeLibrary(dllHandle);
return;
}
//
// Enumerate all the Message Aliases
//
status = NetMessageNameEnum (
NULL, // ServerName - Local version
0, // Level
(LPBYTE *)&InfoStruct, // return status buffer pointer
0xffffffff, // preferred max length
&entriesRead, // entries read
&totalEntries, // total entries
&resumeHandle); // resume handle
if (status != NERR_Success) {
// DebugLog((DEB_ERROR, "NetMessageNameEnum failed %d",status));
FreeLibrary(dllHandle);
return;
}
//
// Remove the aliases that are not the computername.
//
for (i=0; i<entriesRead ;i++) {
if (_wcsicmp(InfoStruct->msgi0_name, ComputerName) != 0) {
status = NetMessageNameDel(
NULL,
InfoStruct->msgi0_name);
if (status != NERR_Success) {
DebugLog((DEB_ERROR, "DeleteMsgAliases: Name - %ws - delete failed",
InfoStruct->msgi0_name));
}
}
InfoStruct++;
}
FreeLibrary(dllHandle);
}
VOID
TickleMessenger(VOID)
{
HANDLE hDll;
PMSG_NAME_DEL NetMessageNameDel = NULL;
//
// Get the address of the functions we need from netapi32.dll
//
hDll = LoadLibraryW(L"netapi32.dll");
if (hDll == NULL) {
return;
}
NetMessageNameDel = (PMSG_NAME_DEL) GetProcAddress(
hDll,
"NetMessageNameDel");
if (NetMessageNameDel) {
NetMessageNameDel(NULL, TEXT(""));
}
FreeLibrary(hDll);
}
|