gsasl  1.8.0
init.c
Go to the documentation of this file.
00001 /* init.c --- Entry point for libgsasl.
00002  * Copyright (C) 2002-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 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 #include "openid20/openid20.h"
00040 
00041 #include "login/login.h"
00042 #include "ntlm/x-ntlm.h"
00043 #include "kerberos_v5/kerberos_v5.h"
00044 
00051 const char *GSASL_VALID_MECHANISM_CHARACTERS =
00052   "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
00053 
00054 static int
00055 register_builtin_mechs (Gsasl * ctx)
00056 {
00057   int rc = GSASL_OK;
00058 
00059 #ifdef USE_ANONYMOUS
00060   rc = gsasl_register (ctx, &gsasl_anonymous_mechanism);
00061   if (rc != GSASL_OK)
00062     return rc;
00063 #endif /* USE_ANONYMOUS */
00064 
00065 #ifdef USE_EXTERNAL
00066   rc = gsasl_register (ctx, &gsasl_external_mechanism);
00067   if (rc != GSASL_OK)
00068     return rc;
00069 #endif /* USE_EXTERNAL */
00070 
00071 #ifdef USE_LOGIN
00072   rc = gsasl_register (ctx, &gsasl_login_mechanism);
00073   if (rc != GSASL_OK)
00074     return rc;
00075 #endif /* USE_LOGIN */
00076 
00077 #ifdef USE_PLAIN
00078   rc = gsasl_register (ctx, &gsasl_plain_mechanism);
00079   if (rc != GSASL_OK)
00080     return rc;
00081 #endif /* USE_PLAIN */
00082 
00083 #ifdef USE_SECURID
00084   rc = gsasl_register (ctx, &gsasl_securid_mechanism);
00085   if (rc != GSASL_OK)
00086     return rc;
00087 #endif /* USE_SECURID */
00088 
00089 #ifdef USE_NTLM
00090   rc = gsasl_register (ctx, &gsasl_ntlm_mechanism);
00091   if (rc != GSASL_OK)
00092     return rc;
00093 #endif /* USE_NTLM */
00094 
00095 #ifdef USE_DIGEST_MD5
00096   rc = gsasl_register (ctx, &gsasl_digest_md5_mechanism);
00097   if (rc != GSASL_OK)
00098     return rc;
00099 #endif /* USE_DIGEST_MD5 */
00100 
00101 #ifdef USE_CRAM_MD5
00102   rc = gsasl_register (ctx, &gsasl_cram_md5_mechanism);
00103   if (rc != GSASL_OK)
00104     return rc;
00105 #endif /* USE_CRAM_MD5 */
00106 
00107 #ifdef USE_SCRAM_SHA1
00108   rc = gsasl_register (ctx, &gsasl_scram_sha1_mechanism);
00109   if (rc != GSASL_OK)
00110     return rc;
00111 
00112   rc = gsasl_register (ctx, &gsasl_scram_sha1_plus_mechanism);
00113   if (rc != GSASL_OK)
00114     return rc;
00115 #endif /* USE_SCRAM_SHA1 */
00116 
00117 #ifdef USE_SAML20
00118   rc = gsasl_register (ctx, &gsasl_saml20_mechanism);
00119   if (rc != GSASL_OK)
00120     return rc;
00121 #endif /* USE_SAML20 */
00122 
00123 #ifdef USE_OPENID20
00124   rc = gsasl_register (ctx, &gsasl_openid20_mechanism);
00125   if (rc != GSASL_OK)
00126     return rc;
00127 #endif /* USE_OPENID20 */
00128 
00129 #ifdef USE_GSSAPI
00130   rc = gsasl_register (ctx, &gsasl_gssapi_mechanism);
00131   if (rc != GSASL_OK)
00132     return rc;
00133 #endif /* USE_GSSAPI */
00134 
00135 #ifdef USE_GS2
00136   rc = gsasl_register (ctx, &gsasl_gs2_krb5_mechanism);
00137   if (rc != GSASL_OK)
00138     return rc;
00139 #endif /* USE_GSSAPI */
00140 
00141   return GSASL_OK;
00142 }
00143 
00156 int
00157 gsasl_init (Gsasl ** ctx)
00158 {
00159   int rc;
00160 
00161   if (gc_init () != GC_OK)
00162     return GSASL_CRYPTO_ERROR;
00163 
00164   *ctx = (Gsasl *) calloc (1, sizeof (**ctx));
00165   if (*ctx == NULL)
00166     return GSASL_MALLOC_ERROR;
00167 
00168   rc = register_builtin_mechs (*ctx);
00169   if (rc != GSASL_OK)
00170     {
00171       gsasl_done (*ctx);
00172       return rc;
00173     }
00174 
00175   return GSASL_OK;
00176 }