libselinux/libselinux-rhat.patch
2004-09-14 13:39:22 +00:00

102 lines
2.4 KiB
Diff

diff --exclude-from=exclude -N -u -r nsalibselinux/src/matchmediacon.c libselinux-1.17.10/src/matchmediacon.c
--- nsalibselinux/src/matchmediacon.c 1969-12-31 19:00:00.000000000 -0500
+++ libselinux-1.17.10/src/matchmediacon.c 2004-09-10 14:40:16.000000000 -0400
@@ -0,0 +1,65 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <string.h>
+#include "selinux_internal.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <regex.h>
+#include <stdarg.h>
+
+int matchmediacon(const char *media,
+ security_context_t *con)
+{
+ const char *path = selinux_media_context_path();
+ FILE *infile;
+ char *ptr, *ptr2;
+ char *target;
+ int found=-1;
+ char current_line[PATH_MAX];
+ if ((infile = fopen(path, "r")) == NULL)
+ return -1;
+ while (!feof_unlocked (infile)) {
+ if (!fgets_unlocked(current_line, sizeof(current_line), infile)) {
+ return -1;
+ }
+ if (current_line[strlen(current_line) - 1])
+ current_line[strlen(current_line) - 1] = 0;
+ /* Skip leading whitespace before the partial context. */
+ ptr = current_line;
+ while (*ptr && isspace(*ptr))
+ ptr++;
+
+ if (!(*ptr))
+ continue;
+
+
+ /* Find the end of the media context. */
+ ptr2 = ptr;
+ while (*ptr2 && !isspace(*ptr2))
+ ptr2++;
+ if (!(*ptr2))
+ continue;
+
+ *ptr2++=NULL;
+ if (strcmp (media, ptr) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ return -1;
+
+ /* Skip whitespace. */
+ while (*ptr2 && isspace(*ptr2))
+ ptr2++;
+ if (!(*ptr2)) {
+ return -1;
+ }
+
+ *con = strdup(ptr2);
+ return 0;
+}
diff --exclude-from=exclude -N -u -r nsalibselinux/utils/matchmediacon.c libselinux-1.17.10/utils/matchmediacon.c
--- nsalibselinux/utils/matchmediacon.c 1969-12-31 19:00:00.000000000 -0500
+++ libselinux-1.17.10/utils/matchmediacon.c 2004-09-10 14:40:17.000000000 -0400
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <selinux/selinux.h>
+#include <errno.h>
+#include <string.h>
+
+int main(int argc, char **argv)
+{
+ char *buf;
+ int rc, i;
+
+ if (argc < 2) {
+ fprintf(stderr, "usage: %s media...\n", argv[0]);
+ exit(1);
+ }
+
+ for (i = 1; i < argc; i++) {
+ rc = matchmediacon(argv[i], &buf);
+ if (rc < 0) {
+ fprintf(stderr, "%s: matchmediacon(%s) failed: %s\n", argv[0], argv[i]);
+ exit(2);
+ }
+ printf("%s\t%s\n", argv[i], buf);
+ freecon(buf);
+ }
+ exit(0);
+}