Example #1
0
mBOOL MHookList::remove(plid_t plid, int hindex) {

    int i=hindex;

    if(!hlist[i])

        RETURN_ERRNO(mFALSE, ME_NOTFOUND);

    if(hlist[i]->plid != plid)

        RETURN_ERRNO(mFALSE, ME_BADREQ);



    MXlock();

    delete(hlist[i]);

    hlist[i]=NULL;

    MXunlock();

    return(mTRUE);

}
Example #2
0
mBOOL MHookList::call(event_args_t *evargs, const char *logline)

{

    int i;



    if(!evargs)

        RETURN_ERRNO(mFALSE, ME_ARGUMENT);

    if(evargs->evtype==EV_NONE)

        RETURN_ERRNO(mFALSE, ME_BADREQ);



    MXlock();

    for(i=0; i < endlist && hlist[i]; i++) {

        if(hlist[i]->event == evargs->evtype)

            hlist[i]->call(evargs, logline);

    }

    MXunlock();

    return(mTRUE);

}
Example #3
0
mBOOL MHook::enqueue(MFuncQueue *mfq, event_args_t *args, const char *logline) {

    func_item_t *fp;



    if(!mfq || !args || !logline)

        RETURN_ERRNO(mFALSE, ME_ARGUMENT);



    fp = (func_item_t *) malloc(sizeof(func_item_t));

    if(!fp) {

        META_ERROR("malloc failed for func_item_t");

        RETURN_ERRNO(mFALSE, ME_NOMEM);

    }

    fp->hook=this;

    fp->evargs=args;

    fp->logline=logline;

    mfq->push(fp);

    return(mTRUE);

}
Example #4
0
MPlugin * MPluginList::plugin_addload(plid_t plid, const char *fname, PLUG_LOADTIME now)
{
	MPlugin pl_temp;
	MPlugin *pl_found, *pl_added, *pl_loader;

	if ( !(pl_loader=find(plid)) )
	{
		META_DEBUG(1, ("Couldn't find plugin that gave this loading request!"));
		RETURN_ERRNO(NULL, ME_BADREQ);
	}

	memset(&pl_temp, 0, sizeof(pl_temp));

	if (!pl_temp.plugin_parseline(fname, pl_loader->index))
	{
		RETURN_ERRNO(NULL, ME_NOTFOUND);
	}

	if (pl_temp.resolve() != mTRUE)
	{
		META_DEBUG(1, ("Couldn't resolve given path into a file: %s", pl_temp.file));
		RETURN_ERRNO(NULL, ME_NOTFOUND);
	}

	if ( (pl_found=find(pl_temp.pathname)) )
	{
		META_DEBUG(1, ("Plugin '%s' already in current list; file=%s desc='%s'", 
				pl_temp.file, pl_found->file, pl_found->desc));
		RETURN_ERRNO(NULL, ME_ALREADY);
	}

	if (!(pl_added=add(&pl_temp)))
	{
		META_DEBUG(1, ("Couldn't add plugin '%s' to list; see log", pl_temp.desc));
		return NULL;
	}

	pl_added->action = PA_LOAD;
	if (!pl_added->load(now))
	{
		if (meta_errno==ME_NOTALLOWED || meta_errno==ME_DELAYED)
		{
			META_DEBUG(1, ("Plugin '%s' couldn't attach; only allowed %s", 
					pl_added->desc, pl_added->str_loadable(SL_ALLOWED)));
			pl_added->clear();
		} else if (pl_added->status == PL_OPENED) {
			META_DEBUG(1, ("Opened plugin '%s', but failed to attach; see log", pl_added->desc));
		} else {
			META_DEBUG(1, ("Couldn't load plugin '%s'; see log", pl_added->desc));
		}
		return NULL;
	}

	META_DEBUG(1, ("Loaded plugin '%s' successfully", pl_added->desc));
	meta_errno = ME_NOERROR;

	return pl_added;
}
Example #5
0
MPlugin *MPluginList::find(int pindex) {
	MPlugin *pfound;
	if(pindex <= 0)
		RETURN_ERRNO(NULL, ME_ARGUMENT);
	pfound=&plist[pindex-1];
	if(pfound->status < PL_VALID)
		RETURN_ERRNO(NULL, ME_NOTFOUND);
	else
		return(pfound);
}
Example #6
0
MPlugin *MPluginList::find(plid_t id) {
	int i;

	if(!id)
		RETURN_ERRNO(NULL, ME_ARGUMENT);
	for(i=0; i < endlist; i++) {
		if(plist[i].status < PL_VALID)
			continue;
		if(plist[i].info == id)
			return(&plist[i]);
	}
	RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #7
0
MPlugin *MPluginList::find(DLHANDLE handle)
{
	int i;

	if(!handle)
		RETURN_ERRNO(NULL, ME_ARGUMENT);
	for(i=0; i < endlist; i++) {
		if(plist[i].status < PL_VALID)
			continue;
		if(plist[i].handle == handle)
			return(&plist[i]);
	}
	RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #8
0
void filter_init(int fd) {
#if defined(__x86_64__)
#define X32_SYSCALL_BIT 0x40000000
	struct sock_filter filter[] = {
		VALIDATE_ARCHITECTURE,
		EXAMINE_SYSCALL,
		// handle X32 ABI
		BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, X32_SYSCALL_BIT, 1, 0),
		BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 0, 1, 0),
		RETURN_ERRNO(EPERM)
	};
#else
	struct sock_filter filter[] = {
		VALIDATE_ARCHITECTURE,
		EXAMINE_SYSCALL
	};
#endif

#if 0
{
	int i;
	unsigned char *ptr = (unsigned char *) &filter[0];
	for (i = 0; i < sizeof(filter); i++, ptr++)
		printf("%x, ", (*ptr) & 0xff);
	printf("\n");
}
#endif

	write_to_file(fd, filter, sizeof(filter));
}
Example #9
0
// Add the given cvar name to the list and return the instance.  This only
// writes the "name" to the new cvar; other fields are written with
// cvar::set().
// meta_errno values:
//  - ME_NOMEM			couldn't alloc or realloc for various parts
MRegCvar * DLLINTERNAL MRegCvarList::add(const char *addname) {
	MRegCvar *icvar;

	if(endlist==size) {
		// grow array
		MRegCvar *temp;
		int i, newsize;
		newsize=size+REG_CVAR_GROWSIZE;
		META_DEBUG(6, ("Growing reg cvar list from %d to %d", size, newsize));
		temp = (MRegCvar *) realloc(vlist, newsize*sizeof(MRegCvar));
		if(!temp) {
			META_WARNING("Couldn't grow registered cvar list to %d for '%s'; %s", newsize, addname, strerror(errno));
			RETURN_ERRNO(NULL, ME_NOMEM);
		}
		vlist=temp;
		size=newsize;
		// initialize new (unused) entries
		for(i=endlist; i<size; i++) {
			memset(&vlist[i], 0, sizeof(vlist[i]));
			vlist[i].init(i+1);		// 1-based
		}
	}

	icvar = &vlist[endlist];

	// Malloc space for the cvar and cvar name, for two reasons:
	//  - Can't point to memory loc in plugin (another segv waiting to 
	//    happen).
	//  - Can't point to memory in vlist which might get moved later by 
	//    realloc (again, segv).
	icvar->data = (cvar_t *) calloc(1, sizeof(cvar_t));
	if(!icvar->data) {
		META_WARNING("Couldn't malloc cvar for adding reg cvar name '%s': %s", 
				addname, strerror(errno));
		RETURN_ERRNO(NULL, ME_NOMEM);
	}
	icvar->data->name=strdup(addname);
	if(!icvar->data->name) {
		META_WARNING("Couldn't strdup for adding reg cvar name '%s': %s", 
				addname, strerror(errno));
		RETURN_ERRNO(NULL, ME_NOMEM);
	}
	endlist++;
	
	return(icvar);
}
Example #10
0
// Try to find a registered cvar with the given name.
// meta_errno values:
//  - ME_NOTFOUND	couldn't find a matching cvar
MRegCvar * DLLINTERNAL MRegCvarList::find(const char *findname) {
	int i;
	for(i=0; i < endlist; i++) {
		if(!strcasecmp(vlist[i].data->name, findname))
			return(&vlist[i]);
	}
	RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #11
0
// Try to find a registered msg with the given name.
// meta_errno values:
//  - ME_NOTFOUND	couldn't find a matching cvar
MRegMsg * DLLINTERNAL MRegMsgList::find(const char *findname) {
	int i;
	for(i=0; i < endlist; i++) {
		if(!mm_strcmp(mlist[i].name, findname))
			return(&mlist[i]);
	}
	RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #12
0
mBOOL DLLINTERNAL MConfig::set(const char *key, const char *value) {
	option_t *optp;
	optp=find(key);
	if(optp)
		return(set(optp, value));
	else
		RETURN_ERRNO(mFALSE, ME_NOTFOUND);
}
Example #13
0
// Try to find a registered msg with the given msgid.
// meta_errno values:
//  - ME_NOTFOUND	couldn't find a matching cvar
MRegMsg * DLLINTERNAL MRegMsgList::find(int findmsgid) {
	int i;
	for(i=0; i < endlist; i++) {
		if(mlist[i].msgid == findmsgid)
			return(&mlist[i]);
	}
	RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #14
0
MPlugin *MPluginList::find(const char *findpath) {
	int i;

	if(!findpath)
		RETURN_ERRNO(NULL, ME_ARGUMENT);
	META_DEBUG(8, ("Looking for loaded plugin with dlfnamepath: %s", findpath));
	for(i=0; i < endlist; i++) {
		META_DEBUG(9, ("Looking at: plugin %s loadedpath: %s", plist[i].file, plist[i].pathname));
		if(plist[i].status < PL_VALID)
			continue;
		if(strmatch(plist[i].pathname, findpath)) {
			META_DEBUG(8, ("Found loaded plugin %s", plist[i].file));
			return(&plist[i]);
		}
	}
	META_DEBUG(8, ("No loaded plugin found with path: %s", findpath));
	RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #15
0
option_t * DLLINTERNAL MConfig::find(const char *lookup) {
	option_t *optp;

	for(optp=list; optp->name && !strmatch(optp->name, lookup); optp++);
	if(optp->name)
		return(optp);
	else
		RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #16
0
// Check if a client cvar is queried for this player
// Returns NULL if not
// or the name of the cvar.
// meta_errno values:
//  - ME_NOTFOUND  invalid entity
const char* DLLINTERNAL MPlayerList::is_querying_cvar(const edict_t *pEntity)
{
	int indx = ENTINDEX(const_cast<edict_t*>(pEntity));

	if(indx < 1 || indx > gpGlobals->maxClients) {
		RETURN_ERRNO(NULL, ME_NOTFOUND);
	}
 
	return(players[indx].is_querying_cvar());
}
Example #17
0
MPlugin *MPluginList::find_match(MPlugin *pmatch) {
	int i;
	MPlugin *iplug, *pfound;
	if(!pmatch)
		RETURN_ERRNO(NULL, ME_ARGUMENT);
	pfound=NULL;
	for(i=0; i < endlist; i++) {
		iplug=&plist[i];
		if(pmatch->platform_match(iplug)) {
			pfound=iplug;
			break;
		}
	}

	if(pfound)
		return(pfound);
	else
		RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #18
0
mBOOL DLLINTERNAL MConfig::load(const char *fn) {
	FILE *fp;
	char loadfile[PATH_MAX];
	char line[MAX_CONF_LEN];
	char *optname, *optval;
	option_t *optp;
	int ln;

	// Make full pathname (from gamedir if relative, collapse "..",
	// backslashes, etc).
	full_gamedir_path(fn, loadfile);

	fp=fopen(loadfile, "r");
	if(!fp) {
		META_WARNING("unable to open config file '%s': %s", loadfile, 
				strerror(errno));
		RETURN_ERRNO(mFALSE, ME_NOFILE);
	}

	META_DEBUG(2, ("Loading from config file: %s", loadfile));
	for(ln=1; !feof(fp) && fgets(line, sizeof(line), fp); ln++) {
		if(line[0]=='#')
			continue;
		if(line[0]==';')
			continue;
		if(strnmatch(line, "//", 2))
			continue;
		if(!(optname=strtok(line, " \t\r\n"))) {
			META_WARNING("'%s' line %d: bad config format: missing option", 
					loadfile, ln);
			continue;
		}
		if(!(optval=strtok(NULL, "\r\n"))) {
			META_WARNING("'%s' line %d: bad config format: missing value", 
					loadfile, ln);
			continue;
		}

		if(!(optp=find(optname))) {
			META_WARNING("'%s' line %d: unknown option name '%s'", 
					loadfile, ln, optname);
			continue;
		}

		if(!set(optp, optval)) {
			META_WARNING("'%s' line %d: unable to set option '%s' value '%s'", 
					loadfile, ln, optname, optval);
			continue;
		}
	}
	filename=strdup(loadfile);
	fclose(fp);
	return(mTRUE);
}
Example #19
0
MPlugin *MPluginList::find_memloc(void *memptr) {
	const char *dlfile;

	if(!memptr)
		RETURN_ERRNO(NULL, ME_ARGUMENT);
	if(!(dlfile=DLFNAME(memptr))) {
		META_DEBUG(8, ("DLFNAME failed to find memloc %d", memptr));
		// meta_errno should be already set in DLFNAME
		return(NULL);
	}
	return(find(dlfile));
}
Example #20
0
// Try to call the function.  Relies on OS-specific routine to attempt
// calling the function without generating a segfault from an unloaded
// plugin DLL.
// meta_errno values:
//  - ME_BADREQ		function disabled/invalid
//  - ME_ARGUMENT	function pointer is null
mBOOL DLLINTERNAL MRegCmd::call(void) {
	mBOOL ret;

	// can we expect to call this function?
	if(status != RG_VALID)
		RETURN_ERRNO(mFALSE, ME_BADREQ);
	if(!pfnCmd)
		RETURN_ERRNO(mFALSE, ME_ARGUMENT);

	// try to call this function
	ret=os_safe_call(pfnCmd);
	if(!ret) {
		META_DEBUG(4, ("Plugin reg_cmd '%s' called after unloaded; removed from list", name));
		status=RG_INVALID;
		pfnCmd=NULL;
		// NOTE: we can't free the malloc'd space for the name, as that
		// would just re-introduce the segfault problem..
	}
	// meta_errno (if failed) is set already in os_safe_call()
	return(ret);
}
Example #21
0
// Add the given name to the list and return the instance.  This only
// writes the "name" to the new cmd; other fields are writtin by caller
// (meta_AddServerCommand).
// meta_errno values:
//  - ME_NOMEM			couldn't realloc or malloc for various parts
MRegCmd * DLLINTERNAL MRegCmdList::add(const char *addname) {
	MRegCmd *icmd;

	if(endlist==size) {
		// grow array
		MRegCmd *temp;
		int i, newsize;
		newsize=size+REG_CMD_GROWSIZE;
		META_DEBUG(6, ("Growing reg cmd list from %d to %d", size, newsize));
		temp = (MRegCmd *) realloc(mlist, newsize*sizeof(MRegCmd));
		if(!temp) {
			META_WARNING("Couldn't grow registered command list to %d for '%s': %s", newsize, addname, strerror(errno));
			RETURN_ERRNO(NULL, ME_NOMEM);
		}
		mlist=temp;
		size=newsize;
		// initialize new (unused) entries
		for(i=endlist; i<size; i++) {
			memset(&mlist[i], 0, sizeof(mlist[i]));
			mlist[i].init(i+1);		// 1-based
		}
	}
	icmd = &mlist[endlist];

	// Malloc space separately for the command name, because:
	//  - Can't point to memory loc in plugin (another segv waiting to 
	//    happen).
	//  - Can't point to memory in mlist which might get moved later by 
	//    realloc (again, segv).
	icmd->name=strdup(addname);
	if(!icmd->name) {
		META_WARNING("Couldn't strdup for adding reg cmd name '%s': %s", 
				addname, strerror(errno));
		RETURN_ERRNO(NULL, ME_NOMEM);
	}
	endlist++;
	
	return(icmd);
}
Example #22
0
// Set the cvar, copying values from given cvar.
// meta_errno values:
//  - ME_ARGUMENT	given cvar doesn't match this cvar
mBOOL DLLINTERNAL MRegCvar::set(cvar_t *src) {
	if(strcasecmp(src->name, data->name)) {
		META_WARNING("Tried to set cvar with mismatched name; src=%s dst=%s",
				src->name, data->name);
		RETURN_ERRNO(mFALSE, ME_ARGUMENT);
	}
	// Would like to free() existing string, but can't tell where it was
	// allocated...
	data->string = strdup(src->string);
	data->flags = src->flags;
	data->value = src->value;
	data->next = src->next;
	return(mTRUE);
}
Example #23
0
MPlugin *MPluginList::find_match(const char *prefix) {
	int i, len;
	MPlugin *iplug, *pfound;
	char buf[NAME_MAX];

	if(!prefix)
		RETURN_ERRNO(NULL, ME_ARGUMENT);
	pfound=NULL;
	len=strlen(prefix);
	snprintf(buf, sizeof(buf), "mm_%s", prefix);
	for(i=0; i < endlist; i++) {
		iplug=&plist[i];
		if(iplug->status < PL_VALID)
			continue;
		if(iplug->info && strncasecmp(iplug->info->name, prefix, len) == 0) {
			if(pfound)
				RETURN_ERRNO(NULL, ME_NOTUNIQ);
			pfound=iplug;
			continue;
		}
		else if(strncasecmp(iplug->desc, prefix, len) == 0) {
			if(pfound)
				RETURN_ERRNO(NULL, ME_NOTUNIQ);
			pfound=iplug;
			continue;
		}
		else if(strncasecmp(iplug->file, prefix, len) == 0) {
			if(pfound)
				RETURN_ERRNO(NULL, ME_NOTUNIQ);
			pfound=iplug;
			continue;
		}
		else if(strncasecmp(iplug->file, buf, strlen(buf)) == 0) {
			if(pfound)
				RETURN_ERRNO(NULL, ME_NOTUNIQ);
			pfound=iplug;
			continue;
		}
		else if(iplug->info 
				&& strncasecmp(iplug->info->logtag, prefix, len) == 0) 
		{
			if(pfound)
				RETURN_ERRNO(NULL, ME_NOTUNIQ);
			pfound=iplug;
			continue;
		}
	}
	if(pfound)
		return(pfound);
	else
		RETURN_ERRNO(NULL, ME_NOTFOUND);
}
Example #24
0
MPlugin *MPluginList::add(MPlugin *padd) {
	int i;
	MPlugin *iplug;

	// Find either:
	//  - a slot in the list that's not being used
	//  - the end of the list
	for(i=0; i < endlist && plist[i].status != PL_EMPTY; i++);

	// couldn't find a slot to use
	if(i==size) {
		META_ERROR("Couldn't add plugin '%s' to list; reached max plugins (%d)", 
				padd->file, i);
		RETURN_ERRNO(NULL, ME_MAXREACHED);
	}

	// if we found the end of the list, advance end marker
	if(i==endlist)
		endlist++;
	iplug = &plist[i];

	// copy filename into this free slot
	STRNCPY(iplug->filename, padd->filename, sizeof(iplug->filename));
	// Copy file offset ptr.
	// Can't just copy ptr, as it points to offset in padd, which will go
	// away; need to point to corresponding offset in iplug.
	iplug->file = iplug->filename + (padd->file - padd->filename);
	// copy description
	STRNCPY(iplug->desc, padd->desc, sizeof(iplug->desc));
	// copy pathname
	STRNCPY(iplug->pathname, padd->pathname, sizeof(iplug->pathname));
	// copy source
	iplug->source=padd->source;
	// copy status
	iplug->status=padd->status;	
	//copy other things
	iplug->source_plugin_index = padd->source_plugin_index;

	return(iplug);
}
Example #25
0
// Add the given user msg the list and return the instance.
// meta_errno values:
//  - ME_MAXREACHED		reached max number of msgs allowed
MRegMsg * DLLINTERNAL MRegMsgList::add(const char *addname, int addmsgid, int addsize) {
	MRegMsg *imsg;

	if(endlist==size) {
		// all slots used
		META_ERROR("Couldn't add registered msg '%s' to list; reached max msgs (%d)",
				addname, size);
		RETURN_ERRNO(NULL, ME_MAXREACHED);
	}

	imsg = &mlist[endlist];
	endlist++;

	// Copy msg data into empty slot.
	// Note: 'addname' assumed to be a constant string allocated in the
	// gamedll.
	imsg->name=addname;
	imsg->msgid=addmsgid;
	imsg->size=addsize;

	return(imsg);
}
Example #26
0
mBOOL MPluginList::ini_startup() {
	FILE *fp;
	char line[MAX_STRBUF_LEN];
	int n, ln;
	MPlugin *pmatch;

	if(!valid_gamedir_file(inifile)) {
		META_ERROR("ini: Metamod plugins file empty or missing: %s", inifile);
		RETURN_ERRNO(mFALSE, ME_NOFILE);
	}
	full_gamedir_path(inifile, inifile);

	fp=fopen(inifile, "r");
	if(!fp) {
		META_ERROR("ini: Unable to open plugins file '%s': %s", inifile, 
				strerror(errno));
		RETURN_ERRNO(mFALSE, ME_NOFILE);
	}

	META_LOG("ini: Begin reading plugins list: %s", inifile);
	for(n=0, ln=1; 
			!feof(fp) && fgets(line, sizeof(line), fp) && n < size; 
			ln++) 
	{
		// Remove line terminations.
		char *cp;
		if((cp=strrchr(line, '\r')))
			*cp='\0';
		if((cp=strrchr(line, '\n')))
			*cp='\0';
		// Parse directly into next entry in array
		if(!plist[n].ini_parseline(line)) {
			if(meta_errno==ME_FORMAT)
				META_ERROR("ini: Skipping malformed line %d of %s", ln, 
						inifile);
			continue;
		}
		// Check for a duplicate - an existing entry with this pathname.
		if(find(plist[n].pathname)) {
			// Should we check platform specific level here?
			META_INFO("ini: Skipping duplicate plugin, line %d of %s: %s", 
					ln, inifile, plist[n].pathname);
			continue;
		}
		// Check for a matching platform with different platform specifics
		// level.
		if(NULL != (pmatch=find_match(&plist[n]))) {
			if(pmatch->pfspecific >= plist[n].pfspecific) {
				META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)",
                         ln, inifile, pmatch->pfspecific, plist[n].pfspecific)); 
				continue;
			}
			META_DEBUG(1, ("ini: Plugin in line %d overrides existing plugin with lower platform specific level %d, ours %d",
					ln, pmatch->pfspecific, plist[n].pfspecific));
			int _index = pmatch->index;
			memset(pmatch, 0, sizeof(MPlugin));
			pmatch->index = _index;
		}
		plist[n].action=PA_LOAD;
		META_LOG("ini: Read plugin config for: %s", plist[n].desc);
		n++;
		endlist=n;		// mark end of list
	}
	META_LOG("ini: Finished reading plugins list: %s; Found %d plugins to load",
			inifile, n);

	fclose(fp);
	if(!n) {
		META_ERROR("ini: Warning; no plugins found to load?");
	}
	return(mTRUE);
}
Example #27
0
mBOOL DLLINTERNAL MConfig::set(option_t *setp, const char *setstr) {
	char pathbuf[PATH_MAX];
	int *optval = (int *) setp->dest;
	char **optstr = (char **) setp->dest;
	// cvar_t *optcvar = (cvar_t *) setp->dest;
	// SETOPT_FN optcmd = (SETOPT_FN) setp->dest;

	if(!setstr)
		return(mTRUE);

	switch(setp->type) {
		case CF_INT:
			if(!isdigit(setstr[0])) {
				META_WARNING("option '%s' invalid format '%s'", setp->name, setstr);
				RETURN_ERRNO(mFALSE, ME_FORMAT);
			}
			*optval=atoi(setstr);
			META_DEBUG(3, ("set config int: %s = %d", setp->name, *optval));
			break;
		case CF_BOOL:
			if(strcasematch(setstr, "true")
					|| strcasematch(setstr, "yes")
					|| strmatch(setstr, "1"))
			{
				*optval=1;
			}
			else if(strcasematch(setstr, "false")
					|| strcasematch(setstr, "no")
					|| strmatch(setstr, "0"))
			{
				*optval=0;
			}
			else {
				META_WARNING("option '%s' invalid format '%s'", setp->name, setstr);
				RETURN_ERRNO(mFALSE, ME_FORMAT);
			}
			META_DEBUG(3, ("set config bool: %s = %s", setp->name, *optval ? "true" : "false"));
			break;
		case CF_STR:
			if(*optstr)
				free(*optstr);
			*optstr=strdup(setstr);
			META_DEBUG(3, ("set config string: %s = %s", setp->name, *optstr));
			break;
		case CF_PATH:
			if(*optstr)
				free(*optstr);
			full_gamedir_path(setstr, pathbuf);
			*optstr=strdup(pathbuf);
			META_DEBUG(3, ("set config path: %s = %s", setp->name, *optstr));
			break;
#if 0
		case CF_CVAR:
			CVAR_SET_STRING(optcvar->name, setstr);
			META_DEBUG(3, ("set config cvar: %s = %s", optcvar->name, setstr));
			break;
		case CF_CMD:
			optcmd(setp->name, setstr);
			META_DEBUG(3, ("set config command: %s, %s", optcvar->name, setstr));
			break;
#endif
		default:
			META_WARNING("unrecognized config type '%d'", setp->type);
			RETURN_ERRNO(mFALSE, ME_ARGUMENT);
	}
	return(mTRUE);
}
Example #28
0
mBOOL MPluginList::ini_refresh() {
	FILE *fp;
	char line[MAX_STRBUF_LEN];
	int n, ln;
	MPlugin pl_temp;
	MPlugin *pl_found, *pl_added;

	fp=fopen(inifile, "r");
	if(!fp) {
		META_ERROR("ini: Unable to open plugins file '%s': %s", inifile, 
				strerror(errno));
		RETURN_ERRNO(mFALSE, ME_NOFILE);
	}

	META_LOG("ini: Begin re-reading plugins list: %s", inifile);
	for(n=0, ln=1; 
			!feof(fp) && fgets(line, sizeof(line), fp) && n < size; 
			ln++) 
	{
		// Remove line terminations.
		char *cp;
		if((cp=strrchr(line, '\r')))
			*cp='\0';
		if((cp=strrchr(line, '\n')))
			*cp='\0';
		// Parse into a temp plugin
		memset(&pl_temp, 0, sizeof(pl_temp));
		if(!pl_temp.ini_parseline(line)) {
			if(meta_errno==ME_FORMAT)
				META_ERROR("ini: Skipping malformed line %d of %s", 
						ln, inifile);
			continue;
		}
		// Try to find plugin with this pathname in the current list of
		// plugins.
		if(!(pl_found=find(pl_temp.pathname))) {
			// Check for a matching platform with higher platform specifics
			// level.
			if(NULL != (pl_found=find_match(&pl_temp))) {
				if(pl_found->pfspecific >= pl_temp.pfspecific) {
					META_DEBUG(1, ("ini: Skipping plugin, line %d of %s: plugin with higher platform specific level already exists. (%d >= %d)",
                       		 ln, inifile, pl_found->pfspecific, pl_temp.pfspecific)); 
					continue;
				}
				if(PA_LOAD == pl_found->action) {
					META_DEBUG(1, ("ini: Plugin in line %d overrides loading of plugin with lower platform specific level %d, ours %d",
								ln, pl_found->pfspecific, pl_temp.pfspecific));
					int _index = pl_found->index;
					memset(pl_found, 0, sizeof(MPlugin));
					pl_found->index = _index;
				}
				else {
					META_DEBUG(1, ("ini: Plugin in line %d should override existing plugin with lower platform specific level %d, ours %d. Unable to comply.",
								ln, pl_found->pfspecific, pl_temp.pfspecific));
					continue;
				}
			}
			// new plugin; add to list
			if((pl_added=add(&pl_temp))) {
				// try to load this plugin at the next opportunity
				pl_added->action=PA_LOAD;
			}
			else
				// error details logged in add()
				continue;
		}
		else {
			// This plugin is already in the current list of plugins.
			// Pathname already matches.  Recopy desc, if specified in
			// plugins.ini.
			if(pl_temp.desc[0] != '<')
				STRNCPY(pl_found->desc, pl_temp.desc, sizeof(pl_found->desc));

			// Check the file to see if it looks like it's been modified
			// since we last loaded it.
			if(!pl_found->newer_file()) {
				if(meta_errno==ME_NOFILE) {
					META_ERROR("ini: Skipping plugin, couldn't stat file '%s': %s",
							pl_found->pathname, strerror(errno));
					continue;
				}
				else {
					// File hasn't been updated.
					// Keep plugin (don't let refresh() unload it).
					pl_found->action=PA_KEEP;
				}
			}
			// Newer file on disk.
			else if(pl_found->status >= PL_OPENED)  {
				META_DEBUG(2, ("ini: Plugin '%s' has newer file on disk", pl_found->desc));
				pl_found->action=PA_RELOAD;
			}
			else
				META_ERROR("ini: Plugin '%s' has newer file, but unexpected status (%s)",
						pl_found->desc, pl_found->str_status());
		}
		if(NULL != pl_found) {
			META_LOG("ini: Read plugin config for: %s", pl_found->desc);
		}
		else {
			META_LOG("ini: Read plugin config for: %s", pl_temp.desc);
		}
		n++;
	}
	META_LOG("ini: Finished reading plugins list: %s; Found %d plugins", inifile, n);

	fclose(fp);
	if(!n) {
		META_ERROR("ini: Warning; no plugins found to load?");
	}
	return(mTRUE);
}
Example #29
0
#include <unistd.h>
#include <net/if.h>
#include <stdarg.h>
 #include <sys/wait.h>
#include "../include/seccomp.h"

static struct sock_filter filter[] = {
	VALIDATE_ARCHITECTURE,
	EXAMINE_SYSCALL,

#if defined(__x86_64__)
#define X32_SYSCALL_BIT 0x40000000
	// handle X32 ABI
	BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, X32_SYSCALL_BIT, 1, 0),
	BPF_JUMP(BPF_JMP+BPF_JGE+BPF_K, 0, 1, 0),
	RETURN_ERRNO(EPERM),
#endif

	// syscall list
#ifdef SYS_mount		
	BLACKLIST(SYS_mount),  // mount/unmount filesystems
#endif
#ifdef SYS_umount2		
	BLACKLIST(SYS_umount2),
#endif
#ifdef SYS_ptrace 		
	BLACKLIST(SYS_ptrace), // trace processes
#endif
#ifdef SYS_kexec_file_load		
	BLACKLIST(SYS_kexec_file_load),
#endif
Example #30
0
mBOOL MPluginList::cmd_addload(const char *args) {
	MPlugin pl_temp;
	MPlugin *pl_found, *pl_added;

	// XXX move back to comands_meta ?

	// parse into a temp plugin
	memset(&pl_temp, 0, sizeof(pl_temp));
	if(pl_temp.cmd_parseline(args) != mTRUE) {
		META_CONS("Couldn't parse 'meta load' arguments: %s", args);
		// meta_errno should be already set in cmd_parseline()
		return(mFALSE);
	}

	// resolve given path into a file; accepts various "shortcut"
	// pathnames.
	if(pl_temp.resolve() != mTRUE) {
		// Couldn't find a matching file on disk
		META_CONS("Couldn't resolve given path into a file: %s", 
				pl_temp.file);
		// meta_errno should be already set in resolve()
		return(mFALSE);
	}

	// Try to find plugin with this pathname in the current list of
	// plugins.
	if((pl_found=find(pl_temp.pathname))) {
		// Already in list
		META_CONS("Plugin '%s' already in current list; file=%s desc='%s'", 
				pl_temp.file, pl_found->file, pl_found->desc);
		RETURN_ERRNO(mFALSE, ME_ALREADY);
	}
	// new plugin; add to list
	if(!(pl_added=add(&pl_temp))) {
		META_CONS("Couldn't add plugin '%s' to list; see log", pl_temp.desc);
		// meta_errno should be already set in add()
		return(mFALSE);
	}

	// try to load new plugin
	pl_added->action=PA_LOAD;
	if(!pl_added->load(PT_ANYTIME)) {
		// load failed
		if(meta_errno==ME_DELAYED) 
			META_CONS("Loaded plugin '%s', but will wait to become active, %s", 
					pl_added->desc, pl_added->str_loadable(SL_ALLOWED));
		else if(meta_errno==ME_NOTALLOWED) {
			META_CONS("Plugin '%s' couldn't attach; only allowed %s", 
					pl_added->desc, pl_added->str_loadable(SL_ALLOWED));
			pl_added->clear();
		}
		else if(pl_added->status == PL_OPENED)
			META_CONS("Opened plugin '%s', but failed to attach; see log", pl_added->desc);
		else
			META_CONS("Couldn't load plugin '%s'; see log", pl_added->desc);
		show(0);
		// meta_errno should be already set in load()
		return(mFALSE);
	}
	META_CONS("Loaded plugin '%s' successfully", pl_added->desc);
	show(0);
	return(mTRUE);
}