root/trunk/secmds/indexcon.cc

Revision 4585, 2.9 kB (checked in by jtang, 6 years ago)

Merged SETools 3.3 into trunk.
Tagged SETools 3.3.

  • Property svn:eol-style set to native
Line 
1 /**
2  * @file
3  *
4  * Command-line program that builds a libsefs database of file
5  * contexts.
6  *
7  *  @author Jeremy A. Mowery jmowery@tresys.com
8  *  @author Jason Tang jtang@tresys.com
9  *
10  *  Copyright (C) 2003-2007 Tresys Technology, LLC
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24  *
25  *  indexcon: a tool for indexing the security contexts of filesystem entities
26  */
27
28 #include <config.h>
29
30 #include <sefs/db.hh>
31 #include <sefs/filesystem.hh>
32
33 using namespace std;
34
35 #include <iostream>
36 #include <getopt.h>
37
38 #define COPYRIGHT_INFO "Copyright (C) 2003-2007 Tresys Technology, LLC"
39
40 static struct option const longopts[] = {
41         {"directory", required_argument, NULL, 'd'},
42         {"help", no_argument, NULL, 'h'},
43         {"version", no_argument, NULL, 'V'},
44         {NULL, 0, NULL, 0}
45 };
46
47 static void usage(const char *program_name, bool brief)
48 {
49         cout << "Usage: " << program_name << " FILE [OPTIONS]" << endl << endl;
50         if (brief)
51         {
52                 cout << "\tTry " << program_name << " --help for more help." << endl << endl;
53                 return;
54         }
55         cout << "Index SELinux contexts on the filesystem." << endl;
56         cout << endl;
57         cout << "  -d DIR, --directory=DIR  start scanning at directory DIR (default \"/\")" << endl;
58         cout << "  -h, --help               print this help text and exit" << endl;
59         cout << "  -V, --version            print version information and exit" << endl;
60 }
61
62 int main(int argc, char *argv[])
63 {
64         int optc;
65
66         char *outfilename = NULL, *dir = "/";
67
68         while ((optc = getopt_long(argc, argv, "d:hV", longopts, NULL)) != -1)
69         {
70                 switch (optc)
71                 {
72                 case 'd':              // starting directory
73                         dir = optarg;
74                         break;
75                 case 'h':
76                         usage(argv[0], false);
77                         exit(0);
78                 case 'V':
79                         cout << "indexcon " << VERSION << endl << COPYRIGHT_INFO << endl;
80                         exit(0);
81                 default:
82                         usage(argv[0], true);
83                         exit(1);
84                 }
85         }
86         if (argc - optind > 1 || argc - optind < 1)
87         {
88                 usage(argv[0], true);
89                 exit(1);
90         }
91         else
92         {
93                 outfilename = argv[optind];
94         }
95
96         if (outfilename == NULL)
97         {
98                 usage(argv[0], true);
99                 exit(1);
100         }
101
102         sefs_filesystem *fs = NULL;
103         sefs_db *db = NULL;
104         try
105         {
106                 fs = new sefs_filesystem(dir, NULL, NULL);
107                 db = new sefs_db(fs, NULL, NULL);
108                 db->save(outfilename);
109         }
110         catch(...)
111         {
112                 delete fs;
113                 delete db;
114                 exit(2);
115         }
116
117         delete fs;
118         delete db;
119
120         return 0;
121 }
Note: See TracBrowser for help on using the browser.