gsasl  2.2.2
init.c
Go to the documentation of this file.
1 /* init.c --- Entry point for libgsasl.
2  * Copyright (C) 2002-2025 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 along with GNU SASL Library; if not, see
18  * <https://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #include <config.h>
23 #include "internal.h"
24 
25 /* Get gc_init. */
26 #include <gc.h>
27 
28 /* Get mechanism headers. */
29 #include "cram-md5/cram-md5.h"
30 #include "external/external.h"
31 #include "gssapi/x-gssapi.h"
32 #include "gs2/gs2.h"
33 #include "anonymous/anonymous.h"
34 #include "plain/plain.h"
35 #include "securid/securid.h"
36 #include "digest-md5/digest-md5.h"
37 #include "scram/scram.h"
38 #include "saml20/saml20.h"
39 #include "openid20/openid20.h"
40 
41 #include "login/login.h"
42 #include "ntlm/x-ntlm.h"
43 
44 static int
45 register_builtin_mechs (Gsasl *ctx)
46 {
47  int rc = GSASL_OK;
48 
49 #ifdef USE_ANONYMOUS
51  if (rc != GSASL_OK)
52  return rc;
53 #endif /* USE_ANONYMOUS */
54 
55 #ifdef USE_EXTERNAL
57  if (rc != GSASL_OK)
58  return rc;
59 #endif /* USE_EXTERNAL */
60 
61 #ifdef USE_LOGIN
63  if (rc != GSASL_OK)
64  return rc;
65 #endif /* USE_LOGIN */
66 
67 #ifdef USE_PLAIN
69  if (rc != GSASL_OK)
70  return rc;
71 #endif /* USE_PLAIN */
72 
73 #ifdef USE_SECURID
75  if (rc != GSASL_OK)
76  return rc;
77 #endif /* USE_SECURID */
78 
79 #ifdef USE_NTLM
81  if (rc != GSASL_OK)
82  return rc;
83 #endif /* USE_NTLM */
84 
85 #ifdef USE_DIGEST_MD5
87  if (rc != GSASL_OK)
88  return rc;
89 #endif /* USE_DIGEST_MD5 */
90 
91 #ifdef USE_CRAM_MD5
93  if (rc != GSASL_OK)
94  return rc;
95 #endif /* USE_CRAM_MD5 */
96 
97 #ifdef USE_SCRAM_SHA1
98  rc = gsasl_register (ctx, &_gsasl_scram_sha1_mechanism);
99  if (rc != GSASL_OK)
100  return rc;
101 
102  rc = gsasl_register (ctx, &_gsasl_scram_sha1_plus_mechanism);
103  if (rc != GSASL_OK)
104  return rc;
105 #endif /* USE_SCRAM_SHA1 */
106 
107 #ifdef USE_SCRAM_SHA256
108  rc = gsasl_register (ctx, &_gsasl_scram_sha256_mechanism);
109  if (rc != GSASL_OK)
110  return rc;
111 
112  rc = gsasl_register (ctx, &_gsasl_scram_sha256_plus_mechanism);
113  if (rc != GSASL_OK)
114  return rc;
115 #endif /* USE_SCRAM_SHA256 */
116 
117 #ifdef USE_SAML20
119  if (rc != GSASL_OK)
120  return rc;
121 #endif /* USE_SAML20 */
122 
123 #ifdef USE_OPENID20
125  if (rc != GSASL_OK)
126  return rc;
127 #endif /* USE_OPENID20 */
128 
129 #ifdef USE_GSSAPI
131  if (rc != GSASL_OK)
132  return rc;
133 #endif /* USE_GSSAPI */
134 
135 #ifdef USE_GS2
137  if (rc != GSASL_OK)
138  return rc;
139 #endif /* USE_GSSAPI */
140 
141  return GSASL_OK;
142 }
143 
156 int
158 {
159  int rc;
160 
161  if (gc_init () != GC_OK)
162  return GSASL_CRYPTO_ERROR;
163 
164  *ctx = (Gsasl *) calloc (1, sizeof (**ctx));
165  if (*ctx == NULL)
166  return GSASL_MALLOC_ERROR;
167 
168  rc = register_builtin_mechs (*ctx);
169  if (rc != GSASL_OK)
170  {
171  gsasl_done (*ctx);
172  return rc;
173  }
174 
175  return GSASL_OK;
176 }
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:33
int rc
Definition: error.c:36
Gsasl_mechanism _gsasl_external_mechanism
Gsasl_mechanism _gsasl_gs2_krb5_mechanism
Definition: gs2/mechinfo.c:27
_GSASL_API int gsasl_register(Gsasl *ctx, const Gsasl_mechanism *mech)
Definition: register.c:38
@ GSASL_OK
Definition: gsasl.h:128
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:132
@ GSASL_CRYPTO_ERROR
Definition: gsasl.h:134
Gsasl_mechanism _gsasl_gssapi_mechanism
int gsasl_init(Gsasl **ctx)
Definition: init.c:157
Gsasl_mechanism _gsasl_login_mechanism
Gsasl_mechanism _gsasl_ntlm_mechanism
Definition: ntlm/mechinfo.c:27
Gsasl_mechanism _gsasl_openid20_mechanism
Gsasl_mechanism _gsasl_plain_mechanism
Gsasl_mechanism _gsasl_saml20_mechanism
Gsasl_mechanism _gsasl_securid_mechanism
Definition: internal.h:36