-/* $OpenBSD: utils.c,v 1.3 1997/01/26 22:04:45 kstailey Exp $ */
+/* $OpenBSD: utils.c,v 1.4 1997/02/24 20:43:27 millert Exp $ */
/* $NetBSD: utils.c,v 1.4 1995/08/02 07:17:02 jtc Exp $ */
/*-
#if 0
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
#else
-static char rcsid[] = "$OpenBSD: utils.c,v 1.3 1997/01/26 22:04:45 kstailey Exp $";
+static char rcsid[] = "$OpenBSD: utils.c,v 1.4 1997/02/24 20:43:27 millert Exp $";
#endif
#endif /* not lint */
warn("symlink: %s", link);
return (1);
}
- return (pflag ? setfile(NULL, 0) : 0);
+ return (pflag ? setfile(p->fts_statp, 0) : 0);
}
int
int fd;
{
static struct timeval tv[2];
- int rval;
+ int rval = 0;
- rval = 0;
- if (fs != NULL) {
- fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
-
- TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
- TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
- if (utimes(to.p_path, tv)) {
- warn("utimes: %s", to.p_path);
- rval = 1;
+ /* Only change the owner for symbolic links. */
+ if (S_ISLNK(fs->st_mode)) {
+ if (lchown(to.p_path, fs->st_uid, fs->st_gid)) {
+ if (errno != EPERM) {
+ warn("lchown: %s", to.p_path);
+ rval = 1;
+ }
}
+ return (rval);
+ }
+
+ fs->st_mode &= S_ISUID | S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO;
+
+ TIMESPEC_TO_TIMEVAL(&tv[0], &fs->st_atimespec);
+ TIMESPEC_TO_TIMEVAL(&tv[1], &fs->st_mtimespec);
+ if (utimes(to.p_path, tv)) {
+ warn("utimes: %s", to.p_path);
+ rval = 1;
}
/*
* Changing the ownership probably won't succeed, unless we're root
* chown. If chown fails, lose setuid/setgid bits.
*/
if (fd ? fchown(fd, fs->st_uid, fs->st_gid) :
- lchown(to.p_path, fs->st_uid, fs->st_gid)) {
+ chown(to.p_path, fs->st_uid, fs->st_gid)) {
if (errno != EPERM) {
- warn("lchown: %s", to.p_path);
+ warn("chown: %s", to.p_path);
rval = 1;
}
- if (fs == NULL)
- return (rval);
fs->st_mode &= ~(S_ISUID | S_ISGID);
}
if (fd ? fchmod(fd, fs->st_mode) : chmod(to.p_path, fs->st_mode)) {
- warn("chown: %s", to.p_path);
+ warn("chmod: %s", to.p_path);
rval = 1;
}