1
0

hook_log.c 747 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 <unistd.h>
  10. #include <sys/types.h>
  11. #include <pwd.h>
  12. #include "clish/shell.h"
  13. #define SYSLOG_IDENT "klish"
  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 = NULL;
  20. /* Initialization */
  21. if (!line) {
  22. openlog(SYSLOG_IDENT, LOG_PID,
  23. clish_shell__get_log_facility(this));
  24. return 0;
  25. }
  26. uname = clish_shell_format_username(this);
  27. syslog(LOG_INFO, "%u(%s) %s : %d",
  28. user ? user->pw_uid : getuid(), uname, line, retcode);
  29. free(uname);
  30. return 0;
  31. }