3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /*
29 * External interface to the libsmbfs/netsmb keychain
30 * storage mechanism. This interface is consumed by
31 * the "smbutil" commands: login, logout, ...
32 * and by the SMBFS PAM module.
33 */
34
35 #include <sys/types.h>
36
37 #include <errno.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
42 #include <libintl.h>
43
111 case SMBIOC_PK_DEL_EVERYONE: /* all owned by everyone */
112 /*
113 * These two do not copyin any args, but we'll
114 * pass pk here anyway just so we can use the
115 * common code path below.
116 */
117 break;
118
119 default:
120 err = SMB_KEYCHAIN_UNKNOWN;
121 goto out;
122 }
123
124 fd = smb_open_driver();
125 if (fd < 0) {
126 err = SMB_KEYCHAIN_NODRIVER;
127 goto out;
128 }
129
130 err = 0;
131 if (ioctl(fd, cmd, &pk) < 0) {
132 err = errno;
133 goto out;
134 }
135
136 if (cmd == SMBIOC_PK_CHK) {
137 if (lmhash != NULL)
138 memcpy(lmhash, pk.pk_lmhash, SMBIOC_HASH_SZ);
139 if (nthash != NULL)
140 memcpy(nthash, pk.pk_nthash, SMBIOC_HASH_SZ);
141 }
142
143 out:
144 if (fd != -1)
145 close(fd);
146
147 return (err);
148 }
149
150 /*
151 * Add a password to the keychain.
152 *
153 * Note: pass is a cleartext password.
154 * We use it here to compute the LM hash and NT hash,
155 * and then store ONLY the hashes.
156 */
157 int
158 smbfs_keychain_add(uid_t uid, const char *dom, const char *usr,
159 const char *pass)
160 {
161 uchar_t lmhash[SMBIOC_HASH_SZ];
162 uchar_t nthash[SMBIOC_HASH_SZ];
163 int err, cmd = SMBIOC_PK_ADD;
164
165 if (pass == NULL)
|
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
24 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27
28 /*
29 * External interface to the libsmbfs/netsmb keychain
30 * storage mechanism. This interface is consumed by
31 * the "smbutil" commands: login, logout, ...
32 * and by the SMBFS PAM module.
33 */
34
35 #include <sys/types.h>
36
37 #include <errno.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
42 #include <libintl.h>
43
111 case SMBIOC_PK_DEL_EVERYONE: /* all owned by everyone */
112 /*
113 * These two do not copyin any args, but we'll
114 * pass pk here anyway just so we can use the
115 * common code path below.
116 */
117 break;
118
119 default:
120 err = SMB_KEYCHAIN_UNKNOWN;
121 goto out;
122 }
123
124 fd = smb_open_driver();
125 if (fd < 0) {
126 err = SMB_KEYCHAIN_NODRIVER;
127 goto out;
128 }
129
130 err = 0;
131 if (nsmb_ioctl(fd, cmd, &pk) < 0) {
132 err = errno;
133 goto out;
134 }
135
136 if (cmd == SMBIOC_PK_CHK) {
137 if (lmhash != NULL)
138 memcpy(lmhash, pk.pk_lmhash, SMBIOC_HASH_SZ);
139 if (nthash != NULL)
140 memcpy(nthash, pk.pk_nthash, SMBIOC_HASH_SZ);
141 }
142
143 out:
144 if (fd != -1)
145 nsmb_close(fd);
146
147 return (err);
148 }
149
150 /*
151 * Add a password to the keychain.
152 *
153 * Note: pass is a cleartext password.
154 * We use it here to compute the LM hash and NT hash,
155 * and then store ONLY the hashes.
156 */
157 int
158 smbfs_keychain_add(uid_t uid, const char *dom, const char *usr,
159 const char *pass)
160 {
161 uchar_t lmhash[SMBIOC_HASH_SZ];
162 uchar_t nthash[SMBIOC_HASH_SZ];
163 int err, cmd = SMBIOC_PK_ADD;
164
165 if (pass == NULL)
|