I use git-send-email but there's issue #104 for this. I'm flexible
enough to let others to use github for merge requests but I don't want
to use it myself. If you have some comments from the patch itself I'm
fully open for them.
On Wed, Apr 16, 2014 at 11:15 AM, Mcgillion, Brian
<brian.mcgillion(a)intel.com> wrote:
Can you provide a link to the gerrit commit id, so it can be reviewed
properly.
Thanks,
Brian
On Wed, Apr 16, 2014 at 7:08 AM, Jarkko Sakkinen
<jarkko.sakkinen(a)linux.intel.com> wrote:
Added option -v/--version for displaying version information
and -h/--help for displaying usage information.
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen(a)linux.intel.com>
---
configure.ac | 1 +
utils/chsmack.c | 14 +++++++++++-
utils/smackaccess.c | 54
++++++++++++++++++++++++++++++++++++++++++----
utils/smackcipso.c | 44 +++++++++++++++++++++++++++++++++++--
utils/smackctl.c | 60
++++++++++++++++++++++++++++++++++++++++++++-------
utils/smackload.c | 55
++++++++++++++++++++++++++++++++++++----------
6 files changed, 202 insertions(+), 26 deletions(-)
diff --git a/configure.ac b/configure.ac
index 6e306c9..3f02ced 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,6 +6,7 @@ AC_INIT([libsmack],
[
https://github.com/smack-team/smack])
AC_CONFIG_SRCDIR([libsmack/libsmack.c])
AC_CONFIG_AUX_DIR([build-aux])
+AC_CONFIG_HEADERS([utils/config.h])
AM_INIT_AUTOMAKE([-Wall -Werror dist-bzip2 foreign])
AC_GNU_SOURCE
AC_CONFIG_MACRO_DIR([m4])
diff --git a/utils/chsmack.c b/utils/chsmack.c
index f72bb56..5320fa5 100644
--- a/utils/chsmack.c
+++ b/utils/chsmack.c
@@ -32,10 +32,13 @@
#include <getopt.h>
#include <errno.h>
#include <libgen.h>
+#include "config.h"
static const char usage[] =
"Usage: %s [options] <path>\n"
"options:\n"
+ " -v --version output version information and exit\n"
+ " -h --help output usage information and exit\n"
" -a --access set/remove "XATTR_NAME_SMACK"\n"
" -e --exec set/remove
"XATTR_NAME_SMACKEXEC"\n"
" -m --mmap set/remove
"XATTR_NAME_SMACKMMAP"\n"
@@ -114,8 +117,10 @@ static int smack_remove_label_for_path(const char
*path,
/* main */
int main(int argc, char *argv[])
{
- static const char shortoptions[] = "a::e::m::tdL";
+ static const char shortoptions[] = "vha::e::m::tdL";
static struct option options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
{"access", optional_argument, 0, 'a'},
{"exec", optional_argument, 0, 'e'},
{"mmap", optional_argument, 0, 'm'},
@@ -185,6 +190,13 @@ int main(int argc, char *argv[])
basename(argv[0]), options[options_map[c]].name);
follow_flag = 1;
break;
+ case 'v':
+ printf("%s (libsmack) version "
PACKAGE_VERSION "\n",
+ basename(argv[0]));
+ exit(0);
+ case 'h':
+ printf(usage, basename(argv[0]));
+ exit(0);
default:
printf(usage, basename(argv[0]));
exit(1);
diff --git a/utils/smackaccess.c b/utils/smackaccess.c
index 726e3f7..69be9fc 100644
--- a/utils/smackaccess.c
+++ b/utils/smackaccess.c
@@ -26,17 +26,63 @@
#include <stdio.h>
#include <stdlib.h>
#include <libgen.h>
+#include <unistd.h>
+#include <getopt.h>
+#include "config.h"
+
+static const char usage[] =
+ "Usage: %s [options] <subject> <object>
<access>\n"
+ "options:\n"
+ " -v --version output version information and exit\n"
+ " -h --help output usage information and exit\n"
+;
+
+static const char short_options[] = "vh";
+
+static struct option options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {NULL, 0, 0, 0}
+};
int main(int argc, char **argv)
{
+ const char *subject;
+ const char *object;
+ const char *access;
int ret;
+ int c;
- if (argc < 4) {
- fprintf(stderr, "Usage: %s <subject> <object>
<access>\n", argv[0]);
- return EXIT_FAILURE;
+ for ( ; ; ) {
+ c = getopt_long(argc, argv, short_options, options,
NULL);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'v':
+ printf("%s (libsmack) version "
PACKAGE_VERSION "\n",
+ basename(argv[0]));
+ exit(0);
+ case 'h':
+ printf(usage, basename(argv[0]));
+ exit(0);
+ default:
+ printf(usage, basename(argv[0]));
+ exit(1);
+ }
+ }
+
+ if ((argc - optind) != 3) {
+ printf(usage, basename(argv[0]));
+ exit(1);
}
- ret = smack_have_access(argv[1], argv[2], argv[3]);
+ subject = argv[optind];
+ object = argv[optind + 1];
+ access = argv[optind + 2];
+
+ ret = smack_have_access(subject, object, access);
if (ret < 0) {
fprintf(stderr,"%s: input values are invalid.\n",
basename(argv[0]));
return EXIT_FAILURE;
diff --git a/utils/smackcipso.c b/utils/smackcipso.c
index f32ea61..9ce65f5 100644
--- a/utils/smackcipso.c
+++ b/utils/smackcipso.c
@@ -23,16 +23,56 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/smack.h>
+#include <getopt.h>
+#include <libgen.h>
+#include "config.h"
+
+static const char usage[] =
+ "Usage: %s [options] <subject> <object>
<access>\n"
+ "options:\n"
+ " -v --version output version information and exit\n"
+ " -h --help output usage information and exit\n"
+;
+
+static const char short_options[] = "vh";
+
+static struct option options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {NULL, 0, 0, 0}
+};
int main(int argc, char **argv)
{
+ int c;
+
+ for ( ; ; ) {
+ c = getopt_long(argc, argv, short_options, options,
NULL);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'v':
+ printf("%s (libsmack) version "
PACKAGE_VERSION "\n",
+ basename(argv[0]));
+ exit(0);
+ case 'h':
+ printf(usage, basename(argv[0]));
+ exit(0);
+ default:
+ printf(usage, basename(argv[0]));
+ exit(1);
+ }
+ }
+
if (!smack_smackfs_path()) {
fprintf(stderr, "SmackFS is not mounted.\n");
exit(1);
}
- if (argc > 2) {
- fprintf(stderr, "Usage: %s <path>\n", argv[0]);
+ if ((argc - optind) > 1) {
+ printf(usage, basename(argv[0]));
exit(1);
}
diff --git a/utils/smackctl.c b/utils/smackctl.c
index 439c233..7e73a51 100644
--- a/utils/smackctl.c
+++ b/utils/smackctl.c
@@ -24,6 +24,25 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <libgen.h>
+#include "config.h"
+
+static const char usage[] =
+ "Usage: %s [options] <subject> <object>
<access>\n"
+ "options:\n"
+ " -v --version output version information and exit\n"
+ " -h --help output usage information and exit\n"
+;
+
+static const char short_options[] = "vh";
+
+static struct option options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {NULL, 0, 0, 0}
+};
static int apply_all(void)
{
@@ -46,21 +65,46 @@ static int apply_all(void)
int main(int argc, char **argv)
{
- const char *tmp = smack_smackfs_path();
- if (argc < 2) {
- fprintf(stderr, "Usage: %s <action>\n", argv[0]);
+ const char *cmd;
+ int c;
+
+ for ( ; ; ) {
+ c = getopt_long(argc, argv, short_options, options,
NULL);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 'v':
+ printf("%s (libsmack) version "
PACKAGE_VERSION "\n",
+ basename(argv[0]));
+ exit(0);
+ case 'h':
+ printf(usage, basename(argv[0]));
+ exit(0);
+ default:
+ printf(usage, basename(argv[0]));
+ exit(1);
+ }
+ }
+
+ if ((argc - optind) != 1) {
+ printf(usage, basename(argv[0]));
exit(1);
}
- if (!strcmp(argv[1], "apply")) {
+ cmd = argv[optind];
+
+ if (!strcmp(cmd, "apply")) {
if (apply_all())
exit(1);
- } else if (!strcmp(argv[1], "clear")) {
+ } else if (!strcmp(cmd, "clear")) {
if (clear())
exit(1);
- } else if (!strcmp(argv[1], "status")) {
- if (tmp)
- printf("SmackFS is mounted to %s.\n", tmp);
+ } else if (!strcmp(cmd, "status")) {
+ if (smack_smackfs_path())
+ printf("SmackFS is mounted to %s.\n",
+ smack_smackfs_path());
else
printf("SmackFS is not mounted.\n");
exit(0);
diff --git a/utils/smackload.c b/utils/smackload.c
index 73e1b72..0316865 100644
--- a/utils/smackload.c
+++ b/utils/smackload.c
@@ -23,33 +23,66 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/smack.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <libgen.h>
+#include "config.h"
-static void usage(const char *bin)
-{
- fprintf(stderr, "Usage: %s [-c] <path>\n", bin);
- exit(1);
-}
+static const char usage[] =
+ "Usage: %s [options] <subject> <object>
<access>\n"
+ "options:\n"
+ " -v --version output version information and exit\n"
+ " -h --help output usage information and exit\n"
+ " -c --clear clear access rules\n"
+;
+
+static const char short_options[] = "vhc";
+
+static struct option options[] = {
+ {"version", no_argument, 0, 'v'},
+ {"help", no_argument, 0, 'h'},
+ {"clear", no_argument, 0, 'c'},
+ {NULL, 0, 0, 0}
+};
int main(int argc, char **argv)
{
int clear = 0;
int c;
- if (!smack_smackfs_path()) {
- fprintf(stderr, "SmackFS is not mounted.\n");
- exit(1);
- }
+ for ( ; ; ) {
+ c = getopt_long(argc, argv, short_options, options,
NULL);
+
+ if (c == -1)
+ break;
- while ((c = getopt(argc, argv, "c")) != -1) {
switch (c) {
case 'c':
clear = 1;
break;
+ case 'v':
+ printf("%s (libsmack) version "
PACKAGE_VERSION "\n",
+ basename(argv[0]));
+ exit(0);
+ case 'h':
+ printf(usage, basename(argv[0]));
+ exit(0);
default:
- usage(argv[0]);
+ printf(usage, basename(argv[0]));
+ exit(1);
}
}
+ if (!smack_smackfs_path()) {
+ fprintf(stderr, "SmackFS is not mounted.\n");
+ exit(1);
+ }
+
+ if ((argc - optind) > 1) {
+ printf(usage, basename(argv[0]));
+ exit(1);
+ }
+
if (optind == argc) {
if (apply_rules(NULL, clear))
exit(1);
--
1.7.9.5
_______________________________________________
SMACK-discuss mailing list
SMACK-discuss(a)lists.01.org
https://lists.01.org/mailman/listinfo/smack-discuss