--- loader/net.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ loader/net.h | 1 + 2 files changed, 97 insertions(+), 0 deletions(-) diff --git a/loader/net.c b/loader/net.c index c84ded2..19bb8be 100644 --- a/loader/net.c +++ b/loader/net.c @@ -39,6 +39,7 @@ #include <glib.h> #include <NetworkManager.h> #include <nm-client.h> +#include <nm-device-wifi.h> #include "../isys/isys.h" #include "../isys/ethtool.h" @@ -407,6 +408,22 @@ void setupIfaceStruct(iface_t * iface, struct loaderData_s * loaderData) { iface->portno = strdup(loaderData->portno); } + if (loaderData->wepkey) { + if (isWirelessDevice(loaderData->netDev)) { + iface->wepkey = strdup(loaderData->wepkey); + } else { + iface->wepkey = NULL; + } + } + + if (loaderData->essid) { + if (isWirelessDevice(loaderData->netDev)) { + iface->ssid = strdup(loaderData->essid); + } else { + iface->ssid = NULL; + } + } + if (loaderData->noDns) { iface->flags |= IFACE_FLAGS_NO_WRITE_RESOLV_CONF; } @@ -1441,6 +1458,14 @@ int writeEnabledNetInfo(iface_t *iface) { fprintf(fp, "MACADDR=%s\n", iface->macaddr); } + if (iface->ssid) { + fprintf(fp, "ESSID=%s\n", iface->ssid); + } + + if (iface->wepkey) { + fprintf(fp, "DEFAULTKEY=1"); + } + if (fclose(fp) == EOF) { free(ofile); free(nfile); @@ -1461,6 +1486,48 @@ int writeEnabledNetInfo(iface_t *iface) { free(nfile); } + /* wireless wepkey: keys-DEVICE file */ + if (iface->wepkey) { + if (asprintf(&ofile, "%s/.keys-%s", + NETWORK_SCRIPTS_PATH, iface->device) == -1) { + return 21; + } + + if (asprintf(&nfile, "%s/keys-%s", + NETWORK_SCRIPTS_PATH, iface->device) == -1) { + return 22; + } + + if ((fp = fopen(ofile, "w")) == NULL) { + free(ofile); + return 23; + } + + fprintf(fp, "KEY1=%s\n", iface->wepkey); + + + if (fclose(fp) == EOF) { + free(ofile); + free(nfile); + return 24; + } + + if (rename(ofile, nfile) == -1) { + free(ofile); + free(nfile); + return 25; + } + + if (ofile) { + free(ofile); + } + + if (nfile) { + free(nfile); + } + } + + /* Global settings */ if ((fp = fopen(SYSCONFIG_PATH"/.network", "w")) == NULL) { return 9; @@ -2119,4 +2186,33 @@ int get_connection(iface_t *iface) { return 3; } +int isWirelessDevice(char *device) { + NMClient *client = NULL; + const GPtrArray *devices; + const char *iface; + int i; + + client = nm_client_new(); + if (!client) { + logMessage(ERROR, "%s (%d): could not connect to system bus", + __func__, __LINE__); + return 0; + } + + devices = nm_client_get_devices(client); + for (i = 0; devices && (i < devices->len); i++) { + NMDevice *candidate = g_ptr_array_index(devices, i); + if (NM_IS_DEVICE_WIFI (candidate)) { + iface = nm_device_get_iface(candidate); + if (!strcmp(device, iface)) { + g_object_unref(client); + return 1; + } + } + + } + g_object_unref(client); + return 0; +} + /* vim:set shiftwidth=4 softtabstop=4: */ diff --git a/loader/net.h b/loader/net.h index 8245084..a494630 100644 --- a/loader/net.h +++ b/loader/net.h @@ -73,5 +73,6 @@ int kickstartNetworkUp(struct loaderData_s * loaderData, iface_t * iface); void splitHostname (char *str, char **host, char **port); int get_connection(iface_t * iface); +int isWirelessDevice(char *device); #endif -- 1.6.0.6 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list