-/* get-permissions.c - get permissions of a file
+/* Get permissions of a file. -*- coding: utf-8 -*-
- Copyright (C) 2002-2003, 2005-2015 Free Software Foundation, Inc.
+ Copyright (C) 2002-2003, 2005-2016 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
get_permissions (const char *name, int desc, mode_t mode,
struct permission_context *ctx)
{
- memset (ctx, 0, sizeof(*ctx));
+ memset (ctx, 0, sizeof *ctx);
ctx->mode = mode;
#if USE_ACL && HAVE_ACL_GET_FILE
return -1;
}
+# if HAVE_ACL_TYPE_NFS4 /* FreeBSD */
+
+ /* TODO (see set_permissions). */
+
+# endif
+
# else /* HAVE_ACL_TYPE_EXTENDED */
/* Mac OS X */
There is an API
pathconf (name, _PC_ACL_ENABLED)
fpathconf (desc, _PC_ACL_ENABLED)
- that allows to determine which of the two kinds of ACLs is supported
+ that allows us to determine which of the two kinds of ACLs is supported
for the given file. But some file systems may implement this call
incorrectly, so better not use it.
When fetching the source ACL, we simply fetch both ACL types.
#elif USE_ACL && HAVE_GETACL /* HP-UX */
- int ret;
-
- if (desc != -1)
- ret = fgetacl (desc, NACLENTRIES, ctx->entries);
- else
- ret = getacl (name, NACLENTRIES, ctx->entries);
- if (ret < 0)
- {
- if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP)
- ret = 0;
- else
- return -1;
- }
- else if (ret > NACLENTRIES)
- /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */
- abort ();
- ctx->count = ret;
+ {
+ int ret;
+
+ if (desc != -1)
+ ret = fgetacl (desc, NACLENTRIES, ctx->entries);
+ else
+ ret = getacl (name, NACLENTRIES, ctx->entries);
+ if (ret < 0)
+ {
+ if (errno == ENOSYS || errno == EOPNOTSUPP || errno == ENOTSUP)
+ ret = 0;
+ else
+ return -1;
+ }
+ else if (ret > NACLENTRIES)
+ /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */
+ abort ();
+ ctx->count = ret;
# if HAVE_ACLV_H
- ret = acl ((char *) name, ACL_GET, NACLVENTRIES, ctx->aclv_entries);
- if (ret < 0)
- {
- if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL)
- ret = 0;
- else
- return -2;
- }
- else if (ret > NACLVENTRIES)
- /* If NACLVENTRIES cannot be trusted, use dynamic memory allocation. */
+ ret = acl ((char *) name, ACL_GET, NACLVENTRIES, ctx->aclv_entries);
+ if (ret < 0)
+ {
+ if (errno == ENOSYS || errno == EOPNOTSUPP || errno == EINVAL)
+ ret = 0;
+ else
+ return -2;
+ }
+ else if (ret > NACLVENTRIES)
+ /* If NACLVENTRIES cannot be trusted, use dynamic memory allocation. */
abort ();
- ctx->aclv_count = ret;
+ ctx->aclv_count = ret;
# endif
+ }
#elif USE_ACL && HAVE_ACLX_GET && ACL_AIX_WIP /* AIX */
#elif USE_ACL && HAVE_STATACL /* older AIX */
- if (desc != -1)
- ret = fstatacl (desc, STX_NORMAL, &ctx->u.a, sizeof (ctx->u));
- else
- ret = statacl (name, STX_NORMAL, &ctx->u.a, sizeof (ctx->u));
- if (ret == 0)
- ctx->have_u = true;
+ {
+ int ret;
+ if (desc != -1)
+ ret = fstatacl (desc, STX_NORMAL, &ctx->u.a, sizeof ctx->u);
+ else
+ ret = statacl ((char *) name, STX_NORMAL, &ctx->u.a, sizeof ctx->u);
+ if (ret == 0)
+ ctx->have_u = true;
+ }
#elif USE_ACL && HAVE_ACLSORT /* NonStop Kernel */
- int ret;
-
- ret = acl ((char *) name, ACL_GET, NACLENTRIES, ctx->entries);
- if (ret < 0)
- return -1;
- else if (ret > NACLENTRIES)
- /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */
- abort ();
- ctx->count = ret;
+ {
+ int ret = acl ((char *) name, ACL_GET, NACLENTRIES, ctx->entries);
+ if (ret < 0)
+ return -1;
+ else if (ret > NACLENTRIES)
+ /* If NACLENTRIES cannot be trusted, use dynamic memory allocation. */
+ abort ();
+ ctx->count = ret;
+ }
#endif