[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CVS gsasl/examples
From: |
gsasl-commit |
Subject: |
CVS gsasl/examples |
Date: |
Thu, 30 Sep 2004 15:56:00 +0200 |
Update of /home/cvs/gsasl/examples
In directory dopio:/tmp/cvs-serv25467/examples
Added Files:
.cvsignore Makefile.am README client-callback.c client-mech.c
client-serverfirst.c client.c
Log Message:
Add examples.
--- /home/cvs/gsasl/examples/.cvsignore 2004/09/30 13:56:00 NONE
+++ /home/cvs/gsasl/examples/.cvsignore 2004/09/30 13:56:00 1.1
.deps
.libs
Makefile
Makefile.in
client
client-callback
client-mech
client-serverfirst
--- /home/cvs/gsasl/examples/Makefile.am 2004/09/30 13:56:00 NONE
+++ /home/cvs/gsasl/examples/Makefile.am 2004/09/30 13:56:00 1.1
## Process this file with automake to produce Makefile.in
# Copyright (C) 2002, 2003, 2004 Simon Josefsson.
#
# This file is part of GNU SASL.
#
# GNU SASL is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU SASL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU SASL; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
EXTRA_DIST = README
AM_CPPFLAGS = -I$(top_srcdir)/lib/src -I../lib/src
LDADD = ../lib/src/libgsasl.la
noinst_PROGRAMS = client client-serverfirst client-mech client-callback
--- /home/cvs/gsasl/examples/README 2004/09/30 13:56:00 NONE
+++ /home/cvs/gsasl/examples/README 2004/09/30 13:56:00 1.1
GNU SASL examples/README -- Information about files in examples/ directory.
Copyright (C) 2003, 2004 Simon Josefsson
See the end for copying conditions.
This directory contains examples on how to use GNU SASL.
client: Example SASL client.
client-serverfirst: Same as previous, but server get to send data first.
client-mech: Same as previous, but you get to chose which mechanism is used.
client-callback: Same as client-serverfirst, but user info is retrieved
using a callback, instead of hard coded.
----------------------------------------------------------------------
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.
--- /home/cvs/gsasl/examples/client-callback.c 2004/09/30 13:56:00 NONE
+++ /home/cvs/gsasl/examples/client-callback.c 2004/09/30 13:56:00 1.1
/* client-callback.c --- Example SASL client, with callback for user info.
* Copyright (C) 2004 Simon Josefsson
*
* This file is part of GNU SASL.
*
* GNU SASL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GNU SASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU SASL; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gsasl.h>
void
client_authenticate (Gsasl * ctx, Gsasl_session * session)
{
char buf[BUFSIZ] = "";
char *p;
int rc;
/* This loop mimic a protocol where the server get to send data first. */
do
{
printf ("Input base64 encoded data from server:\n");
fgets (buf, sizeof (buf) - 1, stdin);
rc = gsasl_step64 (session, buf, &p);
if (rc == GSASL_NEEDS_MORE || rc == GSASL_OK)
{
printf ("Output:\n%s\n", p);
free (p);
}
}
while (rc == GSASL_NEEDS_MORE);
printf ("\n");
if (rc != GSASL_OK)
{
printf ("Authentication error (%d): %s\n", rc, gsasl_strerror (rc));
return;
}
/* The client is done. Here you would typically check if the server
let the client in. If not, you could try again. */
printf ("If server accepted us, we're done.\n");
}
void
client (Gsasl *ctx)
{
Gsasl_session *session;
int rc;
/* Create new authentication session. */
if ((rc = gsasl_client_start (ctx, "SECURID", &session)) != GSASL_OK)
{
printf ("Cannot initialize client (%d): %s\n", rc, gsasl_strerror (rc));
return;
}
/* Do it. */
client_authenticate (ctx, session);
/* Cleanup. */
gsasl_client_finish (session);
}
int
callback (Gsasl * ctx, Gsasl_session * sctx, Gsasl_property prop)
{
char buf[BUFSIZ] = "";
int rc = GSASL_NO_CALLBACK;
/* Get user info from user. */
printf ("Callback invoked, for property %d.\n", prop);
switch (prop)
{
case GSASL_PASSCODE:
printf ("Enter passcode:\n");
fgets (buf, sizeof (buf) - 1, stdin);
buf[strlen (buf) - 1] = '\0';
gsasl_property_set (sctx, GSASL_PASSCODE, buf);
rc = GSASL_OK;
break;
case GSASL_AUTHID:
printf ("Enter username:\n");
fgets (buf, sizeof (buf) - 1, stdin);
buf[strlen (buf) - 1] = '\0';
gsasl_property_set (sctx, GSASL_AUTHID, buf);
rc = GSASL_OK;
break;
default:
printf ("Unknown property! Don't worry.\n");
break;
}
return rc;
}
int
main (int argc, char *argv[])
{
Gsasl *ctx = NULL;
int rc;
/* Initialize library. */
if ((rc = gsasl_init (&ctx)) != GSASL_OK)
{
printf ("Cannot initialize libgsasl (%d): %s", rc, gsasl_strerror (rc));
return 1;
}
/* Set a global callback handler for the library. It may be
overriden, per session, by calling gsasl_callback_set on future
session handles, to indicate another callback function for that
session. */
gsasl_callback_set_global (ctx, callback);
/* Do it. */
client (ctx);
/* Cleanup. */
gsasl_done (ctx);
return 0;
}
--- /home/cvs/gsasl/examples/client-mech.c 2004/09/30 13:56:00 NONE
+++ /home/cvs/gsasl/examples/client-mech.c 2004/09/30 13:56:00 1.1
/* client-mech.c --- Example SASL client, with a choice of mechanism to use.
* Copyright (C) 2004 Simon Josefsson
*
* This file is part of GNU SASL.
*
* GNU SASL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GNU SASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU SASL; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gsasl.h>
void
client_authenticate (Gsasl * ctx, Gsasl_session * session)
{
char buf[BUFSIZ] = "";
char *p;
int rc;
/* This loop mimic a protocol where the server get to send data first. */
do
{
printf ("Input base64 encoded data from server:\n");
fgets (buf, sizeof (buf) - 1, stdin);
rc = gsasl_step64 (session, buf, &p);
if (rc == GSASL_NEEDS_MORE || rc == GSASL_OK)
{
printf ("Output:\n%s\n", p);
free (p);
}
}
while (rc == GSASL_NEEDS_MORE);
printf ("\n");
if (rc != GSASL_OK)
{
printf ("Authentication error (%d): %s\n", rc, gsasl_strerror (rc));
return;
}
/* The client is done. Here you would typically check if the server
let the client in. If not, you could try again. */
printf ("If server accepted us, we're done.\n");
}
const char *
client_mechanism (Gsasl *ctx)
{
static char mech[GSASL_MAX_MECHANISM_SIZE + 1] = "";
char mechlist[BUFSIZ] = "";
const char *suggestion;
printf ("Enter list of mechanism that server support, separate by SPC:\n");
fgets (mechlist, sizeof (mechlist) - 1, stdin);
suggestion = gsasl_client_suggest_mechanism (ctx, mechlist);
if (suggestion)
printf ("Library suggest use of `%s'.\n", suggestion);
printf ("Enter mechanism to use:\n");
fgets (mech, sizeof (mech) - 1, stdin);
mech[strlen (mech) - 1] = '\0';
return mech;
}
void
client (Gsasl *ctx)
{
Gsasl_session *session;
const char *mech;
int rc;
/* Find out which mechanism to use. */
mech = client_mechanism (ctx);
/* Create new authentication session. */
if ((rc = gsasl_client_start (ctx, mech, &session)) != GSASL_OK)
{
printf ("Cannot initialize client (%d): %s\n", rc, gsasl_strerror (rc));
return;
}
/* Set username and password in session handle. This info will be
lost when this session is deallocated below. */
gsasl_property_set (session, GSASL_AUTHID, "jas");
gsasl_property_set (session, GSASL_PASSWORD, "secret");
/* Do it. */
client_authenticate (ctx, session);
/* Cleanup. */
gsasl_client_finish (session);
}
int
main (int argc, char *argv[])
{
Gsasl *ctx = NULL;
int rc;
/* Initialize library. */
if ((rc = gsasl_init (&ctx)) != GSASL_OK)
{
printf ("Cannot initialize libgsasl (%d): %s", rc, gsasl_strerror (rc));
return 1;
}
/* Do it. */
client (ctx);
/* Cleanup. */
gsasl_done (ctx);
return 0;
}
--- /home/cvs/gsasl/examples/client-serverfirst.c 2004/09/30 13:56:00
NONE
+++ /home/cvs/gsasl/examples/client-serverfirst.c 2004/09/30 13:56:00
1.1
/* client-serverfirst.c --- Example SASL client, where server send data first.
* Copyright (C) 2004 Simon Josefsson
*
* This file is part of GNU SASL.
*
* GNU SASL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* GNU SASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU SASL; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gsasl.h>
void
client_authenticate (Gsasl * ctx, Gsasl_session * session)
{
char buf[BUFSIZ] = "";
char *p;
int rc;
/* This loop mimic a protocol where the server get to send data first. */
do
{
printf ("Input base64 encoded data from server:\n");
fgets (buf, sizeof (buf) - 1, stdin);
rc = gsasl_step64 (session, buf, &p);
if (rc == GSASL_NEEDS_MORE || rc == GSASL_OK)
{
printf ("Output:\n%s\n", p);
free (p);
}
}
while (rc == GSASL_NEEDS_MORE);
printf ("\n");
if (rc != GSASL_OK)
{
printf ("Authentication error (%d): %s\n", rc, gsasl_strerror (rc));
return;
}
[53 lines skipped]
--- /home/cvs/gsasl/examples/client.c 2004/09/30 13:56:00 NONE
+++ /home/cvs/gsasl/examples/client.c 2004/09/30 13:56:00 1.1
[173 lines skipped]