2 * Copyright (c) 2011-2014, JANET(UK)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of JANET(UK) nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 namespace WebProvisioning
36 private MoonshotLogger logger;
38 public static int main(string[] args)
40 logger = new MoonshotLogger("WebProvisioning");
43 int force_flat_file_store = 0;
44 bool bad_switch = false;
45 for (arg_index = 1; arg_index < args.length; arg_index++) {
46 string arg = args[arg_index];
47 unichar c = arg.get_char();
49 arg = arg.next_char();
53 force_flat_file_store = 1;
60 break; // arg is not a switch; presume it's the file
63 if (bad_switch || (arg_index != args.length - 1))
65 stdout.printf(_("Usage %s [-f] WEB_PROVISIONING_FILE\n -f: add identities to flat file store.\n"), args[0]);
68 string webp_file = args[arg_index];
70 if (!FileUtils.test(webp_file, FileTest.EXISTS | FileTest.IS_REGULAR))
72 stdout.printf(_("%s does not exist\n"), webp_file);
76 var webp = new Parser(webp_file);
78 logger.trace(@"Have $(webp.cards.length) IdCards");
79 foreach (IdCard card in webp.cards)
83 logger.trace(@"Skipping null IdCard");
88 string[] rules_patterns = {};
89 string[] rules_always_confirm = {};
91 /* use temp arrays to workaround centos array property bug */
92 var rules = card.rules;
93 var services = card.services;
97 rules_patterns = new string[rules.length];
98 rules_always_confirm = new string[rules.length];
99 foreach (Rule r in rules)
101 rules_patterns[i] = r.pattern;
102 rules_always_confirm[i] = r.always_confirm;
107 logger.trace(@"Installing IdCard named '$(card.display_name)'");
108 Moonshot.install_id_card(card.display_name,
113 rules_always_confirm,
115 card.trust_anchor.ca_cert,
116 card.trust_anchor.subject,
117 card.trust_anchor.subject_alt,
118 card.trust_anchor.server_cert,
119 force_flat_file_store,
124 stderr.printf("Error: %s", error.message);