keychain.c revision 4bff34e37def8a90f9194d81bc345c52ba20086a
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER START
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The contents of this file are subject to the terms of the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Common Development and Distribution License (the "License").
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You may not use this file except in compliance with the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * See the License for the specific language governing permissions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * and limitations under the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * When distributing Covered Code, include this CDDL HEADER in each
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If applicable, add the following below this CDDL HEADER, with the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * fields enclosed by brackets "[]" replaced with your own identifying
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * information: Portions Copyright [yyyy] [name of copyright owner]
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER END
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Use is subject to license terms.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#pragma ident "%Z%%M% %I% %E% SMI"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * External interface to the libsmbfs/netsmb keychain
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * storage mechanism. This interface is consumed by
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * the "smbutil" commands: login, logout, ...
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * and by the SMBFS PAM module.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/* common func. for add/del/chk */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow const char *dom,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow const char *usr,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow const char *pass)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (strlcpy(pk.pk_pass, pass, sizeof (pk.pk_pass)) >=
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* FALLTHROUGH */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SMBIOC_PK_DEL_OWNER: /* all owned by the caller */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SMBIOC_PK_DEL_EVERYONE: /* all owned by everyone */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * These two do not copyin any args, but we'll
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * pass &pk here anyway just so we can use the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * common code path below.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/* Add a password to the keychain. */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmbfs_keychain_add(uid_t uid, const char *dom, const char *usr,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow const char *pass)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (smbfs_keychain_cmn(SMBIOC_PK_ADD, uid, dom, usr, pass));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/* Delete a password from the keychain. */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmbfs_keychain_del(uid_t uid, const char *dom, const char *usr)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (smbfs_keychain_cmn(SMBIOC_PK_DEL, uid, dom, usr, NULL));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Check for existence of a keychain entry.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Returns 0 if it exists, else ENOENT.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (smbfs_keychain_cmn(SMBIOC_PK_CHK, (uid_t)-1, dom, usr, NULL));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Delete all keychain entries owned by the caller.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (smbfs_keychain_cmn(SMBIOC_PK_DEL_OWNER, getuid(), 0, 0, 0));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Delete all keychain entries (regardless of onwer).
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Requires super-user privliege.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (smbfs_keychain_cmn(SMBIOC_PK_DEL_EVERYONE, getuid(), 0, 0, 0));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * This is not really part of the keychain library,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * but is typically needed in code that wants to
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * provide (editable) defaults for domain/user
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Get default domain and user names
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Server name is optional.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmbfs_default_dom_usr(const char *home, const char *server,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow err = smb_ctx_init(ctx, 0, NULL, SMBL_VC, SMBL_VC, SMB_ST_ANY);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (0);