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

« back to all changes in this revision

Viewing changes to src/windows/identity/kcreddb/attrib.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2006-10-30 10:28:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20061030102853-x7v876vw4af46v0m
Tags: 1.4.4-3ubuntu1
* Merge with Debian; only Ubuntu change:
  - src/include/k5-thread.h: Define__USE_GNU when #include'ing pthread.h to
    fix FTBFS (from 1.4.3-9ubuntu1).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2004 Massachusetts Institute of Technology
 
2
 * Copyright (c) 2005 Massachusetts Institute of Technology
3
3
 *
4
4
 * Permission is hereby granted, free of charge, to any person
5
5
 * obtaining a copy of this software and associated documentation
33
33
kcdb_attrib_i ** kcdb_property_tbl = NULL;
34
34
kcdb_attrib_i * kcdb_attribs = NULL;
35
35
 
36
 
void kcdb_attrib_add_ref_func(const void * key, void * va)
 
36
void 
 
37
kcdb_attrib_add_ref_func(const void * key, void * va)
37
38
{
38
39
    kcdb_attrib_hold((kcdb_attrib_i *) va);
39
40
}
40
41
 
41
 
void kcdb_attrib_del_ref_func(const void * key, void * va)
 
42
void 
 
43
kcdb_attrib_del_ref_func(const void * key, void * va)
42
44
{
43
45
    kcdb_attrib_release((kcdb_attrib_i *) va);
44
46
}
45
47
 
46
 
void kcdb_attrib_msg_completion(kmq_message * m) 
 
48
void 
 
49
kcdb_attrib_msg_completion(kmq_message * m) 
47
50
{
48
51
    if(m && m->vparam) {
49
52
        kcdb_attrib_release((kcdb_attrib_i *) m->vparam);
50
53
    }
51
54
}
52
55
 
53
 
khm_int32 kcdb_attrib_hold(kcdb_attrib_i * ai)
 
56
khm_int32 
 
57
kcdb_attrib_hold(kcdb_attrib_i * ai)
54
58
{
55
59
    if(!ai)
56
 
        return KHM_ERROR_INVALID_PARM;
 
60
        return KHM_ERROR_INVALID_PARAM;
57
61
 
58
62
    EnterCriticalSection(&cs_attrib);
59
63
    ai->refcount++;
61
65
    return KHM_ERROR_SUCCESS;
62
66
}
63
67
 
64
 
khm_int32 kcdb_attrib_release(kcdb_attrib_i * ai)
 
68
khm_int32 
 
69
kcdb_attrib_release(kcdb_attrib_i * ai)
65
70
{
66
71
    if(!ai)
67
 
        return KHM_ERROR_INVALID_PARM;
 
72
        return KHM_ERROR_INVALID_PARAM;
68
73
 
69
74
    EnterCriticalSection(&cs_attrib);
70
75
    ai->refcount--;
72
77
    return KHM_ERROR_SUCCESS;
73
78
}
74
79
 
75
 
void kcdb_attrib_post_message(khm_int32 op, kcdb_attrib_i * ai)
 
80
void 
 
81
kcdb_attrib_post_message(khm_int32 op, kcdb_attrib_i * ai)
76
82
{
77
83
    kcdb_attrib_hold(ai);
78
84
    kmq_post_message(KMSG_KCDB, KMSG_KCDB_ATTRIB, op, (void *) ai);
79
85
}
80
86
 
81
 
khm_int32 KHMAPI kcdb_attr_sys_cb(khm_handle vcred, 
82
 
                                  khm_int32 attr, 
83
 
                                  void * buf, 
84
 
                                  khm_size * pcb_buf)
 
87
khm_int32 KHMAPI 
 
88
kcdb_attr_sys_cb(khm_handle vcred, 
 
89
                 khm_int32 attr, 
 
90
                 void * buf, 
 
91
                 khm_size * pcb_buf)
85
92
{
86
93
    kcdb_cred * c;
87
94
 
121
128
 
122
129
    case KCDB_ATTR_TIMELEFT:
123
130
        {
124
 
            /* we are going to make liberal use of __int64 here.  It
125
 
               is equivalent to FILETIME and also the MSDN docs say we
126
 
               should use it if the compiler supports it */
127
131
            khm_int32 rv = KHM_ERROR_SUCCESS;
128
 
            unsigned __int64 ftc;
129
 
            SYSTEMTIME st;
130
132
 
131
 
            if(!buf || *pcb_buf < sizeof(__int64)) {
132
 
                *pcb_buf = sizeof(__int64);
 
133
            if(!buf || *pcb_buf < sizeof(FILETIME)) {
 
134
                *pcb_buf = sizeof(FILETIME);
133
135
                rv = KHM_ERROR_TOO_LONG;
134
136
            } else if(!kcdb_cred_buf_exist(c,KCDB_ATTR_EXPIRE)) {
135
 
                *pcb_buf = sizeof(__int64);
 
137
                *pcb_buf = sizeof(FILETIME);
136
138
                /* setting the timeleft to _I64_MAX has the
137
139
                   interpretation that this credential does not
138
140
                   expire, which is the default behavior if the
139
141
                   expiration time is not known */
140
 
                *((__int64 *) buf) = _I64_MAX;
 
142
                *((FILETIME *) buf) = IntToFt(_I64_MAX);
141
143
            } else {
142
 
                GetSystemTime(&st);
143
 
                SystemTimeToFileTime(&st, (LPFILETIME) &ftc);
144
 
                *((__int64 *) buf) =
145
 
                    *((__int64 *) kcdb_cred_buf_get(c,KCDB_ATTR_EXPIRE)) - ftc;
 
144
                FILETIME ftc;
 
145
                khm_int64 iftc;
 
146
 
 
147
                GetSystemTimeAsFileTime(&ftc);
 
148
                iftc = FtToInt(&ftc);
 
149
 
 
150
                *((FILETIME *) buf) =
 
151
                    IntToFt(FtToInt((FILETIME *) 
 
152
                                    kcdb_cred_buf_get(c,KCDB_ATTR_EXPIRE))
 
153
                            - iftc);
 
154
                *pcb_buf = sizeof(FILETIME);
146
155
            }
147
156
 
148
157
            return rv;
150
159
 
151
160
    case KCDB_ATTR_RENEW_TIMELEFT:
152
161
        {
153
 
            /* we are going to make liberal use of __int64 here.  It
154
 
               is equivalent to FILETIME and also the MSDN docs say we
155
 
               should use it if the compiler supports it */
156
162
            khm_int32 rv = KHM_ERROR_SUCCESS;
157
 
            unsigned __int64 ftc;
158
 
            SYSTEMTIME st;
159
163
 
160
 
            if(!buf || *pcb_buf < sizeof(__int64)) {
161
 
                *pcb_buf = sizeof(__int64);
 
164
            if(!buf || *pcb_buf < sizeof(FILETIME)) {
 
165
                *pcb_buf = sizeof(FILETIME);
162
166
                rv = KHM_ERROR_TOO_LONG;
163
167
            } else if(!kcdb_cred_buf_exist(c,KCDB_ATTR_RENEW_EXPIRE)) {
164
 
                *pcb_buf = sizeof(__int64);
 
168
                *pcb_buf = sizeof(FILETIME);
165
169
                /* setting the timeleft to _I64_MAX has the
166
170
                   interpretation that this credential does not
167
171
                   expire, which is the default behavior if the
168
172
                   expiration time is not known */
169
 
                *((__int64 *) buf) = _I64_MAX;
 
173
                *((FILETIME *) buf) = IntToFt(_I64_MAX);
170
174
            } else {
171
 
                GetSystemTime(&st);
172
 
                SystemTimeToFileTime(&st, (LPFILETIME) &ftc);
173
 
                *((__int64 *) buf) =
174
 
                    *((__int64 *) kcdb_cred_buf_get(c,KCDB_ATTR_RENEW_EXPIRE)) - ftc;
 
175
                FILETIME ftc;
 
176
                khm_int64 i_re;
 
177
                khm_int64 i_ct;
 
178
 
 
179
                GetSystemTimeAsFileTime(&ftc);
 
180
 
 
181
                i_re = FtToInt(((FILETIME *)
 
182
                                kcdb_cred_buf_get(c, KCDB_ATTR_RENEW_EXPIRE)));
 
183
                i_ct = FtToInt(&ftc);
 
184
 
 
185
                if (i_re > i_ct)
 
186
                    *((FILETIME *) buf) =
 
187
                        IntToFt(i_re - i_ct);
 
188
                else
 
189
                    *((FILETIME *) buf) =
 
190
                        IntToFt(0);
 
191
 
 
192
                *pcb_buf = sizeof(FILETIME);
175
193
            }
176
194
 
177
195
            return rv;
192
210
    }
193
211
}
194
212
 
195
 
void kcdb_attrib_init(void)
 
213
void 
 
214
kcdb_attrib_init(void)
196
215
{
197
216
    kcdb_attrib attrib;
198
217
    wchar_t sbuf[256];
199
218
 
200
219
    InitializeCriticalSection(&cs_attrib);
201
 
    kcdb_attrib_namemap = hash_new_hashtable(
202
 
        KCDB_ATTRIB_HASH_SIZE,
203
 
        hash_string,
204
 
        hash_string_comp,
205
 
        kcdb_attrib_add_ref_func,
206
 
        kcdb_attrib_del_ref_func);
 
220
    kcdb_attrib_namemap = 
 
221
        hash_new_hashtable(KCDB_ATTRIB_HASH_SIZE,
 
222
                           hash_string,
 
223
                           hash_string_comp,
 
224
                           kcdb_attrib_add_ref_func,
 
225
                           kcdb_attrib_del_ref_func);
207
226
 
208
227
    kcdb_attrib_tbl = 
209
 
        malloc(sizeof(kcdb_attrib_i *) * (KCDB_ATTR_MAX_ID + 1));
 
228
        PMALLOC(sizeof(kcdb_attrib_i *) * (KCDB_ATTR_MAX_ID + 1));
210
229
    assert(kcdb_attrib_tbl != NULL);
211
230
    ZeroMemory(kcdb_attrib_tbl, 
212
231
               sizeof(kcdb_attrib_i *) * (KCDB_ATTR_MAX_ID + 1));
213
232
 
214
233
    kcdb_property_tbl = 
215
 
        malloc(sizeof(kcdb_attrib_i *) * KCDB_ATTR_MAX_PROPS);
 
234
        PMALLOC(sizeof(kcdb_attrib_i *) * KCDB_ATTR_MAX_PROPS);
216
235
    assert(kcdb_property_tbl != NULL);
217
236
    ZeroMemory(kcdb_property_tbl, 
218
237
               sizeof(kcdb_attrib_i *) * KCDB_ATTR_MAX_PROPS);
319
338
    LoadString(hinst_kcreddb, IDS_PARENT, sbuf, ARRAYLENGTH(sbuf));
320
339
    attrib.short_desc = sbuf;
321
340
    attrib.long_desc = NULL;
322
 
    attrib.flags = KCDB_ATTR_FLAG_SYSTEM;
 
341
    attrib.flags = KCDB_ATTR_FLAG_SYSTEM | KCDB_ATTR_FLAG_HIDDEN;
323
342
    attrib.compute_cb = NULL;
324
343
    attrib.compute_min_cbsize = 0;
325
344
    attrib.compute_max_cbsize = 0;
382
401
        KCDB_ATTR_FLAG_ALTVIEW |
383
402
        KCDB_ATTR_FLAG_VOLATILE;
384
403
    attrib.compute_cb = kcdb_attr_sys_cb;
385
 
    attrib.compute_min_cbsize = sizeof(__int64);
386
 
    attrib.compute_max_cbsize = sizeof(__int64);
 
404
    attrib.compute_min_cbsize = sizeof(FILETIME);
 
405
    attrib.compute_max_cbsize = sizeof(FILETIME);
387
406
 
388
407
    kcdb_attrib_register(&attrib, NULL);
389
408
 
401
420
        KCDB_ATTR_FLAG_ALTVIEW |
402
421
        KCDB_ATTR_FLAG_VOLATILE;
403
422
    attrib.compute_cb = kcdb_attr_sys_cb;
404
 
    attrib.compute_min_cbsize = sizeof(__int64);
405
 
    attrib.compute_max_cbsize = sizeof(__int64);
 
423
    attrib.compute_min_cbsize = sizeof(FILETIME);
 
424
    attrib.compute_max_cbsize = sizeof(FILETIME);
406
425
 
407
426
    kcdb_attrib_register(&attrib, NULL);
408
427
 
468
487
    kcdb_attrib_register(&attrib, NULL);
469
488
}
470
489
 
471
 
void kcdb_attrib_exit(void)
 
490
void 
 
491
kcdb_attrib_exit(void)
472
492
{
473
493
    DeleteCriticalSection(&cs_attrib);
474
494
    
475
495
    if(kcdb_attrib_tbl)
476
 
        free(kcdb_attrib_tbl);
 
496
        PFREE(kcdb_attrib_tbl);
477
497
 
478
498
    if(kcdb_property_tbl)
479
 
        free(kcdb_property_tbl);
 
499
        PFREE(kcdb_property_tbl);
480
500
}
481
501
 
482
 
KHMEXP khm_int32 KHMAPI kcdb_attrib_get_id(wchar_t *name, khm_int32 * id)
 
502
KHMEXP khm_int32 KHMAPI 
 
503
kcdb_attrib_get_id(wchar_t *name, khm_int32 * id)
483
504
{
484
505
    kcdb_attrib_i * ai;
485
506
 
486
507
    if(!name)
487
 
        return KHM_ERROR_INVALID_PARM;
 
508
        return KHM_ERROR_INVALID_PARAM;
488
509
 
489
510
    EnterCriticalSection(&cs_attrib);
490
511
    ai = hash_lookup(kcdb_attrib_namemap, (void *) name);
499
520
    }
500
521
}
501
522
 
502
 
KHMEXP khm_int32 KHMAPI kcdb_attrib_register(kcdb_attrib * attrib, khm_int32 * new_id)
 
523
KHMEXP khm_int32 KHMAPI 
 
524
kcdb_attrib_register(kcdb_attrib * attrib, khm_int32 * new_id)
503
525
{
504
526
    kcdb_attrib_i * ai;
505
527
    size_t cb_name;
511
533
    if(!attrib ||
512
534
        KHM_FAILED(kcdb_type_get_info(attrib->type, NULL)) ||
513
535
        !attrib->name)
514
 
        return KHM_ERROR_INVALID_PARM;
 
536
        return KHM_ERROR_INVALID_PARAM;
515
537
 
516
538
    if(FAILED(StringCbLength(attrib->name, KCDB_MAXCB_NAME, &cb_name)))
517
539
        return KHM_ERROR_TOO_LONG;
535
557
        (!attrib->compute_cb ||
536
558
        attrib->compute_min_cbsize <= 0 ||
537
559
        attrib->compute_max_cbsize < attrib->compute_min_cbsize))
538
 
        return KHM_ERROR_INVALID_PARM;
 
560
        return KHM_ERROR_INVALID_PARAM;
539
561
 
540
562
    if ((attrib->flags & KCDB_ATTR_FLAG_ALTVIEW) &&
541
563
        KHM_FAILED(kcdb_attrib_get_info(attrib->alt_id,
542
564
                                        NULL)))
543
 
        return KHM_ERROR_INVALID_PARM;
 
565
        return KHM_ERROR_INVALID_PARAM;
544
566
 
545
567
    prop = !!(attrib->flags & KCDB_ATTR_FLAG_PROPERTY);
546
568
 
547
569
    EnterCriticalSection(&cs_attrib);
548
570
 
549
 
    if(
550
 
        !prop && 
551
 
        (attrib->id < 0 || attrib->id > KCDB_ATTR_MAX_ID)) 
 
571
    if(!prop && 
 
572
       (attrib->id < 0 || attrib->id > KCDB_ATTR_MAX_ID)) 
552
573
    {
553
574
        if(KHM_FAILED(kcdb_attrib_next_free_id(&attr_id))) {
554
575
            LeaveCriticalSection(&cs_attrib);
555
576
            return KHM_ERROR_NO_RESOURCES;
556
577
        }
557
 
    } else if (
558
 
        prop &&
559
 
        (attrib->id < KCDB_ATTR_MIN_PROP_ID || attrib->id > KCDB_ATTR_MAX_PROP_ID))
560
 
    {
 
578
    } else if (prop &&
 
579
               (attrib->id < KCDB_ATTR_MIN_PROP_ID || 
 
580
                attrib->id > KCDB_ATTR_MAX_PROP_ID)) {
 
581
 
561
582
        if(KHM_FAILED(kcdb_attrib_next_free_prop_id(&attr_id))) {
562
583
            LeaveCriticalSection(&cs_attrib);
563
584
            return KHM_ERROR_NO_RESOURCES;
564
585
        }
 
586
 
565
587
    } else {
566
588
        attr_id = attrib->id;
567
589
    }
568
590
 
569
591
#ifdef DEBUG
570
592
    assert(!prop || (attr_id >= KCDB_ATTR_MIN_PROP_ID && attr_id <= KCDB_ATTR_MAX_PROP_ID));
571
 
    assert(prop || (attr_id >= 0 && attr_id <= KCDB_ATTR_MAX_ID));
 
593
    assert(prop  || (attr_id >= 0 && attr_id <= KCDB_ATTR_MAX_ID));
572
594
#endif
573
595
 
574
596
    if((!prop && kcdb_attrib_tbl[attr_id]) ||
575
 
        (prop && kcdb_property_tbl[attr_id - KCDB_ATTR_MIN_PROP_ID])) 
576
 
    {
 
597
       (prop && kcdb_property_tbl[attr_id - KCDB_ATTR_MIN_PROP_ID])) {
 
598
 
577
599
        LeaveCriticalSection(&cs_attrib);
578
600
        return KHM_ERROR_DUPLICATE;
 
601
 
579
602
    }
580
603
 
581
 
    ai = malloc(sizeof(kcdb_attrib_i));
 
604
    ai = PMALLOC(sizeof(kcdb_attrib_i));
582
605
    ZeroMemory(ai, sizeof(kcdb_attrib_i));
583
606
 
584
607
    ai->attr.type = attrib->type;
588
611
    ai->attr.compute_cb = attrib->compute_cb;
589
612
    ai->attr.compute_max_cbsize = attrib->compute_max_cbsize;
590
613
    ai->attr.compute_min_cbsize = attrib->compute_min_cbsize;
591
 
    ai->attr.name = malloc(cb_name);
 
614
    ai->attr.name = PMALLOC(cb_name);
592
615
    StringCbCopy(ai->attr.name, cb_name, attrib->name);
593
616
    if(cb_short_desc) {
594
 
        ai->attr.short_desc = malloc(cb_short_desc);
 
617
        ai->attr.short_desc = PMALLOC(cb_short_desc);
595
618
        StringCbCopy(ai->attr.short_desc, cb_short_desc, attrib->short_desc);
596
619
    }
597
620
    if(cb_long_desc) {
598
 
        ai->attr.long_desc = malloc(cb_long_desc);
 
621
        ai->attr.long_desc = PMALLOC(cb_long_desc);
599
622
        StringCbCopy(ai->attr.long_desc, cb_long_desc, attrib->long_desc);
600
623
    }
601
624
 
632
655
    else if(id >= KCDB_ATTR_MIN_PROP_ID && id <= KCDB_ATTR_MAX_PROP_ID)
633
656
        prop = TRUE;
634
657
    else
635
 
        return KHM_ERROR_INVALID_PARM;
 
658
        return KHM_ERROR_INVALID_PARAM;
636
659
 
637
660
    EnterCriticalSection(&cs_attrib);
638
661
    if(prop)
676
699
{
677
700
    kcdb_attrib_i * ai;
678
701
    size_t cb_size = 0;
679
 
    khm_boolean prop;
 
702
    khm_boolean prop = FALSE;
680
703
 
681
704
    if(!cbsize)
682
 
        return KHM_ERROR_INVALID_PARM;
 
705
        return KHM_ERROR_INVALID_PARAM;
683
706
 
684
707
    if(id >= 0 && id <= KCDB_ATTR_MAX_ID)
685
708
        prop = FALSE;
686
709
    else if(id >= KCDB_ATTR_MIN_PROP_ID && id <= KCDB_ATTR_MAX_PROP_ID)
687
710
        prop = TRUE;
 
711
    else 
 
712
        return KHM_ERROR_INVALID_PARAM;
688
713
 
689
714
    if(prop)
690
715
        ai = kcdb_property_tbl[id - KCDB_ATTR_MIN_PROP_ID];
734
759
    int i;
735
760
 
736
761
    if(!id)
737
 
        return KHM_ERROR_INVALID_PARM;
 
762
        return KHM_ERROR_INVALID_PARAM;
738
763
 
739
764
    EnterCriticalSection(&cs_attrib);
740
765
    for(i=0;i < KCDB_ATTR_MAX_PROPS; i++) {
757
782
    int i;
758
783
 
759
784
    if(!id)
760
 
        return KHM_ERROR_INVALID_PARM;
 
785
        return KHM_ERROR_INVALID_PARAM;
761
786
 
762
787
    EnterCriticalSection(&cs_attrib);
763
788
    for(i=0;i<= KCDB_ATTR_MAX_ID; i++) {
785
810
    int i;
786
811
 
787
812
    if(pcount == NULL)
788
 
        return KHM_ERROR_INVALID_PARM;
 
813
        return KHM_ERROR_INVALID_PARAM;
789
814
 
790
815
    eq_flags &= and_flags;
791
816
 
819
844
    int i;
820
845
 
821
846
    if(plist == NULL || pcsize == NULL)
822
 
        return KHM_ERROR_INVALID_PARM;
 
847
        return KHM_ERROR_INVALID_PARAM;
823
848
 
824
849
    eq_flags &= and_flags;
825
850