1
0

hook_log.c 781 B

12345678910111213141516171819202122232425262728293031323334353637
  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_context_t *context = (clish_context_t *)clish_context;
  18. clish_shell_t *this = context->shell;
  19. struct passwd *user = NULL;
  20. char *uname = "unknown";
  21. /* Initialization */
  22. if (!line) {
  23. openlog(SYSLOG_IDENT, LOG_PID, SYSLOG_FACILITY);
  24. return 0;
  25. }
  26. /* Log the given line */
  27. if ((user = clish_shell__get_user(this)))
  28. uname = user->pw_name;
  29. syslog(LOG_INFO, "(%s) %s : %d", uname, line, retcode);
  30. return 0;
  31. }