summaryrefslogtreecommitdiffstats
path: root/os_win32/popen.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:14:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:14:45 +0000
commit43e8530e93493bb978c446a2023134bdd4277e50 (patch)
treee8c0d3c0c394b17381f48fb2d288f166b4f22440 /os_win32/popen.h
parentInitial commit. (diff)
downloadsmartmontools-43e8530e93493bb978c446a2023134bdd4277e50.tar.xz
smartmontools-43e8530e93493bb978c446a2023134bdd4277e50.zip
Adding upstream version 7.4.upstream/7.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'os_win32/popen.h')
-rw-r--r--os_win32/popen.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/os_win32/popen.h b/os_win32/popen.h
new file mode 100644
index 0000000..0211587
--- /dev/null
+++ b/os_win32/popen.h
@@ -0,0 +1,66 @@
+/*
+ * os_win32/popen.h
+ *
+ * Home page of code is: https://www.smartmontools.org
+ *
+ * Copyright (C) 2018-21 Christian Franke
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef POPEN_H
+#define POPEN_H
+
+#define POPEN_H_CVSID "$Id: popen.h 5272 2021-12-18 15:55:35Z chrfranke $"
+
+#include <stdio.h>
+
+// MinGW <stdio.h> defines these to _popen/_pclose
+#undef popen
+#undef pclose
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// popen(3) reimplementation for Windows
+//
+// The _popen() from MSVCRT is not useful as it always opens a new
+// console window if parent process has none.
+//
+// Differences to popen(3):
+// - Only modes "r[bt]" are supported
+// - stdin and stderr from parent are not inherited to child process
+// but redirected to null device
+// - Only one child process can be run at a time
+
+FILE * popen(const char * command, const char * mode);
+
+int pclose(FILE * f);
+
+#ifdef __cplusplus
+}
+#endif
+
+// Enhanced version of popen() with ability to modify the access token.
+// If 'restricted' is set, the child process is run with a restricted access
+// token. The local Administrator group and most privileges (all except
+// SeChangeNotifyPrivilege) are removed.
+FILE * popen_as_restr_user(const char * cmd, const char * mode, bool restricted);
+
+// Check whether the access token of the current user could be effectively
+// restricted.
+// Returns false if the current user is the local SYSTEM or Administrator account.
+bool popen_as_restr_check();
+
+// wait(3) macros from <sys/wait.h>
+#ifndef WIFEXITED
+#define WIFEXITED(status) (((status) & 0xff) == 0x00)
+#define WIFSIGNALED(status) (((status) & 0xff) != 0x00)
+#define WIFSTOPPED(status) (0)
+#define WEXITSTATUS(status) ((status) >> 8)
+#define WTERMSIG(status) ((status) & 0xff)
+#define WSTOPSIG(status) (0)
+#endif // WIFEXITED
+
+#endif // POPEN_H