| 1 | /** |
| 2 | * @file environmentvariable_probe.c |
| 3 | * @brief environmentvariable probe |
| 4 | * @author "Petr Lautrbach" <[email protected]> |
| 5 | * |
| 6 | * This probe is able to process a environmentvariable_object as defined in OVAL 5.8. |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | /* |
| 11 | * Copyright 2009-2011 Red Hat Inc., Durham, North Carolina. |
| 12 | * All Rights Reserved. |
| 13 | * |
| 14 | * This library is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU Lesser General Public |
| 16 | * License as published by the Free Software Foundation; either |
| 17 | * version 2.1 of the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This library is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | * Lesser General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU Lesser General Public |
| 25 | * License along with this library; if not, write to the Free Software |
| 26 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 27 | * |
| 28 | * Authors: |
| 29 | * Petr Lautrbach <[email protected]> |
| 30 | */ |
| 31 | |
| 32 | /* |
| 33 | * environmentvariable probe: |
| 34 | * |
| 35 | * name |
| 36 | * value |
| 37 | */ |
| 38 | |
| 39 | #ifdef HAVE_CONFIG_H |
| 40 | #include <config.h> |
| 41 | #endif |
| 42 | |
| 43 | #include <stdlib.h> |
| 44 | #include <string.h> |
| 45 | #include <stdio.h> |
| 46 | #include <errno.h> |
| 47 | |
| 48 | #include "_seap.h" |
| 49 | #include "probe-api.h" |
| 50 | #include "probe/entcmp.h" |
| 51 | #include "environmentvariable_probe.h" |
| 52 | |
| 53 | extern char **environ; |
| 54 | |
| 55 | static int read_environment(SEXP_t *un_ent, probe_ctx *ctx) |
| 56 | { |
| 57 | int err = 1; |
| 58 | char **env; |
| 59 | size_t env_name_size; |
| 60 | SEXP_t *env_name, *env_value, *item; |
| 61 | |
| 62 | for (env = environ; *env != 0; env++) { |
| 63 | env_name_size = strchr(*env, '=') - *env; |
| 64 | env_name = SEXP_string_new(*env, env_name_size); |
| 65 | env_value = SEXP_string_newf("%s", *env + env_name_size + 1); |
| 66 | if (probe_entobj_cmp(un_ent, env_name) == OVAL_RESULT_TRUE) { |
| 67 | item = probe_item_create( |
| 68 | OVAL_INDEPENDENT_ENVIRONMENT_VARIABLE, NULL, |
| 69 | "name", OVAL_DATATYPE_SEXP, env_name, |
| 70 | "value", OVAL_DATATYPE_SEXP, env_value, |
| 71 | NULL); |
| 72 | probe_item_collect(ctx, item); |
| 73 | err = 0; |
| 74 | } |
| 75 | SEXP_free(env_name); |
| 76 | SEXP_free(env_value); |
| 77 | } |
| 78 | return err; |
| 79 | } |
| 80 | |
| 81 | int environmentvariable_probe_main(probe_ctx *ctx, void *arg) |
| 82 | { |
| 83 | SEXP_t *probe_in, *ent; |
| 84 | |
| 85 | probe_in = probe_ctx_getobject(ctx); |
| 86 | ent = probe_obj_getent(probe_in, "name", 1); |
| 87 | |
| 88 | if (ent == NULL) { |
| 89 | return PROBE_ENOVAL; |
| 90 | } |
| 91 | |
| 92 | read_environment(ent, ctx); |
| 93 | SEXP_free(ent); |
| 94 | |
| 95 | return 0; |
| 96 | } |