1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef CONTRIB_LIBXLS_SANDBOXED_H_ 16 #define CONTRIB_LIBXLS_SANDBOXED_H_ 17 18 #include <libgen.h> 19 #include <syscall.h> 20 21 #include <memory> 22 23 #include "sapi_libxls.sapi.h" // NOLINT(build/include) 24 25 class LibxlsSapiSandbox : public LibxlsSandbox { 26 public: LibxlsSapiSandbox(std::string filename)27 explicit LibxlsSapiSandbox(std::string filename) 28 : filename_(std::move(filename)) {} 29 ModifyPolicy(sandbox2::PolicyBuilder *)30 std::unique_ptr<sandbox2::Policy> ModifyPolicy( 31 sandbox2::PolicyBuilder*) override { 32 return sandbox2::PolicyBuilder() 33 .AllowDynamicStartup() 34 .AllowOpen() 35 .AllowRead() 36 .AllowWrite() 37 .AllowSystemMalloc() 38 .AllowExit() 39 .AllowSyscall(__NR_recvmsg) 40 .AddFile(filename_) 41 .BuildOrDie(); 42 } 43 44 private: 45 std::string filename_; 46 }; 47 48 #endif // CONTRIB_LIBXLS_SANDBOXED_H_ 49