sbonazzo / rpms / cyrus-sasl

Forked from rpms/cyrus-sasl 2 years ago
Clone

Blame SOURCES/sasl-mechlist.c

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