@@ -81,6 +81,7 @@ static void hsicache_callback(char *name, const uint32_t value)
8181 }
8282 entry -> name = oscap_strdup (name );
8383 entry -> hsi_result = value ;
84+ dD ("HSI cache add name: %s value: %d\n" , entry -> name , entry -> hsi_result );
8485 LIST_INSERT_HEAD (& hsi_result_cache , entry , entries );
8586}
8687
@@ -89,12 +90,13 @@ static uint32_t hsicache_get(const char *key)
8990 struct secattr_cache * next ;
9091
9192 LIST_FOREACH (next , & hsi_result_cache , entries ) {
92- dD ("HSI search key %s name %s value %d\n" , key , next -> name , next -> hsi_result );
93+ dD ("HSI search key: %s ( name: %s value: %d) \n" , key , next -> name , next -> hsi_result );
9394 if (!strncmp (next -> name , key , strlen (next -> name ))) {
9495 return next -> hsi_result ;
9596 }
9697 }
9798
99+ dW ("HSI key not found: %s\n" , key );
98100 return UINT32_MAX ;
99101}
100102
@@ -119,13 +121,14 @@ static int get_all_security_attributes(DBusConnection *conn, void(*callback)(cha
119121 }
120122
121123 DBusMessageIter args , property_iter ;
124+ _DBusBasicValue value ;
122125
123126 if (!dbus_connection_send_with_reply (conn , msg , & pending , -1 )) {
124- dD ("Failed to send message via dbus !" );
127+ dD ("Failed to send message via D-Bus !" );
125128 goto cleanup ;
126129 }
127130 if (pending == NULL ) {
128- dD ("Invalid dbus pending call!" );
131+ dD ("Invalid D-Bus pending call!" );
129132 goto cleanup ;
130133 }
131134
@@ -135,18 +138,19 @@ static int get_all_security_attributes(DBusConnection *conn, void(*callback)(cha
135138 dbus_pending_call_block (pending );
136139 msg = dbus_pending_call_steal_reply (pending );
137140 if (msg == NULL ) {
138- dD ("Failed to steal dbus pending call reply." );
141+ dD ("Failed to steal D-Bus pending call reply." );
139142 goto cleanup ;
140143 }
141144 dbus_pending_call_unref (pending ); pending = NULL ;
142145
143146 if (!dbus_message_iter_init (msg , & args )) {
144- dD ("Failed to initialize iterator over received dbus message." );
147+ dD ("Failed to initialize iterator over received D-Bus message." );
145148 goto cleanup ;
146149 }
147150
148151 if (dbus_message_get_type (msg ) == DBUS_MESSAGE_TYPE_ERROR ) {
149- dD ("Receive an error exception from dBus" );
152+ dbus_message_iter_get_basic (& args , & value );
153+ dW ("Received an error from D-Bus (%s): %s" , dbus_message_get_error_name (msg ), value .str );
150154 goto cleanup ;
151155 }
152156
@@ -180,7 +184,6 @@ static int get_all_security_attributes(DBusConnection *conn, void(*callback)(cha
180184 goto cleanup ;
181185 }
182186
183- _DBusBasicValue value ;
184187 dbus_message_iter_get_basic (& dict_entry , & value );
185188 property_name = oscap_strdup (value .str );
186189 dD ("Element key: %s" , property_name );
@@ -274,13 +277,17 @@ fwupd_security_attr_result_to_string(FwupdSecurityAttrResult result)
274277 return "supported" ;
275278 if (result == FWUPD_SECURITY_ATTR_RESULT_NOT_SUPPORTED )
276279 return "not-supported" ;
277- return NULL ;
280+ if (result == FWUPD_SECURITY_ATTR_RESULT_UNKNOWN ) {
281+ dD ("Got FWUPD_SECURITY_ATTR_RESULT_UNKNOWN\n" );
282+ return "unknown" ;
283+ }
284+ dW ("Unknown/invalid FwupdSecurityAttrResult value: %d\n" , result );
285+ return "invalid-hsi-result" ;
278286}
279287
280288int fwupdsecattr_probe_main (probe_ctx * ctx , void * arg )
281289{
282290 SEXP_t * val , * item , * ent , * probe_in ;
283- oval_schema_version_t oval_version ;
284291 char * stream_id = NULL ;
285292 const char * hsi_result_str ;
286293 uint64_t hsi_result = UINT64_MAX ;
@@ -294,12 +301,7 @@ int fwupdsecattr_probe_main(probe_ctx *ctx, void *arg)
294301 if (probe_in == NULL )
295302 return PROBE_ENOOBJ ;
296303
297- oval_version = probe_obj_get_platform_schema_version (probe_in );
298- if (oval_schema_version_cmp (oval_version , OVAL_SCHEMA_VERSION (5.11 .3 )) < 0 ) {
299- return PROBE_EOPNOTSUPP ;
300- }
301-
302- ent = probe_obj_getent (probe_in , "stream-id" , 1 );
304+ ent = probe_obj_getent (probe_in , "stream_id" , 1 );
303305 if (ent == NULL )
304306 return PROBE_ENOENT ;
305307
@@ -313,25 +315,28 @@ int fwupdsecattr_probe_main(probe_ctx *ctx, void *arg)
313315 SEXP_free (val );
314316 SEXP_free (ent );
315317
316- DBusError dbus_error ;
317- DBusConnection * dbus_conn ;
318-
319318 if (LIST_EMPTY (& hsi_result_cache )) {
319+ DBusError dbus_error ;
320+ DBusConnection * dbus_conn ;
321+
320322 dbus_error_init (& dbus_error );
321323 dbus_conn = connect_dbus ();
322324
323325 if (dbus_conn == NULL ) {
324326 dbus_error_free (& dbus_error );
325- SEXP_t * msg = probe_msg_creat (OVAL_MESSAGE_LEVEL_INFO , "DBus connection failed, could not identify fwupd." );
327+ SEXP_t * msg = probe_msg_creat (OVAL_MESSAGE_LEVEL_INFO , "D-Bus connection failed, could not identify fwupd." );
326328 probe_cobj_set_flag (probe_ctx_getresult (ctx ), SYSCHAR_FLAG_ERROR );
327329 probe_cobj_add_msg (probe_ctx_getresult (ctx ), msg );
328330 SEXP_free (msg );
329331 return 0 ;
330332 }
331333
332- if (get_all_security_attributes (dbus_conn , hsicache_callback , NULL )) {
334+ int res = get_all_security_attributes (dbus_conn , hsicache_callback , NULL );
335+ disconnect_dbus (dbus_conn );
336+
337+ if (res ) {
333338 dbus_error_free (& dbus_error );
334- SEXP_t * msg = probe_msg_creat (OVAL_MESSAGE_LEVEL_INFO , "fwupd is not properly installed or configured." );
339+ SEXP_t * msg = probe_msg_creat (OVAL_MESSAGE_LEVEL_INFO , "The fwupd service is not properly installed or configured." );
335340 probe_cobj_set_flag (probe_ctx_getresult (ctx ), SYSCHAR_FLAG_ERROR );
336341 probe_cobj_add_msg (probe_ctx_getresult (ctx ), msg );
337342 SEXP_free (msg );
@@ -343,7 +348,7 @@ int fwupdsecattr_probe_main(probe_ctx *ctx, void *arg)
343348
344349 if (hsi_result == UINT32_MAX ) {
345350 item = probe_item_create (OVAL_LINUX_FWUPDSECATTR , NULL ,
346- "security-attr " , OVAL_DATATYPE_STRING , "Attribute not found" ,
351+ "security_attr " , OVAL_DATATYPE_STRING , "not- found" ,
347352 NULL );
348353 probe_item_setstatus (item , SYSCHAR_STATUS_NOT_COLLECTED );
349354 probe_item_collect (ctx , item );
@@ -352,12 +357,11 @@ int fwupdsecattr_probe_main(probe_ctx *ctx, void *arg)
352357
353358 hsi_result_str = fwupd_security_attr_result_to_string (hsi_result );
354359 item = probe_item_create (OVAL_LINUX_FWUPDSECATTR , NULL ,
355- "security-attr " , OVAL_DATATYPE_STRING , hsi_result_str ,
360+ "security_attr " , OVAL_DATATYPE_STRING , hsi_result_str ,
356361 NULL );
357362 probe_item_collect (ctx , item );
358363
359364exit :
360365 free (stream_id );
361- disconnect_dbus (dbus_conn );
362366 return 0 ;
363367}
0 commit comments