hook_log.c 728 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. /*--------------------------------------------------------- */
  14. CLISH_HOOK_LOG(clish_hook_log)
  15. {
  16. clish_shell_t *this = clish_context__get_shell(clish_context);
  17. struct passwd *user = NULL;
  18. char *uname = "unknown";
  19. /* Initialization */
  20. if (!line) {
  21. openlog(SYSLOG_IDENT, LOG_PID,
  22. clish_shell__get_facility(this));
  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. }