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)  

listmech.c
Go to the documentation of this file.
1 /* listmech.c --- List active client and server mechanisms.
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 static int
27  Gsasl_mechanism * mechs,
28  size_t n_mechs, char **out, int clientp)
29 {
30  Gsasl_session *sctx;
31  char *list;
32  size_t i;
33  int rc;
34 
35  list = calloc (n_mechs + 1, GSASL_MAX_MECHANISM_SIZE + 1);
36  if (!list)
37  return GSASL_MALLOC_ERROR;
38 
39  for (i = 0; i < n_mechs; i++)
40  {
41  if (clientp)
42  rc = gsasl_client_start (ctx, mechs[i].name, &sctx);
43  else
44  rc = gsasl_server_start (ctx, mechs[i].name, &sctx);
45 
46  if (rc == GSASL_OK)
47  {
48  gsasl_finish (sctx);
49 
50  strcat (list, mechs[i].name);
51  if (i < n_mechs - 1)
52  strcat (list, " ");
53  }
54  }
55 
56  *out = list;
57 
58  return GSASL_OK;
59 }
60 
61 /**
62  * gsasl_client_mechlist:
63  * @ctx: libgsasl handle.
64  * @out: newly allocated output character array.
65  *
66  * Return a newly allocated string containing SASL names, separated by
67  * space, of mechanisms supported by the libgsasl client. @out is
68  * allocated by this function, and it is the responsibility of caller
69  * to deallocate it.
70  *
71  * Return value: Returns %GSASL_OK if successful, or error code.
72  **/
73 int
74 gsasl_client_mechlist (Gsasl * ctx, char **out)
75 {
76  return _gsasl_listmech (ctx, ctx->client_mechs, ctx->n_client_mechs,
77  out, 1);
78 }
79 
80 /**
81  * gsasl_server_mechlist:
82  * @ctx: libgsasl handle.
83  * @out: newly allocated output character array.
84  *
85  * Return a newly allocated string containing SASL names, separated by
86  * space, of mechanisms supported by the libgsasl server. @out is
87  * allocated by this function, and it is the responsibility of caller
88  * to deallocate it.
89  *
90  * Return value: Returns %GSASL_OK if successful, or error code.
91  **/
92 int
93 gsasl_server_mechlist (Gsasl * ctx, char **out)
94 {
95  return _gsasl_listmech (ctx, ctx->server_mechs, ctx->n_server_mechs,
96  out, 0);
97 }
void gsasl_finish(Gsasl_session *sctx)
Definition: xfinish.c:33
int gsasl_client_start(Gsasl *ctx, const char *mech, Gsasl_session **sctx)
Definition: xstart.c:119
@ GSASL_OK
Definition: gsasl.h:171
@ GSASL_MALLOC_ERROR
Definition: gsasl.h:175
int gsasl_server_start(Gsasl *ctx, const char *mech, Gsasl_session **sctx)
Definition: xstart.c:137
@ GSASL_MAX_MECHANISM_SIZE
Definition: gsasl.h:108
const char * name
Definition: error.c:43
int rc
Definition: error.c:42
static int _gsasl_listmech(Gsasl *ctx, Gsasl_mechanism *mechs, size_t n_mechs, char **out, int clientp)
Definition: listmech.c:26
int gsasl_client_mechlist(Gsasl *ctx, char **out)
Definition: listmech.c:74
int gsasl_server_mechlist(Gsasl *ctx, char **out)
Definition: listmech.c:93
Definition: internal.h:41
size_t n_client_mechs
Definition: internal.h:42
Gsasl_mechanism * server_mechs
Definition: internal.h:45
Gsasl_mechanism * client_mechs
Definition: internal.h:43
size_t n_server_mechs
Definition: internal.h:44