sbonazzo / rpms / cyrus-sasl

Forked from rpms/cyrus-sasl 2 years ago
Clone

Blame SOURCES/sasl-mechlist.c

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