X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=tests%2Ftest-sameacls.c;h=20b0a4742de50875e80e502b6eb6bd60a7f3ce91;hb=f6fe750d033c40b403688dc3eee9dbff468aa8f3;hp=55c6f445fc778ad8d859c210b7d6cc8f14547619;hpb=025733d35d2371eca95b865e46f57d892c11ce9d;p=gnulib.git diff --git a/tests/test-sameacls.c b/tests/test-sameacls.c index 55c6f445f..20b0a4742 100644 --- a/tests/test-sameacls.c +++ b/tests/test-sameacls.c @@ -29,6 +29,7 @@ # include #endif +#include "progname.h" #include "read-file.h" #include "xalloc.h" @@ -50,6 +51,8 @@ main (int argc, char *argv[]) const char *file1; const char *file2; + set_program_name (argv[0]); + ASSERT (argc == 3); file1 = argv[1]; @@ -120,97 +123,110 @@ main (int argc, char *argv[]) } { #if HAVE_ACL_GET_FILE /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */ - acl_t acl1; - char *text1; - int errno1; - acl_t acl2; - char *text2; - int errno2; - - acl1 = acl_get_file (file1, ACL_TYPE_ACCESS); - if (acl1 == (acl_t)NULL) + static const int types[] = { - text1 = NULL; - errno1 = errno; - } - else + ACL_TYPE_ACCESS +# if HAVE_ACL_TYPE_EXTENDED /* MacOS X */ + , ACL_TYPE_EXTENDED +# endif + }; + int t; + + for (t = 0; t < sizeof (types) / sizeof (types[0]); t++) { - text1 = acl_to_text (acl1, NULL); - if (text1 == NULL) - errno1 = errno; + int type = types[t]; + acl_t acl1; + char *text1; + int errno1; + acl_t acl2; + char *text2; + int errno2; + + acl1 = acl_get_file (file1, type); + if (acl1 == (acl_t)NULL) + { + text1 = NULL; + errno1 = errno; + } else - errno1 = 0; - } - acl2 = acl_get_file (file2, ACL_TYPE_ACCESS); - if (acl2 == (acl_t)NULL) - { - text2 = NULL; - errno2 = errno; - } - else - { - text2 = acl_to_text (acl2, NULL); - if (text2 == NULL) - errno2 = errno; + { + text1 = acl_to_text (acl1, NULL); + if (text1 == NULL) + errno1 = errno; + else + errno1 = 0; + } + acl2 = acl_get_file (file2, type); + if (acl2 == (acl_t)NULL) + { + text2 = NULL; + errno2 = errno; + } else - errno2 = 0; - } + { + text2 = acl_to_text (acl2, NULL); + if (text2 == NULL) + errno2 = errno; + else + errno2 = 0; + } - if (acl1 != (acl_t)NULL) - { - if (acl2 != (acl_t)NULL) + if (acl1 != (acl_t)NULL) { - if (text1 != NULL) + if (acl2 != (acl_t)NULL) { - if (text2 != NULL) + if (text1 != NULL) { - if (strcmp (text1, text2) != 0) + if (text2 != NULL) + { + if (strcmp (text1, text2) != 0) + { + fprintf (stderr, "files %s and %s have different ACLs:\n%s\n%s\n", + file1, file2, text1, text2); + return 1; + } + } + else { - fprintf (stderr, "files %s and %s have different ACLs:\n%s\n%s\n", - file1, file2, text1, text2); + fprintf (stderr, "file %s has a valid ACL, but file %s has an invalid ACL\n", + file1, file2); return 1; } } else { - fprintf (stderr, "file %s has a valid ACL, but file %s has an invalid ACL\n", - file1, file2); - return 1; - } - } - else - { - if (text2 != NULL) - { - fprintf (stderr, "file %s has an invalid ACL, but file %s has a valid ACL\n", - file1, file2); - return 1; - } - else - { - if (errno1 != errno2) + if (text2 != NULL) { - fprintf (stderr, "files %s and %s have differently invalid ACLs, errno = %d vs. %d\n", - file1, file2, errno1, errno2); + fprintf (stderr, "file %s has an invalid ACL, but file %s has a valid ACL\n", + file1, file2); return 1; } + else + { + if (errno1 != errno2) + { + fprintf (stderr, "files %s and %s have differently invalid ACLs, errno = %d vs. %d\n", + file1, file2, errno1, errno2); + return 1; + } + } } } + else + { + fprintf (stderr, "file %s has an ACL, but file %s has no ACL\n", + file1, file2); + return 1; + } } else { - fprintf (stderr, "file %s has an ACL, but file %s has no ACL\n", - file1, file2); - return 1; - } - } - else - { - if (acl2 != (acl_t)NULL) - { - fprintf (stderr, "file %s has no ACL, but file %s has an ACL\n", - file1, file2); - return 1; + if (acl2 != (acl_t)NULL) + { + fprintf (stderr, "file %s has no ACL, but file %s has an ACL\n", + file1, file2); + return 1; + } } } #elif HAVE_ACL && defined GETACL /* Solaris, Cygwin, not HP-UX */ @@ -220,20 +236,20 @@ main (int argc, char *argv[]) count1 = acl (file1, GETACLCNT, 0, NULL); count2 = acl (file2, GETACLCNT, 0, NULL); + if (count1 < 0) + { + fprintf (stderr, "error accessing the ACLs of file %s\n", file1); + fflush (stderr); + abort (); + } + if (count2 < 0) + { + fprintf (stderr, "error accessing the ACLs of file %s\n", file2); + fflush (stderr); + abort (); + } if (count1 != count2) { - if (count1 < 0) - { - fprintf (stderr, "error accessing the ACLs of file %s\n", file1); - fflush (stderr); - abort (); - } - if (count2 < 0) - { - fprintf (stderr, "error accessing the ACLs of file %s\n", file2); - fflush (stderr); - abort (); - } fprintf (stderr, "files %s and %s have different number of ACLs: %d and %d\n", file1, file2, count1, count2); return 1; @@ -280,21 +296,25 @@ main (int argc, char *argv[]) } # ifdef ACE_GETACL count1 = acl (file1, ACE_GETACLCNT, 0, NULL); + if (count1 < 0 && errno == EINVAL) + count1 = 0; count2 = acl (file2, ACE_GETACLCNT, 0, NULL); + if (count2 < 0 && errno == EINVAL) + count2 = 0; + if (count1 < 0) + { + fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file1); + fflush (stderr); + abort (); + } + if (count2 < 0) + { + fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file2); + fflush (stderr); + abort (); + } if (count1 != count2) { - if (count1 < 0) - { - fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file1); - fflush (stderr); - abort (); - } - if (count2 < 0) - { - fprintf (stderr, "error accessing the ACE-ACLs of file %s\n", file2); - fflush (stderr); - abort (); - } fprintf (stderr, "files %s and %s have different number of ACE-ACLs: %d and %d\n", file1, file2, count1, count2); return 1; @@ -351,27 +371,31 @@ main (int argc, char *argv[]) int count2; count1 = getacl (file1, 0, NULL); + if (count1 < 0 && (errno == ENOSYS || errno == EOPNOTSUPP)) + count1 = 0; count2 = getacl (file2, 0, NULL); + if (count2 < 0 && (errno == ENOSYS || errno == EOPNOTSUPP)) + count2 = 0; + if (count1 < 0) + { + fprintf (stderr, "error accessing the ACLs of file %s\n", file1); + fflush (stderr); + abort (); + } + if (count2 < 0) + { + fprintf (stderr, "error accessing the ACLs of file %s\n", file2); + fflush (stderr); + abort (); + } if (count1 != count2) { - if (count1 < 0) - { - fprintf (stderr, "error accessing the ACLs of file %s\n", file1); - fflush (stderr); - abort (); - } - if (count2 < 0) - { - fprintf (stderr, "error accessing the ACLs of file %s\n", file2); - fflush (stderr); - abort (); - } fprintf (stderr, "files %s and %s have different number of ACLs: %d and %d\n", file1, file2, count1, count2); return 1; } - else + else if (count1 > 0) { struct acl_entry *entries1 = XNMALLOC (count1, struct acl_entry); struct acl_entry *entries2 = XNMALLOC (count2, struct acl_entry); @@ -423,6 +447,7 @@ main (int argc, char *argv[]) mode_t mode2; char text2[1000]; + memset (&type1, 0, sizeof (type1)); /* type1 = ACL_ANY */ if (aclx_get (file1, 0, &type1, acl1, &aclsize1, &mode1) < 0) { fprintf (stderr, "error accessing the ACLs of file %s\n", file1); @@ -436,6 +461,7 @@ main (int argc, char *argv[]) abort (); } + memset (&type2, 0, sizeof (type2)); /* type2 = ACL_ANY */ if (aclx_get (file2, 0, &type2, acl2, &aclsize2, &mode2) < 0) { fprintf (stderr, "error accessing the ACLs of file %s\n", file2);