Path: blob/main/crypto/krb5/src/tests/gssapi/t_saslname.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 2009 by the Massachusetts Institute of Technology.3* All Rights Reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425#include <stdio.h>26#include <stdlib.h>27#include <string.h>2829#include "common.h"3031static void32dump_known_mech_attrs(gss_OID mech)33{34OM_uint32 major, minor;35gss_OID_set mech_attrs = GSS_C_NO_OID_SET;36gss_OID_set known_attrs = GSS_C_NO_OID_SET;37size_t i;3839major = gss_inquire_attrs_for_mech(&minor, mech, &mech_attrs,40&known_attrs);41check_gsserr("gss_inquire_attrs_for_mech", major, minor);4243printf("Known attributes\n");44printf("----------------\n");45for (i = 0; i < known_attrs->count; i++) {46gss_buffer_desc name = GSS_C_EMPTY_BUFFER;47gss_buffer_desc short_desc = GSS_C_EMPTY_BUFFER;48gss_buffer_desc long_desc = GSS_C_EMPTY_BUFFER;4950major = gss_display_mech_attr(&minor, &known_attrs->elements[i],51&name, &short_desc, &long_desc);52check_gsserr("gss_display_mech_attr", major, minor);53printf("%.*s (%.*s): %.*s\n", (int)short_desc.length,54(char *)short_desc.value, (int)name.length, (char *)name.value,55(int)long_desc.length, (char *)long_desc.value);56(void)gss_release_buffer(&minor, &name);57(void)gss_release_buffer(&minor, &short_desc);58(void)gss_release_buffer(&minor, &long_desc);59}60printf("\n");61(void)gss_release_oid_set(&minor, &mech_attrs);62(void)gss_release_oid_set(&minor, &known_attrs);63}6465static void66dump_mech_attrs(gss_OID mech)67{68OM_uint32 major, minor;69gss_OID_set mech_attrs = GSS_C_NO_OID_SET;70gss_OID_set known_attrs = GSS_C_NO_OID_SET;71size_t i;7273major = gss_inquire_attrs_for_mech(&minor, mech, &mech_attrs,74&known_attrs);75check_gsserr("gss_inquire_attrs_for_mech", major, minor);7677printf("Mech attrs: ");7879for (i = 0; i < mech_attrs->count; i++) {80gss_buffer_desc name = GSS_C_EMPTY_BUFFER;81gss_buffer_desc short_desc = GSS_C_EMPTY_BUFFER;82gss_buffer_desc long_desc = GSS_C_EMPTY_BUFFER;8384major = gss_display_mech_attr(&minor, &mech_attrs->elements[i],85&name, &short_desc, &long_desc);86check_gsserr("gss_display_mech_attr", major, minor);87printf("%.*s ", (int)name.length, (char *)name.value);88(void)gss_release_buffer(&minor, &name);89(void)gss_release_buffer(&minor, &short_desc);90(void)gss_release_buffer(&minor, &long_desc);91}92printf("\n");9394(void)gss_release_oid_set(&minor, &mech_attrs);95(void)gss_release_oid_set(&minor, &known_attrs);96}9798int99main(int argc, char *argv[])100{101gss_OID_set mechs;102OM_uint32 major, minor;103size_t i;104105major = gss_indicate_mechs(&minor, &mechs);106check_gsserr("gss_indicate_mechs", major, minor);107if (mechs->count > 0)108dump_known_mech_attrs(mechs->elements);109110for (i = 0; i < mechs->count; i++) {111gss_buffer_desc oidstr = GSS_C_EMPTY_BUFFER;112gss_buffer_desc sasl_mech_name = GSS_C_EMPTY_BUFFER;113gss_buffer_desc mech_name = GSS_C_EMPTY_BUFFER;114gss_buffer_desc mech_description = GSS_C_EMPTY_BUFFER;115gss_OID oid = GSS_C_NO_OID;116117major = gss_oid_to_str(&minor, &mechs->elements[i], &oidstr);118if (GSS_ERROR(major))119continue;120121major = gss_inquire_saslname_for_mech(&minor, &mechs->elements[i],122&sasl_mech_name, &mech_name,123&mech_description);124if (GSS_ERROR(major)) {125gss_release_buffer(&minor, &oidstr);126continue;127}128129printf("-------------------------------------------------------------"130"-----------------\n");131printf("OID : %.*s\n", (int)oidstr.length,132(char *)oidstr.value);133printf("SASL mech : %.*s\n", (int)sasl_mech_name.length,134(char *)sasl_mech_name.value);135printf("Mech name : %.*s\n", (int)mech_name.length,136(char *)mech_name.value);137printf("Mech desc : %.*s\n", (int)mech_description.length,138(char *)mech_description.value);139dump_mech_attrs(&mechs->elements[i]);140printf("-------------------------------------------------------------"141"-----------------\n");142143major = gss_inquire_mech_for_saslname(&minor, &sasl_mech_name, &oid);144check_gsserr("gss_inquire_mech_for_saslname", major, minor);145146if (oid == GSS_C_NO_OID ||147(oid->length != mechs->elements[i].length &&148memcmp(oid->elements, mechs->elements[i].elements,149oid->length) != 0)) {150(void)gss_release_buffer(&minor, &oidstr);151(void)gss_oid_to_str(&minor, oid, &oidstr);152fprintf(stderr, "Got different OID %.*s for mechanism %.*s\n",153(int)oidstr.length, (char *)oidstr.value,154(int)sasl_mech_name.length, (char *)sasl_mech_name.value);155}156(void)gss_release_buffer(&minor, &oidstr);157(void)gss_release_buffer(&minor, &sasl_mech_name);158(void)gss_release_buffer(&minor, &mech_name);159(void)gss_release_buffer(&minor, &mech_description);160}161162(void)gss_release_oid_set(&minor, &mechs);163return 0;164}165166167