Skip to content

Commit

Permalink
Fix #20508: KWallet5 isn't working
Browse files Browse the repository at this point in the history
This attempts to iterate through different KWallet versions

git-svn-id: https://josm.openstreetmap.de/osmsvn/applications/editors/josm/plugins@36339 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
  • Loading branch information
tsmock committed Sep 19, 2024
1 parent aeaab75 commit 957d205
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion native-password-manager/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!-- enter the SVN commit message -->
<property name="commit.message" value="Commit message"/>
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="18991"/>
<property name="plugin.main.version" value="19044"/>
<property name="plugin.author" value="Paul Hartmann"/>
<property name="plugin.class" value="org.openstreetmap.josm.plugins.npm.NPMPlugin"/>
<property name="plugin.description" value="Use your system''s password manager to store the API username and password. (KWallet and gnome-keyring are supported.)"/>
Expand Down
2 changes: 1 addition & 1 deletion native-password-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</developers>
<properties>
<plugin.src.dir>src</plugin.src.dir>
<plugin.main.version>18991</plugin.main.version>
<plugin.main.version>19044</plugin.main.version>
<plugin.author>Paul Hartmann</plugin.author>
<plugin.class>org.openstreetmap.josm.plugins.npm.NPMPlugin</plugin.class>
<plugin.description>Use your system''s password manager to store the API username and password. (KWallet and gnome-keyring are supported.)</plugin.description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class KWalletProvider implements KeyringProvider {
private static final Logger logger = Logger.getLogger(KWalletProvider.class.getName());
private char[] handler = "0".toCharArray();
private boolean timeoutHappened = false;
private char[] defaultLocalWallet = "kdewallet".toCharArray();
private final char[] defaultLocalWallet = "kdewallet".toCharArray();

@Override
public boolean enabled(){
Expand Down Expand Up @@ -99,7 +99,6 @@ public void save(String key, char[] password, String description){
if (result.exitCode != 0 || new String(result.retVal).equals("-1")) {
warning("save action failed");
}
return;
}
//throw new KwalletException("save");
}
Expand All @@ -112,7 +111,6 @@ public void delete(String key){
if (result.exitCode != 0 || new String(result.retVal).equals("-1")) {
warning("delete action failed");
}
return;
}
//throw new KwalletException("delete");
}
Expand All @@ -121,7 +119,7 @@ private boolean updateHandler(){
if(timeoutHappened) {
return false;
}
handler = new String(handler).equals("")? "0".toCharArray() : handler;
handler = new String(handler).isEmpty() ? "0".toCharArray() : handler;
CommandResult result = runCommand("isOpen",handler);
if(new String(result.retVal).equals("true")){
return true;
Expand Down Expand Up @@ -156,13 +154,24 @@ private boolean updateHandler(){


private CommandResult runCommand(String command,char[]... commandArgs) {
CommandResult result = null;
for (int i : new int[] {6, 5, 0}) {
result = runCommandKdeVersion(i, command, commandArgs);
if (result.exitCode == 0 && !result.errVal.equals("Service 'org.kde.kwalletd" + (i != 0 ? i : "") + "' does not exist.")) {
break;
}
}
return result;
}

private CommandResult runCommandKdeVersion(int kdeVersion, String command, char[]... commandArgs) {
String[] argv = new String[commandArgs.length+4];
argv[0] = "qdbus";
argv[1] = "org.kde.kwalletd";
argv[2] = "/modules/kwalletd";
argv[1] = "org.kde.kwalletd" + (kdeVersion != 0 ? kdeVersion : "");
argv[2] = "/modules/kwalletd" + (kdeVersion != 0 ? kdeVersion : "");
argv[3] = "org.kde.KWallet."+command;
for (int i = 0; i < commandArgs.length; i++) {
//unfortunatelly I cannot pass char[] to the exec in any way - so this poses a security issue with passwords in String() !
//unfortunately I cannot pass char[] to the exec in any way - so this poses a security issue with passwords in String() !
//TODO: find a way to avoid changing char[] into String
argv[i+4] = new String(commandArgs[i]);
}
Expand All @@ -180,7 +189,7 @@ private CommandResult runCommand(String command,char[]... commandArgs) {

String line;
while((line = input.readLine()) != null) {
if (!retVal.equals("")){
if (!retVal.isEmpty()){
retVal = retVal.concat("\n");
}
retVal = retVal.concat(line);
Expand All @@ -190,7 +199,7 @@ private CommandResult runCommand(String command,char[]... commandArgs) {

String line;
while((line = input.readLine()) != null) {
if (!errVal.equals("")){
if (!errVal.isEmpty()){
errVal = errVal.concat("\n");
}
errVal = errVal.concat(line);
Expand All @@ -203,6 +212,7 @@ private CommandResult runCommand(String command,char[]... commandArgs) {
new Object[]{exitCode, Arrays.toString(argv), errVal});
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
logger.log(Level.FINE,
"exception thrown while invoking the command \""+Arrays.toString(argv)+"\"",
ex);
Expand All @@ -223,12 +233,14 @@ private void warning(String descr) {
}

private static class CommandResult {
private int exitCode;
private char[] retVal;
private final int exitCode;
private final char[] retVal;
private final String errVal;

public CommandResult(int exitCode, char[] retVal, String errVal) {
this.exitCode = exitCode;
this.retVal = retVal;
this.errVal = errVal;
}
}

Expand Down

0 comments on commit 957d205

Please sign in to comment.