audit_internal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*-
  2. * SPDX-License-Identifier: BSD-3-Clause
  3. *
  4. * Copyright (c) 2005-2008 Apple Inc.
  5. * Copyright (c) 2005 SPARTA, Inc.
  6. * All rights reserved.
  7. *
  8. * This code was developed in part by Robert N. M. Watson, Senior Principal
  9. * Scientist, SPARTA, Inc.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * 3. Neither the name of Apple Inc. ("Apple") nor the names of
  21. * its contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  25. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  28. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  33. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #ifndef _AUDIT_INTERNAL_H
  36. #define _AUDIT_INTERNAL_H
  37. #if defined(__linux__) && !defined(__unused)
  38. #define __unused
  39. #endif
  40. /*
  41. * audit_internal.h contains private interfaces that are shared by user space
  42. * and the kernel for the purposes of assembling audit records. Applications
  43. * should not include this file or use the APIs found within, or it may be
  44. * broken with future releases of OpenBSM, which may delete, modify, or
  45. * otherwise break these interfaces or the assumptions they rely on.
  46. */
  47. struct au_token {
  48. u_char *t_data;
  49. size_t len;
  50. TAILQ_ENTRY(au_token) tokens;
  51. };
  52. struct au_record {
  53. char used; /* Record currently in use? */
  54. int desc; /* Descriptor for record. */
  55. TAILQ_HEAD(, au_token) token_q; /* Queue of BSM tokens. */
  56. u_char *data;
  57. size_t len;
  58. LIST_ENTRY(au_record) au_rec_q;
  59. };
  60. typedef struct au_record au_record_t;
  61. /*
  62. * We could determined the header and trailer sizes by defining appropriate
  63. * structures. We hold off that approach until we have a consistent way of
  64. * using structures for all tokens. This is not straightforward since these
  65. * token structures may contain pointers of whose contents we do not know the
  66. * size (e.g text tokens).
  67. */
  68. #define AUDIT_HEADER_EX_SIZE(a) ((a)->ai_termid.at_type+18+sizeof(u_int32_t))
  69. #define AUDIT_HEADER_SIZE 18
  70. #define MAX_AUDIT_HEADER_SIZE (5*sizeof(u_int32_t)+18)
  71. #define AUDIT_TRAILER_SIZE 7
  72. /*
  73. * BSM token streams store fields in big endian byte order, so as to be
  74. * portable; when encoding and decoding, we must convert byte orders for
  75. * typed values.
  76. */
  77. #define ADD_U_CHAR(loc, val) \
  78. do { \
  79. *(loc) = (val); \
  80. (loc) += sizeof(u_char); \
  81. } while(0)
  82. #define ADD_U_INT16(loc, val) \
  83. do { \
  84. be16enc((loc), (val)); \
  85. (loc) += sizeof(u_int16_t); \
  86. } while(0)
  87. #define ADD_U_INT32(loc, val) \
  88. do { \
  89. be32enc((loc), (val)); \
  90. (loc) += sizeof(u_int32_t); \
  91. } while(0)
  92. #define ADD_U_INT64(loc, val) \
  93. do { \
  94. be64enc((loc), (val)); \
  95. (loc) += sizeof(u_int64_t); \
  96. } while(0)
  97. #define ADD_MEM(loc, data, size) \
  98. do { \
  99. memcpy((loc), (data), (size)); \
  100. (loc) += size; \
  101. } while(0)
  102. #define ADD_STRING(loc, data, size) ADD_MEM(loc, data, size)
  103. #endif /* !_AUDIT_INTERNAL_H_ */