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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1988 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #pragma weak _run_setkey = run_setkey
33 #pragma weak _run_crypt = run_crypt
34 #pragma weak _crypt_close = crypt_close
35 #pragma weak _makekey = makekey
42 #include <sys/types.h>
53 /* Global Variables */
54 static char key
[KSIZE
+1];
60 static mutex_t lock
= DEFAULTMUTEX
;
62 static int cryptopen();
63 static int writekey();
68 run_setkey(int p
[2], const char *keyparam
)
70 (void) mutex_lock(&lock
);
71 if (cryptopen(p
) == -1) {
72 (void) mutex_unlock(&lock
);
75 (void) strncpy(key
, keyparam
, KSIZE
);
77 (void) crypt_close_nolock(p
);
78 (void) mutex_unlock(&lock
);
81 if (writekey(p
, key
) == -1) {
82 (void) mutex_unlock(&lock
);
85 (void) mutex_unlock(&lock
);
89 static char cmd
[] = "exec /usr/bin/crypt -p 2>/dev/null";
95 if (__p2open(cmd
, p
) < 0)
97 if (read(p
[WRITER
], &c
, 1) != 1) { /* check that crypt is working on */
99 (void) crypt_close(p
); /* remove defunct process */
106 writekey(int p
[2], char *keyarg
)
109 pstat
= signal(SIGPIPE
, SIG_IGN
); /* don't want pipe errors to cause */
111 if (write(p
[READER
], keyarg
, KSIZE
) != KSIZE
) {
112 (void) crypt_close(p
); /* remove defunct process */
113 (void) signal(SIGPIPE
, pstat
);
116 (void) signal(SIGPIPE
, pstat
);
122 run_crypt(long offset
, char *buffer
, unsigned int count
, int p
[2])
124 struct header header
;
127 (void) mutex_lock(&lock
);
128 header
.count
= count
;
129 header
.offset
= offset
;
130 pstat
= signal(SIGPIPE
, SIG_IGN
);
131 if (write(p
[READER
], (char *)&header
, sizeof (header
))
132 != sizeof (header
)) {
133 (void) crypt_close_nolock(p
);
134 (void) signal(SIGPIPE
, pstat
);
135 (void) mutex_unlock(&lock
);
138 if (write(p
[READER
], buffer
, count
) < count
) {
139 (void) crypt_close_nolock(p
);
140 (void) signal(SIGPIPE
, pstat
);
141 (void) mutex_unlock(&lock
);
144 if (read(p
[WRITER
], buffer
, count
) < count
) {
145 (void) crypt_close_nolock(p
);
146 (void) signal(SIGPIPE
, pstat
);
147 (void) mutex_unlock(&lock
);
150 (void) signal(SIGPIPE
, pstat
);
151 (void) mutex_unlock(&lock
);
160 char tempbuf
[KSIZE
], *a
, *temp
;
162 (void) mutex_lock(&lock
);
165 for (i
= 0; i
< KSIZE
; i
++)
167 gorp
= getuid() + getgid();
169 for (i
= 0; i
< 4; i
++)
170 temp
[i
] ^= (char)((gorp
>>(8*i
))&0377);
172 if (cryptopen(b
) == -1) {
173 (void) mutex_unlock(&lock
);
176 if (writekey(b
, temp
) == -1) {
177 (void) mutex_unlock(&lock
);
180 (void) mutex_unlock(&lock
);
185 crypt_close_nolock(int p
[2])
188 if (p
[0] == 0 && p
[1] == 0 || p
[0] < 0 || p
[1] < 0) {
192 return (__p2close(p
, NULL
, SIGKILL
));
196 crypt_close(int p
[2])
198 (void) mutex_lock(&lock
);
199 (void) crypt_close_nolock(p
);
200 (void) mutex_unlock(&lock
);