MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / activation_source_open

Function activation_source_open

src/cli/activation_transaction.c:1692–1778  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1690}
1691
1692static bool activation_source_open(const char *path, activation_native_file_t *file_out) {
1693 *file_out = ACTIVATION_INVALID_FILE;
1694 char *directory = NULL;
1695 char *name = NULL;
1696 if (!activation_target_parts(path, &directory, &name)) {
1697 return false;
1698 }
1699#ifdef _WIN32
1700 activation_file_identity_t directory_identity;
1701 activation_file_identity_t expected;
1702 bool exists = false;
1703 bool src_dir_ok = activation_source_directory_secure(directory, &directory_identity);
1704 /* The source (a downloaded release bundle) follows the machine's
1705 * default-owner policy; its bytes are pinned by identity recheck plus the
1706 * staged copy's build-fingerprint validation, so a trusted owner
1707 * (user/Administrators/SYSTEM) is sufficient here. Targets keep the
1708 * exact-current-owner rule. */
1709 bool snapshot_ok =
1710 src_dir_ok && activation_external_snapshot_with_owner(path, false, &exists, &expected);
1711 if (!src_dir_ok || !snapshot_ok || !exists) {
1712 free(directory);
1713 free(name);
1714 return false;
1715 }
1716 wchar_t *wide = activation_utf8_to_wide(path);
1717 if (!wide) {
1718 free(directory);
1719 free(name);
1720 return false;
1721 }
1722 HANDLE file =
1723 CreateFileW(wide, GENERIC_READ | FILE_READ_ATTRIBUTES | READ_CONTROL,
1724 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING,
1725 FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
1726 free(wide);
1727 activation_file_identity_t actual;
1728 activation_file_identity_t directory_now;
1729 bool valid = file != INVALID_HANDLE_VALUE && activation_windows_identity(file, &actual, true) &&
1730 activation_windows_owner_is_trusted(file) && activation_windows_acl_secure(file) &&
1731 activation_identity_equal(&actual, &expected) &&
1732 activation_source_directory_secure(directory, &directory_now) &&
1733 activation_identity_equal(&directory_now, &directory_identity);
1734 if (!valid) {
1735 if (file != INVALID_HANDLE_VALUE) {
1736 (void)CloseHandle(file);
1737 }
1738 free(directory);
1739 free(name);
1740 return false;
1741 }
1742#else
1743 int directory_fd = -1;
1744 activation_file_identity_t directory_identity;
1745 if (!activation_directory_secure(directory, &directory_fd, &directory_identity)) {
1746 free(directory);
1747 free(name);
1748 return false;
1749 }

Callers 1

Tested by

no test coverage detected