Blame SOURCES/sasl-mechlist.c

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