1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
|
/*
* Licensed Materials - Property of IBM
*
* trousers - An open source TCG Software Stack
*
* (C) Copyright International Business Machines Corp. 2004
*
*/
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <errno.h>
#include <grp.h>
#include <stdlib.h>
#ifdef SOLARIS
#include <libscf.h>
#endif
#include "trousers/tss.h"
#include "trousers_types.h"
#include "tcs_tsp.h"
#include "tcs_utils.h"
#include "tcsps.h"
#include "tcslog.h"
#include "tcsd_wrap.h"
#include "tcsd.h"
#include "tcsd_ops.h"
struct tcsd_config_options options_list[] = {
{"port", opt_port},
{"num_threads", opt_max_threads},
{"system_ps_file", opt_system_ps_file},
{"firmware_log_file", opt_firmware_log},
{"firmware_pcrs", opt_firmware_pcrs},
{"kernel_log_file", opt_kernel_log},
{"kernel_pcrs", opt_kernel_pcrs},
{"platform_cred", opt_platform_cred},
{"conformance_cred", opt_conformance_cred},
{"endorsement_cred", opt_endorsement_cred},
{"remote_ops", opt_remote_ops},
{"enforce_exclusive_transport", opt_exclusive_transport},
{"host_platform_class", opt_host_platform_class},
{"all_platform_classes", opt_all_platform_classes},
{NULL, 0}
};
struct tcg_platform_spec tcg_platform_specs[] = {
{"PC_11", TPM_PS_PC_11, TPM_PS_PC_11_URI},
{"PC_12", TPM_PS_PC_12, TPM_PS_PC_12_URI},
{"PDA_12", TPM_PS_PDA_12, TPM_PS_PDA_12_URI},
{"SERVER_12", TPM_PS_Server_12, TPM_PS_Server_12_URI},
{"MOBILE_12", TPM_PS_Mobile_12, TPM_PS_Mobile_12_URI},
{NULL, 0, 0}
};
void
init_tcsd_config(struct tcsd_config *conf)
{
conf->port = -1;
conf->num_threads = -1;
conf->system_ps_file = NULL;
conf->system_ps_dir = NULL;
conf->firmware_log_file = NULL;
conf->firmware_pcrs = 0;
conf->kernel_log_file = NULL;
conf->kernel_pcrs = 0;
conf->platform_cred = NULL;
conf->conformance_cred = NULL;
conf->endorsement_cred = NULL;
memset(conf->remote_ops, 0, sizeof(conf->remote_ops));
conf->unset = 0xffffffff;
conf->exclusive_transport = 0;
conf->host_platform_class = NULL;
conf->all_platform_classes = NULL;
}
TSS_RESULT
platform_class_list_append(struct tcsd_config *conf, char *specName, TSS_BOOL is_main)
{
int i;
struct platform_class *tmp, *new_class;
LogDebugFn("platform_class_list_append start:");
for (i = 0; tcg_platform_specs[i].name; i++) {
if (!strncasecmp(specName, tcg_platform_specs[i].name,
strlen(tcg_platform_specs[i].name))) {
/* Allocate the new structure */
new_class = malloc(sizeof(struct platform_class));
if (new_class == NULL) {
LogError("malloc of %zd bytes failed",
sizeof(struct platform_class));
return TCSERR(TSS_E_OUTOFMEMORY);
}
new_class->simpleID = tcg_platform_specs[i].specNo;
new_class->classURISize = strlen(tcg_platform_specs[i].specURI) + 1;
new_class->classURI = malloc(new_class->classURISize);
if (new_class->classURI == NULL) {
LogError("malloc of %u bytes failed", new_class->classURISize);
return TCSERR(TSS_E_OUTOFMEMORY);
}
memcpy(new_class->classURI, tcg_platform_specs[i].specURI,
new_class->classURISize);
/* Append to the start of the list */
if (is_main) {
tmp = conf->host_platform_class;
conf->host_platform_class = new_class;
} else {
tmp = conf->all_platform_classes;
conf->all_platform_classes = new_class;
}
new_class->next = tmp;
LogDebugFn("Platform Class Added.");
return TSS_SUCCESS;
}
}
LogError("TCG Specification not supported: \"%s\"", specName);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
void
config_set_defaults(struct tcsd_config *conf)
{
/* give all unset options their default values */
if (conf->unset & TCSD_OPTION_PORT)
conf->port = TCSD_DEFAULT_PORT;
if (conf->unset & TCSD_OPTION_MAX_THREADS)
conf->num_threads = TCSD_DEFAULT_MAX_THREADS;
if (conf->unset & TCSD_OPTION_FIRMWARE_PCRS)
conf->firmware_pcrs = TCSD_DEFAULT_FIRMWARE_PCRS;
if (conf->unset & TCSD_OPTION_KERNEL_PCRS)
conf->kernel_pcrs = TCSD_DEFAULT_KERNEL_PCRS;
/* these are strdup'd so we know we can free them at shutdown time */
if (conf->unset & TCSD_OPTION_SYSTEM_PSFILE) {
conf->system_ps_file = strdup(TCSD_DEFAULT_SYSTEM_PS_FILE);
conf->system_ps_dir = strdup(TCSD_DEFAULT_SYSTEM_PS_DIR);
}
if (conf->unset & TCSD_OPTION_FIRMWARE_LOGFILE)
conf->firmware_log_file = strdup(TCSD_DEFAULT_FIRMWARE_LOG_FILE);
if (conf->unset & TCSD_OPTION_KERNEL_LOGFILE)
conf->kernel_log_file = strdup(TCSD_DEFAULT_KERNEL_LOG_FILE);
if (conf->unset & TCSD_OPTION_HOST_PLATFORM_CLASS)
platform_class_list_append(conf, "PC_12", TRUE);
}
int
get_config_option(char *ptr, char **arg)
{
int i;
for (i = 0; options_list[i].name; i++) {
if (!strncasecmp(ptr, options_list[i].name, strlen(options_list[i].name))) {
/* move ptr past our recognized token */
ptr += strlen(options_list[i].name);
/* try to move ptr to the start of the option's argument */
while (*ptr == '=' || *ptr == ' ' || *ptr == '\t')
ptr++;
*arg = ptr;
return options_list[i].option;
}
}
/* on error we'll print the whole line to the log */
*arg = ptr;
return 0;
}
/* copy a file path from a string into a newly malloc'd string */
int
get_file_path(char *ptr, char **dest)
{
char tmp_buf[1024];
int i = 0;
while (isalpha(*ptr) || isdigit(*ptr) ||
*ptr == '/' || *ptr == '.' || *ptr == '#' || *ptr == '_' || *ptr == '-')
{
tmp_buf[i] = *ptr;
ptr++;
i++;
}
/* move through whitespace after the path */
while (*ptr == ' ' || *ptr == '\t')
ptr++;
/* if we're not at a comment or EOL, there's junk */
if (*ptr != '#' && *ptr != '\n') {
*dest = ptr;
return 1;
}
/* too short a path */
if (i == 0)
return -1;
tmp_buf[i] = '\0';
*dest = strdup(tmp_buf);
if (*dest == NULL) {
LogError("malloc of %zd bytes failed", strlen(tmp_buf));
}
return 0;
}
/* add an op ordinal, checking for duplicates along the way */
void
tcsd_add_op(int *remote_ops, int *op)
{
int i = 0, j;
while (op[i] != 0) {
j = 0;
while (remote_ops[j] != 0) {
if (remote_ops[j] == op[i]) {
break;
}
j++;
}
remote_ops[j] = op[i];
i++;
}
}
int
tcsd_set_remote_op(struct tcsd_config *conf, char *op_name)
{
int i = 0;
while(tcsd_ops[i]) {
if (!strcasecmp(tcsd_ops[i]->name, op_name)) {
/* match found */
tcsd_add_op(conf->remote_ops, tcsd_ops[i]->op);
return 0;
}
i++;
}
/* fail, op not found */
return 1;
}
TSS_RESULT
read_conf_line(char *buf, int line_num, struct tcsd_config *conf)
{
char *ptr = buf, *tmp_ptr = NULL, *arg, *comma;
int option, tmp_int;
TSS_RESULT result;
if (ptr == NULL || *ptr == '\0' || *ptr == '#' || *ptr == '\n')
return TSS_SUCCESS;
/* read through whitespace */
while (*ptr == ' ' || *ptr == '\t')
ptr++;
/* ignore comments */
if (*ptr == '#')
return TSS_SUCCESS;
option = get_config_option(ptr, &arg);
switch (option) {
case opt_port:
tmp_int = atoi(arg);
if (tmp_int < 0 || tmp_int > 65535) {
LogError("Config option \"port\" out of range. %s:%d: \"%d\"",
tcsd_config_file, line_num, tmp_int);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else {
conf->port = tmp_int;
conf->unset &= ~TCSD_OPTION_PORT;
}
break;
case opt_max_threads:
tmp_int = atoi(arg);
if (tmp_int <= 0) {
LogError("Config option \"num_threads\" out of range. %s:%d: \"%d\"",
tcsd_config_file, line_num, tmp_int);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else {
conf->num_threads = tmp_int;
conf->unset &= ~TCSD_OPTION_MAX_THREADS;
}
break;
case opt_firmware_pcrs:
conf->unset &= ~TCSD_OPTION_FIRMWARE_PCRS;
while (1) {
comma = rindex(arg, ',');
if (comma == NULL) {
if (!isdigit(*arg))
break;
comma = arg;
tmp_int = atoi(comma);
if (tmp_int >= 0 && tmp_int < TCSD_MAX_PCRS)
conf->firmware_pcrs |= (1 << tmp_int);
else
LogError("Config option \"firmware_pcrs\" is out of range."
"%s:%d: \"%d\"", tcsd_config_file, line_num,
tmp_int);
break;
}
*comma++ = '\0';
tmp_int = atoi(comma);
if (tmp_int >= 0 && tmp_int < TCSD_MAX_PCRS)
conf->firmware_pcrs |= (1 << tmp_int);
else
LogError("Config option \"firmware_pcrs\" is out of range. "
"%s:%d: \"%d\"", tcsd_config_file, line_num, tmp_int);
}
break;
case opt_kernel_pcrs:
conf->unset &= ~TCSD_OPTION_KERNEL_PCRS;
while (1) {
comma = rindex(arg, ',');
if (comma == NULL) {
if (!isdigit(*arg))
break;
comma = arg;
tmp_int = atoi(comma);
if (tmp_int >= 0 && tmp_int < TCSD_MAX_PCRS)
conf->kernel_pcrs |= (1 << tmp_int);
else
LogError("Config option \"kernel_pcrs\" is out of range. "
"%s:%d: \"%d\"", tcsd_config_file, line_num,
tmp_int);
break;
}
*comma++ = '\0';
tmp_int = atoi(comma);
if (tmp_int >= 0 && tmp_int < TCSD_MAX_PCRS)
conf->kernel_pcrs |= (1 << tmp_int);
else
LogError("Config option \"kernel_pcrs\" is out of range. "
"%s:%d: \"%d\"", tcsd_config_file, line_num, tmp_int);
}
break;
case opt_system_ps_file:
if (*arg != '/') {
LogError("Config option \"system_ps_dir\" must be an absolute path name. "
"%s:%d: \"%s\"", tcsd_config_file, line_num, arg);
} else {
char *dir_ptr;
int rc;
if ((rc = get_file_path(arg, &tmp_ptr)) < 0) {
LogError("Config option \"system_ps_file\" is invalid."
" %s:%d: \"%s\"", tcsd_config_file, line_num, arg);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else if (rc > 0) {
LogError("Config option \"system_ps_file\" is invalid. %s:%d:"
" \"%s\"", tcsd_config_file, line_num, tmp_ptr);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
if (tmp_ptr == NULL)
return TCSERR(TSS_E_OUTOFMEMORY);
if (conf->system_ps_file)
free(conf->system_ps_file);
if (conf->system_ps_dir)
free(conf->system_ps_dir);
/* break out the system ps directory from the file path */
dir_ptr = rindex(tmp_ptr, '/');
*dir_ptr = '\0';
if (strlen(tmp_ptr) == 0)
conf->system_ps_dir = strdup("/");
else
conf->system_ps_dir = strdup(tmp_ptr);
if (conf->system_ps_dir == NULL) {
LogError("malloc failed.");
free(tmp_ptr);
return TCSERR(TSS_E_OUTOFMEMORY);
}
*dir_ptr = '/';
conf->system_ps_file = tmp_ptr;
conf->unset &= ~TCSD_OPTION_SYSTEM_PSFILE;
}
break;
case opt_kernel_log:
if (*arg != '/') {
LogError("Config option \"kernel_log\" must be an absolute path name."
" %s:%d: \"%s\"", tcsd_config_file, line_num, arg);
} else {
int rc;
if ((rc = get_file_path(arg, &tmp_ptr)) < 0) {
LogError("Config option \"kernel_log\" is invalid. %s:%d: \"%s\"",
tcsd_config_file, line_num, arg);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else if (rc > 0) {
LogError("Config option \"kernel_log\" is invalid. %s:%d: \"%s\"",
tcsd_config_file, line_num, tmp_ptr);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
if (tmp_ptr == NULL)
return TCSERR(TSS_E_OUTOFMEMORY);
if (conf->kernel_log_file)
free(conf->kernel_log_file);
conf->kernel_log_file = tmp_ptr;
conf->unset &= ~TCSD_OPTION_KERNEL_LOGFILE;
}
break;
case opt_firmware_log:
if (*arg != '/') {
LogError("Config option \"firmware_log\" must be an absolute path name."
" %s:%d: \"%s\"", tcsd_config_file, line_num, arg);
} else {
int rc;
if ((rc = get_file_path(arg, &tmp_ptr)) < 0) {
LogError("Config option \"firmware_log\" is invalid. %s:%d: \"%s\"",
tcsd_config_file, line_num, arg);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else if (rc > 0) {
LogError("Config option \"firmware_log\" is invalid. %s:%d: \"%s\"",
tcsd_config_file, line_num, tmp_ptr);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
if (tmp_ptr == NULL)
return TCSERR(TSS_E_OUTOFMEMORY);
if (conf->firmware_log_file)
free(conf->firmware_log_file);
conf->firmware_log_file = tmp_ptr;
conf->unset &= ~TCSD_OPTION_FIRMWARE_LOGFILE;
}
break;
case opt_platform_cred:
if (*arg != '/') {
LogError("Config option \"platform_cred\" must be an absolute path name. "
"%s:%d: \"%s\"", tcsd_config_file, line_num, arg);
} else {
int rc;
if ((rc = get_file_path(arg, &tmp_ptr)) < 0) {
LogError("Config option \"platform_cred\" is invalid. %s:%d: "
"\"%s\"", tcsd_config_file, line_num, arg);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else if (rc > 0) {
LogError("Config option \"platform_cred\" is invalid. %s:%d: "
"\"%s\"", tcsd_config_file, line_num, tmp_ptr);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
if (tmp_ptr == NULL)
return TCSERR(TSS_E_OUTOFMEMORY);
if (conf->platform_cred)
free(conf->platform_cred);
conf->platform_cred = tmp_ptr;
conf->unset &= ~TCSD_OPTION_PLATFORM_CRED;
}
break;
case opt_conformance_cred:
if (*arg != '/') {
LogError("Config option \"conformance_cred\" must be an absolute path name."
" %s:%d: \"%s\"", tcsd_config_file, line_num, arg);
} else {
int rc;
if ((rc = get_file_path(arg, &tmp_ptr)) < 0) {
LogError("Config option \"conformance_cred\" is invalid. %s:%d: "
"\"%s\"", tcsd_config_file, line_num, arg);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else if (rc > 0) {
LogError("Config option \"conformance_cred\" is invalid. %s:%d: "
"\"%s\"", tcsd_config_file, line_num, tmp_ptr);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
if (tmp_ptr == NULL)
return TCSERR(TSS_E_OUTOFMEMORY);
if (conf->conformance_cred)
free(conf->conformance_cred);
conf->conformance_cred = tmp_ptr;
conf->unset &= ~TCSD_OPTION_CONFORMANCE_CRED;
}
break;
case opt_endorsement_cred:
if (*arg != '/') {
LogError("Config option \"endorsement_cred\" must be an absolute path name."
" %s:%d: \"%s\"", tcsd_config_file, line_num, arg);
} else {
int rc;
if ((rc = get_file_path(arg, &tmp_ptr)) < 0) {
LogError("Config option \"endorsement_cred\" is invalid. %s:%d: "
"\"%s\"", tcsd_config_file, line_num, arg);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else if (rc > 0) {
LogError("Config option \"endorsement_cred\" is invalid. %s:%d: "
"\"%s\"", tcsd_config_file, line_num, tmp_ptr);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
if (tmp_ptr == NULL)
return TCSERR(TSS_E_OUTOFMEMORY);
if (conf->endorsement_cred)
free(conf->endorsement_cred);
conf->endorsement_cred = tmp_ptr;
conf->unset &= ~TCSD_OPTION_ENDORSEMENT_CRED;
}
break;
case opt_remote_ops:
conf->unset &= ~TCSD_OPTION_REMOTE_OPS;
comma = rindex(arg, '\n');
*comma = '\0';
while (1) {
comma = rindex(arg, ',');
if (comma == NULL) {
comma = arg;
if (comma != NULL) {
if (tcsd_set_remote_op(conf, comma)) {
LogError("Config option \"remote_ops\" is invalid. "
"%s:%d: \"%s\"", tcsd_config_file,
line_num, comma);
}
}
break;
}
*comma++ = '\0';
if (tcsd_set_remote_op(conf, comma)) {
LogError("Config option \"remote_ops\" is invalid. "
"%s:%d: \"%s\"", tcsd_config_file, line_num, comma);
}
}
break;
case opt_exclusive_transport:
tmp_int = atoi(arg);
if (tmp_int < 0 || tmp_int > 1) {
LogError("Config option \"enforce_exclusive_transport\" out of range."
" %s:%d: \"%d\"", tcsd_config_file, line_num, tmp_int);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else {
conf->exclusive_transport = tmp_int;
conf->unset &= ~TCSD_OPTION_EXCLUSIVE_TRANSPORT;
}
break;
case opt_host_platform_class:
/* append the host class on the list */
conf->unset &= ~TCSD_OPTION_HOST_PLATFORM_CLASS;
comma = rindex(arg,'\n');
*comma = '\0';
comma = rindex(arg,',');
/* At least one comma: error - more than one host class defined */
if (comma != NULL) {
LogError("Config option \"host_platform_class\" error: more than one "
"defined. %s:%d: \"%s\"", tcsd_config_file, line_num, comma);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else {
comma = arg;
/* Add the platform class on the list */
if ((result = platform_class_list_append(conf, comma, TRUE))){
LogError("Config option \"host_platform_class\" invalid. "
"%s:%d: \"%s\"", tcsd_config_file, line_num, comma);
return result;
}
}
break;
case opt_all_platform_classes:
/* append each of the comma separated values on the list */
comma = rindex(arg, '\n');
*comma = '\0';
while (1) {
comma = rindex(arg, ',');
if (comma == NULL) {
comma = arg;
if (comma != NULL) {
/* Add the platform class on the list */
if ((result = platform_class_list_append(conf, comma,
FALSE))) {
LogError("Config option \"all_platform_class\" "
"invalid. %s:%d: \"%s\"", tcsd_config_file,
line_num, comma);
return result;
}
}
break;
}
*comma++ = '\0';
/* Add the platform class on the list */
if ((result = platform_class_list_append(conf, comma, FALSE))) {
LogError("Config option \"all_platform_class\" invalid. "
"%s:%d: \"%s\"", tcsd_config_file, line_num, comma);
return result;
}
}
break;
default:
/* bail out on any unknown option */
LogError("Unknown config option %s:%d \"%s\"!", tcsd_config_file, line_num, arg);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
return TSS_SUCCESS;
}
TSS_RESULT
read_conf_file(FILE *f, struct tcsd_config *conf)
{
int line_num = 0;
char buf[1024];
while (fgets(buf, 1024, f)) {
line_num++;
if (read_conf_line(buf, line_num, conf))
return TCSERR(TSS_E_INTERNAL_ERROR);
}
return TSS_SUCCESS;
}
void
free_platform_lists(struct platform_class *list)
{
struct platform_class *tmp;
while (list != NULL){
if (list->classURISize > 0)
free(list->classURI);
tmp = list->next;
free(list);
list = tmp;
}
}
void
conf_file_final(struct tcsd_config *conf)
{
free(conf->system_ps_file);
free(conf->system_ps_dir);
free(conf->kernel_log_file);
free(conf->firmware_log_file);
free(conf->platform_cred);
free(conf->conformance_cred);
free(conf->endorsement_cred);
free_platform_lists(conf->host_platform_class);
free_platform_lists(conf->all_platform_classes);
}
#ifdef SOLARIS
static int
get_smf_prop(const char *var, boolean_t def_val)
{
scf_simple_prop_t *prop;
uint8_t *val;
boolean_t res = def_val;
prop = scf_simple_prop_get(NULL, "svc:/application/security/tcsd:default",
"config", var);
if (prop) {
if ((val = scf_simple_prop_next_boolean(prop)) != NULL)
res = (*val == 0) ? B_FALSE : B_TRUE;
scf_simple_prop_free(prop);
}
if (prop == NULL || val == NULL) {
syslog(LOG_ALERT, "no value for config/%s (%s). "
"Using default \"%s\"", var, scf_strerror(scf_error()),
def_val ? "true" : "false");
}
return (res);
}
#endif
TSS_RESULT
conf_file_init(struct tcsd_config *conf)
{
FILE *f = NULL;
struct stat stat_buf;
#ifndef SOLARIS
struct group *grp;
struct passwd *pw;
mode_t mode = (S_IRUSR|S_IWUSR);
#endif /* SOLARIS */
TSS_RESULT result;
init_tcsd_config(conf);
#ifdef SOLARIS
/*
* Solaris runs as Rajiv Andrade <srajiv@linux.vnet.:sys but with reduced privileges
* so we don't need to create a new user/group and also so
* we can have auditing support. The permissions on
* the tcsd configuration file are not checked on Solaris.
*/
#endif
/* look for a config file, create if it doesn't exist */
if (stat(tcsd_config_file, &stat_buf) == -1) {
if (errno == ENOENT) {
/* no config file? use defaults */
config_set_defaults(conf);
LogInfo("Config file %s not found, using defaults.", tcsd_config_file);
return TSS_SUCCESS;
} else {
LogError("stat(%s): %s", tcsd_config_file, strerror(errno));
return TCSERR(TSS_E_INTERNAL_ERROR);
}
}
#ifndef SOLARIS
/* find the gid that owns the conf file */
errno = 0;
grp = getgrnam(TSS_GROUP_NAME);
if (grp == NULL) {
if (errno == 0) {
LogError("Group \"%s\" not found, please add this group"
" manually.", TSS_GROUP_NAME);
} else {
LogError("getgrnam(%s): %s", TSS_GROUP_NAME, strerror(errno));
}
return TCSERR(TSS_E_INTERNAL_ERROR);
}
errno = 0;
pw = getpwnam(TSS_USER_NAME);
if (pw == NULL) {
if (errno == 0) {
LogError("User \"%s\" not found, please add this user"
" manually.", TSS_USER_NAME);
} else {
LogError("getpwnam(%s): %s", TSS_USER_NAME, strerror(errno));
}
return TCSERR(TSS_E_INTERNAL_ERROR);
}
/* make sure user/group TSS owns the conf file */
if (pw->pw_uid != stat_buf.st_uid || grp->gr_gid != stat_buf.st_gid) {
LogError("TCSD config file (%s) must be user/group %s/%s", tcsd_config_file,
TSS_USER_NAME, TSS_GROUP_NAME);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
/* make sure only the tss user can manipulate the config file */
if (((stat_buf.st_mode & 0777) ^ mode) != 0) {
LogError("TCSD config file (%s) must be mode 0600", tcsd_config_file);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
#endif /* SOLARIS */
if ((f = fopen(tcsd_config_file, "r")) == NULL) {
LogError("fopen(%s): %s", tcsd_config_file, strerror(errno));
return TCSERR(TSS_E_INTERNAL_ERROR);
}
result = read_conf_file(f, conf);
fclose(f);
/* fill out any uninitialized options */
config_set_defaults(conf);
#ifdef SOLARIS
/*
* The SMF value for "local_only" overrides the config file and
* disables all remote operations.
*/
if (get_smf_prop("local_only", B_TRUE)) {
(void) memset(conf->remote_ops, 0, sizeof(conf->remote_ops));
conf->unset |= TCSD_OPTION_REMOTE_OPS;
}
#endif
return result;
}
TSS_RESULT
ps_dirs_init()
{
struct stat stat_buf;
mode_t mode = S_IRWXU; /* 0700 */
/* query the key storage directory to make sure it exists and is of the right mode */
if (stat(tcsd_options.system_ps_dir, &stat_buf) == -1) {
if (errno == ENOENT) {
/* The dir DNE, create it with mode drwxrwxrwt */
if (mkdir(tcsd_options.system_ps_dir, mode) == -1) {
LogError("mkdir(%s) failed: %s. If you'd like to use %s to "
"store your system persistent data, please"
" create it. Otherwise, change the location"
" in your tcsd config file.",
tcsd_options.system_ps_dir, strerror(errno),
tcsd_options.system_ps_dir);
return TCSERR(TSS_E_INTERNAL_ERROR);
}
} else {
LogError("stat failed: %s", strerror(errno));
return TCSERR(TSS_E_INTERNAL_ERROR);
}
}
/* stat should not fail now */
if (stat(tcsd_options.system_ps_dir, &stat_buf) == -1) {
LogError("stat %s failed: %s", tcsd_options.system_ps_dir, strerror(errno));
return TCSERR(TSS_E_INTERNAL_ERROR);
}
/* tcsd_options.system_ps_dir should be a directory with mode equal to mode */
if (!S_ISDIR(stat_buf.st_mode)) {
LogError("PS dir %s is not a directory! Exiting.", tcsd_options.system_ps_dir);
return TCSERR(TSS_E_INTERNAL_ERROR);
} else if (((stat_buf.st_mode & 0777) ^ mode) != 0) {
/* This path is likely to be hit since open &'s mode with ~umask */
LogInfo("resetting mode of %s from %o to: %o", tcsd_options.system_ps_dir,
(unsigned int) stat_buf.st_mode, (unsigned int) mode);
if (chmod(tcsd_options.system_ps_dir, mode) == -1) {
LogError("chmod(%s) failed: %s", tcsd_options.system_ps_dir,
strerror(errno));
return TCSERR(TSS_E_INTERNAL_ERROR);
}
}
return TSS_SUCCESS;
}
|