hook_log.c 744 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * callback_log.c
  3. *
  4. * Callback hook to log users's commands
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <syslog.h>
  9. #include <sys/types.h>
  10. #include <pwd.h>
  11. #include "clish/shell.h"
  12. #define SYSLOG_IDENT "klish"
  13. #define SYSLOG_FACILITY LOG_LOCAL0
  14. /*--------------------------------------------------------- */
  15. CLISH_HOOK_LOG(clish_hook_log)
  16. {
  17. clish_shell_t *this = clish_context__get_shell(clish_context);
  18. struct passwd *user = NULL;
  19. char *uname = "unknown";
  20. /* Initialization */
  21. if (!line) {
  22. openlog(SYSLOG_IDENT, LOG_PID, SYSLOG_FACILITY);
  23. return 0;
  24. }
  25. /* Log the given line */
  26. if ((user = clish_shell__get_user(this)))
  27. uname = user->pw_name;
  28. syslog(LOG_INFO, "(%s) %s : %d", uname, line, retcode);
  29. return 0;
  30. }