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