summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2006-10-16 14:51:57 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2006-10-16 14:51:57 +0000
commit8c53ae33271abc10fa0ac450bfd20ea601e03475 (patch)
tree65fa8fb0b09342e96848b2a682e591e0fe813330
parente4049b44ebc99bea0f25433a6af579ee69a5f9c8 (diff)
downloadmailutils-8c53ae33271abc10fa0ac450bfd20ea601e03475.tar.gz
mailutils-8c53ae33271abc10fa0ac450bfd20ea601e03475.tar.bz2
Test auth schemes
-rw-r--r--examples/muauth.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/examples/muauth.c b/examples/muauth.c
new file mode 100644
index 000000000..a03e1930b
--- /dev/null
+++ b/examples/muauth.c
@@ -0,0 +1,130 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ GNU Mailutils is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Mailutils is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Mailutils; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301 USA */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+#include <unistd.h>
+#include <stdio.h>
+#include <assert.h>
+#include <ctype.h>
+#include <string.h>
+#include <mailutils/mailutils.h>
+
+const char *program_version = "muauth (" PACKAGE_STRING ")";
+static char doc[] =
+"muauth -- test mailutils authentication and authorization schemes";
+static char args_doc[] = "key";
+
+static const char *capa[] = {
+ "auth",
+ "license",
+ "common",
+ NULL
+};
+
+static struct argp_option options[] = {
+ { "password", 'p', "STRING", 0, "user password", 0 },
+ { "uid", 'u', NULL, 0, "test getpwuid functions", 0 },
+ { "name", 'n', NULL, 0, "test getpwnam functions", 0 },
+ { NULL },
+};
+
+enum mu_auth_key_type key_type = mu_auth_key_name;
+char *password;
+
+static error_t
+parse_opt (int key, char *arg, struct argp_state *state)
+{
+ switch (key)
+ {
+ case 'p':
+ password = arg;
+ break;
+
+ case 'u':
+ key_type = mu_auth_key_uid;
+ break;
+
+ case 'n':
+ key_type = mu_auth_key_name;
+ break;
+
+ default:
+ return ARGP_ERR_UNKNOWN;
+ }
+ return 0;
+}
+
+static struct argp argp = {
+ options,
+ parse_opt,
+ args_doc,
+ doc,
+ NULL,
+ NULL, NULL
+};
+
+int
+main (int argc, char * argv [])
+{
+ int rc, index;
+ struct mu_auth_data *auth;
+ void *key;
+ uid_t uid;
+
+ MU_AUTH_REGISTER_ALL_MODULES ();
+ mu_argp_init (program_version, NULL);
+ mu_argp_parse (&argp, &argc, &argv, 0, capa, &index, NULL);
+ if (index == argc)
+ {
+ mu_error ("not enough arguments, try `%s --help' for more info",
+ argv[0]);
+ return 1;
+ }
+
+ if (key_type == mu_auth_key_uid)
+ {
+ uid = strtoul (argv[index], NULL, 0);
+ key = &uid;
+ }
+ else
+ key = argv[index];
+
+ rc = mu_get_auth (&auth, key_type, key);
+ printf ("mu_get_auth => %d, %s\n", rc, mu_strerror (rc));
+ if (rc == 0)
+ {
+ printf ("user name: %s\n", auth->name);
+ printf ("password: %s\n", auth->passwd);
+ printf ("uid: %lu\n", (unsigned long) auth->uid);
+ printf ("gid: %lu\n", (unsigned long) auth->gid);
+ printf ("gecos: %s\n", auth->gecos);
+ printf ("home: %s\n", auth->dir);
+ printf ("shell: %s\n", auth->shell);
+ printf ("mailbox: %s\n", auth->mailbox);
+ printf ("change_uid: %d\n", auth->change_uid);
+
+ rc = mu_authenticate (auth, password);
+ printf ("mu_authenticate => %d, %s\n", rc, mu_strerror (rc));
+ mu_auth_data_free (auth);
+ }
+ return rc != 0;
+}
+
+

Return to:

Send suggestions and report system problems to the System administrator.