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
|
newhandler->_next = varhandlers;
varhandlers = newhandler;
return(0);
}
int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra) {
int retval = 0, chkretval = 0;
/* XXX Handle config files. need to handle this in a loop of config files... */
switch (type) {
case LC_CONF_SECTION:
chkretval = lc_process_conf_section(appname, extra);
break;
case LC_CONF_APACHE:
chkretval = lc_process_conf_apache(appname, extra);
break;
case LC_CONF_COLON:
chkretval = lc_process_conf_colon(appname, extra);
break;
case LC_CONF_EQUAL:
chkretval = lc_process_conf_equal(appname, extra);
break;
case LC_CONF_SPACE:
chkretval = lc_process_conf_space(appname, extra);
break;
case LC_CONF_XML:
chkretval = lc_process_conf_xml(appname, extra);
break;
default:
chkretval = -1;
lc_errno = LC_ERR_INVDATA;
break;
}
if (chkretval < 0) {
retval = -1;
}
/* Handle environment variables.*/
chkretval = lc_process_environment(appname);
if (chkretval < 0) {
|
|
|
<
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
|
newhandler->_next = varhandlers;
varhandlers = newhandler;
return(0);
}
static int lc_process_file(const char *appname, const char *pathname, lc_conf_type_t type) {
int chkretval = 0;
switch (type) {
case LC_CONF_SECTION:
chkretval = lc_process_conf_section(appname, pathname);
break;
case LC_CONF_APACHE:
chkretval = lc_process_conf_apache(appname, pathname);
break;
case LC_CONF_COLON:
chkretval = lc_process_conf_colon(appname, pathname);
break;
case LC_CONF_EQUAL:
chkretval = lc_process_conf_equal(appname, pathname);
break;
case LC_CONF_SPACE:
chkretval = lc_process_conf_space(appname, pathname);
break;
case LC_CONF_XML:
chkretval = lc_process_conf_xml(appname, pathname);
break;
default:
chkretval = -1;
lc_errno = LC_ERR_INVDATA;
break;
}
return(chkretval);
}
static int lc_process_files(const char *appname, lc_conf_type_t type, const char *extraconfig) {
struct passwd *pwinfo = NULL;
char configfiles[3][13][512] = {{{0}}};
char *configfile = NULL;
char *homedir = NULL;
int configsetidx = 0, configidx = 0;
int chkretval = 0, retval = 0;
snprintf(configfiles[0][0], sizeof(**configfiles) - 1, "/etc/%s.cfg", appname);
snprintf(configfiles[0][1], sizeof(**configfiles) - 1, "/etc/%s.conf", appname);
snprintf(configfiles[0][2], sizeof(**configfiles) - 1, "/etc/%s/%s.cfg", appname, appname);
snprintf(configfiles[0][3], sizeof(**configfiles) - 1, "/etc/%s/%s.conf", appname, appname);
snprintf(configfiles[0][4], sizeof(**configfiles) - 1, "/usr/etc/%s.cfg", appname);
snprintf(configfiles[0][5], sizeof(**configfiles) - 1, "/usr/etc/%s.conf", appname);
snprintf(configfiles[0][6], sizeof(**configfiles) - 1, "/usr/etc/%s/%s.cfg", appname, appname);
snprintf(configfiles[0][7], sizeof(**configfiles) - 1, "/usr/etc/%s/%s.conf", appname, appname);
snprintf(configfiles[0][8], sizeof(**configfiles) - 1, "/usr/local/etc/%s.cfg", appname);
snprintf(configfiles[0][9], sizeof(**configfiles) - 1, "/usr/local/etc/%s.conf", appname);
snprintf(configfiles[0][10], sizeof(**configfiles) - 1, "/usr/local/etc/%s/%s.cfg", appname, appname);
snprintf(configfiles[0][11], sizeof(**configfiles) - 1, "/usr/local/etc/%s/%s.conf", appname, appname);
snprintf(configfiles[1][0], sizeof(**configfiles) - 1, "%s", extraconfig);
if (getuid() != 0) {
homedir = getenv("HOME");
if (homedir == NULL) {
pwinfo = getpwuid(getuid());
if (pwinfo != NULL) {
homedir = pwinfo->pw_dir;
}
}
if (homedir != NULL) {
if (strcmp(homedir, "/") != 0 && access(homedir, R_OK|W_OK|X_OK) == 0) {
snprintf(configfiles[2][0], sizeof(**configfiles) - 1, "%s/.%src", homedir, appname);
snprintf(configfiles[2][1], sizeof(**configfiles) - 1, "%s/.%s.cfg", homedir, appname);
snprintf(configfiles[2][2], sizeof(**configfiles) - 1, "%s/.%s.conf", homedir, appname);
snprintf(configfiles[2][3], sizeof(**configfiles) - 1, "%s/.%s/%s.cfg", homedir, appname, appname);
snprintf(configfiles[2][4], sizeof(**configfiles) - 1, "%s/.%s/%s.conf", homedir, appname, appname);
snprintf(configfiles[2][5], sizeof(**configfiles) - 1, "%s/.%s/config", homedir, appname);
}
}
}
for (configsetidx = 0; configsetidx < 3; configsetidx++) {
for (configidx = 0; configidx < 13; configidx++) {
configfile = configfiles[configsetidx][configidx];
if (configfile[0] == '\0') {
break;
}
if (access(configfile, R_OK) == 0) {
chkretval = lc_process_file(appname, configfile, type);
if (chkretval < 0) {
retval = -1;
}
break;
}
}
}
return(retval);
}
int lc_process(int argc, char **argv, const char *appname, lc_conf_type_t type, const char *extra) {
int retval = 0, chkretval = 0;
/* Handle config files. */
chkretval = lc_process_files(appname, type, extra);
if (chkretval < 0) {
retval = -1;
}
/* Handle environment variables.*/
chkretval = lc_process_environment(appname);
if (chkretval < 0) {
|