1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
/*
* Copyright (C) Sumit Bose 2009
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <popt.h>
#include "helpers.h"
#include "util.h"
#include "xml_helper.h"
#include "policy_collection.h"
#ifdef WITH_SSSD
#include "sbus_client.h"
#endif
int main(int argc, const char *argv[])
{
int opt_daemon=0;
int opt_once=0;
int opt;
int opt_check;
int poli_c;
int file_c;
poptContext pc;
char *policy_file_name=NULL;
int ret=0;
struct policy_collection *pc_array;
struct poptOption long_options[] = {
POPT_AUTOHELP
{"daemon", 'D', POPT_ARG_NONE, &opt_daemon, 0, \
"Become a daemon (default)", NULL }, \
{"once", 'o', POPT_ARG_NONE, &opt_once, 0, \
"Run once and process all policies (not a daemon)", NULL}, \
{"policy", 'p', POPT_ARG_STRING, NULL, 'p', \
"Only process the given policy", "name of the policy file"}, \
{"searchpath", 's', POPT_ARG_STRING, NULL, 's', \
"add the following path to the XML search path (may be used more than once)", "name of a directory"}, \
POPT_TABLEEND
};
pc = poptGetContext(argv[0], argc, argv, long_options, 0);
while((opt = poptGetNextOpt(pc)) != -1) {
switch(opt) {
case 'p':
policy_file_name=poptGetOptArg(pc);
break;
case 's':
setup_xml_search_path(poptGetOptArg(pc));
break;
default:
fprintf(stderr, "\nInvalid option %s: %s\n\n",
poptBadOption(pc, 0), poptStrerror(opt));
poptPrintUsage(pc, stderr, 0);
poptFreeContext(pc);
ret=1;
goto cleanup;
}
}
opt_check=0;
if (opt_daemon != 0 ) opt_check++;
if (opt_once != 0 ) opt_check++;
if (policy_file_name != NULL ) opt_check++;
if (opt_check > 1) {
fprintf(stderr, "Do not user Option -o|--once, -D|--daemon and -p|--policy together in any combination.\n");
poptPrintUsage(pc, stderr, 0);
poptFreeContext(pc);
ret=1;
goto cleanup;
}
if (opt_check == 0) opt_daemon = 1;
poptFreeContext(pc);
setup_xml_search_path("../policy_metadata/");
if ( policy_file_name != NULL ) {
load_policy_collection("policy_collection_example.xml", &pc_array);
poli_c=0;
while (pc_array[poli_c].name != NULL) {
DEBUG(3,("Schema name for policy collection #%d: %s\n",poli_c, pc_array[poli_c].name));
file_c=0;
while (pc_array[poli_c].files[file_c] != NULL) {
DEBUG(3,(" policy file: %s\n",pc_array[poli_c].files[file_c]));
file_c++;
}
poli_c++;
}
ret=process_policy(policy_file_name);
if ( ret == -1 ) {
DEBUG(0,("Invalid policy, aborting.\n"));
ret=1;
goto cleanup;
}
}
if (opt_daemon!=0) {
#ifdef WITH_SSSD
ret = setup_sbus_and_server_loop();
#else
DEBUG(0,("This binary was not compiled with sssd support.\n"));
#endif
}
cleanup:
free_policy_collection(&pc_array);
free_xml_search_path();
free(policy_file_name);
return ret;
}
|