|
3 | 3 | #include "rpc_import_base.h" |
4 | 4 | #include "rpc_calls.h" |
5 | 5 | #include "rpc_operation_request_base.h" |
| 6 | +#include "fs_path_validation.h" |
6 | 7 |
|
7 | 8 | #include <ydb/public/api/protos/ydb_import.pb.h> |
8 | 9 |
|
|
13 | 14 |
|
14 | 15 | #include <library/cpp/regex/pcre/regexp.h> |
15 | 16 |
|
| 17 | +#include <util/folder/path.h> |
16 | 18 | #include <util/generic/ptr.h> |
17 | 19 | #include <util/string/builder.h> |
18 | 20 |
|
| 21 | +#ifdef _linux_ |
| 22 | +#include <sys/vfs.h> |
| 23 | +#include <linux/magic.h> |
| 24 | +#endif |
| 25 | + |
19 | 26 | namespace NKikimr { |
20 | 27 | namespace NGRpcService { |
21 | 28 |
|
@@ -137,14 +144,37 @@ class TImportRPC: public TRpcOperationRequestActor<TDerived, TEvRequest, true>, |
137 | 144 | } |
138 | 145 |
|
139 | 146 | if constexpr (IsFsImport) { |
140 | | - if (!settings.base_path().StartsWith("/")) { |
| 147 | + if (!TFsPath(settings.base_path()).IsAbsolute()) { |
141 | 148 | return this->Reply(StatusIds::BAD_REQUEST, TIssuesIds::DEFAULT_ERROR, |
142 | 149 | "base_path must be an absolute path"); |
143 | 150 | } |
| 151 | + |
| 152 | +#ifdef _linux_ |
| 153 | + struct statfs fsInfo; |
| 154 | + if (statfs(settings.base_path().c_str(), &fsInfo) == 0) { |
| 155 | + if (fsInfo.f_type != NFS_SUPER_MAGIC) { |
| 156 | + return this->Reply(StatusIds::BAD_REQUEST, TIssuesIds::DEFAULT_ERROR, |
| 157 | + "base_path must be on NFS filesystem"); |
| 158 | + } |
| 159 | + } |
| 160 | +#endif |
| 161 | + |
| 162 | + TString error; |
| 163 | + if (!ValidateFsPath(settings.base_path(), "base_path", error)) { |
| 164 | + return this->Reply(StatusIds::BAD_REQUEST, TIssuesIds::DEFAULT_ERROR, error); |
| 165 | + } |
| 166 | + |
144 | 167 | for (const auto& item : settings.items()) { |
145 | 168 | if (item.destination_path().empty() && item.source_path().empty()) { |
146 | 169 | return this->Reply(StatusIds::BAD_REQUEST, TIssuesIds::DEFAULT_ERROR, "Empty item is not allowed"); |
147 | 170 | } |
| 171 | + |
| 172 | + if (!item.source_path().empty()) { |
| 173 | + const auto pathDesc = TStringBuilder() << "source_path for item to \"" << item.destination_path() << "\""; |
| 174 | + if (!ValidateFsPath(item.source_path(), pathDesc, error)) { |
| 175 | + return this->Reply(StatusIds::BAD_REQUEST, TIssuesIds::DEFAULT_ERROR, error); |
| 176 | + } |
| 177 | + } |
148 | 178 | } |
149 | 179 | } |
150 | 180 |
|
|
0 commit comments