From: nekral-guest Date: Thu, 18 Mar 2010 18:52:53 +0000 (+0000) Subject: * libmisc/chowndir.c: Re-indent. X-Git-Tag: 4.1.5~306 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=86498400da5c07e6c95cc42a3fc776504a8abe5e;p=shadow * libmisc/chowndir.c: Re-indent. * libmisc/chowndir.c: Avoid assignment in comparisons. * libmisc/chowndir.c: Added brackets and parenthesis. --- diff --git a/ChangeLog b/ChangeLog index 0d46810a..e20922cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-03-18 Nicolas François + + * libmisc/chowndir.c: Re-indent. + * libmisc/chowndir.c: Avoid assignment in comparisons. + * libmisc/chowndir.c: Added brackets and parenthesis. + 2010-03-18 Nicolas François * libmisc/strtoday.c: Add support for numerical dates, assuming diff --git a/libmisc/chowndir.c b/libmisc/chowndir.c index d0204023..b1239613 100644 --- a/libmisc/chowndir.c +++ b/libmisc/chowndir.c @@ -2,6 +2,7 @@ * Copyright (c) 1992 - 1993, Julianne Frances Haugh * Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 2003 - 2005, Tomasz Kłoczko + * Copyright (c) 2010 - , Nicolas François * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,8 +47,11 @@ * of all files owned by the provided user ID. */ int -chown_tree (const char *root, uid_t old_uid, uid_t new_uid, gid_t old_gid, - gid_t new_gid) +chown_tree (const char *root, + uid_t old_uid, + uid_t new_uid, + gid_t old_gid, + gid_t new_gid) { char new_name[1024]; int rc = 0; @@ -60,8 +64,9 @@ chown_tree (const char *root, uid_t old_uid, uid_t new_uid, gid_t old_gid, * directory by the invoker, or recursively. */ - if (access (root, F_OK) != 0) + if (access (root, F_OK) != 0) { return -1; + } /* * Open the directory and read each entry. Every entry is tested @@ -70,8 +75,10 @@ chown_tree (const char *root, uid_t old_uid, uid_t new_uid, gid_t old_gid, * old user ID. */ - if (!(dir = opendir (root))) + dir = opendir (root); + if (NULL == dir) { return -1; + } while ((ent = readdir (dir))) { @@ -79,24 +86,27 @@ chown_tree (const char *root, uid_t old_uid, uid_t new_uid, gid_t old_gid, * Skip the "." and ".." entries */ - if (strcmp (ent->d_name, ".") == 0 || - strcmp (ent->d_name, "..") == 0) + if ( (strcmp (ent->d_name, ".") == 0) + || (strcmp (ent->d_name, "..") == 0)) { continue; + } /* * Make the filename for both the source and the * destination files. */ - if (strlen (root) + strlen (ent->d_name) + 2 > sizeof new_name) + if (strlen (root) + strlen (ent->d_name) + 2 > sizeof new_name) { break; + } snprintf (new_name, sizeof new_name, "%s/%s", root, - ent->d_name); + ent->d_name); /* Don't follow symbolic links! */ - if (LSTAT (new_name, &sb) == -1) + if (LSTAT (new_name, &sb) == -1) { continue; + } if (S_ISDIR (sb.st_mode) && !S_ISLNK (sb.st_mode)) { @@ -112,12 +122,14 @@ chown_tree (const char *root, uid_t old_uid, uid_t new_uid, gid_t old_gid, } #ifndef HAVE_LCHOWN /* don't use chown (follows symbolic links!) */ - if (S_ISLNK (sb.st_mode)) + if (S_ISLNK (sb.st_mode)) { continue; + } #endif - if (sb.st_uid == old_uid) + if (sb.st_uid == old_uid) { LCHOWN (new_name, new_uid, - sb.st_gid == old_gid ? new_gid : sb.st_gid); + (sb.st_gid == old_gid) ? new_gid : sb.st_gid); + } } (void) closedir (dir);