ReactOS 0.4.15-dev-8241-g63935f8
recv.cpp File Reference
#include "shellext.h"
#include <windows.h>
#include <strsafe.h>
#include <stddef.h>
#include <sys/stat.h>
#include <iostream>
#include "recv.h"
#include "resource.h"
#include "crc32c.h"
#include <cpuid.h>
Include dependency graph for recv.cpp:

Go to the source code of this file.

Functions

static __inline uint64_t unix_time_to_win (BTRFS_TIME *t)
 
static void delete_directory (const wstring &dir)
 
static bool check_csum (btrfs_send_command *cmd, uint8_t *data)
 
static DWORD WINAPI global_recv_thread (LPVOID lpParameter)
 
static INT_PTR CALLBACK stub_RecvProgressDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void CALLBACK RecvSubvolGUIW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 
void CALLBACK RecvSubvolW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 

Variables

const string EA_NTACL = "security.NTACL"
 
const string EA_DOSATTRIB = "user.DOSATTRIB"
 
const string EA_REPARSE = "user.reparse"
 
const string EA_EA = "user.EA"
 
const string XATTR_USER = "user."
 

Function Documentation

◆ check_csum()

static bool check_csum ( btrfs_send_command cmd,
uint8_t data 
)
static

Definition at line 1147 of file recv.cpp.

1147 {
1148 uint32_t crc32 = cmd->csum, calc;
1149
1150 cmd->csum = 0;
1151
1153
1154 if (cmd->length > 0)
1155 calc = calc_crc32c(calc, data, cmd->length);
1156
1157 return calc == crc32 ? true : false;
1158}
calc_t calc
Definition: winmain.c:247
crc_func calc_crc32c
Definition: crc32c.c:23
UINT32 uint32_t
Definition: types.h:75
#define crc32(crc, buf, len)
Definition: inflate.c:1081
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
BYTE uint8_t
Definition: msvideo1.c:66
#define true
Definition: stdbool.h:36
Definition: ftp_var.h:139

Referenced by BtrfsRecv::do_recv(), and scrub_extent_dup().

◆ delete_directory()

static void delete_directory ( const wstring &  dir)
static

Definition at line 1117 of file recv.cpp.

1117 {
1118 WIN32_FIND_DATAW fff;
1119
1120 fff_handle h = FindFirstFileW((dir + L"*").c_str(), &fff);
1121
1122 if (h == INVALID_HANDLE_VALUE)
1123 return;
1124
1125 do {
1126 wstring file;
1127
1128 file = fff.cFileName;
1129
1130 if (file != L"." && file != L"..") {
1131 if (fff.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
1132 SetFileAttributesW((dir + file).c_str(), fff.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
1133
1134 if (fff.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1135 if (!(fff.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT))
1136 delete_directory(dir + file + L"\\");
1137 else
1138 RemoveDirectoryW((dir + file).c_str());
1139 } else
1140 DeleteFileW((dir + file).c_str());
1141 }
1142 } while (FindNextFileW(h, &fff));
1143
1144 RemoveDirectoryW(dir.c_str());
1145}
unsigned int dir
Definition: maze.c:112
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:794
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define FILE_ATTRIBUTE_REPARSE_POINT
Definition: ntifs_ex.h:381
#define L(x)
Definition: ntvdm.h:50
static void delete_directory(const wstring &dir)
Definition: recv.cpp:1117
Definition: fci.c:127

Referenced by delete_directory(), and BtrfsRecv::do_recv().

◆ global_recv_thread()

static DWORD WINAPI global_recv_thread ( LPVOID  lpParameter)
static

Definition at line 1457 of file recv.cpp.

1457 {
1458 BtrfsRecv* br = (BtrfsRecv*)lpParameter;
1459
1460 return br->recv_thread();
1461}
Definition: recv.h:35
DWORD recv_thread()
Definition: recv.cpp:1393

Referenced by BtrfsRecv::RecvProgressDlgProc().

◆ RecvSubvolGUIW()

void CALLBACK RecvSubvolGUIW ( HWND  hwnd,
HINSTANCE  hinst,
LPWSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 1548 of file recv.cpp.

1548 {
1549 try {
1554 LUID luid;
1555 ULONG tplen;
1556
1557 set_dpi_aware();
1558
1560 throw last_error(GetLastError());
1561
1562 tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
1563 tp = (TOKEN_PRIVILEGES*)malloc(tplen);
1564 if (!tp)
1566
1567 tp->PrivilegeCount = 3;
1568
1569#ifdef __clang__
1570#pragma clang diagnostic push
1571#pragma clang diagnostic ignored "-Warray-bounds"
1572#endif // __clang__
1573
1574 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid)) {
1575 free(tp);
1576 throw last_error(GetLastError());
1577 }
1578
1579 tp->Privileges[0].Luid = luid;
1580 tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1581
1582 if (!LookupPrivilegeValueW(nullptr, L"SeSecurityPrivilege", &luid)) {
1583 free(tp);
1584 throw last_error(GetLastError());
1585 }
1586
1587 tp->Privileges[1].Luid = luid;
1588 tp->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;
1589
1590 if (!LookupPrivilegeValueW(nullptr, L"SeRestorePrivilege", &luid)) {
1591 free(tp);
1592 throw last_error(GetLastError());
1593 }
1594
1595 tp->Privileges[2].Luid = luid;
1596 tp->Privileges[2].Attributes = SE_PRIVILEGE_ENABLED;
1597
1598 if (!AdjustTokenPrivileges(token, false, tp, tplen, nullptr, nullptr)) {
1599 free(tp);
1600 throw last_error(GetLastError());
1601 }
1602
1603#ifdef __clang__
1604 #pragma clang diagnostic pop
1605#endif // __clang__
1606
1607 file[0] = 0;
1608
1609 memset(&ofn, 0, sizeof(OPENFILENAMEW));
1610 ofn.lStructSize = sizeof(OPENFILENAMEW);
1611 ofn.hwndOwner = hwnd;
1613 ofn.lpstrFile = file;
1614 ofn.nMaxFile = sizeof(file) / sizeof(WCHAR);
1616
1617 if (GetOpenFileNameW(&ofn)) {
1619
1620 recv.Open(hwnd, file, lpszCmdLine, false);
1621 }
1622
1623 free(tp);
1624 } catch (const exception& e) {
1625 error_message(hwnd, e.what());
1626 }
1627}
#define IDS_OUT_OF_MEMORY
Definition: resource.h:5
#define OFN_EXPLORER
Definition: commdlg.h:104
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
struct tagOFNW OPENFILENAMEW
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
void set_dpi_aware()
Definition: main.cpp:50
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4736
#define GetCurrentProcess()
Definition: compat.h:759
#define MAX_PATH
Definition: compat.h:34
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
#define e
Definition: ke_i.h:82
#define offsetof(TYPE, MEMBER)
#define memset(x, y, z)
Definition: compat.h:39
OPENFILENAME ofn
Definition: sndrec32.cpp:56
HWND hwndOwner
Definition: commdlg.h:330
HINSTANCE hInstance
Definition: commdlg.h:331
LPSTR lpstrFile
Definition: commdlg.h:336
DWORD Flags
Definition: commdlg.h:342
DWORD lStructSize
Definition: commdlg.h:329
DWORD nMaxFile
Definition: commdlg.h:337
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:17
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_QUERY
Definition: setypes.h:928
struct _LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ RecvSubvolW()

void CALLBACK RecvSubvolW ( HWND  hwnd,
HINSTANCE  hinst,
LPWSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 1629 of file recv.cpp.

1629 {
1630 try {
1632
1633 command_line_to_args(lpszCmdLine, args);
1634
1635 if (args.size() >= 2) {
1638 ULONG tplen;
1639 LUID luid;
1640
1642 return;
1643
1644 tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
1645 tp = (TOKEN_PRIVILEGES*)malloc(tplen);
1646 if (!tp)
1647 return;
1648
1649 tp->PrivilegeCount = 3;
1650
1651#ifdef __clang__
1652#pragma clang diagnostic push
1653#pragma clang diagnostic ignored "-Warray-bounds"
1654#endif // __clang__
1655
1656 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid)) {
1657 free(tp);
1658 return;
1659 }
1660
1661 tp->Privileges[0].Luid = luid;
1662 tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1663
1664 if (!LookupPrivilegeValueW(nullptr, L"SeSecurityPrivilege", &luid)) {
1665 free(tp);
1666 return;
1667 }
1668
1669 tp->Privileges[1].Luid = luid;
1670 tp->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;
1671
1672 if (!LookupPrivilegeValueW(nullptr, L"SeRestorePrivilege", &luid)) {
1673 free(tp);
1674 return;
1675 }
1676
1677 tp->Privileges[2].Luid = luid;
1678 tp->Privileges[2].Attributes = SE_PRIVILEGE_ENABLED;
1679
1680#ifdef __clang__
1681#pragma clang diagnostic pop
1682#endif // __clang__
1683
1684 if (!AdjustTokenPrivileges(token, false, tp, tplen, nullptr, nullptr)) {
1685 free(tp);
1686 return;
1687 }
1688
1689 free(tp);
1690
1691 BtrfsRecv br;
1692 br.Open(nullptr, args[0], args[1], true);
1693 }
1694 } catch (const exception& e) {
1695 cerr << "Error: " << e.what() << endl;
1696 }
1697}
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
void Open(HWND hwnd, const wstring &file, const wstring &path, bool quiet)
Definition: recv.cpp:1531
void command_line_to_args(LPWSTR cmdline, vector< wstring > &args)
Definition: main.cpp:645
#define cerr
Definition: iostream.cpp:39
Definition: match.c:390

◆ stub_RecvProgressDlgProc()

static INT_PTR CALLBACK stub_RecvProgressDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1515 of file recv.cpp.

1515 {
1516 BtrfsRecv* br;
1517
1518 if (uMsg == WM_INITDIALOG) {
1520 br = (BtrfsRecv*)lParam;
1521 } else {
1522 br = (BtrfsRecv*)GetWindowLongPtrW(hwndDlg, GWLP_USERDATA);
1523 }
1524
1525 if (br)
1526 return br->RecvProgressDlgProc(hwndDlg, uMsg, wParam, lParam);
1527 else
1528 return false;
1529}
INT_PTR CALLBACK RecvProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: recv.cpp:1463
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GWLP_USERDATA
Definition: treelist.c:63
#define GetWindowLongPtrW
Definition: winuser.h:4829
#define WM_INITDIALOG
Definition: winuser.h:1739
#define SetWindowLongPtrW
Definition: winuser.h:5355

Referenced by BtrfsRecv::Open().

◆ unix_time_to_win()

static __inline uint64_t unix_time_to_win ( BTRFS_TIME t)
static

Definition at line 1070 of file recv.cpp.

1070 {
1071 return (t->seconds * 10000000) + (t->nanoseconds / 100) + 116444736000000000;
1072}
GLdouble GLdouble t
Definition: gl.h:2047

Referenced by _Function_class_(), BtrfsRecv::cmd_utimes(), fill_in_file_basic_information(), fill_in_file_network_open_information(), fill_in_file_stat_information(), fill_in_file_stat_lx_information(), and query_dir_item().

Variable Documentation

◆ EA_DOSATTRIB

const string EA_DOSATTRIB = "user.DOSATTRIB"

Definition at line 40 of file recv.cpp.

◆ EA_EA

const string EA_EA = "user.EA"

Definition at line 42 of file recv.cpp.

◆ EA_NTACL

const string EA_NTACL = "security.NTACL"

Definition at line 39 of file recv.cpp.

◆ EA_REPARSE

const string EA_REPARSE = "user.reparse"

Definition at line 41 of file recv.cpp.

◆ XATTR_USER

const string XATTR_USER = "user."

Definition at line 43 of file recv.cpp.

Referenced by BtrfsRecv::cmd_removexattr(), and BtrfsRecv::cmd_setxattr().