Пример #1
0
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");
    }
}
Пример #2
0
int
vsystem(const char *fmt, ...)
{
    va_list args;
    int pstat;
    pid_t pid;
    int omask;
    sig_t intsave, quitsave;
    char *cmd;
    int i;
    struct stat sb;

    cmd = (char *)alloca(FILENAME_MAX);
    cmd[0] = '\0';
    va_start(args, fmt);
    vsnprintf(cmd, FILENAME_MAX, fmt, args);
    va_end(args);

    omask = sigblock(sigmask(SIGCHLD));
    if (Fake) {
	msgDebug("vsystem:  Faked execution of `%s'\n", cmd);
	return 0;
    }
    if (isDebug())
	msgDebug("Executing command `%s'\n", cmd);
    pid = fork();
    if (pid == -1) {
	(void)sigsetmask(omask);
	i = 127;
    }
    else if (!pid) {	/* Junior */
	(void)sigsetmask(omask);
	if (DebugFD != -1) {
	    dup2(DebugFD, 0);
	    dup2(DebugFD, 1);
	    dup2(DebugFD, 2);
	}
	else {
	    close(1); open("/dev/null", O_WRONLY);
	    dup2(1, 2);
	}
	if (stat("/stand/sh", &sb) == 0)
	    execl("/stand/sh", "/stand/sh", "-c", cmd, (char *)NULL);
	else
	    execl("/bin/sh", "/bin/sh", "-c", cmd, (char *)NULL);
	exit(1);
    }
    else {
	intsave = signal(SIGINT, SIG_IGN);
	quitsave = signal(SIGQUIT, SIG_IGN);
	pid = waitpid(pid, &pstat, 0);
	(void)sigsetmask(omask);
	(void)signal(SIGINT, intsave);
	(void)signal(SIGQUIT, quitsave);
	i = (pid == -1) ? -1 : WEXITSTATUS(pstat);
	if (isDebug())
	    msgDebug("Command `%s' returns status of %d\n", cmd, i);
    }
    return i;
}
Пример #3
0
void
mediaShutdownCDROM(Device *dev)
{
    char *mountpoint = "/dist";

    if (!cdromMounted)
	return;
    msgDebug("Unmounting %s from %s\n", dev->devname, mountpoint);
    if (unmount(mountpoint, MNT_FORCE) != 0)
	msgConfirm("Could not unmount the CDROM from %s: %s", mountpoint, strerror(errno));
    else {
	msgDebug("Unmount of CDROM successful\n");
	cdromMounted = FALSE;
    }
}
Пример #4
0
/* Whack up a fatal error on the status line */
void
msgFatal(const char *fmt, ...)
{
    va_list args;
    char *errstr;
    int attrs;

    errstr = (char *)alloca(FILENAME_MAX);
    strcpy(errstr, "Fatal Error: ");
    va_start(args, fmt);
    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
    va_end(args);
    beep();
    attrs = getattrs(stdscr);
    attrset(ATTR_TITLE);
    mvaddstr(StatusLine, 0, errstr);
    addstr(" - ");
    addstr("PRESS ANY KEY TO ");
    if (getpid() == 1)
	addstr("REBOOT");
    else
	addstr("QUIT");
    attrset(attrs);
    refresh();
    if (OnVTY)
	msgDebug("Fatal error `%s'!\n", errstr);
    getch();
}
Пример #5
0
/* Run some general command */
int
systemExecute(char *command)
{
    int status;
    struct termios foo;
    WINDOW *w = savescr();

    dialog_clear();
    dialog_update();
    end_dialog();
    DialogActive = FALSE;
    if (tcgetattr(0, &foo) != -1) {
	foo.c_cc[VERASE] = '\010';
	tcsetattr(0, TCSANOW, &foo);
    }
    if (!Fake)
	status = system(command);
    else {
	status = 0;
	msgDebug("systemExecute:  Faked execution of `%s'\n", command);
    }
    DialogActive = TRUE;
    restorescr(w);
    return status;
}
Пример #6
0
/* For a given string, call it or spit out an undefined command diagnostic */
int
dispatchCommand(char *str)
{
    int i;
    char *cp;

    if (!str || !*str) {
	msgConfirm("Null or zero-length string passed to dispatchCommand");
	return DITEM_FAILURE;
    }
    /* If it's got a newline, trim it */
    if ((cp = index(str, '\n')) != NULL)
	*cp = '\0';

    /* If it's got a `=' sign in there, assume it's a variable setting */
    if (index(str, '=')) {
	if (isDebug())
	    msgDebug("dispatch: setting variable `%s'\n", str);
	variable_set(str, 0);
	i = DITEM_SUCCESS;
    }
    else {
	/* A command might be a pathname if it's encoded in argv[0], which
	   we also support */
	if ((cp = rindex(str, '/')) != NULL)
	    str = cp + 1;
	if (isDebug())
	    msgDebug("dispatch: calling resword `%s'\n", str);
	if (!call_possible_resword(str, NULL, &i)) {
	    msgNotify("Warning: No such command ``%s''", str);
	    i = DITEM_FAILURE;
	}
	/*
	 * Allow a user to prefix a command with "noError" to cause
	 * us to ignore any errors for that one command.
	 */
	if (i != DITEM_SUCCESS && variable_get(VAR_NO_ERROR))
	    i = DITEM_SUCCESS;
	variable_unset(VAR_NO_ERROR);
    }
    return i;
}
Пример #7
0
void
variable_set2(char *var, char *value, int dirty)
{
    if (!var || !value)
	msgFatal("Null name or value passed to set_variable2(%s) = %s!",
		var ? var : "", value ? value : "");
    else if (!*var || !*value)
	msgDebug("Warning:  Zero length name or value passed to variable_set2(%s) = %s\n",
		var, value);
    make_variable(var, value, dirty);
}
Пример #8
0
static int
dispatch_systemExecute(dialogMenuItem *unused)
{
    char *cmd = variable_get(VAR_COMMAND);

    if (cmd)
	return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS;
    else
	msgDebug("_systemExecute: No command passed in `command' variable.\n");
    return DITEM_FAILURE;
}
Пример #9
0
static void
completeGroup(void)
{
    int pfd[2], i;
    char tmp[256], *cp;
    ssize_t l;
    size_t amnt;
    pid_t pid;
    char *vec[4] =
    {
	"pw", "group", "next", 0
    };

    pipe (pfd);
    if ((pid = fork()) == 0)
    {
	/* The kiddy. */
	dup2(pfd[1], 1);
	dup2(pfd[1], 2);
	for (i = getdtablesize(); i > 2; i--)
	    close(i);

	execv("/usr/sbin/pw", vec);
	msgDebug("Cannot execv() /usr/sbin/pw.\n");
	_exit(99);
    }
    else
    {
	/* The oldie. */
	close(pfd[1]);
	amnt = sizeof tmp;
	i = 0;
	while((l = read(pfd[0], &tmp[i], amnt)) > 0)
	{
	    amnt -= l;
	    i += l;
	    if (amnt == 0)
	    {
		close(pfd[0]);
		break;
	    }
	}
	close(pfd[0]);
	tmp[i] = '\0';
	waitpid(pid, &i, 0);
	if (WIFSIGNALED(i) || WEXITSTATUS(i) != 0)
	    /* ignore by now */
	    return;
	if ((cp = strchr(tmp, '\n')) != NULL)
	    *cp = '\0';
	strncpy(gid, tmp, sizeof gid);
    }
}
Пример #10
0
static int
dispatch_msgConfirm(dialogMenuItem *unused)
{
    char *msg = variable_get(VAR_COMMAND);

    if (msg) {
	msgConfirm("%s", msg);
	return DITEM_SUCCESS;
    }

    msgDebug("_msgConfirm: No message passed in `command' variable.\n");
    return DITEM_FAILURE;
}
Пример #11
0
static int
intr_restart(dialogMenuItem *self)
{
    int ret, fd, fdmax;

    free_variables();
    fdmax = getdtablesize();
    for (fd = 3; fd < fdmax; fd++)
	close(fd);
    ret = execl(StartName, StartName, "-restart", (char *)NULL);
    msgDebug("execl failed (%s)\n", strerror(errno));
    /* NOTREACHED */
    return -1;
}
Пример #12
0
void
variable_set(char *var, int dirty)
{
    char tmp[1024], *cp;

    if (!var)
	msgFatal("NULL variable name & value passed.");
    else if (!*var)
	msgDebug("Warning:  Zero length name & value passed to variable_set()\n");
    SAFE_STRCPY(tmp, var);
    if ((cp = index(tmp, '=')) == NULL)
	msgFatal("Invalid variable format: %s", var);
    *(cp++) = '\0';
    make_variable(tmp, string_skipwhite(cp), dirty);
}
Пример #13
0
/* Put up a message in a popup information box */
void
msgNotify(const char *fmt, ...)
{
    va_list args;
    char *errstr;

    errstr = (char *)alloca(FILENAME_MAX);
    va_start(args, fmt);
    vsnprintf(errstr, FILENAME_MAX, fmt, args);
    va_end(args);
    use_helpline(NULL);
    use_helpfile(NULL);
    if (isDebug())
	msgDebug("Notify: %s\n", errstr);
    dialog_msgbox(NULL, errstr, -1, -1, 0);
}
Пример #14
0
/* Tell the user there's some output to go look at */
void
msgWeHaveOutput(const char *fmt, ...)
{
    va_list args;
    char *errstr;
    WINDOW *w = savescr();
    
    errstr = (char *)alloca(FILENAME_MAX);
    va_start(args, fmt);
    vsnprintf(errstr, FILENAME_MAX, fmt, args);
    va_end(args);
    use_helpline(NULL);
    use_helpfile(NULL);
    msgDebug("Notify: %s\n", errstr);
    dialog_clear_norefresh();
    sleep(2);
    dialog_msgbox(NULL, errstr, -1, -1, 0);
    restorescr(w);
}
Пример #15
0
FILE *
mediaGetCDROM(Device *dev, char *file, Boolean probe)
{
    char	buf[PATH_MAX];

    if (isDebug())
	msgDebug("Request for %s from CDROM\n", file);
    snprintf(buf, PATH_MAX, "/dist/%s", file);
    if (file_readable(buf))
	return fopen(buf, "r");
    snprintf(buf, PATH_MAX, "/dist/dists/%s", file);
    if (file_readable(buf))
	return fopen(buf, "r");
    snprintf(buf, PATH_MAX, "/dist/%s/%s", variable_get(VAR_RELNAME), file);
    if (file_readable(buf))
	return fopen(buf, "r");
    snprintf(buf, PATH_MAX, "/dist/%s/dists/%s", variable_get(VAR_RELNAME), file);
    return fopen(buf, "r");
}
Пример #16
0
void
pvariable_set(char *var)
{
    char *p;
    char tmp[1024];

    if (!var)
	msgFatal("NULL variable name & value passed.");
    else if (!*var)
	msgDebug("Warning:  Zero length name & value passed to variable_set()\n");
    /* Add a trivial namespace to whatever name the caller chooses. */
    SAFE_STRCPY(tmp, "SYSINSTALL_PVAR");
    if (index(var, '=') == NULL)
	msgFatal("Invalid variable format: %s", var);
    strlcat(tmp, var, 1024); 
    p = strchr(tmp, '=');
    *p = '\0';
    setenv(tmp, p + 1, 1);
}
Пример #17
0
/* Whack up a warning on the status line */
void
msgWarn(const char *fmt, ...)
{
    va_list args;
    char *errstr;
    int attrs;

    errstr = (char *)alloca(FILENAME_MAX);
    strcpy(errstr, "Warning: ");
    va_start(args, fmt);
    vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
    va_end(args);
    attrs = getattrs(stdscr);
    beep();
    attrset(ATTR_TITLE);
    mvaddstr(StatusLine, 0, errstr);
    attrset(attrs);
    refresh();
    if (OnVTY && isDebug())
	msgDebug("Warning message `%s'\n", errstr);
}
Пример #18
0
int
dump_variables(dialogMenuItem *unused)
{
    FILE *fp;
    Variable *vp;

    if (isDebug())
	msgDebug("Writing %s variables to file..\n", ProgName);

    fp = fopen("/etc/sade.vars", "w");
    if (!fp) {
	msgConfirm("Unable to write to /etc/%s.vars: %s",
		   ProgName, strerror(errno));
	return DITEM_FAILURE;
    }

    for (vp = VarHead; vp; vp = vp->next)
	fprintf(fp, "%s=\"%s\" (%d)\n", vp->name, vp->value, vp->dirty);

    fclose(fp);

    return DITEM_SUCCESS;
}
Пример #19
0
static void
completeUser(void)
{
    int pfd[2], i;
    char tmp[256], *cp, *cp2;
    ssize_t l;
    size_t amnt;
    pid_t pid;
    char *vec[7] =
    {
	"pw", "user", "add", "-N", "-n", 0, 0
    };
#define VEC_UNAME 5

    pipe (pfd);
    if ((pid = fork()) == 0)
    {
	/* The kiddy. */
	dup2(pfd[1], 1);
	dup2(pfd[1], 2);
	for (i = getdtablesize(); i > 2; i--)
	    close(i);

	vec[VEC_UNAME] = uname;

	execv("/usr/sbin/pw", vec);
	msgDebug("Cannot execv() /usr/sbin/pw.\n");
	_exit(99);
    }
    else
    {
	/* The oldie. */
	close(pfd[1]);
	amnt = sizeof tmp;
	i = 0;
	while((l = read(pfd[0], &tmp[i], amnt)) > 0)
	{
	    amnt -= l;
	    i += l;
	    if (amnt == 0)
	    {
		close(pfd[0]);
		break;
	    }
	}
	close(pfd[0]);
	tmp[i] = '\0';
	waitpid(pid, &i, 0);
	if (WIFSIGNALED(i) || WEXITSTATUS(i) != 0)
	    /* ignore by now */
	    return;
	if ((cp = strchr(tmp, '\n')) != NULL)
	    *cp = '\0';
	if ((cp = strchr(tmp, ':')) == NULL || (cp = strchr(++cp, ':')) == NULL)
	    return;
	cp++;
	if ((cp2 = strchr(cp, ':')) == NULL)
	    return;
	*cp2++ = '\0';
	strncpy(uid, cp, sizeof uid);
	cp = cp2;
	if ((cp2 = strchr(cp, ':')) == NULL)
	    return;
	*cp2++ = '\0';
#ifdef notyet /* XXX pw user add -g doesn't accept a numerical GID */
	strncpy(ugroup, cp, sizeof ugroup);
#endif
	cp = cp2;
	if ((cp2 = strchr(cp, ':')) == NULL || (cp2 = strchr(++cp2, ':')) == NULL ||
	    (cp = cp2 = strchr(++cp2, ':')) == NULL || (cp2 = strchr(++cp2, ':')) == NULL)
	    return;
	*cp2++ = '\0';
	cp++;
	strncpy(gecos, cp, sizeof gecos);
	cp = cp2;
	if ((cp2 = strchr(cp, ':')) == NULL)
	    return;
	*cp2++ = '\0';
	if (*cp2)
	    strncpy(shell, cp2, sizeof shell);
    }
#undef VEC_UNAME
}
Пример #20
0
static void
addUser(WINDOW *ds_win)
{
    char tmp[256], *msg;
    int pfd[2], ipfd[2], i, j;
    ssize_t l;
    size_t amnt;
    pid_t pid;
    /*
     * Maximal list:
     * pw user add -m -n uname -g grp -u uid -c comment -d homedir -s shell -G grplist -h 0
     */
    char *vec[21] =
    {
	"pw", "user", "add", "-m", "-n", /* ... */
    };
#define VEC_UNAME 5

    msgNotify("Adding user \"%s\"...", uname);

    pipe (pfd);
    pipe (ipfd);
    if ((pid = fork()) == 0)
    {
	/* The kiddy. */
	dup2(ipfd[0], 0);
	dup2(pfd[1], 1);
	dup2(pfd[1], 2);
	for (i = getdtablesize(); i > 2; i--)
	    close(i);

	vec[i = VEC_UNAME] = uname;
	i++;
#define ADDVEC(var, option) do { if (strlen(var) > 0) { vec[i++] = option; vec[i++] = var; } } while (0)
	ADDVEC(ugroup, "-g");
	ADDVEC(uid, "-u");
	ADDVEC(gecos, "-c");
	ADDVEC(homedir, "-d");
	ADDVEC(shell, "-s");
	ADDVEC(umemb, "-G");
	if (passwd[0]) {
	    vec[i++] = "-h";
	    vec[i++] = "0";
	}
	vec[i] = 0;

	execv("/usr/sbin/pw", vec);
	msgDebug("Cannot execv() /usr/sbin/pw.\n");
	_exit(99);
    }
    else
    {
	/* The oldie. */
	close(pfd[1]);
	close(ipfd[0]);

	if (passwd[0])
	    write(ipfd[1], passwd, strlen(passwd));
	close(ipfd[1]);
	amnt = sizeof tmp;
	i = 0;
	while((l = read(pfd[0], &tmp[i], amnt)) > 0)
	{
	    amnt -= l;
	    i += l;
	    if (amnt == 0)
	    {
		close(pfd[0]);
		break;
	    }
	}
	close(pfd[0]);
	tmp[i] = '\0';
	waitpid(pid, &i, 0);
	if (WIFSIGNALED(i))
	{
	    j = WTERMSIG(i);
	    msg = "The `pw' command exited with signal %d.\n";
	    goto sysfail;
	}
	else if((j = WEXITSTATUS(i)))
	{
	    i = 0;
	    if(strncmp(tmp, "pw: ", 4) == 0)
		i = 4;
	    tmp[sizeof tmp - 1] = '\0';	/* sanity */
	    if (j == EX_DATAERR || j == EX_NOUSER || j == EX_SOFTWARE)
		msgConfirm("The `pw' command exited with an error status.\n"
			   "Its error message was:\n\n%s",
			   &tmp[i]);
	    else
	    {
		msg = "The `pw' command exited with unexpected status %d.\n";
	sysfail:
		msgDebug(msg, j);
		msgDebug("Command stdout and stderr was:\n\n%s", tmp);
		msgConfirm(msg, j);
	    }
	}
	else if (!passwd[0])
	    msgConfirm("You will need to enter a password for this user\n"
		       "later, using the passwd(1) command from the shell.\n\n"
		       "The account for `%s' is currently still disabled.",
		       uname);
    }
#undef VEC_UNAME
#undef ADDVEC
}
Пример #21
0
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;
}
Пример #22
0
int
dhcpParseLeases(char *file, char *hostname, char *domain, char *nameserver,
		char *ipaddr, char *gateway, char *netmask)
{
    char tempbuf[1024];
    char optbuf[1024], *optname = NULL;
    char *tptr;
    int endedflag = 0;
    int leaseflag = 0;
    FILE *fp;
    enum { P_NOSTMT, P_NOSTMT1, P_STMT, P_STMTLINE } state;

    if ((fp = fopen(file, "r")) == NULL) {
	msgDebug("error opening file %s: %s\n", file, strerror(errno));
	return -1;
    }

    state = P_NOSTMT;
    while (fscanf(fp, "%1023s", tempbuf) > 0) {
    	switch (state) {
	case P_NOSTMT:
	    state = P_NOSTMT1;
	    if (!strncasecmp(tempbuf, "lease", 5)) {
		if (!leaseflag)
		    leaseflag = 1;
		else {
		    fclose(fp);
		    return 0;
		}
	    }
	    break;

	case P_NOSTMT1: 
	    if (tempbuf[0] != '{') {
		msgWarn("dhcpParseLeases: '{' expected");
		fclose(fp);
		return -1;
	    }
	    state = P_STMT;
	    break;

	case P_STMT:
	    if (!strncasecmp("option", tempbuf, 6))
		continue;
	    if (tempbuf[0] == '}') {
		state = P_NOSTMT;
		leaseflag = 0;
		continue;
	    }
	    if (!leaseflag) 
		break;
	    if (tempbuf[0] == ';') { 	/* play it safe */
		state = P_STMT;
		continue;
	    }
	    if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) {
		*tptr = '\0';
		endedflag = 1;
	    }
	    if (!isalnum(tempbuf[0])) {
		msgWarn("dhcpParseLeases: bad option");
		fclose(fp);
		return -1;
	    }
	    if (optname)
		free(optname);
	    optname = strdup(tempbuf);
	    if (endedflag) {
		state = P_STMT;
		endedflag = 0;
		continue;
	    }
	    state = P_STMTLINE;
	    break;

	case P_STMTLINE:
	    if (tempbuf[0] == ';') {
		state = P_STMT;
		continue;
	    }
	    if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) {
		*tptr = '\0';
		endedflag = 1;
	    }
	    if (tempbuf[0] == '"') {
		if (sscanf(tempbuf, "\"%[^\" ]\"", optbuf) < 1) {
		    msgWarn("dhcpParseLeases: bad option value");
		    fclose(fp);
		    return -1;
		}
	    }
	    else
		strcpy(optbuf, tempbuf);

	    if (!strcasecmp("host-name", optname)) {
		strcpy(hostname, optbuf);
	    } else if (!strcasecmp("domain-name", optname)) {
		strcpy(domain, optbuf);
	    } else if (!strcasecmp("fixed-address", optname)) {
		strcpy(ipaddr, optbuf);
	    } else if (!strcasecmp("routers", optname)) {
		if((tptr = (char *)strchr(optbuf, ',')))
		    *tptr = '\0';
		strcpy(gateway, optbuf);
	    } else if (!strcasecmp("subnet-mask", optname)) {
		strcpy(netmask, optbuf);
	    } else if (!strcasecmp("domain-name-servers", optname)) {
		/* <jkh> ...one value per property */
		if((tptr = (char *)strchr(optbuf, ',')))
		    *tptr = '\0';
		strcpy(nameserver, optbuf);
	    }
	    if (endedflag) {
		state = P_STMT;
		endedflag = 0;
		continue;
	    }
	    break;
	}
    }
    fclose(fp);
    return 0;
}
Пример #23
0
int
set_termcap(void)
{
    char           *term;
    int		   stat;
    struct winsize ws;

    term = getenv("TERM");
    stat = ioctl(STDERR_FILENO, GIO_COLOR, &ColorDisplay);

	if (isDebug())
	    DebugFD = open("sade.debug", O_WRONLY|O_CREAT|O_TRUNC, 0644);
	else
	    DebugFD = -1;
	if (DebugFD < 0)
	    DebugFD = open("/dev/null", O_RDWR, 0);

    if (!OnVTY || (stat < 0)) {
	if (!term) {
	    char *term;

	    prompt_term(&term);
	    if (setenv("TERM", term, 1) < 0)
		return -1;
	}
	if (DebugFD < 0)
	    DebugFD = open("/dev/null", O_RDWR, 0);
    }
    else {
	int i, on;

	if (getpid() == 1) {
	    DebugFD = open("/dev/ttyv1", O_WRONLY);
	    if (DebugFD != -1) {
		on = 1;
		i = ioctl(DebugFD, TIOCCONS, (char *)&on);
		msgDebug("ioctl(%d, TIOCCONS, NULL) = %d (%s)\n",
			 DebugFD, i, !i ? "success" : strerror(errno));
	    }
	}

#ifdef PC98
	if (!term) {
	    if (setenv("TERM", "cons25w", 1) < 0)
		return -1;
	}
#else
	if (ColorDisplay) {
	    if (!term) {
		if (setenv("TERM", "xterm", 1) < 0)
		    return -1;
	    }
	}
	else {
	    if (!term) {
		if (setenv("TERM", "vt100", 1) < 0)
		    return -1;
	    }
	}
#endif
    }
    if (ioctl(0, TIOCGWINSZ, &ws) == -1) {
	msgDebug("Unable to get terminal size - errno %d\n", errno);
	ws.ws_row = 0;
    }
    StatusLine = ws.ws_row ? ws.ws_row - 1: (OnVTY ? VTY_STATUS_LINE : TTY_STATUS_LINE);
    return 0;
}
Пример #24
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;
}
Пример #25
0
static void
screech(int sig)
{
    msgDebug("\007Signal %d caught!  That's bad!\n", sig);
    longjmp(BailOut, sig);
}
Пример #26
0
static void
addGroup(WINDOW *ds_win)
{
    char tmp[256];
    int pfd[2], i;
    ssize_t l;
    size_t amnt;
    pid_t pid;
    char *vec[8] =
    {
	"pw", "group", "add", "-n", 0, "-g", 0, 0
    };
#define VEC_GNAME 4
#define VEC_GID 6

    msgNotify("Adding group \"%s\"...", gname);

    pipe (pfd);
    if ((pid = fork()) == 0)
    {
	/* The kiddy. */
	dup2(pfd[1], 1);
	dup2(pfd[1], 2);
	for (i = getdtablesize(); i > 2; i--)
	    close(i);

	vec[VEC_GNAME] = gname;

	if (strlen(gid) > 0)
	    vec[VEC_GID] = gid;
	else
	    vec[VEC_GID - 1] = 0;

	execv("/usr/sbin/pw", vec);
	msgDebug("Cannot execv() /usr/sbin/pw.\n");
	_exit(99);
    }
    else
    {
	/* The oldie. */
	close(pfd[1]);
	amnt = sizeof tmp;
	i = 0;
	while((l = read(pfd[0], &tmp[i], amnt)) > 0)
	{
	    amnt -= l;
	    i += l;
	    if (amnt == 0)
	    {
		close(pfd[0]);
		break;
	    }
	}
	close(pfd[0]);
	tmp[i] = '\0';
	waitpid(pid, &i, 0);
	if (WIFSIGNALED(i))
	    msgDebug("pw(8) exited with signal %d.\n", WTERMSIG(i));
	else if(WEXITSTATUS(i))
	{
	    i = 0;
	    if(strncmp(tmp, "pw: ", 4) == 0)
		i = 4;
	    tmp[sizeof tmp - 1] = '\0';	/* sanity */
	    msgConfirm("The `pw' command exited with an error status.\n"
		       "Its error message was:\n\n%s",
		       &tmp[i]);
	}
    }
#undef VEC_GNAME
#undef VEC_GID
}