/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2014 Nexenta Systems, Inc. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <syslog.h>
#include <netdb.h>
#include <kerberosv5/krb5.h>
#include <kerberosv5/com_err.h>
#include <smbns_krb.h>
/*
* Kerberized services available on the system.
*/
/*
* Service keys are salted with the SMB_KRB_PN_ID_ID_SALT prinipal
* name.
*/
/* CIFS SPNs. (HOST, CIFS, ...) */
/* NFS */
/* HTTP */
/* ROOT */
};
#define SMB_KRB5_SPN_TAB_SZ \
(sizeof (smb_krb5_pn_tab) / sizeof (smb_krb5_pn_tab[0]))
static int smb_krb5_spn_count(uint32_t);
const char *);
const char *, krb5_principal *);
/*
* Generates a null-terminated array of principal names that
* represents the list of the available Kerberized services
* of the specified type (SPN attribute, UPN attribute, or
* keytab entry).
*
* Returns the number of principal names returned via the 1st
* output parameter (i.e. vals).
*
* Caller must invoke smb_krb5_free_spns to free the allocated
* memory when finished.
*/
{
int cnt, i;
return (0);
return (0);
tabent = &smb_krb5_pn_tab[i];
break;
continue;
"principal names: possible transient memory "
"shortage");
return (0);
}
}
}
void
{
int i;
return;
}
/*
* Initialize the kerberos context.
* Return 0 on success. Otherwise, return -1.
*/
int
{
if (krb5_init_context(ctx) != 0)
return (-1);
return (0);
}
/*
* Free the kerberos context.
*/
void
{
}
/*
* Create an array of Kerberos Princiapls given an array of principal names.
* Caller must free the allocated memory using smb_krb5_free_kprincs()
* upon success.
*
* Returns 0 on success. Otherwise, returns -1.
*/
int
{
int i;
return (-1);
}
for (i = 0; i < num; i++) {
return (-1);
}
}
return (0);
}
void
{
int i;
for (i = 0; i < num; i++)
}
/*
* Set the workstation trust account password.
* Returns 0 on success. Otherwise, returns non-zero value.
*/
int
{
int result_code = 0;
return (-1);
"find %s", SMB_CCACHE_PATH);
return (-1);
}
if (code != 0)
"exchange failed", code);
if (result_code != 0) {
if (code == 0)
}
return (code);
}
/*
* Open the keytab file for writing.
* The keytab should be closed by calling krb5_kt_close().
*/
static int
{
char *ktname;
int len;
"possible transient memory shortage", fname);
return (-1);
}
return (-1);
}
return (0);
}
/*
* Populate the keytab with keys of the specified key version for the
* specified set of krb5 principals. All service keys will be salted by:
* host/<truncated@15_lower_case_hostname>.<fqdn>@<REALM>
*/
int
{
int i, j;
return (-1);
fqdn, &salt_princ) != 0) {
return (-1);
}
if (code != 0) {
"failed", code);
return (-1);
}
for (j = 0; j < count; j++) {
for (i = 0; i < enctype_count; i++) {
return (-1);
}
}
}
return (0);
}
{
return (found);
if (smb_krb5_ctx_init(&ctx) != 0)
return (found);
&princ) != 0) {
return (found);
}
}
}
return (found);
}
/*
* Add a key of the specified encryption type for the specified principal
* to the keytab file.
* Returns 0 on success. Otherwise, returns -1.
*/
static int
const char *pw)
{
int rc = 0;
"encryption type (%d)", enctype);
return (-1);
}
"memory shortage");
return (-1);
}
if (code != 0) {
"generate key (%d)", enctype);
return (-1);
}
"add key (%d)", enctype);
rc = -1;
}
return (rc);
}
static int
{
int i, cnt;
for (i = 0, cnt = 0; i < SMB_KRB5_SPN_TAB_SZ; i++) {
cnt++;
}
return (cnt);
}
/*
* Generate the Kerberos Principal given a principal name format and the
* fully qualified domain name. On success, caller must free the allocated
* memory by calling krb5_free_principal().
*/
static int
{
char *buf;
return (-1);
return (-1);
}
return (0);
}
/*
* Looks up an entry in the principal name table given the ID.
*/
static smb_krb5_pn_t *
{
int i;
for (i = 0; i < SMB_KRB5_SPN_TAB_SZ; i++) {
tabent = &smb_krb5_pn_tab[i];
return (tabent);
}
return (NULL);
}
/*
* Construct the principal name given an ID, the requested type, and the
* fully-qualified name of the domain of which the principal is a member.
*/
static char *
const char *fqdn)
{
char *buf;
/* detect inconsistent requested format and type */
return (NULL);
switch (id) {
case SMB_KRB5_PN_ID_SALT:
break;
case SMB_KRB5_PN_ID_HOST_FQHN:
case SMB_KRB5_PN_ID_CIFS_FQHN:
case SMB_KRB5_PN_ID_NFS_FQHN:
case SMB_KRB5_PN_ID_HTTP_FQHN:
case SMB_KRB5_PN_ID_ROOT_FQHN:
break;
break;
/*
* SPN for the machine account, which is simply the
* (short) machine name with a dollar sign appended.
*/
case SMB_KRB5_PN_ID_MACHINE:
break;
default:
return (NULL);
}
/*
* If the requested principal is either added to keytab / the machine
* account as the UPN attribute or used for key salt generation,
* the principal name must have the @<REALM> portion.
*/
return (NULL);
}
(void) smb_strupr(realm);
char *tmp;
realm);
}
}
return (buf);
}