]> gitweb.factorcode.org Git - factor.git/blob - extra/io/files/acls/macosx/ffi/ffi.factor
change ERROR: words from throw-foo back to foo.
[factor.git] / extra / io / files / acls / macosx / ffi / ffi.factor
1 ! Copyright (C) 2010 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.c-types alien.syntax classes.struct kernel
4 literals math.order sequences unix.types ;
5 IN: io.files.acls.macosx.ffi
6
7 TYPEDEF: uint acl_type_t
8 TYPEDEF: uint acl_perm_t
9 TYPEDEF: void* acl_t
10 TYPEDEF: void* acl_entry_t
11 TYPEDEF: void* acl_permset_t
12 TYPEDEF: void* acl_flagset_t
13
14 CONSTANT: KAUTH_GUID_SIZE 16
15
16 CONSTANT: ACL_MAX_ENTRIES 128
17
18 ! acl_entry_id_t
19 CONSTANT: ACL_FIRST_ENTRY 0
20 CONSTANT: ACL_NEXT_ENTRY -1
21 CONSTANT: ACL_LAST_ENTRY -2
22
23 ! acl_type_t Supported:
24 CONSTANT: ACL_TYPE_EXTENDED 0x00000100
25 ! acl_type_t Unsupported:
26 CONSTANT: ACL_TYPE_ACCESS 0x00000000
27 CONSTANT: ACL_TYPE_DEFAULT 0x00000001
28 CONSTANT: ACL_TYPE_AFS 0x00000002
29 CONSTANT: ACL_TYPE_CODA 0x00000003
30 CONSTANT: ACL_TYPE_NTFS 0x00000004
31 CONSTANT: ACL_TYPE_NWFS 0x00000005
32
33 ! acl_perm_t
34 CONSTANT: ACL_READ_DATA        2
35 CONSTANT: ACL_LIST_DIRECTORY   2
36 CONSTANT: ACL_WRITE_DATA       4
37 CONSTANT: ACL_ADD_FILE         4
38 CONSTANT: ACL_EXECUTE          8
39 CONSTANT: ACL_SEARCH           8
40 CONSTANT: ACL_DELETE           16
41 CONSTANT: ACL_APPEND_DATA      32
42 CONSTANT: ACL_ADD_SUBDIRECTORY 32
43 CONSTANT: ACL_DELETE_CHILD     64
44 CONSTANT: ACL_READ_ATTRIBUTES  128
45 CONSTANT: ACL_WRITE_ATTRIBUTES 256
46 CONSTANT: ACL_READ_EXTATTRIBUTES 512
47 CONSTANT: ACL_WRITE_EXTATTRIBUTES 1024
48 CONSTANT: ACL_READ_SECURITY    2048
49 CONSTANT: ACL_WRITE_SECURITY   4096
50 CONSTANT: ACL_CHANGE_OWNER     8192
51
52 CONSTANT: acl-perms ${
53     ACL_READ_DATA ACL_LIST_DIRECTORY ACL_WRITE_DATA ACL_ADD_FILE
54     ACL_EXECUTE ACL_SEARCH ACL_DELETE ACL_APPEND_DATA ACL_ADD_SUBDIRECTORY
55     ACL_DELETE_CHILD ACL_READ_ATTRIBUTES ACL_WRITE_ATTRIBUTES
56     ACL_READ_EXTATTRIBUTES ACL_WRITE_EXTATTRIBUTES
57     ACL_READ_SECURITY ACL_WRITE_SECURITY ACL_CHANGE_OWNER
58 }
59
60 CONSTANT: acl-perm-names
61 {
62     "read" "list" "write" "add_file" "execute" "search"
63     "delete" "append" "add_subdirectory" "delete_child"
64     "readattr" "writeattr" "readextattr" "writeextattr"
65     "readsecurity" "writesecurity" "chown"
66 }
67
68 CONSTANT: acl-file-perm { t f t f t f t t f f t t t t t t t }
69 CONSTANT: acl-dir-perm  { f t f t f t t f t t t t t t t t t }
70
71 ! acl_tag_t
72 TYPEDEF: uint acl_tag_t
73 CONSTANT: ACL_UNDEFINED_TAG  0
74 CONSTANT: ACL_EXTENDED_ALLOW 1
75 CONSTANT: ACL_EXTENDED_DENY  2
76
77 ERROR: bad-acl-tag-t n ;
78
79 : acl_tag_t>string ( n -- string )
80     dup 0 2 between? [ bad-acl-tag-t ] unless
81     { "undefined" "allow" "deny" } nth ;
82
83 ! acl_flag_t
84 TYPEDEF: int acl_flag_t
85 CONSTANT: ACL_FLAG_DEFER_INHERIT 1
86 CONSTANT: ACL_ENTRY_INHERITED 16
87 CONSTANT: ACL_ENTRY_FILE_INHERIT 32
88 CONSTANT: ACL_ENTRY_DIRECTORY_INHERIT 64
89 CONSTANT: ACL_ENTRY_LIMIT_INHERIT 128
90 CONSTANT: ACL_ENTRY_ONLY_INHERIT 256
91
92 CONSTANT: acl-flags ${
93     ACL_ENTRY_FILE_INHERIT
94     ACL_ENTRY_DIRECTORY_INHERIT
95     ACL_ENTRY_LIMIT_INHERIT
96     ACL_ENTRY_ONLY_INHERIT
97 }
98
99 CONSTANT: acl-flag-names {
100     "file_inherit"
101     "directory_inherit"
102     "limit_inherit"
103     "only_inherit"
104 }
105
106 STRUCT: guid_t
107    { g_guid { uchar KAUTH_GUID_SIZE } } ;
108
109 TYPEDEF: uint kauth_ace_rights_t
110 STRUCT: kauth_ace
111    { ace_applicable guid_t }
112    { ace_flags uint }
113    { ace_rights kauth_ace_rights_t } ;
114 TYPEDEF: kauth_ace* kauth_ace_t
115
116 STRUCT: kauth_acl
117    { acl_entrycount uint }
118    { acl_flags uint }
119    { acl_ace { kauth_ace 1 } } ;
120 TYPEDEF: kauth_acl* kauth_acl_t
121
122 STRUCT: kauth_filesec
123    { fsec_magic uint }
124    { fsec_owner guid_t }
125    { fsec_group guid_t } ;
126 TYPEDEF: kauth_filesec* kauth_filesec_t
127
128 FUNCTION: int acl_dup ( acl_t acl )
129 FUNCTION: int acl_free ( void* obj_p )
130 FUNCTION: acl_t acl_init ( int count )
131
132 FUNCTION: acl_t acl_get_fd ( int fd )
133 FUNCTION: acl_t acl_get_fd_np ( int fd, acl_type_t type )
134 FUNCTION: acl_t acl_get_file ( char* path_p, acl_type_t type )
135 FUNCTION: acl_t acl_get_link_np ( char* path_p, acl_type_t type )
136
137 FUNCTION: int acl_set_file ( char* path_p, acl_type_t type, acl_t acl )
138
139 FUNCTION: int acl_get_entry ( acl_t acl, int entry_id, acl_entry_t* entry_p )
140
141 FUNCTION: int acl_get_permset ( acl_entry_t entry_d, acl_permset_t* permset_p )
142 FUNCTION: int acl_get_perm_np ( acl_permset_t permset_d, acl_perm_t perm )
143
144 FUNCTION: ssize_t acl_copy_ext ( void* buf_p, acl_t acl, ssize_t size )
145 FUNCTION: ssize_t acl_copy_ext_native ( void* buf_p, acl_t acl, ssize_t size )
146 FUNCTION: acl_t acl_copy_int ( void* buf_p )
147 FUNCTION: acl_t acl_copy_int_native ( void* buf_p )
148 FUNCTION: acl_t acl_from_text ( char* buf_p )
149 FUNCTION: ssize_t acl_size ( acl_t acl )
150 FUNCTION: char* acl_to_text ( acl_t acl, ssize_t* len_p )
151 FUNCTION: int acl_valid ( acl_t acl )
152 FUNCTION: int acl_add_perm ( acl_permset_t permset_d, acl_perm_t perm )
153 FUNCTION: int acl_delete_perm ( acl_permset_t permset_d, acl_perm_t perm )
154 FUNCTION: void* acl_get_qualifier ( acl_entry_t entry_d )
155 FUNCTION: int acl_get_flagset_np ( void *obj, acl_flagset_t* flagset_p )
156 FUNCTION: int acl_get_flag_np ( acl_flagset_t flagset_d, acl_flag_t flag )
157 FUNCTION: int acl_get_tag_type ( acl_entry_t entry_d, acl_tag_t *tag_type_p )
158
159 TYPEDEF: uchar[16] uuid_t
160
161 CONSTANT: ID_TYPE_UID 0
162 CONSTANT: ID_TYPE_GID 1
163 CONSTANT: ID_TYPE_SID 3
164 CONSTANT: ID_TYPE_USERNAME 4
165 CONSTANT: ID_TYPE_GROUPNAME 5
166 CONSTANT: ID_TYPE_GSS_EXPORT_NAME 10
167 CONSTANT: ID_TYPE_X509_DN 11
168 CONSTANT: ID_TYPE_KERBEROS 12
169
170 CONSTANT: NTSID_MAX_AUTHORITIES 16
171
172 ! FIXME: Supposed to be packed
173 STRUCT: nt_sid_t
174     { sid_kind u_int8_t }
175     { sid_authcount u_int8_t }
176     { sid_authority u_int8_t[6] }
177     { sid_authorities u_int32_t[NTSID_MAX_AUTHORITIES] } ;
178
179 FUNCTION: int mbr_uid_to_uuid ( uid_t id, uuid_t uu )
180 FUNCTION: int mbr_gid_to_uuid ( gid_t id, uuid_t uu )
181 FUNCTION: int mbr_uuid_to_id ( uuid_t uu, uid_t *id, int *id_type )
182 FUNCTION: int mbr_sid_to_uuid ( nt_sid_t *sid, uuid_t uu )
183 FUNCTION: int mbr_uuid_to_sid ( uuid_t uu, nt_sid_t *sid )
184
185 TYPEDEF: char[37] uuid_string_t
186
187 FUNCTION: int mbr_uuid_to_string (  uuid_t uu, char* string )