From: Jarkko Sakkinen Date: Thu, 10 Nov 2011 09:38:37 +0000 (+0200) Subject: cleaned up smackaccess and made more scriptable X-Git-Tag: accepted/trunk/20130107.204027~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=450f9fc89293d2be8081ec58b1730acefff5cc6a;p=platform%2Fupstream%2Fsmack.git cleaned up smackaccess and made more scriptable --- diff --git a/utils/smackaccess.c b/utils/smackaccess.c index da73d04..026933c 100644 --- a/utils/smackaccess.c +++ b/utils/smackaccess.c @@ -30,44 +30,22 @@ #include #include -#define LABEL_LEN 23 -#define ACC_LEN 5 -#define BUF_SIZE 512 -#define DELIM " \t\n" - int main(int argc, char **argv) { - char buf[BUF_SIZE]; - char *ptr; - int fd; - char *subject; - char *object; - char *access_type; int ret; - while (fgets(buf, BUF_SIZE, stdin) != NULL) { - - subject = strtok_r(buf, DELIM, &ptr); - object = strtok_r(NULL, DELIM, &ptr); - access_type = strtok_r(NULL, DELIM, &ptr); - - if (subject == NULL || object == NULL || access_type == NULL || - strtok_r(NULL, DELIM, &ptr) != NULL) { - fprintf(stderr, "Invalid rule\n"); - close(fd); - exit(EXIT_FAILURE); - } + if (argc < 4) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } - fd = open("/smack/access", O_RDWR); - if (fd < 0) { - perror("open"); - exit(EXIT_FAILURE); - } - ret = smack_have_access(subject, object, access_type); - printf("%d\n", ret); - close(fd); + ret = smack_have_access(argv[1], argv[2], argv[3]); + if (ret < 0) { + perror("smack_have_access"); + return EXIT_FAILURE; } + printf("%d\n", ret); return EXIT_SUCCESS; }