Skip to content

Commit 6230fe5

Browse files
committed
OVAL/probes/sysctl: Unify indentation (8 spaces)
1 parent 90ce15f commit 6230fe5

File tree

1 file changed

+143
-143
lines changed

1 file changed

+143
-143
lines changed

src/OVAL/probes/unix/sysctl_probe.c

Lines changed: 143 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
7070
oval_schema_version_t over;
7171
int over_cmp;
7272

73-
const char *ipv6_conf_path = "/proc/sys/net/ipv6/conf/";
74-
size_t ipv6_conf_path_len = strlen(ipv6_conf_path);
73+
const char *ipv6_conf_path = "/proc/sys/net/ipv6/conf/";
74+
size_t ipv6_conf_path_len = strlen(ipv6_conf_path);
7575

7676
probe_in = probe_ctx_getobject(ctx);
7777
name_entity = probe_obj_getent(probe_in, "name", 1);
@@ -92,28 +92,28 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
9292
"recurse", r3 = SEXP_string_new("symlinks and directories", 24),
9393
NULL);
9494
bh_entity = probe_ent_creat1("behaviors", ent_attrs, NULL);
95-
SEXP_free(r0);
96-
SEXP_free(r1);
97-
SEXP_free(r2);
98-
SEXP_free(r3);
99-
SEXP_free(ent_attrs);
95+
SEXP_free(r0);
96+
SEXP_free(r1);
97+
SEXP_free(r2);
98+
SEXP_free(r3);
99+
SEXP_free(ent_attrs);
100100

101101
/*
102102
* prepare path, filename
103103
*/
104104
ent_attrs = probe_attr_creat("operation", r0 = SEXP_number_newi(OVAL_OPERATION_EQUALS),
105105
NULL);
106106
path_entity = probe_ent_creat1("path", ent_attrs, r1 = SEXP_string_new(PROC_SYS_DIR, strlen(PROC_SYS_DIR)));
107-
SEXP_free(r0);
108-
SEXP_free(r1);
109-
SEXP_free(ent_attrs);
107+
SEXP_free(r0);
108+
SEXP_free(r1);
109+
SEXP_free(ent_attrs);
110110

111111
ent_attrs = probe_attr_creat("operation", r0 = SEXP_number_newi(OVAL_OPERATION_PATTERN_MATCH),
112112
NULL);
113113
filename_entity = probe_ent_creat1("filename", ent_attrs, r1 = SEXP_string_new(".*", 2));
114-
SEXP_free(r0);
115-
SEXP_free(r1);
116-
SEXP_free(ent_attrs);
114+
SEXP_free(r0);
115+
SEXP_free(r1);
116+
SEXP_free(ent_attrs);
117117

118118
/*
119119
* collect sysctls
@@ -123,10 +123,10 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
123123

124124
if (ofts == NULL) {
125125
dE("oval_fts_open_prefixed(%s, %s) failed", PROC_SYS_DIR, ".\\+");
126-
SEXP_free(path_entity);
127-
SEXP_free(filename_entity);
128-
SEXP_free(bh_entity);
129-
SEXP_free(name_entity);
126+
SEXP_free(path_entity);
127+
SEXP_free(filename_entity);
128+
SEXP_free(bh_entity);
129+
SEXP_free(name_entity);
130130

131131
return (PROBE_EFATAL);
132132
}
@@ -135,22 +135,22 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
135135
SEXP_t *se_mib;
136136
char mibpath[PATH_MAX], *mib;
137137
size_t miblen;
138-
struct stat file_stat;
138+
struct stat file_stat;
139139

140140
snprintf(mibpath, sizeof mibpath, "%s/%s", ofts_ent->path, ofts_ent->file);
141141

142-
/* Skip write-only files, eg. /proc/sys/net/ipv4/route/flush */
143-
if (stat(mibpath, &file_stat) == -1) {
144-
dE("Stat failed on %s: %u, %s", mibpath, errno, strerror(errno));
145-
oval_ftsent_free(ofts_ent);
146-
continue;
147-
}
148-
/* the sysctl utility uses same condition in sysctl.c in ReadSetting() */
149-
if ((file_stat.st_mode & S_IRUSR) == 0) {
150-
dD("Skipping write-only file %s", mibpath);
151-
oval_ftsent_free(ofts_ent);
152-
continue;
153-
}
142+
/* Skip write-only files, eg. /proc/sys/net/ipv4/route/flush */
143+
if (stat(mibpath, &file_stat) == -1) {
144+
dE("Stat failed on %s: %u, %s", mibpath, errno, strerror(errno));
145+
oval_ftsent_free(ofts_ent);
146+
continue;
147+
}
148+
/* the sysctl utility uses same condition in sysctl.c in ReadSetting() */
149+
if ((file_stat.st_mode & S_IRUSR) == 0) {
150+
dD("Skipping write-only file %s", mibpath);
151+
oval_ftsent_free(ofts_ent);
152+
continue;
153+
}
154154

155155
mib = strdup(mibpath + strlen(PROC_SYS_DIR) + 1);
156156
miblen = strlen(mib);
@@ -189,35 +189,35 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
189189
l = fread(sysval, 1, sizeof sysval - 1, fp);
190190

191191
if (ferror(fp)) {
192-
/* Linux 4.1.0 introduced a per-NIC IPv6 stable_secret file.
193-
* The stable_secret file cannot be read until it is set,
194-
* so we skip it when it is not readable. Otherwise we collect it.
195-
*/
196-
if (strncmp(ofts_ent->path, ipv6_conf_path, ipv6_conf_path_len) == 0 &&
197-
strcmp(ofts_ent->file, "stable_secret") == 0) {
198-
dD("Skipping file %s", mibpath);
199-
oval_ftsent_free(ofts_ent);
200-
SEXP_free(se_mib);
201-
fclose(fp);
202-
continue;
203-
} else {
204-
dE("An error ocured when reading from \"%s\" (fp=%p): l=%ld, %u, %s",
205-
mibpath, fp, l, errno, strerror(errno));
206-
goto fail_item;
207-
}
192+
/* Linux 4.1.0 introduced a per-NIC IPv6 stable_secret file.
193+
* The stable_secret file cannot be read until it is set,
194+
* so we skip it when it is not readable. Otherwise we collect it.
195+
*/
196+
if (strncmp(ofts_ent->path, ipv6_conf_path, ipv6_conf_path_len) == 0 &&
197+
strcmp(ofts_ent->file, "stable_secret") == 0) {
198+
dD("Skipping file %s", mibpath);
199+
oval_ftsent_free(ofts_ent);
200+
SEXP_free(se_mib);
201+
fclose(fp);
202+
continue;
203+
} else {
204+
dE("An error occurred when reading from \"%s\" (fp=%p): l=%ld, %u, %s",
205+
mibpath, fp, l, errno, strerror(errno));
206+
goto fail_item;
207+
}
208208
}
209209

210210
fclose(fp);
211211

212-
/* Skip empty values as sysctl tool does.
213-
* See https://bugzilla.redhat.com/show_bug.cgi?id=1473207
214-
*/
215-
if (l == 0) {
216-
dD("Skipping file '%s' because it has no value.", mibpath);
217-
oval_ftsent_free(ofts_ent);
218-
SEXP_free(se_mib);
219-
continue;
220-
}
212+
/* Skip empty values as sysctl tool does.
213+
* See https://bugzilla.redhat.com/show_bug.cgi?id=1473207
214+
*/
215+
if (l == 0) {
216+
dD("Skipping file '%s' because it has no value.", mibpath);
217+
oval_ftsent_free(ofts_ent);
218+
SEXP_free(se_mib);
219+
continue;
220+
}
221221

222222
/*
223223
* sanitize the value
@@ -227,8 +227,8 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
227227
sysvals[0] = sysval;
228228

229229
for(s = 0, i = 0; i < l && s < sizeof sysvals/sizeof(char *) - 1; ++i) {
230-
if ((!isprint(sysval[i]) && !isspace(sysval[i]))
231-
|| (over_cmp >= 0 && sysval[i] == '\n' /* OVAL 5.10 and above */))
230+
if ((!isprint(sysval[i]) && !isspace(sysval[i]))
231+
|| (over_cmp >= 0 && sysval[i] == '\n' /* OVAL 5.10 and above */))
232232
{
233233
sysval[i] = '\0';
234234
sysvals[++s] = sysval + i + 1;
@@ -246,24 +246,24 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
246246
sysvals[++s] = NULL;
247247

248248
if (over_cmp >= 0) {
249-
/* Only in OVAL 5.10 and above */
250-
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL,
251-
"name", OVAL_DATATYPE_SEXP, se_mib,
252-
"value", OVAL_DATATYPE_STRING_M, sysvals,
253-
NULL);
249+
/* Only in OVAL 5.10 and above */
250+
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL,
251+
"name", OVAL_DATATYPE_SEXP, se_mib,
252+
"value", OVAL_DATATYPE_STRING_M, sysvals,
253+
NULL);
254254
} else {
255-
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL,
256-
"name", OVAL_DATATYPE_SEXP, se_mib,
257-
"value", OVAL_DATATYPE_STRING, sysval,
258-
NULL);
255+
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL,
256+
"name", OVAL_DATATYPE_SEXP, se_mib,
257+
"value", OVAL_DATATYPE_STRING, sysval,
258+
NULL);
259259
}
260260

261261
goto add_item;
262262
fail_item:
263263
if (fp != NULL)
264264
fclose(fp);
265265

266-
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL, NULL);
266+
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL, NULL);
267267
probe_item_setstatus(item, SYSCHAR_STATUS_ERROR);
268268
add_item:
269269
probe_item_collect(ctx, item);
@@ -274,91 +274,91 @@ int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
274274
}
275275

276276
oval_fts_close(ofts);
277-
SEXP_free(path_entity);
278-
SEXP_free(filename_entity);
279-
SEXP_free(bh_entity);
280-
SEXP_free(name_entity);
277+
SEXP_free(path_entity);
278+
SEXP_free(filename_entity);
279+
SEXP_free(bh_entity);
280+
SEXP_free(name_entity);
281281

282282
return (0);
283283
}
284284

285285
#elif defined(OS_FREEBSD)
286286
int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)
287287
{
288-
FILE *fp;
289-
char output[LINE_MAX];
290-
const char* SEP = "=";
291-
char* mib;
292-
char* sysval;
293-
SEXP_t *se_mib;
294-
SEXP_t *name_entity, *probe_in;
295-
296-
probe_in = probe_ctx_getobject(ctx);
297-
name_entity = probe_obj_getent(probe_in, "name", 1);
298-
299-
if (name_entity == NULL) {
300-
dE("Missing \"name\" entity in the input object");
301-
return (PROBE_ENOENT);
302-
}
303-
304-
/* FreeBSD's sysctl(8) uses undocumented, and potentially unstable,
305-
* kernel interfaces to obtain the list of system properties and values.
306-
* Hence we call the executable and parse its output rather than
307-
* implement the functionality ourselves which risks breakage if/when
308-
* the interfaces change.
309-
*/
310-
fp = popen(SYSCTL_CMD, "r");
311-
312-
if (!fp) {
313-
dE("Failed to open output of %s", SYSCTL_CMD);
314-
return (PROBE_EFATAL);
315-
}
316-
317-
while (fgets(output, sizeof(output), fp)) {
318-
char *strp;
319-
mib = strtok_r(output, SEP, &strp);
320-
sysval = strtok_r(NULL, SEP, &strp);
321-
322-
if (!mib)
323-
continue;
324-
325-
if (!sysval)
326-
continue;
327-
328-
se_mib = SEXP_string_new(mib, strlen(mib));
329-
330-
if (!se_mib) {
331-
dE("Failed to allocate new SEXP_string for se_mib");
332-
pclose(fp);
333-
return (PROBE_ENOENT);
334-
}
335-
336-
/* Remove newline */
337-
sysval[strlen(sysval)-1] = '\0';
338-
339-
if (probe_entobj_cmp(name_entity, se_mib) == OVAL_RESULT_TRUE) {
340-
SEXP_t *item;
341-
342-
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL,
343-
"name", OVAL_DATATYPE_SEXP, se_mib,
344-
"value", OVAL_DATATYPE_STRING, sysval,
345-
NULL);
346-
347-
if (!item) {
348-
dE("probe_item_create() returned a null item");
349-
pclose(fp);
350-
SEXP_free(se_mib);
351-
return (PROBE_ENOENT);
352-
}
353-
354-
probe_item_collect(ctx, item);
355-
}
356-
357-
SEXP_free(se_mib);
288+
FILE *fp;
289+
char output[LINE_MAX];
290+
const char* SEP = "=";
291+
char* mib;
292+
char* sysval;
293+
SEXP_t *se_mib;
294+
SEXP_t *name_entity, *probe_in;
295+
296+
probe_in = probe_ctx_getobject(ctx);
297+
name_entity = probe_obj_getent(probe_in, "name", 1);
298+
299+
if (name_entity == NULL) {
300+
dE("Missing \"name\" entity in the input object");
301+
return (PROBE_ENOENT);
302+
}
303+
304+
/* FreeBSD's sysctl(8) uses undocumented, and potentially unstable,
305+
* kernel interfaces to obtain the list of system properties and values.
306+
* Hence we call the executable and parse its output rather than
307+
* implement the functionality ourselves which risks breakage if/when
308+
* the interfaces change.
309+
*/
310+
fp = popen(SYSCTL_CMD, "r");
311+
312+
if (!fp) {
313+
dE("Failed to open output of %s", SYSCTL_CMD);
314+
return (PROBE_EFATAL);
358315
}
359316

360-
pclose(fp);
361-
return (0);
317+
while (fgets(output, sizeof(output), fp)) {
318+
char *strp;
319+
mib = strtok_r(output, SEP, &strp);
320+
sysval = strtok_r(NULL, SEP, &strp);
321+
322+
if (!mib)
323+
continue;
324+
325+
if (!sysval)
326+
continue;
327+
328+
se_mib = SEXP_string_new(mib, strlen(mib));
329+
330+
if (!se_mib) {
331+
dE("Failed to allocate new SEXP_string for se_mib");
332+
pclose(fp);
333+
return (PROBE_ENOENT);
334+
}
335+
336+
/* Remove newline */
337+
sysval[strlen(sysval)-1] = '\0';
338+
339+
if (probe_entobj_cmp(name_entity, se_mib) == OVAL_RESULT_TRUE) {
340+
SEXP_t *item;
341+
342+
item = probe_item_create(OVAL_UNIX_SYSCTL, NULL,
343+
"name", OVAL_DATATYPE_SEXP, se_mib,
344+
"value", OVAL_DATATYPE_STRING, sysval,
345+
NULL);
346+
347+
if (!item) {
348+
dE("probe_item_create() returned a null item");
349+
pclose(fp);
350+
SEXP_free(se_mib);
351+
return (PROBE_ENOENT);
352+
}
353+
354+
probe_item_collect(ctx, item);
355+
}
356+
357+
SEXP_free(se_mib);
358+
}
359+
360+
pclose(fp);
361+
return (0);
362362
}
363363
#else
364364
int sysctl_probe_main(probe_ctx *ctx, void *probe_arg)

0 commit comments

Comments
 (0)