~ubuntu-branches/ubuntu/raring/heimdal/raring

« back to all changes in this revision

Viewing changes to lib/krb5/fcache.c

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-07-21 17:40:58 UTC
  • mfrom: (1.1.12 upstream) (2.4.10 experimental)
  • Revision ID: james.westby@ubuntu.com-20110721174058-byiuowgocek307cs
Tags: 1.5~pre2+git20110720-2
Fix dependency on pthreads when building on Linux 3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
fcc_get_name(krb5_context context,
63
63
             krb5_ccache id)
64
64
{
 
65
    if (FCACHE(id) == NULL)
 
66
        return NULL;
 
67
 
65
68
    return FILENAME(id);
66
69
}
67
70
 
155
158
        return ret;
156
159
    }
157
160
    sret = write(fd, data.data, data.length);
158
 
    ret = (sret != data.length);
 
161
    ret = (sret != (ssize_t)data.length);
159
162
    krb5_data_free(&data);
160
163
    if (ret) {
161
164
        ret = errno;
220
223
        return errno;
221
224
    memset(buf, 0, sizeof(buf));
222
225
    while(pos > 0) {
223
 
        ssize_t tmp = write(fd, buf, min(sizeof(buf), pos));
 
226
        ssize_t tmp = write(fd, buf, min((off_t)sizeof(buf), pos));
224
227
 
225
228
        if (tmp < 0)
226
229
            return errno;
334
337
 
335
338
    fd = mkstemp(exp_file);
336
339
    if(fd < 0) {
337
 
        int ret = errno;
338
 
        krb5_set_error_message(context, ret, N_("mkstemp %s failed", ""), exp_file);
 
340
        int xret = errno;
 
341
        krb5_set_error_message(context, xret, N_("mkstemp %s failed", ""), exp_file);
339
342
        free(f);
340
343
        free(exp_file);
341
 
        return ret;
 
344
        return xret;
342
345
    }
343
346
    close(fd);
344
347
    f->filename = exp_file;
383
386
    krb5_boolean exclusive = ((flags | O_WRONLY) == flags ||
384
387
                              (flags | O_RDWR) == flags);
385
388
    krb5_error_code ret;
386
 
    const char *filename = FILENAME(id);
 
389
    const char *filename;
387
390
    int fd;
 
391
 
 
392
    if (FCACHE(id) == NULL)
 
393
        return krb5_einval(context, 2);
 
394
 
 
395
    filename = FILENAME(id);
 
396
 
388
397
    fd = open(filename, flags, mode);
389
398
    if(fd < 0) {
390
399
        char buf[128];
412
421
    krb5_fcache *f = FCACHE(id);
413
422
    int ret = 0;
414
423
    int fd;
415
 
    char *filename = f->filename;
416
 
 
417
 
    unlink (filename);
 
424
 
 
425
    if (f == NULL)
 
426
        return krb5_einval(context, 2);
 
427
 
 
428
    unlink (f->filename);
418
429
 
419
430
    ret = fcc_open(context, id, &fd, O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_CLOEXEC, 0600);
420
431
    if(ret)
443
454
            }
444
455
        }
445
456
        ret |= krb5_store_principal(sp, primary_principal);
446
 
        
 
457
 
447
458
        ret |= write_storage(context, sp, fd);
448
459
 
449
460
        krb5_storage_free(sp);
464
475
fcc_close(krb5_context context,
465
476
          krb5_ccache id)
466
477
{
 
478
    if (FCACHE(id) == NULL)
 
479
        return krb5_einval(context, 2);
 
480
 
467
481
    free (FILENAME(id));
468
482
    krb5_data_free(&id->data);
469
483
    return 0;
473
487
fcc_destroy(krb5_context context,
474
488
            krb5_ccache id)
475
489
{
 
490
    if (FCACHE(id) == NULL)
 
491
        return krb5_einval(context, 2);
 
492
 
476
493
    _krb5_erase_file(context, FILENAME(id));
477
494
    return 0;
478
495
}
701
718
    krb5_error_code ret;
702
719
    krb5_principal principal;
703
720
 
 
721
    if (FCACHE(id) == NULL)
 
722
        return krb5_einval(context, 2);
 
723
 
704
724
    *cursor = malloc(sizeof(struct fcc_cursor));
705
725
    if (*cursor == NULL) {
706
726
        krb5_set_error_message(context, ENOMEM, N_("malloc: out of memory", ""));
733
753
              krb5_creds *creds)
734
754
{
735
755
    krb5_error_code ret;
 
756
 
 
757
    if (FCACHE(id) == NULL)
 
758
        return krb5_einval(context, 2);
 
759
 
 
760
    if (FCC_CURSOR(*cursor) == NULL)
 
761
        return krb5_einval(context, 3);
 
762
 
736
763
    if((ret = fcc_lock(context, id, FCC_CURSOR(*cursor)->fd, FALSE)) != 0)
737
764
        return ret;
738
765
 
749
776
             krb5_ccache id,
750
777
             krb5_cc_cursor *cursor)
751
778
{
 
779
 
 
780
    if (FCACHE(id) == NULL)
 
781
        return krb5_einval(context, 2);
 
782
 
 
783
    if (FCC_CURSOR(*cursor) == NULL)
 
784
        return krb5_einval(context, 3);
 
785
 
752
786
    krb5_storage_free(FCC_CURSOR(*cursor)->sp);
753
787
    close (FCC_CURSOR(*cursor)->fd);
754
788
    free(*cursor);
767
801
    char *newname = NULL;
768
802
    int fd;
769
803
 
 
804
    if (FCACHE(id) == NULL)
 
805
        return krb5_einval(context, 2);
 
806
 
770
807
    ret = krb5_cc_new_unique(context, krb5_cc_type_memory, NULL, &copy);
771
808
    if (ret)
772
809
        return ret;
827
864
              krb5_ccache id,
828
865
              krb5_flags flags)
829
866
{
 
867
    if (FCACHE(id) == NULL)
 
868
        return krb5_einval(context, 2);
 
869
 
830
870
    return 0; /* XXX */
831
871
}
832
872
 
834
874
fcc_get_version(krb5_context context,
835
875
                krb5_ccache id)
836
876
{
 
877
    if (FCACHE(id) == NULL)
 
878
        return -1;
 
879
 
837
880
    return FCACHE(id)->version;
838
881
}
839
 
                
 
882
 
840
883
struct fcache_iter {
841
884
    int first;
842
885
};
864
907
    const char *fn;
865
908
    char *expandedfn = NULL;
866
909
 
 
910
    if (iter == NULL)
 
911
        return krb5_einval(context, 2);
 
912
 
867
913
    if (!iter->first) {
868
914
        krb5_clear_error_message(context);
869
915
        return KRB5_CC_END;
900
946
fcc_end_cache_get(krb5_context context, krb5_cc_cursor cursor)
901
947
{
902
948
    struct fcache_iter *iter = cursor;
 
949
 
 
950
    if (iter == NULL)
 
951
        return krb5_einval(context, 2);
 
952
 
903
953
    free(iter);
904
954
    return 0;
905
955
}