Exemplo n.º 1
0
static int parse_line(char *line, char *homedir)
{
	int ret;
	char *str;
	enum parse_states s = PARSE_ALIAS;
	struct server_store *elem;
	unsigned char pkey[crypto_box_pub_key_size];

	elem = server_store_alloc();
	elem->next = store;

	str = strtok(line, ";");
	for (; str != NULL;) {
		switch (s) {
		case PARSE_ALIAS:
			strlcpy(elem->alias, str, sizeof(elem->alias));
			s = PARSE_SERVER;
			break;
		case PARSE_SERVER:
			strlcpy(elem->host, str, sizeof(elem->host));
			s = PARSE_PORT;
			break;
		case PARSE_PORT:
			strlcpy(elem->port, str, sizeof(elem->port));
			s = PARSE_CARRIER;
			break;
		case PARSE_CARRIER:
			if (!strncmp("udp", str, strlen("udp")))
				elem->udp = 1;
			else
				elem->udp = 0;
			s = PARSE_PUBKEY;
			break;
		case PARSE_PUBKEY:
			if (!curve25519_pubkey_hexparse_32(pkey, sizeof(pkey),
							   str, strlen(str)))
				return -EINVAL;
			memcpy(elem->publickey, pkey, sizeof(elem->publickey));
			memcpy(elem->auth_token, pkey, sizeof(elem->auth_token));
			ret = curve25519_proto_init(&elem->proto_inf,
					 	    elem->publickey,
						    sizeof(elem->publickey),
						    homedir, 1);
			if (ret)
				return -EIO;
			s = PARSE_DONE;
			break;
		case PARSE_DONE:
			break;
		default:
			return -EIO;
		}

		str = strtok(NULL, ";");
	}

	store = elem;
	return s == PARSE_DONE ? 0 : -EIO;
}
Exemplo n.º 2
0
static int parse_line(char *line, char *homedir)
{
	int ret;
	char *str;
	enum parse_states s = PARSE_USERNAME;
	struct user_store *elem;
	unsigned char pkey[crypto_box_pub_key_size];

	elem = user_store_alloc();
	elem->next = store;

	str = strtok(line, ";");
	for (; str != NULL;) {
		switch (s) {
		case PARSE_USERNAME:
			if (__check_duplicate_username(str, strlen(str) + 1))
				return -EINVAL;
			strlcpy(elem->username, str, sizeof(elem->username));
			s = PARSE_PUBKEY;
			break;
		case PARSE_PUBKEY:
			if (!curve25519_pubkey_hexparse_32(pkey, sizeof(pkey),
							   str, strlen(str)))
				return -EINVAL;
			if (__check_duplicate_pubkey(pkey, sizeof(pkey)))
				return -EINVAL;
			memcpy(elem->publickey, pkey, sizeof(elem->publickey));
			ret = curve25519_proto_init(&elem->proto_inf,
					 	    elem->publickey,
						    sizeof(elem->publickey),
						    homedir, 1);
			if (ret)
				return -EIO;
			s = PARSE_DONE;
			break;
		case PARSE_DONE:
			break;
		default:
			return -EIO;
		}

		str = strtok(NULL, ";");
	}

	store = elem;
	return s == PARSE_DONE ? 0 : -EIO;
}