cvsdist eb2d101
#include "sasl.h"
cvsdist eb2d101
#include <stdio.h>
cvsdist eb2d101
#include <stdlib.h>
cvsdist eb2d101
#include <string.h>
cvsdist eb2d101
cvsdist eb2d101
static int
cvsdist eb2d101
my_getopt(void *context, const char *plugin_name,
cvsdist eb2d101
	  const char *option, const char **result, unsigned *len)
cvsdist eb2d101
{
cvsdist eb2d101
	if (result) {
cvsdist eb2d101
		*result = NULL;
cvsdist eb2d101
#if 0
cvsdist eb2d101
		fprintf(stderr, "Getopt plugin=%s%s%s/option=%s%s%s -> ",
cvsdist eb2d101
			plugin_name ? "\"" : "",
cvsdist eb2d101
			plugin_name ? plugin_name : "(null)",
cvsdist eb2d101
			plugin_name ? "\"" : "",
cvsdist eb2d101
			option ? "\"" : "",
cvsdist eb2d101
			option ? option : "(null)",
cvsdist eb2d101
			option ? "\"" : "");
cvsdist eb2d101
		fprintf(stderr, "'%s'.\n", *result ? *result : "");
cvsdist eb2d101
#endif
cvsdist eb2d101
	}
cvsdist eb2d101
	if (len) {
cvsdist eb2d101
		*len = 0;
cvsdist eb2d101
	}
cvsdist eb2d101
	return 0;
cvsdist eb2d101
}
cvsdist eb2d101
cvsdist eb2d101
int
cvsdist eb2d101
main(int argc, char **argv)
cvsdist eb2d101
{
cvsdist eb2d101
	int ret, i;
cvsdist eb2d101
	const char *mechs, **globals;
cvsdist eb2d101
	sasl_callback_t callbacks[] = {
cvsdist eb2d101
		{SASL_CB_GETOPT, my_getopt, NULL},
cvsdist eb2d101
		{SASL_CB_LIST_END},
cvsdist eb2d101
	};
cvsdist eb2d101
	sasl_conn_t *connection;
cvsdist eb2d101
	char hostname[512];
cvsdist eb2d101
cvsdist eb2d101
	if ((argc > 1) && (argv[1][0] == '-')) {
cvsdist eb2d101
		fprintf(stderr, "Usage: %s [appname [hostname] ]\n", argv[0]);
cvsdist eb2d101
		return 0;
cvsdist eb2d101
	}
cvsdist eb2d101
cvsdist eb2d101
	ret = sasl_server_init(callbacks, argc > 1 ? argv[1] : "sasl-mechlist");
cvsdist eb2d101
	if (ret != SASL_OK) {
cvsdist eb2d101
		fprintf(stderr, "Error in sasl_server_init(): %s\n",
cvsdist eb2d101
			sasl_errstring(ret, NULL, NULL));
cvsdist eb2d101
	}
cvsdist eb2d101
cvsdist eb2d101
	connection = NULL;
cvsdist eb2d101
	strcpy(hostname, "localhost");
cvsdist eb2d101
	gethostname(hostname, sizeof(hostname));
cvsdist eb2d101
	ret = sasl_server_new(argc > 2 ? argv[2] : "host",
cvsdist eb2d101
			      hostname,
cvsdist eb2d101
			      NULL,
cvsdist eb2d101
			      NULL,
cvsdist eb2d101
			      NULL,
cvsdist eb2d101
			      callbacks,
cvsdist eb2d101
			      0,
cvsdist eb2d101
			      &connection);
cvsdist eb2d101
	if (ret != SASL_OK) {
cvsdist eb2d101
		fprintf(stderr, "Error in sasl_server_new(): %s\n",
cvsdist eb2d101
			sasl_errstring(ret, NULL, NULL));
cvsdist eb2d101
	}
cvsdist eb2d101
cvsdist eb2d101
	ret = sasl_listmech(connection,
cvsdist eb2d101
			    getenv("USER") ? getenv("USER") : "root",
cvsdist eb2d101
			    "Available mechanisms: ",
cvsdist eb2d101
			    ",",
cvsdist eb2d101
			    "\n",
cvsdist eb2d101
			    &mechs,
cvsdist eb2d101
			    NULL,
cvsdist eb2d101
			    NULL);
cvsdist eb2d101
	if (ret != SASL_OK) {
cvsdist eb2d101
		fprintf(stderr, "Error in sasl_listmechs(): %s\n",
cvsdist eb2d101
			sasl_errstring(ret, NULL, NULL));
cvsdist eb2d101
	} else {
cvsdist eb2d101
		fprintf(stdout, "%s", mechs);
cvsdist eb2d101
	}
cvsdist eb2d101
cvsdist eb2d101
	globals = sasl_global_listmech();
cvsdist eb2d101
	for (i = 0; (globals != NULL) && (globals[i] != NULL); i++) {
cvsdist eb2d101
		if (i == 0) {
cvsdist eb2d101
			fprintf(stdout, "Library supports: ");
cvsdist eb2d101
		}
cvsdist eb2d101
		fprintf(stdout, "%s", globals[i]);
cvsdist eb2d101
		if (globals[i + 1] != NULL) {
cvsdist eb2d101
			fprintf(stdout, ",");
cvsdist eb2d101
		} else {
cvsdist eb2d101
			fprintf(stdout, "\n");
cvsdist eb2d101
		}
cvsdist eb2d101
	}
cvsdist eb2d101
cvsdist eb2d101
	return 0;
cvsdist eb2d101
}