Debian Codegraph @

src/OVAL/probes/unix/linux/dpkginfo_probe.c

raw symbols SCIP
1 /**
2 * @file dpkginfo_probe.c
3 * @brief dpkginfo probe
4 * @author "Pierre Chifflier" <[email protected]>
5 */
6
7 /*
8 * Copyright 2009 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 * "Pierre Chifflier <[email protected]>"
27 */
28
29
30 /*
31 * dpkginfo probe:
32 *
33 * dpkginfo_object(string name)
34 *
35 * dpkginfo_state(string name,
36 * string arch,
37 * string epoch,
38 * string release,
39 * string version,
40 * string evr,
41 * string signature_keyid)
42 */
43
44 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
45 #include <config.h>cxx . . $ `<file>/build/config.h`/
46 #endif
47
48 #include <stdio.h>
49 #include <string.h>
50 #include <errno.h>
51 #include <assert.h>
52
53 /* SEAP */
54 #include "_seap.h"cxx . . $ `<file>/src/OVAL/probes/SEAP/_seap.h`/
55 #include <probe-api.h>cxx . . $ `<file>/src/OVAL/probes/public/probe-api.h`/
56
57 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
58 #include "public/oval_schema_version.h"cxx . . $ `<file>/src/OVAL/public/oval_schema_version.h`/
59
60 #include <probe/probe.h>cxx . . $ `<file>/src/OVAL/probes/probe/probe.h`/
61
62 #include "dpkginfo-helper.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/dpkginfo-helper.h`/
63
64 #include "dpkginfo_probe.h"cxx . . $ `<file>/src/OVAL/probes/unix/linux/dpkginfo_probe.h`/
65
66 int dpkginfo_probe_offline_mode_supportedcxx . . $ dpkginfo_probe_offline_mode_supported(b126dc7c1de90089).(void) {
67 return PROBE_OFFLINE_OWNcxx . . $ PROBE_OFFLINE_OWN.;
68 }
69
70 int dpkginfo_probe_maincxx . . $ dpkginfo_probe_main(470536d3ffacaf10). (probe_ctxcxx . . $ probe_ctx# *ctx, void *arg)
71 {
72 SEXP_tcxx . . $ SEXP_t# *val, *item, *ent, *obj;
73 char *request_st = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
74 struct dpkginfo_reply_tcxx . . $ dpkginfo_reply_t# *dpkginfo_reply = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
75 int errflag;
76
77 obj = probe_ctx_getobjectcxx . . $ probe_ctx_getobject(4299b6b53fa804a5).(ctx);
78 ent = probe_obj_getentcxx . . $ probe_obj_getent(7907a01f2ff841f3).(obj, "name", 1);
79
80 if (ent == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
81 return (PROBE_ENOENTcxx . . $ `src/OVAL/probes/public/probe-common.h:20:9`!);
82 }
83
84 val = probe_ent_getvalcxx . . $ probe_ent_getval(2f7f980afaaae0f0). (ent);
85
86 if (val == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
87 dDcxx . . $ `src/common/debug_priv.h:64:9`!("%s: no value", "name");
88 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (ent);
89 return (PROBE_ENOVALcxx . . $ `src/OVAL/probes/public/probe-common.h:10:9`!);
90 }
91
92 request_st = SEXP_string_cstrcxx . . $ SEXP_string_cstr(c831a2fa12818dfe). (val);
93 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (val);
94
95 if (request_st == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
96 switch (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!) {
97 case EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!:
98 dDcxx . . $ `src/common/debug_priv.h:64:9`!("%s: invalid value type", "name");
99 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (ent);
100 return PROBE_EINVALcxx . . $ `src/OVAL/probes/public/probe-common.h:8:9`!;
101 break;
102 case EFAULTcxx . . $ `<external>/8987895939074593727/errno-base.h:18:9`!:
103 dDcxx . . $ `src/common/debug_priv.h:64:9`!("%s: element not found", "name");
104 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (ent);
105 return PROBE_ENOELMcxx . . $ `src/OVAL/probes/public/probe-common.h:9:9`!;
106 break;
107 default:
108 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4). (ent);
109 return PROBE_EUNKNOWNcxx . . $ `src/OVAL/probes/public/probe-common.h:24:9`!;
110 }
111 }
112
113 /* get info from debian apt cache */
114 dpkginfo_reply = dpkginfo_get_by_namecxx . . $ dpkginfo_get_by_name(2e3b51866dbd47b4).(request_st, &errflag);
115
116 if (dpkginfo_reply == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
117 switch (errflag) {
118 case 0: /* Not found */
119 {
120 dDcxx . . $ `src/common/debug_priv.h:64:9`!("Package \"%s\" not found.", request_st);
121 break;
122 }
123 case -1: /* Error */
124 {
125 dDcxx . . $ `src/common/debug_priv.h:64:9`!("dpkginfo_get_by_name failed.");
126 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c).(OVAL_LINUX_DPKG_INFOcxx . . $ OVAL_LINUX_DPKG_INFO., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
127 "name", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., request_st,
128 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
129 probe_item_setstatuscxx . . $ probe_item_setstatus(112b785eb420e6c0). (item, SYSCHAR_STATUS_ERRORcxx . . $ SYSCHAR_STATUS_ERROR.);
130 probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item);
131 break;
132 }
133 }
134 } else { /* Ok */
135 int i;
136 int num_items = 1; /* FIXME */
137 oval_datatype_tcxx . . $ oval_datatype_t# evr_string_type;
138 oval_schema_version_tcxx . . $ oval_schema_version_t# oval_version = probe_obj_get_platform_schema_versioncxx . . $ probe_obj_get_platform_schema_version(5bacca80194debea).(obj);
139 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.1)) >= 0) {
140 evr_string_type = OVAL_DATATYPE_DEBIAN_EVR_STRINGcxx . . $ OVAL_DATATYPE_DEBIAN_EVR_STRING.;
141 } else {
142 evr_string_type = OVAL_DATATYPE_EVR_STRINGcxx . . $ OVAL_DATATYPE_EVR_STRING.;
143 }
144
145 for (i = 0; i < num_items; ++i) {
146 dDcxx . . $ `src/common/debug_priv.h:64:9`!("%s: element found version %s", dpkginfo_reply->name, dpkginfo_reply->evr);
147 item = probe_item_createcxx . . $ probe_item_create(36b16a6622050a9c). (OVAL_LINUX_DPKG_INFOcxx . . $ OVAL_LINUX_DPKG_INFO., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!,
148 "name", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., dpkginfo_reply->namecxx . . $ dpkginfo_reply_t#name.,
149 "arch", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., dpkginfo_reply->archcxx . . $ dpkginfo_reply_t#arch.,
150 "epoch", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., dpkginfo_reply->epochcxx . . $ dpkginfo_reply_t#epoch.,
151 "release", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., dpkginfo_reply->releasecxx . . $ dpkginfo_reply_t#release.,
152 "version", OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING., dpkginfo_reply->versioncxx . . $ dpkginfo_reply_t#version.,
153 "evr", evr_string_type, dpkginfo_reply->evrcxx . . $ dpkginfo_reply_t#evr.,
154 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
155
156 probe_item_collectcxx . . $ probe_item_collect(11bb80e0c30650d7).(ctx, item);
157
158 dpkginfo_free_replycxx . . $ dpkginfo_free_reply(d06f8a2c2281da9b).(dpkginfo_reply);
159 }
160 }
161
162 SEXP_freecxx . . $ SEXP_free(c6b28547479798f4).(ent);
163 freecxx . . $ free(5d22bdacc48458e8).(request_st);
164
165 return (0);
166 }