Path: blob/main/crypto/krb5/src/tests/gssapi/t_imp_name.c
34923 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 1996, 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/*26* Simple test program for testing how GSSAPI import name works. (May27* be made into a more full-fledged test program later.)28*/2930#include <stdio.h>31#include <string.h>3233#include "common.h"3435static const char *36oid_str(char type)37{38switch (type) {39case 'p': /* GSS_KRB5_NT_PRINCIPAL_NAME */40return "{ 1 2 840 113554 1 2 2 1 }";41case 'e': /* GSS_KRB5_NT_ENTERPRISE_NAME */42return "{ 1 2 840 113554 1 2 2 6 }";43case 'c': /* GSS_KRB5_NT_X509_CERT */44return "{ 1 2 840 113554 1 2 2 7 }";45case 'h': /* GSS_C_NT_HOSTBASED_SERVICE */46return "{ 1 2 840 113554 1 2 1 4 }";47}48return "no_oid";49}5051/* Return true if buf has the same contents as str, plus a zero byte if52* indicated by buf_includes_nullterm. */53static int54buf_eq_str(gss_buffer_t buf, const char *str, int buf_includes_nullterm)55{56size_t len = strlen(str) + (buf_includes_nullterm ? 1 : 0);5758return (buf->length == len && memcmp(buf->value, str, len) == 0);59}6061static void62test_import_name(const char *name)63{64OM_uint32 major, minor;65gss_name_t gss_name;66gss_buffer_desc buf;67gss_OID name_oid;6869gss_name = import_name(name);7071major = gss_display_name(&minor, gss_name, &buf, &name_oid);72check_gsserr("gss_display_name", major, minor);73if (!buf_eq_str(&buf, name + 2, 0))74errout("wrong name string");75(void)gss_release_buffer(&minor, &buf);7677major = gss_oid_to_str(&minor, name_oid, &buf);78check_gsserr("gss_oid_to_str", major, minor);79if (!buf_eq_str(&buf, oid_str(*name), 1))80errout("wrong name type");81(void)gss_release_buffer(&minor, &buf);82(void)gss_release_name(&minor, &gss_name);83}8485int86main(int argc, char **argv)87{88test_import_name("p:[email protected]");89test_import_name("e:[email protected]@MIT.EDU");90test_import_name("h:[email protected]");9192return 0;93}949596