| 1 | /* |
| 2 | * Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * "Daniel Kopecek" <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 24 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 25 | #endif |
| 26 | |
| 27 | #include <pthread.h> |
| 28 | |
| 29 | #include "generic/bitmap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/generic/bitmap.h`/ |
| 30 | #include "seap-descriptor.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/seap-descriptor.h`/ |
| 31 | #include "_sexp-atomic.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_sexp-atomic.h`/ |
| 32 | |
| 33 | SEAP_desctable_tcxx . . $ SEAP_desctable_t# *SEAP_desctable_newcxx . . $ SEAP_desctable_new(3edbe157c33b3149). (void) |
| 34 | { |
| 35 | SEAP_desctable_tcxx . . $ SEAP_desctable_t# *t = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(SEAP_desctable_tcxx . . $ SEAP_desctable_t#)); |
| 36 | t->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 37 | t->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 38 | |
| 39 | return(t); |
| 40 | } |
| 41 | |
| 42 | int SEAP_desc_addcxx . . $ SEAP_desc_add(4bfd83e388c9f71b).(SEAP_desctable_tcxx . . $ SEAP_desctable_t# *sd_table, SEAP_scheme_tcxx . . $ SEAP_scheme_t# scheme, |
| 43 | void *scheme_data) |
| 44 | { |
| 45 | bitmap_bitn_tcxx . . $ bitmap_bitn_t# sd; |
| 46 | pthread_mutexattr_tcxx . . $ pthread_mutexattr_t# mutex_attr; |
| 47 | SEAP_desc_tcxx . . $ SEAP_desc_t# *sd_dsc; |
| 48 | |
| 49 | if (sd_table->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 50 | sd_table->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap. = bitmap_newcxx . . $ bitmap_new(538d52d70ff53ed1).(128); /* XXX: hardcoded size */ |
| 51 | if (sd_table->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 52 | return (-1); |
| 53 | |
| 54 | sd = bitmap_setfreecxx . . $ bitmap_setfree(51a957349079d69a). (sd_table->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap.); |
| 55 | |
| 56 | if (sd >= 0) { |
| 57 | if (sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 58 | sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree. = rbt_i32_newcxx . . $ rbt_i32_new(557e4aca7c153cb).(); |
| 59 | |
| 60 | sd_dsc = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(SEAP_desc_tcxx . . $ SEAP_desc_t#)); |
| 61 | |
| 62 | sd_dsc->next_idcxx . . $ $anonymous_type_5b6d52305350878e_0#next_id. = 0; |
| 63 | /* sd_dsc->sexpcnt = 0; */ |
| 64 | sd_dsc->schemecxx . . $ $anonymous_type_5b6d52305350878e_0#scheme. = scheme; |
| 65 | sd_dsc->scheme_datacxx . . $ $anonymous_type_5b6d52305350878e_0#scheme_data. = scheme_data; |
| 66 | sd_dsc->next_cidcxx . . $ $anonymous_type_5b6d52305350878e_0#next_cid. = 0; |
| 67 | sd_dsc->cmd_c_tablecxx . . $ $anonymous_type_5b6d52305350878e_0#cmd_c_table. = SEAP_cmdtbl_newcxx . . $ SEAP_cmdtbl_new(d478133e2e207a3d). (); |
| 68 | sd_dsc->cmd_w_tablecxx . . $ $anonymous_type_5b6d52305350878e_0#cmd_w_table. = SEAP_cmdtbl_newcxx . . $ SEAP_cmdtbl_new(d478133e2e207a3d). (); |
| 69 | sd_dsc->msg_queuecxx . . $ $anonymous_type_5b6d52305350878e_0#msg_queue. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 70 | sd_dsc->err_queuecxx . . $ $anonymous_type_5b6d52305350878e_0#err_queue. = rbt_i32_newcxx . . $ rbt_i32_new(557e4aca7c153cb).(); |
| 71 | sd_dsc->cmd_queuecxx . . $ $anonymous_type_5b6d52305350878e_0#cmd_queue. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 72 | |
| 73 | SEAP_packetq_initcxx . . $ SEAP_packetq_init(112d135064bed797).(&sd_dsc->pck_queuecxx . . $ $anonymous_type_5b6d52305350878e_0#pck_queue.); |
| 74 | |
| 75 | pthread_mutexattr_initcxx . . $ pthread_mutexattr_init(7099fa328d29ec1). (&mutex_attr); |
| 76 | pthread_mutexattr_settypecxx . . $ pthread_mutexattr_settype(490643a50482da1c). (&mutex_attr, PTHREAD_MUTEX_RECURSIVEcxx . . $ PTHREAD_MUTEX_RECURSIVE.); |
| 77 | |
| 78 | pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa). (&(sd_dsc->r_lockcxx . . $ $anonymous_type_5b6d52305350878e_0#r_lock.), &mutex_attr); |
| 79 | pthread_mutex_initcxx . . $ pthread_mutex_init(db9d29dab44ea1aa). (&(sd_dsc->w_lockcxx . . $ $anonymous_type_5b6d52305350878e_0#w_lock.), &mutex_attr); |
| 80 | |
| 81 | pthread_mutexattr_destroycxx . . $ pthread_mutexattr_destroy(7099fa328d29ec1). (&mutex_attr); |
| 82 | |
| 83 | if (rbt_i32_addcxx . . $ rbt_i32_add(3215e2e734e57b31).(sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree., (int32_tcxx . . $ int32_t#)sd, (void *)sd_dsc, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) != 0) { |
| 84 | SEAP_desc_freecxx . . $ SEAP_desc_free(13ce8cd49ba0beb5).(sd_dsc); |
| 85 | return (-1); |
| 86 | } |
| 87 | |
| 88 | return ((int)sd); |
| 89 | } |
| 90 | |
| 91 | return (-1); |
| 92 | } |
| 93 | |
| 94 | int SEAP_desc_delcxx . . $ SEAP_desc_del(ad0fa72a6b5db2). (SEAP_desctable_tcxx . . $ SEAP_desctable_t# *sd_table, int sd) |
| 95 | { |
| 96 | SEAP_desc_tcxx . . $ SEAP_desc_t# *dsc = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 97 | |
| 98 | if (sd < 0) { |
| 99 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 100 | return (-1); |
| 101 | } |
| 102 | |
| 103 | if (sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 104 | return (-1); |
| 105 | |
| 106 | if (rbt_i32_delcxx . . $ rbt_i32_del(fbdfcf5a3c6c46ec).(sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree., sd, (void *)&dsc) != 0) |
| 107 | return (-1); |
| 108 | |
| 109 | bitmap_unsetcxx . . $ bitmap_unset(67e573966af952d7).(sd_table->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap., sd); |
| 110 | |
| 111 | if (dsc != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 112 | SEAP_desc_freecxx . . $ SEAP_desc_free(13ce8cd49ba0beb5).(dsc); |
| 113 | |
| 114 | return (0); |
| 115 | } |
| 116 | |
| 117 | static void __SEAP_desc_errqueue_free_cbcxx . . $ __SEAP_desc_errqueue_free_cb(5d3939e05c3402e7).(struct rbt_i32_nodecxx . . $ rbt_i32_node# *n) |
| 118 | { |
| 119 | SEAP_error_freecxx . . $ SEAP_error_free(7b4adf922bbc6529).(n->datacxx . . $ rbt_i32_node#data.); |
| 120 | } |
| 121 | |
| 122 | void SEAP_desc_freecxx . . $ SEAP_desc_free(13ce8cd49ba0beb5).(SEAP_desc_tcxx . . $ SEAP_desc_t# *dsc) |
| 123 | { |
| 124 | SEAP_cmdtbl_freecxx . . $ SEAP_cmdtbl_free(52f2919cbb21a2a).(dsc->cmd_c_tablecxx . . $ $anonymous_type_5b6d52305350878e_0#cmd_c_table.); |
| 125 | SEAP_cmdtbl_freecxx . . $ SEAP_cmdtbl_free(52f2919cbb21a2a).(dsc->cmd_w_tablecxx . . $ $anonymous_type_5b6d52305350878e_0#cmd_w_table.); |
| 126 | SEAP_packetq_freecxx . . $ SEAP_packetq_free(b0f42a28b90020d2).(&dsc->pck_queuecxx . . $ $anonymous_type_5b6d52305350878e_0#pck_queue.); |
| 127 | pthread_mutex_destroycxx . . $ pthread_mutex_destroy(d89ae235521888f9).(&(dsc->r_lockcxx . . $ $anonymous_type_5b6d52305350878e_0#r_lock.)); |
| 128 | pthread_mutex_destroycxx . . $ pthread_mutex_destroy(d89ae235521888f9).(&(dsc->w_lockcxx . . $ $anonymous_type_5b6d52305350878e_0#w_lock.)); |
| 129 | rbt_i32_free_cbcxx . . $ rbt_i32_free_cb(bb6fef081ac885b3).(dsc->err_queuecxx . . $ $anonymous_type_5b6d52305350878e_0#err_queue., __SEAP_desc_errqueue_free_cbcxx . . $ __SEAP_desc_errqueue_free_cb(5d3939e05c3402e7).); |
| 130 | freecxx . . $ free(5d22bdacc48458e8).(dsc); |
| 131 | } |
| 132 | |
| 133 | static void SEAP_desc_free_nodecxx . . $ SEAP_desc_free_node(5d3939e05c3402e7).(struct rbt_i32_nodecxx . . $ rbt_i32_node# *n) |
| 134 | { |
| 135 | SEAP_desc_freecxx . . $ SEAP_desc_free(13ce8cd49ba0beb5).(n->datacxx . . $ rbt_i32_node#data.); |
| 136 | } |
| 137 | |
| 138 | void SEAP_desctable_freecxx . . $ SEAP_desctable_free(dcdcf0775e6a3e02).(SEAP_desctable_tcxx . . $ SEAP_desctable_t# *sd_table) |
| 139 | { |
| 140 | if (sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 141 | rbt_i32_free_cbcxx . . $ rbt_i32_free_cb(bb6fef081ac885b3).(sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree., &SEAP_desc_free_nodecxx . . $ SEAP_desc_free_node(5d3939e05c3402e7).); |
| 142 | if (sd_table->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 143 | bitmap_freecxx . . $ bitmap_free(80bd7b4154c2ebf9).(sd_table->bmapcxx . . $ $anonymous_type_5317b32fcdb93fc7_0#bmap.); |
| 144 | freecxx . . $ free(5d22bdacc48458e8).(sd_table); |
| 145 | } |
| 146 | |
| 147 | SEAP_desc_tcxx . . $ SEAP_desc_t# *SEAP_desc_getcxx . . $ SEAP_desc_get(b324436d5ff0f8fe). (SEAP_desctable_tcxx . . $ SEAP_desctable_t# *sd_table, int sd) |
| 148 | { |
| 149 | SEAP_desc_tcxx . . $ SEAP_desc_t# *dsc = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 150 | |
| 151 | if (sd < 0 || sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 152 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EBADFcxx . . $ `<external>/8987895939074593727/errno-base.h:13:9`!; |
| 153 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 154 | } |
| 155 | |
| 156 | if (rbt_i32_getcxx . . $ rbt_i32_get(fbdfcf5a3c6c46ec).(sd_table->treecxx . . $ $anonymous_type_5317b32fcdb93fc7_0#tree., sd, (void *)&dsc) != 0) { |
| 157 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EBADFcxx . . $ `<external>/8987895939074593727/errno-base.h:13:9`!; |
| 158 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 159 | } |
| 160 | |
| 161 | return(dsc); |
| 162 | } |
| 163 | |
| 164 | SEAP_msgid_tcxx . . $ SEAP_msgid_t# SEAP_desc_genmsgidcxx . . $ SEAP_desc_genmsgid(c52f604638ef6a39). (SEAP_desctable_tcxx . . $ SEAP_desctable_t# *sd_table, int sd) |
| 165 | { |
| 166 | SEAP_desc_tcxx . . $ SEAP_desc_t# *dsc; |
| 167 | SEAP_msgid_tcxx . . $ SEAP_msgid_t# id; |
| 168 | dsc = SEAP_desc_getcxx . . $ SEAP_desc_get(b324436d5ff0f8fe). (sd_table, sd); |
| 169 | |
| 170 | if (dsc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 171 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 172 | return (-1); |
| 173 | } |
| 174 | |
| 175 | #if SEAP_MSGID_BITScxx . . $ `build/config.h:61:9`! == 64 |
| 176 | id = SEXP_atomic_inc_u64 (&(dsc->next_id)); |
| 177 | #else |
| 178 | id = SEXP_atomic_inc_u32cxx . . $ SEXP_atomic_inc_u32(48ceeaa61d58e9a9). (&(dsc->next_idcxx . . $ $anonymous_type_5b6d52305350878e_0#next_id.)); |
| 179 | #endif |
| 180 | return (id); |
| 181 | } |
| 182 | |
| 183 | SEAP_cmdid_tcxx . . $ SEAP_cmdid_t# SEAP_desc_gencmdidcxx . . $ SEAP_desc_gencmdid(bbbb35498d66006b). (SEAP_desctable_tcxx . . $ SEAP_desctable_t# *sd_table, int sd) |
| 184 | { |
| 185 | SEAP_desc_tcxx . . $ SEAP_desc_t# *dsc; |
| 186 | SEAP_cmdid_tcxx . . $ SEAP_cmdid_t# id; |
| 187 | |
| 188 | dsc = SEAP_desc_getcxx . . $ SEAP_desc_get(b324436d5ff0f8fe). (sd_table, sd); |
| 189 | |
| 190 | if (dsc == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 191 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 192 | return (-1); |
| 193 | } |
| 194 | |
| 195 | id = SEXP_atomic_inc_u16cxx . . $ SEXP_atomic_inc_u16(d0497ca61a8ba429). (&(dsc->next_cidcxx . . $ $anonymous_type_5b6d52305350878e_0#next_cid.)); |
| 196 | |
| 197 | return (id); |
| 198 | } |