~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to servers/exchange/lib/e2k-kerberos.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
 
3
 
/* Copyright (C) 2004 Novell, Inc.
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or
6
 
 * modify it under the terms of version 2 of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 * General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this program; if not, write to the
16
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 
 * Boston, MA 02110-1301, USA.
18
 
 */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include <config.h>
22
 
#endif
23
 
 
24
 
#include <ctype.h>
25
 
#include <glib.h>
26
 
#include <stdio.h>
27
 
#include <stdlib.h>
28
 
#include <string.h>
29
 
 
30
 
#include "e2k-kerberos.h"
31
 
#include <krb5.h>
32
 
 
33
 
static krb5_context
34
 
e2k_kerberos_context_new (const gchar *domain)
35
 
{
36
 
        krb5_context ctx;
37
 
        gchar *realm;
38
 
 
39
 
        if (krb5_init_context (&ctx) != 0)
40
 
                return NULL;
41
 
 
42
 
        realm = g_ascii_strup (domain, strlen (domain));
43
 
        krb5_set_default_realm (ctx, realm);
44
 
        g_free (realm);
45
 
 
46
 
        return ctx;
47
 
}
48
 
 
49
 
static E2kKerberosResult
50
 
krb5_result_to_e2k_kerberos_result (gint result)
51
 
{
52
 
        switch (result) {
53
 
        case 0:
54
 
                return E2K_KERBEROS_OK;
55
 
 
56
 
        case KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN:
57
 
                return E2K_KERBEROS_USER_UNKNOWN;
58
 
 
59
 
        case KRB5KRB_AP_ERR_BAD_INTEGRITY:
60
 
        case KRB5KDC_ERR_PREAUTH_FAILED:
61
 
        case KRB5KDC_ERR_CLIENT_REVOKED:
62
 
                return E2K_KERBEROS_PASSWORD_INCORRECT;
63
 
 
64
 
        case KRB5KDC_ERR_KEY_EXP:
65
 
                return E2K_KERBEROS_PASSWORD_EXPIRED;
66
 
 
67
 
        case KRB5_KDC_UNREACH:
68
 
                return E2K_KERBEROS_KDC_UNREACHABLE;
69
 
 
70
 
        case KRB5KRB_AP_ERR_SKEW:
71
 
                return E2K_KERBEROS_TIME_SKEW;
72
 
 
73
 
        default:
74
 
                g_warning ("Unexpected kerberos error %d", result);
75
 
 
76
 
        case KRB5_REALM_UNKNOWN:
77
 
                return E2K_KERBEROS_FAILED;
78
 
        }
79
 
}
80
 
 
81
 
static E2kKerberosResult
82
 
get_init_cred (krb5_context ctx, const gchar *usr_name, const gchar *passwd,
83
 
               const gchar *in_tkt_service, krb5_creds *cred)
84
 
{
85
 
        krb5_principal principal;
86
 
        krb5_get_init_creds_opt opt;
87
 
        krb5_error_code result;
88
 
 
89
 
        result = krb5_parse_name (ctx, usr_name, &principal);
90
 
        if (result)
91
 
                return E2K_KERBEROS_USER_UNKNOWN;
92
 
 
93
 
        krb5_get_init_creds_opt_init (&opt);
94
 
        krb5_get_init_creds_opt_set_tkt_life (&opt, 5*60);
95
 
        krb5_get_init_creds_opt_set_renew_life (&opt, 0);
96
 
        krb5_get_init_creds_opt_set_forwardable (&opt, 0);
97
 
        krb5_get_init_creds_opt_set_proxiable (&opt, 0);
98
 
 
99
 
        result = krb5_get_init_creds_password (ctx, cred, principal,
100
 
                                               (gchar *) passwd,
101
 
                                               NULL, NULL, 0,
102
 
                                               (gchar *) in_tkt_service, &opt);
103
 
        krb5_free_principal (ctx, principal);
104
 
 
105
 
        return krb5_result_to_e2k_kerberos_result (result);
106
 
}
107
 
 
108
 
/**
109
 
 * e2k_kerberos_change_password
110
 
 * @user: username
111
 
 * @domain: Windows (2000) domain name
112
 
 * @old_password: currrent password
113
 
 * @new_password: password to be changed to
114
 
 *
115
 
 * Changes the password for the given user
116
 
 *
117
 
 * Return value: an #E2kKerberosResult
118
 
 **/
119
 
E2kKerberosResult
120
 
e2k_kerberos_change_password (const gchar *user, const gchar *domain,
121
 
                              const gchar *old_password, const gchar *new_password)
122
 
{
123
 
        krb5_context ctx;
124
 
        krb5_creds creds;
125
 
        krb5_data res_code_string, res_string;
126
 
        E2kKerberosResult result;
127
 
        gint res_code;
128
 
 
129
 
        ctx = e2k_kerberos_context_new (domain);
130
 
        if (!ctx)
131
 
                return E2K_KERBEROS_FAILED;
132
 
 
133
 
        result = get_init_cred (ctx, user, old_password,
134
 
                                "kadmin/changepw", &creds);
135
 
        if (result != E2K_KERBEROS_OK) {
136
 
                krb5_free_context (ctx);
137
 
                return result;
138
 
        }
139
 
 
140
 
        result = krb5_change_password (ctx, &creds, (gchar *)new_password,
141
 
                                       &res_code, &res_code_string, &res_string);
142
 
        krb5_free_cred_contents (ctx, &creds);
143
 
        krb5_free_data_contents (ctx, &res_code_string);
144
 
        krb5_free_data_contents (ctx, &res_string);
145
 
        krb5_free_context (ctx);
146
 
 
147
 
        if (result != 0)
148
 
                return krb5_result_to_e2k_kerberos_result (result);
149
 
        else if (res_code != 0)
150
 
                return E2K_KERBEROS_FAILED;
151
 
        else
152
 
                return E2K_KERBEROS_OK;
153
 
}
154
 
 
155
 
/**
156
 
 * e2k_kerberos_check_password:
157
 
 * @user: username
158
 
 * @domain: Windows (2000) domain name
159
 
 * @password: current password
160
 
 *
161
 
 * Checks if the password is valid, invalid, or expired
162
 
 *
163
 
 * Return value: %E2K_KERBEROS_OK, %E2K_KERBEROS_USER_UNKNOWN,
164
 
 * %E2K_KERBEROS_PASSWORD_INCORRECT, %E2K_KERBEROS_PASSWORD_EXPIRED,
165
 
 * or %E2K_KERBEROS_FAILED (for unknown errors)
166
 
 **/
167
 
E2kKerberosResult
168
 
e2k_kerberos_check_password (const gchar *user, const gchar *domain,
169
 
                             const gchar *password)
170
 
{
171
 
        krb5_context ctx;
172
 
        krb5_creds creds;
173
 
        E2kKerberosResult result;
174
 
 
175
 
        ctx = e2k_kerberos_context_new (domain);
176
 
        if (!ctx)
177
 
                return E2K_KERBEROS_FAILED;
178
 
 
179
 
        result = get_init_cred (ctx, user, password, NULL, &creds);
180
 
 
181
 
        krb5_free_context (ctx);
182
 
        if (result == E2K_KERBEROS_OK)
183
 
                krb5_free_cred_contents (ctx, &creds);
184
 
 
185
 
        return result;
186
 
}