gsasl  1.8.0
gs2helper.c
Go to the documentation of this file.
00001 /* gs2helper.c --- GS2 helper functions common to client and server.
00002  * Copyright (C) 2010-2012 Simon Josefsson
00003  *
00004  * This file is part of GNU SASL Library.
00005  *
00006  * GNU SASL Library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public License
00008  * as published by the Free Software Foundation; either version 2.1 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * GNU SASL Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with GNU SASL Library; if not, write to the Free
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026 
00027 /* Get strcmp. */
00028 #include <string.h>
00029 
00030 /* Get malloc, free. */
00031 #include <stdlib.h>
00032 
00033 /* Get specification. */
00034 #include "gs2helper.h"
00035 
00036 /* Populate mech_oid with OID for the current SASL mechanism name.  A
00037    bit silly given that we only support Kerberos V5 today, but will be
00038    useful when that changes.  */
00039 int
00040 gs2_get_oid (Gsasl_session * sctx, gss_OID * mech_oid)
00041 {
00042   gss_buffer_desc sasl_mech_name;
00043   OM_uint32 maj_stat, min_stat;
00044 
00045   sasl_mech_name.value = (void *) gsasl_mechanism_name (sctx);
00046   if (!sasl_mech_name.value)
00047     return GSASL_AUTHENTICATION_ERROR;
00048   sasl_mech_name.length = strlen (sasl_mech_name.value);
00049 
00050   maj_stat = gss_inquire_mech_for_saslname (&min_stat, &sasl_mech_name,
00051                                             mech_oid);
00052   if (GSS_ERROR (maj_stat))
00053     return GSASL_GSSAPI_INQUIRE_MECH_FOR_SASLNAME_ERROR;
00054 
00055   return GSASL_OK;
00056 }