Use lchown() if it's available
authorewt <devnull@localhost>
Tue, 20 May 1997 15:28:25 +0000 (15:28 +0000)
committerewt <devnull@localhost>
Tue, 20 May 1997 15:28:25 +0000 (15:28 +0000)
CVS patchset: 1644
CVS date: 1997/05/20 15:28:25

config.h.in
configure.in
lib/cpio.c
misc/miscfn.h

index 9b5833a..03c3d56 100644 (file)
 /* Define as 1 if we need myrealloc */
 #define NEED_MYREALLOC 0
 
-/* Define as 1 if chown() or chgrp() follows symlinks */
+/* Define as 1 if chown() follows symlinks and you don't have lchown() */
 #define CHOWN_FOLLOWS_SYMLINK 0
 
 /* Define as 1 if you have <sys/select.h> */
 #define HAVE_SYS_SELECT_H 0
 
+/* Define as 1 if you have lchown() */
+#define HAVE_LCHOWN 0
+
 #endif
index be70f89..3b2b930 100644 (file)
@@ -265,33 +265,6 @@ if test $HAS_S_ISSOCK = yes; then
        AC_DEFINE(HAVE_S_ISSOCK)
 fi
 
-dnl Does chown() follow symlinks? This should be a good enough test.
-AC_MSG_CHECKING(whether chown() follows symlinks...)
-AC_ARG_ENABLE([broken-chown],
-[  --enable-broken-chown  this system's chown follows symbolic links], 
-       result=yes, result=no)
-if test $result = no; then
-    if test `id -u` = 0; then
-       rm -f foo bar
-       touch foo
-       ln -s foo bar
-       chown 10 bar
-       if test `ls -l foo | awk '{print $3}'` != "root"; then
-           result=yes
-       else
-           result=no
-       fi
-       rm -f foo bar
-    else
-       AC_MSG_CHECKING((cannot check by non-root user))
-       result=no
-    fi
-fi
-AC_MSG_RESULT($result)
-if test $result = yes; then
-       AC_DEFINE(CHOWN_FOLLOWS_SYMLINK)
-fi
-
 AC_MSG_CHECKING(if timezone is defined...)
 AC_TRY_LINK([#include <time.h>],printf("%ld", timezone),
       HAS_TIMEZONE=yes,HAS_TIMEZONE=no)
@@ -306,6 +279,38 @@ AC_CHECK_FUNC(realpath, AC_DEFINE(HAVE_REALPATH), MISCOBJS="$MISCOBJS realpath.o
 AC_CHECK_FUNC(strerror, [], MISCOBJS="$MISCOBJS strerror.o")
 AC_CHECK_FUNC(strtol, [], MISCOBJS="$MISCOBJS strtol.o")
 AC_CHECK_FUNC(strtoul, [], MISCOBJS="$MISCOBJS strtoul.o")
+LCHOWN=no
+AC_CHECK_FUNC(lchown, [LCHOWN=yes; AC_DEFINE(HAVE_LCHOWN)])
+
+if test "$LCHOWN" = no; then 
+    dnl Does chown() follow symlinks? This should be a good enough test.
+    AC_MSG_CHECKING(whether chown() follows symlinks...)
+    AC_ARG_ENABLE([broken-chown],
+    [  --enable-broken-chown  this system's chown follows symbolic links], 
+           result=yes, result=no)
+    if test $result = no; then
+       if test `id -u` = 0; then
+           rm -f foo bar
+           touch foo
+           ln -s foo bar
+           chown 10 bar
+           if test `ls -l foo | awk '{print $3}'` != "root"; then
+               result=yes
+           else
+               result=no
+           fi
+           rm -f foo bar
+       else
+           AC_MSG_CHECKING((cannot check by non-root user))
+           result=no
+       fi
+    fi
+
+    AC_MSG_RESULT($result)
+    if test $result = yes; then
+           AC_DEFINE(CHOWN_FOLLOWS_SYMLINK)
+    fi
+fi
 
 if test -n "$MISCOBJS"; then
        LIBMISC=-lmisc
index 906a65b..712e6e2 100644 (file)
@@ -207,7 +207,7 @@ static int setInfo(struct cpioHeader * hdr) {
            rc = CPIO_UTIME_FAILED;
     } else {
        #if ! CHOWN_FOLLOWS_SYMLINK
-           if (!getuid() && !rc && chown(hdr->path, hdr->uid, hdr->gid))
+           if (!getuid() && !rc && lchown(hdr->path, hdr->uid, hdr->gid))
                rc = CPIO_CHOWN_FAILED;
        #endif
     }
index 2597e06..32fb4a3 100644 (file)
@@ -58,4 +58,8 @@ extern void *myrealloc(void *, size_t);
 #include <sys/select.h>
 #endif
 
+#if ! HAVE_LCHOWN
+#define lchown chown
+#endif
+
 #endif