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
139
140
|
/* This file is part of Eclat.
Copyright (C) 2013 Sergey Poznyakoff.
Eclat 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, or (at your option)
any later version.
Eclat 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 Eclat. If not, see <http://www.gnu.org/licenses/>. */
ECLAT_CL_BEGIN([<modify ingress rules of a security group>],
[<GROUPARG>])
OPTION(add,A,,
[<add rules>])
BEGIN
command = "AuthorizeSecurityGroupIngress";
END
OPTION(delete,D,,
[<delete rules>])
BEGIN
command = "RevokeSecurityGroupIngress";
END
OPTION(list,L,,
[<list rules>])
BEGIN
list_option = 1;
command = "DescribeSecurityGroups";
END
OPTION(name,n,,
[<ID argument is a group name>])
BEGIN
dest_n = GROUP_NAME;
END
OPTION(protocol,p,[<PROTO>],
[<IP protocol name or number>])
BEGIN
proto = optarg;
END
OPTION(group-id,g,[<ID>],
[<use before --from to indicate that its argument is a group ID>])
BEGIN
struct group_arg *g = grecs_malloc(sizeof(*g));
translate_ids(1, &optarg, rt[GROUP_ID].map);
g->type = GROUP_ID;
g->str = optarg;
g->usr = user;
if (!group_list)
group_list = _grecs_simple_list_create(1);
grecs_list_append(group_list, g);
END
OPTION(group-name,G,[<NAME>],
[<use before --from to indicate that its argument is a group name>])
BEGIN
struct group_arg *g = grecs_malloc(sizeof(*g));
translate_ids(1, &optarg, rt[GROUP_NAME].map);
g->type = GROUP_NAME;
g->str = optarg;
g->usr = user;
if (!group_list)
group_list = _grecs_simple_list_create(1);
grecs_list_append(group_list, g);
END
OPTION(user,u,[<USER>],
[<user name for the subsequent --from option>])
BEGIN
user = optarg;
END
OPTION(source,s,[<CIDR>],
[<source CIDR>])
BEGIN
if (!source_list)
source_list = grecs_list_create();
grecs_list_append(source_list, optarg);
END
OPTION(port,P,[<PORT[-PORT]>],
[<destination port number or range>])
BEGIN
char *p = strchr(optarg, '-');
if (p) {
*p++ = 0;
to_port = p;
} else
to_port = optarg;
from_port = optarg;
END
OPTION(next,N,,
[<delimits rules>])
ALIAS(new)
BEGIN
flush_rule();
END
ECLAT_CL_END
ECLAT_CL_PARSER(parse_options, [<int argc, char *argv[]>],[<
{
int idx;
GETOPT(argc, argv, idx, exit(EX_USAGE))
if (!command)
die(EX_USAGE, "either --list or --add or --delete must be given");
if (list_option &&
(rule_n > 1 || group_list || source_list || from_port || to_port))
die(EX_USAGE, "conflicting options");
argc -= idx;
argv += idx;
if (argc != 1)
die(EX_USAGE, "bad number of arguments");
translate_ids(1, argv, rt[dest_n].map);
eclat_query_add_param(env->query, "Action", command);
if (list_option)
describe_query_create(env, argc, argv, rt[dest_n].resid);
else {
if (group_list || source_list || from_port || to_port)
flush_rule();
if (rule_n == 1)
die(EX_USAGE, "no rules");
eclat_query_add_param(query, rt[dest_n].resid, argv[0]);
}
}>])
|