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
|
/**
* Author: Sumit Bose <sbose@redhat.com>
*
* Copyright (C) 2008 Red Hat
*
* 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; version 2 only
*
* 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; see the file COPYING.LGPL. If not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include <popt.h>
#include "helpers.h"
#include "util.h"
#include "xml_helper.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;
poptContext pc;
char *policy_file_name=NULL;
int ret=0;
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 ) {
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_xml_search_path();
return ret;
}
|