| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#ifdef HAVE_CONFIG_H |
| 31 |
#include <config.h> |
| 32 |
#endif |
| 33 |
|
| 34 |
#include <stdlib.h> |
| 35 |
#include <string.h> |
| 36 |
#include <stdint.h> |
| 37 |
#include <limits.h> |
| 38 |
#include <probe-api.h> |
| 39 |
#include <gconf/gconf.h> |
| 40 |
#include "gconf_probe.h" |
| 41 |
|
| 42 |
#include "common/debug_priv.h" |
| 43 |
#include "oval_fts.h" |
| 44 |
|
| 45 |
#ifndef MTAB_LINE_MAX |
| 46 |
# define MTAB_LINE_MAX 4096 |
| 47 |
#endif |
| 48 |
|
| 49 |
static int collect_item(probe_ctx *ctx, const char *source, GConfEntry *entry) |
| 50 |
{ |
| 51 |
GConfValue *gconf_value; |
| 52 |
char *gconf_type; |
| 53 |
SEXP_t *sexp_value, *item; |
| 54 |
|
| 55 |
gconf_value = gconf_entry_get_value(entry); |
| 56 |
|
| 57 |
if (gconf_value != NULL) { |
| 58 |
switch(gconf_value->type) { |
| 59 |
case GCONF_VALUE_STRING: |
| 60 |
gconf_type = "GCONF_VALUE_STRING"; |
| 61 |
sexp_value = SEXP_string_newf("%s", gconf_value_get_string(gconf_value)); |
| 62 |
break; |
| 63 |
case GCONF_VALUE_INT: |
| 64 |
gconf_type = "GCONF_VALUE_INT"; |
| 65 |
sexp_value = SEXP_number_newi_32(gconf_value_get_int(gconf_value)); |
| 66 |
break; |
| 67 |
case GCONF_VALUE_FLOAT: |
| 68 |
gconf_type = "GCONF_VALUE_FLOAT"; |
| 69 |
sexp_value = SEXP_number_newf(gconf_value_get_float(gconf_value)); |
| 70 |
break; |
| 71 |
case GCONF_VALUE_BOOL: |
| 72 |
gconf_type = "GCONF_VALUE_BOOL"; |
| 73 |
sexp_value = SEXP_number_newb(gconf_value_get_bool(gconf_value)); |
| 74 |
break; |
| 75 |
case GCONF_VALUE_INVALID: |
| 76 |
case GCONF_VALUE_SCHEMA: |
| 77 |
case GCONF_VALUE_LIST: |
| 78 |
case GCONF_VALUE_PAIR: |
| 79 |
default: |
| 80 |
dE("Unsupported GConfValue type: %d", gconf_value->type); |
| 81 |
gconf_type = "GCONF_VALUE_INVALID"; |
| 82 |
sexp_value = NULL; |
| 83 |
} |
| 84 |
} else { |
| 85 |
gconf_type = "GCONF_VALUE_INVALID"; |
| 86 |
sexp_value = NULL; |
| 87 |
} |
| 88 |
|
| 89 |
item = probe_item_create(OVAL_UNIX_GCONF, NULL, |
| 90 |
"key", OVAL_DATATYPE_STRING, entry->key, |
| 91 |
"source", OVAL_DATATYPE_STRING, source, |
| 92 |
"type", OVAL_DATATYPE_STRING, gconf_type, |
| 93 |
"is_writable", OVAL_DATATYPE_BOOLEAN, gconf_entry_get_is_writable(entry), |
| 94 |
|
| 95 |
|
| 96 |
"is_default", OVAL_DATATYPE_BOOLEAN, gconf_entry_get_is_default(entry), |
| 97 |
"value", OVAL_DATATYPE_SEXP, sexp_value, |
| 98 |
NULL); |
| 99 |
|
| 100 |
probe_item_collect(ctx, item); |
| 101 |
SEXP_free(sexp_value); |
| 102 |
|
| 103 |
return (0); |
| 104 |
} |
| 105 |
|
| 106 |
static int collect_item_direct(probe_ctx *ctx, const char *source, GConfEngine *engine, SEXP_t *key) |
| 107 |
{ |
| 108 |
char gconf_key[1024]; |
| 109 |
int ret; |
| 110 |
GError *gconf_err = NULL; |
| 111 |
GConfEntry *gconf_entry; |
| 112 |
|
| 113 |
PROBE_ENT_STRVAL(key, gconf_key, sizeof gconf_key, return -1;, return 0;); |
| 114 |
|
| 115 |
gconf_entry = gconf_engine_get_entry(engine, gconf_key, |
| 116 |
NULL, true, &gconf_err); |
| 117 |
|
| 118 |
if (gconf_entry != NULL) { |
| 119 |
ret = collect_item(ctx, source, gconf_entry); |
| 120 |
gconf_entry_unref(gconf_entry); |
| 121 |
} else { |
| 122 |
|
| 123 |
ret = 0; |
| 124 |
if (gconf_err != NULL) |
| 125 |
g_error_free(gconf_err); |
| 126 |
} |
| 127 |
|
| 128 |
return (ret); |
| 129 |
} |
| 130 |
|
| 131 |
static int collect_item_regexp(probe_ctx *ctx, const char *source, GConfEngine *engine, SEXP_t *key) |
| 132 |
{ |
| 133 |
return (0); |
| 134 |
} |
| 135 |
|
| 136 |
int gconf_probe_main(probe_ctx *ctx, void *probe_arg) |
| 137 |
{ |
| 138 |
int probe_ret = 0; |
| 139 |
SEXP_t *probe_in, *gconf_src, *gconf_key, *key_opval; |
| 140 |
SEXP_t *gconf_src_val; |
| 141 |
oval_operation_t key_op; |
| 142 |
GConfEngine *gconf_engine = NULL; |
| 143 |
|
| 144 |
probe_in = probe_ctx_getobject(ctx); |
| 145 |
if ((gconf_src = probe_obj_getent(probe_in, "source", 1)) == NULL) |
| 146 |
return (PROBE_ENOENT); |
| 147 |
|
| 148 |
if ((gconf_key = probe_obj_getent(probe_in, "key", 1)) == NULL) { |
| 149 |
SEXP_free(gconf_src); |
| 150 |
return (PROBE_ENOENT); |
| 151 |
} |
| 152 |
|
| 153 |
key_opval = probe_ent_getattrval(gconf_key, "operation"); |
| 154 |
|
| 155 |
if (key_opval != NULL) { |
| 156 |
key_op = (oval_operation_t)SEXP_number_geti(key_opval); |
| 157 |
SEXP_free(key_opval); |
| 158 |
} else |
| 159 |
key_op = OVAL_OPERATION_EQUALS; |
| 160 |
|
| 161 |
gconf_src_val = probe_ent_getval(gconf_src); |
| 162 |
|
| 163 |
if (gconf_src_val != NULL) { |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
if (!SEXP_stringp(gconf_src_val)) { |
| 169 |
SEXP_free(gconf_src_val); |
| 170 |
SEXP_free(gconf_src); |
| 171 |
SEXP_free(gconf_key); |
| 172 |
|
| 173 |
return (PROBE_EINVAL); |
| 174 |
} |
| 175 |
|
| 176 |
SEXP_free(gconf_src_val); |
| 177 |
} else { |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
gconf_engine = gconf_engine_get_default(); |
| 184 |
|
| 185 |
if (gconf_engine == NULL) { |
| 186 |
dE("Unable to get the default GConf engine!"); |
| 187 |
SEXP_free(gconf_src); |
| 188 |
SEXP_free(gconf_key); |
| 189 |
|
| 190 |
return (0); |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
if (gconf_engine == NULL) { |
| 195 |
OVAL_FTS *ofts; |
| 196 |
OVAL_FTSENT *ofts_ent; |
| 197 |
char gconf_addr[PATH_MAX]; |
| 198 |
GError *gconf_err = NULL; |
| 199 |
SEXP_t *behaviors = NULL; |
| 200 |
|
| 201 |
probe_filebehaviors_canonicalize(&behaviors); |
| 202 |
|
| 203 |
if ((ofts = oval_fts_open_prefixed(NULL, NULL, NULL, gconf_src, behaviors, probe_ctx_getresult(ctx))) != NULL) { |
| 204 |
while ((ofts_ent = oval_fts_read(ofts)) != NULL) { |
| 205 |
if (ofts_ent->path_len + ofts_ent->file_len + 2 > PATH_MAX) { |
| 206 |
return PROBE_EFATAL; |
| 207 |
} |
| 208 |
|
| 209 |
strcpy(gconf_addr, ofts_ent->path); |
| 210 |
gconf_addr[ofts_ent->path_len] = '/'; |
| 211 |
strcpy(gconf_addr + ofts_ent->path_len + 1, ofts_ent->file); |
| 212 |
|
| 213 |
dI("GConf source: %s", gconf_addr); |
| 214 |
|
| 215 |
gconf_engine = gconf_engine_get_for_address(gconf_addr, &gconf_err); |
| 216 |
|
| 217 |
if (gconf_engine != NULL) { |
| 218 |
switch(key_op) { |
| 219 |
case OVAL_OPERATION_EQUALS: |
| 220 |
collect_item_direct(ctx, gconf_addr, gconf_engine, gconf_key); |
| 221 |
break; |
| 222 |
case OVAL_OPERATION_PATTERN_MATCH: |
| 223 |
|
| 224 |
collect_item_regexp(ctx, gconf_addr, gconf_engine, gconf_key); |
| 225 |
break; |
| 226 |
default: |
| 227 |
dE("Unsupported operation on the `key' entity: %d.", key_op); |
| 228 |
probe_ret = PROBE_EOPNOTSUPP; |
| 229 |
abort(); |
| 230 |
} |
| 231 |
|
| 232 |
gconf_engine_unref(gconf_engine); |
| 233 |
} else { |
| 234 |
dW("Invalid GConf source, skipping!"); |
| 235 |
} |
| 236 |
|
| 237 |
oval_ftsent_free(ofts_ent); |
| 238 |
} |
| 239 |
oval_fts_close(ofts); |
| 240 |
} |
| 241 |
|
| 242 |
SEXP_free(behaviors); |
| 243 |
} else { |
| 244 |
dI("GConf source: gconfd"); |
| 245 |
|
| 246 |
switch(key_op) { |
| 247 |
case OVAL_OPERATION_EQUALS: |
| 248 |
collect_item_direct(ctx, NULL, gconf_engine, gconf_key); |
| 249 |
break; |
| 250 |
case OVAL_OPERATION_PATTERN_MATCH: |
| 251 |
|
| 252 |
collect_item_regexp(ctx, NULL, gconf_engine, gconf_key); |
| 253 |
break; |
| 254 |
default: |
| 255 |
dE("Unsupported operation on the `key' entity: %d.", key_op); |
| 256 |
probe_ret = PROBE_EOPNOTSUPP; |
| 257 |
} |
| 258 |
|
| 259 |
gconf_engine_unref(gconf_engine); |
| 260 |
} |
| 261 |
|
| 262 |
SEXP_free(gconf_src); |
| 263 |
SEXP_free(gconf_key); |
| 264 |
|
| 265 |
return (probe_ret); |
| 266 |
} |