Esempio n. 1
0
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;
}
Esempio n. 2
0
int
index_extract(Device *dev, PkgNodePtr top, PkgNodePtr who, Boolean depended,
    int current_volume)
{
    int status = DITEM_SUCCESS;
    Boolean notyet = FALSE;
    PkgNodePtr tmp2;
    IndexEntryPtr id = who->data;
    WINDOW *w;

    /* 
     * Short-circuit the package dependency checks.  We're already
     * maintaining a data structure of installed packages, so if a
     * package is already installed, don't try to check to make sure
     * that all of its dependencies are installed.  At best this
     * wastes a ton of cycles and can cause minor delays between
     * package extraction.  At worst it can cause an infinite loop with
     * a certain faulty INDEX file. 
     */

    if (id->installed == 1 || (have_volumes && id->vol_checked == current_volume))
	return DITEM_SUCCESS;

    w = savescr();
    if (id && id->deps && strlen(id->deps)) {
	char t[2048 * 8], *cp, *cp2;

	SAFE_STRCPY(t, id->deps);
	cp = t;
	while (cp && DITEM_STATUS(status) == DITEM_SUCCESS) {
	    if ((cp2 = index(cp, ' ')) != NULL)
		*cp2 = '\0';
	    if ((tmp2 = index_search(top, cp, NULL)) != NULL) {
		status = index_extract(dev, top, tmp2, TRUE, current_volume);
		if (DITEM_STATUS(status) != DITEM_SUCCESS) {
		    /* package probably on a future disc volume */
		    if (status & DITEM_CONTINUE) {
			status = DITEM_SUCCESS;
			notyet = TRUE;
		    } else if (variable_get(VAR_NO_CONFIRM))
			msgNotify("Loading of dependent package %s failed", cp);
		    else
			msgConfirm("Loading of dependent package %s failed", cp);
		}
	    }
	    else if (!package_installed(cp)) {
		if (variable_get(VAR_NO_CONFIRM))
		    msgNotify("Warning: %s is a required package but was not found.", cp);
		else
		    msgConfirm("Warning: %s is a required package but was not found.", cp);
	    }
	    if (cp2)
		cp = cp2 + 1;
	    else
		cp = NULL;
	}
    }

    /*
     * If iterating through disc volumes one at a time indicate failure if
     * dependency install failed due to package being on a higher volume
     * numbered disc, but that we should continue anyway.  Note that this
     * package has already been processed for this disc volume so we don't
     * need to do it again.
     */

    if (notyet) {
    	restorescr(w);
	id->vol_checked = current_volume;
	return DITEM_FAILURE | DITEM_CONTINUE;
    }

    /*
     * Done with the deps?  Try to load the real m'coy.  If iterating
     * through a multi-volume disc set fail the install if the package
     * is on a higher numbered volume to cut down on disc switches the
     * user needs to do, but indicate caller should continue processing
     * despite error return.  Note this package was processed for the
     * current disc being checked.
     */

    if (DITEM_STATUS(status) == DITEM_SUCCESS) {
	/* Prompt user if the package is not available on the current volume. */
	if(mediaDevice->type == DEVICE_TYPE_CDROM) {
	    if (current_volume != 0 && id->volume > current_volume) {
		restorescr(w);
		id->vol_checked = current_volume;
		return DITEM_FAILURE | DITEM_CONTINUE;
	    }
	    while (id->volume != dev->volume) {
		if (!msgYesNo("This is disc #%d.  Package %s is on disc #%d\n"
			  "Would you like to switch discs now?\n", dev->volume,
			  id->name, id->volume)) {
		    DEVICE_SHUTDOWN(mediaDevice);
		    msgConfirm("Please remove disc #%d from your drive, and add disc #%d\n",
			dev->volume, id->volume);
		    DEVICE_INIT(mediaDevice);
		} else {
		    restorescr(w);
		    return DITEM_FAILURE;
		}
	    }
	}
	status = package_extract(dev, who->name, depended);
	if (DITEM_STATUS(status) == DITEM_SUCCESS)
	    id->installed = 1;
    }
    restorescr(w);
    return status;
}
Esempio n. 3
0
int
main(int argc, char **argv)
{
    int choice, scroll, curr, max, status;

    /* Catch fatal signals and complain about them if running as init */
    if (getpid() == 1) {
	signal(SIGBUS, screech);
	signal(SIGSEGV, screech);
    }

    /* We don't work too well when running as non-root anymore */
    if (geteuid() != 0) {
	fprintf(stderr, "Error: This utility should only be run as root.\n");
	return 1;
    }

    if (argc > 1 && !strcmp(argv[1], "-fake")) {
	Fake = TRUE;
    }

    /* Set up whatever things need setting up */
    systemInitialize(argc, argv);

    /* Set default flag and variable values */
    installVarDefaults(NULL);
    /* only when multi-user is it reasonable to do this here */
    if (!RunningAsInit)
	installEnvironment();

    if (argc > 1 && !strcmp(argv[1], "-fake")) {
	variable_set2(VAR_DEBUG, "YES");
	msgConfirm("I'll be just faking it from here on out, OK?");
    }

    /* Try to preserve our scroll-back buffer */
    if (OnVTY) {
	for (curr = 0; curr < 25; curr++)
	    putchar('\n');
    }
    /* Move stderr aside */
    if (DebugFD)
	dup2(DebugFD, 2);

#ifdef PCCARD
    /* Initialize PC-card */
    pccardInitialize();
#endif

    /* Probe for all relevant devices on the system */
    deviceGetAll();

    /* First, see if we have any arguments to process (and argv[0] counts if it's not "sysinstall") */
    if (!RunningAsInit) {
	int i, start_arg;

	if (!strstr(argv[0], "sysinstall"))
	    start_arg = 0;
	else if (Fake)
	    start_arg = 2;
	else
	    start_arg = 1;
	for (i = start_arg; i < argc; i++) {
	    if (DITEM_STATUS(dispatchCommand(argv[i])) != DITEM_SUCCESS)
		systemShutdown(1);
	}
	if (argc > start_arg)
	    systemShutdown(0);
    }
    else
	dispatch_load_file_int(TRUE);

    status = setjmp(BailOut);
    if (status) {
	msgConfirm("A signal %d was caught - I'm saving what I can and shutting\n"
		   "If you can reproduce the problem, please turn Debug on in\n"
		   "the Options menu for the extra information it provides in\n"
		   "debugging problems like this.", status);
	systemShutdown(status);
    }

    /* Begin user dialog at outer menu */
    dialog_clear();
    while (1) {
	choice = scroll = curr = max = 0;
	dmenuOpen(&MenuInitial, &choice, &scroll, &curr, &max, TRUE);
	if (getpid() != 1 || !msgYesNo("Are you sure you wish to exit?  The system will reboot\n"
				       "(be sure to remove any floppies from the drives)."))
	    break;
    }

    /* Say goodnight, Gracie */
    systemShutdown(0);

    return 0; /* We should never get here */
}
Esempio n. 4
0
Boolean
mediaInitCDROM(Device *dev)
{
    struct iso_args	args;
    Attribs *cd_attr;
    char *cp, *mountpoint = "/dist";
    Boolean readInfo = TRUE;
    static Boolean bogusCDOK = FALSE;

    if (cdromMounted)
	return TRUE;

    bzero(&args, sizeof(args));
    args.fspec = dev->devname;
    args.flags = 0;

    cd_attr = alloca(sizeof(Attribs) * MAX_ATTRIBS);
    cp = NULL;

    Mkdir(mountpoint);

    if (mount(MOUNT_CD9660, mountpoint, MNT_RDONLY, (caddr_t) &args) == -1) {
	if (errno == EINVAL) {
	    msgConfirm("The CD in your drive looks more like an Audio CD than a FreeBSD release.");
	    return FALSE;
	}
	else if (errno != EBUSY) {
	    msgConfirm("Error mounting %s on %s: %s (%u)", dev->devname, mountpoint, strerror(errno), errno);
	    return FALSE;
	}
	cdromMounted = TRUE;
    }
    else
	cdromMounted = TRUE;

    if (!file_readable(string_concat(mountpoint, "/cdrom.inf")) && !bogusCDOK) {
	if (msgYesNo("Warning: The CD currently in the drive is either not a FreeBSD\n"
		     "CD or it is an older (pre 2.1.5) FreeBSD CD which does not\n"
		     "have a version number on it.  Do you wish to use this CD anyway?") != 0) {
	    unmount(mountpoint, MNT_FORCE);
	    cdromMounted = FALSE;
	    return FALSE;
	}
	else {
	    readInfo = FALSE;
	    bogusCDOK = TRUE;
	}
    }

    if (readInfo &&
	(DITEM_STATUS(attr_parse_file(cd_attr, string_concat(mountpoint, "/cdrom.inf"))) == DITEM_FAILURE ||
		      !(cp = attr_match(cd_attr, "CD_VERSION")) || (strcmp(cp, variable_get(VAR_RELNAME)) && strcmp("none", variable_get(VAR_RELNAME))))) {
	if (!cp) {
	    msgConfirm("Unable to find a %s/cdrom.inf file.\n"
		       "Either this is not a FreeBSD CDROM, there is a problem with\n"
		       "the CDROM driver or something is wrong with your hardware.\n"
		       "Please fix this problem (check the console logs on VTY2) and\n"
		       "try again.", mountpoint);
	}
	else if (!bogusCDOK) {
	    msgConfirm("Warning: The version of the FreeBSD CD currently in the drive\n"
		       "(%s) does not match the version of the boot floppy\n"
		       "(%s).\n\n"
		       "If this is intentional, to avoid this message in the future\n"
		       "please visit the Options editor to set the boot floppy version\n"
		       "string to match that of the CD before selecting it as your\n"
		       "installation media.", cp, variable_get(VAR_RELNAME));

	    if (msgYesNo("Would you like to try and use this CDROM anyway?") != 0) {
		unmount(mountpoint, MNT_FORCE);
		cdromMounted = FALSE;
		return FALSE;
	    }
	    else
		bogusCDOK = TRUE;
	}
    }
    msgDebug("Mounted FreeBSD CDROM from device %s\n", dev->devname);
    return TRUE;
}