14
14
#include <aducpal/stdlib.h> // setenv
15
15
#include <azure_c_shared_utility/crt_abstractions.h>
16
16
#include <azure_c_shared_utility/strings_types.h>
17
+ #include <errno.h>
17
18
#include <parson.h>
18
19
#include <parson_json_utils.h>
19
20
#include <pthread.h>
20
21
#include <stdbool.h>
21
22
#include <stdlib.h>
22
23
#include <string.h>
23
- #include <errno.h>
24
24
25
25
static pthread_mutex_t s_config_mutex = PTHREAD_MUTEX_INITIALIZER ;
26
26
@@ -68,8 +68,8 @@ static const char* INVALID_OR_MISSING_FIELD_ERROR_FMT = "Invalid json - '%s' mis
68
68
69
69
static void ADUC_AgentInfo_Free (ADUC_AgentInfo * agent );
70
70
71
-
72
- static char * ADUC_AgentInfo_Read_X509_File ( const char * const x509_file_path ) {
71
+ static char * ADUC_AgentInfo_Read_X509_File ( const char * const x509_file_path )
72
+ {
73
73
char * buffer = NULL ;
74
74
long ftellResult = 0 ;
75
75
size_t bufferLength = 0 ;
@@ -118,7 +118,8 @@ static char* ADUC_AgentInfo_Read_X509_File(const char* const x509_file_path) {
118
118
{
119
119
Log_Error ("Unexpected end of file while reading '%s' (bytesRead: %zu)!" , x509_file_path , bytesRead );
120
120
}
121
- else if (ferror (x509File )) {
121
+ else if (ferror (x509File ))
122
+ {
122
123
Log_Error ("Error occurred while reading '%s' (bytesRead: %zu)!" , x509_file_path , bytesRead );
123
124
}
124
125
else
@@ -191,8 +192,10 @@ static bool ADUC_AgentInfo_Init(ADUC_AgentInfo* agent, const JSON_Object* agent_
191
192
connection_type = json_object_get_string (connection_source , CONFIG_CONNECTION_TYPE );
192
193
connection_data = json_object_get_string (connection_source , CONFIG_CONNECTION_DATA );
193
194
connection_x509_cert_file_path = json_object_get_string (connection_source , CONFIG_CONNECTION_X509_CERT_FILE_PATH );
194
- connection_x509_private_key_file_path = json_object_get_string (connection_source , CONFIG_CONNECTION_X509_PRIVATE_KEY_FILE_PATH );
195
- connection_x509_ca_cert_file_path = json_object_get_string (connection_source , CONFIG_CONNECTION_X509_CA_CERT_FILE_PATH );
195
+ connection_x509_private_key_file_path =
196
+ json_object_get_string (connection_source , CONFIG_CONNECTION_X509_PRIVATE_KEY_FILE_PATH );
197
+ connection_x509_ca_cert_file_path =
198
+ json_object_get_string (connection_source , CONFIG_CONNECTION_X509_CA_CERT_FILE_PATH );
196
199
197
200
// As these fields are mandatory, if any of the fields doesn't exist, the agent will fail to be constructed.
198
201
if (name == NULL || runas == NULL || connection_type == NULL || connection_data == NULL || manufacturer == NULL
@@ -221,8 +224,11 @@ static bool ADUC_AgentInfo_Init(ADUC_AgentInfo* agent, const JSON_Object* agent_
221
224
goto done ;
222
225
}
223
226
224
- if (connection_x509_cert_file_path || connection_x509_private_key_file_path || connection_x509_ca_cert_file_path ) {
225
- if (connection_x509_cert_file_path && connection_x509_private_key_file_path && connection_x509_ca_cert_file_path ) {
227
+ if (connection_x509_cert_file_path || connection_x509_private_key_file_path || connection_x509_ca_cert_file_path )
228
+ {
229
+ if (connection_x509_cert_file_path && connection_x509_private_key_file_path
230
+ && connection_x509_ca_cert_file_path )
231
+ {
226
232
agent -> x509Cert = ADUC_AgentInfo_Read_X509_File (connection_x509_cert_file_path );
227
233
if (!agent -> x509Cert )
228
234
{
@@ -238,8 +244,11 @@ static bool ADUC_AgentInfo_Init(ADUC_AgentInfo* agent, const JSON_Object* agent_
238
244
{
239
245
goto done ;
240
246
}
241
- } else {
242
- Log_Error ("Incomplete X509 client certificate configuration! Cert file path or private key file path is missing." );
247
+ }
248
+ else
249
+ {
250
+ Log_Error (
251
+ "Incomplete X509 client certificate configuration! Cert file path or private key file path is missing." );
243
252
}
244
253
}
245
254
0 commit comments