--Boundary-00=_pbflDH/11UUaFKM
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I made a little hack to kwallet to able to use KWALLET_ASKPASS environment
variable same way as ssh-add uses SSH_ASKPASS (code is mostly from openssh).
I use it to get password from usb key. I was asked to post it here since some
others might be interested too.

Petri

--Boundary-00=_pbflDH/11UUaFKM
Content-Type: text/x-diff;
charset="us-ascii";
name="kwallet_askpass.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="kwallet_askpass.diff"

Index: readpass.cpp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
=2D-- readpass.cpp (revision 0)
+++ readpass.cpp (revision 0)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2001 Markus Friedl. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTI=
ES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF US=
E,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* modified from OpenSSH readpass.c by Petri Damst=E9n */
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+char *exec_askpass(const char *askpass, const char *msg)
+{
+ pid_t pid;
+ size_t len;
+ char *pass;
+ int p[2], status, ret;
+ char buf[1024];
+
+ if (fflush(stdout) !=3D 0)
+ kdDebug() << "ssh_askpass: fflush: " << strerror(errno) << endl;
+ if (askpass =3D=3D NULL) {
+ kdDebug() << "internal error: askpass undefined" << endl;
+ return NULL;
+ }
+ if (pipe(p) < 0) {
+ kdDebug() << "ssh_askpass: pipe: " << strerror(errno) << endl;
+ return NULL;
+ }
+ if ((pid =3D fork()) < 0) {
+ kdDebug() << "ssh_askpass: fork: " << strerror(errno) << endl;
+ return NULL;
+ }
+ if (pid =3D=3D 0) {
+ seteuid(getuid());
+ setuid(getuid());
+ close(p[0]);
+ if (dup2(p[1], STDOUT_FILENO) < 0){
+ kdDebug() << "ssh_askpass: dup2: " << strerror(errno) << endl;
+ return NULL;
+ }
+ execlp(askpass, askpass, msg, (char *) 0);
+ kdDebug() << "ssh_askpass: exec(" << askpass << ") : " << strerror(errno=
) << endl;
+ return NULL;
+ }
+ close(p[1]);
+
+ len =3D ret =3D 0;
+ do {
+ ret =3D read(p[0], buf + len, sizeof(buf) - 1 - len);
+ if (ret =3D=3D -1 && errno =3D=3D EINTR)
+ continue;
+ if (ret <=3D 0)
+ break;
+ len +=3D ret;
+ } while (sizeof(buf) - 1 - len > 0);
+ buf[len] =3D '\0';
+
+ close(p[0]);
+ while (waitpid(pid, &status, 0) < 0)
+ if (errno !=3D EINTR)
+ break;
+
+ if (!WIFEXITED(status) || WEXITSTATUS(status) !=3D 0) {
+ memset(buf, 0, sizeof(buf));
+ return NULL;
+ }
+
+ buf[strcspn(buf, "\r\n")] =3D '\0';
+ pass =3D strdup(buf);
+ memset(buf, 0, sizeof(buf));
+ return pass;
+}
Index: kwalletd.cpp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
=2D-- kwalletd.cpp (revision 485719)
+++ kwalletd.cpp (working copy)
@@ -24,6 +24,7 @@
#include "kwalletwizard.h"
#include "kwalletd.h"
#include "ktimeout.h"
+#include "readpass.h"
=20
#include
#include
@@ -417,21 +418,32 @@
}
=20
const char *p =3D 0L;
+ const char *askpass =3D getenv("KWALLET_ASKPASS");
while (!b->isOpen()) {
+ if(askpass)
+ {
+ QString s =3D i18n("wallet %1 password").arg(QStyleSheet::escape(walle=
t));
+ p =3D exec_askpass(askpass, s.ascii());
+ b->open(QByteArray().duplicate(p, strlen(p)));
+ break;
+ }
+ else
+ {
#ifdef Q_WS_X11
=2D XSetTransientForHint(qt_xdisplay(), kpd->winId(), w);
+ XSetTransientForHint(qt_xdisplay(), kpd->winId(), w);
#endif
=2D KWin::setState( kpd->winId(), NET::KeepAbove );
=2D KWin::setOnAllDesktops(kpd->winId(), true);
=2D if (kpd->exec() =3D=3D KDialog::Accepted) {
=2D p =3D kpd->password();
=2D int rc =3D b->open(QByteArray().duplicate(p, strlen(p)));
=2D if (!b->isOpen()) {
=2D kpd->setPrompt(i18n("Error opening the wallet '%1'. Plea=
se try again.
(Error code %2: %3)").arg(QStyleSheet::escape(wallet)).arg=
(rc).arg(KWallet::Backend:penRCToString(rc)));
=2D kpd->clearPassword();
+ KWin::setState( kpd->winId(), NET::KeepAbove );
+ KWin::setOnAllDesktops(kpd->winId(), true);
+ if (kpd->exec() =3D=3D KDialog::Accepted) {
+ p =3D kpd->password();
+ int rc =3D b->open(QByteArray().duplicate(p, strlen(p)));
+ if (!b->isOpen()) {
+ kpd->setPrompt(i18n("Error opening the wallet '%1'. Pleas=
e try again.
(Error code %2: %3)").arg(QStyleSheet::escape(wallet)).arg(=
rc).arg(KWallet::Backend:penRCToString(rc)));
+ kpd->clearPassword();
+ }
+ } else {
+ break;
}
=2D } else {
=2D break;
}
}
=20
Index: readpass.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
=2D-- readpass.h (revision 0)
+++ readpass.h (revision 0)
@@ -0,0 +1,6 @@
+#ifndef _READPASS_H_
+#define _READPASS_H_
+
+char *exec_askpass(const char *askpass, const char *msg);
+
+#endif
Index: Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3 D
=2D-- Makefile.am (revision 485719)
+++ Makefile.am (working copy)
@@ -22,7 +22,7 @@
=20
kded_kwalletd_la_LDFLAGS =3D $(all_libraries) -module -avoid-version
kded_kwalletd_la_LIBADD =3D $(LIB_KIO) ../../../kwallet/backend/libkwallet=
backend.la ../../../kwallet/client/libkwalletclient.la $(LIB_KDED)
=2Dkded_kwalletd_la_SOURCES =3D kwalletd.cpp kwalletd.skel ktimeout.cpp kwa=
lletwizard.ui kbetterthankdialogbase.ui
+kded_kwalletd_la_SOURCES =3D kwalletd.cpp kwalletd.skel ktimeout.cpp kwall=
etwizard.ui readpass.cpp kbetterthankdialogbase.ui
=20
METASOURCES =3D AUTO
=20

--Boundary-00=_pbflDH/11UUaFKM
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


--Boundary-00=_pbflDH/11UUaFKM--