~linuxhackerman/iwd

2e475b7c0ee070812a182dc26f2ac087c19dcfda — Maximilian Bosch 1 year, 1 month ago aa3dc1b
nixos hack
3 files changed, 35 insertions(+), 0 deletions(-)

M src/dbus.c
M src/dbus.h
M src/network.c
M src/dbus.c => src/dbus.c +6 -0
@@ 114,6 114,12 @@ struct l_dbus_message *dbus_error_not_supported(struct l_dbus_message *msg)
					"Operation not supported");
}

struct l_dbus_message *dbus_error_file_is_a_nix_store_path(struct l_dbus_message *msg, char *ssid)
{
	return l_dbus_message_new_error(msg, IWD_SERVICE ".NotSupportNixOS",
					"Cannot update SSID %s as it's configured in a file that points to a store path! Please update your NixOS config accordingly!", ssid);
}

struct l_dbus_message *dbus_error_no_agent(struct l_dbus_message *msg)
{
	return l_dbus_message_new_error(msg, IWD_SERVICE ".NoAgent",

M src/dbus.h => src/dbus.h +1 -0
@@ 62,6 62,7 @@ struct l_dbus_message *dbus_error_invalid_format(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_already_exists(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_not_found(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_not_supported(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_file_is_a_nix_store_path(struct l_dbus_message *msg, char *ssid);
struct l_dbus_message *dbus_error_no_agent(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_not_connected(struct l_dbus_message *msg);
struct l_dbus_message *dbus_error_not_configured(struct l_dbus_message *msg);

M src/network.c => src/network.c +28 -0
@@ 853,6 853,34 @@ static struct l_dbus_message *network_connect_psk(struct network *network,
		network->ask_passphrase ? "true" : "false");

	if (network->ask_passphrase) {
		FILE *handle;
		handle = fopen("/var/lib/iwd/.declarative-nixos-networks", "r");
		char *line = NULL;
		size_t at = 0;
		if (handle != NULL && network->info != NULL) {
			char *cfgpath_ = network->info->ops->get_file_path(network->info);
			char *cfgpath = calloc(1, PATH_MAX);
			if (realpath(cfgpath_, cfgpath) != NULL) {
				char *tocheck = calloc(1, PATH_MAX);
				while (getline(&line, &at, handle) != -1) {
					*index(line, '\n') = '\0';
					snprintf(tocheck, PATH_MAX - 1, "/var/lib/iwd/%s", line);
					if (strcmp(tocheck, cfgpath) == 0) {
						free(tocheck);
						free(line);
						free(cfgpath);
						fclose(handle);

						return dbus_error_file_is_a_nix_store_path(message, network->ssid);
					}
				}
				free(tocheck);
			}
			free(cfgpath);
			free(line);
			fclose(handle);
		}

		network->ask_passphrase = false;

		network->agent_request =