1 /* 2 Copyright 2021 Northern.tech AS 3 4 This file is part of CFEngine 3 - written and maintained by Northern.tech AS. 5 6 This program is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License as published by the 8 Free Software Foundation; version 3. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 19 To the extent this program is licensed as part of the Enterprise 20 versions of CFEngine, the applicable Commercial Open Source License 21 (COSL) may apply to this file if you as a licensee so wish it. See 22 included file COSL.txt. 23 */ 24 25 #ifndef CFENGINE_PIPES_H 26 #define CFENGINE_PIPES_H 27 28 #include <cf3.defs.h> 29 30 typedef struct 31 { 32 int write_fd; 33 int read_fd; 34 FILE *write_stream; 35 FILE *read_stream; 36 } IOData; 37 38 typedef enum OutputSelect 39 { 40 OUTPUT_SELECT_BOTH, 41 OUTPUT_SELECT_STDOUT, 42 OUTPUT_SELECT_STDERR, 43 } OutputSelect; 44 45 IOData cf_popen_full_duplex(const char *command, bool capture_stderr, bool require_full_path); 46 IOData cf_popen_full_duplex_streams(const char *command, bool capture_stderr, bool require_full_path); 47 int cf_pclose_full_duplex(IOData *data); 48 int cf_pclose_full_duplex_side(int fd); 49 50 FILE *cf_popen(const char *command, const char *type, bool capture_stderr); 51 FILE *cf_popen_select(const char *command, const char *type, OutputSelect output_select); 52 FILE *cf_popensetuid(const char *command, const char *type, uid_t uid, gid_t gid, char *chdirv, char *chrootv, int background); 53 FILE *cf_popen_sh(const char *command, const char *type); 54 FILE *cf_popen_sh_select(const char *command, const char *type, OutputSelect output_select); 55 FILE *cf_popen_shsetuid(const char *command, const char *type, uid_t uid, gid_t gid, char *chdirv, char *chrootv, int background); 56 int cf_pclose(FILE *pp); 57 void cf_pclose_nowait(FILE *pp); 58 bool PipeToPid(pid_t *pid, FILE *pp); 59 bool PipeTypeIsOk(const char *type); 60 61 int PipeIsReadWriteReady(const IOData *io, int timeout_sec); 62 Rlist *PipeReadData(const IOData *io, int pipe_timeout_secs, int pipe_termination_check_secs); 63 ssize_t PipeWrite(IOData *io, const char *data); 64 int PipeWriteData(const char *base_cmd, const char *args, const char *data); 65 int PipeReadWriteData(const char *base_command, const char *args, const char *request, 66 Rlist **response, int pipe_timeout_secs, int pipe_termination_check_secs); 67 68 #ifdef __MINGW32__ 69 FILE *cf_popen_powershell(const char *command, const char *type); 70 FILE *cf_popen_powershell_select(const char *command, const char *type, OutputSelect output_select); 71 FILE *cf_popen_powershell_setuid(const char *command, const char *type, uid_t uid, gid_t gid, char *chdirv, char *chrootv, 72 int background); 73 #endif 74 75 #endif 76