gsasl  1.10.0
About: GNU SASL is an implementation of the Simple Authentication and Security Layer (SASL). Development version.
  Fossies Dox: gsasl-1.10.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

init.c
Go to the documentation of this file.
1 /* init.c --- Entry point for libgsasl.
2  * Copyright (C) 2002-2021 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 "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"
44 
45 /**
46  * GSASL_VALID_MECHANISM_CHARACTERS:
47  *
48  * A zero-terminated character array, or string, with all ASCII
49  * characters that may be used within a SASL mechanism name.
50  **/
52  "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
53 
54 static int
56 {
57  int rc = GSASL_OK;
58 
59 #ifdef USE_ANONYMOUS
61  if (rc != GSASL_OK)
62  return rc;
63 #endif /* USE_ANONYMOUS */
64 
65 #ifdef USE_EXTERNAL
67  if (rc != GSASL_OK)
68  return rc;
69 #endif /* USE_EXTERNAL */
70 
71 #ifdef USE_LOGIN
73  if (rc != GSASL_OK)
74  return rc;
75 #endif /* USE_LOGIN */
76 
77 #ifdef USE_PLAIN
79  if (rc != GSASL_OK)
80  return rc;
81 #endif /* USE_PLAIN */
82 
83 #ifdef USE_SECURID
85  if (rc != GSASL_OK)
86  return rc;
87 #endif /* USE_SECURID */
88 
89 #ifdef USE_NTLM
91  if (rc != GSASL_OK)
92  return rc;
93 #endif /* USE_NTLM */
94 
95 #ifdef USE_DIGEST_MD5
97  if (rc != GSASL_OK)
98  return rc;
99 #endif /* USE_DIGEST_MD5 */
100 
101 #ifdef USE_CRAM_MD5
103  if (rc != GSASL_OK)
104  return rc;
105 #endif /* USE_CRAM_MD5 */
106 
107 #ifdef USE_SCRAM_SHA1
108  rc = gsasl_register (ctx, &gsasl_scram_sha1_mechanism);
109  if (rc != GSASL_OK)
110  return rc;
111 
112  rc = gsasl_register (ctx, &gsasl_scram_sha1_plus_mechanism);
113  if (rc != GSASL_OK)
114  return rc;
115 #endif /* USE_SCRAM_SHA1 */
116 
117 #ifdef USE_SCRAM_SHA256
118  rc = gsasl_register (ctx, &gsasl_scram_sha256_mechanism);
119  if (rc != GSASL_OK)
120  return rc;
121 
122  rc = gsasl_register (ctx, &gsasl_scram_sha256_plus_mechanism);
123  if (rc != GSASL_OK)
124  return rc;
125 #endif /* USE_SCRAM_SHA256 */
126 
127 #ifdef USE_SAML20
129  if (rc != GSASL_OK)
130  return rc;
131 #endif /* USE_SAML20 */
132 
133 #ifdef USE_OPENID20
135  if (rc != GSASL_OK)
136  return rc;
137 #endif /* USE_OPENID20 */
138 
139 #ifdef USE_GSSAPI
141  if (rc != GSASL_OK)
142  return rc;
143 #endif /* USE_GSSAPI */
144 
145 #ifdef USE_GS2
147  if (rc != GSASL_OK)
148  return rc;
149 #endif /* USE_GSSAPI */
150 
151  return GSASL_OK;
152 }
153 
154 /**
155  * gsasl_init:
156  * @ctx: pointer to libgsasl handle.
157  *
158  * This functions initializes libgsasl. The handle pointed to by ctx
159  * is valid for use with other libgsasl functions iff this function is
160  * successful. It also register all builtin SASL mechanisms, using
161  * gsasl_register().
162  *
163  * Return value: GSASL_OK iff successful, otherwise
164  * %GSASL_MALLOC_ERROR.
165  **/
166 int
168 {
169  int rc;
170 
171  if (gc_init () != GC_OK)
172  return GSASL_CRYPTO_ERROR;
173 
174  *ctx = (Gsasl *) calloc (1, sizeof (**ctx));
175  if (*ctx == NULL)
176  return GSASL_MALLOC_ERROR;
177 
178  rc = register_builtin_mechs (*ctx);
179  if (rc != GSASL_OK)
180  {
181  gsasl_done (*ctx);
182  return rc;
183  }
184 
185  return GSASL_OK;
186 }
Gsasl_mechanism gsasl_anonymous_mechanism
Definition: mechinfo.c:30
Gsasl_mechanism gsasl_cram_md5_mechanism
Definition: mechinfo.c:30
Gsasl_mechanism gsasl_digest_md5_mechanism
Definition: mechinfo.c:30
void gsasl_done(Gsasl *ctx)
Definition: done.c:33
Gsasl_mechanism gsasl_external_mechanism
Definition: mechinfo.c:30
Gc_rc gc_init(void)
Definition: gc-gnulib.c:99
@ GC_OK
Definition: gc.h:27
#define NULL
Definition: stddef.in.h:72
Gsasl_mechanism gsasl_gs2_krb5_mechanism
Definition: mechinfo.c:30
GSASL_API int gsasl_register(Gsasl *ctx, const Gsasl_mechanism *mech)
Definition: register.c:38
@ GSASL_OK
Definition: gsasl.h:171
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:175
@ GSASL_CRYPTO_ERROR
Definition: gsasl.h:177
Gsasl_mechanism gsasl_gssapi_mechanism
Definition: mechinfo.c:30
const char * GSASL_VALID_MECHANISM_CHARACTERS
Definition: init.c:51
static int register_builtin_mechs(Gsasl *ctx)
Definition: init.c:55
int gsasl_init(Gsasl **ctx)
Definition: init.c:167
int rc
Definition: error.c:42
Gsasl_mechanism gsasl_login_mechanism
Definition: mechinfo.c:30
Gsasl_mechanism gsasl_ntlm_mechanism
Definition: mechinfo.c:30
Gsasl_mechanism gsasl_openid20_mechanism
Definition: mechinfo.c:30
Gsasl_mechanism gsasl_plain_mechanism
Definition: mechinfo.c:30
Gsasl_mechanism gsasl_saml20_mechanism
Definition: mechinfo.c:30
Gsasl_mechanism gsasl_securid_mechanism
Definition: mechinfo.c:30
Definition: internal.h:41