summaryrefslogtreecommitdiffstats
path: root/private/eventlog/server/alert.c
blob: 3751b91b208050a7cbffffffda4cc3f1c685dbea (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
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

    ALERT.C

Abstract:

    This file contains the routine that sends the alert to the admin.

Author:

    Rajen Shah  (rajens)    28-Aug-1991


Revision History:


--*/

//
// INCLUDES
//

#include <eventp.h>
#include <string.h>
#include <lmalert.h>                // LAN Manager alert structures



BOOL
SendAdminAlert (
            ULONG   MessageID,
            ULONG   NumStrings,
            UNICODE_STRING  *pStrings
            )


/*++

Routine Description:

    This routine raises an ADMIN alert with the message specified.


Arguments:

    MessageID  - Message ID.
    NumStrings - Number of replacement strings.
    pStrings   - Array of UNICODE_STRING Replacement strings.

Return Value:

    NONE

Note:

    This routine dynamically links to netapi32.dll to avoid a build
    dependency.

--*/
{

    typedef DWORD (*ALERT_FNC_PTR)(
        IN LPTSTR AlertEventName,
        IN LPVOID VariableInfo,
        IN DWORD VariableInfoSize,
        IN LPTSTR ServiceName
        );


    NET_API_STATUS NetStatus;

    BYTE AlertBuffer[ELF_ADMIN_ALERT_BUFFER_SIZE + sizeof(ADMIN_OTHER_INFO)];
    ADMIN_OTHER_INFO UNALIGNED *VariableInfo = (PADMIN_OTHER_INFO) AlertBuffer;

    DWORD DataSize;
    DWORD i;
    LPWSTR pReplaceString;

    HANDLE dllHandle;
    ALERT_FNC_PTR AlertFunction;

    //
    // Dynamically link to netapi.dll.  If it's not there just return.  Return
    // TRUE so we won't try to send this alert again.
    //

    dllHandle = LoadLibraryA("NetApi32.Dll");
    if ( dllHandle == INVALID_HANDLE_VALUE ) {
        ElfDbgPrint(("[ELF] Failed to load DLL NetApi32.Dll: %ld\n",
                     GetLastError()));
        return(TRUE);
    }

    //
    // Get the address of the service's main entry point.  This
    // entry point has a well-known name.
    //

    AlertFunction = (ALERT_FNC_PTR)GetProcAddress(
                                                dllHandle,
                                                "NetAlertRaiseEx"
                                                );
    if (AlertFunction == NULL ) {
        ElfDbgPrint(("[ELF] Can't find entry NetAlertRaiseEx in NetApi32.Dll: %ld\n",
                     GetLastError()));
        return(TRUE);

    }

    VariableInfo->alrtad_errcode = MessageID;
    VariableInfo->alrtad_numstrings = NumStrings;

    pReplaceString = (LPWSTR)(AlertBuffer + sizeof(ADMIN_OTHER_INFO));

    //
    // Copy over the replacement strings
    //

    for (i = 0; i < NumStrings; i++) {
        RtlMoveMemory(pReplaceString, pStrings[i].Buffer,
            pStrings[i].MaximumLength);
        pReplaceString = (LPWSTR) ((PBYTE) pReplaceString +
            pStrings[i].MaximumLength);
    }

    DataSize = (PBYTE) pReplaceString - (PBYTE) AlertBuffer;

    NetStatus = (*AlertFunction)(ALERT_ADMIN_EVENT, AlertBuffer, DataSize,
        wname_Eventlogsvc);

    if (NetStatus != NERR_Success) {
        ElfDbgPrint(("[ELF] NetAlertRaiseEx failed with %d\n", NetStatus));
        ElfDbgPrint(("[ELF] Attempted to raise alert %d\n", MessageID));

        //
        // Probably just not started yet, try again later
        //

        return(FALSE);
    }

    return(TRUE);
}