Beispiel #1
0
static void		exec_file(char **cmd, int isnew_env, char **env)
{
	if (!isnew_env)
		env = build_env(glob()->env);
	isaccess(&(*cmd), 0, 0);
	execve(*cmd, cmd, env);
	ft_puttext_fd("42sh: cannot exec: ", *cmd, "\n", 2);
	if (env)
		ft_p_free(&env);
	exit(3);
}
Beispiel #2
0
static void		exec_bin(char **cmd, int isnew_env, char **env)
{
	char	**path;
	int		i;

	if (!isnew_env)
		env = build_env(glob()->env);
	if ((!isnew_env) || (isnew_env && !getenv_path(env)))
		path = bin(*cmd, ft_getenv("PATH"));
	else
		path = bin(*cmd, getenv_path(env));
	if ((i = isaccess(path, 1, 0)) > -1)
		execve(path[i], cmd, env);
	ft_puttext_fd("42sh: command not found: ", *cmd, "\n", 2);
	if (path)
		ft_p_free(&path);
	if (env)
		ft_p_free(&env);
	exit(5);
}
Beispiel #3
0
/* FIXME! buffer overflows? */
static int handle_choice(const char *askbuf)
{
	char lesbabuf[30];
	struct userbase muser = user;
	int leps;
		
	if (!(strcasecmp(askbuf, "1"))) {
		for (;;) {
			if (!isaccess(SECB_REALNAME, access2))
				break;
			DDPut(sd[eu1str]);
			strlcpy(lesbabuf, user.user_realname, sizeof lesbabuf);
			if (!(Prompt(lesbabuf, 25, 0)))
				return 1;
			removespaces(lesbabuf);
			if (strcasecmp(lesbabuf, user.user_realname)) {
				leps = findusername(lesbabuf);
				if (leps == user.user_account_id || leps == -1) {
					if (lesbabuf[0])
						strlcpy(user.user_realname, lesbabuf, sizeof user.user_realname);
				} else {
					DDPut(sd[newalreadystr]);
					continue;
				}
			}
			break;
		}
	} else if (!(strcasecmp(askbuf, "2"))) {
		for (;;) {
			if (!isaccess(SECB_HANDLE, access2))
				break;
			DDPut(sd[eu2str]);
			strlcpy(lesbabuf, user.user_handle, sizeof lesbabuf);
			if (!(Prompt(lesbabuf, 25, 0)))
				return 1;
			removespaces(lesbabuf);
			if (strcasecmp(lesbabuf, user.user_handle)) {
				leps = findusername(lesbabuf);
				if (leps == user.user_account_id || leps == -1) {
					if (lesbabuf[0])
						strlcpy(user.user_handle, lesbabuf, sizeof user.user_handle);
				} else {
					DDPut(sd[newalreadystr]);
					continue;
				}
			}
			break;
		}
	} else if (!(strcasecmp(askbuf, "3"))) {
		DDPut(sd[eu3str]);
		if (!(Prompt(user.user_organization, 25, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "4"))) {
		DDPut(sd[eu4str]);
		if (!(Prompt(user.user_zipcity, 20, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "5"))) {
		DDPut(sd[eu5str]);
		if (!(Prompt(user.user_voicephone, 20, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "6"))) {
		MD_CTX context;
		char verifypw[32];
		DDPut(sd[eu6str]);
		lesbabuf[0] = 0;
		if (!(Prompt(lesbabuf, 15, PROMPT_SECRET)))
			return 1;
		if (lesbabuf[0] == 0)
			return 0;
		*verifypw = 0;
		DDPut(sd[euverifypwstr]);
		if (!(Prompt(verifypw, 15, PROMPT_SECRET)))
			return 1;
		if (strcasecmp(lesbabuf, verifypw)) {
			DDPut(sd[eunomatchstr]);
			return 0;
		}
		strupr(lesbabuf);
		MDInit(&context);
		MDUpdate(&context, (unsigned char *) lesbabuf, 
			strlen(lesbabuf));
		MDFinal(user.user_password, &context);
	} else if (!strcasecmp(askbuf, "7")) {
		for (;;) {
			int fallos;
			
			DDPut(sd[eu7str]);
			lesbabuf[0] = 0;
			if (!(Prompt(lesbabuf, 3, 0)))
				return 1;
			if (lesbabuf[0] == 't' || lesbabuf[0] == 'T') {
				testscreenl();
				continue;
			}
			fallos = atoi(lesbabuf);
			if (fallos < 10) {
				DDPut(sd[newminslstr]);
				continue;
			}
			user.user_screenlength = fallos;
			break;
		}
	} else if (!(strcasecmp(askbuf, "8"))) {
		struct DayDream_Protocol *tp;

		TypeFile("protocols", TYPE_MAKE | TYPE_WARN);
		DDPut(sd[eu8str]);
		*lesbabuf = 0;
		if (user.user_protocol) {
			*lesbabuf = user.user_protocol;
			lesbabuf[1] = 0;
		}
		if (!(Prompt(lesbabuf, 3, 0)))
			return 1;
		*lesbabuf = toupper(*lesbabuf);
		if (!*lesbabuf)
			return 0;
		tp = protocols;
		for (;;) {
			if (tp->PROTOCOL_ID == 0)
				return 0;
			if (tp->PROTOCOL_ID == *lesbabuf) {
				protocol = tp;
				user.user_protocol = *lesbabuf;
				return 0;
			}
			tp++;
		}
	} else if (!(strcasecmp(askbuf, "9"))) {
		DDPut(sd[eu9str]);
		if (!(Prompt(user.user_signature, 44, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "10"))) {
		DDPut(sd[eu10str]);
		if (!(Prompt(user.user_computermodel, 20, 0)))
			return 1;
	} else if (!(strcasecmp(askbuf, "11"))) {
		DDPut(sd[eu11str]);
		snprintf(lesbabuf, sizeof lesbabuf, "%d", user.user_flines);
		if (!(Prompt(lesbabuf, 3, 0)))
			return 1;
		user.user_flines = atoi(lesbabuf);
        } else if (!(strcasecmp(askbuf, "12"))) {
		rundoor("doors/autosig %N", 0);
		return 1;
	} else if (!(strcasecmp(askbuf, "a"))) {
		DDPut(sd[euabortedstr]);
		user = muser;
		return 1;
	} else if (!(strcasecmp(askbuf, "v"))) {
		TypeFile("edituser", TYPE_MAKE | TYPE_WARN);
	} else if (!(strcasecmp(askbuf, "s"))) {
		switches();
	} else if ((!(strcasecmp(askbuf, "c")) || (askbuf[0] == 0))) {
		DDPut(sd[eusavedstr]);
		saveuserbase(&user);
		return 1;
	}
	return 0;
}