#include #include #include #include #include #include #include #include #include #include #include #define SOCKET_PATH "selinux.filename.label" #define MAX_LABEL_LEN 4096 #include clock_t startm, stopm; #define START if ( (startm = clock()) == -1) {printf("Error calling clock");exit(1);} #define STOP if ( (stopm = clock()) == -1) {printf("Error calling clock");exit(1);} #define PRINTTIME printf( "%6.3f seconds used by the processor.\n", ((double)stopm-startm)/CLOCKS_PER_SEC); int main(int argc, char *argv[]) { int rc, i; mode_t mode = 0; security_context_t con; if (argc < 2) { printf("usage: %s filename [mode]\n", argv[0]); return 0; } if (argc >= 3) { unsigned long model; errno = 0; /* To distinguish success/failure after call */ model = strtoul(argv[2], NULL, 16); if ((errno == ERANGE && model == ULONG_MAX) || (errno != 0 && model == 0)) { perror("strtol"); exit(EXIT_FAILURE); } mode = (mode_t)model; } rc = matchpathcon_init(NULL); if (rc < 0) return -1; START for (i = 0; i < 1000; i++) { rc = matchpathcon(argv[1], mode, &con); if (rc < 0) return -2; #ifdef VERBOSE printf("pathname=%s mode=%x context=%s\n", argv[1], mode, con); #endif free(con); } STOP PRINTTIME matchpathcon_fini(); return rc; }