~ubuntu-branches/ubuntu/precise/krb5/precise-updates

« back to all changes in this revision

Viewing changes to src/windows/leash/LeashAboutBox.cpp

  • Committer: Package Import Robot
  • Author(s): Sam Hartman
  • Date: 2011-12-01 19:34:41 UTC
  • mfrom: (28.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20111201193441-9tipg3aru1jsidyv
Tags: 1.10+dfsg~alpha1-6
* Fix segfault with unknown hostnames in krb5_sname_to_principal,
  Closes: #650671
* Indicate that this library breaks libsmbclient versions that depend on
  krb5_locate_kdc, Closes: #650603, #650611

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//*****************************************************************************
 
2
// File:        LeashAboutBox.cpp
 
3
// By:          Arthur David Leather
 
4
// Created:     12/02/98
 
5
// Copyright:   @1998 Massachusetts Institute of Technology - All rights
 
6
//              reserved.
 
7
// Description: CPP file for LeashAboutBox.h. Contains variables and functions
 
8
//              for the Leash About Box Dialog Box
 
9
//
 
10
// History:
 
11
//
 
12
// MM/DD/YY     Inits   Description of Change
 
13
// 12/02/98     ADL     Original
 
14
//*****************************************************************************
 
15
 
 
16
 
 
17
#include "stdafx.h"
 
18
#include "leash.h"
 
19
#include "LeashAboutBox.h"
 
20
#include "reminder.h"
 
21
#include "lglobals.h"
 
22
#include "psapi.h"
 
23
 
 
24
#ifdef _DEBUG
 
25
#define new DEBUG_NEW
 
26
#undef THIS_FILE
 
27
static char THIS_FILE[] = __FILE__;
 
28
#endif
 
29
 
 
30
/////////////////////////////////////////////////////////////////////////////
 
31
// CLeashAboutBox dialog
 
32
 
 
33
 
 
34
CLeashAboutBox::CLeashAboutBox(CWnd* pParent /*=NULL*/)
 
35
        : CDialog(CLeashAboutBox::IDD, pParent)
 
36
{
 
37
    m_missingFileError = FALSE;
 
38
 
 
39
    //{{AFX_DATA_INIT(CLeashAboutBox)
 
40
    m_fileItem = _T("");
 
41
    //}}AFX_DATA_INIT
 
42
}
 
43
 
 
44
 
 
45
void CLeashAboutBox::DoDataExchange(CDataExchange* pDX)
 
46
{
 
47
    CDialog::DoDataExchange(pDX);
 
48
    //{{AFX_DATA_MAP(CLeashAboutBox)
 
49
    DDX_Control(pDX, IDC_PROPERTIES, m_propertiesButton);
 
50
    DDX_Control(pDX, IDC_LEASH_MODULES, m_radio_LeashDLLs);
 
51
    DDX_Control(pDX, IDC_LEASH_MODULE_LB, m_LB_DLLsLoaded);
 
52
    DDX_LBString(pDX, IDC_LEASH_MODULE_LB, m_fileItem);
 
53
    //}}AFX_DATA_MAP
 
54
}
 
55
 
 
56
 
 
57
BEGIN_MESSAGE_MAP(CLeashAboutBox, CDialog)
 
58
    //{{AFX_MSG_MAP(CLeashAboutBox)
 
59
    ON_WM_HSCROLL()
 
60
    ON_LBN_SELCHANGE(IDC_LEASH_MODULE_LB, OnSelchangeLeashModuleLb)
 
61
    ON_BN_CLICKED(IDC_ALL_MODULES, OnAllModules)
 
62
    ON_BN_CLICKED(IDC_LEASH_MODULES, OnLeashModules)
 
63
    ON_LBN_DBLCLK(IDC_LEASH_MODULE_LB, OnDblclkLeashModuleLb)
 
64
    ON_BN_CLICKED(IDC_PROPERTIES, OnProperties)
 
65
    ON_LBN_SETFOCUS(IDC_LEASH_MODULE_LB, OnSetfocusLeashModuleLb)
 
66
    ON_BN_CLICKED(IDC_NOT_LOADED_MODULES, OnNotLoadedModules)
 
67
    //}}AFX_MSG_MAP
 
68
END_MESSAGE_MAP()
 
69
;
 
70
/////////////////////////////////////////////////////////////////////////////
 
71
// CLeashAboutBox message handlers
 
72
 
 
73
void CLeashAboutBox::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
 
74
{
 
75
    CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
 
76
}
 
77
 
 
78
BOOL CLeashAboutBox::GetModules95(DWORD processID, BOOL allModules)
 
79
{
 
80
    char szModNames[1024];
 
81
    MODULEENTRY32 me32 = {0};
 
82
    HANDLE hProcessSnap = NULL;
 
83
 
 
84
    hProcessSnap = pCreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processID);
 
85
    if (hProcessSnap == (HANDLE)-1)
 
86
        return FALSE;
 
87
 
 
88
    me32.dwSize = sizeof(MODULEENTRY32);
 
89
    if (pModule32First(hProcessSnap, &me32))
 
90
    {
 
91
        do
 
92
        {
 
93
            lstrcpy(szModNames, me32.szExePath);
 
94
            strupr(szModNames);
 
95
 
 
96
            if (!allModules)
 
97
            {
 
98
                if (!strstr(szModNames, "SYSTEM"))
 
99
                    m_LB_DLLsLoaded.AddString(me32.szExePath);
 
100
            }
 
101
            else
 
102
                m_LB_DLLsLoaded.AddString(me32.szExePath);
 
103
        }
 
104
        while (pModule32Next(hProcessSnap, &me32));
 
105
    }
 
106
 
 
107
    return TRUE;
 
108
}
 
109
 
 
110
void CLeashAboutBox::GetModulesNT(DWORD processID, BOOL allModules)
 
111
{
 
112
    char checkName[1024];
 
113
    HMODULE hMods[1024];
 
114
    HANDLE hProcess;
 
115
    DWORD cbNeeded;
 
116
    unsigned int i;
 
117
 
 
118
    // Get a list of all the modules in this process.
 
119
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
 
120
                           FALSE, processID);
 
121
 
 
122
    if (pEnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded))
 
123
    {
 
124
        for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++)
 
125
        {
 
126
            char szModName[2048];
 
127
 
 
128
            // Get the full path to the module's file.
 
129
            if (pGetModuleFileNameEx(hProcess, hMods[i], szModName,
 
130
                                     sizeof(szModName)))
 
131
            {
 
132
                lstrcpy(checkName, szModName);
 
133
                strupr(checkName);
 
134
 
 
135
                if (!allModules)
 
136
                {
 
137
                    if (!strstr(checkName, "SYSTEM32"))
 
138
                        m_LB_DLLsLoaded.AddString(szModName);
 
139
                }
 
140
                else
 
141
                    m_LB_DLLsLoaded.AddString(szModName);
 
142
            }
 
143
        }
 
144
    }
 
145
 
 
146
    CloseHandle(hProcess);
 
147
}
 
148
 
 
149
void CLeashAboutBox::HighlightFirstItem()
 
150
{
 
151
    UINT numModules = m_LB_DLLsLoaded.GetCount();
 
152
    CHAR numModulesBuffer [25];
 
153
    _itoa(numModules, numModulesBuffer, 10);
 
154
 
 
155
    if (numModules)
 
156
    {
 
157
        m_LB_DLLsLoaded.SetCurSel(0);
 
158
        m_propertiesButton.EnableWindow();
 
159
    }
 
160
    else
 
161
        m_propertiesButton.EnableWindow(FALSE);
 
162
 
 
163
    GetDlgItem(IDC_STATIC_NO_OF_MODULES)->SetWindowText(numModulesBuffer);
 
164
}
 
165
 
 
166
DWORD
 
167
CLeashAboutBox::SetVersionInfo(
 
168
    UINT id_version,
 
169
    UINT id_copyright
 
170
    )
 
171
{
 
172
    TCHAR filename[1024];
 
173
    DWORD dwVersionHandle;
 
174
    LPVOID pVersionInfo = 0;
 
175
    DWORD retval = 0;
 
176
    LPDWORD pLangInfo = 0;
 
177
    LPTSTR szVersion = 0;
 
178
    LPTSTR szCopyright = 0;
 
179
    UINT len = 0;
 
180
    TCHAR sname_version[] = TEXT("FileVersion");
 
181
    TCHAR sname_copyright[] = TEXT("LegalCopyright");
 
182
    TCHAR szVerQ[(sizeof("\\StringFileInfo\\12345678\\") +
 
183
                  max(sizeof(sname_version) / sizeof(TCHAR),
 
184
                      sizeof(sname_copyright) / sizeof(TCHAR)))];
 
185
    TCHAR * cp = szVerQ;
 
186
 
 
187
    if (!GetModuleFileName(NULL, filename, sizeof(filename)))
 
188
        return GetLastError();
 
189
 
 
190
    DWORD size = GetFileVersionInfoSize(filename, &dwVersionHandle);
 
191
 
 
192
    if (!size)
 
193
        return GetLastError();
 
194
 
 
195
    pVersionInfo = malloc(size);
 
196
    if (!pVersionInfo)
 
197
        return ERROR_NOT_ENOUGH_MEMORY;
 
198
 
 
199
    if (!GetFileVersionInfo(filename, dwVersionHandle, size, pVersionInfo))
 
200
    {
 
201
        retval = GetLastError();
 
202
        goto cleanup;
 
203
    }
 
204
 
 
205
    if (!VerQueryValue(pVersionInfo, TEXT("\\VarFileInfo\\Translation"),
 
206
                       (LPVOID*)&pLangInfo, &len))
 
207
    {
 
208
        retval = GetLastError();
 
209
        goto cleanup;
 
210
    }
 
211
 
 
212
 
 
213
    cp += wsprintf(szVerQ,
 
214
                   TEXT("\\StringFileInfo\\%04x%04x\\"),
 
215
                   LOWORD(*pLangInfo), HIWORD(*pLangInfo));
 
216
 
 
217
    lstrcpy(cp, sname_version);
 
218
    if (!VerQueryValue(pVersionInfo, szVerQ, (LPVOID*)&szVersion, &len))
 
219
    {
 
220
        retval = GetLastError() || ERROR_NOT_ENOUGH_MEMORY;
 
221
        goto cleanup;
 
222
    }
 
223
    TCHAR version[100];
 
224
    _sntprintf(version, sizeof(version), TEXT("Leash Version %s"), szVersion);
 
225
    version[sizeof(version) - 1] = 0;
 
226
    GetDlgItem(id_version)->SetWindowText(version);
 
227
 
 
228
    lstrcpy(cp, sname_copyright);
 
229
    if (!VerQueryValue(pVersionInfo, szVerQ, (LPVOID*)&szCopyright, &len))
 
230
    {
 
231
        retval = GetLastError() || ERROR_NOT_ENOUGH_MEMORY;
 
232
        goto cleanup;
 
233
    }
 
234
    GetDlgItem(id_copyright)->SetWindowText(szCopyright);
 
235
 
 
236
 cleanup:
 
237
    if (pVersionInfo)
 
238
        free(pVersionInfo);
 
239
    return retval;
 
240
}
 
241
 
 
242
BOOL CLeashAboutBox::OnInitDialog()
 
243
{
 
244
    CDialog::OnInitDialog();
 
245
 
 
246
    // XXX - we need to add some sensible behavior on error.
 
247
    SetVersionInfo(IDC_ABOUT_VERSION, IDC_ABOUT_COPYRIGHT);
 
248
 
 
249
    if (!CLeashApp::m_hToolHelp32 && !CLeashApp::m_hPsapi)
 
250
        m_missingFileError = TRUE;
 
251
 
 
252
    m_radio_LeashDLLs.SetCheck(TRUE);
 
253
    OnLeashModules();
 
254
 
 
255
    // We need to get the version info and display it...
 
256
    HighlightFirstItem();
 
257
 
 
258
    if (!CLeashApp::m_hPsapi)
 
259
        GetDlgItem(IDC_PROPERTIES)->EnableWindow(FALSE);
 
260
 
 
261
    return TRUE;  // return TRUE unless you set the focus to a control
 
262
    // EXCEPTION: OCX Property Pages should return FALSE
 
263
}
 
264
 
 
265
void CLeashAboutBox::OnSelchangeLeashModuleLb()
 
266
{
 
267
}
 
268
 
 
269
void CLeashAboutBox::OnAllModules()
 
270
{
 
271
    if (!CLeashApp::m_hToolHelp32 && !CLeashApp::m_hPsapi)
 
272
        return; //error
 
273
 
 
274
    m_LB_DLLsLoaded.ResetContent();
 
275
 
 
276
    if (!CLeashApp::m_hPsapi)
 
277
        GetModules95(GetCurrentProcessId());
 
278
    //m_LB_DLLsLoaded.AddString("Doesn't work in Windows 95");
 
279
    else
 
280
        GetModulesNT(GetCurrentProcessId());
 
281
 
 
282
    HighlightFirstItem();
 
283
}
 
284
 
 
285
void CLeashAboutBox::OnLeashModules()
 
286
{
 
287
    if (!CLeashApp::m_hToolHelp32 && !CLeashApp::m_hPsapi)
 
288
        return; // error
 
289
 
 
290
    m_LB_DLLsLoaded.ResetContent();
 
291
 
 
292
    if (!CLeashApp::m_hPsapi)
 
293
        GetModules95(GetCurrentProcessId(), FALSE);
 
294
    //m_LB_DLLsLoaded.AddString("Doesn't work in Windows 95");
 
295
    else
 
296
        GetModulesNT(GetCurrentProcessId(), FALSE);
 
297
 
 
298
    HighlightFirstItem();
 
299
}
 
300
 
 
301
void CLeashAboutBox::OnNotLoadedModules()
 
302
{
 
303
    m_LB_DLLsLoaded.ResetContent();
 
304
 
 
305
#ifndef NO_KRB4
 
306
    if (!CLeashApp::m_hKrb4DLL)
 
307
        m_LB_DLLsLoaded.AddString(KERB4DLL);
 
308
#endif
 
309
 
 
310
    if (!CLeashApp::m_hKrb5DLL)
 
311
        m_LB_DLLsLoaded.AddString(KERB5DLL);
 
312
 
 
313
    // NOTE: If the snippet below is commented back in,
 
314
    // it should read
 
315
    // if (!CLeashApp::m_hAfsDLL)
 
316
    // m_LB_DLLsLoaded.AddString(AFSAuthentDLL());
 
317
 
 
318
    //if (!CLeashApp::m_hAfsDLL)
 
319
    //m_LB_DLLsLoaded.AddString(ASFDLL);
 
320
 
 
321
    HighlightFirstItem();
 
322
}
 
323
 
 
324
void CLeashAboutBox::OnDblclkLeashModuleLb()
 
325
{
 
326
    m_LB_DLLsLoaded.GetText(m_LB_DLLsLoaded.GetCurSel(), m_fileItem);
 
327
 
 
328
    SHELLEXECUTEINFO sei;
 
329
    ZeroMemory(&sei,sizeof(sei));
 
330
    sei.cbSize = sizeof(sei);
 
331
    sei.lpFile = m_fileItem;
 
332
    sei.lpVerb = "properties";
 
333
    sei.fMask  = SEE_MASK_INVOKEIDLIST;
 
334
 
 
335
    if (!ShellExecuteEx(&sei))
 
336
    {
 
337
        MessageBox("Can't find selected file or Properties dialog", "Error",
 
338
                   MB_OK);
 
339
    }
 
340
}
 
341
 
 
342
void CLeashAboutBox::OnProperties()
 
343
{
 
344
    OnDblclkLeashModuleLb();
 
345
}
 
346
 
 
347
void CLeashAboutBox::OnSetfocusLeashModuleLb()
 
348
{
 
349
    if (m_LB_DLLsLoaded.GetCount())
 
350
        m_propertiesButton.EnableWindow(TRUE);
 
351
}
 
352
 
 
353
BOOL CLeashAboutBox::PreTranslateMessage(MSG* pMsg)
 
354
{
 
355
    if (m_missingFileError)
 
356
    {
 
357
        ::MessageBox(NULL, "OnInitDialog::We can't find file\"PSAPI.DLL\" "
 
358
                     "or \"KERNEL32.DLL\"!!!\n"
 
359
                     "About Box will not work properly.",
 
360
                     "Error", MB_OK);
 
361
 
 
362
        m_missingFileError = FALSE;
 
363
    }
 
364
    return CDialog::PreTranslateMessage(pMsg);
 
365
}