~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper

« back to all changes in this revision

Viewing changes to driver/passwd-kerberos.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2005-10-11 21:00:42 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051011210042-u7q6zslgevdxspr3
Tags: 4.21-4ubuntu17
updated pt_BR again, fixed to UTF-8 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* kpasswd.c --- verify kerberos passwords.
2
2
 * written by Nat Lanza (magus@cs.cmu.edu) for
3
 
 * xscreensaver, Copyright (c) 1993-1997, 1998, 2000
4
 
 *  Jamie Zawinski <jwz@jwz.org>
 
3
 * xscreensaver, Copyright (c) 1993-2004 Jamie Zawinski <jwz@jwz.org>
5
4
 *
6
5
 * Permission to use, copy, modify, distribute, and sell this software and its
7
6
 * documentation for any purpose is hereby granted without fee, provided that
26
25
#include <stdio.h>
27
26
#include <string.h>
28
27
#include <sys/types.h>
29
 
 
30
 
#ifdef HAVE_KERBEROS5
 
28
#include <sys/stat.h>
 
29
 
 
30
/* I'm not sure if this is exactly the right test...
 
31
   Might __APPLE__ be defined if this is apple hardware, but not
 
32
   an Apple OS?
 
33
 
 
34
   Thanks to Alexei Kosut <akosut@stanford.edu> for the MacOS X code.
 
35
 */
 
36
#ifdef __APPLE__
 
37
# define HAVE_DARWIN
 
38
#endif
 
39
 
 
40
 
 
41
#if defined(HAVE_DARWIN)
 
42
# include <Kerberos/Kerberos.h>
 
43
#elif defined(HAVE_KERBEROS5)
31
44
# include <kerberosIV/krb.h>
32
45
# include <kerberosIV/des.h>
33
46
#else /* !HAVE_KERBEROS5 (meaning Kerberos 4) */
56
69
#define False 0
57
70
 
58
71
/* The user information we need to store */
59
 
static char realm[REALM_SZ];
60
 
static char  name[ANAME_SZ];
61
 
static char  inst[INST_SZ];
62
 
static char *tk_file;
 
72
#ifdef HAVE_DARWIN
 
73
 static KLPrincipal princ;
 
74
#else /* !HAVE_DARWIN */
 
75
 static char realm[REALM_SZ];
 
76
 static char  name[ANAME_SZ];
 
77
 static char  inst[INST_SZ];
 
78
 static char *tk_file;
 
79
#endif /* !HAVE_DARWIN */
63
80
 
64
81
 
65
82
/* Called at startup to grab user, instance, and realm information
83
100
Bool
84
101
kerberos_lock_init (int argc, char **argv, Bool verbose_p)
85
102
{
 
103
# ifdef HAVE_DARWIN
 
104
 
 
105
    KLBoolean found;
 
106
    return ((klNoErr == (KLCacheHasValidTickets (NULL, kerberosVersion_Any,
 
107
                                                 &found, &princ, NULL)))
 
108
            && found);
 
109
 
 
110
# else /* !HAVE_DARWIN */
 
111
 
 
112
    /* Perhaps we should be doing it the Mac way (above) all the time?
 
113
       The following code assumes Unix-style file-based Kerberos credentials
 
114
       cache, which Mac OS X doesn't use.  But is there any real reason to
 
115
       do it this way at all, even on other Unixen?
 
116
     */
86
117
    int k_errno;
87
118
    
88
119
    memset(name, 0, sizeof(name));
120
151
 
121
152
    /* success */
122
153
    return True;
 
154
 
 
155
# endif /* !HAVE_DARWIN */
123
156
}
124
157
 
125
158
 
128
161
   we are. Calling it ive_got_your_local_function_right_here_buddy()
129
162
   would have been rude.
130
163
 */
 
164
#ifndef HAVE_DARWIN
131
165
static int 
132
166
key_to_key(char *user, char *instance, char *realm, char *passwd, C_Block key)
133
167
{
134
168
  memcpy(key, passwd, sizeof(des_cblock));
135
169
  return (0);
136
170
}
 
171
#endif /* !HAVE_DARWIN */
137
172
 
138
173
/* Called to see if the user's typed password is valid. We do this by asking
139
174
   the kerberos server for a ticket and checking to see if it gave us one.
145
180
Bool
146
181
kerberos_passwd_valid_p (const char *typed_passwd, Bool verbose_p)
147
182
{
 
183
# ifdef HAVE_DARWIN
 
184
    return (klNoErr ==
 
185
            KLAcquireNewInitialTicketsWithPassword (princ, NULL,
 
186
                                                    typed_passwd, NULL));
 
187
# else /* !HAVE_DARWIN */
 
188
 
 
189
    /* See comments in kerberos_lock_init -- should we do it the Mac Way
 
190
       on all systems?
 
191
     */
148
192
    C_Block mitkey;
149
193
    Bool success;
150
194
    char *newtkfile;
 
195
    int fh = -1;
151
196
 
152
197
    /* temporarily switch to a new ticketfile.
153
198
       I'm not using tmpnam() because it isn't entirely portable.
155
200
    newtkfile = malloc(80 * sizeof(char));
156
201
    memset(newtkfile, 0, sizeof(newtkfile));
157
202
 
158
 
    sprintf(newtkfile, "/tmp/xscrn-%i", getpid());
 
203
    sprintf(newtkfile, "/tmp/xscrn-%i.XXXXXX", getpid());
 
204
 
 
205
    if( (fh = mkstemp(newtkfile)) < 0)
 
206
    {
 
207
        free(newtkfile);
 
208
        return(False);
 
209
    }
 
210
    if( fchmod(fh, 0600) < 0)
 
211
    {
 
212
        free(newtkfile);
 
213
        return(False);
 
214
    }
 
215
 
159
216
 
160
217
    krb_set_tkt_string(newtkfile);
161
218
 
178
235
    krb_set_tkt_string(tk_file);
179
236
    free(newtkfile);
180
237
    memset(mitkey, 0, sizeof(mitkey));
 
238
    close(fh); /* #### tom: should the file be removed? */
181
239
    
182
240
 
183
241
    /* Did we verify successfully? */
184
242
    return success;
 
243
 
 
244
# endif /* !HAVE_DARWIN */
185
245
}
186
246
 
187
247
#endif /* NO_LOCKING -- whole file */