s4:auth: kinit_to_ccache() should always use the canonicalized principal
[Samba.git] / source3 / lib / adouble.h
blob71072d32560e6ef7b32db6c6f9864496521b2dde
1 /*
2 * Samba AppleDouble helpers
4 * Copyright (C) Ralph Boehme, 2019
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #ifndef _ADOUBLE_H_
21 #define _ADOUBLE_H_
23 #include "MacExtensions.h"
25 #define ADOUBLE_NAME_PREFIX "._"
27 #define NETATALK_META_XATTR "org.netatalk.Metadata"
28 #define NETATALK_RSRC_XATTR "org.netatalk.ResourceFork"
30 #if defined(HAVE_ATTROPEN)
31 #define AFPINFO_EA_NETATALK NETATALK_META_XATTR
32 #define AFPRESOURCE_EA_NETATALK NETATALK_RSRC_XATTR
33 #else
34 #define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR
35 #define AFPRESOURCE_EA_NETATALK "user." NETATALK_RSRC_XATTR
36 #endif
39 * There are two AppleDouble blobs we deal with:
41 * - ADOUBLE_META - AppleDouble blob used by Netatalk for storing
42 * metadata in an xattr
44 * - ADOUBLE_RSRC - AppleDouble blob used by OS X and Netatalk in
45 * ._ files
47 typedef enum {ADOUBLE_META, ADOUBLE_RSRC} adouble_type_t;
49 /* Version info */
50 #define AD_VERSION2 0x00020000
51 #define AD_VERSION AD_VERSION2
54 * AppleDouble entry IDs.
56 #define ADEID_DFORK 1
57 #define ADEID_RFORK 2
58 #define ADEID_NAME 3
59 #define ADEID_COMMENT 4
60 #define ADEID_ICONBW 5
61 #define ADEID_ICONCOL 6
62 #define ADEID_FILEI 7
63 #define ADEID_FILEDATESI 8
64 #define ADEID_FINDERI 9
65 #define ADEID_MACFILEI 10
66 #define ADEID_PRODOSFILEI 11
67 #define ADEID_MSDOSFILEI 12
68 #define ADEID_SHORTNAME 13
69 #define ADEID_AFPFILEI 14
70 #define ADEID_DID 15
72 /* Private Netatalk entries */
73 #define ADEID_PRIVDEV 16
74 #define ADEID_PRIVINO 17
75 #define ADEID_PRIVSYN 18
76 #define ADEID_PRIVID 19
77 #define ADEID_MAX (ADEID_PRIVID + 1)
80 * These are the real ids for the private entries,
81 * as stored in the adouble file
83 #define AD_DEV 0x80444556
84 #define AD_INO 0x80494E4F
85 #define AD_SYN 0x8053594E
86 #define AD_ID 0x8053567E
88 /* AppleDouble magic */
89 #define AD_APPLESINGLE_MAGIC 0x00051600
90 #define AD_APPLEDOUBLE_MAGIC 0x00051607
91 #define AD_MAGIC AD_APPLEDOUBLE_MAGIC
93 /* Field widths */
94 #define ADEDLEN_NAME 255
95 #define ADEDLEN_COMMENT 200
96 #define ADEDLEN_FILEI 16
97 #define ADEDLEN_FINDERI 32
98 #define ADEDLEN_FILEDATESI 16
99 #define ADEDLEN_SHORTNAME 12 /* length up to 8.3 */
100 #define ADEDLEN_AFPFILEI 4
101 #define ADEDLEN_MACFILEI 4
102 #define ADEDLEN_PRODOSFILEI 8
103 #define ADEDLEN_MSDOSFILEI 2
104 #define ADEDLEN_DID 4
105 #define ADEDLEN_PRIVDEV 8
106 #define ADEDLEN_PRIVINO 8
107 #define ADEDLEN_PRIVSYN 8
108 #define ADEDLEN_PRIVID 4
111 * Sharemode locks fcntl() offsets
113 #if _FILE_OFFSET_BITS == 64 || defined(HAVE_LARGEFILE)
114 #define AD_FILELOCK_BASE (UINT64_C(0x7FFFFFFFFFFFFFFF) - 9)
115 #else
116 #define AD_FILELOCK_BASE (UINT32_C(0x7FFFFFFF) - 9)
117 #endif
118 #define BYTELOCK_MAX (AD_FILELOCK_BASE - 1)
120 #define AD_FILELOCK_OPEN_WR (AD_FILELOCK_BASE + 0)
121 #define AD_FILELOCK_OPEN_RD (AD_FILELOCK_BASE + 1)
122 #define AD_FILELOCK_RSRC_OPEN_WR (AD_FILELOCK_BASE + 2)
123 #define AD_FILELOCK_RSRC_OPEN_RD (AD_FILELOCK_BASE + 3)
124 #define AD_FILELOCK_DENY_WR (AD_FILELOCK_BASE + 4)
125 #define AD_FILELOCK_DENY_RD (AD_FILELOCK_BASE + 5)
126 #define AD_FILELOCK_RSRC_DENY_WR (AD_FILELOCK_BASE + 6)
127 #define AD_FILELOCK_RSRC_DENY_RD (AD_FILELOCK_BASE + 7)
128 #define AD_FILELOCK_OPEN_NONE (AD_FILELOCK_BASE + 8)
129 #define AD_FILELOCK_RSRC_OPEN_NONE (AD_FILELOCK_BASE + 9)
131 /* Time stuff we overload the bits a little */
132 #define AD_DATE_CREATE 0
133 #define AD_DATE_MODIFY 4
134 #define AD_DATE_BACKUP 8
135 #define AD_DATE_ACCESS 12
136 #define AD_DATE_MASK (AD_DATE_CREATE | AD_DATE_MODIFY | \
137 AD_DATE_BACKUP | AD_DATE_ACCESS)
138 #define AD_DATE_UNIX (1 << 10)
139 #define AD_DATE_START 0x80000000
140 #define AD_DATE_DELTA 946684800
141 #define AD_DATE_FROM_UNIX(x) (htonl((x) - AD_DATE_DELTA))
142 #define AD_DATE_TO_UNIX(x) (ntohl(x) + AD_DATE_DELTA)
144 #define AD_CONV_WIPE_BLANK (1<<0)
145 #define AD_CONV_DELETE (1<<1)
147 struct adouble;
149 size_t ad_getentrylen(const struct adouble *ad, int eid);
150 size_t ad_getentryoff(const struct adouble *ad, int eid);
151 size_t ad_setentrylen(struct adouble *ad, int eid, size_t len);
152 size_t ad_setentryoff(struct adouble *ad, int eid, size_t off);
153 char *ad_get_entry(const struct adouble *ad, int eid);
154 int ad_getdate(const struct adouble *ad, unsigned int dateoff, uint32_t *date);
155 int ad_setdate(struct adouble *ad, unsigned int dateoff, uint32_t date);
156 int ad_convert(struct vfs_handle_struct *handle,
157 const struct smb_filename *smb_fname,
158 const char *catia_mappings,
159 uint32_t flags);
160 bool ad_unconvert(TALLOC_CTX *mem_ctx,
161 struct vfs_handle_struct *handle,
162 const char *catia_mappings,
163 struct smb_filename *smb_fname,
164 bool *converted);
165 struct adouble *ad_init(TALLOC_CTX *ctx, adouble_type_t type);
166 struct adouble *ad_get(TALLOC_CTX *ctx,
167 vfs_handle_struct *handle,
168 const struct smb_filename *smb_fname,
169 adouble_type_t type);
170 struct adouble *ad_fget(TALLOC_CTX *ctx, vfs_handle_struct *handle,
171 files_struct *fsp, adouble_type_t type);
172 int ad_set(vfs_handle_struct *handle,
173 struct adouble *ad,
174 const struct smb_filename *smb_fname);
175 int ad_fset(struct vfs_handle_struct *handle,
176 struct adouble *ad,
177 files_struct *fsp);
178 bool is_adouble_file(const char *path);
179 int adouble_path(TALLOC_CTX *ctx,
180 const struct smb_filename *smb_fname_in,
181 struct smb_filename **pp_smb_fname_out);
183 AfpInfo *afpinfo_new(TALLOC_CTX *ctx);
184 ssize_t afpinfo_pack(const AfpInfo *ai, char *buf);
185 AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *data);
187 #endif