Avoid implicit brackets.

This commit is contained in:
nekral-guest 2007-12-27 23:40:00 +00:00
parent 6bc43fea06
commit 7f5a4e15c6
2 changed files with 44 additions and 23 deletions

View File

@ -9,6 +9,7 @@
end. end.
* libmisc/copydir.c: Avoid assignment in comparisons. * libmisc/copydir.c: Avoid assignment in comparisons.
* libmisc/copydir.c: Document selinux_file_context. * libmisc/copydir.c: Document selinux_file_context.
* libmisc/copydir.c: Avoid implicit brackets.
2007-12-27 Nicolas François <nicolas.francois@centraliens.net> 2007-12-27 Nicolas François <nicolas.francois@centraliens.net>

View File

@ -86,15 +86,22 @@ static int selinux_file_context (const char *dst_name)
{ {
security_context_t scontext = NULL; security_context_t scontext = NULL;
if (selinux_enabled < 0) if (selinux_enabled < 0) {
selinux_enabled = is_selinux_enabled () > 0; selinux_enabled = is_selinux_enabled () > 0;
}
if (selinux_enabled) { if (selinux_enabled) {
if (matchpathcon (dst_name, 0, &scontext) < 0) /* Get the default security context for this file */
if (security_getenforce ()) if (matchpathcon (dst_name, 0, &scontext) < 0) {
if (security_getenforce ()) {
return 1; 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; return 1;
}
}
freecon (scontext); freecon (scontext);
} }
return 0; return 0;
@ -114,12 +121,15 @@ static void remove_link (struct link_name *ln)
free (ln); free (ln);
return; return;
} }
for (lp = links; lp; lp = lp->ln_next) for (lp = links; lp; lp = lp->ln_next) {
if (lp->ln_next == ln) if (lp->ln_next == ln) {
break; break;
}
}
if (!lp) if (!lp) {
return; return;
}
lp->ln_next = lp->ln_next->ln_next; lp->ln_next = lp->ln_next->ln_next;
free (ln->ln_name); free (ln->ln_name);
@ -138,12 +148,15 @@ static struct link_name *check_link (const char *name, const struct stat *sb)
int name_len; int name_len;
int len; int len;
for (lp = links; lp; lp = lp->ln_next) for (lp = links; lp; lp = lp->ln_next) {
if (lp->ln_dev == sb->st_dev && lp->ln_ino == sb->st_ino) if (lp->ln_dev == sb->st_dev && lp->ln_ino == sb->st_ino) {
return lp; return lp;
}
}
if (sb->st_nlink == 1) if (sb->st_nlink == 1) {
return 0; return 0;
}
lp = (struct link_name *) xmalloc (sizeof *lp); lp = (struct link_name *) xmalloc (sizeof *lp);
src_len = strlen (src_orig); src_len = strlen (src_orig);
@ -167,7 +180,6 @@ static struct link_name *check_link (const char *name, const struct stat *sb)
* copy_tree() walks a directory tree and copies ordinary files * copy_tree() walks a directory tree and copies ordinary files
* as it goes. * as it goes.
*/ */
int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid) int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid)
{ {
char src_name[1024]; char src_name[1024];
@ -183,8 +195,9 @@ int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid)
* target is created. It assumes the target directory exists. * 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; return -1;
}
/* /*
* Open the source directory and read each entry. Every file * Open the source directory and read each entry. Every file
@ -194,8 +207,9 @@ int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid)
* is made set-ID. * is made set-ID.
*/ */
dir = opendir (src_root); dir = opendir (src_root);
if (NULL == dir) if (NULL == dir) {
return -1; return -1;
}
if (src_orig == 0) { if (src_orig == 0) {
src_orig = src_root; src_orig = src_root;
@ -209,8 +223,9 @@ int copy_tree (const char *src_root, const char *dst_root, uid_t uid, gid_t gid)
*/ */
if (strcmp (ent->d_name, ".") == 0 || if (strcmp (ent->d_name, ".") == 0 ||
strcmp (ent->d_name, "..") == 0) strcmp (ent->d_name, "..") == 0) {
continue; continue;
}
/* /*
* Make the filename for both the source and the * Make the filename for both the source and the
@ -357,9 +372,8 @@ static int copy_symlink (const char *src, const char *dst,
* destination directory name. * destination directory name.
*/ */
if ((len = len = readlink (src, oldlink, sizeof (oldlink) - 1);
readlink (src, oldlink, if (len < 0) {
sizeof (oldlink) - 1)) < 0) {
return -1; return -1;
} }
oldlink[len] = '\0'; /* readlink() does not NUL-terminate */ oldlink[len] = '\0'; /* readlink() does not NUL-terminate */
@ -401,8 +415,9 @@ static int copy_hardlink (const char *src, const char *dst,
if (unlink (src)) { if (unlink (src)) {
return -1; return -1;
} }
if (--lp->ln_count <= 0) if (--lp->ln_count <= 0) {
remove_link (lp); remove_link (lp);
}
return 0; return 0;
} }
@ -494,8 +509,9 @@ int remove_tree (const char *root)
* Make certain the directory exists. * Make certain the directory exists.
*/ */
if (access (root, F_OK) != 0) if (access (root, F_OK) != 0) {
return -1; return -1;
}
/* /*
* Open the source directory and read each entry. Every file * Open the source directory and read each entry. Every file
@ -505,8 +521,9 @@ int remove_tree (const char *root)
* is made set-ID. * is made set-ID.
*/ */
dir = opendir (root); dir = opendir (root);
if (NULL == dir) if (NULL == dir) {
return -1; return -1;
}
while ((ent = readdir (dir))) { while ((ent = readdir (dir))) {
@ -515,8 +532,9 @@ int remove_tree (const char *root)
*/ */
if (strcmp (ent->d_name, ".") == 0 || if (strcmp (ent->d_name, ".") == 0 ||
strcmp (ent->d_name, "..") == 0) strcmp (ent->d_name, "..") == 0) {
continue; continue;
}
/* /*
* Make the filename for the current entry. * Make the filename for the current entry.
@ -528,8 +546,9 @@ int remove_tree (const char *root)
} }
snprintf (new_name, sizeof new_name, "%s/%s", root, snprintf (new_name, sizeof new_name, "%s/%s", root,
ent->d_name); ent->d_name);
if (LSTAT (new_name, &sb) == -1) if (LSTAT (new_name, &sb) == -1) {
continue; continue;
}
if (S_ISDIR (sb.st_mode)) { if (S_ISDIR (sb.st_mode)) {
@ -553,3 +572,4 @@ int remove_tree (const char *root)
return err; return err;
} }