Blame SOURCES/sasl-mechlist.c

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