MCPcopy Create free account
hub / github.com/coreutils/coreutils / restorecon

Function restorecon

src/selinux.c:284–326  ·  view source on GitHub ↗

This function takes three parameters: SELABEL_HANDLE for selabel_lookup, or null to preserve. PATH of an existing file system object. A RECURSE boolean which if the file system object is a directory, will call restorecon_private on every file system object in the directory. Return false on failure. errno will be set appropriately. */

Source from the content-addressed store, hash-verified

282 Return false on failure. errno will be set appropriately.
283*/
284bool
285restorecon (struct selabel_handle *selabel_handle,
286 char const *path, bool recurse)
287{
288 char *newpath = NULL;
289
290 if (! IS_ABSOLUTE_FILE_NAME (path))
291 {
292 /* Generate absolute name as required by subsequent selabel_lookup.
293 When RECURSE, this also generates absolute names in the
294 fts entries, which may be quicker to process in any case. */
295 newpath = canonicalize_filename_mode (path, CAN_MISSING);
296 if (! newpath)
297 return false;
298 path = newpath;
299 }
300
301 if (! recurse)
302 {
303 bool ok = restorecon_private (selabel_handle, path) != -1;
304 int err = errno;
305 free (newpath);
306 errno = err;
307 return ok;
308 }
309
310 char const *ftspath[2] = { path, NULL };
311 FTS *fts = xfts_open ((char *const *) ftspath, FTS_PHYSICAL, NULL);
312
313 int err = 0;
314 for (FTSENT *ent; (ent = fts_read (fts)); )
315 if (restorecon_private (selabel_handle, fts->fts_path) < 0)
316 err = errno;
317
318 if (errno != 0)
319 err = errno;
320
321 if (fts_close (fts) != 0)
322 err = errno;
323
324 free (newpath);
325 return !err;
326}
327#endif

Callers 3

process_dirFunction · 0.70
set_file_security_ctxFunction · 0.70
process_dirFunction · 0.70

Calls 2

restorecon_privateFunction · 0.85
xfts_openFunction · 0.85

Tested by

no test coverage detected