Skip to content

Commit a7aff82

Browse files
committed
Remove Apple specific xattr handling
1 parent cd623e2 commit a7aff82

File tree

7 files changed

+26
-304
lines changed

7 files changed

+26
-304
lines changed

sources/apple_xattr_workaround.cpp

Lines changed: 0 additions & 95 deletions
This file was deleted.

sources/apple_xattr_workaround.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

sources/files.cpp

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,8 @@ FileBase::FileBase(std::shared_ptr<FileStream> data_stream,
166166
generated_keys + 2 * KEY_LENGTH, KEY_LENGTH, null_iv, array_length(null_iv));
167167
m_xattr_dec.SetKeyWithIV(
168168
generated_keys + 2 * KEY_LENGTH, KEY_LENGTH, null_iv, array_length(null_iv));
169+
m_xattr_name_cryptor.emplace(generated_keys + 2 * KEY_LENGTH, KEY_LENGTH);
169170

170-
if (!is_apple())
171-
{
172-
m_xattr_name_cryptor.emplace(generated_keys + 2 * KEY_LENGTH, KEY_LENGTH);
173-
}
174171
if (max_padding_size > 0)
175172
{
176173
warn_if_key_not_random(generated_keys, sizeof(generated_keys), __FILE__, __LINE__);
@@ -288,25 +285,20 @@ static const ssize_t XATTR_IV_LENGTH = 16, XATTR_MAC_LENGTH = 16;
288285

289286
ssize_t FileBase::listxattr(char* buffer, size_t size)
290287
{
291-
if (m_xattr_name_cryptor)
292-
{
293-
return generic_xattr::wrapped_listxattr(
294-
[m_data_stream = this->m_data_stream](char* buffer, size_t size)
295-
{ return m_data_stream->listxattr(buffer, size); },
296-
*m_xattr_name_cryptor,
297-
buffer,
298-
size);
299-
}
300-
return m_data_stream->listxattr(buffer, size);
288+
return generic_xattr::wrapped_listxattr(
289+
[m_data_stream = this->m_data_stream](char* buffer, size_t size)
290+
{ return m_data_stream->listxattr(buffer, size); },
291+
m_xattr_name_cryptor.value(),
292+
buffer,
293+
size);
301294
}
302295

303296
ssize_t FileBase::getxattr(const char* name, char* value, size_t size)
304297
{
305298
if (!name)
306299
throwVFSException(EFAULT);
307-
std::string wrapped_name = m_xattr_name_cryptor
308-
? generic_xattr::encrypt_xattr_name(*m_xattr_name_cryptor, name)
309-
: name;
300+
std::string wrapped_name
301+
= generic_xattr::encrypt_xattr_name(m_xattr_name_cryptor.value(), name);
310302

311303
auto true_size = m_data_stream->getxattr(wrapped_name.c_str(), value, size);
312304
if (!value)
@@ -370,9 +362,8 @@ void FileBase::setxattr(const char* name, const char* value, size_t size, int fl
370362
if (!name || !value)
371363
throwVFSException(EFAULT);
372364

373-
std::string wrapped_name = m_xattr_name_cryptor
374-
? generic_xattr::encrypt_xattr_name(*m_xattr_name_cryptor, name)
375-
: name;
365+
std::string wrapped_name
366+
= generic_xattr::encrypt_xattr_name(m_xattr_name_cryptor.value(), name);
376367

377368
auto buffer = make_unique_array<byte>(size);
378369
byte* ciphertext = buffer.get();
@@ -403,9 +394,8 @@ void FileBase::setxattr(const char* name, const char* value, size_t size, int fl
403394

404395
void FileBase::removexattr(const char* name)
405396
{
406-
std::string wrapped_name = m_xattr_name_cryptor
407-
? generic_xattr::encrypt_xattr_name(*m_xattr_name_cryptor, name)
408-
: name;
397+
std::string wrapped_name
398+
= generic_xattr::encrypt_xattr_name(m_xattr_name_cryptor.value(), name);
409399

410400
m_data_stream->removexattr(wrapped_name.c_str());
411401
m_meta_stream->removexattr(wrapped_name.c_str());

sources/full_format.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "full_format.h"
2-
#include "apple_xattr_workaround.h"
32
#include "exceptions.h"
43
#include "files.h"
54
#include "logger.h"
@@ -16,6 +15,10 @@
1615
#include <cstdlib>
1716
#include <string>
1817

18+
#if __has_include(<sys/xattr.h>)
19+
#include <sys/xattr.h>
20+
#endif
21+
1922
namespace securefs::full_format
2023
{
2124
void FuseHighLevelOps::initialize(struct fuse_conn_info* conn)
@@ -398,8 +401,6 @@ int FuseHighLevelOps::vlistxattr(const char* path, char* list, size_t size, cons
398401
FileLockGuard fg(**opened);
399402
rc = (**opened).listxattr(list, size);
400403
}
401-
if (is_apple())
402-
securefs::apple_xattr::transform_listxattr_result(list, size);
403404
return rc;
404405
};
405406
int FuseHighLevelOps::vgetxattr(const char* path,
@@ -411,11 +412,6 @@ int FuseHighLevelOps::vgetxattr(const char* path,
411412
{
412413
if (position != 0)
413414
return -EINVAL;
414-
if (is_apple())
415-
{
416-
if (int rc = securefs::apple_xattr::precheck_getxattr(&name); rc <= 0)
417-
return rc;
418-
}
419415
auto opened = open_all(path);
420416
if (!opened)
421417
{
@@ -434,13 +430,11 @@ int FuseHighLevelOps::vsetxattr(const char* path,
434430
{
435431
if (position != 0)
436432
return -EINVAL;
437-
if (is_apple())
438-
{
439-
if (int rc = securefs::apple_xattr::precheck_setxattr(&name, &flags); rc <= 0)
440-
return rc;
441-
}
442433

434+
#if __has_include(<sys/xattr.h>)
443435
flags &= XATTR_CREATE | XATTR_REPLACE;
436+
#endif
437+
444438
auto opened = open_all(path);
445439
if (!opened)
446440
{
@@ -452,13 +446,6 @@ int FuseHighLevelOps::vsetxattr(const char* path,
452446
};
453447
int FuseHighLevelOps::vremovexattr(const char* path, const char* name, const fuse_context* ctx)
454448
{
455-
if (is_apple())
456-
{
457-
if (int rc = securefs::apple_xattr::precheck_removexattr(&name); rc <= 0)
458-
{
459-
return rc;
460-
}
461-
}
462449
auto opened = open_all(path);
463450
if (!opened)
464451
{

sources/fuse_high_level_ops_base.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "fuse_high_level_ops_base.h"
2-
#include "apple_xattr_workaround.h"
32
#include "exceptions.h"
43
#include "fuse2_workaround.h"
54
#include "fuse_tracer_v2.h"

sources/lite_format.cpp

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "lite_format.h"
2-
#include "apple_xattr_workaround.h"
32
#include "crypto.h"
43
#include "exceptions.h"
54
#include "lite_long_name_lookup_table.h"
@@ -1072,23 +1071,13 @@ int FuseHighLevelOps::vutimens(const char* path, const fuse_timespec* ts, const
10721071
int FuseHighLevelOps::vlistxattr(const char* path, char* list, size_t size, const fuse_context* ctx)
10731072
{
10741073
auto encrypted_path = name_trans_->encrypt_full_path(path, nullptr);
1075-
if (!is_apple())
1076-
{
1077-
return generic_xattr::wrapped_listxattr(
1078-
[&](char* buffer, size_t size)
1079-
{ return root_->listxattr(encrypted_path.c_str(), buffer, size); },
1080-
xattr_name_cryptor_.get(),
1081-
list,
1082-
size);
1083-
}
10841074

1085-
int rc = root_->listxattr(name_trans_->encrypt_full_path(path, nullptr).c_str(), list, size);
1086-
if (rc < 0)
1087-
{
1088-
return rc;
1089-
}
1090-
securefs::apple_xattr::transform_listxattr_result(list, size);
1091-
return rc;
1075+
return generic_xattr::wrapped_listxattr(
1076+
[&](char* buffer, size_t size)
1077+
{ return root_->listxattr(encrypted_path.c_str(), buffer, size); },
1078+
xattr_name_cryptor_.get(),
1079+
list,
1080+
size);
10921081
}
10931082
int FuseHighLevelOps::vgetxattr(const char* path,
10941083
const char* name,
@@ -1101,13 +1090,6 @@ int FuseHighLevelOps::vgetxattr(const char* path,
11011090
{
11021091
return -EINVAL;
11031092
}
1104-
if (is_apple())
1105-
{
1106-
if (int rc = securefs::apple_xattr::precheck_getxattr(&name); rc <= 0)
1107-
{
1108-
return rc;
1109-
}
1110-
}
11111093
std::string wrapped_name = generic_xattr::encrypt_xattr_name(xattr_name_cryptor_.get(), name);
11121094

11131095
if (!value)
@@ -1147,13 +1129,6 @@ int FuseHighLevelOps::vsetxattr(const char* path,
11471129
{
11481130
return -EINVAL;
11491131
}
1150-
if (is_apple())
1151-
{
1152-
if (int rc = securefs::apple_xattr::precheck_setxattr(&name, &flags); rc <= 0)
1153-
{
1154-
return rc;
1155-
}
1156-
}
11571132
if (!value || size == 0)
11581133
{
11591134
return 0;
@@ -1170,15 +1145,6 @@ int FuseHighLevelOps::vsetxattr(const char* path,
11701145
}
11711146
int FuseHighLevelOps::vremovexattr(const char* path, const char* name, const fuse_context* ctx)
11721147
{
1173-
if (is_apple())
1174-
{
1175-
int rc = securefs::apple_xattr::precheck_removexattr(&name);
1176-
if (rc <= 0)
1177-
{
1178-
return rc;
1179-
}
1180-
}
1181-
11821148
std::string wrapped_name = generic_xattr::encrypt_xattr_name(xattr_name_cryptor_.get(), name);
11831149

11841150
return root_->removexattr(name_trans_->encrypt_full_path(path, nullptr).c_str(),

0 commit comments

Comments
 (0)