Path: blob/main/crypto/heimdal/lib/kadm5/default_keys.c
34878 views
/*1* Copyright (c) 2003 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233#include "kadm5_locl.h"34#include <err.h>3536RCSID("$Id$");3738static void39print_keys(krb5_context context, Key *keys, size_t nkeys)40{41krb5_error_code ret;42char *str;43int i;4445printf("keys:\n");4647for (i = 0; i < nkeys; i++) {4849ret = krb5_enctype_to_string(context, keys[i].key.keytype, &str);50if (ret)51krb5_err(context, ret, 1, "krb5_enctype_to_string: %d\n",52(int)keys[i].key.keytype);5354printf("\tenctype %s", str);55free(str);5657if (keys[i].salt) {58printf(" salt: ");5960switch (keys[i].salt->type) {61case KRB5_PW_SALT:62printf("pw-salt:");63break;64case KRB5_AFS3_SALT:65printf("afs3-salt:");66break;67default:68printf("unknown salt: %d", keys[i].salt->type);69break;70}71if (keys[i].salt->salt.length)72printf("%.*s", (int)keys[i].salt->salt.length,73(char *)keys[i].salt->salt.data);74}75printf("\n");76}77printf("end keys:\n");78}7980static void81parse_file(krb5_context context, krb5_principal principal, int no_salt)82{83krb5_error_code ret;84size_t nkeys;85Key *keys;8687ret = hdb_generate_key_set(context, principal, &keys, &nkeys, no_salt);88if (ret)89krb5_err(context, 1, ret, "hdb_generate_key_set");9091print_keys(context, keys, nkeys);9293hdb_free_keys(context, nkeys, keys);94}9596int97main(int argc, char **argv)98{99krb5_error_code ret;100krb5_context context;101krb5_principal principal;102103ret = krb5_init_context(&context);104if (ret)105errx(1, "krb5_init_context");106107ret = krb5_parse_name(context, "[email protected]", &principal);108if (ret)109krb5_err(context, ret, 1, "krb5_parse_name");110111parse_file(context, principal, 0);112parse_file(context, principal, 1);113114krb5_free_principal(context, principal);115116krb5_free_context(context);117118return 0;119}120121122