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 +#include +#include +#include +#include "selinux_internal.h" +#include +#include +#include +#include +#include +#include +#include + +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 +#include +#include +#include +#include +#include + +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); +}