void mediaShutdownNetwork(Device *dev) { char *cp; if (!RunningAsInit || !networkInitialized) return; msgDebug("Shutdown called for network device %s\n", dev->name); int i; char ifconfig[255]; snprintf(ifconfig, 255, "%s%s", VAR_IFCONFIG, dev->name); cp = variable_get(ifconfig); if (!cp) return; msgDebug("ifconfig %s down\n", dev->name); i = vsystem("ifconfig %s down", dev->name); if (i) msgConfirm("Warning: Unable to down the %s interface properly", dev->name); cp = variable_get(VAR_GATEWAY); if (cp) { msgDebug("Deleting default route.\n"); vsystem("route -n delete default"); } }
/* Using permission defaults, apply them as necessary */ void apply_perms(const char *dir, const char *arg) { const char *cd_to; if (!dir || *arg == '/') /* absolute path? */ cd_to = "/"; else cd_to = dir; if (Mode) if (vsystem("cd %s && /bin/chmod -R %s %s", cd_to, Mode, arg)) warnx("couldn't change modes of '%s' to '%s'", arg, Mode); if (Owner && Group) { if (vsystem("cd %s && /usr/sbin/chown -R %s:%s %s", cd_to, Owner, Group, arg)) warnx("couldn't change owner/group of '%s' to '%s:%s'", arg, Owner, Group); return; } if (Owner) { if (vsystem("cd %s && /usr/sbin/chown -R %s %s", cd_to, Owner, arg)) warnx("couldn't change owner of '%s' to '%s'", arg, Owner); return; } else if (Group) if (vsystem("cd %s && /usr/bin/chgrp -R %s %s", cd_to, Group, arg)) warnx("couldn't change group of '%s' to '%s'", arg, Group); }
static int RLog_Restart(PCOSA_DML_RLOG conf) { int err, level; #if 0 /* no PID file in current version */ if (access(SYSLOGD_PID_FILE, F_OK) == 0) vsystem("kill `cat %s`", SYSLOGD_PID_FILE); #else vsystem("kill `ps | awk '/syslogd/ && !/awk/ {print $1}'`"); #endif level = RLog_GetLevel(); if (conf->Enable && strlen(conf->Host) > 0) { if (conf->Port == 0 || conf->Port > 65535) err = vsystem("syslogd -l %d -R %s -L", level, conf->Host); else err = vsystem("syslogd -l %d -R %s:%d -L", level, conf->Host, conf->Port); } else { err = vsystem("syslogd -l %d", level); } if (err != 0) return -1; return 0; }
void set_ntp_server(const struct ntp_servers *servers) { int i; vsystem("uci set system.ntp=timeserver"); vasystem("uci set system.ntp.enable_server=%d", servers->enabled); vsystem("uci delete system.ntp.server"); for (i = 0; i < servers->count; i++) { vasystem("uci add_list system.ntp.server='%s'", servers->server[i]); } vsystem("uci commit system.ntp"); vsystem("/etc/init.d/sysntpd restart"); }
void set_dns(const struct string_list *search, const struct string_list *servers) { int i; vsystem("uci delete dhcp.@dnsmasq[0].server"); for (i = 0; i < servers->count; i++) vasystem("uci add_list dhcp.@dnsmasq[0].server='%s'", servers->s[i]); vsystem("uci set dhcp.@dnsmasq[0].add_local_domain=1"); if (search->count != 0) vasystem("uci set dhcp.@dnsmasq[0].domain=\"%s\"", search->s[0]); vsystem("uci commit dhcp"); vsystem("/etc/init.d/dnsmasq restart"); }
ANSC_STATUS CosaDmlRLog_Init(void) { COSA_DML_RLOG conf; int level; if (RLog_LoadConf(&conf) != 0) { RLOG_DBG("%s: fail to load config\n", __FUNCTION__); AnscTraceError(("%s: fail to load config\n", __FUNCTION__)); return ANSC_STATUS_FAILURE; } if (!conf.Enable && vsystem("ps | grep syslogd | grep -v grep >/dev/null") == 0) { /* do not restart syslogd */ RLOG_DBG("%s: Nothing need to do !\n", __FUNCTION__); return ANSC_STATUS_SUCCESS; } if (RLog_Restart(&conf) != 0) { RLOG_DBG("%s: fail to start remote logging\n", __FUNCTION__); AnscTraceError(("%s: fail to start remote logging\n", __FUNCTION__)); return ANSC_STATUS_FAILURE; } RLOG_DBG("%s: start remote log success !\n", __FUNCTION__); return ANSC_STATUS_SUCCESS; }
/* Convenience routine for getting out of playpen */ int leave_playpen() { static char left[FILENAME_MAX]; void (*oldsig)(int); if (!PenLocation[0]) return 0; /* Don't interrupt while we're cleaning up */ oldsig = signal(SIGINT, SIG_IGN); strcpy(left, PenLocation); popPen(PenLocation); if (chdir(PenLocation) == FAIL) { cleanup(0); errx(2, "%s: can't chdir back to '%s'", __func__, PenLocation); } if (left[0] == '/' && vsystem("/bin/rm -rf %s", left)) warnx("couldn't remove temporary dir '%s'", left); signal(SIGINT, oldsig); return 1; }
static int pkg_fire(dialogMenuItem *self) { int ret; ListPtrsPtr lists = (ListPtrsPtr)self->aux; PkgNodePtr sp, kp = self->data, plist = lists->plist; if (!plist) ret = DITEM_FAILURE; else if (kp->type == PACKAGE) { IndexEntryPtr ie = kp->data; sp = index_search(plist, kp->name, NULL); /* Not already selected? */ if (!sp) { if (!ie->installed) { PkgNodePtr np = (PkgNodePtr)safe_malloc(sizeof(PkgNode)); *np = *kp; np->next = plist->kids; plist->kids = np; index_recorddeps(TRUE, lists->root, ie); msgInfo("Added %s to selection list", kp->name); } else if (ie->depc == 0) { if (!msgNoYes("Do you really want to delete %s from the system?", kp->name)) { if (vsystem("pkg_delete %s %s", isDebug() ? "-v" : "", kp->name)) { msgConfirm("Warning: pkg_delete of %s failed.\n Check debug output for details.", kp->name); } else { ie->installed = 0; index_recorddeps(FALSE, lists->root, ie); } } } else msgConfirm("Warning: Package %s is needed by\n %d other installed package%s.", kp->name, ie->depc, (ie->depc != 1) ? "s" : ""); } else { index_recorddeps(FALSE, lists->root, ie); msgInfo("Removed %s from selection list", kp->name); index_delete(sp); } ret = DITEM_SUCCESS; /* Mark menu for redraw if we had dependencies */ if (strlen(ie->deps) > 0) ret |= DITEM_REDRAW; } else { /* Not a package, must be a directory */ int p, s; p = s = 0; index_menu(lists->root, kp, plist, &p, &s); ret = DITEM_SUCCESS | DITEM_CONTINUE; } return ret; }
void set_value(char *path, const char *str) { fprintf(stderr, "Parameter \"%s\" changed to \"%s\"\n", path, str); if (strcmp(path, "system.hostname") == 0) { if (sethostname(str, strlen(str)) < 0) fprintf(stderr, "setting hostname failed with: %m\n"); vasystem("uci set system.@system[0].hostname='%s'", str); vsystem("uci commit system.@system[0].hostname"); } }
static int vasystem(const char *fmt, ...) { va_list args; char buf[1024]; va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); return vsystem(buf); }
static int verifyUserSettings(WINDOW *ds_win) { char tmp[256], *cp; long luid; WINDOW *save; int rv; if (strlen(uname) == 0) { feepout("The user name field must not be empty!"); return 0; } snprintf(tmp, 256, "pw user show -q -n %s > /dev/null", uname); if (vsystem(tmp) == 0) { feepout("This user name is already in use."); return 0; } if (strlen(uid) > 0) { luid = strtol(uid, &cp, 10); if (luid < 0 || luid >= 65536 || (*cp != '\0' && !isspace(*cp))) { feepout("The UID must be a number between 1 and 65535."); return 0; } } if (strlen(shell) > 0) { while((cp = getusershell()) != NULL) if (strcmp(cp, shell) == 0) break; endusershell(); if (cp == NULL) { save = savescr(); rv = msgYesNo("Warning:\n\n" "The requested shell \"%s\" is not\n" "a valid user shell.\n\n" "Use it anyway?\n", shell); restorescr(save); wrefresh(ds_win); if (rv != DITEM_SUCCESS) return 0; } } if (strlen(umemb) > 0) { if (strpbrk(umemb, " \t") != NULL) { feepout("The member groups list must not contain any whitespace;\n" "use commas to separate the names."); return 0; } } return 1; }
void set_if_neigh(struct interface_list *info) { int i, j; vsystem("ip neigh flush nud permanent"); for (i = 0; i < info->count; i++) { for (j = 0; j < info->iface[i].ipv4.neigh.count; j++) vasystem("ip neigh replace %s lladdr %s nud permanent dev %s", info->iface[i].ipv4.neigh.ip[j].address, info->iface[i].ipv4.neigh.ip[j].value, wrt_ifname(info->iface[i].name)); for (j = 0; j < info->iface[i].ipv6.neigh.count; j++) vasystem("ip neigh replace %s lladdr %s nud permanent dev %s", info->iface[i].ipv6.neigh.ip[j].address, info->iface[i].ipv6.neigh.ip[j].value, wrt_ifname(info->iface[i].name)); } }
static int trylink(const char *from, const char *to) { if (link(from, to) == 0) return 0; if (errno == ENOENT) { /* try making the container directory */ char *cp = strrchr(to, '/'); if (cp) vsystem("/bin/mkdir -p %.*s", cp - to, to); return link(from, to); } return -1; }
static int Connect2Wifi(char *ssid, char *psk) { char buff[512]; FILE *fstream; vsystem("wpa_cli add_n | tail -n +2 > /mnt/sdcard/nid"); if (NULL == (fstream = fopen("/mnt/sdcard/nid", "r"))) { perror("fopen"); return; } while (NULL != mfgets(buff, sizeof(buff), fstream)) { } fclose(fstream); }
void cleanup(int sig) { static int in_cleanup = 0; if (!in_cleanup) { in_cleanup = 1; if (sig) printf("Signal %d received, cleaning up..\n", sig); if (!Fake && zapLogDir && LogDir[0]) vsystem("%s -rf %s", REMOVE_CMD, LogDir); while (leave_playpen()) ; } if (sig) exit(1); }
/* Selectively delete a hierarchy */ int delete_hierarchy(const char *dir, Boolean ign_err, Boolean nukedirs) { char *cp1, *cp2; cp1 = cp2 = strdup(dir); if (!fexists(dir) && !issymlink(dir)) { if (!ign_err) warnx("%s '%s' doesn't exist", isdir(dir) ? "directory" : "file", dir); return !ign_err; } else if (nukedirs) { if (vsystem("%s -r%s %s", REMOVE_CMD, (ign_err ? "f" : ""), dir)) return 1; } else if (isdir(dir) && !issymlink(dir)) { if (RMDIR(dir) && !ign_err) return 1; } else { if (REMOVE(dir, ign_err)) return 1; } if (!nukedirs) return 0; while (cp2) { if ((cp2 = strrchr(cp1, '/')) != NULL) *cp2 = '\0'; if (!isemptydir(dir)) return 0; if (RMDIR(dir) && !ign_err) { if (!fexists(dir)) warnx("directory '%s' doesn't exist", dir); else return 1; } /* back up the pathname one component */ if (cp2) { cp1 = strdup(dir); } } return 0; }
/* Expand a file into a convenient location, nuking it each time */ static char * expand(char *fname) { char *gunzip = "/usr/bin/gunzip"; if (!directory_exists(DOC_TMP_DIR)) { Mkdir(DOC_TMP_DIR); if (chown(DOC_TMP_DIR, 0, 0) < 0) return NULL; if (chmod(DOC_TMP_DIR, S_IRWXU) < 0) return NULL; } else unlink(DOC_TMP_FILE); if (!file_readable(fname) || vsystem("%s < %s > %s", gunzip, fname, DOC_TMP_FILE)) return NULL; return DOC_TMP_FILE; }
/* Initialize system defaults */ void systemInitialize(int argc, char **argv) { size_t i; int boothowto; sigset_t signalset; signal(SIGINT, SIG_IGN); globalsInit(); i = sizeof(boothowto); if (!sysctlbyname("debug.boothowto", &boothowto, &i, NULL, 0) && (i == sizeof(boothowto)) && (boothowto & RB_VERBOSE)) variable_set2(VAR_DEBUG, "YES", 0); if (set_termcap() == -1) { printf("Can't find terminal entry\n"); exit(-1); } /* XXX - libdialog has particularly bad return value checking */ init_dialog(); /* If we haven't crashed I guess dialog is running ! */ DialogActive = TRUE; /* Make sure HOME is set for those utilities that need it */ signal(SIGINT, handle_intr); /* * Make sure we can be interrupted even if we were re-executed * from an interrupt. */ sigemptyset(&signalset); sigaddset(&signalset, SIGINT); sigprocmask(SIG_UNBLOCK, &signalset, NULL); (void)vsystem("rm -rf %s", DOC_TMP_DIR); }
static int verifyGroupSettings(void) { char tmp[256], *cp; long lgid; if (strlen(gname) == 0) { feepout("The group name field must not be empty!"); return 0; } snprintf(tmp, 256, "pw group show -q -n %s > /dev/null", gname); if (vsystem(tmp) == 0) { feepout("This group name is already in use."); return 0; } if (strlen(gid) > 0) { lgid = strtol(gid, &cp, 10); if (lgid < 0 || lgid >= 65536 || (*cp != '\0' && !isspace(*cp))) { feepout("The GID must be a number between 1 and 65535."); return 0; } } if (strlen(gmemb) > 0) { if (strpbrk(gmemb, " \t") != NULL) { feepout("The group member list must not contain any whitespace;\n" "use commas to separate the names."); return 0; } #ifndef notyet /* XXX */ feepout("Sorry, the group member list feature\n" "is currently not yet implemented."); return 0; #endif } return 1; }
static void WifiScan_r() { FILE *fstream; char buffer[512] = {0}; char buffer1[512] = {0}; vsystem("wpa_cli scan_r > /mnt/sdcard/wifi/list.txt"); MsecSleep(1000); vsystem("awk '{print $5}' /mnt/sdcard/wifi/list.txt | tail -n +3 > /mnt/sdcard/scan"); MutexLock(&pWifiMutex); if (NULL == (fstream = fopen("/mnt/sdcard/scan", "r"))) { perror("fopen"); return; } int index = 0; while (NULL != mfgets(buffer, sizeof(buffer), fstream)) { if (index >= MAX_SIGNUM) { break; } strncpy(stWifi[index].ssid, buffer, sizeof(stWifi[index].ssid) - 1); index++; } fclose(fstream); vsystem("awk '{print $3}' /mnt/sdcard/wifi/list.txt | tail -n +3 > /mnt/sdcard/scan"); if (NULL == (fstream = fopen("/mnt/sdcard/scan", "r"))) { perror("fopen"); return; } index = 0; while (NULL != mfgets(buffer, sizeof(buffer), fstream)) { if (index >= MAX_SIGNUM) { break; } stWifi[index].iLevel = atoi(buffer); stWifi[index].iCell = CalcWifiCell(stWifi[index].iLevel); index++; } fclose(fstream); SortByLevel(index); int i; for(i = 0; i < index; i++) { if(i < WIFIITEM) { snprintf(buffer1, sizeof(buffer1), "%s", stWifi[i].ssid); if(NULL == pWiFiStrItem[i]) { free(pWiFiStrItem[i]); pWiFiStrItem[i] = NULL; } pWiFiStrItem[i] = TransString(buffer1); SetLabelText(pWiFiStrItem[i], pWiFiLblItem[i]); DisplayPicture(pWiFiItem[i]); DisplayLabel(pWiFiLblItem[i]); } printf("sig%d %s %d %d\n", i, stWifi[i].ssid, stWifi[i].iCell, stWifi[i].iLevel); } MutexUnlock(&pWifiMutex); WriteWifiMsgQueue(ENUM_SCAN); }
static void WifiScan() { vsystem("wpa_cli scan"); MsecSleep(10000); WriteWifiMsgQueue(ENUM_SCAN_R); }
static void WifiConnect()//victor { printf("enter wifi connecting !"); vsystem("wpa_cli enable 0"); }
/* * This is seriously ugly code following. Written very fast! * [And subsequently made even worse.. Sigh! This code was just born * to be hacked, I guess.. :) -jkh] */ static int pkg_do(char *pkg) { Package Plist; char pkg_fullname[FILENAME_MAX]; char playpen[FILENAME_MAX]; char extract_contents[FILENAME_MAX]; char *extract; const char *where_to; FILE *cfile; int code; PackingList p; struct stat sb; int inPlace, conflictsfound, errcode; /* support for separate pre/post install scripts */ int new_m = 0; char pre_script[FILENAME_MAX] = INSTALL_FNAME; char post_script[FILENAME_MAX]; char pre_arg[FILENAME_MAX], post_arg[FILENAME_MAX]; char *conflict[2]; char **matched; int fd; conflictsfound = 0; code = 0; zapLogDir = 0; LogDir[0] = '\0'; strcpy(playpen, FirstPen); inPlace = 0; memset(&Plist, '\0', sizeof(Plist)); /* Are we coming in for a second pass, everything already extracted? */ if (!pkg) { fgets(playpen, FILENAME_MAX, stdin); playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */ if (chdir(playpen) == FAIL) { warnx("pkg_add in SLAVE mode can't chdir to %s", playpen); return 1; } read_plist(&Plist, stdin); where_to = playpen; } /* Nope - do it now */ else { /* Is it an ftp://foo.bar.baz/file.t[bg]z specification? */ if (isURL(pkg)) { if (!(where_to = fileGetURL(NULL, pkg, KeepPackage))) { warnx("unable to fetch '%s' by URL", pkg); return 1; } strcpy(pkg_fullname, pkg); cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { warnx( "unable to open table of contents file '%s' - not a package?", CONTENTS_FNAME); goto bomb; } read_plist(&Plist, cfile); fclose(cfile); } else { strcpy(pkg_fullname, pkg); /* * Copy for sanity's sake, * could remove pkg_fullname */ if (strcmp(pkg, "-")) { if (stat(pkg_fullname, &sb) == FAIL) { warnx("can't stat package file '%s'", pkg_fullname); goto bomb; } sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); extract = extract_contents; } else { extract = NULL; sb.st_size = 100000; /* Make up a plausible average size */ } if (!(where_to = make_playpen(playpen, sb.st_size * 4))) errx(1, "unable to make playpen for %lld bytes", (long long)sb.st_size * 4); /* Since we can call ourselves recursively, keep notes on where we came from */ if (!getenv("_TOP")) setenv("_TOP", where_to, 1); if (unpack(pkg_fullname, extract)) { warnx( "unable to extract table of contents file from '%s' - not a package?", pkg_fullname); goto bomb; } cfile = fopen(CONTENTS_FNAME, "r"); if (!cfile) { warnx( "unable to open table of contents file '%s' - not a package?", CONTENTS_FNAME); goto bomb; } read_plist(&Plist, cfile); fclose(cfile); /* Extract directly rather than moving? Oh goodie! */ if (find_plist_option(&Plist, "extract-in-place")) { if (Verbose) printf("Doing in-place extraction for %s\n", pkg_fullname); p = find_plist(&Plist, PLIST_CWD); if (p) { if (!isdir(p->name) && !Fake) { if (Verbose) printf("Desired prefix of %s does not exist, creating..\n", p->name); vsystem("/bin/mkdir -p %s", p->name); if (chdir(p->name) == -1) { warn("unable to change directory to '%s'", p->name); goto bomb; } } where_to = p->name; inPlace = 1; } else { warnx( "no prefix specified in '%s' - this is a bad package!", pkg_fullname); goto bomb; } } /* * Apply a crude heuristic to see how much space the package will * take up once it's unpacked. I've noticed that most packages * compress an average of 75%, so multiply by 4 for good measure. */ if (!extract && !inPlace && min_free(playpen) < sb.st_size * 4) { warnx("projected size of %lld exceeds available free space.\n" "Please set your PKG_TMPDIR variable to point to a location with more\n" "free space and try again", (long long)sb.st_size * 4); warnx("not extracting %s\ninto %s, sorry!", pkg_fullname, where_to); goto bomb; } /* If this is a direct extract and we didn't want it, stop now */ if (inPlace && Fake) goto success; /* Finally unpack the whole mess. If extract is null we already + did so so don't bother doing it again. */ if (extract && unpack(pkg_fullname, NULL)) { warnx("unable to extract '%s'!", pkg_fullname); goto bomb; } } /* Check for sanity and dependencies */ if (sanity_check(pkg)) goto bomb; /* If we're running in MASTER mode, just output the plist and return */ if (AddMode == MASTER) { printf("%s\n", where_playpen()); write_plist(&Plist, stdout); return 0; } } /* * If we have a prefix, delete the first one we see and add this * one in place of it. */ if (Prefix) { delete_plist(&Plist, FALSE, PLIST_CWD, NULL); add_plist_top(&Plist, PLIST_CWD, Prefix); } setenv(PKG_PREFIX_VNAME, (p = find_plist(&Plist, PLIST_CWD)) ? p->name : ".", 1); /* Protect against old packages with bogus @name and origin fields */ if (Plist.name == NULL) Plist.name = "anonymous"; if (Plist.origin == NULL) Plist.origin = "anonymous/anonymous"; /* * See if we're already registered either with the same name (the same * version) or some other version with the same origin. */ if ((isinstalledpkg(Plist.name) > 0 || matchbyorigin(Plist.origin, NULL) != NULL) && !Force) { warnx("package '%s' or its older version already installed%s", Plist.name, FailOnAlreadyInstalled ? "" : " (ignored)"); code = FailOnAlreadyInstalled != FALSE; goto success; /* close enough for government work */ } /* Now check the packing list for conflicts */ if (!IgnoreDeps){ for (p = Plist.head; p != NULL; p = p->next) { if (p->type == PLIST_CONFLICTS) { int i; conflict[0] = strdup(p->name); conflict[1] = NULL; matched = matchinstalled(MATCH_GLOB, conflict, &errcode); free(conflict[0]); if (errcode == 0 && matched != NULL) for (i = 0; matched[i] != NULL; i++) if (isinstalledpkg(matched[i]) > 0) { warnx("package '%s' conflicts with %s", Plist.name, matched[i]); conflictsfound = 1; } continue; } } if(conflictsfound) { if(!Force) { warnx("please use pkg_delete first to remove conflicting package(s) or -f to force installation"); code = 1; goto bomb; } else warnx("-f specified; proceeding anyway"); } #if ENSURE_THAT_ALL_REQUIREMENTS_ARE_MET /* * Before attempting to do the slave mode bit, ensure that we've * downloaded & processed everything we need. * It's possible that we haven't already installed all of our * dependencies if the dependency list was misgenerated due to * other dynamic dependencies or if a dependency was added to a * package without all REQUIRED_BY packages being regenerated. */ for (p = pkg ? Plist.head : NULL; p; p = p->next) { const char *ext; char *deporigin; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (isinstalledpkg(p->name) <= 0 && !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { char subpkg[FILENAME_MAX], *sep; strlcpy(subpkg, pkg, sizeof subpkg); if ((sep = strrchr(subpkg, '/')) != NULL) { *sep = '\0'; if ((sep = strrchr(subpkg, '/')) != NULL) { *sep = '\0'; strlcat(subpkg, "/All/", sizeof subpkg); strlcat(subpkg, p->name, sizeof subpkg); if ((ext = strrchr(pkg, '.')) == NULL) { if (getenv("PACKAGESUFFIX")) ext = getenv("PACKAGESUFFIX"); else ext = ".tbz"; } strlcat(subpkg, ext, sizeof subpkg); pkg_do(subpkg); } } } } #endif /* Now check the packing list for dependencies */ for (p = Plist.head; p ; p = p->next) { char *deporigin; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (Verbose) { printf("Package '%s' depends on '%s'", Plist.name, p->name); if (deporigin != NULL) printf(" with '%s' origin", deporigin); printf(".\n"); } if (isinstalledpkg(p->name) <= 0 && !(deporigin != NULL && matchbyorigin(deporigin, NULL) != NULL)) { char path[FILENAME_MAX]; const char *cp = NULL; if (!Fake) { char prefixArg[2 + MAXPATHLEN]; /* "-P" + Prefix */ if (PrefixRecursive) { strlcpy(prefixArg, "-P", sizeof(prefixArg)); strlcat(prefixArg, Prefix, sizeof(prefixArg)); } if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) { const char *ext; ext = strrchr(pkg_fullname, '.'); if (ext == NULL) { if (getenv("PACKAGESUFFIX")) { ext = getenv("PACKAGESUFFIX"); } else { ext = ".tbz"; } } snprintf(path, FILENAME_MAX, "%s/%s%s", getenv("_TOP"), p->name, ext); if (fexists(path)) cp = path; else cp = fileFindByPath(pkg, p->name); if (cp) { if (Verbose) printf("Loading it from %s.\n", cp); if (vsystem("%s %s %s '%s'", PkgAddCmd, Verbose ? "-v " : "", PrefixRecursive ? prefixArg : "", cp)) { warnx("autoload of dependency '%s' failed%s", cp, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else { warnx("could not find package %s %s", p->name, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else if ((cp = fileGetURL(pkg, p->name, KeepPackage)) != NULL) { if (Verbose) printf("Finished loading %s via a URL\n", p->name); if (!fexists("+CONTENTS")) { warnx("autoloaded package %s has no +CONTENTS file?", p->name); if (!Force) ++code; } else if (vsystem("(pwd; /bin/cat +CONTENTS) | %s %s %s %s -S", PkgAddCmd, Verbose ? "-v" : "", PrefixRecursive ? prefixArg : "", KeepPackage ? "-K" : "")) { warnx("pkg_add of dependency '%s' failed%s", p->name, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } else if (Verbose) printf("\t'%s' loaded successfully.\n", p->name); /* Nuke the temporary playpen */ leave_playpen(); } } else { if (Verbose) printf("and was not found%s.\n", Force ? " (proceeding anyway)" : ""); else printf("Package dependency %s for %s not found%s\n", p->name, pkg, Force ? " (proceeding anyway)" : "!"); if (!Force) ++code; } } else if (Verbose) printf(" - already installed.\n"); } } /* if (!IgnoreDeps) */ if (code != 0) goto bomb; /* Look for the requirements file */ if ((fd = open(REQUIRE_FNAME, O_RDWR)) != -1) { fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IXALL); /* be sure, chmod a+x */ close(fd); if (Verbose) printf("Running requirements file first for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, Plist.name)) { warnx("package %s fails requirements %s", pkg_fullname, Force ? "installing anyway" : "- not installed"); if (!Force) { code = 1; goto success; /* close enough for government work */ } } } /* * Test whether to use the old method of passing tokens to installation * scripts, and set appropriate variables.. */ if (fexists(POST_INSTALL_FNAME)) { new_m = 1; sprintf(post_script, "%s", POST_INSTALL_FNAME); pre_arg[0] = '\0'; post_arg[0] = '\0'; } else { if (fexists(INSTALL_FNAME)) { sprintf(post_script, "%s", INSTALL_FNAME); sprintf(pre_arg, "PRE-INSTALL"); sprintf(post_arg, "POST-INSTALL"); } } /* If we're really installing, and have an installation file, run it */ if (!NoInstall && (fd = open(pre_script, O_RDWR)) != -1) { fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IXALL); /* be sure, chmod a+x */ close(fd); if (Verbose) printf("Running pre-install for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s %s", pre_script, Plist.name, pre_arg)) { warnx("install script returned error status"); unlink(pre_script); code = 1; goto success; /* nothing to uninstall yet */ } } /* Now finally extract the entire show if we're not going direct */ if (!inPlace && !Fake) extract_plist(".", &Plist); if (!Fake && fexists(MTREE_FNAME)) { if (Verbose) printf("Running mtree for %s..\n", Plist.name); p = find_plist(&Plist, PLIST_CWD); if (Verbose) printf("mtree -U -f %s -d -e -p %s >%s\n", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL); if (!Fake) { if (vsystem("/usr/sbin/mtree -U -f %s -d -e -p %s >%s", MTREE_FNAME, p ? p->name : "/", _PATH_DEVNULL)) warnx("mtree returned a non-zero status - continuing"); } } /* Run the installation script one last time? */ if (!NoInstall && (fd = open(post_script, O_RDWR)) != -1) { fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IXALL); /* be sure, chmod a+x */ close(fd); if (Verbose) printf("Running post-install for %s..\n", Plist.name); if (!Fake && vsystem("./%s %s %s", post_script, Plist.name, post_arg)) { warnx("install script returned error status"); unlink(post_script); code = 1; goto fail; } } /* Time to record the deed? */ if (!NoRecord && !Fake) { char contents[FILENAME_MAX]; char **depnames = NULL, **deporigins = NULL, ***depmatches; int i, dep_count = 0; FILE *contfile; if (getuid() != 0) warnx("not running as root - trying to record install anyway"); sprintf(LogDir, "%s/%s", LOG_DIR, Plist.name); zapLogDir = 1; if (Verbose) printf("Attempting to record package into %s..\n", LogDir); if (make_hierarchy(LogDir, FALSE)) { warnx("can't record package into '%s', you're on your own!", LogDir); bzero(LogDir, FILENAME_MAX); code = 1; goto success; /* close enough for government work */ } /* Make sure pkg_info can read the entry */ fd = open(LogDir, O_RDWR); fstat(fd, &sb); fchmod(fd, sb.st_mode | S_IRALL | S_IXALL); /* be sure, chmod a+rx */ close(fd); move_file(".", DESC_FNAME, LogDir); move_file(".", COMMENT_FNAME, LogDir); if (fexists(INSTALL_FNAME)) move_file(".", INSTALL_FNAME, LogDir); if (fexists(POST_INSTALL_FNAME)) move_file(".", POST_INSTALL_FNAME, LogDir); if (fexists(DEINSTALL_FNAME)) move_file(".", DEINSTALL_FNAME, LogDir); if (fexists(POST_DEINSTALL_FNAME)) move_file(".", POST_DEINSTALL_FNAME, LogDir); if (fexists(REQUIRE_FNAME)) move_file(".", REQUIRE_FNAME, LogDir); if (fexists(DISPLAY_FNAME)) move_file(".", DISPLAY_FNAME, LogDir); if (fexists(MTREE_FNAME)) move_file(".", MTREE_FNAME, LogDir); sprintf(contents, "%s/%s", LogDir, CONTENTS_FNAME); contfile = fopen(contents, "w"); if (!contfile) { warnx("can't open new contents file '%s'! can't register pkg", contents); goto success; /* can't log, but still keep pkg */ } write_plist(&Plist, contfile); fclose(contfile); for (p = Plist.head; p ; p = p->next) { char *deporigin; if (p->type != PLIST_PKGDEP) continue; deporigin = (p->next->type == PLIST_DEPORIGIN) ? p->next->name : NULL; if (Verbose) { printf("Trying to record dependency on package '%s'", p->name); if (deporigin != NULL) printf(" with '%s' origin", deporigin); printf(".\n"); } if (deporigin) { /* Defer to origin lookup */ depnames = realloc(depnames, (dep_count + 1) * sizeof(*depnames)); depnames[dep_count] = p->name; deporigins = realloc(deporigins, (dep_count + 2) * sizeof(*deporigins)); deporigins[dep_count] = deporigin; deporigins[dep_count + 1] = NULL; dep_count++; } else { /* No origin recorded, try to register on literal package name */ sprintf(contents, "%s/%s/%s", LOG_DIR, p->name, REQUIRED_BY_FNAME); contfile = fopen(contents, "a"); if (!contfile) { warnx("can't open dependency file '%s'!\n" "dependency registration is incomplete", contents); } else { fprintf(contfile, "%s\n", Plist.name); if (fclose(contfile) == EOF) { warnx("cannot properly close file %s", contents); } } } } if (dep_count > 0) { depmatches = matchallbyorigin((const char **)deporigins, NULL); free(deporigins); if (!IgnoreDeps && depmatches) { for (i = 0; i < dep_count; i++) { if (depmatches[i]) { int j; char **tmp = depmatches[i]; for (j = 0; tmp[j] != NULL; j++) { /* Origin looked up */ sprintf(contents, "%s/%s/%s", LOG_DIR, tmp[j], REQUIRED_BY_FNAME); if (depnames[i] && strcmp(depnames[i], tmp[j]) != 0) warnx("warning: package '%s' requires '%s', but '%s' " "is installed", Plist.name, depnames[i], tmp[j]); contfile = fopen(contents, "a"); if (!contfile) { warnx("can't open dependency file '%s'!\n" "dependency registration is incomplete", contents); } else { fprintf(contfile, "%s\n", Plist.name); if (fclose(contfile) == EOF) warnx("cannot properly close file %s", contents); } } } else if (depnames[i]) { /* No package present with this origin, try literal package name */ sprintf(contents, "%s/%s/%s", LOG_DIR, depnames[i], REQUIRED_BY_FNAME); contfile = fopen(contents, "a"); if (!contfile) { warnx("can't open dependency file '%s'!\n" "dependency registration is incomplete", contents); } else { fprintf(contfile, "%s\n", Plist.name); if (fclose(contfile) == EOF) { warnx("cannot properly close file %s", contents); } } } } } } if (Verbose) printf("Package %s registered in %s\n", Plist.name, LogDir); } if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) { FILE *fp; char buf[BUFSIZ]; snprintf(buf, sizeof buf, "%s/%s", LogDir, p->name); fp = fopen(buf, "r"); if (fp) { putc('\n', stdout); while (fgets(buf, sizeof(buf), fp)) fputs(buf, stdout); putc('\n', stdout); (void) fclose(fp); } else { if (!Fake) { warnx("cannot open %s as display file", buf); } } } goto success; bomb: code = 1; goto success; fail: /* Nuke the whole (installed) show, XXX but don't clean directories */ if (!Fake) delete_package(FALSE, FALSE, &Plist); success: /* delete the packing list contents */ free_plist(&Plist); leave_playpen(); return code; }
Boolean mediaInitNetwork(Device *dev) { int i; char *rp; char *cp, ifconfig[255]; WINDOW *w; if (!RunningAsInit || networkInitialized) return TRUE; if (isDebug()) msgDebug("Init routine called for network device %s.\n", dev->name); if (!file_readable("/etc/resolv.conf")) { if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE) { msgConfirm("Can't seem to write out /etc/resolv.conf. Net cannot be used."); return FALSE; } } w = savescr(); dialog_clear_norefresh(); snprintf(ifconfig, 255, "%s%s", VAR_IFCONFIG, dev->name); cp = variable_get(ifconfig); if (cp) { /* * If this interface isn't a DHCP one, bring it up. * If it is, then it's already up. */ if (strstr(cp, "DHCP") == NULL) { msgDebug("Not a DHCP interface.\n"); i = vsystem("ifconfig %s %s", dev->name, cp); if (i) { msgConfirm("Unable to configure the %s interface!\n" "This installation method cannot be used.", dev->name); return FALSE; } rp = variable_get(VAR_GATEWAY); if (!rp || *rp == '0') { msgConfirm("No gateway has been set. You will be unable to access hosts\n" "not on your local network"); } else { /* * Explicitly flush all routes to get back to a known sane * state. We don't need to check this exit code because if * anything fails it will show up in the route add below. */ system("route -n flush"); msgDebug("Adding default route to %s.\n", rp); if (vsystem("route -n add default %s", rp) != 0) { msgConfirm("Failed to add a default route; please check " "your network configuration"); return FALSE; } } } else { msgDebug("A DHCP interface. Should already be up.\n"); } } else if ((cp = variable_get(VAR_IPV6ADDR)) == NULL || *cp == '\0') { msgConfirm("The %s device is not configured. You will need to do so\n" "in the Networking configuration menu before proceeding.", dev->name); return FALSE; } if (isDebug()) msgDebug("Network initialized successfully.\n"); networkInitialized = TRUE; return TRUE; }
static int createFtpUser(void) { struct passwd *tpw; struct group *tgrp; char pwline[256]; char *tptr; int gid; FILE *fptr; if ((gid = atoi(tconf.group)) <= 0) { if (!(tgrp = getgrnam(tconf.group))) { /* group does not exist, create it by name */ tptr = msgGetInput("14", "What group ID to use for group %s ?", tconf.group); if (tptr && *tptr && ((gid = atoi(tptr)) > 0)) { if ((fptr = fopen(_PATH_GROUP,"a"))) { fprintf(fptr,"%s:*:%d:%s\n",tconf.group,gid,FTP_NAME); fclose(fptr); } } else gid = FTP_GID; } else gid = tgrp->gr_gid; } else if (!getgrgid(gid)) { /* group does not exist, create it by number */ tptr = msgGetInput("ftp", "What group name to use for gid %d ?", gid); if (tptr && *tptr) { SAFE_STRCPY(tconf.group, tptr); if ((tgrp = getgrnam(tconf.group))) { gid = tgrp->gr_gid; } else if ((fptr = fopen(_PATH_GROUP,"a"))) { fprintf(fptr,"%s:*:%d:%s\n",tconf.group,gid,FTP_NAME); fclose(fptr); } } } if ((tpw = getpwnam(FTP_NAME))) { if (tpw->pw_uid != FTP_UID) msgConfirm("FTP user already exists with a different uid."); return DITEM_SUCCESS; /* succeeds if already exists */ } sprintf(pwline, "%s:*:%s:%d::0:0:%s:%s:/nonexistent\n", FTP_NAME, tconf.uid, gid, tconf.comment, tconf.homedir); fptr = fopen(_PATH_MASTERPASSWD,"a"); if (! fptr) { msgConfirm("Could not open master password file."); return DITEM_FAILURE; } fprintf(fptr, "%s", pwline); fclose(fptr); msgNotify("Remaking password file: %s", _PATH_MASTERPASSWD); vsystem("pwd_mkdb -p %s", _PATH_MASTERPASSWD); return DITEM_SUCCESS | DITEM_RESTORE; }