|
cvsdist |
9f53563 |
--- libselinux-1.4/utils/getcon.c.rhat 2003-10-24 16:39:11.000000000 -0400
|
|
cvsdist |
9f53563 |
+++ libselinux-1.4/utils/getcon.c 2003-12-18 14:50:39.000000000 -0500
|
|
cvsdist |
9f53563 |
@@ -2,19 +2,103 @@
|
|
cvsdist |
9f53563 |
#include <stdio.h>
|
|
cvsdist |
9f53563 |
#include <stdlib.h>
|
|
cvsdist |
9f53563 |
#include <selinux/selinux.h>
|
|
cvsdist |
9f53563 |
+#include <selinux/context.h>
|
|
cvsdist |
9f53563 |
+#include <getopt.h>
|
|
cvsdist |
9f53563 |
+
|
|
cvsdist |
9f53563 |
+/* The name the program was run with. */
|
|
cvsdist |
9f53563 |
+static char *program_name;
|
|
cvsdist |
9f53563 |
+static struct option const long_options[] =
|
|
cvsdist |
9f53563 |
+{
|
|
cvsdist |
9f53563 |
+ {"user", no_argument, 0, 'u'},
|
|
cvsdist |
9f53563 |
+ {"role", no_argument, 0, 'r'},
|
|
cvsdist |
9f53563 |
+ {"type", no_argument, 0, 't'},
|
|
cvsdist |
9f53563 |
+ {"help", no_argument, 0, 'h'},
|
|
cvsdist |
9f53563 |
+ {0, 0, 0, 0}
|
|
cvsdist |
9f53563 |
+};
|
|
cvsdist |
9f53563 |
+
|
|
cvsdist |
9f53563 |
+static void
|
|
cvsdist |
9f53563 |
+usage (int status)
|
|
cvsdist |
9f53563 |
+{
|
|
cvsdist |
9f53563 |
+ if (status != 0)
|
|
cvsdist |
9f53563 |
+ fprintf (stderr, "Try `%s --help' for more information.\n",
|
|
cvsdist |
9f53563 |
+ program_name);
|
|
cvsdist |
9f53563 |
+ else
|
|
cvsdist |
9f53563 |
+ {
|
|
cvsdist |
9f53563 |
+ printf ("\
|
|
cvsdist |
9f53563 |
+Usage: %s [ [-u USER] | [-r ROLE] | [-t TYPE] ] \n\
|
|
cvsdist |
9f53563 |
+",
|
|
cvsdist |
9f53563 |
+ program_name);
|
|
cvsdist |
9f53563 |
+ printf ("\
|
|
cvsdist |
9f53563 |
+Get the current security context for this process.\n\
|
|
cvsdist |
9f53563 |
+\n\
|
|
cvsdist |
9f53563 |
+ -u, --user=USER set user USER in the target security context\n\
|
|
cvsdist |
9f53563 |
+ -r, --role=ROLE set role ROLE in the target security context\n\
|
|
cvsdist |
9f53563 |
+ -t, --type=TYPE set type TYPE in the target security context\n\
|
|
cvsdist |
9f53563 |
+ --help display this help and exit\n\
|
|
cvsdist |
9f53563 |
+ --version output version information and exit\n\
|
|
cvsdist |
9f53563 |
+");
|
|
cvsdist |
9f53563 |
+ }
|
|
cvsdist |
9f53563 |
+ exit (status);
|
|
cvsdist |
9f53563 |
+}
|
|
cvsdist |
9f53563 |
|
|
cvsdist |
9f53563 |
int main(int argc __attribute__ ((unused)), char **argv)
|
|
cvsdist |
9f53563 |
{
|
|
cvsdist |
9f53563 |
char *buf;
|
|
cvsdist |
9f53563 |
int rc;
|
|
cvsdist |
9f53563 |
+ int user=0,type=0,role=0,show_help=0;
|
|
cvsdist |
9f53563 |
+ char optc;
|
|
cvsdist |
9f53563 |
+ program_name = argv[0];
|
|
cvsdist |
9f53563 |
+ while ((optc = getopt_long (argc, argv, "hurt", long_options, NULL)) != -1)
|
|
cvsdist |
9f53563 |
+ {
|
|
cvsdist |
9f53563 |
+ switch (optc)
|
|
cvsdist |
9f53563 |
+ {
|
|
cvsdist |
9f53563 |
+ case 0:
|
|
cvsdist |
9f53563 |
+ break;
|
|
cvsdist |
9f53563 |
+ case 'u':
|
|
cvsdist |
9f53563 |
+ if (type || role)
|
|
cvsdist |
9f53563 |
+ usage(1);
|
|
cvsdist |
9f53563 |
+ user = 1;
|
|
cvsdist |
9f53563 |
+ break;
|
|
cvsdist |
9f53563 |
+ case 'r':
|
|
cvsdist |
9f53563 |
+ if (user || type)
|
|
cvsdist |
9f53563 |
+ usage(1);
|
|
cvsdist |
9f53563 |
+ role = 1;
|
|
cvsdist |
9f53563 |
+ break;
|
|
cvsdist |
9f53563 |
+ case 't':
|
|
cvsdist |
9f53563 |
+ if (user || role)
|
|
cvsdist |
9f53563 |
+ usage(1);
|
|
cvsdist |
9f53563 |
+ type=1;
|
|
cvsdist |
9f53563 |
+ break;
|
|
cvsdist |
9f53563 |
+ case 'h':
|
|
cvsdist |
9f53563 |
+ show_help=1;
|
|
cvsdist |
9f53563 |
+ break;
|
|
cvsdist |
9f53563 |
+ default:
|
|
cvsdist |
9f53563 |
+ usage (1);
|
|
cvsdist |
9f53563 |
+ }
|
|
cvsdist |
9f53563 |
+ }
|
|
cvsdist |
9f53563 |
|
|
cvsdist |
9f53563 |
rc = getcon(&buf;;
|
|
cvsdist |
9f53563 |
if (rc < 0) {
|
|
cvsdist |
9f53563 |
fprintf(stderr, "%s: getcon() failed\n", argv[0]);
|
|
cvsdist |
9f53563 |
exit(2);
|
|
cvsdist |
9f53563 |
}
|
|
cvsdist |
9f53563 |
-
|
|
cvsdist |
9f53563 |
- printf("%s\n", buf);
|
|
cvsdist |
9f53563 |
+ if (show_help)
|
|
cvsdist |
9f53563 |
+ usage (0);
|
|
cvsdist |
9f53563 |
+ if (role || user || type) {
|
|
cvsdist |
9f53563 |
+ context_t context=context_new(buf);
|
|
cvsdist |
9f53563 |
+ if (user) {
|
|
cvsdist |
9f53563 |
+ printf("%s",context_user_get(context));
|
|
cvsdist |
9f53563 |
+ }
|
|
cvsdist |
9f53563 |
+ if (role) {
|
|
cvsdist |
9f53563 |
+ printf("%s",context_role_get(context));
|
|
cvsdist |
9f53563 |
+ }
|
|
cvsdist |
9f53563 |
+ if (type) {
|
|
cvsdist |
9f53563 |
+ printf("%s",context_type_get(context));
|
|
cvsdist |
9f53563 |
+ }
|
|
cvsdist |
9f53563 |
+ context_free(context);
|
|
cvsdist |
9f53563 |
+ } else {
|
|
cvsdist |
9f53563 |
+ printf("%s\n", buf);
|
|
cvsdist |
9f53563 |
+ }
|
|
cvsdist |
9f53563 |
freecon(buf);
|
|
cvsdist |
9f53563 |
exit(0);
|
|
cvsdist |
9f53563 |
}
|
|
cvsdist |
9f53563 |
--- libselinux-1.4/utils/Makefile.rhat 2003-12-19 15:37:51.815619330 -0500
|
|
cvsdist |
9f53563 |
+++ libselinux-1.4/utils/Makefile 2003-12-19 15:37:32.014789494 -0500
|
|
cvsdist |
9f53563 |
@@ -1,6 +1,5 @@
|
|
cvsdist |
9f53563 |
# Installation directories.
|
|
cvsdist |
9f53563 |
-PREFIX ?= $(DESTDIR)/usr
|
|
cvsdist |
9f53563 |
-BINDIR ?= $(PREFIX)/bin
|
|
cvsdist |
9f53563 |
+BINDIR ?= $(DESTDIR)/bin
|
|
cvsdist |
9f53563 |
|
|
cvsdist |
9f53563 |
CFLAGS = -Wall
|
|
cvsdist |
9f53563 |
override CFLAGS += -I../include
|