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