SEXP_t *probe_rcache_sexp_get(probe_rcache_t *cache, const SEXP_t * id) { char b[128], *k = b; SEXP_t *r = NULL; if (SEXP_string_cstr_r(id, k, sizeof b) == ((size_t)-1)) k = SEXP_string_cstr(id); if (k == NULL) return(NULL); rbt_str_get(cache->tree, k, (void *)&r); if (k != b) free(k); return (r != NULL ? SEXP_ref(r) : NULL); }
int partition_probe_main(probe_ctx *ctx, void *probe_arg) { int probe_ret = 0; SEXP_t *mnt_entity, *mnt_opval, *mnt_entval, *probe_in; char mnt_path[PATH_MAX]; oval_operation_t mnt_op; FILE *mnt_fp; oval_schema_version_t obj_over; #if defined(PROC_CHECK) && defined(__linux__) int mnt_fd; struct statfs stfs; mnt_fd = open(MTAB_PATH, O_RDONLY); if (mnt_fd < 0) return (PROBE_ESYSTEM); if (fstatfs(mnt_fd, &stfs) != 0) { close(mnt_fd); return (PROBE_ESYSTEM); } if (stfs.f_type != PROC_SUPER_MAGIC) { close(mnt_fd); return (PROBE_EFATAL); } mnt_fp = fdopen(mnt_fd, "r"); if (mnt_fp == NULL) { close(mnt_fd); return (PROBE_ESYSTEM); } #else mnt_fp = fopen(MTAB_PATH, "r"); if (mnt_fp == NULL) return (PROBE_ESYSTEM); #endif probe_in = probe_ctx_getobject(ctx); obj_over = probe_obj_get_platform_schema_version(probe_in); mnt_entity = probe_obj_getent(probe_in, "mount_point", 1); if (mnt_entity == NULL) { fclose(mnt_fp); return (PROBE_ENOENT); } mnt_opval = probe_ent_getattrval(mnt_entity, "operation"); if (mnt_opval != NULL) { mnt_op = (oval_operation_t)SEXP_number_geti(mnt_opval); SEXP_free(mnt_opval); } else mnt_op = OVAL_OPERATION_EQUALS; mnt_entval = probe_ent_getval(mnt_entity); if (!SEXP_stringp(mnt_entval)) { SEXP_free(mnt_entval); SEXP_free(mnt_entity); fclose(mnt_fp); return (PROBE_EINVAL); } SEXP_string_cstr_r(mnt_entval, mnt_path, sizeof mnt_path); SEXP_free(mnt_entval); SEXP_free(mnt_entity); if (mnt_fp != NULL) { char buffer[MTAB_LINE_MAX]; struct mntent mnt_ent, *mnt_entp; pcre *re = NULL; const char *estr = NULL; int eoff = -1; #if defined(HAVE_BLKID_GET_TAG_VALUE) blkid_cache blkcache; if (blkid_get_cache(&blkcache, NULL) != 0) { endmntent(mnt_fp); return (PROBE_EUNKNOWN); } #endif if (mnt_op == OVAL_OPERATION_PATTERN_MATCH) { re = pcre_compile(mnt_path, PCRE_UTF8, &estr, &eoff, NULL); if (re == NULL) { endmntent(mnt_fp); return (PROBE_EINVAL); } } while ((mnt_entp = getmntent_r(mnt_fp, &mnt_ent, buffer, sizeof buffer)) != NULL) { if (strcmp(mnt_entp->mnt_type, "rootfs") == 0) continue; if (mnt_op == OVAL_OPERATION_EQUALS) { if (strcmp(mnt_entp->mnt_dir, mnt_path) == 0) { #if defined(HAVE_BLKID_GET_TAG_VALUE) collect_item(ctx, obj_over, mnt_entp, blkcache); #else collect_item(ctx, obj_over, mnt_entp); #endif break; } } else if (mnt_op == OVAL_OPERATION_NOT_EQUAL) { if (strcmp(mnt_entp->mnt_dir, mnt_path) != 0) { if ( #if defined(HAVE_BLKID_GET_TAG_VALUE) collect_item(ctx, obj_over, mnt_entp, blkcache) #else collect_item(ctx, obj_over, mnt_entp) #endif != 0) break; } } else if (mnt_op == OVAL_OPERATION_PATTERN_MATCH) { int rc; rc = pcre_exec(re, NULL, mnt_entp->mnt_dir, strlen(mnt_entp->mnt_dir), 0, 0, NULL, 0); if (rc == 0) { if ( #if defined(HAVE_BLKID_GET_TAG_VALUE) collect_item(ctx, obj_over, mnt_entp, blkcache) #else collect_item(ctx, obj_over, mnt_entp) #endif != 0) break; } /* XXX: check for pcre_exec error */ } } endmntent(mnt_fp); if (mnt_op == OVAL_OPERATION_PATTERN_MATCH) pcre_free(re); } return (probe_ret); }
static struct oval_sysent *oval_sexp_to_sysent(struct oval_syschar_model *model, struct oval_sysitem *item, SEXP_t * sexp, struct oval_string_map *mask_map) { char *key; oval_syschar_status_t status; oval_datatype_t dt; struct oval_sysent *ent; key = probe_ent_getname(sexp); if (!key) return NULL; if (strcmp("message", key) == 0 && item != NULL) { struct oval_message *msg; oval_message_level_t lvl; SEXP_t *lvl_sexp, *txt_sexp; char txt[1024]; lvl_sexp = probe_obj_getattrval(sexp, "level"); lvl = SEXP_number_getu_32(lvl_sexp); txt_sexp = probe_ent_getval(sexp); SEXP_string_cstr_r(txt_sexp, txt, sizeof txt); SEXP_vfree(lvl_sexp, txt_sexp); /* TODO: sanity checks */ msg = oval_message_new(); oval_message_set_level(msg, lvl); oval_message_set_text(msg, txt); oval_sysitem_add_message(item, msg); return (NULL); } status = probe_ent_getstatus(sexp); dt = probe_ent_getdatatype(sexp); ent = oval_sysent_new(model); oval_sysent_set_name(ent, key); oval_sysent_set_status(ent, status); oval_sysent_set_datatype(ent, dt); if (mask_map == NULL || oval_string_map_get_value(mask_map, key) == NULL) oval_sysent_set_mask(ent, 0); else oval_sysent_set_mask(ent, 1); if (status != SYSCHAR_STATUS_EXISTS) return ent; if (dt == OVAL_DATATYPE_RECORD) { SEXP_t *srf, *srfs; probe_ent_getvals(sexp, &srfs); SEXP_list_foreach(srf, srfs) { struct oval_record_field *rf; rf = oval_record_field_ITEM_from_sexp(srf); oval_sysent_add_record_field(ent, rf); } SEXP_free(srfs); } else {