1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <netinet/in.h> /* struct sockaddr_in */
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <libscf.h>
35 #include <inet/kssl/kssl.h>
36 #include "kssladm.h"
37 
38 void
39 usage_delete(boolean_t do_print)
40 {
41 	if (do_print)
42 		(void) fprintf(stderr, "Usage:\n");
43 	(void) fprintf(stderr,
44 	    "kssladm delete [-v] [<server_address>] <server_port>\n");
45 }
46 
47 int
48 do_delete(int argc, char *argv[])
49 {
50 	struct sockaddr_in server_addr;
51 	char c;
52 	char *port, *addr;
53 	int pcnt;
54 
55 	if (argc < 3) {
56 		goto err;
57 	}
58 
59 	argc -= 1;
60 	argv += 1;
61 
62 	while ((c = getopt(argc, argv, "v")) != -1) {
63 		switch (c) {
64 		case 'v':
65 			verbose = B_TRUE;
66 			break;
67 		default:
68 			goto err;
69 		}
70 	}
71 
72 	pcnt = argc - optind;
73 	if (pcnt == 1) {
74 		port = argv[optind];
75 		addr = NULL;
76 	} else if (pcnt == 2) {
77 		addr = argv[optind];
78 		port = argv[optind + 1];
79 	}
80 
81 	if (parse_and_set_addr(addr, port, &server_addr) < 0) {
82 		goto err;
83 	}
84 
85 	if (kssl_send_command((char *)&server_addr, KSSL_DELETE_ENTRY) < 0) {
86 		perror("Error deleting entry");
87 		return (FAILURE);
88 	}
89 
90 	if (verbose)
91 		(void) printf("Successfully loaded cert and key\n");
92 
93 	return (SUCCESS);
94 
95 err:
96 	usage_delete(B_TRUE);
97 	return (SMF_EXIT_ERR_CONFIG);
98 }
99