static void loadLanguageList(void) { char * file = FL_TESTING(flags) ? "../lang-table" : "/etc/lang-table"; FILE * f; char line[256]; char name[256], key[256], font[256], code[256], keyboard[256], timezone[256]; int lineNum = 0; wcwidth(0); f = fopen(file, "r"); if (!f) { newtWinMessage(_("Error"), _("OK"), "cannot open %s: %m", file); return; } while (fgets(line, sizeof(line), f)) { lineNum++; languages = realloc(languages, sizeof(*languages) * (numLanguages + 1)); if (sscanf(line, "%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\n", name, key, font, code, keyboard, timezone) != 6) { printf("bad line %d in lang-table", lineNum); logMessage(WARNING, "bad line %d in lang-table", lineNum); } else { languages[numLanguages].lang = strdup(name); languages[numLanguages].key = strdup(key); languages[numLanguages].font = strdup(font); languages[numLanguages].lc_all = strdup(code); languages[numLanguages++].keyboard = strdup(keyboard); } } fclose(f); }
int usbInitialize(moduleList modLoaded, moduleDeps modDeps, moduleInfoSet modInfo) { struct device ** devices; char * buf; int i; char * loadUsbStorage = NULL; if (FL_NOUSB(flags)) return 0; logMessage(INFO, "looking for usb controllers"); devices = probeDevices(CLASS_USB, BUS_PCI, 0); if (!devices) { logMessage(DEBUGLVL, "no usb controller found"); return 0; } /* JKFIXME: if we looked for all of them, we could batch this up and it * would be faster */ for (i=0; devices[i]; i++) { if (!devices[i]->driver) continue; logMessage(INFO, "found USB controller %s", devices[i]->driver); if (mlLoadModuleSet(devices[i]->driver, modLoaded, modDeps, modInfo)) { /* dont return, just keep going. */ /* may have USB built into kernel */ /* return 1; */ } } free(devices); if (FL_TESTING(flags)) return 0; if (doPwMount("/proc/bus/usb", "/proc/bus/usb", "usbfs", 0, NULL)) logMessage(ERROR, "failed to mount device usbfs: %s", strerror(errno)); /* sleep so we make sure usb devices get properly enumerated. that way we should block when initializing each usb driver until the device is ready for use */ sleepUntilUsbIsStable(); if (!FL_NOUSBSTORAGE(flags)) { devices = probeDevices(CLASS_HD | CLASS_FLOPPY | CLASS_CDROM, BUS_USB, PROBE_ALL); if (devices) { if (FL_UB(flags)) loadUsbStorage = ":ub"; else loadUsbStorage = ":usb-storage"; free(devices); } } buf = alloca(40); sprintf(buf, "hid:keybdev%s", (loadUsbStorage ? loadUsbStorage : "")); mlLoadModuleSet(buf, modLoaded, modDeps, modInfo); sleep(1); return 0; }
char * mountNfsImage(struct installMethod * method, char * location, struct loaderData_s * loaderData) { char * host = NULL; char * directory = NULL; char * mountOpts = NULL; char * fullPath = NULL; char * url = NULL; enum { NFS_STAGE_NFS, NFS_STAGE_MOUNT, NFS_STAGE_DONE, NFS_STAGE_UPDATES } stage = NFS_STAGE_NFS; int rc; /* JKFIXME: ASSERT -- we have a network device setup when we get here */ while (stage != NFS_STAGE_DONE) { switch (stage) { case NFS_STAGE_NFS: logMessage(INFO, "going to do nfsGetSetup"); if (loaderData->method == METHOD_NFS && loaderData->stage2Data) { host = ((struct nfsInstallData *)loaderData->stage2Data)->host; directory = ((struct nfsInstallData *)loaderData->stage2Data)->directory; if (((struct nfsInstallData *) loaderData->stage2Data)->mountOpts == NULL) { mountOpts = strdup("ro"); } else { if (asprintf(&mountOpts, "ro,%s", ((struct nfsInstallData *) loaderData->stage2Data)->mountOpts) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } } logMessage(INFO, "host is %s, dir is %s, opts are '%s'", host, directory, mountOpts); if (!host || !directory) { logMessage(ERROR, "missing host or directory specification"); if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; loaderData->method = -1; break; } else { host = strdup(host); directory = strdup(directory); } } else { char *substr, *tmp; if (nfsGetSetup(&host, &directory) == LOADER_BACK) return NULL; /* If the user-provided URL points at a repo instead of a * stage2 image, fix that up now. */ substr = strstr(directory, ".img"); if (!substr || (substr && *(substr+4) != '\0')) { if (asprintf(&(loaderData->instRepo), "nfs:%s:%s", host, directory) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } if (asprintf(&tmp, "nfs:%s:%s/images/install.img", host, directory) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } setStage2LocFromCmdline(tmp, loaderData); free(host); free(directory); free(tmp); continue; } loaderData->invalidRepoParam = 1; } stage = NFS_STAGE_MOUNT; break; case NFS_STAGE_MOUNT: { char *buf; if (asprintf(&fullPath, "%s:%.*s", host, (int) (strrchr(directory, '/')-directory), directory) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } logMessage(INFO, "mounting nfs path %s", fullPath); if (FL_TESTING(flags)) { stage = NFS_STAGE_DONE; break; } stage = NFS_STAGE_NFS; if (!doPwMount(fullPath, "/mnt/stage2", "nfs", mountOpts, NULL)) { if (asprintf(&buf, "/mnt/stage2/%s", strrchr(directory, '/')) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } if (!access(buf, R_OK)) { logMessage(INFO, "can access %s", buf); rc = mountStage2(buf); if (rc == 0) { stage = NFS_STAGE_UPDATES; if (asprintf(&url, "nfs:%s:%s", host, directory) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } free(buf); break; } else { logMessage(WARNING, "unable to mount %s", buf); free(buf); break; } } else { logMessage(WARNING, "unable to access %s", buf); free(buf); umount("/mnt/stage2"); } } else { newtWinMessage(_("Error"), _("OK"), _("That directory could not be mounted from " "the server.")); if (loaderData->method >= 0) loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; break; } if (asprintf(&buf, _("That directory does not seem to " "contain a %s installation image."), getProductName()) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } newtWinMessage(_("Error"), _("OK"), buf); free(buf); if (loaderData->method >= 0) loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; break; } case NFS_STAGE_UPDATES: { char *buf; if (asprintf(&buf, "%.*s/RHupdates", (int) (strrchr(fullPath, '/')-fullPath), fullPath) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } logMessage(INFO, "mounting nfs path %s for updates", buf); if (!doPwMount(buf, "/tmp/update-disk", "nfs", mountOpts, NULL)) { logMessage(INFO, "Using RHupdates/ for NFS install"); copyDirectory("/tmp/update-disk", "/tmp/updates", NULL, NULL); umount("/tmp/update-disk"); unlink("/tmp/update-disk"); } else { logMessage(INFO, "No RHupdates/ directory found, skipping"); } stage = NFS_STAGE_DONE; break; } case NFS_STAGE_DONE: break; } } free(host); free(directory); if (fullPath) free(fullPath); return url; }
char *mountUrlImage(struct installMethod *method, char *location, struct loaderData_s *loaderData) { struct iurlinfo ui; char *url = NULL; enum { URL_STAGE_MAIN, URL_STAGE_FETCH, URL_STAGE_DONE } stage = URL_STAGE_MAIN; memset(&ui, 0, sizeof(ui)); while (stage != URL_STAGE_DONE) { switch(stage) { case URL_STAGE_MAIN: { /* If the stage2= parameter was given (or inferred from repo=) * then use that configuration info to fetch the image. This * could also have come from kickstart. Else, we need to show * the UI. */ if (loaderData->method == METHOD_URL && loaderData->stage2Data) { url = ((struct urlInstallData *) loaderData->stage2Data)->url; logMessage(INFO, "URL_STAGE_MAIN: url is %s", url); if (!url) { logMessage(ERROR, "missing URL specification"); loaderData->method = -1; free(loaderData->stage2Data); loaderData->stage2Data = NULL; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; break; } /* explode url into ui struct */ convertURLToUI(url, &ui); /* ks info was adequate, lets skip to fetching image */ stage = URL_STAGE_FETCH; break; } else { char *substr; if (urlMainSetupPanel(&ui)) return NULL; /* If the user-provided URL points at a repo instead of * a stage2 image, fix it up now. */ substr = strstr(ui.prefix, ".img"); if (!substr || (substr && *(substr+4) != '\0')) { loaderData->instRepo = strdup(ui.prefix); if (asprintf(&ui.prefix, "%s/images/install.img", ui.prefix) == -1) { logMessage(CRITICAL, "%s: %d: %m", __func__, __LINE__); abort(); } } loaderData->invalidRepoParam = 1; } stage = URL_STAGE_FETCH; break; } case URL_STAGE_FETCH: { if (FL_TESTING(flags)) { stage = URL_STAGE_DONE; break; } if (loadUrlImages(&ui)) { stage = URL_STAGE_MAIN; if (loaderData->method >= 0) loaderData->method = -1; if (loaderData->inferredStage2) loaderData->invalidRepoParam = 1; } else { stage = URL_STAGE_DONE; } break; } case URL_STAGE_DONE: break; } } url = convertUIToURL(&ui); return url; }
void loadLanguage (char * file) { char filename[200]; gzFile stream; int fd, hash, rc; char * key = getenv("LANGKEY"); if (strings) { free(strings), strings = NULL; numStrings = allocedStrings = 0; } /* english requires no files */ if (!strcmp(key, "en")) return; if (!file) { file = filename; if (FL_TESTING(flags)) sprintf(filename, "loader.tr"); else sprintf(filename, "/etc/loader.tr"); } stream = gunzip_open(file); if (!stream) { newtWinMessage("Error", "OK", "Translation for %s is not available. " "The Installation will proceed in English.", key); return ; } sprintf(filename, "%s.tr", key); rc = installCpioFile(stream, filename, "/tmp/translation", 1); gunzip_close(stream); if (rc || access("/tmp/translation", R_OK)) { newtWinMessage("Error", "OK", "Cannot get translation file %s.\n", filename); return; } fd = open("/tmp/translation", O_RDONLY); if (fd < 0) { newtWinMessage("Error", "OK", "Failed to open /tmp/translation: %m\n"); return; } while (read(fd, &hash, 4) == 4) { if (allocedStrings == numStrings) { allocedStrings += 10; strings = realloc(strings, sizeof(*strings) * allocedStrings); } strings[numStrings].hash = ntohl(hash); rc = read(fd, &strings[numStrings].length, 2); strings[numStrings].length = ntohs(strings[numStrings].length); strings[numStrings].str = malloc(strings[numStrings].length + 1); rc = read(fd, strings[numStrings].str, strings[numStrings].length); strings[numStrings].str[strings[numStrings].length] = '\0'; numStrings++; } close(fd); unlink("/tmp/translation"); qsort(strings, numStrings, sizeof(*strings), aStringCmp); }
char * mountNfsImage(struct installMethod * method, char * location, struct loaderData_s * loaderData, moduleInfoSet modInfo, moduleList modLoaded, moduleDeps * modDepsPtr) { char * host = NULL; char * directory = NULL; char * mountOpts = NULL; char * fullPath = NULL; char * path; char * url = NULL; enum { NFS_STAGE_NFS, NFS_STAGE_MOUNT, NFS_STAGE_DONE } stage = NFS_STAGE_NFS; int rc; int dir = 1; /* JKFIXME: ASSERT -- we have a network device setup when we get here */ while (stage != NFS_STAGE_DONE) { switch (stage) { case NFS_STAGE_NFS: logMessage(INFO, "going to do nfsGetSetup"); if (loaderData->method == METHOD_NFS && loaderData->methodData) { host = ((struct nfsInstallData *)loaderData->methodData)->host; directory = ((struct nfsInstallData *)loaderData->methodData)->directory; mountOpts = ((struct nfsInstallData *)loaderData->methodData)->mountOpts; logMessage(INFO, "host is %s, dir is %s, opts are '%s'", host, directory, mountOpts); if (!host || !directory) { logMessage(ERROR, "missing host or directory specification"); loaderData->method = -1; break; } else { host = strdup(host); directory = strdup(directory); if (mountOpts) { mountOpts = strdup(mountOpts); } } } else if (nfsGetSetup(&host, &directory, &mountOpts) == LOADER_BACK) { return NULL; } stage = NFS_STAGE_MOUNT; dir = 1; break; case NFS_STAGE_MOUNT: { int foundinvalid = 0; char * buf; struct in_addr ip; if (loaderData->noDns && !(inet_pton(AF_INET, host, &ip))) { newtWinMessage(_("Error"), _("OK"), _("Hostname specified with no DNS configured")); if (loaderData->method >= 0) { loaderData->method = -1; } break; } fullPath = alloca(strlen(host) + strlen(directory) + 2); sprintf(fullPath, "%s:%s", host, directory); logMessage(INFO, "mounting nfs path %s, options '%s'", fullPath, mountOpts); if (FL_TESTING(flags)) { stage = NFS_STAGE_DONE; dir = 1; break; } stage = NFS_STAGE_NFS; if (!doPwMount(fullPath, "/mnt/source", "nfs", IMOUNT_RDONLY, mountOpts)) { if (!access("/mnt/source/images/stage2.img", R_OK)) { logMessage(INFO, "can access /mnt/source/images/stage2.img"); rc = mountStage2("/mnt/source/images/stage2.img"); logMessage(DEBUGLVL, "after mountStage2, rc is %d", rc); if (rc) { if (rc == -1) { foundinvalid = 1; logMessage(WARNING, "not the right one"); } } else { stage = NFS_STAGE_DONE; url = "nfs://mnt/source/."; break; } } else { logMessage(WARNING, "unable to access /mnt/source/images/stage2.img"); } if ((path = validIsoImages("/mnt/source", &foundinvalid))) { foundinvalid = 0; logMessage(INFO, "Path to valid iso is %s", path); copyUpdatesImg("/mnt/source/updates.img"); if (mountLoopback(path, "/mnt/source2", "loop1")) logMessage(WARNING, "failed to mount iso %s loopback", path); else { rc = mountStage2("/mnt/source2/images/stage2.img"); if (rc) { umountLoopback("/mnt/source2", "loop1"); if (rc == -1) foundinvalid = 1; } else { /* JKFIXME: hack because /mnt/source is hard-coded * in mountStage2() */ copyUpdatesImg("/mnt/source2/images/updates.img"); copyProductImg("/mnt/source2/images/product.img"); queryIsoMediaCheck(path); stage = NFS_STAGE_DONE; url = "nfsiso:/mnt/source"; break; } } } /* if we fell through to here we did not find a valid NFS */ /* source for installation. */ umount("/mnt/source"); if (foundinvalid) buf = sdupprintf(_("The %s installation tree in that " "directory does not seem to match " "your boot media."), getProductName()); else buf = sdupprintf(_("That directory does not seem to " "contain a %s installation tree."), getProductName()); newtWinMessage(_("Error"), _("OK"), buf); if (loaderData->method >= 0) { loaderData->method = -1; } break; } else { newtWinMessage(_("Error"), _("OK"), _("That directory could not be mounted from " "the server.")); if (loaderData->method >= 0) { loaderData->method = -1; } break; } } case NFS_STAGE_DONE: break; } } free(host); free(directory); free(mountOpts); return url; }
char * mountUrlImage(struct installMethod * method, char * location, struct loaderData_s * loaderData, moduleInfoSet modInfo, moduleList modLoaded, moduleDeps * modDeps) { int rc; char * url, *p; struct iurlinfo ui; char needsSecondary = ' '; int dir = 1; char * login; char * finalPrefix; char * cdurl; enum { URL_STAGE_MAIN, URL_STAGE_SECOND, URL_STAGE_FETCH, URL_STAGE_DONE } stage = URL_STAGE_MAIN; enum urlprotocol_t proto = !strcmp(method->name, "FTP") ? URL_METHOD_FTP : URL_METHOD_HTTP; /* JKFIXME: we used to do another ram check here... keep it? */ memset(&ui, 0, sizeof(ui)); while (stage != URL_STAGE_DONE) { switch(stage) { case URL_STAGE_MAIN: if ((loaderData->method == METHOD_FTP || loaderData->method == METHOD_HTTP) && loaderData->methodData) { url = ((struct urlInstallData *)loaderData->methodData)->url; logMessage(INFO, "URL_STAGE_MAIN - url is %s", url); if (!url) { logMessage(ERROR, "missing url specification"); loaderData->method = -1; break; } /* explode url into ui struct */ convertURLToUI(url, &ui); /* ks info was adequate, lets skip to fetching image */ stage = URL_STAGE_FETCH; dir = 1; break; } else if (urlMainSetupPanel(&ui, proto, &needsSecondary)) { return NULL; } /* got required information from user, proceed */ stage = (needsSecondary != ' ') ? URL_STAGE_SECOND : URL_STAGE_FETCH; dir = 1; break; case URL_STAGE_SECOND: rc = urlSecondarySetupPanel(&ui, proto); if (rc) { stage = URL_STAGE_MAIN; dir = -1; } else { stage = URL_STAGE_FETCH; dir = 1; } break; case URL_STAGE_FETCH: if (FL_TESTING(flags)) { stage = URL_STAGE_DONE; dir = 1; break; } #ifdef ROCKS /* * before we start the web server, make sure /tmp/rocks.conf * exists */ if (access("/tmp/rocks.conf", F_OK) != 0) { writeAvalancheInfo(NULL, NULL); } start_httpd(); #endif /* ROCKS */ /* ok messy - see if we have a stage2 on local CD */ /* before trying to pull one over network */ cdurl = findAnacondaCD(location, modInfo, modLoaded, *modDeps, 0); if (cdurl) { logMessage(INFO, "Detected stage 2 image on CD"); winStatus(50, 3, _("Media Detected"), _("Local installation media detected..."), 0); sleep(3); newtPopWindow(); stage = URL_STAGE_DONE; dir = 1; } else { /* need to find stage 2 on remote site */ if (loadUrlImages(&ui)) { stage = URL_STAGE_MAIN; dir = -1; if (loaderData->method >= 0) { loaderData->method = -1; } } else { stage = URL_STAGE_DONE; dir = 1; } } break; case URL_STAGE_DONE: break; } } login = ""; login = getLoginName(login, ui); if (!strcmp(ui.prefix, "/")) finalPrefix = "/."; else finalPrefix = ui.prefix; url = malloc(strlen(finalPrefix) + 25 + strlen(ui.address) + strlen(login)); /* sanitize url so we dont have problems like bug #101265 */ /* basically avoid duplicate /'s */ if (ui.protocol == URL_METHOD_HTTP) { for (p=finalPrefix; *p == '/'; p++); finalPrefix = p; } sprintf(url, "%s://%s%s/%s", ui.protocol == URL_METHOD_FTP ? "ftp" : "http", login, ui.address, finalPrefix); return url; }