Debian Codegraph @

src/OVAL/probes/unix/symlink_probe.c

raw symbols SCIP
1 /**
2 * @file symlink_probe.c
3 * @brief implementation of the symlink_object
4 * @author "Jan Černý" <[email protected]>
5 */
6
7 /*
8 * Copyright 2015 Red Hat Inc., Durham, North Carolina.
9 * All Rights Reserved.
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Authors:
26 * Jan Černý <[email protected]>
27 */
28
29 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
30 #include <config.h>cxx . . $ `<file>/build/config.h`/
31 #endif
32
33 #include <probe-api.h>cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
34 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
35 #include <string.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <unistd.h>
39 #include <errno.h>
40 #include <limits.h>
41 #include <stdlib.h>
42 #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/
43
44 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
45 #include <probe/option.h>cxx . . $ `<file>/src/OVAL/probes/probe/option.h`/
46 #include "symlink_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/symlink_probe.h`/
47
48 static int collect_symlinkcxx . . $ collect_symlink(241d6c535218441).(SEXP_tcxx . . $ SEXP_t# *ent, probe_ctxcxx . . $ probe_ctx# *ctx)
49 {
50 SEXP_tcxx . . $ SEXP_t# *ent_val, *item_sexp, *msg;
51 struct statcxx . . $ stat# sb;
52 char *linkname;
53 char resolved_name[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!];
54
55 ent_val = probe_ent_getvalcxx . . $ probe_ent_getval(2f7f980afaaae0f0).(ent);
56 char *pathname = SEXP_string_cstrcxx . . $ SEXP_string_cstr(c831a2fa12818dfe).(ent_val);
57 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(ent_val);
58 if (pathname == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
59 return PROBE_EINVALcxx . . $ `src/OVAL/probes/public/probe-common.h:8:9`!;
60 }
61 if (probe_path_is_blockedcxx . . $ probe_path_is_blocked(6f786adec44f4a13).(pathname, ctx->blocked_pathscxx . . $ probe_ctx#blocked_paths.)) {
62 freecxx . . $ free(5d22bdacc48458e8).(pathname);
63 return 0;
64 }
65
66 if (lstatcxx . . $ lstat(a9cd1e23e96f423c).(pathname, &sb) == -1) {
67 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
68 /* File does not exist.
69 * Resulting item should have a status of "does not exist". */
70 msg = probe_msg_creatfcxx . . $ probe_msg_creatf(2da488f08a70551b).(OVAL_MESSAGE_LEVEL_INFOcxx . . $ OVAL_MESSAGE_LEVEL_INFO.,
71 "File '%s' does not exist.", pathname);
72 } else {
73 /* error */
74 msg = probe_msg_creatcxx . . $ probe_msg_creat(c07e3aa4e7ab9719).(OVAL_MESSAGE_LEVEL_ERRORcxx . . $ OVAL_MESSAGE_LEVEL_ERROR., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
75 probe_cobj_set_flagcxx . . $ probe_cobj_set_flag(644bab5dffe689c).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), SYSCHAR_FLAG_ERRORcxx . . $ SYSCHAR_FLAG_ERROR.);
76 }
77 probe_cobj_add_msgcxx . . $ probe_cobj_add_msg(ef7ee42b5817e0be).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), msg);
78 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(msg);
79 freecxx . . $ free(5d22bdacc48458e8).(pathname);
80 return 0;
81 }
82
83 if (!S_ISLNKcxx . . $ `<external>/531885356569766532/stat.h:133:10`!(sb.st_mode)) {
84 /* File is not a symlink.
85 * Resulting item should have a status "does not exist". */
86 msg = probe_msg_creatfcxx . . $ probe_msg_creatf(2da488f08a70551b).(OVAL_MESSAGE_LEVEL_INFOcxx . . $ OVAL_MESSAGE_LEVEL_INFO.,
87 "File '%s' is not a symlink.", pathname);
88 probe_cobj_add_msgcxx . . $ probe_cobj_add_msg(ef7ee42b5817e0be).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), msg);
89 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(msg);
90 freecxx . . $ free(5d22bdacc48458e8).(pathname);
91 return 0;
92 }
93
94 linkname = oscap_realpathcxx . . $ oscap_realpath(ed8193f262e4eda).(pathname, resolved_name);
95 if (linkname == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
96 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
97 msg = probe_msg_creatfcxx . . $ probe_msg_creatf(2da488f08a70551b).(OVAL_MESSAGE_LEVEL_ERRORcxx . . $ OVAL_MESSAGE_LEVEL_ERROR.,
98 "Link target of symlink '%s' does not exist.", pathname);
99 } else if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ELOOPcxx . . $ `<external>/17922322188510340118/errno.h:21:9`!) {
100 msg = probe_msg_creatfcxx . . $ probe_msg_creatf(2da488f08a70551b).(OVAL_MESSAGE_LEVEL_ERRORcxx . . $ OVAL_MESSAGE_LEVEL_ERROR.,
101 "Link '%s' is a circular link.", pathname);
102 } else {
103 msg = probe_msg_creatcxx . . $ probe_msg_creat(c07e3aa4e7ab9719).(OVAL_MESSAGE_LEVEL_ERRORcxx . . $ OVAL_MESSAGE_LEVEL_ERROR., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
104 }
105 probe_cobj_add_msgcxx . . $ probe_cobj_add_msg(ef7ee42b5817e0be).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), msg);
106 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(msg);
107 probe_cobj_set_flagcxx . . $ probe_cobj_set_flag(644bab5dffe689c).(probe_ctx_getresultcxx . . $ probe_ctx_getresult(4299b6b53fa804a5).(ctx), SYSCHAR_FLAG_ERRORcxx . . $ SYSCHAR_FLAG_ERROR.);
108 freecxx . . $ free(5d22bdacc48458e8).(pathname);
109 return 0;
110 }
111
112
113 item_sexp = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_UNIX_SYMLINKcxx . . $ OVAL_UNIX_SYMLINK., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
114 "filepath", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., pathname,
115 "canonical_path", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., linkname,
116 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
117 probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item_sexp);
118
119 freecxx . . $ free(5d22bdacc48458e8).(pathname);
120 return 0;
121 }
122
123 int symlink_probe_offline_mode_supportedcxx . . $ symlink_probe_offline_mode_supported(b126dc7c1de90089).()
124 {
125 return PROBE_OFFLINE_CHROOTcxx . . $ PROBE_OFFLINE_CHROOT.;
126 }
127
128 int symlink_probe_maincxx . . $ symlink_probe_main(470536d3ffacaf10).(probe_ctxcxx . . $ probe_ctx# *ctx, void *probe_arg)
129 {
130 int err;
131 SEXP_tcxx . . $ SEXP_t# *entity, *probe_in;
132 oval_schema_version_tcxx . . $ oval_schema_version_t# oval_version;
133
134 probe_in = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx);
135
136 oval_version = probe_obj_get_platform_schema_versioncxx . . $ probe_obj_get_platform_schema_version(5bacca80194debea).(probe_in);
137 if (oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(oval_version, OVAL_SCHEMA_VERSIONcxx . . $ `src/OVAL/public/oval_schema_version.h:39:9`!(5.11)) < 0) {
138 // OVAL 5.10 and less
139 return PROBE_EOPNOTSUPPcxx . . $ `src/OVAL/probes/public/probe-common.h:14:9`!;
140 }
141
142 entity = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(probe_in, "filepath", 1);
143
144 err = collect_symlinkcxx . . $ collect_symlink(241d6c535218441).(entity, ctx);
145
146 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(entity);
147 return err;
148 }