1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright 2012 Red Hat, Inc.
12 #include "libsoup/soup.h"
14 const char *helper_protocol, *username, *domain;
15 gboolean use_cached_creds;
17 static GOptionEntry entries[] = {
18 { "helper-protocol", 0, 0,
19 G_OPTION_ARG_STRING, &helper_protocol,
21 { "use-cached-creds", 0, 0,
22 G_OPTION_ARG_NONE, &use_cached_creds,
25 G_OPTION_ARG_STRING, &username,
28 G_OPTION_ARG_STRING, &domain,
34 main (int argc, char **argv)
37 char buf[256], *header;
42 g_setenv ("SOUP_NTLM_AUTH_DEBUG", "", TRUE);
44 setlocale (LC_ALL, "");
46 opts = g_option_context_new (NULL);
47 g_option_context_add_main_entries (opts, entries, NULL);
48 if (!g_option_context_parse (opts, &argc, &argv, NULL)) {
49 g_printerr ("Bad arguments\n");
52 g_option_context_free (opts);
54 if (!username || !use_cached_creds || !helper_protocol ||
55 !g_str_equal (helper_protocol, "ntlmssp-client-1")) {
56 g_printerr ("Wrong arguments; this program is only intended for use by ntlm-test\n");
60 msg = soup_message_new ("GET", "http://localhost/");
63 while (fgets (buf, sizeof (buf), stdin)) {
64 if (strchr (buf, '\n'))
65 *strchr (buf, '\n') = '\0';
66 if (!strcmp (buf, "YR")) {
67 if (g_getenv ("SOUP_NTLM_AUTH_DEBUG_NOCREDS")) {
72 g_clear_object (&auth);
73 auth = g_object_new (SOUP_TYPE_AUTH_NTLM, NULL);
74 header = soup_auth_get_authorization (auth, msg);
75 g_print ("YR %s\n", header + 5);
77 } else if (g_str_has_prefix (buf, "TT ")) {
78 header = g_strdup_printf ("NTLM %s\n", buf + 3);
79 if (!soup_auth_update (auth, msg, header)) {
80 g_printerr ("Bad challenge\n");
85 soup_auth_authenticate (auth, username, "password");
86 header = soup_auth_get_authorization (auth, msg);
88 g_printerr ("Internal authentication failure\n");
91 g_print ("KK %s\n", header + 5);
94 g_printerr ("Unexpected command\n");
100 g_clear_object (&auth);