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]
21 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
22 * Use is subject to license terms.
25 #pragma ident "%Z%%M% %I% %E% SMI"
35 #include <sys/param.h>
36 #include <cryptoutil.h>
39 static int err
; /* To store errno which may be overwritten by gettext() */
42 kc_uninstall(int argc
, char *argv
[])
47 extern char *optarg_av
;
48 char *keystore_name
= NULL
;
49 conf_entry_t
*entry
= NULL
;
51 FILE *pfile_tmp
= NULL
;
52 char tmpfile_name
[MAXPATHLEN
];
53 char buffer
[MAXPATHLEN
];
54 char buffer2
[MAXPATHLEN
];
58 while ((opt
= getopt_av(argc
, argv
, "k:(keystore)")) != EOF
) {
61 if (keystore_name
!= NULL
)
64 keystore_name
= get_string(optarg_av
, &rv
);
65 if (keystore_name
== NULL
) {
66 (void) fprintf(stderr
, gettext(
67 "Error keystore input.\n"));
72 (void) fprintf(stderr
,
73 gettext("Error input option.\n"));
81 /* No additional args allowed. */
84 (void) fprintf(stderr
,
85 gettext("Error input option\n"));
90 if (keystore_name
== NULL
) {
91 (void) fprintf(stderr
,
92 gettext("Error input option\n"));
97 if (strcasecmp(keystore_name
, "nss") == 0 ||
98 strcasecmp(keystore_name
, "pkcs11") == 0 ||
99 strcasecmp(keystore_name
, "file") == 0) {
100 (void) fprintf(stderr
,
101 gettext("Can not uninstall the built-in keystore %s\n"),
103 rv
= KC_ERR_UNINSTALL
;
107 entry
= get_keystore_entry(keystore_name
);
109 (void) fprintf(stderr
, gettext("%s does not exist.\n"),
115 if ((pfile
= fopen(_PATH_KMF_CONF
, "r+")) == NULL
) {
117 (void) fprintf(stderr
,
118 gettext("failed to update the configuration - %s\n"),
124 if (lockf(fileno(pfile
), F_TLOCK
, 0) == -1) {
126 (void) fprintf(stderr
,
127 gettext("failed to lock the configuration - %s\n"),
129 rv
= KC_ERR_UNINSTALL
;
134 * Create a temporary file in the /etc/crypto directory.
136 (void) strlcpy(tmpfile_name
, CONF_TEMPFILE
, sizeof (tmpfile_name
));
137 if (mkstemp(tmpfile_name
) == -1) {
139 (void) fprintf(stderr
,
140 gettext("failed to create a temporary file - %s\n"),
142 rv
= KC_ERR_UNINSTALL
;
146 if ((pfile_tmp
= fopen(tmpfile_name
, "w")) == NULL
) {
148 (void) fprintf(stderr
,
149 gettext("failed to open a temporary file - %s\n"),
151 rv
= KC_ERR_UNINSTALL
;
156 * Loop thru the config file. If the plugin to be uninstalled is in
157 * a package, then just comment it off.
159 in_package
= B_FALSE
;
160 while (fgets(buffer
, MAXPATHLEN
, pfile
) != NULL
) {
162 if (buffer
[0] != ' ' && buffer
[0] != '\n' &&
164 if (strstr(buffer
, " Start ") != NULL
) {
166 } else if (strstr(buffer
, " End ") != NULL
) {
167 in_package
= B_FALSE
;
168 } else if (buffer
[0] != '#') {
173 * make a copy of the original buffer to
174 * buffer2. Also get rid of the trailing
177 (void) strlcpy(buffer2
, buffer
, MAXPATHLEN
);
178 /* get rid of trailing '\n' */
179 len
= strlen(buffer2
);
180 if (buffer2
[len
-1] == '\n') {
185 if ((name
= strtok(buffer2
, SEP_COLON
)) ==
187 rv
= KC_ERR_UNINSTALL
;
191 if (strcmp(keystore_name
, name
) == 0)
198 * If found and not in_package, then don't write
199 * this line to the result file.
202 (void) snprintf(buffer2
, sizeof (buffer2
),
203 "%s%s", "#", buffer
);
205 if (fputs(buffer2
, pfile_tmp
) == EOF
) {
206 rv
= KC_ERR_UNINSTALL
;
211 if (fputs(buffer
, pfile_tmp
) == EOF
) {
212 rv
= KC_ERR_UNINSTALL
;
220 (void) fclose(pfile
);
222 if (rv
!= KC_OK
&& pfile_tmp
!= NULL
)
223 (void) unlink(tmpfile_name
);
225 if (pfile_tmp
!= NULL
)
226 (void) fclose(pfile_tmp
);
229 if (rename(tmpfile_name
, _PATH_KMF_CONF
) == -1) {
231 (void) fprintf(stderr
, gettext(
232 "failed to update the configuration - %s"),
234 return (KC_ERR_UNINSTALL
);
237 if (chmod(_PATH_KMF_CONF
,
238 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IROTH
) == -1) {
240 (void) fprintf(stderr
, gettext(
241 "failed to update the configuration - %s\n"),
243 return (KC_ERR_UNINSTALL
);