[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])
#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"
/* 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'},
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);
#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;
#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);
}
#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)
{
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);
#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);