upload tizen1.0 source
[framework/security/smack.git] / utils / smackload.c
1 /*
2  * This file is part of libsmack
3  *
4  * Copyright (C) 2011 Intel Corporation
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * version 2.1 as published by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  * Authors:
21  * Brian McGillion <brian.mcgillion@intel.com>
22  * Jarkko Sakkinen <jarkko.sakkinen@intel.com>
23  */
24
25 #include "common.h"
26 #include <unistd.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29
30 static void usage(const char *bin)
31 {
32         fprintf(stderr, "Usage: %s [-c] <path>\n", bin);
33         exit(1);
34 }
35
36 int main(int argc, char **argv)
37 {
38         int clear = 0;
39         int c;
40
41         if (is_smackfs_mounted() != 1) {
42                 fprintf(stderr, "SmackFS is not mounted.\n");
43                 exit(1);
44         }
45
46         while ((c = getopt(argc, argv, "c")) != -1) {
47                 switch (c) {
48                 case 'c':
49                         clear = 1;
50                         break;
51                 default:
52                         usage(argv[0]);
53                 }
54         }
55
56         if (optind == argc) {
57                 if (apply_rules_file(STDIN_FILENO, clear)) {
58                         perror("apply_rules_file");
59                         exit(1);
60                 }
61         } else {
62                 if (apply_rules(argv[optind], clear)) {
63                         perror("apply_rules");
64                         exit(1);
65                 }
66         }
67
68         exit(0);
69 }