gsasl  2.2.1
init.c
Go to the documentation of this file.
1 /* init.c --- Entry point for libgsasl.
2  * Copyright (C) 2002-2024 Simon Josefsson
3  *
4  * This file is part of GNU SASL Library.
5  *
6  * GNU SASL Library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * GNU SASL Library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License License along with GNU SASL Library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include <config.h>
24 #include "internal.h"
25 
26 /* Get gc_init. */
27 #include <gc.h>
28 
29 /* Get mechanism headers. */
30 #include "cram-md5/cram-md5.h"
31 #include "external/external.h"
32 #include "gssapi/x-gssapi.h"
33 #include "gs2/gs2.h"
34 #include "anonymous/anonymous.h"
35 #include "plain/plain.h"
36 #include "securid/securid.h"
37 #include "digest-md5/digest-md5.h"
38 #include "scram/scram.h"
39 #include "saml20/saml20.h"
40 #include "openid20/openid20.h"
41 
42 #include "login/login.h"
43 #include "ntlm/x-ntlm.h"
44 
45 static int
46 register_builtin_mechs (Gsasl *ctx)
47 {
48  int rc = GSASL_OK;
49 
50 #ifdef USE_ANONYMOUS
52  if (rc != GSASL_OK)
53  return rc;
54 #endif /* USE_ANONYMOUS */
55 
56 #ifdef USE_EXTERNAL
58  if (rc != GSASL_OK)
59  return rc;
60 #endif /* USE_EXTERNAL */
61 
62 #ifdef USE_LOGIN
64  if (rc != GSASL_OK)
65  return rc;
66 #endif /* USE_LOGIN */
67 
68 #ifdef USE_PLAIN
70  if (rc != GSASL_OK)
71  return rc;
72 #endif /* USE_PLAIN */
73 
74 #ifdef USE_SECURID
76  if (rc != GSASL_OK)
77  return rc;
78 #endif /* USE_SECURID */
79 
80 #ifdef USE_NTLM
82  if (rc != GSASL_OK)
83  return rc;
84 #endif /* USE_NTLM */
85 
86 #ifdef USE_DIGEST_MD5
88  if (rc != GSASL_OK)
89  return rc;
90 #endif /* USE_DIGEST_MD5 */
91 
92 #ifdef USE_CRAM_MD5
94  if (rc != GSASL_OK)
95  return rc;
96 #endif /* USE_CRAM_MD5 */
97 
98 #ifdef USE_SCRAM_SHA1
99  rc = gsasl_register (ctx, &_gsasl_scram_sha1_mechanism);
100  if (rc != GSASL_OK)
101  return rc;
102 
103  rc = gsasl_register (ctx, &_gsasl_scram_sha1_plus_mechanism);
104  if (rc != GSASL_OK)
105  return rc;
106 #endif /* USE_SCRAM_SHA1 */
107 
108 #ifdef USE_SCRAM_SHA256
109  rc = gsasl_register (ctx, &_gsasl_scram_sha256_mechanism);
110  if (rc != GSASL_OK)
111  return rc;
112 
113  rc = gsasl_register (ctx, &_gsasl_scram_sha256_plus_mechanism);
114  if (rc != GSASL_OK)
115  return rc;
116 #endif /* USE_SCRAM_SHA256 */
117 
118 #ifdef USE_SAML20
120  if (rc != GSASL_OK)
121  return rc;
122 #endif /* USE_SAML20 */
123 
124 #ifdef USE_OPENID20
126  if (rc != GSASL_OK)
127  return rc;
128 #endif /* USE_OPENID20 */
129 
130 #ifdef USE_GSSAPI
132  if (rc != GSASL_OK)
133  return rc;
134 #endif /* USE_GSSAPI */
135 
136 #ifdef USE_GS2
138  if (rc != GSASL_OK)
139  return rc;
140 #endif /* USE_GSSAPI */
141 
142  return GSASL_OK;
143 }
144 
157 int
159 {
160  int rc;
161 
162  if (gc_init () != GC_OK)
163  return GSASL_CRYPTO_ERROR;
164 
165  *ctx = (Gsasl *) calloc (1, sizeof (**ctx));
166  if (*ctx == NULL)
167  return GSASL_MALLOC_ERROR;
168 
169  rc = register_builtin_mechs (*ctx);
170  if (rc != GSASL_OK)
171  {
172  gsasl_done (*ctx);
173  return rc;
174  }
175 
176  return GSASL_OK;
177 }
Gsasl_mechanism _gsasl_anonymous_mechanism
Gsasl_mechanism _gsasl_cram_md5_mechanism
Gsasl_mechanism _gsasl_digest_md5_mechanism
void gsasl_done(Gsasl *ctx)
Definition: done.c:34
int rc
Definition: error.c:37
Gsasl_mechanism _gsasl_external_mechanism
Gsasl_mechanism _gsasl_gs2_krb5_mechanism
Definition: gs2/mechinfo.c:28
_GSASL_API int gsasl_register(Gsasl *ctx, const Gsasl_mechanism *mech)
Definition: register.c:39
@ GSASL_OK
Definition: gsasl.h:129
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:133
@ GSASL_CRYPTO_ERROR
Definition: gsasl.h:135
Gsasl_mechanism _gsasl_gssapi_mechanism
int gsasl_init(Gsasl **ctx)
Definition: init.c:158
Gsasl_mechanism _gsasl_login_mechanism
Gsasl_mechanism _gsasl_ntlm_mechanism
Definition: ntlm/mechinfo.c:28
Gsasl_mechanism _gsasl_openid20_mechanism
Gsasl_mechanism _gsasl_plain_mechanism
Gsasl_mechanism _gsasl_saml20_mechanism
Gsasl_mechanism _gsasl_securid_mechanism
Definition: internal.h:37