dblogin: Test an Informix Login
dblogin is a small ESQL/C utility that tests whether a
given username and password can actually log in to an Informix®
server, and reports what the session sees once connected — the
CURRENT user, DBINFO('dbhostname'), and the
server version — as one JSON object or a single raw line.
Deliberately minimal: no schema access beyond
systables, which exists in every database on every
version. Full source:
dblogin.ec.
Build
esql -o dblogin dblogin.ec. The password-prompt length
limit is detected per platform (unlimited on Linux via glibc's
getpass(), 256 on Solaris via getpassphrase(),
128 on the BSDs, the platform's own PASS_MAX where
published) — override with -DDBLOGIN_PROMPT_MAX=N
at build time if a platform's real limit isn't one of those.
Usage
Two calling shapes. The first reads credentials as two lines on stdin, so a password never appears as a process argument:
$ dblogin ALIAS <<'EOF' myuser mypassword EOF
The second takes flags, prompting for the password (no echo) if
--password is omitted:
$ dblogin --server ALIAS --username myuser Database password:
Full option list: --server ALIAS (or
--informixserver), --username USER (or
--user), --password PASS,
--sqlhosts PATH (to point at a non-default sqlhosts file
before connecting), --database NAME (default
sysmaster), and --output json|raw.
Output
JSON (the default):
{"success":true,"sqlcode":0,"current":"myuser","host":"zeus","version":"IBM Informix Dynamic Server Version 14.10..."}
Raw (--output raw): the same three fields, space-separated,
for shell scripting without a JSON parser:
myuser zeus IBM Informix Dynamic Server Version 14.10...
On failure, both formats report sqlcode and the real
Informix error text rather than a bare exit code alone:
{"success":false,"sqlcode":-951,"isam":0,"stage":"connect","error":"Incorrect password or user myuser@host[alias] is not known on the database server."}
Exit codes
0 success, 1 SQL failure (connect or query),
2 input/usage failure (bad arguments, unreadable sqlhosts,
a password that reached the platform's no-echo prompt limit and may
have been silently truncated).