-
Notifications
You must be signed in to change notification settings - Fork 1
/
kwif4.cc
108 lines (93 loc) · 2.76 KB
/
kwif4.cc
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
/*-
* Copyright © 2009, 2010
* mirabilos <[email protected]>
* Copyright © 2009
* Thomas Fischer <[email protected]>
*
* Provided that these terms and disclaimer and all copyright notices
* are retained or reproduced in an accompanying document, permission
* is granted to deal in this work without restriction, including un‐
* limited rights to use, publicly perform, distribute, sell, modify,
* merge, give away, or sublicence.
*
* This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
* the utmost extent permitted by applicable law, neither express nor
* implied; without malicious intent or gross negligence. In no event
* may a licensor, author or contributor be held liable for indirect,
* direct, other damage, loss, or other issues arising in any way out
* of dealing in the work, even if advised of the possibility of such
* damage or existence of a defect, except proven that it results out
* of said person’s immediate fault when using the work as intended.
*-
* KWallet interface file for Qt 4 and KDE 4
*/
#include <qstring.h>
#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <kwallet.h>
#include "kwalletcli.h"
extern "C" char *getenv(const char *);
extern "C" char *strdup(const char *);
extern "C" const char __rcsid_kwif[] =
"$MirOS: contrib/hosted/tg/code/kwalletcli/kwif4.cc,v 1.3 2016/08/30 17:37:58 tg Exp $";
extern "C" int
kw_io(const char *fld, const char *ent, const char **pwp, const char *vers)
{
int rv;
QString localwallet, qfld, qent, qpw;
KWallet::Wallet *wallet;
char *env_DISPLAY;
if (pwp == NULL)
return (KWE_ABORT);
/* very basic protection against kdeinit4 errors */
if (!(env_DISPLAY = getenv("DISPLAY")) || !*env_DISPLAY)
return (KWE_NOWALLET);
qfld = QString::fromUtf8(fld);
qent = QString::fromUtf8(ent);
if (*pwp != NULL)
qpw = QString::fromUtf8(*pwp);
/* this is ridiculous */
KAboutData aboutData("kwalletcli", 0, ki18n("KWallet CLI"), vers);
KCmdLineArgs::init(&aboutData);
KApplication app(false);
localwallet = KWallet::Wallet::LocalWallet();
wallet = KWallet::Wallet::openWallet(localwallet, 0);
if (!wallet) {
rv = KWE_NOWALLET;
goto out;
}
if (!wallet->hasFolder(qfld)) {
if (*pwp == NULL) {
rv = KWE_NOFOLDER;
goto out;
}
wallet->createFolder(qfld);
}
if (!wallet->setFolder(qfld)) {
rv = KWE_ERRFOLDER;
goto out;
}
if (*pwp == NULL) {
if (!wallet->hasEntry(qent)) {
rv = KWE_NOENTRY;
goto out;
}
qpw = "";
if (wallet->readPassword(qent, qpw)) {
rv = KWE_ERRENTRY;
goto out;
}
rv = KWE_OK_GET;
*pwp = strdup((const char *)qpw.toUtf8().data());
} else {
if (wallet->writePassword(qent, qpw)) {
rv = KWE_ERR_SET;
goto out;
}
rv = KWE_OK_SET;
}
out:
delete wallet;
return (rv);
}