int it_driver(int nr,int in,int cn) { switch(nr) { case IDR_MINEWALL: minewall(in,cn); return 1; case IDR_ENHANCE: collect_item(in,cn); return 1; case IDR_MINEDOOR: minedoor(in,cn); return 1; case IDR_MINEKEYDOOR: keyholder_door(in,cn); return 1; case IDR_MINEGATEWAY: minegateway(in,cn); return 1; default: return 0; } }
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); }
int routingtable_probe_main(probe_ctx *ctx, void *arg) { SEXP_t *probe_in, *dst_ent; FILE *fp; char *line_buf; size_t line_len; struct route_info rt; int probe_ret = 0; probe_in = probe_ctx_getobject(ctx); dst_ent = probe_obj_getent(probe_in, "destination", 1); if (dst_ent == NULL) return (PROBE_ENOENT); rt.ip_dst_ent = dst_ent; line_len = 0; line_buf = NULL; fp = NULL; switch(probe_ent_getdatatype(dst_ent)) { case OVAL_DATATYPE_IPV4ADDR: fp = fopen("/proc/net/route", "r"); /* Skip the header line */ if (getline(&line_buf, &line_len, fp) != -1) { while(getline(&line_buf, &line_len, fp) != -1) { if (process_line_ip4(line_buf, &rt) != 0) break; if (collect_item(&rt, ctx) != 0) break; } } if (!feof(fp)) { /* error */ dE("An error ocured while reading /proc/net/route: %s", strerror(errno)); } break; case OVAL_DATATYPE_IPV6ADDR: fp = fopen("/proc/net/ipv6_route", "r"); while(getline(&line_buf, &line_len, fp) != -1) { if (process_line_ip6(line_buf, &rt) != 0) break; if (collect_item(&rt, ctx) != 0) break; } if (!feof(fp)) { /* error */ dE("An error ocured while reading /proc/net/ipv6_route: %s", strerror(errno)); } break; default: probe_ret = EINVAL; } if (fp != NULL) fclose(fp); if (line_buf != NULL) free(line_buf); SEXP_free(dst_ent); return (probe_ret); }