Ejemplo n.º 1
0
/*
 * Clear all the keys on the given keyring
 */
static int keyring_clear(const char *keyring)
{
	key_serial_t key;

	key = find_key_by_type_and_desc("keyring", keyring, 0);
	if (key == -1) {
		xlog_err("'%s' keyring was not found.", keyring);
		return EXIT_FAILURE;
	}

	if (keyctl_clear(key) < 0) {
		xlog_err("keyctl_clear(0x%x) failed: %m",
				(unsigned int)key);
		return EXIT_FAILURE;
	}
	
	if (verbose)
		xlog_warn("'%s' cleared", keyring);

	return EXIT_SUCCESS;
}
Ejemplo n.º 2
0
/*
 * Clear all the keys on the given keyring
 */
static int keyring_clear(char *keyring)
{
	FILE *fp;
	char buf[BUFSIZ];
	key_serial_t key;

	if (keyring == NULL)
		keyring = DEFAULT_KEYRING;

	if ((fp = fopen(PROCKEYS, "r")) == NULL) {
		xlog_err("fopen(%s) failed: %m", PROCKEYS);
		return 1;
	}

	while(fgets(buf, BUFSIZ, fp) != NULL) {
		if (strstr(buf, "keyring") == NULL)
			continue;
		if (strstr(buf, keyring) == NULL)
			continue;
		if (verbose) {
			*(strchr(buf, '\n')) = '\0';
			xlog_warn("clearing '%s'", buf);
		}
		/*
		 * The key is the first arugment in the string
		 */
		*(strchr(buf, ' ')) = '\0';
		sscanf(buf, "%x", &key);
		if (keyctl_clear(key) < 0) {
			xlog_err("keyctl_clear(0x%x) failed: %m", key);
			fclose(fp);
			return 1;
		}
		fclose(fp);
		return 0;
	}
	xlog_err("'%s' keyring was not found.", keyring);
	fclose(fp);
	return 1;
}