Ejemplo n.º 1
0
static int ldap_cb(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
{
	scconf_entry ldap_entry[] =
	{
		{"ldaphost", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
		{"ldapport", SCCONF_INTEGER, SCCONF_VERBOSE, NULL, NULL},
		{"scope", SCCONF_INTEGER, SCCONF_VERBOSE, NULL, NULL},
		{"binddn", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
		{"passwd", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
		{"base", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
		{"attributes", SCCONF_LIST, SCCONF_VERBOSE, NULL, NULL},
		{"filter", SCCONF_STRING, SCCONF_VERBOSE, NULL, NULL},
		{NULL, 0, 0, NULL, NULL}
	};
	char *cardprefix = (char *) entry->arg;
	char *str = scconf_list_strdup(block->name, " ");

	if (!str)
		return 1;
	printf("LDAP entry[%s%s%s]\n", cardprefix ? cardprefix : "", cardprefix ? " " : "", str);
	free(str);
	if (scconf_parse_entries(config, block, ldap_entry) != 0) {
		printf("scconf_parse_entries failed\n");
		return 1;
	}
	return 0;		/* 0 for ok, 1 for error */
}
Ejemplo n.º 2
0
static int print_card_remove_action(void)
{
    const scconf_block *pkcs11_eventmgr;
    scconf_block **event_blocks = NULL;
    scconf_context *ctx = NULL;
    const scconf_list *actionList = NULL;
    int result = 1;

    /*
     * read the pkcs11_eventmgr.conf to get our action
     */
    ctx = scconf_new(EVENTMGR_CONF);
    if (ctx == NULL) {
        goto bail;
    }
    if (scconf_parse(ctx) <= 0) {
        goto bail;
    }
    pkcs11_eventmgr = scconf_find_block(ctx, NULL, "pkcs11_eventmgr");
    if (!pkcs11_eventmgr) {
        goto bail;
    }
    event_blocks = scconf_find_blocks(ctx, pkcs11_eventmgr, "event",
                                      "card_remove");
    if (!event_blocks || !event_blocks[0]) {
        goto bail;
    }
    actionList = scconf_find_list(event_blocks[0],"action");
    if (actionList) {
        char *lst = scconf_list_strdup(actionList, "\n");
        if (lst != NULL) {
            printf("%s\n", lst);
            free(lst);
        }
    }
    result = 0;

bail:
    if (event_blocks) {
        free(event_blocks);
    }
    if (ctx) {
        scconf_free(ctx);
    }

    return result;
}
Ejemplo n.º 3
0
static int card_cb(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
{
	char *str = scconf_list_strdup(block->name, " ");
	scconf_entry card_entry[] =
	{
		{"ldap", SCCONF_CALLBACK, SCCONF_VERBOSE | SCCONF_ALL_BLOCKS, (void *) ldap_cb, str},
		{NULL, 0, 0, NULL, NULL}
	};

	if (!str)
		return 1;
	printf("CARD entry[%s]\n", str);
	if (scconf_parse_entries(config, block, card_entry) != 0) {
		printf("scconf_parse_entries failed\n");
		free(str);
		return 1;
	}
	free(str);
	return 0;		/* 0 for ok, 1 for error */
}
Ejemplo n.º 4
0
static int write_type(scconf_context * config, scconf_block * block, scconf_entry * entry, int depth)
{
	void *parm = entry->parm;
	void *arg = entry->arg;
	int (*callback_func) (scconf_context * config, scconf_block * block, scconf_entry * entry, int depth) =
	(int (*)(scconf_context *, scconf_block *, scconf_entry *, int)) parm;
	int r = 0;

	if (config->debug) {
		fprintf(stderr, "encoding '%s'\n", entry->name);
	}
	switch (entry->type) {
	case SCCONF_CALLBACK:
		if (parm) {
			r = callback_func(config, block, entry, depth);
		}
		break;
	case SCCONF_BLOCK:
		if (parm) {
			scconf_block *subblock;
			const scconf_list *name = (const scconf_list *) arg;

			subblock = scconf_block_add(config, block, entry->name, name);
			r = write_entries(config, subblock, (scconf_entry *) parm, depth + 1);
		}
		break;
	case SCCONF_LIST:
		if (parm) {
			const scconf_list *val = (const scconf_list *) parm;

			scconf_item_add(config, block, NULL, SCCONF_ITEM_TYPE_VALUE, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				char *buf = scconf_list_strdup(val, ", ");
				printf("%s = %s\n", entry->name, buf);
				free(buf);
			}
		}
		break;
	case SCCONF_BOOLEAN:
		if (parm) {
			const int val = * (int* ) parm;

			scconf_put_bool(block, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %s\n", entry->name, val == 0 ? "false" : "true");
			}
		}
		break;
	case SCCONF_INTEGER:
		if (parm) {
			const int val = * (int*) parm;

			scconf_put_int(block, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %i\n", entry->name, val);
			}
		}
		break;
	case SCCONF_STRING:
		if (parm) {
			const char *val = (const char *) parm;

			scconf_put_str(block, entry->name, val);
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %s\n", entry->name, val);
			}
		}
		break;
	default:
		fprintf(stderr, "invalid configuration type: %d\n", entry->type);
	}
	if (r) {
		fprintf(stderr, "encoding of configuration entry '%s' failed.\n", entry->name);
		return r;
	}
	entry->flags |= SCCONF_PRESENT;
	return 0;
}
Ejemplo n.º 5
0
static int parse_type(const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth)
{
	void *parm = entry->parm;
	size_t *len = (size_t *) entry->arg;
	int (*callback_func) (const scconf_context * config, const scconf_block * block, scconf_entry * entry, int depth) =
	(int (*)(const scconf_context *, const scconf_block *, scconf_entry *, int)) parm;
	int r = 0;

	if (config->debug) {
		fprintf(stderr, "decoding '%s'\n", entry->name);
	}
	switch (entry->type) {
	case SCCONF_CALLBACK:
		if (parm) {
			r = callback_func(config, block, entry, depth);
		}
		break;
	case SCCONF_BLOCK:
		if (parm) {
			r = parse_entries(config, block, (scconf_entry *) parm, depth + 1);
		}
		break;
	case SCCONF_LIST:
		{
			const scconf_list *val = scconf_find_list(block, entry->name);

			if (!val) {
				r = 1;
				break;
			}
			if (parm) {
				if (entry->flags & SCCONF_ALLOC) {
					scconf_list *dest = NULL;

					for (; val != NULL; val = val->next) {
						if (!scconf_list_add(&dest, val->data)) {
							r = 1;
							break;
						}
					}
					*((scconf_list **) parm) = dest;
				} else {
					*((const scconf_list **) parm) = val;
				}
			}
			if (entry->flags & SCCONF_VERBOSE) {
				char *buf = scconf_list_strdup(val, ", ");
				printf("%s = %s\n", entry->name, buf);
				free(buf);
			}
		}
		break;
	case SCCONF_BOOLEAN:
		{
			int val = scconf_get_bool(block, entry->name, 0);

			if (parm) {
				*((int *) parm) = val;
			}
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %s\n", entry->name, val == 0 ? "false" : "true");
			}
		}
		break;
	case SCCONF_INTEGER:
		{
			int val = scconf_get_int(block, entry->name, 0);

			if (parm) {
				*((int *) parm) = val;
			}
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %i\n", entry->name, val);
			}
		}
		break;
	case SCCONF_STRING:
		{
			const char *val = scconf_get_str(block, entry->name, NULL);
			int vallen = val ? strlen(val) : 0;

			if (!vallen) {
				r = 1;
				break;
			}
			if (parm) {
				if (entry->flags & SCCONF_ALLOC) {
					char **buf = (char **) parm;
					*buf = malloc(vallen + 1);
					if (*buf == NULL) {
						r = 1;
						break;
					}
					memset(*buf, 0, vallen + 1);
					if (len) {
						*len = vallen;
					}
					parm = *buf;
				}
				memcpy((char *) parm, val, vallen);
			}
			if (entry->flags & SCCONF_VERBOSE) {
				printf("%s = %s\n", entry->name, val);
			}
		}
		break;
	default:
		fprintf(stderr, "invalid configuration type: %d\n", entry->type);
	}
	if (r) {
		fprintf(stderr, "decoding of configuration entry '%s' failed.\n", entry->name);
		return r;
	}
	entry->flags |= SCCONF_PRESENT;
	return 0;
}