openat: work around AIX 7.1 fstatat bug
[gnulib.git] / lib / file-has-acl.c
1 /* Test whether a file has a nontrivial access control list.
2
3    Copyright (C) 2002-2003, 2005-2011 Free Software Foundation, Inc.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18    Written by Paul Eggert, Andreas Grünbacher, and Bruno Haible.  */
19
20 #include <config.h>
21
22 #include "acl.h"
23
24 #include "acl-internal.h"
25
26
27 #if USE_ACL && HAVE_ACL_GET_FILE
28
29 # if HAVE_ACL_TYPE_EXTENDED /* MacOS X */
30
31 /* ACL is an ACL, from a file, stored as type ACL_TYPE_EXTENDED.
32    Return 1 if the given ACL is non-trivial.
33    Return 0 if it is trivial.  */
34 int
35 acl_extended_nontrivial (acl_t acl)
36 {
37   /* acl is non-trivial if it is non-empty.  */
38   return (acl_entries (acl) > 0);
39 }
40
41 # else /* Linux, FreeBSD, IRIX, Tru64 */
42
43 /* ACL is an ACL, from a file, stored as type ACL_TYPE_ACCESS.
44    Return 1 if the given ACL is non-trivial.
45    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.
46    Return -1 and set errno upon failure to determine it.  */
47 int
48 acl_access_nontrivial (acl_t acl)
49 {
50   /* acl is non-trivial if it has some entries other than for "user::",
51      "group::", and "other::".  Normally these three should be present
52      at least, allowing us to write
53         return (3 < acl_entries (acl));
54      but the following code is more robust.  */
55 #  if HAVE_ACL_FIRST_ENTRY /* Linux, FreeBSD */
56
57   acl_entry_t ace;
58   int got_one;
59
60   for (got_one = acl_get_entry (acl, ACL_FIRST_ENTRY, &ace);
61        got_one > 0;
62        got_one = acl_get_entry (acl, ACL_NEXT_ENTRY, &ace))
63     {
64       acl_tag_t tag;
65       if (acl_get_tag_type (ace, &tag) < 0)
66         return -1;
67       if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER))
68         return 1;
69     }
70   return got_one;
71
72 #  else /* IRIX, Tru64 */
73 #   if HAVE_ACL_TO_SHORT_TEXT /* IRIX */
74   /* Don't use acl_get_entry: it is undocumented.  */
75
76   int count = acl->acl_cnt;
77   int i;
78
79   for (i = 0; i < count; i++)
80     {
81       acl_entry_t ace = &acl->acl_entry[i];
82       acl_tag_t tag = ace->ae_tag;
83
84       if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ
85             || tag == ACL_OTHER_OBJ))
86         return 1;
87     }
88   return 0;
89
90 #   endif
91 #   if HAVE_ACL_FREE_TEXT /* Tru64 */
92   /* Don't use acl_get_entry: it takes only one argument and does not work.  */
93
94   int count = acl->acl_num;
95   acl_entry_t ace;
96
97   for (ace = acl->acl_first; count > 0; ace = ace->next, count--)
98     {
99       acl_tag_t tag;
100       acl_perm_t perm;
101
102       tag = ace->entry->acl_type;
103       if (!(tag == ACL_USER_OBJ || tag == ACL_GROUP_OBJ || tag == ACL_OTHER))
104         return 1;
105
106       perm = ace->entry->acl_perm;
107       /* On Tru64, perm can also contain non-standard bits such as
108          PERM_INSERT, PERM_DELETE, PERM_MODIFY, PERM_LOOKUP, ... */
109       if ((perm & ~(ACL_READ | ACL_WRITE | ACL_EXECUTE)) != 0)
110         return 1;
111     }
112   return 0;
113
114 #   endif
115 #  endif
116 }
117
118 # endif
119
120
121 #elif USE_ACL && HAVE_FACL && defined GETACL /* Solaris, Cygwin, not HP-UX */
122
123 # if !defined ACL_NO_TRIVIAL /* Solaris <= 10, Cygwin */
124
125 /* Test an ACL retrieved with GETACL.
126    Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
127    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
128 int
129 acl_nontrivial (int count, aclent_t *entries)
130 {
131   int i;
132
133   for (i = 0; i < count; i++)
134     {
135       aclent_t *ace = &entries[i];
136
137       /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat().
138          If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat().
139          We don't need to check ace->a_id in these cases.  */
140       if (!(ace->a_type == USER_OBJ
141             || ace->a_type == GROUP_OBJ
142             || ace->a_type == OTHER_OBJ
143             /* Note: Cygwin does not return a CLASS_OBJ ("mask:") entry
144                sometimes.  */
145             || ace->a_type == CLASS_OBJ))
146         return 1;
147     }
148   return 0;
149 }
150
151 #  ifdef ACE_GETACL
152
153 /* Test an ACL retrieved with ACE_GETACL.
154    Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
155    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
156 int
157 acl_ace_nontrivial (int count, ace_t *entries)
158 {
159   int i;
160
161   /* The flags in the ace_t structure changed in a binary incompatible way
162      when ACL_NO_TRIVIAL etc. were introduced in <sys/acl.h> version 1.15.
163      How to distinguish the two conventions at runtime?
164      In the old convention, usually three ACEs have a_flags = ACE_OWNER /
165      ACE_GROUP / ACE_OTHER, in the range 0x0100..0x0400.  In the new
166      convention, these values are not used.  */
167   int old_convention = 0;
168
169   for (i = 0; i < count; i++)
170     if (entries[i].a_flags & (ACE_OWNER | ACE_GROUP | ACE_OTHER))
171       {
172         old_convention = 1;
173         break;
174       }
175
176   if (old_convention)
177     /* Running on Solaris 10.  */
178     for (i = 0; i < count; i++)
179       {
180         ace_t *ace = &entries[i];
181
182         /* Note:
183            If ace->a_flags = ACE_OWNER, ace->a_who is the st_uid from stat().
184            If ace->a_flags = ACE_GROUP, ace->a_who is the st_gid from stat().
185            We don't need to check ace->a_who in these cases.  */
186         if (!(ace->a_type == ALLOW
187               && (ace->a_flags == ACE_OWNER
188                   || ace->a_flags == ACE_GROUP
189                   || ace->a_flags == ACE_OTHER)))
190           return 1;
191       }
192   else
193     /* Running on Solaris 10 (newer version) or Solaris 11.  */
194     for (i = 0; i < count; i++)
195       {
196         ace_t *ace = &entries[i];
197
198         if (!(ace->a_type == ACE_ACCESS_ALLOWED_ACE_TYPE
199               && (ace->a_flags == NEW_ACE_OWNER
200                   || ace->a_flags
201                      == (NEW_ACE_GROUP | NEW_ACE_IDENTIFIER_GROUP)
202                   || ace->a_flags == ACE_EVERYONE)
203               && (ace->a_access_mask
204                   & ~(NEW_ACE_READ_DATA | NEW_ACE_WRITE_DATA | NEW_ACE_EXECUTE))
205                  == 0))
206           return 1;
207       }
208
209   return 0;
210 }
211
212 #  endif
213
214 # endif
215
216 #elif USE_ACL && HAVE_GETACL /* HP-UX */
217
218 /* Return 1 if the given ACL is non-trivial.
219    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
220 int
221 acl_nontrivial (int count, struct acl_entry *entries, struct stat *sb)
222 {
223   int i;
224
225   for (i = 0; i < count; i++)
226     {
227       struct acl_entry *ace = &entries[i];
228
229       if (!((ace->uid == sb->st_uid && ace->gid == ACL_NSGROUP)
230             || (ace->uid == ACL_NSUSER && ace->gid == sb->st_gid)
231             || (ace->uid == ACL_NSUSER && ace->gid == ACL_NSGROUP)))
232         return 1;
233     }
234   return 0;
235 }
236
237 # if HAVE_ACLV_H /* HP-UX >= 11.11 */
238
239 /* Return 1 if the given ACL is non-trivial.
240    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
241 int
242 aclv_nontrivial (int count, struct acl *entries)
243 {
244   int i;
245
246   for (i = 0; i < count; i++)
247     {
248       struct acl *ace = &entries[i];
249
250       /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat().
251          If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat().
252          We don't need to check ace->a_id in these cases.  */
253       if (!(ace->a_type == USER_OBJ /* no need to check ace->a_id here */
254             || ace->a_type == GROUP_OBJ /* no need to check ace->a_id here */
255             || ace->a_type == CLASS_OBJ
256             || ace->a_type == OTHER_OBJ))
257         return 1;
258     }
259   return 0;
260 }
261
262 # endif
263
264 #elif USE_ACL && (HAVE_ACLX_GET || HAVE_STATACL) /* AIX */
265
266 /* Return 1 if the given ACL is non-trivial.
267    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
268 int
269 acl_nontrivial (struct acl *a)
270 {
271   /* The normal way to iterate through an ACL is like this:
272        struct acl_entry *ace;
273        for (ace = a->acl_ext; ace != acl_last (a); ace = acl_nxt (ace))
274          {
275            struct ace_id *aei;
276            switch (ace->ace_type)
277              {
278              case ACC_PERMIT:
279              case ACC_DENY:
280              case ACC_SPECIFY:
281                ...;
282              }
283            for (aei = ace->ace_id; aei != id_last (ace); aei = id_nxt (aei))
284              ...
285          }
286    */
287   return (acl_last (a) != a->acl_ext ? 1 : 0);
288 }
289
290 # if HAVE_ACLX_GET && defined ACL_AIX_WIP /* newer AIX */
291
292 /* Return 1 if the given ACL is non-trivial.
293    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
294 int
295 acl_nfs4_nontrivial (nfs4_acl_int_t *a)
296 {
297 #  if 1 /* let's try this first */
298   return (a->aclEntryN > 0 ? 1 : 0);
299 #  else
300   int count = a->aclEntryN;
301   int i;
302
303   for (i = 0; i < count; i++)
304     {
305       nfs4_ace_int_t *ace = &a->aclEntry[i];
306
307       if (!((ace->flags & ACE4_ID_SPECIAL) != 0
308             && (ace->aceWho.special_whoid == ACE4_WHO_OWNER
309                 || ace->aceWho.special_whoid == ACE4_WHO_GROUP
310                 || ace->aceWho.special_whoid == ACE4_WHO_EVERYONE)
311             && ace->aceType == ACE4_ACCESS_ALLOWED_ACE_TYPE
312             && ace->aceFlags == 0
313             && (ace->aceMask & ~(ACE4_READ_DATA | ACE4_LIST_DIRECTORY
314                                  | ACE4_WRITE_DATA | ACE4_ADD_FILE
315                                  | ACE4_EXECUTE)) == 0))
316         return 1;
317     }
318   return 0;
319 #  endif
320 }
321
322 # endif
323
324 #elif USE_ACL && HAVE_ACLSORT /* NonStop Kernel */
325
326 /* Test an ACL retrieved with ACL_GET.
327    Return 1 if the given ACL, consisting of COUNT entries, is non-trivial.
328    Return 0 if it is trivial, i.e. equivalent to a simple stat() mode.  */
329 int
330 acl_nontrivial (int count, struct acl *entries)
331 {
332   int i;
333
334   for (i = 0; i < count; i++)
335     {
336       struct acl *ace = &entries[i];
337
338       /* Note: If ace->a_type = USER_OBJ, ace->a_id is the st_uid from stat().
339          If ace->a_type = GROUP_OBJ, ace->a_id is the st_gid from stat().
340          We don't need to check ace->a_id in these cases.  */
341       if (!(ace->a_type == USER_OBJ /* no need to check ace->a_id here */
342             || ace->a_type == GROUP_OBJ /* no need to check ace->a_id here */
343             || ace->a_type == CLASS_OBJ
344             || ace->a_type == OTHER_OBJ))
345         return 1;
346     }
347   return 0;
348 }
349
350 #endif
351
352
353 /* Return 1 if NAME has a nontrivial access control list, 0 if NAME
354    only has no or a base access control list, and -1 (setting errno)
355    on error.  SB must be set to the stat buffer of FILE.  */
356
357 int
358 file_has_acl (char const *name, struct stat const *sb)
359 {
360 #if USE_ACL
361   if (! S_ISLNK (sb->st_mode))
362     {
363 # if HAVE_ACL_GET_FILE
364
365       /* POSIX 1003.1e (draft 17 -- abandoned) specific version.  */
366       /* Linux, FreeBSD, MacOS X, IRIX, Tru64 */
367       int ret;
368
369       if (HAVE_ACL_EXTENDED_FILE || HAVE_ACL_EXTENDED_FILE_NOFOLLOW) /* Linux */
370         {
371 #  if HAVE_ACL_EXTENDED_FILE_NOFOLLOW
372           /* acl_extended_file_nofollow() uses lgetxattr() in order to prevent
373              unnecessary mounts, but it returns the same result as we already
374              know that NAME is not a symbolic link at this point (modulo the
375              TOCTTOU race condition).  */
376           ret = acl_extended_file_nofollow (name);
377 #  else
378           /* On Linux, acl_extended_file is an optimized function: It only
379              makes two calls to getxattr(), one for ACL_TYPE_ACCESS, one for
380              ACL_TYPE_DEFAULT.  */
381           ret = acl_extended_file (name);
382 #  endif
383         }
384       else /* FreeBSD, MacOS X, IRIX, Tru64 */
385         {
386 #  if HAVE_ACL_TYPE_EXTENDED /* MacOS X */
387           /* On MacOS X, acl_get_file (name, ACL_TYPE_ACCESS)
388              and acl_get_file (name, ACL_TYPE_DEFAULT)
389              always return NULL / EINVAL.  There is no point in making
390              these two useless calls.  The real ACL is retrieved through
391              acl_get_file (name, ACL_TYPE_EXTENDED).  */
392           acl_t acl = acl_get_file (name, ACL_TYPE_EXTENDED);
393           if (acl)
394             {
395               ret = acl_extended_nontrivial (acl);
396               acl_free (acl);
397             }
398           else
399             ret = -1;
400 #  else /* FreeBSD, IRIX, Tru64 */
401           acl_t acl = acl_get_file (name, ACL_TYPE_ACCESS);
402           if (acl)
403             {
404               int saved_errno;
405
406               ret = acl_access_nontrivial (acl);
407               saved_errno = errno;
408               acl_free (acl);
409               errno = saved_errno;
410 #   if HAVE_ACL_FREE_TEXT /* Tru64 */
411               /* On OSF/1, acl_get_file (name, ACL_TYPE_DEFAULT) always
412                  returns NULL with errno not set.  There is no point in
413                  making this call.  */
414 #   else /* FreeBSD, IRIX */
415               /* On Linux, FreeBSD, IRIX, acl_get_file (name, ACL_TYPE_ACCESS)
416                  and acl_get_file (name, ACL_TYPE_DEFAULT) on a directory
417                  either both succeed or both fail; it depends on the
418                  file system.  Therefore there is no point in making the second
419                  call if the first one already failed.  */
420               if (ret == 0 && S_ISDIR (sb->st_mode))
421                 {
422                   acl = acl_get_file (name, ACL_TYPE_DEFAULT);
423                   if (acl)
424                     {
425                       ret = (0 < acl_entries (acl));
426                       acl_free (acl);
427                     }
428                   else
429                     ret = -1;
430                 }
431 #   endif
432             }
433           else
434             ret = -1;
435 #  endif
436         }
437       if (ret < 0)
438         return ACL_NOT_WELL_SUPPORTED (errno) ? 0 : -1;
439       return ret;
440
441 # elif HAVE_FACL && defined GETACLCNT /* Solaris, Cygwin, not HP-UX */
442
443 #  if defined ACL_NO_TRIVIAL
444
445       /* Solaris 10 (newer version), which has additional API declared in
446          <sys/acl.h> (acl_t) and implemented in libsec (acl_set, acl_trivial,
447          acl_fromtext, ...).  */
448       return acl_trivial (name);
449
450 #  else /* Solaris, Cygwin, general case */
451
452       /* Solaris 2.5 through Solaris 10, Cygwin, and contemporaneous versions
453          of Unixware.  The acl() call returns the access and default ACL both
454          at once.  */
455       int count;
456       {
457         aclent_t *entries;
458
459         for (;;)
460           {
461             count = acl (name, GETACLCNT, 0, NULL);
462
463             if (count < 0)
464               {
465                 if (errno == ENOSYS || errno == ENOTSUP)
466                   break;
467                 else
468                   return -1;
469               }
470
471             if (count == 0)
472               break;
473
474             /* Don't use MIN_ACL_ENTRIES:  It's set to 4 on Cygwin, but Cygwin
475                returns only 3 entries for files with no ACL.  But this is safe:
476                If there are more than 4 entries, there cannot be only the
477                "user::", "group::", "other:", and "mask:" entries.  */
478             if (count > 4)
479               return 1;
480
481             entries = (aclent_t *) malloc (count * sizeof (aclent_t));
482             if (entries == NULL)
483               {
484                 errno = ENOMEM;
485                 return -1;
486               }
487             if (acl (name, GETACL, count, entries) == count)
488               {
489                 if (acl_nontrivial (count, entries))
490                   {
491                     free (entries);
492                     return 1;
493                   }
494                 free (entries);
495                 break;
496               }
497             /* Huh? The number of ACL entries changed since the last call.
498                Repeat.  */
499             free (entries);
500           }
501       }
502
503 #   ifdef ACE_GETACL
504       /* Solaris also has a different variant of ACLs, used in ZFS and NFSv4
505          file systems (whereas the other ones are used in UFS file systems).  */
506       {
507         ace_t *entries;
508
509         for (;;)
510           {
511             count = acl (name, ACE_GETACLCNT, 0, NULL);
512
513             if (count < 0)
514               {
515                 if (errno == ENOSYS || errno == EINVAL)
516                   break;
517                 else
518                   return -1;
519               }
520
521             if (count == 0)
522               break;
523
524             /* If there are more than 3 entries, there cannot be only the
525                ACE_OWNER, ACE_GROUP, ACE_OTHER entries.  */
526             if (count > 3)
527               return 1;
528
529             entries = (ace_t *) malloc (count * sizeof (ace_t));
530             if (entries == NULL)
531               {
532                 errno = ENOMEM;
533                 return -1;
534               }
535             if (acl (name, ACE_GETACL, count, entries) == count)
536               {
537                 if (acl_ace_nontrivial (count, entries))
538                   {
539                     free (entries);
540                     return 1;
541                   }
542                 free (entries);
543                 break;
544               }
545             /* Huh? The number of ACL entries changed since the last call.
546                Repeat.  */
547             free (entries);
548           }
549       }
550 #   endif
551
552       return 0;
553 #  endif
554
555 # elif HAVE_GETACL /* HP-UX */
556
557       for (;;)
558         {
559           int count;
560           struct acl_entry entries[NACLENTRIES];
561
562           count = getacl (name, 0, NULL);
563
564           if (count < 0)
565             {
566               /* ENOSYS is seen on newer HP-UX versions.
567                  EOPNOTSUPP is typically seen on NFS mounts.
568                  ENOTSUP was seen on Quantum StorNext file systems (cvfs).  */
569               if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP)
570                 break;
571               else
572                 return -1;
573             }
574
575           if (count == 0)
576             return 0;
577
578           if (count > NACLENTRIES)
579             /* If NACLENTRIES cannot be trusted, use dynamic memory
580                allocation.  */
581             abort ();
582
583           /* If there are more than 3 entries, there cannot be only the
584              (uid,%), (%,gid), (%,%) entries.  */
585           if (count > 3)
586             return 1;
587
588           if (getacl (name, count, entries) == count)
589             {
590               struct stat statbuf;
591
592               if (stat (name, &statbuf) < 0)
593                 return -1;
594
595               return acl_nontrivial (count, entries, &statbuf);
596             }
597           /* Huh? The number of ACL entries changed since the last call.
598              Repeat.  */
599         }
600
601 #  if HAVE_ACLV_H /* HP-UX >= 11.11 */
602
603       for (;;)
604         {
605           int count;
606           struct acl entries[NACLVENTRIES];
607
608           count = acl ((char *) name, ACL_CNT, NACLVENTRIES, entries);
609
610           if (count < 0)
611             {
612               /* EOPNOTSUPP is seen on NFS in HP-UX 11.11, 11.23.
613                  EINVAL is seen on NFS in HP-UX 11.31.  */
614               if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL)
615                 break;
616               else
617                 return -1;
618             }
619
620           if (count == 0)
621             return 0;
622
623           if (count > NACLVENTRIES)
624             /* If NACLVENTRIES cannot be trusted, use dynamic memory
625                allocation.  */
626             abort ();
627
628           /* If there are more than 4 entries, there cannot be only the
629              four base ACL entries.  */
630           if (count > 4)
631             return 1;
632
633           if (acl ((char *) name, ACL_GET, count, entries) == count)
634             return aclv_nontrivial (count, entries);
635           /* Huh? The number of ACL entries changed since the last call.
636              Repeat.  */
637         }
638
639 #  endif
640
641 # elif HAVE_ACLX_GET && defined ACL_AIX_WIP /* AIX */
642
643       acl_type_t type;
644       char aclbuf[1024];
645       void *acl = aclbuf;
646       size_t aclsize = sizeof (aclbuf);
647       mode_t mode;
648
649       for (;;)
650         {
651           /* The docs say that type being 0 is equivalent to ACL_ANY, but it
652              is not true, in AIX 5.3.  */
653           type.u64 = ACL_ANY;
654           if (aclx_get (name, 0, &type, aclbuf, &aclsize, &mode) >= 0)
655             break;
656           if (errno != ENOSPC)
657             {
658               if (acl != aclbuf)
659                 {
660                   int saved_errno = errno;
661                   free (acl);
662                   errno = saved_errno;
663                 }
664               return -1;
665             }
666           aclsize = 2 * aclsize;
667           if (acl != aclbuf)
668             free (acl);
669           acl = malloc (aclsize);
670           if (acl == NULL)
671             {
672               errno = ENOMEM;
673               return -1;
674             }
675         }
676
677       if (type.u64 == ACL_AIXC)
678         {
679           int result = acl_nontrivial ((struct acl *) acl);
680           if (acl != aclbuf)
681             free (acl);
682           return result;
683         }
684       else if (type.u64 == ACL_NFS4)
685         {
686           int result = acl_nfs4_nontrivial ((nfs4_acl_int_t *) acl);
687           if (acl != aclbuf)
688             free (acl);
689           return result;
690         }
691       else
692         {
693           /* A newer type of ACL has been introduced in the system.
694              We should better support it.  */
695           if (acl != aclbuf)
696             free (acl);
697           errno = EINVAL;
698           return -1;
699         }
700
701 # elif HAVE_STATACL /* older AIX */
702
703       union { struct acl a; char room[4096]; } u;
704
705       if (statacl (name, STX_NORMAL, &u.a, sizeof (u)) < 0)
706         return -1;
707
708       return acl_nontrivial (&u.a);
709
710 # elif HAVE_ACLSORT /* NonStop Kernel */
711
712       int count;
713       struct acl entries[NACLENTRIES];
714
715       for (;;)
716         {
717           count = acl ((char *) name, ACL_CNT, NACLENTRIES, NULL);
718
719           if (count < 0)
720             return -1;
721
722           if (count == 0)
723             return 0;
724
725           if (count > NACLENTRIES)
726             /* If NACLENTRIES cannot be trusted, use dynamic memory
727                allocation.  */
728             abort ();
729
730           /* If there are more than 4 entries, there cannot be only the
731              four base ACL entries.  */
732           if (count > 4)
733             return 1;
734
735           if (acl ((char *) name, ACL_GET, count, entries) == count)
736             return acl_nontrivial (count, entries);
737           /* Huh? The number of ACL entries changed since the last call.
738              Repeat.  */
739         }
740
741 # endif
742     }
743 #endif
744
745   return 0;
746 }