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