ReactOS  0.4.15-dev-4616-g17e0e44
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 1144 of file recv.cpp.

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

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

◆ delete_directory()

static void delete_directory ( const wstring &  dir)
static

Definition at line 1114 of file recv.cpp.

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

Referenced by BtrfsRecv::do_recv().

◆ global_recv_thread()

static DWORD WINAPI global_recv_thread ( LPVOID  lpParameter)
static

Definition at line 1454 of file recv.cpp.

1454  {
1455  BtrfsRecv* br = (BtrfsRecv*)lpParameter;
1456 
1457  return br->recv_thread();
1458 }
Definition: recv.h:35
DWORD recv_thread()
Definition: recv.cpp:1390

Referenced by BtrfsRecv::RecvProgressDlgProc().

◆ RecvSubvolGUIW()

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

Definition at line 1545 of file recv.cpp.

1545  {
1546  try {
1548  WCHAR file[MAX_PATH];
1549  win_handle token;
1551  LUID luid;
1552  ULONG tplen;
1553 
1554  set_dpi_aware();
1555 
1557  throw last_error(GetLastError());
1558 
1559  tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
1560  tp = (TOKEN_PRIVILEGES*)malloc(tplen);
1561  if (!tp)
1563 
1564  tp->PrivilegeCount = 3;
1565 
1566 #ifdef __clang__
1567 #pragma clang diagnostic push
1568 #pragma clang diagnostic ignored "-Warray-bounds"
1569 #endif // __clang__
1570 
1571  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid)) {
1572  free(tp);
1573  throw last_error(GetLastError());
1574  }
1575 
1576  tp->Privileges[0].Luid = luid;
1577  tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1578 
1579  if (!LookupPrivilegeValueW(nullptr, L"SeSecurityPrivilege", &luid)) {
1580  free(tp);
1581  throw last_error(GetLastError());
1582  }
1583 
1584  tp->Privileges[1].Luid = luid;
1585  tp->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;
1586 
1587  if (!LookupPrivilegeValueW(nullptr, L"SeRestorePrivilege", &luid)) {
1588  free(tp);
1589  throw last_error(GetLastError());
1590  }
1591 
1592  tp->Privileges[2].Luid = luid;
1593  tp->Privileges[2].Attributes = SE_PRIVILEGE_ENABLED;
1594 
1595  if (!AdjustTokenPrivileges(token, false, tp, tplen, nullptr, nullptr)) {
1596  free(tp);
1597  throw last_error(GetLastError());
1598  }
1599 
1600 #ifdef __clang__
1601  #pragma clang diagnostic pop
1602 #endif // __clang__
1603 
1604  file[0] = 0;
1605 
1606  memset(&ofn, 0, sizeof(OPENFILENAMEW));
1607  ofn.lStructSize = sizeof(OPENFILENAMEW);
1608  ofn.hwndOwner = hwnd;
1609  ofn.hInstance = module;
1610  ofn.lpstrFile = file;
1611  ofn.nMaxFile = sizeof(file) / sizeof(WCHAR);
1613 
1614  if (GetOpenFileNameW(&ofn)) {
1615  BtrfsRecv recv;
1616 
1617  recv.Open(hwnd, file, lpszCmdLine, false);
1618  }
1619 
1620  free(tp);
1621  } catch (const exception& e) {
1622  error_message(hwnd, e.what());
1623  }
1624 }
#define OFN_FILEMUSTEXIST
Definition: commdlg.h:106
#define IDS_OUT_OF_MEMORY
Definition: resource.h:5
#define OFN_EXPLORER
Definition: commdlg.h:104
HMODULE module
Definition: main.cpp:47
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
Definition: recv.h:35
HWND hwndOwner
Definition: commdlg.h:330
#define free
Definition: debug_ros.c:5
struct _LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES
OPENFILENAME ofn
Definition: main.cpp:37
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
DWORD nMaxFile
Definition: commdlg.h:337
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define L(x)
Definition: ntvdm.h:50
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
#define e
Definition: ke_i.h:82
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
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
Definition: filedlg.c:4677
#define offsetof(TYPE, MEMBER)
HINSTANCE hInstance
Definition: commdlg.h:331
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2965
#define TOKEN_QUERY
Definition: setypes.h:924
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
DWORD lStructSize
Definition: commdlg.h:329
const char file[]
Definition: icontest.c:11
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:13
struct tagOFNW OPENFILENAMEW
#define OFN_HIDEREADONLY
Definition: commdlg.h:107
#define GetCurrentProcess()
Definition: compat.h:618
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
LPSTR lpstrFile
Definition: commdlg.h:336
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
#define memset(x, y, z)
Definition: compat.h:39
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:926
void set_dpi_aware()
Definition: main.cpp:50
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
DWORD Flags
Definition: commdlg.h:342
Definition: fci.c:126

◆ RecvSubvolW()

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

Definition at line 1626 of file recv.cpp.

1626  {
1627  try {
1629 
1630  command_line_to_args(lpszCmdLine, args);
1631 
1632  if (args.size() >= 2) {
1633  win_handle token;
1635  ULONG tplen;
1636  LUID luid;
1637 
1639  return;
1640 
1641  tplen = offsetof(TOKEN_PRIVILEGES, Privileges[0]) + (3 * sizeof(LUID_AND_ATTRIBUTES));
1642  tp = (TOKEN_PRIVILEGES*)malloc(tplen);
1643  if (!tp)
1644  return;
1645 
1646  tp->PrivilegeCount = 3;
1647 
1648 #ifdef __clang__
1649 #pragma clang diagnostic push
1650 #pragma clang diagnostic ignored "-Warray-bounds"
1651 #endif // __clang__
1652 
1653  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid)) {
1654  free(tp);
1655  return;
1656  }
1657 
1658  tp->Privileges[0].Luid = luid;
1659  tp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1660 
1661  if (!LookupPrivilegeValueW(nullptr, L"SeSecurityPrivilege", &luid)) {
1662  free(tp);
1663  return;
1664  }
1665 
1666  tp->Privileges[1].Luid = luid;
1667  tp->Privileges[1].Attributes = SE_PRIVILEGE_ENABLED;
1668 
1669  if (!LookupPrivilegeValueW(nullptr, L"SeRestorePrivilege", &luid)) {
1670  free(tp);
1671  return;
1672  }
1673 
1674  tp->Privileges[2].Luid = luid;
1675  tp->Privileges[2].Attributes = SE_PRIVILEGE_ENABLED;
1676 
1677 #ifdef __clang__
1678 #pragma clang diagnostic pop
1679 #endif // __clang__
1680 
1681  if (!AdjustTokenPrivileges(token, false, tp, tplen, nullptr, nullptr)) {
1682  free(tp);
1683  return;
1684  }
1685 
1686  free(tp);
1687 
1688  BtrfsRecv br;
1689  br.Open(nullptr, args[0], args[1], true);
1690  }
1691  } catch (const exception& e) {
1692  cerr << "Error: " << e.what() << endl;
1693  }
1694 }
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
#define args
Definition: format.c:66
Definition: recv.h:35
#define free
Definition: debug_ros.c:5
struct _LUID_AND_ATTRIBUTES LUID_AND_ATTRIBUTES
Definition: match.c:390
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define L(x)
Definition: ntvdm.h:50
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
#define e
Definition: ke_i.h:82
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 offsetof(TYPE, MEMBER)
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2965
#define TOKEN_QUERY
Definition: setypes.h:924
_STLP_DECLSPEC _Stl_aligned_buffer< ostream > cerr
Definition: iostream.cpp:102
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:13
void Open(HWND hwnd, const wstring &file, const wstring &path, bool quiet)
Definition: recv.cpp:1528
#define GetCurrentProcess()
Definition: compat.h:618
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
void command_line_to_args(LPWSTR cmdline, vector< wstring > &args)
Definition: main.cpp:645
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:926

◆ stub_RecvProgressDlgProc()

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

Definition at line 1512 of file recv.cpp.

1512  {
1513  BtrfsRecv* br;
1514 
1515  if (uMsg == WM_INITDIALOG) {
1517  br = (BtrfsRecv*)lParam;
1518  } else {
1519  br = (BtrfsRecv*)GetWindowLongPtrW(hwndDlg, GWLP_USERDATA);
1520  }
1521 
1522  if (br)
1523  return br->RecvProgressDlgProc(hwndDlg, uMsg, wParam, lParam);
1524  else
1525  return false;
1526 }
Definition: recv.h:35
#define GetWindowLongPtrW
Definition: winuser.h:4809
WPARAM wParam
Definition: combotst.c:138
#define GWLP_USERDATA
Definition: treelist.c:63
INT_PTR CALLBACK RecvProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: recv.cpp:1460
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define SetWindowLongPtrW
Definition: winuser.h:5326
#define WM_INITDIALOG
Definition: winuser.h:1726
LPARAM lParam
Definition: combotst.c:139

Referenced by BtrfsRecv::Open().

◆ unix_time_to_win()

static __inline uint64_t unix_time_to_win ( BTRFS_TIME t)
static

Definition at line 1067 of file recv.cpp.

1067  {
1068  return (t->seconds * 10000000) + (t->nanoseconds / 100) + 116444736000000000;
1069 }
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

◆ EA_EA

◆ EA_NTACL

const string EA_NTACL = "security.NTACL"

◆ EA_REPARSE

const string EA_REPARSE = "user.reparse"

◆ XATTR_USER

const string XATTR_USER = "user."

Definition at line 40 of file recv.cpp.

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