]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
CLI: ability to change file ownership 26760/head
authorSébastien Han <seb@redhat.com>
Mon, 18 Feb 2019 18:17:23 +0000 (19:17 +0100)
committerPrashant D <pdhange@redhat.com>
Tue, 5 Mar 2019 01:53:55 +0000 (20:53 -0500)
When creating/fetching key it's nice to have the ability to change the
ownership of the created file.

This commit adds the '--setuser' and 'setgroup' which respectively apply
the desired owner and group to a file user when '--output' is passed.

Closes: https://tracker.ceph.com/issues/38370
Signed-off-by: Sébastien Han <seb@redhat.com>
(cherry picked from commit 0e26090960213ef911cfc7bfcdf2925ddf1b268f)

doc/man/8/ceph.rst
src/ceph.in

index 7b7ae93448ce229279183abd06be98a76c296e2d..d34467e83b9de4e65f9083532f05a50b33669ce2 100644 (file)
@@ -1446,6 +1446,16 @@ Options
    reply to outfile.  Only specific monitor commands (e.g. osd getmap)
    return a payload.
 
+.. option:: --setuser user
+
+   will apply the appropriate user ownership to the file specified by
+   the option '-o'.
+
+.. option:: --setgroup group
+
+   will apply the appropriate group ownership to the file specified by
+   the option '-o'.
+
 .. option:: -c ceph.conf, --conf=ceph.conf
 
    Use ceph.conf configuration file instead of the default
index 6d0b6e7d97f8c2290f4f256c2168dafc8bbe4eac..81a12a315a1c587c02778993b8368416c1228d43 100755 (executable)
@@ -22,7 +22,9 @@ Foundation.  See file COPYING.
 from __future__ import print_function
 from time import sleep
 import codecs
+import grp
 import os
+import pwd
 import sys
 import subprocess
 import time
@@ -273,7 +275,10 @@ def parse_cmdargs(args=None, target=''):
                         help='input file, or "-" for stdin')
     parser.add_argument('-o', '--out-file', dest='output_file',
                         help='output file, or "-" for stdout')
-
+    parser.add_argument('--setuser', dest='setuser',
+                        help='set user file permission')
+    parser.add_argument('--setgroup', dest='setgroup',
+                        help='set group file permission')
     parser.add_argument('--id', '--user', dest='client_id',
                         help='client id for authentication')
     parser.add_argument('--name', '-n', dest='client_name',
@@ -1086,6 +1091,20 @@ def main():
         except Exception as e:
             print('Can\'t open output file {0}: {1}'.format(parsed_args.output_file, e), file=sys.stderr)
             return 1
+        if parsed_args.setuser:
+            try:
+                ownerid = pwd.getpwnam(parsed_args.setuser).pw_uid
+                os.fchown(outf.fileno(), ownerid, -1)
+            except OSError as e:
+                print('Failed to change user ownership of {0} to {1}: {2}'.format(outf, parsed_args.setuser, e))
+                return 1
+        if parsed_args.setgroup:
+            try:
+                groupid = grp.getgrnam(parsed_args.setgroup).gr_gid
+                os.fchown(outf.fileno(), -1, groupid)
+            except OSError as e:
+                print('Failed to change group ownership of {0} to {1}: {2}'.format(outf, parsed_args.setgroup, e))
+                return 1
 
     # -s behaves like a command (ceph status).
     if parsed_args.status: