~ubuntu-branches/ubuntu/maverick/krb5/maverick

« back to all changes in this revision

Viewing changes to src/util/profile/prof_file.c

  • Committer: Bazaar Package Importer
  • Author(s): Sam Hartman
  • Date: 2009-05-07 16:16:34 UTC
  • mfrom: (13.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090507161634-xqyk0s9na0le4flj
Tags: 1.7dfsg~beta1-4
When  decrypting the TGS response fails with the subkey, try with the
session key to work around Heimdal bug, Closes: #527353 

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#ifdef SHOW_INITFINI_FUNCS
53
53
    printf("profile_library_initializer\n");
54
54
#endif
55
 
#if !USE_BUNDLE_ERROR_STRINGS
56
55
    add_error_table(&et_prof_error_table);
57
 
#endif
 
56
 
58
57
    return k5_mutex_finish_init(&g_shared_trees_mutex);
59
58
}
60
59
void profile_library_finalizer(void)
69
68
    printf("profile_library_finalizer\n");
70
69
#endif
71
70
    k5_mutex_destroy(&g_shared_trees_mutex);
72
 
#if !USE_BUNDLE_ERROR_STRINGS
 
71
 
73
72
    remove_error_table(&et_prof_error_table);
74
 
#endif
75
73
}
76
74
 
77
75
static void profile_free_file_data(prf_data_t);
157
155
#endif
158
156
}
159
157
 
 
158
int profile_file_is_writable(prf_file_t profile)
 
159
{
 
160
    if (profile && profile->data) {
 
161
        return rw_access(profile->data->filespec);
 
162
    } else {
 
163
        return 0;
 
164
    }
 
165
}
 
166
 
160
167
prf_data_t
161
168
profile_make_prf_data(const char *filename)
162
169
{
175
182
    memset(d, 0, len);
176
183
    fcopy = (char *) d + slen;
177
184
    assert(fcopy == d->filespec);
178
 
    strcpy(fcopy, filename);
 
185
    strlcpy(fcopy, filename, flen + 1);
179
186
    d->refcount = 1;
180
187
    d->comment = NULL;
181
188
    d->magic = PROF_MAGIC_FILE_DATA;
191
198
        prf_file_t      prf;
192
199
        errcode_t       retval;
193
200
        char            *home_env = 0;
194
 
        unsigned int    len;
195
201
        prf_data_t      data;
196
202
        char            *expanded_filename;
197
203
 
207
213
        memset(prf, 0, sizeof(struct _prf_file_t));
208
214
        prf->magic = PROF_MAGIC_FILE;
209
215
 
210
 
        len = strlen(filespec)+1;
211
216
        if (filespec[0] == '~' && filespec[1] == '/') {
212
217
                home_env = getenv("HOME");
213
218
#ifdef HAVE_PWD_H
222
227
                        home_env = pw->pw_dir;
223
228
                }
224
229
#endif
225
 
                if (home_env)
226
 
                        len += strlen(home_env);
227
230
        }
228
 
        expanded_filename = malloc(len);
229
 
        if (expanded_filename == 0)
230
 
            return errno;
231
231
        if (home_env) {
232
 
            strcpy(expanded_filename, home_env);
233
 
            strcat(expanded_filename, filespec+1);
 
232
            if (asprintf(&expanded_filename, "%s%s", home_env,
 
233
                         filespec + 1) < 0)
 
234
                expanded_filename = 0;
234
235
        } else
235
 
            memcpy(expanded_filename, filespec, len);
 
236
            expanded_filename = strdup(filespec);
 
237
        if (expanded_filename == 0) {
 
238
            free(prf);
 
239
            return ENOMEM;
 
240
        }
236
241
 
237
242
        retval = k5_mutex_lock(&g_shared_trees_mutex);
238
243
        if (retval) {
367
372
                        retval = ENOENT;
368
373
                return retval;
369
374
        }
 
375
        set_cloexec_file(f);
370
376
        data->upd_serial++;
371
 
        data->flags &= PROFILE_FILE_SHARED;
372
 
        if (rw_access(data->filespec))
373
 
                data->flags |= PROFILE_FILE_RW;
 
377
        data->flags &= PROFILE_FILE_SHARED;  /* FIXME same as '=' operator */
374
378
        retval = profile_parse_file(f, &data->root);
375
379
        fclose(f);
376
380
        if (retval) {
407
411
        retval = ENOMEM;
408
412
        
409
413
        new_file = old_file = 0;
410
 
        new_file = malloc(strlen(outfile) + 5);
411
 
        if (!new_file)
412
 
                goto errout;
413
 
        old_file = malloc(strlen(outfile) + 5);
414
 
        if (!old_file)
415
 
                goto errout;
416
 
 
417
 
        sprintf(new_file, "%s.$$$", outfile);
418
 
        sprintf(old_file, "%s.bak", outfile);
 
414
        if (asprintf(&new_file, "%s.$$$", outfile) < 0) {
 
415
            new_file = NULL;
 
416
            goto errout;
 
417
        }
 
418
        if (asprintf(&old_file, "%s.bak", outfile) < 0) {
 
419
            old_file = NULL;
 
420
            goto errout;
 
421
        }
419
422
 
420
423
        errno = 0;
421
424
 
427
430
                goto errout;
428
431
        }
429
432
 
 
433
        set_cloexec_file(f);
430
434
        profile_write_tree_file(data->root, f);
431
435
        if (fclose(f) != 0) {
432
436
                retval = errno;
469
473
        }
470
474
 
471
475
        data->flags = 0;
472
 
        if (rw_access(outfile))
473
 
                data->flags |= PROFILE_FILE_RW;
474
476
        retval = 0;
475
477
 
476
478
errout: