init.c

Go to the documentation of this file.
00001 /* init.c --- Entry point for libgsasl.
00002  * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010  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 License along with GNU SASL Library; if not, write to the
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "internal.h"
00024 
00025 /* Get gc_init. */
00026 #include <gc.h>
00027 
00028 /* Get mechanism headers. */
00029 #include "cram-md5/cram-md5.h"
00030 #include "external/external.h"
00031 #include "gssapi/x-gssapi.h"
00032 #include "gs2/gs2.h"
00033 #include "anonymous/anonymous.h"
00034 #include "plain/plain.h"
00035 #include "securid/securid.h"
00036 #include "digest-md5/digest-md5.h"
00037 #include "scram/scram.h"
00038 #include "saml20/saml20.h"
00039 
00040 #include "login/login.h"
00041 #include "ntlm/x-ntlm.h"
00042 #include "kerberos_v5/kerberos_v5.h"
00043 
00050 const char *GSASL_VALID_MECHANISM_CHARACTERS =
00051   "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
00052 
00053 static int
00054 register_builtin_mechs (Gsasl * ctx)
00055 {
00056   int rc = GSASL_OK;
00057 
00058 #ifdef USE_ANONYMOUS
00059   rc = gsasl_register (ctx, &gsasl_anonymous_mechanism);
00060   if (rc != GSASL_OK)
00061     return rc;
00062 #endif /* USE_ANONYMOUS */
00063 
00064 #ifdef USE_EXTERNAL
00065   rc = gsasl_register (ctx, &gsasl_external_mechanism);
00066   if (rc != GSASL_OK)
00067     return rc;
00068 #endif /* USE_EXTERNAL */
00069 
00070 #ifdef USE_LOGIN
00071   rc = gsasl_register (ctx, &gsasl_login_mechanism);
00072   if (rc != GSASL_OK)
00073     return rc;
00074 #endif /* USE_LOGIN */
00075 
00076 #ifdef USE_PLAIN
00077   rc = gsasl_register (ctx, &gsasl_plain_mechanism);
00078   if (rc != GSASL_OK)
00079     return rc;
00080 #endif /* USE_PLAIN */
00081 
00082 #ifdef USE_SECURID
00083   rc = gsasl_register (ctx, &gsasl_securid_mechanism);
00084   if (rc != GSASL_OK)
00085     return rc;
00086 #endif /* USE_SECURID */
00087 
00088 #ifdef USE_NTLM
00089   rc = gsasl_register (ctx, &gsasl_ntlm_mechanism);
00090   if (rc != GSASL_OK)
00091     return rc;
00092 #endif /* USE_NTLM */
00093 
00094 #ifdef USE_DIGEST_MD5
00095   rc = gsasl_register (ctx, &gsasl_digest_md5_mechanism);
00096   if (rc != GSASL_OK)
00097     return rc;
00098 #endif /* USE_DIGEST_MD5 */
00099 
00100 #ifdef USE_CRAM_MD5
00101   rc = gsasl_register (ctx, &gsasl_cram_md5_mechanism);
00102   if (rc != GSASL_OK)
00103     return rc;
00104 #endif /* USE_CRAM_MD5 */
00105 
00106 #ifdef USE_SCRAM_SHA1
00107   rc = gsasl_register (ctx, &gsasl_scram_sha1_mechanism);
00108   if (rc != GSASL_OK)
00109     return rc;
00110 #endif /* USE_SCRAM_SHA1 */
00111 
00112 #ifdef USE_SAML20
00113   rc = gsasl_register (ctx, &gsasl_saml20_mechanism);
00114   if (rc != GSASL_OK)
00115     return rc;
00116 #endif /* USE_SAML20 */
00117 
00118 #ifdef USE_GSSAPI
00119   rc = gsasl_register (ctx, &gsasl_gssapi_mechanism);
00120   if (rc != GSASL_OK)
00121     return rc;
00122 #endif /* USE_GSSAPI */
00123 
00124 #ifdef USE_GS2
00125   rc = gsasl_register (ctx, &gsasl_gs2_krb5_mechanism);
00126   if (rc != GSASL_OK)
00127     return rc;
00128 #endif /* USE_GSSAPI */
00129 
00130   return GSASL_OK;
00131 }
00132 
00145 int
00146 gsasl_init (Gsasl ** ctx)
00147 {
00148   int rc;
00149 
00150   if (gc_init () != GC_OK)
00151     return GSASL_CRYPTO_ERROR;
00152 
00153   *ctx = (Gsasl *) calloc (1, sizeof (**ctx));
00154   if (*ctx == NULL)
00155     return GSASL_MALLOC_ERROR;
00156 
00157   rc = register_builtin_mechs (*ctx);
00158   if (rc != GSASL_OK)
00159     {
00160       gsasl_done (*ctx);
00161       return rc;
00162     }
00163 
00164   return GSASL_OK;
00165 }