{
security_context_t scontext = NULL;
- if (selinux_enabled < 0)
+ if (selinux_enabled < 0) {
selinux_enabled = is_selinux_enabled () > 0;
+ }
if (selinux_enabled) {
- if (matchpathcon (dst_name, 0, &scontext) < 0)
- if (security_getenforce ())
+ /* Get the default security context for this file */
+ if (matchpathcon (dst_name, 0, &scontext) < 0) {
+ if (security_getenforce ()) {
return 1;
- if (setfscreatecon (scontext) < 0)
- if (security_getenforce ())
+ }
+ }
+ /* Set the security context for the next created file */
+ if (setfscreatecon (scontext) < 0) {
+ if (security_getenforce ()) {
return 1;
+ }
+ }
freecon (scontext);
}
return 0;
free (ln);
return;
}
- for (lp = links; lp; lp = lp->ln_next)
- if (lp->ln_next == ln)
+ for (lp = links; lp; lp = lp->ln_next) {
+ if (lp->ln_next == ln) {
break;
+ }
+ }
- if (!lp)
+ if (!lp) {
return;
+ }
lp->ln_next = lp->ln_next->ln_next;
free (ln->ln_name);
int name_len;
int len;
- for (lp = links; lp; lp = lp->ln_next)
- if (lp->ln_dev == sb->st_dev && lp->ln_ino == sb->st_ino)
+ for (lp = links; lp; lp = lp->ln_next) {
+ if (lp->ln_dev == sb->st_dev && lp->ln_ino == sb->st_ino) {
return lp;
+ }
+ }
- if (sb->st_nlink == 1)
+ if (sb->st_nlink == 1) {
return 0;
+ }
lp = (struct link_name *) xmalloc (sizeof *lp);
src_len = strlen (src_orig);
* copy_tree() walks a directory tree and copies ordinary files
* as it goes.
*/
-
int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid)
{
char src_name[1024];
* target is created. It assumes the target directory exists.
*/
- if (access (src_root, F_OK) != 0 || access (dst_root, F_OK) != 0)
+ if (access (src_root, F_OK) != 0 || access (dst_root, F_OK) != 0) {
return -1;
+ }
/*
* Open the source directory and read each entry. Every file
* is made set-ID.
*/
dir = opendir (src_root);
- if (NULL == dir)
+ if (NULL == dir) {
return -1;
+ }
if (src_orig == 0) {
src_orig = src_root;
*/
if (strcmp (ent->d_name, ".") == 0 ||
- strcmp (ent->d_name, "..") == 0)
+ strcmp (ent->d_name, "..") == 0) {
continue;
+ }
/*
* Make the filename for both the source and the
* destination directory name.
*/
- if ((len =
- readlink (src, oldlink,
- sizeof (oldlink) - 1)) < 0) {
+ len = readlink (src, oldlink, sizeof (oldlink) - 1);
+ if (len < 0) {
return -1;
}
oldlink[len] = '\0'; /* readlink() does not NUL-terminate */
if (unlink (src)) {
return -1;
}
- if (--lp->ln_count <= 0)
+ if (--lp->ln_count <= 0) {
remove_link (lp);
+ }
return 0;
}
* Make certain the directory exists.
*/
- if (access (root, F_OK) != 0)
+ if (access (root, F_OK) != 0) {
return -1;
+ }
/*
* Open the source directory and read each entry. Every file
* is made set-ID.
*/
dir = opendir (root);
- if (NULL == dir)
+ if (NULL == dir) {
return -1;
+ }
while ((ent = readdir (dir))) {
*/
if (strcmp (ent->d_name, ".") == 0 ||
- strcmp (ent->d_name, "..") == 0)
+ strcmp (ent->d_name, "..") == 0) {
continue;
+ }
/*
* Make the filename for the current entry.
}
snprintf (new_name, sizeof new_name, "%s/%s", root,
ent->d_name);
- if (LSTAT (new_name, &sb) == -1)
+ if (LSTAT (new_name, &sb) == -1) {
continue;
+ }
if (S_ISDIR (sb.st_mode)) {
return err;
}
+