-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotesIPass.cpp
More file actions
126 lines (113 loc) · 3.27 KB
/
NotesIPass.cpp
File metadata and controls
126 lines (113 loc) · 3.27 KB
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
// NotesIPass.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <global.h>
#include <extmgr.h>
#include <bsafeerr.h>
#include <nsferr.h>
#include <osenv.h>
#include "KeePassHttpClient\src\KeePassHttpClient.h"
#include "NotesIPass.h"
#include <neon/ne_socket.h>
#include <neon/ne_session.h>
#include <neon/ne_request.h>
#include <neon/ne_utils.h>
#include <neon/ne_uri.h>
#ifdef _DEBUG
#define LOG(s) OutputDebugString((s).c_str());OutputDebugString(_T("\n"))
#else
#define LOG(s)
#endif
HEMREGISTRATION hHandler = 0;
bool passwordRequested = false;
tstring uuid = "";
DLL_EXPORT STATUS LNPUBLIC MainEntryPoint() {
STATUS status;
char msgBuf[256];
status = EMRegister(EM_GETPASSWORD, EM_REG_BEFORE, ExtHandler, 0, &hHandler);
if (NOERROR != status) {
wsprintf(msgBuf, "Could not register extension handler - status: 0x%lX",
status);
MessageBox(NULL, msgBuf, "NotesIPass", MB_ICONERROR | MB_OK);
}
return (status);
}
DLL_EXPORT STATUS LNPUBLIC ExtClear() {
STATUS status;
if (0 != hHandler){
status = EMDeregister(hHandler);
hHandler = 0;
}
else
status = NOERROR;
return (status);
}
STATUS LNCALLBACK ExtHandler(EMRECORD* pRecord) {
VARARG_PTR pArgs;
DWORD MaxPwdLen;
DWORD far * retLength;
char far * retPassword;
char far * FileName;
char far * OwnerName;
char buff[512];
if (EM_GETPASSWORD != pRecord->EId)
return (ERR_EM_CONTINUE);
/* check error status */
if (pRecord->Status != NOERROR)
return (ERR_EM_CONTINUE);
/* Fetch the arguments */
pArgs = pRecord->Ap;
MaxPwdLen = VARARG_GET(pArgs, DWORD);
retLength = VARARG_GET(pArgs, DWORD *);
retPassword = VARARG_GET(pArgs, char *);
FileName = VARARG_GET(pArgs, char *);
OwnerName = VARARG_GET(pArgs, char *);
/* Use the current password */
if ((NULL != retLength)
&& (NULL != retPassword))
{
KeePassHttpClient* kee;
try{
if (OSGetEnvironmentString("KeePassSettings", buff, 512))
kee = new KeePassHttpClient(buff);
else{
if (OSGetEnvironmentString("KeePassPort", buff, 512))
kee = new KeePassHttpClient(buff, "", "");
else
kee = new KeePassHttpClient("19455", "", "");
}
OSSetEnvironmentVariable("KeePassSettings", kee->Settings().c_str());
tstring url = tstring("notes://") + OwnerName;
Json::Value logins = kee->GetLogins(url, FileName);
if (logins.size() > 0)
uuid = logins[0]["Uuid"].asString();
if (passwordRequested || logins.size() == 0){
EXT_DLG_DATA data;
data.FileName = FileName;
data.MaxPwdLen = MaxPwdLen;
data.OwnerName = OwnerName;
data.retLength = retLength;
data.retPassword = retPassword;
if (IDOK != PasswordDialog(&data)){
if (kee != NULL) delete kee;
return (ERR_EM_CONTINUE);
}
kee->SetLogin(url, FileName, OwnerName, retPassword, uuid);
}
else {
tstring tmp = logins[0]["Password"].asCString();
strcpy_s(retPassword, MaxPwdLen, logins[0]["Password"].asCString());
}
if (kee != NULL) delete kee;
*retLength = strlen(retPassword);
passwordRequested = true;
return (ERR_BSAFE_EXTERNAL_PASSWORD);
}
catch (std::exception e)
{
MessageBox(NULL, e.what(), "Error in NotesIPass", MB_OK|MB_ICONERROR);
}
if (kee != NULL) delete kee;
}
return ERR_EM_CONTINUE;
}