Hide lsnrctl password from users

From Oracle FAQ
Jump to: navigation, search

Small C-program to allow users to get a listener status without having to specify the listener's password.

It's required to embed the password in a compiled language (like C), and not a scripting language. Reason is that users require read access on scripts to be able to execute them. If the password is embedded in a C-program, users need only execute permissions on the program.

/* -------------------------------------------------------------------------
 * Execute listener status without showing the listener password
 * Compile: $ cc lsnrctl_status.c -o lsnrctl_status
 * Run:     $ ./lsnrctl_status orcl
 * -------------------------------------------------------------------------
**/

#include <stdlib.h>

int main(int argc, char *argv[]) {
  char cmd[80];

  if (argc > 1) {
    printf("Get status of listener %s\n", argv[1]);
  } else {
    printf("No listener name specified.\n");
    return -1;
  }

  sprintf(cmd, "lsnrctl <<_eof\nset password FEDE3B12CF2978B9\nstatus %s\n_eof", argv[1]);
  system(cmd);

  return 0;
}