ktutil_funcs.c revision e49962a00eea60555f3c78ebf58a9a641590802c
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
*(C) Copyright 1995, 1996 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
* require a specific license from the United States Government.
* It is the responsibility of any person or organization contemplating
* export to obtain such a license before exporting.
*
* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
* distribute this software and its documentation for any purpose and
* without fee is hereby granted, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation, and that
* the name of M.I.T. not be used in advertising or publicity pertaining
* to distribution of the software without specific, written prior
* permission. Furthermore if you modify this software you must label
* your software as modified software and not distribute it in such a
* fashion that it might be confused with the original M.I.T. software.
* M.I.T. makes no representations about the suitability of
* this software for any purpose. It is provided "as is" without express
* or implied warranty.
*
* Utility functions for ktutil.
*/
#include "k5-int.h"
#include "ktutil.h"
#ifdef KRB5_KRB4_COMPAT
#include "kerberosIV/krb.h"
#include <stdio.h>
#endif
#include <string.h>
#include <ctype.h>
#include <libintl.h>
/*
* Free a kt_list
*/
{
krb5_error_code retval = 0;
if (retval)
break;
}
return retval;
}
/*
* Delete a numbered entry in a kt_list. Takes a pointer to a kt_list
* in case head gets deleted.
*/
int index;
{
int i;
if (i == index) {
if (i == 1)
else
}
}
return EINVAL;
}
/*
* Create a new keytab entry and add it to the keytab list.
* Based on the value of use_pass, either prompt the user for a
* password or key. If the keytab list is NULL, allocate a new
* one first.
*/
char *princ_str;
char *enctype_str;
int use_pass;
{
char promptstr[1024];
char *cp;
if (retval)
return retval;
/* now unparse in order to get the default realm appended
to princ_str, if no realm was specified */
if (retval)
return retval;
if (retval)
return KRB5_BAD_ENCTYPE;
if (retval)
return retval;
if (*list) {
/* point lp at the tail of the list */
}
if (!entry) {
return ENOMEM;
}
if (!lp) { /* if list is empty, start one */
if (!lp) {
return ENOMEM;
}
} else {
return ENOMEM;
}
}
if (use_pass) {
goto cleanup;
}
if (retval)
goto cleanup;
if (retval)
goto cleanup;
if (retval)
goto cleanup;
} else {
/*
* We need to get rid of the trailing '\n' from fgets.
* If we have an even number of hex digits (as we should),
* write a '\0' over the '\n'. If for some reason we have
* an odd number of hex digits, force an even number of hex
* digits by writing a '0' into the last position (the string
* will still be null-terminated).
*/
retval = 0;
goto cleanup;
}
goto cleanup;
}
i = 0;
gettext("Illegal character in key.\n"));
retval = 0;
goto cleanup;
}
}
}
if (!*list)
return 0;
if (prev)
return retval;
}
/*
* Read in a keytab and append it to list. If list starts as NULL,
* allocate a new one if necessary.
*/
char *name;
{
krb5_error_code retval = 0;
if (*list) {
/* point lp at the tail of the list */
}
if (retval)
return retval;
if (retval)
goto close_kt;
for (;;) {
if (!entry) {
break;
}
if (retval)
break;
if (!lp) { /* if list is empty, start one */
if (!lp) {
break;
}
} else {
break;
}
}
if (!tail)
}
if (entry)
if (retval)
if (retval == KRB5_KT_END)
retval = 0;
else {
if (back)
}
if (!*list)
return retval;
}
/*
* Takes a kt_list and writes it to the named keytab.
*/
char *name;
{
krb5_error_code retval = 0;
return ENAMETOOLONG;
if (retval)
return retval;
if (retval)
break;
}
return retval;
}
#ifdef KRB5_KRB4_COMPAT
/*
* getstr() takes a file pointer, a string and a count. It reads from
* the file until either it has read "count" characters, or until it
* reads a null byte. When finished, what has been read exists in the
* given string "s". If "count" characters were actually read, the
* last is changed to a null, so the returned string is always null-
* terminated. getstr() returns the number of characters read,
* including the null terminator.
*/
register char *s;
int n;
{
register count = n;
if (*s++ == '\0')
return (n - count);
*s = '\0';
return (n - count);
}
/*
* Read in a named krb4 srvtab and append to list. Allocate new list
* if needed.
*/
char *name;
{
krb5_error_code retval = 0;
unsigned char kvno; /* key version number */
if (*list) {
/* point lp at the tail of the list */
}
if (!fp)
return EIO;
for (;;) {
if (!entry) {
break;
}
break;
if (retval)
break;
break;
}
if (!lp) { /* if list is empty, start one */
if (!lp) {
break;
}
} else {
break;
}
}
if (!tail)
}
if (entry) {
}
if (retval) {
if (back)
}
if (!*list)
return retval;
}
/*
* Writes a kt_list out to a krb4 srvtab file. Note that it first
* prunes the kt_list so that it won't contain any keys that are not
* the most recent, and ignores keys that are not ENCTYPE_DES.
*/
char *name;
{
krb5_error_code retval = 0;
/* First do heinous stuff to prune the list. */
continue;
/* Hunt for the current principal in the pruned list */
break;
}
if (!lp1) { /* need to add entry to tail of pruned list */
if (!pruned) {
if (!pruned)
return ENOMEM;
} else {
goto free_pruned;
}
}
/* Check if lp->entry is newer kvno; if so, update */
}
if (!fp) {
goto free_pruned;
}
unsigned char kvno;
if (retval)
break;
}
/*
* Loop over and free the pruned list; don't use free_kt_list
* because that kills the entries.
*/
}
return retval;
}
#endif /* KRB5_KRB4_COMPAT */