(root)/
acl-2.3.1/
libacl/
libobj.h
       1  /*
       2    Copyright (C) 2000, 2002, 2003  Andreas Gruenbacher <agruen@suse.de>
       3  
       4    This program is free software: you can redistribute it and/or modify it
       5    under the terms of the GNU Lesser General Public License as published by
       6    the Free Software Foundation, either version 2.1 of the License, or
       7    (at your option) any later version.
       8  
       9    This program is distributed in the hope that it will be useful,
      10    but WITHOUT ANY WARRANTY; without even the implied warranty of
      11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12    GNU Lesser General Public License for more details.
      13  
      14    You should have received a copy of the GNU Lesser General Public License
      15    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      16  */
      17  
      18  #ifndef __LIBOBJ_H
      19  #define __LIBOBJ_H
      20  
      21  #include <stdlib.h>
      22  
      23  #include "misc.h"
      24  
      25  /* Ugly pointer manipulation */
      26  
      27  #ifdef LIBACL_DEBUG
      28  #  define ext2int(T, ext_p) \
      29  	((T##_obj *)__ext2int_and_check(ext_p, T##_MAGIC, #T))
      30  #else
      31  #  define ext2int(T, ext_p) \
      32  	((T##_obj *)__ext2int_and_check(ext_p, T##_MAGIC))
      33  #endif
      34  
      35  #define int2ext(int_p) \
      36  	((int_p) ? &(int_p)->i : NULL)
      37  #define new_var_obj_p(T, sz) \
      38  	((T##_obj *)__new_var_obj_p(T##_MAGIC, sizeof(T##_obj) + sz))
      39  #define realloc_var_obj_p(T, p, sz) \
      40  	((T##_obj *)realloc(p, sizeof(T##_obj) + sz))
      41  #define new_obj_p(T) \
      42  	new_var_obj_p(T, 0)
      43  #define new_obj_p_here(T, p) \
      44  	__new_obj_p_here(T##_MAGIC, p)
      45  #define check_obj_p(T, obj_p) \
      46  	((T##_obj *)__check_obj_p((obj_prefix *)(obj_p), T##_MAGIC))
      47  #define free_obj_p(obj_p) \
      48  	(__free_obj_p((obj_prefix *)(obj_p)))
      49  
      50  
      51  /* prefix for all objects */
      52  /* [Note: p_magic is a long rather than int so that this structure */
      53  /* does not become padded by the compiler on 64-bit architectures] */
      54  
      55  typedef struct {
      56  	unsigned long		p_magic:16;
      57  	unsigned long		p_flags:16;
      58  } obj_prefix;
      59  
      60  #define pmagic o_prefix.p_magic
      61  #define pflags o_prefix.p_flags
      62  
      63  /* magic object values */
      64  #define acl_MAGIC		(0x712C)
      65  #define acl_entry_MAGIC		(0x9D6B)
      66  #define acl_permset_MAGIC	(0x1ED5)
      67  #define qualifier_MAGIC		(0x1C27)
      68  #define string_MAGIC		(0xD5F2)
      69  #define cap_MAGIC		(0x6CA8)
      70  
      71  /* object flags */
      72  #define OBJ_MALLOC_FLAG		1
      73  
      74  /* object types */
      75  struct string_obj_tag;
      76  typedef struct string_obj_tag string_obj;
      77  
      78  /* string object */
      79  struct __string_ext {
      80  	char			s_str[0];
      81  };
      82  struct string_obj_tag {
      83  	obj_prefix		o_prefix;
      84  	struct __string_ext	i;
      85  };
      86  
      87  #define sstr i.s_str
      88  
      89  /* object creation, destruction, conversion and validation */
      90  void *__new_var_obj_p(int magic, size_t size) hidden;
      91  void __new_obj_p_here(int magic, void *here) hidden;
      92  void __free_obj_p(obj_prefix *obj_p) hidden;
      93  obj_prefix *__check_obj_p(obj_prefix *obj_p, int magic) hidden;
      94  #ifdef LIBACL_DEBUG
      95  obj_prefix *__ext2int_and_check(void *ext_p, int magic,
      96  				const char *typename) hidden;
      97  #else
      98  obj_prefix *__ext2int_and_check(void *ext_p, int magic) hidden;
      99  #endif
     100  
     101  #endif /* __LIBOBJ_H */