Discussion:
Java program that prompts password using systemd service
(too old to reply)
Dinesh Prasanth Moluguwan Krishnamoorthy
2018-11-28 00:07:41 UTC
Permalink
Hi,

I'm trying to write a Java program that queries user for password. The
difficulty I'm facing is, this java program is started using `systemd`
service.

I'm aware that `systemd` services are meant to run non-interactively.
I'm trying to change it based on my program's need.

I was reading about `ProcessBuilder` in Java to invoke `systemd-ask-
password` command.


public static void main(String arg[]) {
try {
ProcessBuilder pb = new
ProcessBuilder();// padd user nuxwdog:internalDB mkdtest1 @u"});
pb.command("/bin/bash", "-c", "systemd-ask-
password internaldb: --no-output");

pb.inheritIO();
Process p = pb.start();


int exitCode = p.waitFor();
assert exitCode == 0;
System.out.println(exitCode);
}
}

I get the following `journalctl` logs when I start using systemd. I'm
not prompted for password.

Nov 27 18:25:35 localhost.localdomain systemd[1]: Stopping
pki-tomcatd-***@pki-tomcat.service...
Nov 27 18:25:35 localhost.localdomain java[7034]: 143
Nov 27 18:25:35 localhost.localdomain systemd[1]:
pki-tomcatd-***@pki-tomcat.service: Main process exited,
code=exited, status=143/n/a
Nov 27 18:25:35 localhost.localdomain systemd[1]:
pki-tomcatd-***@pki-tomcat.service: Failed with result 'exit-code'.
Nov 27 18:25:35 localhost.localdomain systemd[1]: Stopped
pki-tomcatd-***@pki-tomcat.service.
Nov 27 18:25:35 localhost.localdomain systemd[1]: Started
pki-tomcatd-***@pki-tomcat.service.

Is there a way to query a password interactively from a Java program
started using a systemd service?


Thanks,
Dinesh
Lennart Poettering
2018-11-28 08:31:43 UTC
Permalink
Post by Dinesh Prasanth Moluguwan Krishnamoorthy
Hi,
I'm trying to write a Java program that queries user for password. The
difficulty I'm facing is, this java program is started using `systemd`
service.
I'm aware that `systemd` services are meant to run non-interactively.
I'm trying to change it based on my program's need.
I was reading about `ProcessBuilder` in Java to invoke `systemd-ask-
password` command.
public static void main(String arg[]) {
try {
ProcessBuilder pb = new
pb.command("/bin/bash", "-c", "systemd-ask-
password internaldb: --no-output");
pb.inheritIO();
Process p = pb.start();
Is there a way to query a password interactively from a Java program
started using a systemd service?
If you run privileged you can implement this:

https://www.freedesktop.org/wiki/Software/systemd/PasswordAgents/

i.e. listen on an AF_UNIX/SOCK_DGRAM socket (not sure you can do that
from Java though?), then drop a file /run/systemd/ask-password that
describes the question you want to ask, and wait until you get a reply
on that socket. Then delete socket and file.

Lennart
--
Lennart Poettering, Red Hat
Continue reading on narkive:
Loading...