libaudit.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2012, Samsung Telecommunications of America
  3. * Copyright (C) 2014 The Android Open Source Project
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. * Written by William Roberts <[email protected]>
  18. */
  19. #ifndef _LIBAUDIT_H_
  20. #define _LIBAUDIT_H_
  21. #include <stdint.h>
  22. #include <sys/cdefs.h>
  23. #include <sys/socket.h>
  24. #include <sys/types.h>
  25. #include <linux/audit.h>
  26. #include <linux/netlink.h>
  27. __BEGIN_DECLS
  28. #define MAX_AUDIT_MESSAGE_LENGTH 8970
  29. typedef enum { GET_REPLY_BLOCKING = 0, GET_REPLY_NONBLOCKING } reply_t;
  30. /* type == AUDIT_SIGNAL_INFO */
  31. struct audit_sig_info {
  32. uid_t uid;
  33. pid_t pid;
  34. char ctx[0];
  35. };
  36. struct audit_message {
  37. struct nlmsghdr nlh;
  38. char data[MAX_AUDIT_MESSAGE_LENGTH];
  39. };
  40. /**
  41. * Opens a connection to the Audit netlink socket
  42. * @return
  43. * A valid fd on success or < 0 on error with errno set.
  44. * Returns the same errors as man 2 socket.
  45. */
  46. extern int audit_open(void);
  47. /**
  48. * Closes the fd returned from audit_open()
  49. * @param fd
  50. * The fd to close
  51. */
  52. extern void audit_close(int fd);
  53. /**
  54. *
  55. * @param fd
  56. * The fd returned by a call to audit_open()
  57. * @param rep
  58. * The response struct to store the response in.
  59. * @param block
  60. * Whether or not to block on IO
  61. * @param peek
  62. * Whether or not we are to remove the message from
  63. * the queue when we do a read on the netlink socket.
  64. * @return
  65. * This function returns 0 on success, else -errno.
  66. */
  67. extern int audit_get_reply(int fd, struct audit_message* rep, reply_t block,
  68. int peek);
  69. /**
  70. * Sets a pid to receive audit netlink events from the kernel
  71. * @param fd
  72. * The fd returned by a call to audit_open()
  73. * @param pid
  74. * The pid whom to set as the receiver of audit messages
  75. * @return
  76. * This function returns 0 on success, -errno on error.
  77. */
  78. extern int audit_setup(int fd, pid_t pid);
  79. /**
  80. * Throttle kernel messages at the provided rate
  81. * @param fd
  82. * The fd returned by a call to audit_open()
  83. * @param rate
  84. * The rate, in messages per second, above which the kernel
  85. * should drop audit messages.
  86. * @return
  87. * This function returns 0 on success, -errno on error.
  88. */
  89. extern int audit_rate_limit(int fd, uint32_t limit);
  90. __END_DECLS
  91. #endif