libc/winsup/cygwin/sec_posixacl.h
Corinna Vinschen 9ddf063921 Implement POSIX.1e ACL functions
* Makefile.in (DLL_OFILES): Add sec_posixacl.o.
	(SUBLIBS): Add libacl.a
	(libacl.a): New rule to create libacl.a.
	* common.din: Export POSIX ACL functions as well as most libacl.a
	extensions.
	* fhandler.h (fhander_base::acl_get): New prototype.
	(fhander_base::acl_set): Ditto.
	(fhandler_disk_file::acl_get): Ditto.
	(fhandler_disk_file::acl_set): Ditto.
	* include/acl/libacl.h: New file.
	* include/cygwin/version.h: Bump API minor version.
	* include/sys/acl.h: Drop including cygwin/acl.h.  Accommodate
	throughout Cygwin.  Add POSIX ACL definitions.
	* sec_acl.cc: Include sec_posixacl.h.  Replace ILLEGAL_UID and
	ILLEGAL_GID with ACL_UNDEFINED_ID where sensible.
	(__aclcheck): New internal acl check function to be used for
	Solaris and POSIX ACLs.
	(aclcheck32): Call __aclcheck.
	(__aclcalcmask): New function to compute ACL_MASK value.
	(__aclsort): New internal acl sort function to be used for Solaris
	and POSIX ACLs.
	(aclsort32): Call __aclsort.
	(permtostr): Work directly on provided buffer.
	(__acltotext): New internal acltotext function to be used for
	Solaris and POSIX ACLs.
	(acltotext32): Call __acltotext.
	(__aclfromtext): New internal aclfromtext function to be used for
	Solaris and POSIX ACLs.
	(aclfromtext32): Call __aclfromtext.
	* sec_posixacl.cc: New file implemeting POSIX ACL functions.
	* sec_posixacl.h: New internal header.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-03-08 13:56:40 +01:00

69 lines
2 KiB
C

/* sec_posixacl.h: Internal definitions for POSIX ACLs.
This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#include <cygwin/acl.h>
#include <sys/acl.h>
#include <acl/libacl.h>
/* Magic marker for acl_t. */
#define ACL_MAGIC (0xacdccdcadcaccacdULL)
/* Only used internally as a_type for deleted entries. */
#define ACL_DELETED_TAG (0xffff)
/* Only used internally from acl_to_text/acl_to_any_text. */
#define TEXT_END_SEPARATOR (0x1000)
#define TEXT_IS_POSIX (0x2000)
/* Internal ACL representation. */
struct __acl_t
{
uint64_t magic; /* Must be ACL_MAGIC. */
uint16_t max_count; /* Max. number of entries. */
uint16_t count; /* Number of used entries. */
uint16_t deleted; /* Number of used but deleted entries. */
uint16_t next; /* Next entry to be returned by acl_get_entry. */
aclent_t *entry; /* Pointer to variable array of ACL entries. */
};
inline acl_entry_t
__to_entry (acl_t acl, uint16_t idx)
{
return ((uint64_t) idx << 48) | (uint64_t) acl;
}
#define __to_permset(a,i) ((acl_permset_t)__to_entry((a),(i)))
inline acl_t
__from_entry (acl_entry_t entry_d, uint16_t &idx)
{
idx = entry_d >> 48;
acl_t acl = (acl_t) (entry_d & ~((uint64_t) 0xffff << 48));
if (acl->magic != ACL_MAGIC)
return NULL;
if (idx >= acl->count)
return NULL;
if (acl->entry[idx].a_type == ACL_DELETED_TAG)
return NULL;
return acl;
}
#define __from_permset(p,i) __from_entry((acl_permset_t)(p),(i))
/* External (but opaque) ACL representation. */
struct __acl_ext_t
{
uint16_t count; /* Number of used entries. */
aclent_t entry[0]; /* Variable array of ACL entries. */
};
/* Shared functions defined in sec_acl.cc. */
mode_t __aclcalcmask (aclent_t *, int);
int __aclsort (int, aclent_t *);
int __aclcheck (aclent_t *, int, int *, bool);
char *__acltotext (aclent_t *, int, const char *, char, int);
void *__aclfromtext (const char *, int *, bool);