1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camel-nntp-auth.c : authentication for nntp */
6 * Copyright (C) 2000 Ximian, Inc. <toshok@ximian.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU Lesser General Public
10 * License as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
29 #include "camel-exception.h"
30 #include "camel-session.h"
32 #include "camel-nntp-auth.h"
33 #include "camel-nntp-store.h"
34 #include "camel-nntp-resp-codes.h"
37 camel_nntp_auth_authenticate (CamelNNTPStore *store, CamelException *ex)
39 CamelService *service = CAMEL_SERVICE (store);
40 CamelSession *session = camel_service_get_session (service);
43 if (!service->url->authmech && !service->url->passwd) {
46 prompt = g_strdup_printf (_("Please enter the NNTP password for %s@%s"),
47 service->url->user, service->url->host);
48 service->url->passwd =
49 camel_session_get_password (session, prompt,
50 TRUE, service, "password", ex);
53 if (!service->url->passwd) {
54 camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL,
55 "You didn\'t enter a password.");
61 /* first send username */
62 resp = camel_nntp_command (store, ex, NULL, "AUTHINFO USER %s", service->url->user);
64 if (resp == NNTP_AUTH_REJECTED) {
65 camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
66 _("Server rejected username"));
70 else if (resp != NNTP_AUTH_CONTINUE) {
71 camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
72 _("Failed to send username to server"));
76 /* then send the username if the server asks for it */
77 resp = camel_nntp_command (store, ex, NULL, "AUTHINFO PASS %s", service->url->passwd);
79 if (resp == NNTP_AUTH_REJECTED) {
80 camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
81 _("Server rejected username/password"));
87 if (service->url->passwd) {
88 /* let's be paranoid */
89 memset (service->url->passwd, 0, strlen (service->url->passwd));
90 g_free (service->url->passwd);
91 service->url->passwd = NULL;