2
* Copyright (c) 2004 Massachusetts Institute of Technology
2
* Copyright (c) 2005 Massachusetts Institute of Technology
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;
36
void kcdb_attrib_add_ref_func(const void * key, void * va)
37
kcdb_attrib_add_ref_func(const void * key, void * va)
38
39
kcdb_attrib_hold((kcdb_attrib_i *) va);
41
void kcdb_attrib_del_ref_func(const void * key, void * va)
43
kcdb_attrib_del_ref_func(const void * key, void * va)
43
45
kcdb_attrib_release((kcdb_attrib_i *) va);
46
void kcdb_attrib_msg_completion(kmq_message * m)
49
kcdb_attrib_msg_completion(kmq_message * m)
48
51
if(m && m->vparam) {
49
52
kcdb_attrib_release((kcdb_attrib_i *) m->vparam);
53
khm_int32 kcdb_attrib_hold(kcdb_attrib_i * ai)
57
kcdb_attrib_hold(kcdb_attrib_i * ai)
56
return KHM_ERROR_INVALID_PARM;
60
return KHM_ERROR_INVALID_PARAM;
58
62
EnterCriticalSection(&cs_attrib);
61
65
return KHM_ERROR_SUCCESS;
64
khm_int32 kcdb_attrib_release(kcdb_attrib_i * ai)
69
kcdb_attrib_release(kcdb_attrib_i * ai)
67
return KHM_ERROR_INVALID_PARM;
72
return KHM_ERROR_INVALID_PARAM;
69
74
EnterCriticalSection(&cs_attrib);
72
77
return KHM_ERROR_SUCCESS;
75
void kcdb_attrib_post_message(khm_int32 op, kcdb_attrib_i * ai)
81
kcdb_attrib_post_message(khm_int32 op, kcdb_attrib_i * ai)
77
83
kcdb_attrib_hold(ai);
78
84
kmq_post_message(KMSG_KCDB, KMSG_KCDB_ATTRIB, op, (void *) ai);
81
khm_int32 KHMAPI kcdb_attr_sys_cb(khm_handle vcred,
88
kcdb_attr_sys_cb(khm_handle vcred,
122
129
case KCDB_ATTR_TIMELEFT:
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;
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);
143
SystemTimeToFileTime(&st, (LPFILETIME) &ftc);
145
*((__int64 *) kcdb_cred_buf_get(c,KCDB_ATTR_EXPIRE)) - ftc;
147
GetSystemTimeAsFileTime(&ftc);
148
iftc = FtToInt(&ftc);
150
*((FILETIME *) buf) =
151
IntToFt(FtToInt((FILETIME *)
152
kcdb_cred_buf_get(c,KCDB_ATTR_EXPIRE))
154
*pcb_buf = sizeof(FILETIME);
151
160
case KCDB_ATTR_RENEW_TIMELEFT:
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;
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);
172
SystemTimeToFileTime(&st, (LPFILETIME) &ftc);
174
*((__int64 *) kcdb_cred_buf_get(c,KCDB_ATTR_RENEW_EXPIRE)) - ftc;
179
GetSystemTimeAsFileTime(&ftc);
181
i_re = FtToInt(((FILETIME *)
182
kcdb_cred_buf_get(c, KCDB_ATTR_RENEW_EXPIRE)));
183
i_ct = FtToInt(&ftc);
186
*((FILETIME *) buf) =
187
IntToFt(i_re - i_ct);
189
*((FILETIME *) buf) =
192
*pcb_buf = sizeof(FILETIME);
195
void kcdb_attrib_init(void)
214
kcdb_attrib_init(void)
197
216
kcdb_attrib attrib;
198
217
wchar_t sbuf[256];
200
219
InitializeCriticalSection(&cs_attrib);
201
kcdb_attrib_namemap = hash_new_hashtable(
202
KCDB_ATTRIB_HASH_SIZE,
205
kcdb_attrib_add_ref_func,
206
kcdb_attrib_del_ref_func);
220
kcdb_attrib_namemap =
221
hash_new_hashtable(KCDB_ATTRIB_HASH_SIZE,
224
kcdb_attrib_add_ref_func,
225
kcdb_attrib_del_ref_func);
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));
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);
388
407
kcdb_attrib_register(&attrib, NULL);
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);
407
426
kcdb_attrib_register(&attrib, NULL);
468
487
kcdb_attrib_register(&attrib, NULL);
471
void kcdb_attrib_exit(void)
491
kcdb_attrib_exit(void)
473
493
DeleteCriticalSection(&cs_attrib);
475
495
if(kcdb_attrib_tbl)
476
free(kcdb_attrib_tbl);
496
PFREE(kcdb_attrib_tbl);
478
498
if(kcdb_property_tbl)
479
free(kcdb_property_tbl);
499
PFREE(kcdb_property_tbl);
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)
484
505
kcdb_attrib_i * ai;
487
return KHM_ERROR_INVALID_PARM;
508
return KHM_ERROR_INVALID_PARAM;
489
510
EnterCriticalSection(&cs_attrib);
490
511
ai = hash_lookup(kcdb_attrib_namemap, (void *) name);
512
534
KHM_FAILED(kcdb_type_get_info(attrib->type, NULL)) ||
514
return KHM_ERROR_INVALID_PARM;
536
return KHM_ERROR_INVALID_PARAM;
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;
540
562
if ((attrib->flags & KCDB_ATTR_FLAG_ALTVIEW) &&
541
563
KHM_FAILED(kcdb_attrib_get_info(attrib->alt_id,
543
return KHM_ERROR_INVALID_PARM;
565
return KHM_ERROR_INVALID_PARAM;
545
567
prop = !!(attrib->flags & KCDB_ATTR_FLAG_PROPERTY);
547
569
EnterCriticalSection(&cs_attrib);
551
(attrib->id < 0 || attrib->id > KCDB_ATTR_MAX_ID))
572
(attrib->id < 0 || attrib->id > KCDB_ATTR_MAX_ID))
553
574
if(KHM_FAILED(kcdb_attrib_next_free_id(&attr_id))) {
554
575
LeaveCriticalSection(&cs_attrib);
555
576
return KHM_ERROR_NO_RESOURCES;
559
(attrib->id < KCDB_ATTR_MIN_PROP_ID || attrib->id > KCDB_ATTR_MAX_PROP_ID))
579
(attrib->id < KCDB_ATTR_MIN_PROP_ID ||
580
attrib->id > KCDB_ATTR_MAX_PROP_ID)) {
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;
566
588
attr_id = attrib->id;
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));
574
596
if((!prop && kcdb_attrib_tbl[attr_id]) ||
575
(prop && kcdb_property_tbl[attr_id - KCDB_ATTR_MIN_PROP_ID]))
597
(prop && kcdb_property_tbl[attr_id - KCDB_ATTR_MIN_PROP_ID])) {
577
599
LeaveCriticalSection(&cs_attrib);
578
600
return KHM_ERROR_DUPLICATE;
581
ai = malloc(sizeof(kcdb_attrib_i));
604
ai = PMALLOC(sizeof(kcdb_attrib_i));
582
605
ZeroMemory(ai, sizeof(kcdb_attrib_i));
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);
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);
677
700
kcdb_attrib_i * ai;
678
701
size_t cb_size = 0;
702
khm_boolean prop = FALSE;
682
return KHM_ERROR_INVALID_PARM;
705
return KHM_ERROR_INVALID_PARAM;
684
707
if(id >= 0 && id <= KCDB_ATTR_MAX_ID)
686
709
else if(id >= KCDB_ATTR_MIN_PROP_ID && id <= KCDB_ATTR_MAX_PROP_ID)
712
return KHM_ERROR_INVALID_PARAM;
690
715
ai = kcdb_property_tbl[id - KCDB_ATTR_MIN_PROP_ID];