Пример #1
0
void l4dtoolz::OnChangeMaxplayers ( IConVar *var, const char *pOldValue, float flOldValue )
{
	int new_value = ((ConVar*)var)->GetInt();
	int old_value = atoi(pOldValue);
	if (max_players_friend_lobby == NULL || max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
		Msg("sv_maxplayers init error\n");
		return;
	}
	if(new_value != old_value) {
		if(new_value >= 0) {
			max_players_new[4] = friends_lobby_new[3] = server_bplayers_new[3] = new_value;
			if(lobby_match_ptr) {
				lobby_match_new[2] = new_value;
				write_signature(lobby_match_ptr, lobby_match_new);
			} else {
				Msg("sv_maxplayers MS init error\n");
			}
			write_signature(max_players_friend_lobby, friends_lobby_new);
			write_signature(max_players_connect, max_players_new);
			write_signature(lobby_sux_ptr, lobby_sux_new);
			write_signature(max_players_server_browser, server_bplayers_new);
		} else {
			write_signature(max_players_friend_lobby, friends_lobby_org);
			write_signature(max_players_connect, max_players_org);
			write_signature(lobby_sux_ptr, lobby_sux_org);
			write_signature(max_players_server_browser, server_bplayers_org);
		
			if(lobby_match_ptr)
				write_signature(lobby_match_ptr, lobby_match_org);
		}
	}
}
Пример #2
0
void l4dtoolz::OnChangeIvailosp ( IConVar *var, const char *pOldValue, float flOldValue )
{
	if(tmp_player == NULL || tmp_player2 == NULL) {
		return;
	}
	write_signature(tmp_player, players_org);
	free(players_org);
	players_org = NULL;
	write_signature(tmp_player2, players_org2);
	free(players_org2);
	players_org2 = NULL;
}
Пример #3
0
void l4dtoolz::OnChangeRemovehumanlimit ( IConVar *var, const char *pOldValue, float flOldValue )
{
	int new_value = ((ConVar*)var)->GetInt();
	int old_value = atoi(pOldValue);
	if(chuman_limit == NULL) {
		Msg( "sv_removehumanlimit init error\n");
		return;
	}
	if(new_value != old_value) {
		if(new_value == 1) {
			write_signature(chuman_limit, human_limit_new);
		}else{
			write_signature(chuman_limit, human_limit_org);
		}
	}
}
Пример #4
0
void Manifold::write(const char* filename) const {
	ofstream f;

	f.open(filename, ios::out | ios::binary);

	if (f.fail())
		ibex_error("[manifold]: cannot create output file.\n");

	write_signature(f);
	write_int(f,n);
	write_int(f,m);
	write_int(f,nb_ineq);
	write_int(f,status);
	write_int(f,inner.size());
	write_int(f,boundary.size());
	write_int(f,unknown.size());
	write_int(f,pending.size());
	write_double(f,time);
	write_int(f,nb_cells);

	for (vector<SolverOutputBox>::const_iterator it=inner.begin(); it!=inner.end(); it++)
		write_output_box(f,*it);

	for (vector<SolverOutputBox>::const_iterator it=boundary.begin(); it!=boundary.end(); it++)
		write_output_box(f,*it);

	for (vector<SolverOutputBox>::const_iterator it=unknown.begin(); it!=unknown.end(); it++)
		write_output_box(f,*it);

	for (vector<SolverOutputBox>::const_iterator it=pending.begin(); it!=pending.end(); it++)
		write_output_box(f,*it);

	f.close();
}
Пример #5
0
void l4dtoolz::OnChangeUnreserved ( IConVar *var, const char *pOldValue, float flOldValue )
{
	int new_value = ((ConVar*)var)->GetInt();
	int old_value = atoi(pOldValue);
	if(unreserved_ptr == NULL ) {
		Msg("unreserved_ptr init error\n");
		return;
	}
	if(new_value != old_value) {
		if(new_value == 1) {
			write_signature(unreserved_ptr, unreserved_new);
			engine->ServerCommand("sv_allow_lobby_connect_only 0\n");
		} else {
			write_signature(unreserved_ptr, unreserved_org);
		}
	}
}
Пример #6
0
static int build_image(image_info_t* im)
{
	char* mem;
	char* ptr;
	u_int32_t mem_size;
	FILE* f;
	int i;

	// build in-memory buffer
	mem_size = sizeof(header_t) + sizeof(signature_t);
	for (i = 0; i < im->part_count; ++i)
	{
		part_data_t* d = &im->parts[i];
		mem_size += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t);
	}

	mem = (char*)calloc(mem_size, 1);
	if (mem == NULL)
	{
		ERROR("Cannot allocate memory chunk of size '%u'\n", mem_size);
		return -1;
	}

	// write header
	write_header(mem, im->version);
	ptr = mem + sizeof(header_t);
	// write all parts
	for (i = 0; i < im->part_count; ++i)
	{
		part_data_t* d = &im->parts[i];
		int rc;
		if ((rc = write_part(ptr, d)) != 0)
		{
			ERROR("ERROR: failed writing part %u '%s'\n", i, d->partition_name);
		}
		ptr += sizeof(part_t) + d->stats.st_size + sizeof(part_crc_t);
	}
	// write signature
	write_signature(mem, mem_size - sizeof(signature_t));

	// write in-memory buffer into file
	if ((f = fopen(im->outputfile, "w")) == NULL)
	{
		ERROR("Can not create output file: '%s'\n", im->outputfile);
		return -10;
	}

	if (fwrite(mem, mem_size, 1, f) != 1)
	{
		ERROR("Could not write %d bytes into file: '%s'\n", 
				mem_size, im->outputfile);
		return -11;
	}

	free(mem);
	fclose(f);
	return 0;
}
Пример #7
0
bool l4dtoolz::Unload(char *error, size_t maxlen)
{

#if !defined METAMOD_PLAPI_VERSION
	SH_RELEASE_CALLCLASS(m_EngineCC);
#endif

#ifdef L4D1
	write_signature(max_players_friend_lobby, friends_lobby_org);
	write_signature(chuman_limit, human_limit_org);
	free(friends_lobby_org);
	free(human_limit_org);
#endif

	write_signature(max_players_connect, max_players_org);
	write_signature(lobby_sux_ptr, lobby_sux_org);
	write_signature(max_players_server_browser, server_bplayers_org);
	write_signature(unreserved_ptr, unreserved_org);
	write_signature(lobby_match_ptr, lobby_match_org);

	free(max_players_org);
	free(lobby_sux_org);
	free(server_bplayers_org);
	free(unreserved_org);
	free(lobby_match_org);

	return true;
}
Пример #8
0
/**
 * cdk_pkt_write:
 * @out: the output stream handle
 * @pkt: the packet itself
 *
 * Write the contents of @pkt into the @out stream.
 * Return 0 on success.
 **/
cdk_error_t
cdk_pkt_write (cdk_stream_t out, cdk_packet_t pkt)
{
  cdk_error_t rc;

  if (!out || !pkt)
    return CDK_Inv_Value;

  _cdk_log_debug ("write packet pkttype=%d\n", pkt->pkttype);
  switch (pkt->pkttype)
    {
    case CDK_PKT_LITERAL:
      rc = write_literal (out, pkt->pkt.literal, pkt->old_ctb);
      break;
    case CDK_PKT_ONEPASS_SIG:
      rc = write_onepass_sig (out, pkt->pkt.onepass_sig);
      break;
    case CDK_PKT_MDC:
      rc = write_mdc (out, pkt->pkt.mdc);
      break;
    case CDK_PKT_PUBKEY_ENC:
      rc = write_pubkey_enc (out, pkt->pkt.pubkey_enc, pkt->old_ctb);
      break;
    case CDK_PKT_SIGNATURE:
      rc = write_signature (out, pkt->pkt.signature, pkt->old_ctb);
      break;
    case CDK_PKT_PUBLIC_KEY:
      rc = write_public_key (out, pkt->pkt.public_key, 0, pkt->old_ctb);
      break;
    case CDK_PKT_PUBLIC_SUBKEY:
      rc = write_public_key (out, pkt->pkt.public_key, 1, pkt->old_ctb);
      break;
    case CDK_PKT_COMPRESSED:
      rc = write_compressed (out, pkt->pkt.compressed);
      break;
    case CDK_PKT_SECRET_KEY:
      rc = write_secret_key (out, pkt->pkt.secret_key, 0, pkt->old_ctb);
      break;
    case CDK_PKT_SECRET_SUBKEY:
      rc = write_secret_key (out, pkt->pkt.secret_key, 1, pkt->old_ctb);
      break;
    case CDK_PKT_USER_ID:
    case CDK_PKT_ATTRIBUTE:
      rc = write_user_id (out, pkt->pkt.user_id, pkt->old_ctb, pkt->pkttype);
      break;
    default:
      rc = CDK_Inv_Packet;
      break;
    }

  if (DEBUG_PKT)
    _cdk_log_debug ("write_packet rc=%d pkttype=%d\n", rc, pkt->pkttype);
  return rc;
}
Пример #9
0
void l4dtoolz::OnChangeMaxplayers ( IConVar *var, const char *pOldValue, float flOldValue )
{
	int new_value = ((ConVar*)var)->GetInt();
	int old_value = atoi(pOldValue);
	if (max_players_friend_lobby == NULL || max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
		Msg("sv_maxplayers init error\n");
		return;
	}
	if(new_value != old_value) {
		ConVar *sv_visiblemaxplayers = g_pCVar->FindVar("sv_visiblemaxplayers");
		sv_visiblemaxplayers->SetValue(new_value);
		
		if(new_value > 8) {
			sv_removehumanlimit.SetValue(true);
		}
		
		if(new_value >= 0) {
			sv_force_unreserved.SetValue(true);

			max_players_new[4] = friends_lobby_new[3] = server_bplayers_new[3] = new_value;
			if(lobby_match_ptr) {
				lobby_match_new[2] = new_value;
				write_signature(lobby_match_ptr, lobby_match_new);
			} else {
				Msg("sv_maxplayers MS init error\n");
			}
			write_signature(max_players_friend_lobby, friends_lobby_new);
			write_signature(max_players_connect, max_players_new);
			write_signature(lobby_sux_ptr, lobby_sux_new);
			write_signature(max_players_server_browser, server_bplayers_new);
		} else {
			write_signature(max_players_friend_lobby, friends_lobby_org);
			write_signature(max_players_connect, max_players_org);
			write_signature(lobby_sux_ptr, lobby_sux_org);
			write_signature(max_players_server_browser, server_bplayers_org);
		
			if(lobby_match_ptr)
				write_signature(lobby_match_ptr, lobby_match_org);
		}
	}
}
Пример #10
0
/*

=item C<static char *
get_signatured_opname(instruction * const instr)>

Returns the full opname of the instruction C<name>; the signature
of the opname is based on the operands, some examples are shown
below:

 set I0, 10        --> set_i_ic
 print "hi"        --> print_sc
 set P0[1], 3.14   --> set_p_kic_nc

For each operand, an underscore is added; then for the types
int, num, string or pmc, an 'i', 'n', 's' or 'p' is added
respectively. If the operand is a constant, a 'c' suffic is added.

If the operand is a key of something, a 'k' prefix is added.

=cut

*/
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
static char *
get_signatured_opname(NOTNULL(lexer_state * const lexer), NOTNULL(instruction * const instr)) {
    size_t      fullname_length;
    char       *fullname;
    char       *instr_writer;
    expression *iter         = instr->operands;
    unsigned    num_operands = 0;

    /* get length of short opname (and add 1 for the NULL character) */
    fullname_length = strlen(instr->opname) + 1;

    /* for each operand, calculate the length of the signature (for that op.)
     * and add it to the full length.
     */
    if (iter) {
        iter = iter->next;
        do {
            int keylength    = get_signature_length(iter);
            fullname_length += keylength;
            iter             = iter->next;
            ++num_operands;
        }
        while (iter != instr->operands->next);
    }

    /* now we know how long the fullname will be, allocate enough memory. */
    fullname = (char *)pir_mem_allocate_zeroed(lexer, fullname_length * sizeof (char));

    /* copy the short name into fullname buffer, and set instr_writer to
     * the character after that.
     */
    strcpy(fullname, instr->opname);
    instr_writer = fullname + strlen(instr->opname);

    /* now iterate again over all operands, and codify them into the fullname.
     * As we counted the number of operands, this loop can be written a bit simpler.
     */
    iter = instr->operands;
    while (num_operands-- > 0) {
        iter            = iter->next;
        *instr_writer++ = '_'; /* separate each operand code by a '_' */
        instr_writer    = write_signature(iter, instr_writer);
    }

    return fullname;
}
Пример #11
0
static int write_assmodes( Externalclosure closure,
                           FILE *outfile, 
                           char *language,
                           int pkd )
{  Transformer *nulltprocs = MakeNullTransformer( objtable, objtable);
   char *signature = GetSignature( language);

   assem_outfile = outfile;
   if( signature != NULL )
   {  Assemwriter *assemwriter = 
                      write_signature( unpacked_put, pkd, pkd, signature);
      if( assemwriter != NULL )
      {  write_closure(closure, assemwriter, nulltprocs);
      }
      free( assemwriter );
      return( 0 );
   }
   else
   {  printf( "Language %s not known\n", language );
      return( 1 );
   }
}
Пример #12
0
int
main(int argc, char ** argv) {
	struct stat statbuf;
	struct swap_header_v1_2 *hdr;
	int i;
	unsigned long long maxpages;
	unsigned long long goodpages;
	unsigned long long sz;
	off_t offset;
	int force = 0;
	int version = 1;
	char *block_count = 0;
	char *pp;
	char *opt_label = NULL;
	unsigned char *uuid = NULL;
#ifdef HAVE_LIBUUID
	const char *opt_uuid = NULL;
	uuid_t uuid_dat;
#endif

	program_name = (argc && *argv) ? argv[0] : "mkswap";
	if ((pp = strrchr(program_name, '/')) != NULL)
		program_name = pp+1;

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	if (argc == 2 &&
	    (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
		printf(_("%s (%s)\n"), program_name, PACKAGE_STRING);
		exit(0);
	}

	for (i=1; i<argc; i++) {
		if (argv[i][0] == '-') {
			switch (argv[i][1]) {
				case 'c':
					check=1;
					break;
				case 'f':
					force=1;
					break;
				case 'p':
					pp = argv[i]+2;
					if (!*pp && i+1 < argc)
						pp = argv[++i];
					if (isnzdigit(*pp))
						user_pagesize = atoi(pp);
					else
						usage();
					break;
			        case 'L':
					pp = argv[i]+2;
					if (!*pp && i+1 < argc)
						pp = argv[++i];
					opt_label = pp;
				        break;
				case 'v':
					version = atoi(argv[i]+2);
					break;
				case 'U':
#ifdef HAVE_LIBUUID
					opt_uuid = argv[i]+2;
					if (!*opt_uuid && i+1 < argc)
						opt_uuid = argv[++i];
#else
					fprintf(stderr, _("%1$s: warning: ignore -U (UUIDs are unsupported by %1$s)\n"),
						program_name);
#endif
					break;
				default:
					usage();
			}
		} else if (!device_name) {
			device_name = argv[i];
		} else if (!block_count) {
			block_count = argv[i];
		} else
			usage();
	}

	if (version != 1) {
		fprintf(stderr, _("%s: does not support swapspace version %d.\n"),
			program_name, version);
		exit(EXIT_FAILURE);
	}

#ifdef HAVE_LIBUUID
	if(opt_uuid) {
		if (uuid_parse(opt_uuid, uuid_dat) != 0)
			die(_("error: UUID parsing failed"));
	} else
		uuid_generate(uuid_dat);
	uuid = uuid_dat;
#endif

	init_signature_page();	/* get pagesize */
	atexit(deinit_signature_page);

	if (!device_name) {
		fprintf(stderr,
			_("%s: error: Nowhere to set up swap on?\n"),
			program_name);
		usage();
	}
	if (block_count) {
		/* this silly user specified the number of blocks explicitly */
		char *tmp = NULL;
		long long blks;

		errno = 0;
		blks = strtoll(block_count, &tmp, 0);
		if ((tmp == block_count) ||
		    (tmp && *tmp) ||
		    (errno != 0 && (blks == LLONG_MAX || blks == LLONG_MIN)) ||
		    blks < 0)
			usage();

		PAGES = blks / (pagesize / 1024);
	}
	sz = get_size(device_name);
	if (!PAGES) {
		PAGES = sz;
	} else if (PAGES > sz && !force) {
		fprintf(stderr,
			_("%s: error: "
			  "size %llu KiB is larger than device size %llu KiB\n"),
			program_name,
			PAGES*(pagesize/1024), sz*(pagesize/1024));
		exit(1);
	}

	if (PAGES < MIN_GOODPAGES) {
		fprintf(stderr,
			_("%s: error: swap area needs to be at least %ld KiB\n"),
			program_name, (long)(MIN_GOODPAGES * pagesize/1024));
		usage();
	}

#ifdef __linux__
	if (get_linux_version() >= KERNEL_VERSION(2,3,4))
		maxpages = UINT_MAX + 1ULL;
	else if (get_linux_version() >= KERNEL_VERSION(2,2,1))
		maxpages = V1_MAX_PAGES;
	else
#endif
		maxpages = V1_OLD_MAX_PAGES;

	if (PAGES > maxpages) {
		PAGES = maxpages;
		fprintf(stderr,
			_("%s: warning: truncating swap area to %llu KiB\n"),
			program_name, PAGES * pagesize / 1024);
	}

	if (stat(device_name, &statbuf) < 0) {
		perror(device_name);
		exit(EXIT_FAILURE);
	}
	if (S_ISBLK(statbuf.st_mode))
		DEV = open(device_name, O_RDWR | O_EXCL);
	else
		DEV = open(device_name, O_RDWR);

	if (DEV < 0) {
		perror(device_name);
		exit(1);
	}

	/* Want a block device. Probably not /dev/hda or /dev/hdb. */
	if (!S_ISBLK(statbuf.st_mode))
		check=0;
	else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340) {
		fprintf(stderr,
			_("%s: error: "
			  "will not try to make swapdevice on '%s'\n"),
			program_name, device_name);
		exit(1);
	} else if (check_mount()) {
		fprintf(stderr,
			_("%s: error: "
			  "%s is mounted; will not make swapspace.\n"),
			program_name, device_name);
		exit(1);
	}

	if (check)
		check_blocks();

	zap_bootbits(DEV, device_name, force, S_ISBLK(statbuf.st_mode));

	hdr = (struct swap_header_v1_2 *) signature_page;
	hdr->version = 1;
	hdr->last_page = PAGES - 1;
	hdr->nr_badpages = badpages;

	if (badpages > PAGES - MIN_GOODPAGES)
		die(_("Unable to set up swap-space: unreadable"));

	goodpages = PAGES - badpages - 1;
	printf(_("Setting up swapspace version 1, size = %llu KiB\n"),
		goodpages * pagesize / 1024);

	write_signature("SWAPSPACE2");
	write_uuid_and_label(uuid, opt_label);

	offset = 1024;
	if (lseek(DEV, offset, SEEK_SET) != offset)
		die(_("unable to rewind swap-device"));
	if (write_all(DEV, (char *) signature_page + offset,
				    pagesize - offset) == -1) {
		fprintf(stderr, _("%s: %s: unable to write signature page: %s"),
			program_name, device_name, strerror(errno));
		exit(1);
	}

	/*
	 * A subsequent swapon() will fail if the signature
	 * is not actually on disk. (This is a kernel bug.)
	 */
#ifdef HAVE_FSYNC
	if (fsync(DEV))
		 die(_("fsync failed"));
#endif

#ifdef HAVE_LIBSELINUX
	if (S_ISREG(statbuf.st_mode) && is_selinux_enabled() > 0) {
		security_context_t context_string;
		security_context_t oldcontext;
		context_t newcontext;

		if (fgetfilecon(DEV, &oldcontext) < 0) {
			if (errno != ENODATA) {
				fprintf(stderr, _("%s: %s: unable to obtain selinux file label: %s\n"),
						program_name, device_name,
						strerror(errno));
				exit(1);
			}
			if (matchpathcon(device_name, statbuf.st_mode, &oldcontext))
				die(_("unable to matchpathcon()"));
		}
		if (!(newcontext = context_new(oldcontext)))
			die(_("unable to create new selinux context"));
		if (context_type_set(newcontext, SELINUX_SWAPFILE_TYPE))
			die(_("couldn't compute selinux context"));

		context_string = context_str(newcontext);

		if (strcmp(context_string, oldcontext)!=0) {
			if (fsetfilecon(DEV, context_string)) {
				fprintf(stderr, _("%s: unable to relabel %s to %s: %s\n"),
						program_name, device_name,
						context_string,
						strerror(errno));
				exit(1);
			}
		}
		context_free(newcontext);
		freecon(oldcontext);
	}
#endif
	return 0;
}
Пример #13
0
/*

=item C<static char *
write_signature(expression * const iter, char *instr_writer)>

Write the signature for the operand C<iter>, using the character
pointer C<instr_writer>. When the operand is an indexed target node
(in other words, it has a key node), this function is invoked recursively
passing the key as an argument.

This function returns the updated character pointer (due to pass-by-value
semantics of the C calling conventions).

=cut

*/
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
static char *
write_signature(NOTNULL(expression * const iter), NOTNULL(char *instr_writer)) {
    switch (iter->type) {
        case EXPR_TARGET:
            *instr_writer++ = type_codes[iter->expr.t->info->type];

            if (iter->expr.t->key) {
                *instr_writer++ = '_';
                *instr_writer++ = 'k';

                switch (iter->expr.t->key->head->expr->type) {
                    case EXPR_TARGET:
                        switch (iter->expr.t->key->head->expr->expr.t->info->type) {
                            case PMC_TYPE:
                                /* the key is a target, and its type is a PMC. In that
                                 * case, do not print the signature; 'kp' is not valid.
                                 */
                                break;
                            case STRING_TYPE: /* strings become key-constant */
                                *instr_writer++ = 'c';
                                break;
                            case INT_TYPE:
                                *instr_writer++ = 'i';
                                break;
                            default:
                                break;
                        }
                        break;
                    case EXPR_CONSTANT:
                        /* integer constant key results in '_kic' signature */
                        if (iter->expr.c->type == INT_VAL)
                            *instr_writer++ = 'i';

                        *instr_writer++ = 'c';
                        break;
                    default:
                        /* XXX does this ever happen? */
                        fprintf(stderr, "write_signature: non-constant key\n");
                        instr_writer = write_signature(iter->expr.t->key->head->expr, instr_writer);
                        break;
                }

            }
            break;
        case EXPR_CONSTANT:
            *instr_writer++ = type_codes[iter->expr.c->type];
            *instr_writer++ = 'c';
            break;
        case EXPR_IDENT: /* used for labels; these will be converted to (i)nteger (c)onstants*/
            *instr_writer++ = 'i';
            *instr_writer++ = 'c';
            break;
        case EXPR_KEY:
            *instr_writer++ = 'k';

            instr_writer    = write_signature(iter->expr.k->head->expr, instr_writer);
            /*

            switch (iter->expr.k->expr->type) {
                case EXPR_CONSTANT:
                   *instr_writer++ = 'c';
                   break;
                default:
                    fprintf(stderr, "write_signature: non-constant key\n");
                    instr_writer = write_signature(iter->expr.k->expr, instr_writer);
                    break;
            }
            */

            break;
        default:
            fprintf(stderr, "wrong expression type in write_signature()\n");
            break;
    }
    return instr_writer;
}
Пример #14
0
int
main(int argc, char **argv) {
	struct stat statbuf;
	struct swap_header_v1_2 *hdr;
	int c;
	unsigned long long maxpages;
	unsigned long long goodpages;
	unsigned long long sz;
	off_t offset;
	int force = 0;
	int version = 1;
	char *block_count = 0;
	char *opt_label = NULL;
	unsigned char *uuid = NULL;
#ifdef HAVE_LIBUUID
	const char *opt_uuid = NULL;
	uuid_t uuid_dat;
#endif
	static const struct option longopts[] = {
		{ "check",       no_argument,       0, 'c' },
		{ "force",       no_argument,       0, 'f' },
		{ "pagesize",    required_argument, 0, 'p' },
		{ "label",       required_argument, 0, 'L' },
		{ "swapversion", required_argument, 0, 'v' },
		{ "uuid",        required_argument, 0, 'U' },
		{ "version",     no_argument,       0, 'V' },
		{ "help",        no_argument,       0, 'h' },
		{ NULL,          0, 0, 0 }
	};

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	while((c = getopt_long(argc, argv, "cfp:L:v:U:Vh", longopts, NULL)) != -1) {
		switch (c) {
		case 'c':
			check=1;
			break;
		case 'f':
			force=1;
			break;
		case 'p':
			user_pagesize = strtou32_or_err(optarg, _("parsing page size failed"));
			break;
		case 'L':
			opt_label = optarg;
			break;
		case 'v':
			version = strtos32_or_err(optarg, _("parsing version number failed"));
			break;
		case 'U':
#ifdef HAVE_LIBUUID
			opt_uuid = optarg;
#else
			warnx(_("warning: ignoring -U (UUIDs are unsupported by %s)"),
				program_invocation_short_name);
#endif
			break;
		case 'V':
			printf(UTIL_LINUX_VERSION);
			exit(EXIT_SUCCESS);
		case 'h':
			usage(stdout);
		default:
			usage(stderr);
		}
	}
	if (optind < argc)
		device_name = argv[optind++];
	if (optind < argc)
		block_count = argv[optind++];
	if (optind != argc) {
		warnx(_("only one device argument is currently supported"));
		usage(stderr);
	}

	if (version != 1)
		errx(EXIT_FAILURE,
			_("swapspace version %d is not supported"), version);

#ifdef HAVE_LIBUUID
	if(opt_uuid) {
		if (uuid_parse(opt_uuid, uuid_dat) != 0)
			errx(EXIT_FAILURE, _("error: parsing UUID failed"));
	} else
		uuid_generate(uuid_dat);
	uuid = uuid_dat;
#endif

	init_signature_page();	/* get pagesize */

	if (!device_name) {
		warnx(_("error: Nowhere to set up swap on?"));
		usage(stderr);
	}
	if (block_count) {
		/* this silly user specified the number of blocks explicitly */
		uint64_t blks = strtou64_or_err(block_count,
					_("invalid block count argument"));
		PAGES = blks / (pagesize / 1024);
	}
	sz = get_size(device_name);
	if (!PAGES)
		PAGES = sz;
	else if (PAGES > sz && !force) {
		errx(EXIT_FAILURE,
			_("error: "
			  "size %llu KiB is larger than device size %llu KiB"),
			PAGES*(pagesize/1024), sz*(pagesize/1024));
	}

	if (PAGES < MIN_GOODPAGES) {
		warnx(_("error: swap area needs to be at least %ld KiB"),
			(long)(MIN_GOODPAGES * pagesize/1024));
		usage(stderr);
	}

#ifdef __linux__
	if (get_linux_version() >= KERNEL_VERSION(2,3,4))
		maxpages = UINT_MAX + 1ULL;
	else if (get_linux_version() >= KERNEL_VERSION(2,2,1))
		maxpages = V1_MAX_PAGES;
	else
#endif
		maxpages = V1_OLD_MAX_PAGES;

	if (PAGES > maxpages) {
		PAGES = maxpages;
		warnx(_("warning: truncating swap area to %llu KiB"),
			PAGES * pagesize / 1024);
	}

	if (is_mounted(device_name))
		errx(EXIT_FAILURE, _("error: "
			"%s is mounted; will not make swapspace"),
			device_name);

	if (stat(device_name, &statbuf) < 0) {
		perror(device_name);
		exit(EXIT_FAILURE);
	}
	if (S_ISBLK(statbuf.st_mode))
		DEV = open(device_name, O_RDWR | O_EXCL);
	else
		DEV = open(device_name, O_RDWR);

	if (DEV < 0) {
		perror(device_name);
		exit(EXIT_FAILURE);
	}

	if (!S_ISBLK(statbuf.st_mode))
		check=0;
	else if (blkdev_is_misaligned(DEV))
		warnx(_("warning: %s is misaligned"), device_name);

	if (check)
		check_blocks();

	wipe_device(DEV, device_name, force);

	hdr = (struct swap_header_v1_2 *) signature_page;
	hdr->version = 1;
	hdr->last_page = PAGES - 1;
	hdr->nr_badpages = badpages;

	if (badpages > PAGES - MIN_GOODPAGES)
		errx(EXIT_FAILURE, _("Unable to set up swap-space: unreadable"));

	goodpages = PAGES - badpages - 1;
	printf(_("Setting up swapspace version 1, size = %llu KiB\n"),
		goodpages * pagesize / 1024);

	write_signature("SWAPSPACE2");
	write_uuid_and_label(uuid, opt_label);

	offset = 1024;
	if (lseek(DEV, offset, SEEK_SET) != offset)
		errx(EXIT_FAILURE, _("unable to rewind swap-device"));
	if (write_all(DEV, (char *) signature_page + offset,
				    pagesize - offset) == -1)
		err(EXIT_FAILURE,
			_("%s: unable to write signature page"),
			device_name);

#ifdef HAVE_LIBSELINUX
	if (S_ISREG(statbuf.st_mode) && is_selinux_enabled() > 0) {
		security_context_t context_string;
		security_context_t oldcontext;
		context_t newcontext;

		if (fgetfilecon(DEV, &oldcontext) < 0) {
			if (errno != ENODATA)
				err(EXIT_FAILURE,
					_("%s: unable to obtain selinux file label"),
					device_name);
			if (matchpathcon(device_name, statbuf.st_mode, &oldcontext))
				errx(EXIT_FAILURE, _("unable to matchpathcon()"));
		}
		if (!(newcontext = context_new(oldcontext)))
			errx(EXIT_FAILURE, _("unable to create new selinux context"));
		if (context_type_set(newcontext, SELINUX_SWAPFILE_TYPE))
			errx(EXIT_FAILURE, _("couldn't compute selinux context"));

		context_string = context_str(newcontext);

		if (strcmp(context_string, oldcontext)!=0) {
			if (fsetfilecon(DEV, context_string))
				err(EXIT_FAILURE, _("unable to relabel %s to %s"),
						device_name, context_string);
		}
		context_free(newcontext);
		freecon(oldcontext);
	}
#endif
	/*
	 * A subsequent swapon() will fail if the signature
	 * is not actually on disk. (This is a kernel bug.)
	 * The fsync() in close_fd() will take care of writing.
	 */
	if (close_fd(DEV) != 0)
		err(EXIT_FAILURE, _("write failed"));
	return EXIT_SUCCESS;
}
Пример #15
0
int mkswap_main(int argc, char **argv)
{
	char *tmp;
	struct stat statbuf;
	int sz;
	int maxpages;
	int goodpages;
	int offset;
	int force = 0;

	init_signature_page();		/* get pagesize */

	while (argc-- > 1) {
		argv++;
		if (argv[0][0] != '-') {
			if (device_name) {
				int blocks_per_page = pagesize / 1024;

				PAGES = strtol(argv[0], &tmp, 0) / blocks_per_page;
				if (*tmp)
					bb_show_usage();
			} else
				device_name = argv[0];
		} else {
			switch (argv[0][1]) {
			case 'c':
				check = 1;
				break;
			case 'f':
				force = 1;
				break;
			case 'v':
				version = atoi(argv[0] + 2);
				break;
			default:
				bb_show_usage();
			}
		}
	}
	if (!device_name) {
		bb_error_msg("error: Nowhere to set up swap on?");
		bb_show_usage();
	}
	sz = get_size(device_name);
	if (!PAGES) {
		PAGES = sz;
	} else if (PAGES > sz && !force) {
		bb_error_msg("error: size %ld is larger than device size %d",
				PAGES * (pagesize / 1024), sz * (pagesize / 1024));
		return EXIT_FAILURE;
	}

	if (version == -1) {
		if (PAGES <= V0_MAX_PAGES)
			version = 0;
		else if (get_kernel_revision() < MAKE_VERSION(2, 1, 117))
			version = 0;
		else if (pagesize < 2048)
			version = 0;
		else
			version = 1;
	}
	if (version != 0 && version != 1) {
		bb_error_msg("error: unknown version %d", version);
		bb_show_usage();
	}
	if (PAGES < 10) {
		bb_error_msg("error: swap area needs to be at least %ldkB",
				(long) (10 * pagesize / 1024));
		bb_show_usage();
	}
#if 0
	maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES);
#else
	if (!version)
		maxpages = V0_MAX_PAGES;
	else if (get_kernel_revision() >= MAKE_VERSION(2, 2, 1))
		maxpages = V1_MAX_PAGES;
	else {
		maxpages = V1_OLD_MAX_PAGES;
		if (maxpages > V1_MAX_PAGES)
			maxpages = V1_MAX_PAGES;
	}
#endif
	if (PAGES > maxpages) {
		PAGES = maxpages;
		bb_error_msg("warning: truncating swap area to %ldkB",
				PAGES * pagesize / 1024);
	}

	DEV = open(device_name, O_RDWR);
	if (DEV < 0 || fstat(DEV, &statbuf) < 0)
		bb_perror_msg_and_die("%s", device_name);
	if (!S_ISBLK(statbuf.st_mode))
		check = 0;
	else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
		bb_error_msg_and_die("Will not try to make swapdevice on '%s'", device_name);

#ifdef __sparc__
	if (!force && version == 0) {
		/* Don't overwrite partition table unless forced */
		unsigned char *buffer = (unsigned char *) signature_page;
		unsigned short *q, sum;

		if (read(DEV, buffer, 512) != 512)
			bb_error_msg_and_die("fatal: first page unreadable");
		if (buffer[508] == 0xDA && buffer[509] == 0xBE) {
			q = (unsigned short *) (buffer + 510);
			for (sum = 0; q >= (unsigned short *) buffer;)
				sum ^= *q--;
			if (!sum) {
				bb_error_msg("Device '%s' contains a valid Sun disklabel.\n"
"This probably means creating v0 swap would destroy your partition table\n"
"No swap created. If you really want to create swap v0 on that device, use\n"
"the -f option to force it.", device_name);
				return EXIT_FAILURE;
			}
		}
	}
#endif

	if (version == 0 || check)
		check_blocks();
	if (version == 0 && !bit_test_and_clear(signature_page, 0))
		bb_error_msg_and_die("fatal: first page unreadable");
	if (version == 1) {
		p->version = version;
		p->last_page = PAGES - 1;
		p->nr_badpages = badpages;
	}

	goodpages = PAGES - badpages - 1;
	if (goodpages <= 0)
		bb_error_msg_and_die("Unable to set up swap-space: unreadable");
	printf("Setting up swapspace version %d, size = %ld bytes\n",
		   version, (long) (goodpages * pagesize));
	write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");

	offset = ((version == 0) ? 0 : 1024);
	if (lseek(DEV, offset, SEEK_SET) != offset)
		bb_error_msg_and_die("unable to rewind swap-device");
	if (write(DEV, (char *) signature_page + offset, pagesize - offset)
		!= pagesize - offset)
		bb_error_msg_and_die("unable to write signature page");

	/*
	 * A subsequent swapon() will fail if the signature
	 * is not actually on disk. (This is a kernel bug.)
	 */
	if (fsync(DEV))
		bb_error_msg_and_die("fsync failed");
	return EXIT_SUCCESS;
}
Пример #16
0
void			header_signature(char *signature, int fd)
{
  init_signature(signature);
  write_signature(signature, fd);
}
Пример #17
0
int mkswap_main(int argc, char **argv)
{
    char *tmp;
    struct stat statbuf;
    int sz;
    int maxpages;
    int goodpages;
#ifdef __sparc__
    int force = 0;
#endif

    init_signature_page();		/* get pagesize */

    bb_opt_complementally = "?"; /* call bb_show_usage internally */
    sz = bb_getopt_ulflags(argc, argv, "+cfv:", &tmp);
    if (sz & 1)
        check = 1;
#ifdef __sparc__
    if (sz & 2)
        force = 1;
#endif
#if ENABLE_FEATURE_MKSWAP_V0
    if (sz & 4) {
        version = bb_xgetlarg(tmp, 10, 0, 1);
    } else {
        if (get_linux_version_code() < KERNEL_VERSION(2, 1, 117))
            version = 0;
        else
            version = 1;
    }
#endif

    argv += optind;
    argc -= optind;

    goodpages = pagesize / 1024; /* cache division */
    while (argc--) {
        if (device_name) {
            PAGES = bb_xgetlarg(argv[0], 0, 10, sz * goodpages) / goodpages;
            argc = 0; /* ignore any surplus args.. */
        } else {
            device_name = argv[0];
            sz = get_size(device_name);
            argv++;
        }
    }

    if (!device_name) {
        bb_error_msg_and_die("error: Nowhere to set up swap on?");
    }
    if (!PAGES) {
        PAGES = sz;
    }

#if 0
    maxpages = ((version == 0) ? V0_MAX_PAGES : V1_MAX_PAGES);
#else
    if (!version)
        maxpages = V0_MAX_PAGES;
    else if (get_linux_version_code() >= KERNEL_VERSION(2,2,1))
        maxpages = V1_MAX_PAGES;
    else {
        maxpages = V1_OLD_MAX_PAGES;
        if (maxpages > V1_MAX_PAGES)
            maxpages = V1_MAX_PAGES;
    }
#endif
    if (PAGES > maxpages) {
        PAGES = maxpages;
        bb_error_msg("warning: truncating swap area to %ldkB",
                     PAGES * goodpages);
    }

    DEV = bb_xopen3(device_name, O_RDWR, 0);
    if (fstat(DEV, &statbuf) < 0)
        bb_perror_msg_and_die("%s", device_name);
    if (!S_ISBLK(statbuf.st_mode))
        check = 0;
    else if (statbuf.st_rdev == 0x0300 || statbuf.st_rdev == 0x0340)
        bb_error_msg_and_die("Will not try to make swapdevice on '%s'", device_name);

#ifdef __sparc__
    if (!force && version == 0) {
        /* Don't overwrite partition table unless forced */
        unsigned char *buffer = (unsigned char *) signature_page;
        unsigned short *q, sum;

        if (read(DEV, buffer, 512) != 512)
            bb_error_msg_and_die("fatal: first page unreadable");
        if (buffer[508] == 0xDA && buffer[509] == 0xBE) {
            q = (unsigned short *) (buffer + 510);
            for (sum = 0; q >= (unsigned short *) buffer;)
                sum ^= *q--;
            if (!sum) {
                bb_error_msg("Device '%s' contains a valid Sun disklabel.\n"
                             "This probably means creating v0 swap would destroy your partition table\n"
                             "No swap created. If you really want to create swap v0 on that device, use\n"
                             "the -f option to force it.", device_name);
                return EXIT_FAILURE;
            }
        }
    }
#endif

    if (version == 0 || check)
        check_blocks();
    if (version == 0 && !bit_test_and_clear(signature_page, 0))
        bb_error_msg_and_die("fatal: first page unreadable");
    if (version == 1) {
        p->swap_version = version;
        p->last_page = PAGES - 1;
        p->nr_badpages = badpages;
    }

    goodpages = PAGES - badpages - 1;
    if (goodpages <= 0)
        bb_error_msg_and_die("Unable to set up swap-space: unreadable");
    printf("Setting up swapspace version %d, size = %ld bytes\n",
           version, (long) (goodpages * pagesize));
    write_signature((version == 0) ? "SWAP-SPACE" : "SWAPSPACE2");

    sz = ((version == 0) ? 0 : 1024); /* offset */
    if (lseek(DEV, sz, SEEK_SET) != sz)
        bb_error_msg_and_die("unable to rewind swap-device");
    goodpages = pagesize - sz; /* cache substraction */
    if (write(DEV, (char *) signature_page + sz, goodpages)
            != goodpages)
        bb_error_msg_and_die("unable to write signature page");

    /*
     * A subsequent swapon() will fail if the signature
     * is not actually on disk. (This is a kernel bug.)
     */
    if (fsync(DEV))
        bb_error_msg_and_die("fsync failed");
    if (ENABLE_FEATURE_CLEAN_UP) {
        close(DEV);
        free(signature_page);
    }
    return EXIT_SUCCESS;
}
Пример #18
0
bool l4dtoolz::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{

	PLUGIN_SAVEVARS();

	GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
	GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);


#if defined METAMOD_PLAPI_VERSION
	if ((vsp_callbacks = ismm->GetVSPInfo(NULL)) == NULL)
#endif
	{
		ismm->AddListener(this, this);
		ismm->EnableVSPListener();
	}


#if !defined METAMOD_PLAPI_VERSION
	m_EngineCC = SH_GET_CALLCLASS(engine);
#endif

#if SOURCE_ENGINE >= SE_ORANGEBOX
	g_pCVar = icvar;
	ConVar_Register(0, &s_BaseAccessor);
#else
	ConCommandBaseMgr::OneTimeInit(&s_BaseAccessor);
#endif

	struct base_addr_t base_addr;
	base_addr.addr = NULL;
	base_addr.len = 0;

	find_base_from_list(matchmaking_dll, &base_addr);

	if(!lobby_match_ptr) {
		lobby_match_ptr = find_signature(lobby_match, &base_addr, 1);
		get_original_signature(lobby_match_ptr, lobby_match_new, lobby_match_org);
	}

	find_base_from_list(engine_dll, &base_addr);
#ifdef L4D1
	if(!max_players_friend_lobby) {
		max_players_friend_lobby = find_signature(friends_lobby, &base_addr, 0);
		get_original_signature(max_players_friend_lobby, friends_lobby_new, friends_lobby_org);
	}
#endif
	if(!max_players_connect) {
		max_players_connect = find_signature(max_players, &base_addr, 0);
		get_original_signature(max_players_connect, max_players_new, max_players_org);
	}
	if(!lobby_sux_ptr) {

#ifdef WIN32
		lobby_sux_ptr = max_players_connect;
#else
		lobby_sux_ptr = find_signature(lobby_sux, &base_addr, 0);
#endif
		get_original_signature(lobby_sux_ptr, lobby_sux_new, lobby_sux_org);
	}
#ifdef L4D1
#ifdef WIN32
	if(!max_players_server_browser) {
		max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
		get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
	}
#endif
#endif
	if(!tmp_player) {
		tmp_player = find_signature(players, &base_addr, 0);
		if(tmp_player) {
			tmp_player2 = find_signature(players2, &base_addr, 0);
			if(tmp_player2) {
				get_original_signature(tmp_player, players_new, players_org);
				write_signature(tmp_player, players_new);
				get_original_signature(tmp_player2, players_new2, players_org2);
				write_signature(tmp_player2, players_new2);
				engine->ServerCommand("maxplayers 32\n");
				engine->ServerCommand("L4DToolZ [email protected]\n");
			}
		}
	}
	if(!unreserved_ptr) {
		unreserved_ptr = find_signature(unreserved, &base_addr, 0);
		get_original_signature(unreserved_ptr, unreserved_new, unreserved_org);
	}

	find_base_from_list(server_dll, &base_addr);
#ifdef L4D1
	if(!chuman_limit) {
		chuman_limit = find_signature(human_limit, &base_addr, 0);
		get_original_signature(chuman_limit, human_limit_new, human_limit_org);
	}
#ifndef WIN32
	if(!max_players_server_browser) {
		max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
		get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
	}
#endif
#else
	if(!max_players_server_browser) {
		max_players_server_browser = find_signature(server_bplayers, &base_addr, 0);
		get_original_signature(max_players_server_browser, server_bplayers_new, server_bplayers_org);
	}
#endif

	return true;
}
Пример #19
0
void l4dtoolz::OnChangeMaxplayers ( IConVar *var, const char *pOldValue, float flOldValue )
{
	int new_value = ((ConVar*)var)->GetInt();
	int old_value = atoi(pOldValue);
#ifdef L4D1
	if (max_players_friend_lobby == NULL || max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
#else
	if (max_players_connect == NULL || max_players_server_browser == NULL || lobby_sux_ptr == NULL) {
#endif
	Msg("sv_maxplayers init error\n");
		return;
	}
	if(new_value != old_value) {
		if(new_value >= 0) {
#ifdef L4D1
			max_players_new[4] = friends_lobby_new[3] = server_bplayers_new[3] = new_value;
#else
			max_players_new[4] = server_bplayers_new[3] = (unsigned char)new_value;
#endif
			if(lobby_match_ptr) {
				lobby_match_new[2] = (unsigned char)new_value;
				write_signature(lobby_match_ptr, lobby_match_new);
			} else {
				Msg("sv_maxplayers MS init error\n");
			}
#ifdef L4D1
			write_signature(max_players_friend_lobby, friends_lobby_new);
#endif
			write_signature(max_players_connect, max_players_new);
			write_signature(lobby_sux_ptr, lobby_sux_new);
			write_signature(max_players_server_browser, server_bplayers_new);
		} else {
#ifdef L4D1
			write_signature(max_players_friend_lobby, friends_lobby_org);
#endif
			write_signature(max_players_connect, max_players_org);
			write_signature(lobby_sux_ptr, lobby_sux_org);
			write_signature(max_players_server_browser, server_bplayers_org);
		
			if(lobby_match_ptr)
				write_signature(lobby_match_ptr, lobby_match_org);
		}
	}
}

#ifdef L4D1
void l4dtoolz::OnChangeRemovehumanlimit ( IConVar *var, const char *pOldValue, float flOldValue )
{
	int new_value = ((ConVar*)var)->GetInt();
	int old_value = atoi(pOldValue);
	if(chuman_limit == NULL) {
		Msg( "sv_removehumanlimit init error\n");
		return;
	}
	if(new_value != old_value) {
		if(new_value == 1) {
			write_signature(chuman_limit, human_limit_new);
		}else{
			write_signature(chuman_limit, human_limit_org);
		}
	}
}