69
69
#define FILE_SEPARATOR '/'
70
70
71
71
struct cbargs {
72
- probe_ctx * ctx ;
72
+ probe_ctx * ctx ;
73
73
int error ;
74
- SEXP_t * attr_ent ;
74
+ SEXP_t * attr_ent ;
75
75
};
76
76
77
77
static int file_cb (const char * prefix , const char * p , const char * f , void * ptr , SEXP_t * gr_lastpath )
78
78
{
79
- char path_buffer [PATH_MAX ];
80
- SEXP_t * item , xattr_name ;
81
- struct cbargs * args = (struct cbargs * ) ptr ;
82
- const char * st_path ;
79
+ char path_buffer [PATH_MAX ];
80
+ SEXP_t * item , xattr_name ;
81
+ struct cbargs * args = (struct cbargs * ) ptr ;
82
+ const char * st_path ;
83
83
84
- ssize_t xattr_count = -1 ;
85
- char * xattr_buf = NULL ;
86
- size_t xattr_buflen = 0 , i ;
84
+ ssize_t xattr_count = -1 ;
85
+ char * xattr_buf = NULL ;
86
+ size_t xattr_buflen = 0 , i ;
87
87
88
88
if (f == NULL ) {
89
89
st_path = p ;
@@ -98,23 +98,22 @@ static int file_cb(const char *prefix, const char *p, const char *f, void *ptr,
98
98
st_path = path_buffer ;
99
99
}
100
100
101
- SEXP_init (& xattr_name );
101
+ SEXP_init (& xattr_name );
102
102
103
103
char * st_path_with_prefix = oscap_path_join (prefix , st_path );
104
104
do {
105
105
/* estimate the size of the buffer */
106
-
107
106
xattr_count = llistxattr (st_path_with_prefix , NULL , 0 );
108
107
109
108
if (xattr_count == 0 ) {
110
109
free (st_path_with_prefix );
111
- return ( 0 ) ;
110
+ return 0 ;
112
111
}
113
112
114
113
if (xattr_count < 0 ) {
115
114
free (st_path_with_prefix );
116
- dD ("FAIL: llistxattr(%s, %p, %zu): errno=%u, %s." , errno , strerror (errno ));
117
- return 0 ;
115
+ dD ("FAIL: llistxattr(%s, %p, %zu): errno=%u, %s." , errno , strerror (errno ));
116
+ return 0 ;
118
117
}
119
118
120
119
/* allocate space for xattr names */
@@ -127,12 +126,12 @@ static int file_cb(const char *prefix, const char *p, const char *f, void *ptr,
127
126
/* check & retry if needed */
128
127
} while (errno == ERANGE );
129
128
130
- if (xattr_count < 0 ) {
131
- dD ("FAIL: llistxattr(%s, %p, %zu): errno=%u, %s." , errno , strerror (errno ));
132
- free (xattr_buf );
133
- }
129
+ if (xattr_count < 0 ) {
130
+ dD ("FAIL: llistxattr(%s, %p, %zu): errno=%u, %s." , errno , strerror (errno ));
131
+ free (xattr_buf );
132
+ }
134
133
135
- /* update lastpath if needed */
134
+ /* update lastpath if needed */
136
135
if (!SEXP_emptyp (gr_lastpath )) {
137
136
if (SEXP_strcmp (gr_lastpath , p ) != 0 ) {
138
137
SEXP_free_r (gr_lastpath );
@@ -142,69 +141,69 @@ static int file_cb(const char *prefix, const char *p, const char *f, void *ptr,
142
141
SEXP_string_new_r (gr_lastpath , p , strlen (p ));
143
142
}
144
143
145
- i = 0 ;
146
- /* collect */
147
- do {
148
- SEXP_string_new_r (& xattr_name , xattr_buf + i , strlen (xattr_buf + i ));
144
+ i = 0 ;
145
+ /* collect */
146
+ do {
147
+ SEXP_string_new_r (& xattr_name , xattr_buf + i , strlen (xattr_buf + i ));
149
148
150
- if (probe_entobj_cmp (args -> attr_ent , & xattr_name ) == OVAL_RESULT_TRUE ) {
151
- ssize_t xattr_vallen = -1 ;
152
- char * xattr_val = NULL ;
149
+ if (probe_entobj_cmp (args -> attr_ent , & xattr_name ) == OVAL_RESULT_TRUE ) {
150
+ ssize_t xattr_vallen = -1 ;
151
+ char * xattr_val = NULL ;
153
152
154
- xattr_vallen = lgetxattr (st_path_with_prefix , xattr_buf + i , NULL , 0 );
155
- retry_value :
156
- if (xattr_vallen >= 0 ) {
153
+ xattr_vallen = lgetxattr (st_path_with_prefix , xattr_buf + i , NULL , 0 );
154
+ retry_value :
155
+ if (xattr_vallen >= 0 ) {
157
156
// Check possible buffer overflow
158
157
if (sizeof (char ) * (xattr_vallen + 1 ) <= sizeof (char ) * xattr_vallen ) {
159
158
dE ("Attribute is too long." );
160
159
abort ();
161
160
}
162
161
163
162
// Allocate buffer, '+1' is for trailing '\0'
164
- xattr_val = realloc (xattr_val , sizeof (char ) * (xattr_vallen + 1 ));
163
+ xattr_val = realloc (xattr_val , sizeof (char ) * (xattr_vallen + 1 ));
165
164
166
165
// we don't want to override space for '\0' by call of 'lgetxattr'
167
166
// we pass only 'xattr_vallen' instead of 'xattr_vallen + 1'
168
- xattr_vallen = lgetxattr (st_path_with_prefix , xattr_buf + i , xattr_val , xattr_vallen );
167
+ xattr_vallen = lgetxattr (st_path_with_prefix , xattr_buf + i , xattr_val , xattr_vallen );
169
168
170
- if (xattr_vallen < 0 || errno == ERANGE )
171
- goto retry_value ;
169
+ if (xattr_vallen < 0 || errno == ERANGE )
170
+ goto retry_value ;
172
171
173
172
xattr_val [xattr_vallen ] = '\0' ;
174
173
175
- item = probe_item_create (OVAL_UNIX_FILEEXTENDEDATTRIBUTE , NULL ,
176
- "filepath" , OVAL_DATATYPE_STRING , f == NULL ? NULL : st_path ,
177
- "path" , OVAL_DATATYPE_SEXP , gr_lastpath ,
178
- "filename" , OVAL_DATATYPE_STRING , f == NULL ? "" : f ,
179
- "attribute_name" , OVAL_DATATYPE_SEXP , & xattr_name ,
180
- "value" , OVAL_DATATYPE_STRING , xattr_val ,
181
- NULL );
174
+ item = probe_item_create (OVAL_UNIX_FILEEXTENDEDATTRIBUTE , NULL ,
175
+ "filepath" , OVAL_DATATYPE_STRING , f == NULL ? NULL : st_path ,
176
+ "path" , OVAL_DATATYPE_SEXP , gr_lastpath ,
177
+ "filename" , OVAL_DATATYPE_STRING , f == NULL ? "" : f ,
178
+ "attribute_name" , OVAL_DATATYPE_SEXP , & xattr_name ,
179
+ "value" , OVAL_DATATYPE_STRING , xattr_val ,
180
+ NULL );
182
181
183
- free (xattr_val );
184
- } else {
185
- dD ("FAIL: lgetxattr(%s, %s, NULL, 0): errno=%u, %s." , errno , strerror (errno ));
182
+ free (xattr_val );
183
+ } else {
184
+ dD ("FAIL: lgetxattr(%s, %s, NULL, 0): errno=%u, %s." , errno , strerror (errno ));
186
185
187
- item = probe_item_create (OVAL_UNIX_FILEEXTENDEDATTRIBUTE , NULL , NULL );
188
- probe_item_setstatus (item , SYSCHAR_STATUS_ERROR );
186
+ item = probe_item_create (OVAL_UNIX_FILEEXTENDEDATTRIBUTE , NULL , NULL );
187
+ probe_item_setstatus (item , SYSCHAR_STATUS_ERROR );
189
188
190
- if (xattr_val != NULL )
191
- free (xattr_val );
192
- }
189
+ if (xattr_val != NULL )
190
+ free (xattr_val );
191
+ }
193
192
194
- probe_item_collect (args -> ctx , item ); /* XXX: handle ENOMEM */
195
- }
193
+ probe_item_collect (args -> ctx , item ); /* XXX: handle ENOMEM */
194
+ }
196
195
197
- SEXP_free_r (& xattr_name );
196
+ SEXP_free_r (& xattr_name );
198
197
199
- /* skip to next name */
200
- while (i < xattr_buflen && xattr_buf [i ] != '\0' )
201
- ++ i ;
198
+ /* skip to next name */
199
+ while (i < xattr_buflen && xattr_buf [i ] != '\0' )
200
+ ++ i ;
202
201
++ i ;
203
- } while (xattr_buf + i < xattr_buf + xattr_buflen - 1 );
202
+ } while (xattr_buf + i < xattr_buf + xattr_buflen - 1 );
204
203
205
- free (xattr_buf );
204
+ free (xattr_buf );
206
205
free (st_path_with_prefix );
207
- return ( 0 ) ;
206
+ return 0 ;
208
207
}
209
208
210
209
int fileextendedattribute_probe_offline_mode_supported ()
@@ -214,86 +213,82 @@ int fileextendedattribute_probe_offline_mode_supported()
214
213
215
214
void * fileextendedattribute_probe_init (void )
216
215
{
217
- /*
218
- * Initialize mutex.
219
- */
216
+ /*
217
+ * Initialize mutex.
218
+ */
220
219
pthread_mutex_t * mutex = malloc (sizeof (pthread_mutex_t ));
221
- switch (pthread_mutex_init (mutex , NULL )) {
222
- case 0 :
223
- return (( void * )mutex ) ;
224
- default :
225
- dD ("Can't initialize mutex: errno=%u, %s." , errno , strerror (errno ));
226
- }
220
+ switch (pthread_mutex_init (mutex , NULL )) {
221
+ case 0 :
222
+ return (void * )mutex ;
223
+ default :
224
+ dD ("Can't initialize mutex: errno=%u, %s." , errno , strerror (errno ));
225
+ }
227
226
#if 0
228
227
probe_setoption (PROBEOPT_VARREF_HANDLING , false, "path" );
229
228
probe_setoption (PROBEOPT_VARREF_HANDLING , false, "filename" );
230
229
#endif
231
- return ( NULL ) ;
230
+ return NULL ;
232
231
}
233
232
234
233
void fileextendedattribute_probe_fini (void * arg )
235
234
{
236
- /*
237
- * Destroy mutex.
238
- */
235
+ /*
236
+ * Destroy mutex.
237
+ */
239
238
(void ) pthread_mutex_destroy ((pthread_mutex_t * )arg );
240
239
free (arg );
241
240
}
242
241
243
242
int fileextendedattribute_probe_main (probe_ctx * ctx , void * mutex )
244
243
{
245
- SEXP_t * path , * filename , * behaviors ;
246
- SEXP_t * filepath , * attribute_ , * probe_in ;
244
+ SEXP_t * path , * filename , * behaviors ;
245
+ SEXP_t * filepath , * attribute_ , * probe_in ;
247
246
int err ;
248
- struct cbargs cbargs ;
247
+ struct cbargs cbargs ;
249
248
OVAL_FTS * ofts ;
250
249
OVAL_FTSENT * ofts_ent ;
251
250
SEXP_t gr_lastpath ;
252
251
253
- if (mutex == NULL )
254
- return PROBE_EINIT ;
252
+ if (mutex == NULL )
253
+ return PROBE_EINIT ;
255
254
256
- probe_in = probe_ctx_getobject (ctx );
255
+ probe_in = probe_ctx_getobject (ctx );
257
256
258
- path = probe_obj_getent (probe_in , "path" , 1 );
259
- filename = probe_obj_getent (probe_in , "filename" , 1 );
260
- behaviors = probe_obj_getent (probe_in , "behaviors" , 1 );
261
- filepath = probe_obj_getent (probe_in , "filepath" , 1 );
262
- attribute_ = probe_obj_getent (probe_in , "attribute_name" , 1 );
257
+ path = probe_obj_getent (probe_in , "path" , 1 );
258
+ filename = probe_obj_getent (probe_in , "filename" , 1 );
259
+ behaviors = probe_obj_getent (probe_in , "behaviors" , 1 );
260
+ filepath = probe_obj_getent (probe_in , "filepath" , 1 );
261
+ attribute_ = probe_obj_getent (probe_in , "attribute_name" , 1 );
263
262
264
263
/* we want either path+filename or filepath */
265
- if (((path == NULL || filename == NULL ) && filepath == NULL )
266
- || attribute_ == NULL )
267
- {
268
- SEXP_free (behaviors );
269
- SEXP_free (path );
270
- SEXP_free (filename );
271
- SEXP_free (filepath );
272
- SEXP_free (attribute_ );
273
-
274
- return PROBE_ENOELM ;
275
- }
264
+ if (((path == NULL || filename == NULL ) && filepath == NULL ) || attribute_ == NULL )
265
+ {
266
+ SEXP_free (behaviors );
267
+ SEXP_free (path );
268
+ SEXP_free (filename );
269
+ SEXP_free (filepath );
270
+ SEXP_free (attribute_ );
271
+ return PROBE_ENOELM ;
272
+ }
276
273
277
274
probe_filebehaviors_canonicalize (& behaviors );
278
275
279
276
switch (pthread_mutex_lock (mutex )) {
280
- case 0 :
281
- break ;
282
- default :
277
+ case 0 :
278
+ break ;
279
+ default :
283
280
dD ("Can't lock mutex(%p): %u, %s." , mutex , errno , strerror (errno ));
284
-
285
281
SEXP_free (path );
286
282
SEXP_free (filename );
287
283
SEXP_free (filepath );
288
284
SEXP_free (behaviors );
289
- SEXP_free (attribute_ );
290
-
291
- return PROBE_EFATAL ;
292
- }
285
+ SEXP_free (attribute_ );
286
+ return PROBE_EFATAL ;
287
+ }
293
288
294
- cbargs .ctx = ctx ;
289
+ cbargs .ctx = ctx ;
295
290
cbargs .error = 0 ;
296
- cbargs .attr_ent = attribute_ ;
291
+ cbargs .attr_ent = attribute_ ;
297
292
298
293
const char * prefix = getenv ("OSCAP_PROBE_ROOT" );
299
294
SEXP_init (& gr_lastpath );
@@ -305,6 +300,7 @@ int fileextendedattribute_probe_main(probe_ctx *ctx, void *mutex)
305
300
}
306
301
oval_fts_close (ofts );
307
302
}
303
+
308
304
if (!SEXP_emptyp (& gr_lastpath ))
309
305
SEXP_free_r (& gr_lastpath );
310
306
@@ -314,16 +310,15 @@ int fileextendedattribute_probe_main(probe_ctx *ctx, void *mutex)
314
310
SEXP_free (filename );
315
311
SEXP_free (filepath );
316
312
SEXP_free (behaviors );
317
- SEXP_free (attribute_ );
313
+ SEXP_free (attribute_ );
318
314
319
315
switch (pthread_mutex_unlock (mutex )) {
320
- case 0 :
321
- break ;
322
- default :
316
+ case 0 :
317
+ break ;
318
+ default :
323
319
dD ("Can't unlock mutex(%p): %u, %s." , mutex , errno , strerror (errno ));
320
+ return PROBE_EFATAL ;
321
+ }
324
322
325
- return PROBE_EFATAL ;
326
- }
327
-
328
- return err ;
323
+ return err ;
329
324
}
0 commit comments