| 1 | /** |
| 2 | * @file entcmp.c |
| 3 | * @author "Tomas Heinrich" <[email protected]> |
| 4 | * |
| 5 | * @addtogroup PROBEAPI |
| 6 | * @{ |
| 7 | */ |
| 8 | /* |
| 9 | * Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 10 | * All Rights Reserved. |
| 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Lesser General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2.1 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Lesser General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 | * |
| 26 | * Authors: |
| 27 | * Tomas Heinrich <[email protected]> |
| 28 | */ |
| 29 | |
| 30 | #ifdef HAVE_CONFIG_H |
| 31 | #include <config.h> |
| 32 | #endif |
| 33 | |
| 34 | #include <sexp.h> |
| 35 | #include <assert.h> |
| 36 | #include <string.h> |
| 37 | #include <stdarg.h> |
| 38 | #include <errno.h> |
| 39 | #ifdef OS_WINDOWS |
| 40 | #include <winsock2.h> |
| 41 | #else |
| 42 | #include <arpa/inet.h> |
| 43 | #include <sys/socket.h> |
| 44 | #endif |
| 45 | |
| 46 | #include "common/debug_priv.h" |
| 47 | #include "entcmp.h" |
| 48 | #include "../_probe-api.h" |
| 49 | #include "../../results/oval_cmp_basic_impl.h" |
| 50 | #include "../../results/oval_cmp_evr_string_impl.h" |
| 51 | #include "../../results/oval_cmp_ip_address_impl.h" |
| 52 | |
| 53 | oval_result_t probe_ent_cmp_binary(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 54 | { |
| 55 | oval_result_t result = OVAL_RESULT_ERROR; |
| 56 | char *s1, *s2; |
| 57 | |
| 58 | s1 = SEXP_string_cstr(val1); |
| 59 | s2 = SEXP_string_cstr(val2); |
| 60 | |
| 61 | result = oval_binary_cmp(s1, s2, op); |
| 62 | |
| 63 | free(s1); |
| 64 | free(s2); |
| 65 | |
| 66 | return result; |
| 67 | } |
| 68 | |
| 69 | oval_result_t probe_ent_cmp_bool(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 70 | { |
| 71 | int v1, v2; |
| 72 | |
| 73 | v1 = SEXP_number_geti_32(val1); |
| 74 | v2 = SEXP_number_geti_32(val2); |
| 75 | |
| 76 | return oval_boolean_cmp(v1, v2, op); |
| 77 | } |
| 78 | |
| 79 | oval_result_t probe_ent_cmp_evr(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 80 | { |
| 81 | oval_result_t result = OVAL_RESULT_ERROR; |
| 82 | char *s1 = SEXP_string_cstr(val1); |
| 83 | char *s2 = SEXP_string_cstr(val2); |
| 84 | |
| 85 | result = oval_evr_string_cmp(s1, s2, op); |
| 86 | |
| 87 | free(s1); |
| 88 | free(s2); |
| 89 | return result; |
| 90 | } |
| 91 | |
| 92 | oval_result_t probe_ent_cmp_debian_evr(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 93 | { |
| 94 | oval_result_t result = OVAL_RESULT_ERROR; |
| 95 | char *s1 = SEXP_string_cstr(val1); |
| 96 | char *s2 = SEXP_string_cstr(val2); |
| 97 | |
| 98 | result = oval_debian_evr_string_cmp(s1, s2, op); |
| 99 | |
| 100 | free(s1); |
| 101 | free(s2); |
| 102 | return result; |
| 103 | } |
| 104 | |
| 105 | oval_result_t probe_ent_cmp_filesetrev(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 106 | { |
| 107 | oval_result_t result = OVAL_RESULT_ERROR; |
| 108 | |
| 109 | // todo: |
| 110 | |
| 111 | return result; |
| 112 | } |
| 113 | |
| 114 | oval_result_t probe_ent_cmp_float(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 115 | { |
| 116 | double v1, v2; |
| 117 | |
| 118 | v1 = SEXP_number_getf(val1); |
| 119 | v2 = SEXP_number_getf(val2); |
| 120 | |
| 121 | return oval_float_cmp(v1, v2, op); |
| 122 | } |
| 123 | |
| 124 | oval_result_t probe_ent_cmp_int(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 125 | { |
| 126 | oval_result_t result = OVAL_RESULT_ERROR; |
| 127 | int64_t v1, v2; |
| 128 | |
| 129 | v1 = SEXP_number_geti_64(val1); |
| 130 | v2 = SEXP_number_geti_64(val2); |
| 131 | |
| 132 | result = oval_int_cmp(v1, v2, op); |
| 133 | |
| 134 | return result; |
| 135 | } |
| 136 | |
| 137 | oval_result_t probe_ent_cmp_ios(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 138 | { |
| 139 | oval_result_t result = OVAL_RESULT_ERROR; |
| 140 | |
| 141 | // todo: |
| 142 | |
| 143 | return result; |
| 144 | } |
| 145 | |
| 146 | oval_result_t probe_ent_cmp_version(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 147 | { |
| 148 | char *state_version = SEXP_string_cstr(val1); |
| 149 | char *sys_version = SEXP_string_cstr(val2); |
| 150 | |
| 151 | oval_result_t result = oval_versiontype_cmp(state_version, sys_version, op); |
| 152 | |
| 153 | free(state_version); |
| 154 | free(sys_version); |
| 155 | return result; |
| 156 | } |
| 157 | |
| 158 | oval_result_t probe_ent_cmp_string(SEXP_t * val1, SEXP_t * val2, oval_operation_t op) |
| 159 | { |
| 160 | oval_result_t result = OVAL_RESULT_ERROR; |
| 161 | char *s1, *s2; |
| 162 | |
| 163 | s1 = SEXP_string_cstr(val1); |
| 164 | s2 = SEXP_string_cstr(val2); |
| 165 | |
| 166 | result = oval_string_cmp(s1, s2, op); |
| 167 | |
| 168 | free(s1); |
| 169 | free(s2); |
| 170 | |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | static oval_result_t probe_ent_cmp_ipaddr(int af, SEXP_t *val1, SEXP_t *val2, oval_operation_t op) |
| 175 | { |
| 176 | oval_result_t result = OVAL_RESULT_ERROR; |
| 177 | char *addr1 = SEXP_string_cstr(val1); |
| 178 | char *addr2 = SEXP_string_cstr(val2); |
| 179 | |
| 180 | result = oval_ipaddr_cmp(af, addr1, addr2, op); |
| 181 | |
| 182 | free(addr1); |
| 183 | free(addr2); |
| 184 | return result; |
| 185 | } |
| 186 | |
| 187 | static inline oval_result_t probe_ent_cmp_single(SEXP_t *state_ent, oval_datatype_t state_data_type, SEXP_t *sysent, oval_operation_t op) |
| 188 | { |
| 189 | // This compares a single entity of a state with a single entity of a sysitem |
| 190 | // This is very similar to oval_ent_cmp_str, we hope to get a rid of this soon |
| 191 | |
| 192 | switch (state_data_type) { |
| 193 | case OVAL_DATATYPE_BINARY: |
| 194 | return probe_ent_cmp_binary(state_ent, sysent, op); |
| 195 | case OVAL_DATATYPE_BOOLEAN: |
| 196 | return probe_ent_cmp_bool(state_ent, sysent, op); |
| 197 | case OVAL_DATATYPE_EVR_STRING: |
| 198 | return probe_ent_cmp_evr(state_ent, sysent, op); |
| 199 | case OVAL_DATATYPE_DEBIAN_EVR_STRING: |
| 200 | return probe_ent_cmp_debian_evr(state_ent, sysent, op); |
| 201 | case OVAL_DATATYPE_FILESET_REVISION: |
| 202 | return probe_ent_cmp_filesetrev(state_ent, sysent, op); |
| 203 | case OVAL_DATATYPE_FLOAT: |
| 204 | return probe_ent_cmp_float(state_ent, sysent, op); |
| 205 | case OVAL_DATATYPE_IOS_VERSION: |
| 206 | return probe_ent_cmp_ios(state_ent, sysent, op); |
| 207 | case OVAL_DATATYPE_VERSION: |
| 208 | return probe_ent_cmp_version(state_ent, sysent, op); |
| 209 | case OVAL_DATATYPE_INTEGER: |
| 210 | return probe_ent_cmp_int(state_ent, sysent, op); |
| 211 | case OVAL_DATATYPE_STRING: |
| 212 | return probe_ent_cmp_string(state_ent, sysent, op); |
| 213 | case OVAL_DATATYPE_IPV4ADDR: |
| 214 | return probe_ent_cmp_ipaddr(AF_INET, state_ent, sysent, op); |
| 215 | case OVAL_DATATYPE_IPV6ADDR: |
| 216 | return probe_ent_cmp_ipaddr(AF_INET6, state_ent, sysent, op); |
| 217 | default: |
| 218 | dI("Unexpected data type: %d", state_data_type); |
| 219 | break; |
| 220 | } |
| 221 | |
| 222 | return OVAL_RESULT_ERROR; |
| 223 | } |
| 224 | |
| 225 | static oval_result_t probe_ent_cmp(SEXP_t * ent, SEXP_t * val2) |
| 226 | { |
| 227 | oval_operation_t op; |
| 228 | oval_datatype_t dtype; |
| 229 | SEXP_t *stmp, *val1, *vals, *res_lst, *r0; |
| 230 | int val_cnt, is_var; |
| 231 | oval_check_t ochk; |
| 232 | oval_result_t ores, result; |
| 233 | |
| 234 | ores = OVAL_RESULT_ERROR; |
| 235 | result = OVAL_RESULT_ERROR; |
| 236 | vals = NULL; |
| 237 | val_cnt = probe_ent_getvals(ent, &vals); |
| 238 | |
| 239 | if (probe_ent_attrexists(ent, "var_ref")) { |
| 240 | is_var = 1; |
| 241 | } else { |
| 242 | if (val_cnt != 1) { |
| 243 | SEXP_free(vals); |
| 244 | return OVAL_RESULT_ERROR; |
| 245 | } |
| 246 | |
| 247 | is_var = 0; |
| 248 | } |
| 249 | |
| 250 | dtype = probe_ent_getdatatype(ent); |
| 251 | stmp = probe_ent_getattrval(ent, "operation"); |
| 252 | if (stmp == NULL) |
| 253 | op = OVAL_OPERATION_EQUALS; |
| 254 | else |
| 255 | op = SEXP_number_geti_32(stmp); |
| 256 | SEXP_free(stmp); |
| 257 | res_lst = SEXP_list_new(NULL); |
| 258 | |
| 259 | SEXP_list_foreach(val1, vals) { |
| 260 | if (SEXP_typeof(val1) != SEXP_typeof(val2)) { |
| 261 | dI("Types of values to compare don't match: val1: %d, val2: %d", |
| 262 | SEXP_typeof(val1), SEXP_typeof(val2)); |
| 263 | |
| 264 | SEXP_free(vals); |
| 265 | SEXP_free(val1); |
| 266 | SEXP_free(res_lst); |
| 267 | |
| 268 | return OVAL_RESULT_ERROR; |
| 269 | } |
| 270 | |
| 271 | ores = probe_ent_cmp_single(val1, dtype, val2, op); |
| 272 | |
| 273 | SEXP_list_add(res_lst, r0 = SEXP_number_newi_32(ores)); |
| 274 | SEXP_free(r0); |
| 275 | } |
| 276 | |
| 277 | if (is_var) { |
| 278 | stmp = probe_ent_getattrval(ent, "var_check"); |
| 279 | if (stmp == NULL) { |
| 280 | ochk = OVAL_CHECK_ALL; |
| 281 | } else { |
| 282 | ochk = SEXP_number_geti_32(stmp); |
| 283 | SEXP_free(stmp); |
| 284 | } |
| 285 | |
| 286 | result = probe_ent_result_bychk(res_lst, ochk); |
| 287 | } else { |
| 288 | result = ores; |
| 289 | } |
| 290 | |
| 291 | SEXP_free(res_lst); |
| 292 | SEXP_free(vals); |
| 293 | |
| 294 | return result; |
| 295 | } |
| 296 | |
| 297 | static oval_result_t _probe_entste_cmp_record(SEXP_t *ent_ste, SEXP_t *ent_itm) |
| 298 | { |
| 299 | oval_result_t res; |
| 300 | oval_operation_t op; |
| 301 | oval_check_t ochk; |
| 302 | SEXP_t *stmp, *ste_res, *ste_record_fields, *ste_rf, *itm_record_fields; |
| 303 | int val_cnt; |
| 304 | |
| 305 | stmp = probe_ent_getattrval(ent_ste, "operation"); |
| 306 | if (stmp == NULL) { |
| 307 | op = OVAL_OPERATION_EQUALS; |
| 308 | } else { |
| 309 | op = SEXP_number_getu(stmp); |
| 310 | SEXP_free(stmp); |
| 311 | if (op != OVAL_OPERATION_EQUALS) |
| 312 | return OVAL_RESULT_ERROR; |
| 313 | } |
| 314 | |
| 315 | val_cnt = probe_ent_getvals(ent_ste, &ste_record_fields); |
| 316 | if (val_cnt <= 0) { |
| 317 | SEXP_free(ste_record_fields); |
| 318 | return OVAL_RESULT_ERROR; |
| 319 | } |
| 320 | val_cnt = probe_ent_getvals(ent_itm, &itm_record_fields); |
| 321 | if (val_cnt <= 0) { |
| 322 | SEXP_free(ste_record_fields); |
| 323 | SEXP_free(itm_record_fields); |
| 324 | return OVAL_RESULT_ERROR; |
| 325 | } |
| 326 | |
| 327 | ste_res = SEXP_list_new(NULL); |
| 328 | |
| 329 | SEXP_list_foreach(ste_rf, ste_record_fields) { |
| 330 | SEXP_t *itm_rf, *itm_res; |
| 331 | bool matched; |
| 332 | |
| 333 | char *sname = probe_ent_getname(ste_rf); |
| 334 | itm_res = SEXP_list_new(NULL); |
| 335 | matched = false; |
| 336 | |
| 337 | SEXP_list_foreach(itm_rf, itm_record_fields) { |
| 338 | char *iname = probe_ent_getname(itm_rf); |
| 339 | if (strcmp(sname, iname)) { |
| 340 | free(iname); |
| 341 | continue; |
| 342 | } |
| 343 | free(iname); |
| 344 | matched = true; |
| 345 | |
| 346 | res = probe_entste_cmp(ste_rf, itm_rf); |
| 347 | /* todo: _oval_result_to_sexp() */ |
| 348 | stmp = SEXP_number_newu(res); |
| 349 | SEXP_list_add(itm_res, stmp); |
| 350 | SEXP_free(stmp); |
| 351 | } |
| 352 | |
| 353 | free(sname); |
| 354 | |
| 355 | if (!matched) { |
| 356 | stmp = SEXP_number_newu(OVAL_RESULT_ERROR); |
| 357 | SEXP_list_add(itm_res, stmp); |
| 358 | SEXP_free(stmp); |
| 359 | } |
| 360 | |
| 361 | stmp = probe_ent_getattrval(ste_rf, "entity_check"); |
| 362 | if (stmp == NULL) { |
| 363 | ochk = OVAL_CHECK_ALL; |
| 364 | } else { |
| 365 | ochk = SEXP_number_getu(stmp); |
| 366 | SEXP_free(stmp); |
| 367 | } |
| 368 | |
| 369 | res = probe_ent_result_bychk(itm_res, ochk); |
| 370 | SEXP_free(itm_res); |
| 371 | stmp = SEXP_number_newu(res); |
| 372 | SEXP_list_add(ste_res, stmp); |
| 373 | SEXP_free(stmp); |
| 374 | } |
| 375 | |
| 376 | SEXP_free(ste_record_fields); |
| 377 | SEXP_free(itm_record_fields); |
| 378 | |
| 379 | stmp = probe_ent_getattrval(ent_ste, "entity_check"); |
| 380 | if (stmp == NULL) { |
| 381 | ochk = OVAL_CHECK_ALL; |
| 382 | } else { |
| 383 | ochk = SEXP_number_getu(stmp); |
| 384 | SEXP_free(stmp); |
| 385 | } |
| 386 | |
| 387 | res = probe_ent_result_bychk(ste_res, ochk); |
| 388 | SEXP_free(ste_res); |
| 389 | |
| 390 | return res; |
| 391 | } |
| 392 | |
| 393 | oval_result_t probe_entste_cmp(SEXP_t * ent_ste, SEXP_t * ent_itm) |
| 394 | { |
| 395 | oval_datatype_t ste_dt; |
| 396 | oval_syschar_status_t item_status; |
| 397 | oval_result_t ores; |
| 398 | SEXP_t *val2; |
| 399 | int valcnt; |
| 400 | |
| 401 | item_status = probe_ent_getstatus(ent_itm); |
| 402 | switch (item_status) { |
| 403 | case SYSCHAR_STATUS_DOES_NOT_EXIST: |
| 404 | return OVAL_RESULT_FALSE; |
| 405 | case SYSCHAR_STATUS_ERROR: |
| 406 | case SYSCHAR_STATUS_NOT_COLLECTED: |
| 407 | return OVAL_RESULT_ERROR; |
| 408 | default: |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | ste_dt = probe_ent_getdatatype(ent_ste); |
| 413 | if (ste_dt != probe_ent_getdatatype(ent_itm)) |
| 414 | return OVAL_RESULT_ERROR; |
| 415 | |
| 416 | if (ste_dt == OVAL_DATATYPE_RECORD) |
| 417 | /* records require special handling */ |
| 418 | return _probe_entste_cmp_record(ent_ste, ent_itm); |
| 419 | |
| 420 | valcnt = probe_ent_getvals(ent_ste, NULL); |
| 421 | if (valcnt == 0) |
| 422 | return OVAL_RESULT_ERROR; |
| 423 | |
| 424 | val2 = probe_ent_getval(ent_itm); |
| 425 | ores = probe_ent_cmp(ent_ste, val2); |
| 426 | SEXP_free(val2); |
| 427 | |
| 428 | if (ores == OVAL_RESULT_NOT_EVALUATED) |
| 429 | return OVAL_RESULT_ERROR; |
| 430 | return ores; |
| 431 | } |
| 432 | |
| 433 | oval_result_t probe_entobj_cmp(SEXP_t * ent_obj, SEXP_t * val) |
| 434 | { |
| 435 | oval_result_t ores; |
| 436 | SEXP_t *r0 = NULL; |
| 437 | int valcnt; |
| 438 | |
| 439 | valcnt = probe_ent_getvals(ent_obj, &r0); |
| 440 | SEXP_free(r0); |
| 441 | if (valcnt == 0) { |
| 442 | dD("valcnt == 0."); |
| 443 | return OVAL_RESULT_FALSE; |
| 444 | } |
| 445 | |
| 446 | ores = probe_ent_cmp(ent_obj, val); |
| 447 | #if defined(OSCAP_VERBOSE_DEBUG) |
| 448 | dI("Result of entobj comparison: %s.", oval_result_get_text(ores)); |
| 449 | #endif |
| 450 | if (ores == OVAL_RESULT_NOT_EVALUATED) |
| 451 | return OVAL_RESULT_FALSE; |
| 452 | return ores; |
| 453 | } |
| 454 | |
| 455 | struct _oresults { |
| 456 | int true_cnt, false_cnt, unknown_cnt, error_cnt, noteval_cnt, notappl_cnt; |
| 457 | }; |
| 458 | |
| 459 | static int results_parser(SEXP_t * res_lst, struct _oresults *ores) |
| 460 | { |
| 461 | oval_result_t r; |
| 462 | SEXP_t *res; |
| 463 | |
| 464 | memset(ores, 0, sizeof(struct _oresults)); |
| 465 | |
| 466 | SEXP_list_foreach(res, res_lst) { |
| 467 | r = SEXP_number_geti_32(res); |
| 468 | switch (r) { |
| 469 | case OVAL_RESULT_TRUE: |
| 470 | ++(ores->true_cnt); |
| 471 | break; |
| 472 | case OVAL_RESULT_FALSE: |
| 473 | ++(ores->false_cnt); |
| 474 | break; |
| 475 | case OVAL_RESULT_UNKNOWN: |
| 476 | ++(ores->unknown_cnt); |
| 477 | break; |
| 478 | case OVAL_RESULT_ERROR: |
| 479 | ++(ores->error_cnt); |
| 480 | break; |
| 481 | case OVAL_RESULT_NOT_EVALUATED: |
| 482 | ++(ores->noteval_cnt); |
| 483 | break; |
| 484 | case OVAL_RESULT_NOT_APPLICABLE: |
| 485 | ++(ores->notappl_cnt); |
| 486 | break; |
| 487 | default: |
| 488 | return -1; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | // todo: already implemented elsewhere; consolidate |
| 496 | oval_result_t probe_ent_result_bychk(SEXP_t * res_lst, oval_check_t check) |
| 497 | { |
| 498 | oval_result_t result = OVAL_RESULT_UNKNOWN; |
| 499 | struct _oresults ores; |
| 500 | |
| 501 | if (SEXP_list_length(res_lst) == 0) |
| 502 | return OVAL_RESULT_UNKNOWN; |
| 503 | |
| 504 | if (results_parser(res_lst, &ores) != 0) { |
| 505 | return OVAL_RESULT_ERROR; |
| 506 | } |
| 507 | |
| 508 | if (ores.notappl_cnt > 0 && |
| 509 | ores.noteval_cnt == 0 && |
| 510 | ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.true_cnt == 0) |
| 511 | return OVAL_RESULT_NOT_APPLICABLE; |
| 512 | |
| 513 | switch (check) { |
| 514 | case OVAL_CHECK_ALL: |
| 515 | if (ores.true_cnt > 0 && |
| 516 | ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt == 0) { |
| 517 | result = OVAL_RESULT_TRUE; |
| 518 | } else if (ores.false_cnt > 0) { |
| 519 | result = OVAL_RESULT_FALSE; |
| 520 | } else if (ores.false_cnt == 0 && ores.error_cnt > 0) { |
| 521 | result = OVAL_RESULT_ERROR; |
| 522 | } else if (ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt > 0) { |
| 523 | result = OVAL_RESULT_UNKNOWN; |
| 524 | } else if (ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt > 0) { |
| 525 | result = OVAL_RESULT_NOT_EVALUATED; |
| 526 | } |
| 527 | break; |
| 528 | case OVAL_CHECK_AT_LEAST_ONE: |
| 529 | if (ores.true_cnt > 0) { |
| 530 | result = OVAL_RESULT_TRUE; |
| 531 | } else if (ores.false_cnt > 0 && |
| 532 | ores.true_cnt == 0 && |
| 533 | ores.unknown_cnt == 0 && ores.error_cnt == 0 && ores.noteval_cnt == 0) { |
| 534 | result = OVAL_RESULT_FALSE; |
| 535 | } else if (ores.true_cnt == 0 && ores.error_cnt > 0) { |
| 536 | result = OVAL_RESULT_ERROR; |
| 537 | } else if (ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt > 0) { |
| 538 | result = OVAL_RESULT_UNKNOWN; |
| 539 | } else if (ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt > 0) { |
| 540 | result = OVAL_RESULT_NOT_EVALUATED; |
| 541 | } |
| 542 | break; |
| 543 | case OVAL_CHECK_NONE_EXIST: |
| 544 | dW("The 'none exist' CheckEnumeration value has been deprecated. " |
| 545 | "Converted to check='none satisfy'."); |
| 546 | /* FALLTHROUGH */ |
| 547 | case OVAL_CHECK_NONE_SATISFY: |
| 548 | if (ores.true_cnt > 0) { |
| 549 | result = OVAL_RESULT_FALSE; |
| 550 | } else if (ores.true_cnt == 0 && ores.error_cnt > 0) { |
| 551 | result = OVAL_RESULT_ERROR; |
| 552 | } else if (ores.true_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt > 0) { |
| 553 | result = OVAL_RESULT_UNKNOWN; |
| 554 | } else if (ores.true_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt > 0) { |
| 555 | result = OVAL_RESULT_NOT_EVALUATED; |
| 556 | } else if (ores.false_cnt > 0 && |
| 557 | ores.error_cnt == 0 && |
| 558 | ores.unknown_cnt == 0 && ores.noteval_cnt == 0 && ores.true_cnt == 0) { |
| 559 | result = OVAL_RESULT_TRUE; |
| 560 | } |
| 561 | break; |
| 562 | case OVAL_CHECK_ONLY_ONE: |
| 563 | if (ores.true_cnt == 1 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt == 0) { |
| 564 | result = OVAL_RESULT_TRUE; |
| 565 | } else if (ores.true_cnt > 1) { |
| 566 | result = OVAL_RESULT_FALSE; |
| 567 | } else if (ores.true_cnt < 2 && ores.error_cnt > 0) { |
| 568 | result = OVAL_RESULT_ERROR; |
| 569 | } else if (ores.true_cnt < 2 && ores.error_cnt == 0 && ores.unknown_cnt > 0) { |
| 570 | result = OVAL_RESULT_UNKNOWN; |
| 571 | } else if (ores.true_cnt < 2 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt > 0) { |
| 572 | result = OVAL_RESULT_NOT_EVALUATED; |
| 573 | } else if (ores.true_cnt != 1 && ores.false_cnt > 0) { |
| 574 | result = OVAL_RESULT_FALSE; |
| 575 | } |
| 576 | break; |
| 577 | default: |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | return result; |
| 582 | } |
| 583 | |
| 584 | // todo: already implemented elsewhere; consolidate |
| 585 | oval_result_t probe_ent_result_byopr(SEXP_t * res_lst, oval_operator_t operator) |
| 586 | { |
| 587 | oval_result_t result = OVAL_RESULT_UNKNOWN; |
| 588 | struct _oresults ores; |
| 589 | |
| 590 | if (SEXP_list_length(res_lst) == 0) |
| 591 | return OVAL_RESULT_UNKNOWN; |
| 592 | |
| 593 | if (results_parser(res_lst, &ores) != 0) { |
| 594 | return OVAL_RESULT_ERROR; |
| 595 | } |
| 596 | |
| 597 | if (ores.notappl_cnt > 0 && |
| 598 | ores.noteval_cnt == 0 && |
| 599 | ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.true_cnt == 0) |
| 600 | return OVAL_RESULT_NOT_APPLICABLE; |
| 601 | |
| 602 | switch (operator) { |
| 603 | case OVAL_OPERATOR_AND: |
| 604 | if (ores.true_cnt > 0 && |
| 605 | ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt == 0) { |
| 606 | result = OVAL_RESULT_TRUE; |
| 607 | } else if (ores.false_cnt > 0) { |
| 608 | result = OVAL_RESULT_FALSE; |
| 609 | } else if (ores.false_cnt == 0 && ores.error_cnt > 0) { |
| 610 | result = OVAL_RESULT_ERROR; |
| 611 | } else if (ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt > 0) { |
| 612 | result = OVAL_RESULT_UNKNOWN; |
| 613 | } else if (ores.false_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt > 0) { |
| 614 | result = OVAL_RESULT_NOT_EVALUATED; |
| 615 | } |
| 616 | break; |
| 617 | case OVAL_OPERATOR_ONE: |
| 618 | if (ores.true_cnt == 1 && |
| 619 | ores.false_cnt >= 0 && |
| 620 | ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt == 0 && ores.notappl_cnt >= 0) { |
| 621 | result = OVAL_RESULT_TRUE; |
| 622 | } else if (ores.true_cnt >= 2 && |
| 623 | ores.false_cnt >= 0 && |
| 624 | ores.error_cnt >= 0 && |
| 625 | ores.unknown_cnt >= 0 && ores.noteval_cnt >= 0 && ores.notappl_cnt >= 0) { |
| 626 | result = OVAL_RESULT_FALSE; |
| 627 | } else if (ores.true_cnt == 0 && |
| 628 | ores.false_cnt >= 0 && |
| 629 | ores.error_cnt == 0 && |
| 630 | ores.unknown_cnt == 0 && ores.noteval_cnt == 0 && ores.notappl_cnt >= 0) { |
| 631 | result = OVAL_RESULT_FALSE; |
| 632 | } else if (ores.true_cnt < 2 && |
| 633 | ores.false_cnt >= 0 && |
| 634 | ores.error_cnt > 0 && |
| 635 | ores.unknown_cnt >= 0 && ores.noteval_cnt >= 0 && ores.notappl_cnt >= 0) { |
| 636 | result = OVAL_RESULT_ERROR; |
| 637 | } else if (ores.true_cnt < 2 && |
| 638 | ores.false_cnt >= 0 && |
| 639 | ores.error_cnt == 0 && |
| 640 | ores.unknown_cnt >= 1 && ores.noteval_cnt >= 0 && ores.notappl_cnt >= 0) { |
| 641 | result = OVAL_RESULT_UNKNOWN; |
| 642 | } else if (ores.true_cnt < 2 && |
| 643 | ores.false_cnt >= 0 && |
| 644 | ores.error_cnt == 0 && |
| 645 | ores.unknown_cnt == 0 && ores.noteval_cnt > 0 && ores.notappl_cnt >= 0) { |
| 646 | result = OVAL_RESULT_NOT_EVALUATED; |
| 647 | } |
| 648 | break; |
| 649 | case OVAL_OPERATOR_OR: |
| 650 | if (ores.true_cnt > 0) { |
| 651 | result = OVAL_RESULT_TRUE; |
| 652 | } else if (ores.true_cnt == 0 && |
| 653 | ores.false_cnt > 0 && |
| 654 | ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt == 0) { |
| 655 | result = OVAL_RESULT_FALSE; |
| 656 | } else if (ores.true_cnt == 0 && ores.error_cnt > 0) { |
| 657 | result = OVAL_RESULT_ERROR; |
| 658 | } else if (ores.true_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt > 0) { |
| 659 | result = OVAL_RESULT_UNKNOWN; |
| 660 | } else if (ores.true_cnt == 0 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt > 0) { |
| 661 | result = OVAL_RESULT_NOT_EVALUATED; |
| 662 | } |
| 663 | break; |
| 664 | case OVAL_OPERATOR_XOR: |
| 665 | if ((ores.true_cnt % 2) == 1 && ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt == 0) { |
| 666 | result = OVAL_RESULT_TRUE; |
| 667 | } else if ((ores.true_cnt % 2) == 0 && |
| 668 | ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt == 0) { |
| 669 | result = OVAL_RESULT_FALSE; |
| 670 | } else if (ores.error_cnt > 0) { |
| 671 | result = OVAL_RESULT_ERROR; |
| 672 | } else if (ores.error_cnt == 0 && ores.unknown_cnt > 0) { |
| 673 | result = OVAL_RESULT_UNKNOWN; |
| 674 | } else if (ores.error_cnt == 0 && ores.unknown_cnt == 0 && ores.noteval_cnt > 0) { |
| 675 | result = OVAL_RESULT_NOT_EVALUATED; |
| 676 | } |
| 677 | break; |
| 678 | default: |
| 679 | break; |
| 680 | } |
| 681 | |
| 682 | return result; |
| 683 | } |
| 684 | |
| 685 | /// @} |