05bd408
Binary files nsalibselinux/debugsources.list and libselinux-1.33.3/debugsources.list differ
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/include/selinux/selinux.h libselinux-1.33.3/include/selinux/selinux.h
e6bab37
--- nsalibselinux/include/selinux/selinux.h	2006-11-16 17:15:18.000000000 -0500
e3bd599
+++ libselinux-1.33.3/include/selinux/selinux.h	2007-01-09 09:49:51.000000000 -0500
e6bab37
@@ -406,6 +406,7 @@
e6bab37
 	extern const char *selinux_homedir_context_path(void);
e6bab37
 	extern const char *selinux_media_context_path(void);
e6bab37
 	extern const char *selinux_contexts_path(void);
e6bab37
+	extern const char *selinux_securetty_context_path(void);
e6bab37
 	extern const char *selinux_booleans_path(void);
e6bab37
 	extern const char *selinux_customizable_types_path(void);
e6bab37
 	extern const char *selinux_users_path(void);
e3bd599
@@ -413,12 +414,15 @@
e6bab37
 	extern const char *selinux_translations_path(void);
e6bab37
 	extern const char *selinux_netfilter_context_path(void);
e6bab37
 	extern const char *selinux_path(void);
e6bab37
-
e6bab37
 /* Check a permission in the passwd class.
e6bab37
    Return 0 if granted or -1 otherwise. */
e6bab37
 	extern int selinux_check_passwd_access(access_vector_t requested);
e6bab37
 	extern int checkPasswdAccess(access_vector_t requested);
dbfbfbe
 
e6bab37
+/* Check if the tty_context is defined as a securetty
e6bab37
+   Return 1 if secure, 0 if not, or -1 if otherwise. */
e3bd599
+	extern int selinux_check_securetty_context(security_context_t
e3bd599
+						   tty_context);
e6bab37
 /* Set the path to the selinuxfs mount point explicitly.
e6bab37
    Normally, this is determined automatically during libselinux 
e6bab37
    initialization, but this is not always possible, e.g. for /sbin/init
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/man/man3/selinux_binary_policy_path.3 libselinux-1.33.3/man/man3/selinux_binary_policy_path.3
e6bab37
--- nsalibselinux/man/man3/selinux_binary_policy_path.3	2006-11-16 17:15:30.000000000 -0500
e3bd599
+++ libselinux-1.33.3/man/man3/selinux_binary_policy_path.3	2007-01-09 09:49:51.000000000 -0500
e6bab37
@@ -27,6 +27,8 @@
e6bab37
 .br
e6bab37
 extern const char *selinux_media_context_path(void);
e6bab37
 .br
e6bab37
+extern const char *selinux_securetty_context_path(void);
e6bab37
+.br
e6bab37
 extern const char *selinux_contexts_path(void);
e6bab37
 .br
e6bab37
 extern const char *selinux_booleans_path(void);
e6bab37
@@ -56,6 +58,8 @@
e6bab37
 .sp
e6bab37
 selinux_contexts_path() - directory containing all of the context configuration files
e6bab37
 .sp
e6bab37
+selinux_securetty_context_path() - defines terminal contexts for securetty
e6bab37
+.sp
e6bab37
 selinux_booleans_path() - initial policy boolean settings
e6bab37
 
e6bab37
 .SH AUTHOR	
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/man/man3/selinux_check_securetty_context.3 libselinux-1.33.3/man/man3/selinux_check_securetty_context.3
e6bab37
--- nsalibselinux/man/man3/selinux_check_securetty_context.3	1969-12-31 19:00:00.000000000 -0500
e3bd599
+++ libselinux-1.33.3/man/man3/selinux_check_securetty_context.3	2007-01-09 09:49:51.000000000 -0500
e6bab37
@@ -0,0 +1,13 @@
e6bab37
+.TH "selinux_check_securetty_context" "3" "1 January 2007" "dwalsh@redhat.com" "SE Linux API documentation"
e6bab37
+.SH "NAME"
e6bab37
+selinux_check_securetty_context \- check whether a tty security context is defined as a securetty context
e6bab37
+.SH "SYNOPSIS"
e6bab37
+.B #include <selinux/selinux.h>
e6bab37
+.sp
e6bab37
+.BI "int selinux_check_securetty_context(security_context_t "tty_context );
e6bab37
+
e6bab37
+.SH "DESCRIPTION"
e6bab37
+.B selinux_check_securetty_context
e6bab37
+returns 1 if tty_context is a securetty context
e6bab37
+returns 0 if tty_context is a not a securetty context
e6bab37
+returns -1 on error.
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/man/man3/selinux_securetty_context_path.3 libselinux-1.33.3/man/man3/selinux_securetty_context_path.3
e6bab37
--- nsalibselinux/man/man3/selinux_securetty_context_path.3	1969-12-31 19:00:00.000000000 -0500
e3bd599
+++ libselinux-1.33.3/man/man3/selinux_securetty_context_path.3	2007-01-09 09:49:51.000000000 -0500
e6bab37
@@ -0,0 +1 @@
e6bab37
+.so man3/selinux_binary_policy_path.3
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/src/file_path_suffixes.h libselinux-1.33.3/src/file_path_suffixes.h
e6bab37
--- nsalibselinux/src/file_path_suffixes.h	2006-11-16 17:15:25.000000000 -0500
e3bd599
+++ libselinux-1.33.3/src/file_path_suffixes.h	2007-01-09 09:49:51.000000000 -0500
e6bab37
@@ -7,6 +7,7 @@
e6bab37
     S_(USER_CONTEXTS, "/contexts/users/")
e6bab37
     S_(FAILSAFE_CONTEXT, "/contexts/failsafe_context")
e6bab37
     S_(DEFAULT_TYPE, "/contexts/default_type")
e6bab37
+    S_(SECURETTY_CONTEXTS, "/contexts/securetty_contexts")
e6bab37
     S_(BOOLEANS, "/booleans")
e6bab37
     S_(MEDIA_CONTEXTS, "/contexts/files/media")
e6bab37
     S_(REMOVABLE_CONTEXT, "/contexts/removable_context")
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_check_securetty_context.c libselinux-1.33.3/src/selinux_check_securetty_context.c
e6bab37
--- nsalibselinux/src/selinux_check_securetty_context.c	1969-12-31 19:00:00.000000000 -0500
e3bd599
+++ libselinux-1.33.3/src/selinux_check_securetty_context.c	2007-01-09 10:00:58.000000000 -0500
e3bd599
@@ -0,0 +1,54 @@
e6bab37
+#include <unistd.h>
e6bab37
+#include <stdlib.h>
e6bab37
+#include <string.h>
e6bab37
+#include <stdio.h>
e6bab37
+#include <ctype.h>
e6bab37
+#include "selinux_internal.h"
e6bab37
+#include "context_internal.h"
e6bab37
+
e6bab37
+int selinux_check_securetty_context(security_context_t tty_context)
e6bab37
+{
e3bd599
+	char *line = NULL;
e3bd599
+	char *start, *end = NULL;
e3bd599
+	size_t line_len = 0;
e6bab37
+	size_t len;
e6bab37
+	int found = -1;
e6bab37
+	FILE *fp;
e6bab37
+	fp = fopen(selinux_securetty_context_path(), "r");
e6bab37
+	if (fp) {
e3bd599
+		context_t con = context_new(tty_context);
e6bab37
+		if (con) {
e3bd599
+			const char *type = context_type_get(con);
e6bab37
+			found = 0;
e3bd599
+			while ((len = getline(&line, &line_len, fp)) != -1) {
e6bab37
+
e3bd599
+				if (line[len - 1] == '\n')
e3bd599
+					line[len - 1] = 0;
e6bab37
+
e3bd599
+				/* Skip leading whitespace. */
e3bd599
+				start = line;
e3bd599
+				while (*start && isspace(*start))
e3bd599
+					start++;
e3bd599
+				if (!(*start))
e6bab37
+					continue;
e6bab37
+
e3bd599
+				end = start;
e3bd599
+				while (*end && !isspace(*end))
e3bd599
+					end++;
e3bd599
+				if (*end)
e3bd599
+					*end++ = 0;
e3bd599
+				if (!strcmp(type, start)) {
e6bab37
+					found = 1;
e6bab37
+					break;
e6bab37
+				}
e6bab37
+			}
e3bd599
+			free(line);
e6bab37
+			context_free(con);
e6bab37
+		}
e6bab37
+		fclose(fp);
e6bab37
+	}
e6bab37
+
e6bab37
+	return found;
e6bab37
+}
e6bab37
+
e6bab37
+hidden_def(selinux_check_securetty_context)
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_config.c libselinux-1.33.3/src/selinux_config.c
e6bab37
--- nsalibselinux/src/selinux_config.c	2006-11-16 17:15:25.000000000 -0500
e3bd599
+++ libselinux-1.33.3/src/selinux_config.c	2007-01-09 09:49:51.000000000 -0500
e6bab37
@@ -38,7 +38,8 @@
e6bab37
 #define NETFILTER_CONTEXTS    15
e6bab37
 #define FILE_CONTEXTS_HOMEDIR 16
e6bab37
 #define FILE_CONTEXTS_LOCAL 17
e6bab37
-#define NEL               18
e6bab37
+#define SECURETTY_CONTEXTS  18
e6bab37
+#define NEL               19
e6bab37
 
e6bab37
 /* New layout is relative to SELINUXDIR/policytype. */
e6bab37
 static char *file_paths[NEL];
e3bd599
@@ -299,6 +300,13 @@
dbfbfbe
 
e6bab37
 hidden_def(selinux_default_context_path)
e6bab37
 
e6bab37
+const char *selinux_securetty_context_path()
e6bab37
+{
e6bab37
+	return get_path(SECURETTY_CONTEXTS);
e6bab37
+}
e3bd599
+
e6bab37
+hidden_def(selinux_securetty_context_path)
e6bab37
+
e6bab37
 const char *selinux_failsafe_context_path()
dbfbfbe
 {
e6bab37
 	return get_path(FAILSAFE_CONTEXT);
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/src/selinux_internal.h libselinux-1.33.3/src/selinux_internal.h
e6bab37
--- nsalibselinux/src/selinux_internal.h	2006-11-16 17:15:25.000000000 -0500
e3bd599
+++ libselinux-1.33.3/src/selinux_internal.h	2007-01-09 09:49:51.000000000 -0500
e6bab37
@@ -53,6 +53,7 @@
e6bab37
     hidden_proto(security_setenforce)
e6bab37
     hidden_proto(selinux_binary_policy_path)
e6bab37
     hidden_proto(selinux_default_context_path)
e6bab37
+    hidden_proto(selinux_securetty_context_path)
e6bab37
     hidden_proto(selinux_failsafe_context_path)
e6bab37
     hidden_proto(selinux_removable_context_path)
e6bab37
     hidden_proto(selinux_file_context_path)
e6bab37
@@ -66,6 +67,7 @@
e6bab37
     hidden_proto(selinux_media_context_path)
e6bab37
     hidden_proto(selinux_path)
e6bab37
     hidden_proto(selinux_check_passwd_access)
e6bab37
+    hidden_proto(selinux_check_securetty_context)
e6bab37
     hidden_proto(matchpathcon_init_prefix)
e6bab37
     hidden_proto(selinux_users_path)
e6bab37
     hidden_proto(selinux_usersconf_path);
05bd408
diff --exclude-from=exclude -N -u -r nsalibselinux/utils/getdefaultcon.c libselinux-1.33.3/utils/getdefaultcon.c
05bd408
--- nsalibselinux/utils/getdefaultcon.c	1969-12-31 19:00:00.000000000 -0500
05bd408
+++ libselinux-1.33.3/utils/getdefaultcon.c	2007-01-09 14:55:19.000000000 -0500
05bd408
@@ -0,0 +1,75 @@
05bd408
+#include <unistd.h>
05bd408
+#include <sys/types.h>
05bd408
+#include <fcntl.h>
05bd408
+#include <stdio.h>
05bd408
+#include <stdlib.h>
05bd408
+#include <errno.h>
05bd408
+#include <string.h>
05bd408
+#include <ctype.h>
05bd408
+#include <selinux/selinux.h>
05bd408
+#include <selinux/get_context_list.h>
05bd408
+
05bd408
+void usage(char *name, char *detail, int rc)
05bd408
+{
05bd408
+	fprintf(stderr, "usage:  %s [-l level] user fromcon\n", name);
05bd408
+	if (detail)
05bd408
+		fprintf(stderr, "%s:  %s\n", name, detail);
05bd408
+	exit(rc);
05bd408
+}
05bd408
+
05bd408
+int main(int argc, char **argv)
05bd408
+{
05bd408
+	security_context_t usercon = NULL, cur_context = NULL;
05bd408
+	char *user = NULL, *level = NULL, *role=NULL, *seuser=NULL;
05bd408
+	int ret, opt;
05bd408
+
05bd408
+	while ((opt = getopt(argc, argv, "l:r:")) > 0) {
05bd408
+		switch (opt) {
05bd408
+		case 'l':
05bd408
+			level = strdup(optarg);
05bd408
+			break;
05bd408
+		case 'r':
05bd408
+			role = strdup(optarg);
05bd408
+			break;
05bd408
+		default:
05bd408
+			usage(argv[0], "invalid option", 1);
05bd408
+		}
05bd408
+	}
05bd408
+
05bd408
+	if (((argc - optind) < 1) || ((argc - optind) > 2))
05bd408
+		usage(argv[0], "invalid number of arguments", 2);
05bd408
+
05bd408
+	/* If selinux isn't available, bail out. */
05bd408
+	if (!is_selinux_enabled()) {
05bd408
+		fprintf(stderr,
05bd408
+			"%s may be used only on a SELinux kernel.\n", argv[0]);
05bd408
+		return 1;
05bd408
+	}
05bd408
+
05bd408
+	user = argv[optind];
05bd408
+
05bd408
+	/* If a context wasn't passed, use the current context. */
05bd408
+	if (((argc - optind) < 2)) {
05bd408
+		if (getcon(&cur_context) < 0) {
05bd408
+			fprintf(stderr, "Couldn't get current context.\n");
05bd408
+			return 2;
05bd408
+		}
05bd408
+	} else
05bd408
+		cur_context = argv[optind + 1];
05bd408
+
05bd408
+	if (getseuserbyname(user, &seuser, &level)==0) {
05bd408
+		if (role != NULL && role[0]) 
05bd408
+			ret=get_default_context_with_rolelevel(seuser, role, level,cur_context,&usercon);
05bd408
+		else
05bd408
+			ret=get_default_context_with_level(seuser, level, cur_context,&usercon);
05bd408
+	}
05bd408
+	if (ret < 0)
05bd408
+		perror(argv[0]);
05bd408
+	else
05bd408
+		printf("%s: %s from %s %s %s %s -> %s\n", argv[0], user, cur_context, seuser, role, level, usercon);
05bd408
+
05bd408
+
05bd408
+	free(usercon);
05bd408
+
05bd408
+	return 0;
05bd408
+}
e3bd599
diff --exclude-from=exclude -N -u -r nsalibselinux/utils/matchpathcon.c libselinux-1.33.3/utils/matchpathcon.c
e3bd599
--- nsalibselinux/utils/matchpathcon.c	2007-01-04 17:01:41.000000000 -0500
e3bd599
+++ libselinux-1.33.3/utils/matchpathcon.c	2007-01-09 09:49:51.000000000 -0500
e3bd599
@@ -95,7 +95,7 @@
e3bd599
 		}
e3bd599
 	}
e3bd599
 	for (i = optind; i < argc; i++) {
e3bd599
-		int mode=0;
e3bd599
+		int mode = 0;
e3bd599
 		struct stat buf;
e3bd599
 		if (lstat(argv[i], &buf) == 0)
e3bd599
 			mode = buf.st_mode;
e3bd599
@@ -114,13 +114,15 @@
e3bd599
 				if (rc >= 0) {
e3bd599
 					printf("%s has context %s, should be ",
e3bd599
 					       argv[i], con);
e3bd599
-					error += printmatchpathcon(argv[i], 0, mode);
e3bd599
+					error +=
e3bd599
+					    printmatchpathcon(argv[i], 0, mode);
e3bd599
 					freecon(con);
e3bd599
 				} else {
e3bd599
 					printf
e3bd599
 					    ("actual context unknown: %s, should be ",
e3bd599
 					     strerror(errno));
e3bd599
-					error += printmatchpathcon(argv[i], 0,mode);
e3bd599
+					error +=
e3bd599
+					    printmatchpathcon(argv[i], 0, mode);
e3bd599
 				}
e3bd599
 			}
e3bd599
 		} else {
e6bab37
diff --exclude-from=exclude -N -u -r nsalibselinux/utils/selinux_check_securetty_context.c libselinux-1.33.3/utils/selinux_check_securetty_context.c
e6bab37
--- nsalibselinux/utils/selinux_check_securetty_context.c	1969-12-31 19:00:00.000000000 -0500
e3bd599
+++ libselinux-1.33.3/utils/selinux_check_securetty_context.c	2007-01-09 09:49:51.000000000 -0500
e3bd599
@@ -0,0 +1,38 @@
e6bab37
+#include <unistd.h>
e6bab37
+#include <stdio.h>
e6bab37
+#include <stdlib.h>
e6bab37
+#include <getopt.h>
e6bab37
+#include <errno.h>
e6bab37
+#include <string.h>
e6bab37
+#include <sys/types.h>
e6bab37
+#include <sys/stat.h>
e6bab37
+#include <sys/errno.h>
e6bab37
+#include <selinux/selinux.h>
e6bab37
+
e6bab37
+void usage(const char *progname)
e6bab37
+{
e3bd599
+	fprintf(stderr, "usage:  %s tty_context...\n", progname);
e6bab37
+	exit(1);
e6bab37
+}
e6bab37
+
e6bab37
+int main(int argc, char **argv)
e6bab37
+{
e6bab37
+	int i;
e6bab37
+	if (argc < 2)
e6bab37
+		usage(argv[0]);
dbfbfbe
+
e6bab37
+	for (i = 1; i < argc; i++) {
e6bab37
+		switch (selinux_check_securetty_context(argv[i])) {
e6bab37
+		case 1:
e6bab37
+			printf("%s securetty.\n", argv[i]);
e6bab37
+			break;
e6bab37
+		case 0:
e6bab37
+			printf("%s not securetty.\n", argv[i]);
e6bab37
+			break;
e6bab37
+		case -1:
e6bab37
+			perror("Failed on check if securetty");
e6bab37
+			return -1;
e6bab37
+		}
e6bab37
+	}
e6bab37
+	return 0;
e6bab37
+}