audit_internal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * $FreeBSD$
  36. */
  37. #ifndef _AUDIT_INTERNAL_H
  38. #define _AUDIT_INTERNAL_H
  39. #if defined(__linux__) && !defined(__unused)
  40. #define __unused
  41. #endif
  42. /*
  43. * audit_internal.h contains private interfaces that are shared by user space
  44. * and the kernel for the purposes of assembling audit records. Applications
  45. * should not include this file or use the APIs found within, or it may be
  46. * broken with future releases of OpenBSM, which may delete, modify, or
  47. * otherwise break these interfaces or the assumptions they rely on.
  48. */
  49. struct au_token {
  50. u_char *t_data;
  51. size_t len;
  52. TAILQ_ENTRY(au_token) tokens;
  53. };
  54. struct au_record {
  55. char used; /* Record currently in use? */
  56. int desc; /* Descriptor for record. */
  57. TAILQ_HEAD(, au_token) token_q; /* Queue of BSM tokens. */
  58. u_char *data;
  59. size_t len;
  60. LIST_ENTRY(au_record) au_rec_q;
  61. };
  62. typedef struct au_record au_record_t;
  63. /*
  64. * We could determined the header and trailer sizes by defining appropriate
  65. * structures. We hold off that approach until we have a consistent way of
  66. * using structures for all tokens. This is not straightforward since these
  67. * token structures may contain pointers of whose contents we do not know the
  68. * size (e.g text tokens).
  69. */
  70. #define AUDIT_HEADER_EX_SIZE(a) ((a)->ai_termid.at_type+18+sizeof(u_int32_t))
  71. #define AUDIT_HEADER_SIZE 18
  72. #define MAX_AUDIT_HEADER_SIZE (5*sizeof(u_int32_t)+18)
  73. #define AUDIT_TRAILER_SIZE 7
  74. /*
  75. * BSM token streams store fields in big endian byte order, so as to be
  76. * portable; when encoding and decoding, we must convert byte orders for
  77. * typed values.
  78. */
  79. #define ADD_U_CHAR(loc, val) \
  80. do { \
  81. *(loc) = (val); \
  82. (loc) += sizeof(u_char); \
  83. } while(0)
  84. #define ADD_U_INT16(loc, val) \
  85. do { \
  86. be16enc((loc), (val)); \
  87. (loc) += sizeof(u_int16_t); \
  88. } while(0)
  89. #define ADD_U_INT32(loc, val) \
  90. do { \
  91. be32enc((loc), (val)); \
  92. (loc) += sizeof(u_int32_t); \
  93. } while(0)
  94. #define ADD_U_INT64(loc, val) \
  95. do { \
  96. be64enc((loc), (val)); \
  97. (loc) += sizeof(u_int64_t); \
  98. } while(0)
  99. #define ADD_MEM(loc, data, size) \
  100. do { \
  101. memcpy((loc), (data), (size)); \
  102. (loc) += size; \
  103. } while(0)
  104. #define ADD_STRING(loc, data, size) ADD_MEM(loc, data, size)
  105. #endif /* !_AUDIT_INTERNAL_H_ */