/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* tests/s2p.c - krb5_name_to_principal test harness */2/*3* Copyright (C) 2013 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the16* distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS21* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE22* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,23* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR25* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED29* OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132#include <stdio.h>33#include <string.h>34#include <assert.h>35#include <krb5.h>3637static krb5_context ctx;3839static void40check(krb5_error_code code)41{42const char *errmsg;4344if (code) {45errmsg = krb5_get_error_message(ctx, code);46fprintf(stderr, "%s\n", errmsg);47krb5_free_error_message(ctx, errmsg);48exit(1);49}50}5152int53main(int argc, char **argv)54{55krb5_principal princ;56krb5_int32 type;57const char *service, *hostname;58char *name;5960/* Parse arguments. */61assert(argc == 4);62hostname = argv[1];63service = argv[2];64if (strcmp(argv[3], "unknown") == 0)65type = KRB5_NT_UNKNOWN;66else if (strcmp(argv[3], "srv-hst") == 0)67type = KRB5_NT_SRV_HST;68else69abort();7071check(krb5_init_context(&ctx));72check(krb5_sname_to_principal(ctx, hostname, service, type, &princ));73check(krb5_unparse_name(ctx, princ, &name));74printf("%s\n", name);7576krb5_free_unparsed_name(ctx, name);77krb5_free_principal(ctx, princ);78krb5_free_context(ctx);79return 0;80}818283