Allow user to specify input/output filenames
git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@384 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
8cc8ea1e6e
commit
2142557bb8
|
@ -24,19 +24,21 @@
|
||||||
#endif
|
#endif
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "scconf.h"
|
#include "scconf.h"
|
||||||
|
|
||||||
void print_ldap_block(scconf_context * conf, scconf_block * block, char *cardprefix)
|
void print_ldap_block(scconf_context * conf, scconf_block * block)
|
||||||
{
|
{
|
||||||
scconf_block **blocks = NULL;
|
scconf_block **blocks = NULL;
|
||||||
int i;
|
unsigned int i;
|
||||||
|
|
||||||
blocks = scconf_find_blocks(conf, block, "ldap");
|
blocks = scconf_find_blocks(conf, block, "ldap");
|
||||||
for (i = 0; blocks[i]; i++) {
|
for (i = 0; blocks[i]; i++) {
|
||||||
scconf_block *block = blocks[i];
|
scconf_block *block = blocks[i];
|
||||||
scconf_list *list, *tmp;
|
scconf_list *list, *tmp;
|
||||||
|
|
||||||
printf("LDAP entry[%s%s]\n", !cardprefix ? "" : cardprefix, !block->name ? "Default" : block->name->data);
|
printf("LDAP entry[%s]\n", !block->name ? "Default" : block->name->data);
|
||||||
printf("ldaphost: %s\n", scconf_find_value_first(block, "ldaphost"));
|
printf("ldaphost: %s\n", scconf_find_value_first(block, "ldaphost"));
|
||||||
printf("ldapport: %s\n", scconf_find_value_first(block, "ldapport"));
|
printf("ldapport: %s\n", scconf_find_value_first(block, "ldapport"));
|
||||||
printf("scope: %s\n", scconf_find_value_first(block, "scope"));
|
printf("scope: %s\n", scconf_find_value_first(block, "scope"));
|
||||||
|
@ -46,49 +48,46 @@ void print_ldap_block(scconf_context * conf, scconf_block * block, char *cardpre
|
||||||
printf("attributes: [");
|
printf("attributes: [");
|
||||||
list = scconf_find_value(block, "attributes");
|
list = scconf_find_value(block, "attributes");
|
||||||
for (tmp = list; tmp; tmp = tmp->next) {
|
for (tmp = list; tmp; tmp = tmp->next) {
|
||||||
printf("%s ", tmp->data);
|
printf(" %s", tmp->data);
|
||||||
}
|
}
|
||||||
printf("]\n");
|
printf(" ]\n");
|
||||||
printf("filter: %s\n", scconf_find_value_first(block, "filter"));
|
printf("filter: %s\n", scconf_find_value_first(block, "filter"));
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
free(blocks);
|
free(blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
scconf_context *conf = NULL;
|
scconf_context *conf = NULL;
|
||||||
scconf_block **blocks = NULL;
|
char *in = NULL, *out = NULL;
|
||||||
int i;
|
int r;
|
||||||
|
|
||||||
conf = scconf_init("test.conf");
|
if (argc != 3) {
|
||||||
|
printf("Usage: test-conf <in.conf> <out.conf>\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
in = argv[argc - 2];
|
||||||
|
out = argv[argc - 1];
|
||||||
|
|
||||||
|
conf = scconf_init(in);
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
printf("scconf_init failed\n");
|
printf("scconf_init failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (scconf_parse(conf) < 1) {
|
if (scconf_parse(conf) < 1) {
|
||||||
|
printf("scconf_parse failed\n");
|
||||||
scconf_deinit(conf);
|
scconf_deinit(conf);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* Parse normal LDAP blocks first */
|
/* See if the file contains any ldap configuration blocks */
|
||||||
print_ldap_block(conf, NULL, NULL);
|
print_ldap_block(conf, NULL);
|
||||||
|
|
||||||
/* Parse card specific LDAP blocks */
|
if ((r = scconf_write(conf, out)) != 0) {
|
||||||
blocks = scconf_find_blocks(conf, NULL, "card");
|
printf("scconf_write: %s\n", strerror(r));
|
||||||
for (i = 0; blocks[i]; i++) {
|
} else {
|
||||||
scconf_block *block = blocks[i];
|
printf("Successfully rewrote file \"%s\" as \"%s\"\n", in, out);
|
||||||
char *name = NULL;
|
|
||||||
|
|
||||||
name = scconf_list_strdup(block->name, " ");
|
|
||||||
print_ldap_block(conf, block, name);
|
|
||||||
if (name) {
|
|
||||||
free(name);
|
|
||||||
}
|
|
||||||
name = NULL;
|
|
||||||
}
|
}
|
||||||
free(blocks);
|
|
||||||
|
|
||||||
scconf_write(conf, "test.conf.write");
|
|
||||||
scconf_deinit(conf);
|
scconf_deinit(conf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue