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.
26 #pragma ident "%Z%%M% %I% %E% SMI"
40 kc_export(int argc
, char *argv
[])
43 char *filename
= NULL
;
45 char *policyname
= NULL
;
46 POLICY_LIST
*plclist
= NULL
, *pnode
;
49 extern char *optarg_av
;
51 while ((opt
= getopt_av(argc
, argv
,
52 "d:(dbfile)p:(policy)o:(outfile)")) != EOF
) {
55 filename
= get_string(optarg_av
, &rv
);
56 if (filename
== NULL
) {
57 (void) fprintf(stderr
,
58 gettext("Error dbfile input.\n"));
62 policyname
= get_string(optarg_av
, &rv
);
63 if (policyname
== NULL
) {
64 (void) fprintf(stderr
,
65 gettext("Error policy name.\n"));
69 outfile
= get_string(optarg_av
, &rv
);
70 if (outfile
== NULL
) {
71 (void) fprintf(stderr
,
72 gettext("Error outfile input.\n"));
76 (void) fprintf(stderr
,
77 gettext("Error input option.\n"));
86 /* No additional args allowed. */
89 (void) fprintf(stderr
,
90 gettext("Error input option\n"));
95 if (filename
== NULL
) {
96 filename
= strdup(KMF_DEFAULT_POLICY_FILE
);
97 if (filename
== NULL
) {
103 if (policyname
== NULL
) {
104 (void) fprintf(stderr
,
105 gettext("You must specify a policy name\n"));
110 if (outfile
== NULL
) {
111 (void) fprintf(stderr
,
112 gettext("You must specify a output DB file\n"));
117 if (strcmp(outfile
, KMF_DEFAULT_POLICY_FILE
) == 0 &&
118 strcmp(policyname
, KMF_DEFAULT_POLICY_NAME
) == 0) {
119 (void) fprintf(stderr
,
120 gettext("Can not export the default policy record to "
121 "the system default policy database\n"));
126 rv
= load_policies(filename
, &plclist
);
131 while (pnode
!= NULL
&& !found
) {
132 if (strcmp(policyname
, pnode
->plc
.name
) == 0) {
136 ret
= kmf_verify_policy(&pnode
->plc
);
138 print_sanity_error(ret
);
139 rv
= KC_ERR_VERIFY_POLICY
;
142 rv
= kmf_add_policy_to_db(&pnode
->plc
, outfile
,
149 (void) fprintf(stderr
,
150 gettext("Could not find policy \"%s\" in %s\n"),
151 policyname
, filename
);
152 rv
= KC_ERR_FIND_POLICY
;
156 if (filename
!= NULL
)
159 if (policyname
!= NULL
)
165 free_policy_list(plclist
);