summaryrefslogtreecommitdiff
path: root/script/moveto3.py
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2024-04-04 12:13:29 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2024-04-04 12:13:29 +0200
commitf43673af60286ddf97c70035ecd99e817ff846f7 (patch)
treeb59d991daa81fe717b677f9960d3aa0df54350e2 /script/moveto3.py
parent65864b6d92800978de3e33cdfb9752f821c5dbf5 (diff)
introduce moveto3
A program to move a file descriptor to 3 required for qmail-authuser and does not require a shell
Diffstat (limited to 'script/moveto3.py')
-rwxr-xr-xscript/moveto3.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/script/moveto3.py b/script/moveto3.py
new file mode 100755
index 0000000..ae10d63
--- /dev/null
+++ b/script/moveto3.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+import argparse
+import os
+import sys
+
+
+def main():
+ ap = argparse.ArgumentParser()
+ ap.add_argument("-a", default="qmail-authuser", dest="pam")
+ ap.add_argument("fd", type=int)
+ ap.add_argument("prog")
+ ap.add_argument("args", nargs='*')
+
+ vals = ap.parse_args()
+
+ if vals.fd < 3:
+ raise ValueError(f"fd({fd}) must be 3 or greater")
+
+ if vals.fd != 3:
+ os.dup2(vals.fd, 3)
+ os.close(vals.fd)
+
+ os.execvp(vals.pam, [vals.pam, vals.prog] + vals.args)
+
+ raise ValueError("should not be reachable")
+
+
+if __name__ == '__main__':
+ main()