4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
38 kc_export(int argc
, char *argv
[])
41 char *filename
= NULL
;
43 char *policyname
= NULL
;
44 POLICY_LIST
*plclist
= NULL
, *pnode
;
47 extern char *optarg_av
;
49 while ((opt
= getopt_av(argc
, argv
,
50 "d:(dbfile)p:(policy)o:(outfile)")) != EOF
) {
53 filename
= get_string(optarg_av
, &rv
);
54 if (filename
== NULL
) {
55 (void) fprintf(stderr
,
56 gettext("Error dbfile input.\n"));
60 policyname
= get_string(optarg_av
, &rv
);
61 if (policyname
== NULL
) {
62 (void) fprintf(stderr
,
63 gettext("Error policy name.\n"));
67 outfile
= get_string(optarg_av
, &rv
);
68 if (outfile
== NULL
) {
69 (void) fprintf(stderr
,
70 gettext("Error outfile input.\n"));
74 (void) fprintf(stderr
,
75 gettext("Error input option.\n"));
84 /* No additional args allowed. */
87 (void) fprintf(stderr
,
88 gettext("Error input option\n"));
93 if (filename
== NULL
) {
94 filename
= strdup(KMF_DEFAULT_POLICY_FILE
);
95 if (filename
== NULL
) {
101 if (policyname
== NULL
) {
102 (void) fprintf(stderr
,
103 gettext("You must specify a policy name\n"));
108 if (outfile
== NULL
) {
109 (void) fprintf(stderr
,
110 gettext("You must specify a output DB file\n"));
115 if (strcmp(outfile
, KMF_DEFAULT_POLICY_FILE
) == 0 &&
116 strcmp(policyname
, KMF_DEFAULT_POLICY_NAME
) == 0) {
117 (void) fprintf(stderr
,
118 gettext("Can not export the default policy record to "
119 "the system default policy database\n"));
124 rv
= load_policies(filename
, &plclist
);
129 while (pnode
!= NULL
&& !found
) {
130 if (strcmp(policyname
, pnode
->plc
.name
) == 0) {
134 ret
= kmf_verify_policy(&pnode
->plc
);
136 print_sanity_error(ret
);
137 rv
= KC_ERR_VERIFY_POLICY
;
140 rv
= kmf_add_policy_to_db(&pnode
->plc
, outfile
,
147 (void) fprintf(stderr
,
148 gettext("Could not find policy \"%s\" in %s\n"),
149 policyname
, filename
);
150 rv
= KC_ERR_FIND_POLICY
;
160 free_policy_list(plclist
);