1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal 2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling 3 // Copyright (c) 2009 Boris Schaeling 4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling 5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling 6 // Copyright (c) 2016 Klemens D. Morgenstern 7 // 8 // Distributed under the Boost Software License, Version 1.0. (See accompanying 9 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 10 11 #ifndef BOOST_PROCESS_SHELL_PATH_HPP 12 #define BOOST_PROCESS_SHELL_PATH_HPP 13 14 #include <boost/process/detail/config.hpp> 15 #include <boost/process/detail/traits/wchar_t.hpp> 16 17 #if defined(BOOST_POSIX_API) 18 #include <boost/process/detail/posix/shell_path.hpp> 19 #elif defined(BOOST_WINDOWS_API) 20 #include <boost/process/detail/windows/shell_path.hpp> 21 #endif 22 23 /** \file boost/process/shell.hpp 24 * 25 * Header which provides the shell property. This provides the 26 * property to launch a process through the system shell. 27 * It also allows the user to obtain the shell-path via shell(). 28 \xmlonly 29 <programlisting> 30 namespace boost { 31 namespace process { 32 <emphasis>unspecified</emphasis> <globalname alt="boost::process::shell">shell</globalname>; 33 } 34 } 35 </programlisting> 36 \endxmlonly 37 38 */ 39 40 namespace boost { namespace process { namespace detail { 41 42 43 struct shell_ 44 { shell_boost::process::detail::shell_45 constexpr shell_() {} 46 operator ()boost::process::detail::shell_47 boost::filesystem::path operator()() const 48 { 49 return boost::process::detail::api::shell_path(); 50 } operator ()boost::process::detail::shell_51 boost::filesystem::path operator()(std::error_code & ec) const noexcept 52 { 53 return boost::process::detail::api::shell_path(ec); 54 } 55 }; 56 57 template<> 58 struct is_wchar_t<shell_> : is_wchar_t<boost::filesystem::path> 59 { 60 }; 61 62 } 63 /** 64 The shell property enables to launch a program through the shell of the system. 65 66 \code{.cpp} 67 system("gcc", shell); 68 \endcode 69 70 The shell argument goes without any expression. The operator() is overloaded, to 71 obtain the path of the system shell. 72 73 \code{.cpp} 74 auto shell_cmd = shell(); 75 //avoid exceptions 76 std::error_code ec; 77 shell_cmd = shell(ec); 78 \endcode 79 80 \attention Launching through the shell will NOT provide proper error handling, i.e. 81 you will get an error via the return code. 82 83 \attention Executing shell commands that incorporate unsanitized input from an untrusted source makes a program vulnerable to shell injection, a serious security flaw which can result in arbitrary command execution. For this reason, the use of `shell` is strongly discouraged in cases where the command string is constructed from external input: 84 85 */ 86 constexpr ::boost::process::detail::shell_ shell; 87 88 }} 89 90 91 92 #endif 93