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"
41 kc_import(int argc
, char *argv
[])
44 char *filename
= NULL
;
46 char *policyname
= NULL
;
47 POLICY_LIST
*plclist
= NULL
, *pnode
;
50 extern char *optarg_av
;
52 while ((opt
= getopt_av(argc
, argv
,
53 "d:(dbfile)p:(policy)i:(infile)")) != EOF
) {
56 filename
= get_string(optarg_av
, &rv
);
57 if (filename
== NULL
) {
58 (void) fprintf(stderr
,
59 gettext("Error dbfile input.\n"));
63 policyname
= get_string(optarg_av
, &rv
);
64 if (policyname
== NULL
) {
65 (void) fprintf(stderr
,
66 gettext("Error policy name.\n"));
70 infile
= get_string(optarg_av
, &rv
);
72 (void) fprintf(stderr
,
73 gettext("Error infile input.\n"));
77 (void) fprintf(stderr
,
78 gettext("Error input option.\n"));
88 /* No additional args allowed. */
91 (void) fprintf(stderr
,
92 gettext("Error input option\n"));
97 if (filename
== NULL
) {
98 filename
= strdup(KMF_DEFAULT_POLICY_FILE
);
99 if (filename
== NULL
) {
105 if (policyname
== NULL
) {
106 (void) fprintf(stderr
,
107 gettext("You must specify a policy name\n"));
112 if (infile
== NULL
) {
113 (void) fprintf(stderr
,
114 gettext("You must specify a input DB file\n"));
119 if (strcmp(filename
, KMF_DEFAULT_POLICY_FILE
) == 0 &&
120 strcmp(policyname
, KMF_DEFAULT_POLICY_NAME
) == 0) {
121 (void) fprintf(stderr
,
122 gettext("Can not import the default policy record to "
123 "the system default policy database\n"));
128 rv
= load_policies(infile
, &plclist
);
133 while (pnode
!= NULL
&& !found
) {
134 if (strcmp(policyname
, pnode
->plc
.name
) == 0) {
138 ret
= kmf_verify_policy(&pnode
->plc
);
140 print_sanity_error(ret
);
141 rv
= KC_ERR_VERIFY_POLICY
;
144 rv
= kmf_add_policy_to_db(&pnode
->plc
, filename
,
151 (void) fprintf(stderr
,
152 gettext("Could not find policy \"%s\" in %s\n"),
154 rv
= KC_ERR_FIND_POLICY
;
158 if (filename
!= NULL
)
161 if (policyname
!= NULL
)
167 free_policy_list(plclist
);