1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * soup-auth-ntlm.c: HTTP NTLM Authentication helper
5 * Copyright (C) 2007 Red Hat, Inc.
14 #include "soup-auth-ntlm.h"
15 #include "soup-headers.h"
16 #include "soup-message.h"
17 #include "soup-misc.h"
20 static gboolean update (SoupAuth *auth, SoupMessage *msg, GHashTable *auth_params);
21 static GSList *get_protection_space (SoupAuth *auth, SoupURI *source_uri);
22 static void authenticate (SoupAuth *auth, const char *username, const char *password);
23 static gboolean is_authenticated (SoupAuth *auth);
24 static char *get_authorization (SoupAuth *auth, SoupMessage *msg);
27 char *username, *password;
28 } SoupAuthNTLMPrivate;
29 #define SOUP_AUTH_NTLM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUP_TYPE_AUTH_NTLM, SoupAuthNTLMPrivate))
31 G_DEFINE_TYPE (SoupAuthNTLM, soup_auth_ntlm, SOUP_TYPE_AUTH)
34 soup_auth_ntlm_init (SoupAuthNTLM *ntlm)
39 finalize (GObject *object)
41 SoupAuthNTLMPrivate *priv = SOUP_AUTH_NTLM_GET_PRIVATE (object);
43 g_free (priv->username);
45 memset (priv->password, 0, strlen (priv->password));
46 g_free (priv->password);
49 G_OBJECT_CLASS (soup_auth_ntlm_parent_class)->finalize (object);
53 soup_auth_ntlm_class_init (SoupAuthNTLMClass *auth_ntlm_class)
55 SoupAuthClass *auth_class = SOUP_AUTH_CLASS (auth_ntlm_class);
56 GObjectClass *object_class = G_OBJECT_CLASS (auth_ntlm_class);
58 g_type_class_add_private (auth_ntlm_class, sizeof (SoupAuthNTLMPrivate));
60 auth_class->scheme_name = "NTLM";
61 auth_class->strength = 3;
63 auth_class->update = update;
64 auth_class->get_protection_space = get_protection_space;
65 auth_class->authenticate = authenticate;
66 auth_class->is_authenticated = is_authenticated;
67 auth_class->get_authorization = get_authorization;
69 object_class->finalize = finalize;
73 soup_auth_ntlm_new (const char *realm, const char *host)
77 auth = g_object_new (SOUP_TYPE_AUTH_NTLM,
78 SOUP_AUTH_REALM, realm,
85 update (SoupAuth *auth, SoupMessage *msg, GHashTable *auth_params)
87 g_return_val_if_reached (FALSE);
91 get_protection_space (SoupAuth *auth, SoupURI *source_uri)
93 g_return_val_if_reached (NULL);
97 authenticate (SoupAuth *auth, const char *username, const char *password)
99 SoupAuthNTLMPrivate *priv = SOUP_AUTH_NTLM_GET_PRIVATE (auth);
101 g_return_if_fail (username != NULL);
102 g_return_if_fail (password != NULL);
104 priv->username = g_strdup (username);
105 priv->password = g_strdup (password);
109 is_authenticated (SoupAuth *auth)
111 return SOUP_AUTH_NTLM_GET_PRIVATE (auth)->password != NULL;
115 get_authorization (SoupAuth *auth, SoupMessage *msg)
117 g_return_val_if_reached (NULL);
121 soup_auth_ntlm_get_username (SoupAuth *auth)
123 SoupAuthNTLMPrivate *priv = SOUP_AUTH_NTLM_GET_PRIVATE (auth);
125 return priv->username;
129 soup_auth_ntlm_get_password (SoupAuth *auth)
131 SoupAuthNTLMPrivate *priv = SOUP_AUTH_NTLM_GET_PRIVATE (auth);
133 return priv->password;