render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
43fe83
From b76dda6c153e1251de6aa935b85942bb53213470 Mon Sep 17 00:00:00 2001
43fe83
Message-Id: <b76dda6c153e1251de6aa935b85942bb53213470.1377873639.git.jdenemar@redhat.com>
43fe83
From: "Daniel P. Berrange" <berrange@redhat.com>
43fe83
Date: Tue, 13 Aug 2013 15:20:43 +0100
43fe83
Subject: [PATCH] Address missed feedback from review of virt-login-shell
43fe83
43fe83
For https://bugzilla.redhat.com/show_bug.cgi?id=988491
43fe83
43fe83
Address a number of code, style and docs issues identified
43fe83
in review of virt-login-shell after it was merged.
43fe83
43fe83
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
43fe83
(cherry picked from commit a396473494dd099c2a0e6e03af9a9c7406a86108)
43fe83
---
43fe83
 tools/Makefile.am          |  1 -
43fe83
 tools/virt-login-shell.c   | 58 ++++++++++++++++++++++++++++++----------------
43fe83
 tools/virt-login-shell.pod | 30 ++++++++++++++++++------
43fe83
 3 files changed, 61 insertions(+), 28 deletions(-)
43fe83
43fe83
diff --git a/tools/Makefile.am b/tools/Makefile.am
43fe83
index 00c582a..d48883c 100644
43fe83
--- a/tools/Makefile.am
43fe83
+++ b/tools/Makefile.am
43fe83
@@ -134,7 +134,6 @@ virt_host_validate_CFLAGS = \
43fe83
 		$(NULL)
43fe83
 
43fe83
 virt_login_shell_SOURCES =					\
43fe83
-		virt-login-shell.conf				\
43fe83
 		virt-login-shell.c
43fe83
 
43fe83
 virt_login_shell_LDFLAGS = $(COVERAGE_LDFLAGS)
43fe83
diff --git a/tools/virt-login-shell.c b/tools/virt-login-shell.c
43fe83
index b27e44f..1157cd0 100644
43fe83
--- a/tools/virt-login-shell.c
43fe83
+++ b/tools/virt-login-shell.c
43fe83
@@ -41,11 +41,11 @@
43fe83
 #include "vircommand.h"
43fe83
 #define VIR_FROM_THIS VIR_FROM_NONE
43fe83
 
43fe83
-static ssize_t nfdlist = 0;
43fe83
-static int *fdlist = NULL;
43fe83
+static ssize_t nfdlist;
43fe83
+static int *fdlist;
43fe83
 static const char *conf_file = SYSCONFDIR "/libvirt/virt-login-shell.conf";
43fe83
 
43fe83
-static void virLoginShellFini(virConnectPtr conn, virDomainPtr  dom)
43fe83
+static void virLoginShellFini(virConnectPtr conn, virDomainPtr dom)
43fe83
 {
43fe83
     size_t i;
43fe83
 
43fe83
@@ -105,7 +105,7 @@ static int virLoginShellAllowedUser(virConfPtr conf,
43fe83
             }
43fe83
         }
43fe83
     }
43fe83
-    virReportSystemError(EPERM, _("%s not listed as an allowed_users in %s"), name, conf_file);
43fe83
+    virReportSystemError(EPERM, _("%s not matched against 'allowed_users' in %s"), name, conf_file);
43fe83
 cleanup:
43fe83
     VIR_FREE(gname);
43fe83
     return ret;
43fe83
@@ -121,7 +121,7 @@ static char **virLoginShellGetShellArgv(virConfPtr conf)
43fe83
     if (!p)
43fe83
         return virStringSplit("/bin/sh -l", " ", 3);
43fe83
 
43fe83
-    if (p && p->type == VIR_CONF_LIST) {
43fe83
+    if (p->type == VIR_CONF_LIST) {
43fe83
         size_t len;
43fe83
         virConfValuePtr pp;
43fe83
 
43fe83
@@ -139,7 +139,6 @@ static char **virLoginShellGetShellArgv(virConfPtr conf)
43fe83
             if (VIR_STRDUP(shargv[i], pp->str) < 0)
43fe83
                 goto error;
43fe83
         }
43fe83
-        shargv[len] = NULL;
43fe83
     }
43fe83
     return shargv;
43fe83
 error:
43fe83
@@ -155,16 +154,27 @@ static char *progname;
43fe83
 static void
43fe83
 usage(void)
43fe83
 {
43fe83
-    fprintf(stdout, _("\n"
43fe83
-                      "%s is a privileged program that allows non root users \n"
43fe83
-                      "specified in %s to join a Linux container \n"
43fe83
-                      "with a matching user name and launch a shell. \n"
43fe83
-                      "\n%s [options]\n\n"
43fe83
-                      "  options:\n"
43fe83
-                      "    -h | --help             this help:\n\n"), progname, conf_file, progname);
43fe83
+    fprintf(stdout,
43fe83
+            _("\n"
43fe83
+              "Usage:\n"
43fe83
+              "  %s [options]\n\n"
43fe83
+              "Options:\n"
43fe83
+              "  -h | --help            Display program help:\n"
43fe83
+              "  -V | --version         Display program version:\n"
43fe83
+              "\n"
43fe83
+              "libvirt login shell\n"),
43fe83
+            progname);
43fe83
     return;
43fe83
 }
43fe83
 
43fe83
+/* Display version information. */
43fe83
+static void
43fe83
+show_version(void)
43fe83
+{
43fe83
+    printf("%s (%s) %s\n", progname, PACKAGE_NAME, PACKAGE_VERSION);
43fe83
+}
43fe83
+
43fe83
+
43fe83
 int
43fe83
 main(int argc, char **argv)
43fe83
 {
43fe83
@@ -190,6 +200,7 @@ main(int argc, char **argv)
43fe83
 
43fe83
     struct option opt[] = {
43fe83
         {"help", no_argument, NULL, 'h'},
43fe83
+        {"version", optional_argument, NULL, 'V'},
43fe83
         {NULL, 0, NULL, 0}
43fe83
     };
43fe83
     if (virInitialize() < 0) {
43fe83
@@ -214,20 +225,25 @@ main(int argc, char **argv)
43fe83
         return ret;
43fe83
     }
43fe83
 
43fe83
-    /* The only option we support is help
43fe83
-     */
43fe83
-    while ((arg = getopt_long(argc, argv, "h", opt, &longindex)) != -1) {
43fe83
+    while ((arg = getopt_long(argc, argv, "hV", opt, &longindex)) != -1) {
43fe83
         switch (arg) {
43fe83
         case 'h':
43fe83
             usage();
43fe83
             exit(EXIT_SUCCESS);
43fe83
-            break;
43fe83
+
43fe83
+        case 'V':
43fe83
+            show_version();
43fe83
+            exit(EXIT_SUCCESS);
43fe83
+
43fe83
+        case '?':
43fe83
+        default:
43fe83
+            usage();
43fe83
+            exit(EXIT_FAILURE);
43fe83
         }
43fe83
     }
43fe83
 
43fe83
     if (argc > optind) {
43fe83
         virReportSystemError(EINVAL, _("%s takes no options"), progname);
43fe83
-        errno = EINVAL;
43fe83
         goto cleanup;
43fe83
     }
43fe83
 
43fe83
@@ -268,7 +284,9 @@ main(int argc, char **argv)
43fe83
         virErrorPtr last_error;
43fe83
         last_error = virGetLastError();
43fe83
         if (last_error->code != VIR_ERR_OPERATION_INVALID) {
43fe83
-            virReportSystemError(last_error->code,_("Can't create %s container: %s"), name, virGetLastErrorMessage());
43fe83
+            virReportSystemError(last_error->code,
43fe83
+                                 _("Can't create %s container: %s"),
43fe83
+                                 name, last_error->message);
43fe83
             goto cleanup;
43fe83
         }
43fe83
     }
43fe83
@@ -327,7 +345,7 @@ main(int argc, char **argv)
43fe83
             }
43fe83
             if (execv(shargv[0], (char *const*) shargv) < 0) {
43fe83
                 virReportSystemError(errno, _("Unable exec shell %s"), shargv[0]);
43fe83
-                return -errno;
43fe83
+                return EXIT_FAILURE;
43fe83
             }
43fe83
         }
43fe83
         return virProcessWait(ccpid, &status2);
43fe83
diff --git a/tools/virt-login-shell.pod b/tools/virt-login-shell.pod
43fe83
index 0cd35cf..e27d500 100644
43fe83
--- a/tools/virt-login-shell.pod
43fe83
+++ b/tools/virt-login-shell.pod
43fe83
@@ -8,26 +8,42 @@ B<virt-login-shell>
43fe83
 
43fe83
 =head1 DESCRIPTION
43fe83
 
43fe83
-The B<virt-login-shell> program is setuid shell that is used to join
43fe83
-an LXC container that matches the users name.  If the container is not
43fe83
-running virt-login-shell will attempt to start the container.
43fe83
+The B<virt-login-shell> program is a setuid shell that is used to join
43fe83
+an LXC container that matches the user's name.  If the container is not
43fe83
+running, virt-login-shell will attempt to start the container.
43fe83
 virt-sandbox-shell is not allowed to be run by root.  Normal users will get
43fe83
-added to a container that matches their username, if it exists.  And they are
43fe83
+added to a container that matches their username, if it exists, and they are
43fe83
 configured in /etc/libvirt/virt-login-shell.conf.
43fe83
 
43fe83
 The basic structure of most virt-login-shell usage is:
43fe83
 
43fe83
   virt-login-shell
43fe83
 
43fe83
+=head1 OPTIONS
43fe83
+
43fe83
+=over
43fe83
+
43fe83
+=item B<-h, --help>
43fe83
+
43fe83
+Display command line help usage then exit.
43fe83
+
43fe83
+=item B<-V, --version>
43fe83
+
43fe83
+Display version information then exit.
43fe83
+
43fe83
+=back
43fe83
+
43fe83
 =head1 CONFIG
43fe83
 
43fe83
 By default, virt-login-shell will execute the /bin/sh program for the user.
43fe83
-You can modify this behaviour by defining the shell variable in /etc/libvirt/virt-login-shell.conf.
43fe83
+You can modify this behaviour by defining the shell variable in
43fe83
+/etc/libvirt/virt-login-shell.conf.
43fe83
 
43fe83
 eg.  shell = [ "/bin/ksh", "--login"]
43fe83
 
43fe83
-By default no users are allowed to user virt-login-shell, if you want to allow
43fe83
-certain users to use virt-login-shell, you need to modify the allowed_users variable in /etc/libvirt/virt-login-shell.conf.
43fe83
+By default no users are allowed to use virt-login-shell, if you want to allow
43fe83
+certain users to use virt-login-shell, you need to modify the allowed_users
43fe83
+variable in /etc/libvirt/virt-login-shell.conf.
43fe83
 
43fe83
 eg. allowed_users = [ "tom", "dick", "harry" ]
43fe83
 
43fe83
-- 
43fe83
1.8.3.2
43fe83