summaryrefslogtreecommitdiff
path: root/support
diff options
context:
space:
mode:
authorWayne Davison <wayne@opencoder.net>2020-07-17 10:22:27 -0700
committerWayne Davison <wayne@opencoder.net>2020-07-17 10:30:59 -0700
commit7e07a325043453ca2974f199b5cdda5f858b5603 (patch)
tree9fd35b2035b82deab725719cd0b2536c01b1fc4d /support
parentbe11a496bb2fe02d6e5c5780458dd4bcab303615 (diff)
downloadrsync-7e07a325043453ca2974f199b5cdda5f858b5603.tar.gz
Add the `name converter` daemon parameter.
This is based on the long-standing patch but with the protocol changed to just use newlines as delimiters instead of null chars (since names should not contain a newline AND it makes it easier to write a helper script). Lots of other small improvements and a better default value for "numeric ids" when using "use chroot" with "name converter".
Diffstat (limited to 'support')
-rwxr-xr-xsupport/nameconvert50
1 files changed, 50 insertions, 0 deletions
diff --git a/support/nameconvert b/support/nameconvert
new file mode 100755
index 00000000..968fdbe3
--- /dev/null
+++ b/support/nameconvert
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+# This implements a simple protocol to do user & group conversions between
+# names & ids. All input and output consists of simple strings with a
+# terminating newline.
+#
+# The requests can be:
+#
+# uid ID_NUM\n -> NAME\n
+# gid ID_NUM\n -> NAME\n
+# usr NAME\n -> ID_NUM\n
+# grp NAME\n -> ID_NUM\n
+#
+# An unknown ID_NUM or NAME results in an empty return value.
+#
+# This is used by an rsync daemon when configured with the "name converter" and
+# "use chroot = true". While this converter uses real user & group lookups you
+# could change it to use any mapping idiom you'd like.
+
+import sys, argparse, pwd, grp
+
+def main():
+ for line in sys.stdin:
+ try:
+ req, arg = line.rstrip().split(' ', 1)
+ except:
+ req = None
+ try:
+ if req == 'uid':
+ ans = pwd.getpwuid(int(arg)).pw_name
+ elif req == 'gid':
+ ans = grp.getgrgid(int(arg)).gr_name
+ elif req == 'usr':
+ ans = pwd.getpwnam(arg).pw_uid
+ elif req == 'grp':
+ ans = grp.getgrnam(arg).gr_gid
+ else:
+ print("Invalid request", file=sys.stderr)
+ sys.exit(1)
+ except KeyError:
+ ans = ''
+ print(ans, flush=True)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description="Convert users & groups between names & numbers for an rsync daemon.")
+ args = parser.parse_args()
+ main()
+
+# vim: sw=4 et