Exemplo n.º 1
0
int
send_request(Request req)
{
	if (! req->socket ) {
		req->socket = connect_socket(req->host,req->port,0);
		if (! req->socket) {
			error("Failed to connect to %s:%i\n",req->host,req->port);
			return 0;
		}
		add_req_socket(req->socket->fd);
		return 0;
	}
	if (req->length < 0) {
		str cmd = _("%s %s HTTP/1.1\r\n",req->method,req->path);
		write_socket(req->socket,cmd);
		request_headers(req,_("Host"),req->host);
		send_headers(req->socket,req->headers);
		req->length = outbound_content_length(req->contents,req->raw_contents);	
		return req->contents != NULL || req->raw_contents != NULL ;
	}
	req->written += req->contents ?
			send_contents(req->socket,req->contents,is_chunked(req->headers)) :
		req->raw_contents ?
			send_raw_contents(req->socket,req->raw_contents,req->written,0):
			0;
	if (is_chunked(req->headers) && req->written >= req->length)
		write_chunk(req->socket,NULL,0);
	return req->written < req->length;
}
Exemplo n.º 2
0
int
main (int argc, char **argv)
{
    unsigned char action = 0, console_flag = 3;
    int console_fd, vcsa_fd, console_minor, buffer_size;
    struct stat st;
    uid_t uid, euid;
    char *buffer, *tty_name, console_name[16], vcsa_name[16];
    const char *p, *q;
    struct winsize winsz;

    close (2);

    if (argc != 2)
        die ();

    tty_name = argv[1];
    if (strnlen (tty_name, 15) == 15 || strncmp (tty_name, "/dev/", 5))
        die ();

    setsid ();
    uid = getuid ();
    euid = geteuid ();

    if (seteuid (uid) < 0)
        die ();
    console_fd = open (tty_name, O_RDONLY);
    if (console_fd < 0)
        die ();
    if (fstat (console_fd, &st) < 0 || !S_ISCHR (st.st_mode))
        die ();
    if ((st.st_rdev & 0xff00) != 0x0400)
        die ();
    console_minor = (int) (st.st_rdev & 0x00ff);
    if (console_minor < 1 || console_minor > 63)
        die ();
    if (st.st_uid != uid)
        die ();

    switch (tty_name[5])
    {
        /* devfs */
    case 'v':
        p = "/dev/vc/%d";
        q = "/dev/vcc/a%d";
        break;
        /* /dev/ttyN */
    case 't':
        p = "/dev/tty%d";
        q = "/dev/vcsa%d";
        break;
    default:
        die ();
        break;
    }

    snprintf (console_name, sizeof (console_name), p, console_minor);
    if (strncmp (console_name, tty_name, sizeof (console_name)) != 0)
        die ();

    if (seteuid (euid) < 0)
        die ();

    snprintf (vcsa_name, sizeof (vcsa_name), q, console_minor);
    vcsa_fd = open (vcsa_name, O_RDWR);
    if (vcsa_fd < 0)
        die ();
    if (fstat (vcsa_fd, &st) < 0 || !S_ISCHR (st.st_mode))
        die ();

    if (seteuid (uid) < 0)
        die ();

    winsz.ws_col = winsz.ws_row = 0;
    if (ioctl (console_fd, TIOCGWINSZ, &winsz) < 0
        || winsz.ws_col <= 0 || winsz.ws_row <= 0 || winsz.ws_col >= 256 || winsz.ws_row >= 256)
        die ();

    buffer_size = 4 + 2 * winsz.ws_col * winsz.ws_row;
    buffer = calloc (buffer_size, 1);
    if (buffer == NULL)
        die ();

    if (write (1, &console_flag, 1) != 1)
        die ();

    while (console_flag && read (0, &action, 1) == 1)
    {
        switch (action)
        {
        case CONSOLE_DONE:
            console_flag = 0;
            continue;
        case CONSOLE_SAVE:
            if (seteuid (euid) < 0
                || lseek (vcsa_fd, 0, 0) != 0
                || fstat (console_fd, &st) < 0 || st.st_uid != uid
                || read (vcsa_fd, buffer, buffer_size) != buffer_size
                || fstat (console_fd, &st) < 0 || st.st_uid != uid)
                memset (buffer, 0, buffer_size);
            if (seteuid (uid) < 0)
                die ();
            break;
        case CONSOLE_RESTORE:
            if (seteuid (euid) >= 0
                && lseek (vcsa_fd, 0, 0) == 0 && fstat (console_fd, &st) >= 0 && st.st_uid == uid)
                if (write (vcsa_fd, buffer, buffer_size) != buffer_size)
                    die ();
            if (seteuid (uid) < 0)
                die ();
            break;
        case CONSOLE_CONTENTS:
            send_contents (buffer + 4, winsz.ws_col, winsz.ws_row);
            break;
        }

        if (write (1, &console_flag, 1) != 1)
            die ();
    }

    exit (0);
}
Exemplo n.º 3
0
Arquivo: wiz.c Projeto: hyena/fuzzball
void
do_toad(int descr, dbref player, const char *name, const char *recip)
{
	dbref victim;
	dbref recipient;
	dbref stuff;
	char buf[BUFFER_LEN];

	if (!Wizard(player) || Typeof(player) != TYPE_PLAYER) {
		notify(player, "Only a Wizard player can turn a person into a toad.");
		return;
	}
	if ((victim = lookup_player(name)) == NOTHING) {
		notify(player, "That player does not exist.");
		return;
	}
#ifdef GOD_PRIV
	if (God(victim)) {
		notify(player, "You cannot @toad God.");
		if(!God(player)) {
			log_status("TOAD ATTEMPT: %s(#%d) tried to toad God.",NAME(player),player);
		}
		return;
	}
#endif
	if(player == victim) {
		/* If GOD_PRIV isn't defined, this could happen: we don't want the
		 * last wizard to be toaded, in any case, so only someone else can
		 * do it. */
		notify(player, "You cannot toad yourself.  Get someone else to do it for you.");
		return;
	}

	if (victim == tp_toad_default_recipient) {
		notify(player, "That player is part of the @toad process, and cannot be deleted.");
		return;
	}

	if (!*recip) {
		recipient = tp_toad_default_recipient;
	} else {
		if ((recipient = lookup_player(recip)) == NOTHING || recipient == victim) {
			notify(player, "That recipient does not exist.");
			return;
		}
	}

	if (Typeof(victim) != TYPE_PLAYER) {
		notify(player, "You can only turn players into toads!");
#ifdef GOD_PRIV
	} else if (!(God(player)) && (TrueWizard(victim))) {
#else
	} else if (TrueWizard(victim)) {
#endif
		notify(player, "You can't turn a Wizard into a toad.");
	} else {
		/* we're ok */
		/* do it */
		send_contents(descr, victim, HOME);
		dequeue_prog(victim, 0);  /* Dequeue the programs that the player's running */
		for (stuff = 0; stuff < db_top; stuff++) {
			if (OWNER(stuff) == victim) {
				switch (Typeof(stuff)) {
				case TYPE_PROGRAM:
					dequeue_prog(stuff, 0);	/* dequeue player's progs */
					if (TrueWizard(recipient)) {
						FLAGS(stuff) &= ~(ABODE | WIZARD);
						SetMLevel(stuff, 1);
					}
				case TYPE_ROOM:
				case TYPE_THING:
				case TYPE_EXIT:
					OWNER(stuff) = recipient;
					DBDIRTY(stuff);
					break;
				}
			}
			if (Typeof(stuff) == TYPE_THING && THING_HOME(stuff) == victim) {
				THING_SET_HOME(stuff, tp_lost_and_found);
			}
		}

		chown_macros(victim, recipient);

		if (PLAYER_PASSWORD(victim)) {
			free((void *) PLAYER_PASSWORD(victim));
			PLAYER_SET_PASSWORD(victim, 0);
		}

		/* notify people */
		notify(victim, "You have been turned into a toad.");
		snprintf(buf, sizeof(buf), "You turned %s into a toad!", NAME(victim));
		notify(player, buf);
		log_status("TOADED: %s(%d) by %s(%d)", NAME(victim), victim, NAME(player), player);
		/* reset name */
		delete_player(victim);
		snprintf(buf, sizeof(buf), "A slimy toad named %s", NAME(victim));
		free((void *) NAME(victim));
		NAME(victim) = alloc_string(buf);
		DBDIRTY(victim);

		boot_player_off(victim); /* Disconnect the toad */

		if (PLAYER_DESCRS(victim)) {
			free(PLAYER_DESCRS(victim));
			PLAYER_SET_DESCRS(victim, NULL);
			PLAYER_SET_DESCRCOUNT(victim, 0);
		}

		ignore_remove_from_all_players(victim);
		ignore_flush_cache(victim);

		FREE_PLAYER_SP(victim);
		ALLOC_THING_SP(victim);
		THING_SET_HOME(victim, PLAYER_HOME(player));

		FLAGS(victim) = TYPE_THING;
		OWNER(victim) = player;	/* you get it */
		SETVALUE(victim, 1);	/* don't let him keep his immense wealth */
	}
}