smbns_ksetpwd.c revision bbf6f00c25b6a2bed23c35eac6d62998ecdb338c
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#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>
krb5_keytab *kt);
const char *pw);
/*
* smb_krb5_get_spn
*
* Gets Service Principal Name.
* Caller must free the memory allocated for the spn.
*/
char *
{
int len;
char *princ;
char *spn;
if (!fqhost)
return (NULL);
return (NULL);
if (!princ)
return (NULL);
return (princ);
}
/*
* smb_krb5_get_upn
*
* Gets User Principal Name.
* Caller must free the memory allocated for the upn.
*/
char *
{
int len;
char *realm;
char *upn;
return (NULL);
if (!realm)
return (NULL);
(void) smb_strupr(realm);
if (!upn) {
return (NULL);
}
return (upn);
}
/*
* smb_krb5_get_host_upn
*
* Derives UPN by the given fully-qualified hostname.
* Caller must free the memory allocated for the upn.
*/
static char *
smb_krb5_get_host_upn(const char *fqhn)
{
char *upn;
char *realm;
char *dom;
int len;
return (NULL);
return (NULL);
(void) smb_strupr(realm);
return (NULL);
}
return (upn);
}
/*
* smb_krb5_ctx_init
*
* Initialize the kerberos context.
* Return 0 on success. Otherwise, return -1.
*/
int
{
if (krb5_init_context(ctx) != 0)
return (-1);
return (0);
}
/*
* smb_krb5_get_principals
*
* Setup the krb5_principal array given the principals in string format.
* Return 0 on success. Otherwise, return -1.
*/
int
{
char fqhn[MAXHOSTNAMELEN];
int i;
return (-1);
domain);
for (i = 0; i < SMBKRB5_SPN_IDX_MAX; i++) {
return (-1);
}
return (-1);
}
}
return (0);
}
void
{
int i;
for (i = 0; i < num; i++)
}
/*
* smb_krb5_ctx_fini
*
* Free the kerberos context.
*/
void
{
}
/*
* smb_ksetpw
*
* Set the workstation trust account password.
* Returns 0 on success. Otherwise, returns non-zero value.
*/
int
{
int result_code;
return (-1);
}
if (code != 0)
"smb_krb5_setpwd: Result: %.*s (%d) %.*s\n",
result_code == 0 ?
return (code);
}
/*
* smb_krb5_open_wrfile
*
* Open the keytab file for writing.
* The keytab should be closed by calling krb5_kt_close().
*/
static int
{
char *ktname;
int len;
return (-1);
}
"keytab %s\n", fname);
return (-1);
}
return (0);
}
/*
* smb_krb5_add_keytab_entries
*
* Update the keys for the specified principal in the keytab.
* Returns 0 on success. Otherwise, returns -1.
*/
int
int enctype_count)
{
int i, j;
return (-1);
for (j = 0; j < SMBKRB5_SPN_IDX_MAX; j++) {
for (i = 0; i < enctype_count; i++) {
return (-1);
}
}
}
return (0);
}
{
char ktname[MAXPATHLEN];
char *upn;
return (found);
return (found);
if (smb_krb5_ctx_init(&ctx) != 0) {
return (found);
}
return (found);
}
}
}
return (found);
}
/*
* smb_krb5_ktadd
*
* Add a Keberos key to the keytab file.
* Returns 0 on success. Otherwise, returns -1.
*/
static int
{
char buf[100];
int rc = 0;
enctype);
return (-1);
}
enctype);
return (-1);
}
enctype);
return (-1);
}
if (code != 0) {
enctype);
return (-1);
}
rc = -1;
}
return (rc);
}