login/client.c

Go to the documentation of this file.
00001 /* client.c --- Non-standard SASL mechanism LOGIN, client side.
00002  * Copyright (C) 2002, 2003, 2004, 2006  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 along with GNU SASL Library; if not, write to the Free
00018  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #if HAVE_CONFIG_H
00024 # include "config.h"
00025 #endif
00026 
00027 /* Get malloc, free. */
00028 #include <stdlib.h>
00029 
00030 /* Get strlen. */
00031 #include <string.h>
00032 
00033 /* Get specification. */
00034 #include "login.h"
00035 
00036 struct _Gsasl_login_client_state
00037 {
00038   int step;
00039 };
00040 
00041 int
00042 _gsasl_login_client_start (Gsasl_session * sctx, void **mech_data)
00043 {
00044   struct _Gsasl_login_client_state *state;
00045 
00046   state = malloc (sizeof (*state));
00047   if (state == NULL)
00048     return GSASL_MALLOC_ERROR;
00049 
00050   state->step = 0;
00051 
00052   *mech_data = state;
00053 
00054   return GSASL_OK;
00055 }
00056 
00057 int
00058 _gsasl_login_client_step (Gsasl_session * sctx,
00059                           void *mech_data,
00060                           const char *input, size_t input_len,
00061                           char **output, size_t * output_len)
00062 {
00063   struct _Gsasl_login_client_state *state = mech_data;
00064   const char *p;
00065   int res;
00066 
00067   switch (state->step)
00068     {
00069     case 0:
00070       p = gsasl_property_get (sctx, GSASL_AUTHID);
00071       if (!p)
00072         return GSASL_NO_AUTHID;
00073 
00074       *output = strdup (p);
00075       *output_len = strlen (p);
00076 
00077       state->step++;
00078       res = GSASL_NEEDS_MORE;
00079       break;
00080 
00081     case 1:
00082       p = gsasl_property_get (sctx, GSASL_PASSWORD);
00083       if (!p)
00084         return GSASL_NO_PASSWORD;
00085 
00086       *output = strdup (p);
00087       *output_len = strlen (*output);
00088 
00089       state->step++;
00090       res = GSASL_OK;
00091       break;
00092 
00093     default:
00094       res = GSASL_MECHANISM_CALLED_TOO_MANY_TIMES;
00095       break;
00096     }
00097 
00098   return res;
00099 }
00100 
00101 void
00102 _gsasl_login_client_finish (Gsasl_session * sctx, void *mech_data)
00103 {
00104   struct _Gsasl_login_client_state *state = mech_data;
00105 
00106   if (!state)
00107     return;
00108 
00109   free (state);
00110 }

Generated on Tue Aug 22 12:06:06 2006 for gsasl by  doxygen 1.4.7