10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <fcntl.h>
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/stat.h>
310Sstevel@tonic-gate #include <door.h>
320Sstevel@tonic-gate #include <libintl.h>
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include <errno.h>
350Sstevel@tonic-gate #include <signal.h>
360Sstevel@tonic-gate #include <libscf.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate #include <cryptoutil.h>
390Sstevel@tonic-gate #include <sys/crypto/elfsign.h>
400Sstevel@tonic-gate #include "cryptoadm.h"
410Sstevel@tonic-gate
420Sstevel@tonic-gate int
start_daemon(void)430Sstevel@tonic-gate start_daemon(void)
440Sstevel@tonic-gate {
450Sstevel@tonic-gate closefrom(0);
460Sstevel@tonic-gate (void) open("/dev/null", O_RDONLY);
470Sstevel@tonic-gate (void) open("/dev/null", O_WRONLY);
480Sstevel@tonic-gate (void) dup(1);
490Sstevel@tonic-gate (void) setsid();
500Sstevel@tonic-gate
510Sstevel@tonic-gate return (execl(_PATH_KCFD, _PATH_KCFD, (char *)0));
520Sstevel@tonic-gate }
530Sstevel@tonic-gate
540Sstevel@tonic-gate int
stop_daemon(void)550Sstevel@tonic-gate stop_daemon(void)
560Sstevel@tonic-gate {
570Sstevel@tonic-gate int fd = -1;
580Sstevel@tonic-gate int err = 0;
590Sstevel@tonic-gate struct door_info dinfo;
600Sstevel@tonic-gate
610Sstevel@tonic-gate /* read PID of kcfd process from kcfd lock file */
620Sstevel@tonic-gate if ((fd = open(_PATH_KCFD_DOOR, O_RDONLY)) == -1) {
630Sstevel@tonic-gate err = errno;
640Sstevel@tonic-gate cryptodebug("Can not open %s: %s", _PATH_KCFD_DOOR,
650Sstevel@tonic-gate strerror(err));
660Sstevel@tonic-gate goto stop_fail;
670Sstevel@tonic-gate }
680Sstevel@tonic-gate
690Sstevel@tonic-gate if (door_info(fd, &dinfo) == -1 || dinfo.di_target == -1) {
700Sstevel@tonic-gate err = ENOENT; /* no errno if di_target == -1 */
710Sstevel@tonic-gate cryptodebug("no door server listening on %s", _PATH_KCFD_DOOR);
720Sstevel@tonic-gate goto stop_fail;
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate cryptodebug("Sending SIGINT to %d", dinfo.di_target);
760Sstevel@tonic-gate /* send a signal to kcfd process */
770Sstevel@tonic-gate if ((kill(dinfo.di_target, SIGINT)) != 0) {
780Sstevel@tonic-gate err = errno;
790Sstevel@tonic-gate cryptodebug("failed to send a signal to kcfd: %s",
800Sstevel@tonic-gate strerror(errno));
810Sstevel@tonic-gate goto stop_fail;
820Sstevel@tonic-gate }
830Sstevel@tonic-gate
840Sstevel@tonic-gate stop_fail:
850Sstevel@tonic-gate if (fd != -1)
860Sstevel@tonic-gate (void) close(fd);
870Sstevel@tonic-gate
880Sstevel@tonic-gate if (err != 0) {
890Sstevel@tonic-gate cryptoerror(LOG_STDERR, gettext(
90*957Sdarrenm "no kcfd available to stop - %s."),
910Sstevel@tonic-gate strerror(err));
92*957Sdarrenm /*
93*957Sdarrenm * We return with SMF_EXIT_OK because this was a request
94*957Sdarrenm * to stop something that wasn't running.
95*957Sdarrenm */
96*957Sdarrenm return (SMF_EXIT_OK);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate return (SMF_EXIT_OK);
1000Sstevel@tonic-gate }
101