示例#1
0
void
notify_except(dbref first, dbref exception, const char *msg, dbref who)
{
	dbref room, srch;

	if (first != NOTHING) {

		srch = room = DBFETCH(first)->location;

		if (tp_listeners) {
			notify_from_echo(who, srch, msg, 0);

			if (tp_listeners_env) {
				srch = DBFETCH(srch)->location;
				while (srch != NOTHING) {
					notify_from_echo(who, srch, msg, 0);
					srch = getparent(srch);
				}
			}
		}

		DOLIST(first, first) {
			if ((Typeof(first) != TYPE_ROOM) && (first != exception)) {
				/* don't want excepted player or child rooms to hear */
				notify_from_echo(who, first, msg, 0);
			}
		}
	}
void getpath(int filedesc, int post, char * pathstr, int bs,int fns){
	int firstpost=post;
	int postt=post;
	int error;
	char temp[200];
	char temps[200];
	char par[200];
	strcpy(temp,"");
	strcpy(temps,"/");
	strcpy(par,"");
	while(postt!=0 && postt !=1){
		postt=getparent(filedesc,postt,par,bs,fns);
		sprintf(temps,"/%s%s",par,temp);
	strcpy(temp,temps);
	strcpy(par,"");

	}
	strcpy(pathstr,"");
	strcat(pathstr,temps);
	error=(int)lseek(filedesc, firstpost*bs, SEEK_SET);
	if (error==-1) {
		perror("seeking");
	}
	
}
示例#3
0
PropPtr
regenvprop(dbref *where, const char *propname, int typ)
{
    PropPtr temp;

    temp = get_property(0, propname);
#ifdef DISKBASE
    if (temp)
        propfetch(0, temp);
#endif
    if (temp && (!typ || PropType(temp) == typ))
        return temp;

    while (*where != NOTHING && *where != 0) {
        temp = get_property(*where, propname);
#ifdef DISKBASE
        if (temp)
            propfetch(*where, temp);
#endif
        if (temp && (!typ || PropType(temp) == typ))
            return temp;
        *where = getparent(*where);
    }
    return NULL;
}
示例#4
0
void gui_filterbar_c::show_options(bool show)
{
    if (show && option1 != nullptr)
        return;
    if (!show && option1 == nullptr)
        return;

    if (show)
    {
        int tag = gui->get_free_tag();
        gui_button_c &o1 = MAKE_VISIBLE_CHILD<gui_button_c>(getrid());
        o1.set_check(tag);
        o1.set_handler(DELEGATE(this, option_handler), as_param(1));
        o1.set_face_getter(BUTTON_FACE(check));
        o1.set_text(TTT("Search in messages",337));
        if (search_in_messages)
            o1.mark();

        option1 = &o1;
    } else
    {
        TSDEL( option1 );
    }

    HOLD( getparent() ).as<gui_contactlist_c>().update_filter_pos();
}
示例#5
0
/* If only paternity checks were this easy in real life... 
 * Returns 1 if the given 'child' is contained by the 'parent'.*/
int
isancestor(dbref parent, dbref child)
{
	while (child != NOTHING && child != parent) {
		child = getparent(child);
	}
	return child == parent;
}
示例#6
0
void
envpropqueue(int descr, dbref player, dbref where, dbref trigger, dbref what, dbref xclude,
			 const char *propname, const char *toparg, int mlev, int mt)
{
	while (what != NOTHING) {
		propqueue(descr, player, where, trigger, what, xclude, propname, toparg, mlev, mt);
		what = getparent(what);
	}
}
示例#7
0
static void tek_lib_exec_checkabort(lua_State *L, struct TExecBase *TExecBase,
	TUINT sig)
{
	if (sig & TTASK_SIG_ABORT)
	{
		struct LuaExecTask *parent = getparent(TExecBase);
		if (parent)
			TSignal(parent->task, TTASK_SIG_ABORT);
		luaL_error(L, "received abort signal");
	}
}
示例#8
0
const char *
safegetprop(dbref player, dbref what, dbref perms, const char *inbuf)
{
    const char *ptr;

    while (what != NOTHING) {
	ptr = safegetprop_strict(player, what, perms, inbuf);
        if (!ptr || *ptr) return ptr;
        what = getparent(what);
    }
    return "";
}
示例#9
0
/* checks if object has property, returning 1 if it or any of it's contents has
   the property stated                                                      */
int
has_property(int descr, dbref player, dbref what, const char *type,
             const char *pclass, int value)
{
    dbref things;

    if (has_property_strict(descr, player, what, type, pclass, value))
        return 1;
    for (things = DBFETCH(what)->contents; things != NOTHING;
         things = DBFETCH(things)->next) {
        if (has_property(descr, player, things, type, pclass, value))
            return 1;
    }
    if (tp_lock_envcheck) {
        things = getparent(what);
        while (things != NOTHING) {
            if (has_property_strict(descr, player, things, type, pclass, value))
                return 1;
            things = getparent(things);
        }
    }
    return 0;
}
示例#10
0
const char *
safegetprop_limited(dbref player, dbref what, dbref whom, dbref perms, const char *inbuf)
{
    const char *ptr;

    while (what != NOTHING) {
	if (OWNER(what) == whom || Wizard(what) ||
	    safegetprop_strict(player, what, perms, "~mpi_macros_ok")
	) {
	    ptr = safegetprop_strict(player, what, perms, inbuf);
	    if (!ptr || *ptr) return ptr;
	}
        what = getparent(what);
    }
    return "";
}
示例#11
0
/*
 * Handle WDS discovery; create a WDS vap for the specified bssid.
 * If a vap already exists then do nothing (can happen when a flood
 * of 4-address frames causes multiple events to be queued before
 * we create a vap).
 */
static void
wds_discovery(const char *ifname, const uint8_t bssid[IEEE80211_ADDR_LEN])
{
	struct wds *p;
	char parent[256];
	char cmd[1024];
	int status;

	for (p = wds; p != NULL; p = p->next)
		if (IEEE80211_ADDR_EQ(p->bssid, bssid)) {
			syslog(LOG_INFO, "[%s] wds vap already created (%s)",
			    ether_sprintf(bssid), ifname);
			return;
		}
	if (getparent(ifname, parent) < 0) {
		syslog(LOG_ERR, "%s: no pointer to parent interface: %m",
		    ifname);
		return;
	}

	p = malloc(sizeof(struct wds));
	if (p == NULL) {
		syslog(LOG_ERR, "%s: malloc failed: %m", __func__);
		return;
	}
	IEEE80211_ADDR_COPY(p->bssid, bssid);
	if (wds_vap_create(parent, p) < 0) {
		free(p);
		return;
	}
	/*
	 * Add to table and launch setup script.
	 */
	p->next = wds;
	wds = p;
	syslog(LOG_INFO, "[%s] create wds vap %s", ether_sprintf(bssid),
	    p->ifname);
	if (script != NULL) {
		snprintf(cmd, sizeof(cmd), "%s %s", script, p->ifname);
		status = system(cmd);
		if (status)
			syslog(LOG_ERR, "vap setup script %s exited with "
			    "status %d", script, status);
	}
}
示例#12
0
const char *
safegetprop_limited(dbref player, dbref what, dbref whom, dbref perms, const char *inbuf, int mesgtyp, int* blessed)
{
	const char *ptr;

	while (what != NOTHING) {
		ptr = safegetprop_strict(player, what, perms, inbuf, mesgtyp, blessed);
		if (!ptr)
			return ptr;
		if (*ptr) {
			if (OWNER(what) == whom || *blessed) {
				return ptr;
			}
		}
		what = getparent(what);
	}
	return "";
}
示例#13
0
/*
 * Check if the specified ifnet is one we're supposed to monitor.
 * The ifnet is assumed to be a vap; we find it's parent and check
 * it against the set of ifnet's specified on the command line.
 */
static int
checkifnet(const char *ifname, int complain)
{
	char parent[256];
	int i;

	if (getparent(ifname, parent) < 0) {
		if (complain)
			syslog(LOG_ERR,
			   "%s: no pointer to parent interface: %m", ifname);
		return 0;
	}

	for (i = 0; i < nifnets; i++)
		if (strcasecmp(ifnets[i], "any") == 0 ||
		    strcmp(ifnets[i], parent) == 0)
			return 1;
	syslog(LOG_DEBUG, "%s: parent %s not being monitored", ifname, parent);
	return 0;
}
示例#14
0
static TAPTR tek_lib_exec_locktask(struct TExecBase *TExecBase,
	const char *name, TAPTR *ref)
{
	if (name && strcmp(name, "*p") != 0)
	{
		char atomname[TEK_LIB_TASKNAME_LEN];
		tek_lib_exec_taskname(atomname, name);
		*ref = TLockAtom(atomname, TATOMF_NAME | TATOMF_SHARED);
		if (*ref)
			return (TAPTR) TGetAtomData(*ref);
	}
	else
	{
		struct LuaExecTask *parent = getparent(TExecBase);
		*ref = TNULL;
		if (parent)
			return parent->task;
	}
	return TNULL;
}
示例#15
0
PropPtr
envprop_cmds(dbref *where, const char *propname, int typ)
{
    PropPtr temp;

    while (*where != NOTHING) {
        if (typ ? 1
            : ((FLAG2(*where) & F2COMMAND) && !(FLAG2(*where) & F2NO_COMMAND)
               && ((FLAGS(OWNER(*where)) & BUILDER)
                   || (MLevel(OWNER(*where)) >= LMAGE)))) {
            temp = get_property(*where, propname);
#ifdef DISKBASE
            if (temp)
                propfetch(*where, temp);
#endif
            if (temp)
                return temp;
        }
        *where = getparent(*where);
    }
    return NULL;
}
示例#16
0
文件: fileio.cpp 项目: sintrb/nesa
/*
该函数用于安全的打开文件
2013-12-09
16:15
*/
FILE * fileio::safeopen(const char *fname, const char *status)
{
	TYPE_FILENAME cfn = gloab::g_filepoint.getfilename();
	TYPE_FILENAME fn = fname;
	FILE *fp;
	fp = inopen(fname, status);
	if(!fp && !isabspath(fname) && cfn != ""){
		strprocess::killfbspace(cfn);
		TYPE_FILENAME pp = getparent(cfn);
		if(pp != ""){
			fn = pp+fname;
			fp = inopen(fn, status);
		}
	}

	if(fp){
//		gloab::g_filepoint.set(fn);
		return fp;
	}
	errorprocess::showerr(ERR_HAVANO_FILE, fname);
	return NULL;
}
示例#17
0
bool gui_filterbar_c::do_contact_check(RID, GUIPARAM p)
{
    for (int n = ts::tmax(1, contacts().count() / 10 ); contact_index < contacts().count() && n > 0; --n)
    {
        contact_c &c = contacts().get(contact_index++);
        if (c.is_rootcontact())
        {
            contact_root_c *cr = ts::ptr_cast<contact_root_c *>(&c);

            if (cr->is_full_search_result())
            {
                cr->full_search_result(false);
                if (cr->gui_item) cr->gui_item->update_text();
            }

            if (cr->gui_item)
            {
                MODIFY(*cr->gui_item).visible(check_one(cr));
            }
        }
    }

    if (contact_index < contacts().count())
    {
        if (active)
        {
            gui_contactlist_c &cl = HOLD(getparent()).as<gui_contactlist_c>();
            cl.scroll_to_child(active, false);
        }
        DEFERRED_UNIQUE_CALL(0, DELEGATE(this, do_contact_check), 0);
    }
    else
    {
        apply_full_text_search_result();
    }

    return true;
}
示例#18
0
void gui_filterbar_c::apply_full_text_search_result()
{
    for (found_item_s &itm : found_stuff.items)
        if (contact_root_c *c = contacts().rfind(itm.historian))
        {
            c->full_search_result(true);
            if (c->gui_item)
            {
                c->gui_item->update_text();
                MODIFY(*c->gui_item).show();
            }
        }

    if (active)
    {
        gui_contactlist_c &cl = HOLD(getparent()).as<gui_contactlist_c>();
        cl.scroll_to_child(active, false);
    }

    gmsg<ISOGM_REFRESH_SEARCH_RESULT>().send();


}
示例#19
0
int main(int argc, char **argv) {
  char *end, *item = NULL, *path;
  pid_t child = -1, parent, pid;
  size_t size;
  struct dirent *entry;
  DIR *dir;
  FILE *file;

  if (argc < 2)
    usage(argv[0]);

  parent = strtol(argv[1], &end, 10);
  if (end == argv[1] || *end)
    usage(argv[0]);

  if (geteuid() != getuid())
    error(1, 0, "setuid installation is unsafe");
  else if (getegid() != getgid())
    error(1, 0, "setgid installation is unsafe");

  join(parent, "user");
  setgid(0);
  setgroups(0, NULL);
  setuid(0);

  if (!(dir = opendir("/proc")))
    error(1, 0, "Failed to list processes");
  while (child < 0 && (entry = readdir(dir))) {
    pid = strtol(entry->d_name, &end, 10);
    if (end == entry->d_name || *end)
      continue;
    if (getparent(pid) == parent) {
      path = string("/proc/%u/environ", pid);
      if ((file = fopen(path, "r"))) {
        while (getdelim(&item, &size, '\0', file) >= 0)
          if (strcmp(item, "container=contain") == 0)
            child = pid;
        fclose(file);
      }
      free(path);
    }
  }
  closedir(dir);
  if (item)
    free(item);

  if (child < 0)
    error(1, 0, "PID %u is not a container supervisor", parent);

  join(child, "ipc");
  join(child, "net");
  join(child, "pid");
  join(child, "uts");
  join(child, "mnt");

  if (chdir("/") < 0)
    error(1, 0, "Failed to enter container root directory");

  switch (child = fork()) {
    case -1:
      error(1, errno, "fork");
    case 0:
      if (argv[2])
        execvp(argv[2], argv + 2);
      else if (getenv("SHELL"))
        execl(getenv("SHELL"), getenv("SHELL"), NULL);
      else
        execl(SHELL, SHELL, NULL);
      error(1, errno, "exec");
  }

  waitforexit(child);
  return EXIT_SUCCESS;
}
示例#20
0
static int tek_lib_exec_child_sigjoin(lua_State *L, TUINT sig, TBOOL sigparent,
	TBOOL do_results)
{
	struct LuaExecChild *ctx = luaL_checkudata(L, 1, TEK_LIB_TASK_CLASSNAME);
	struct TExecBase *TExecBase = ctx->exec;
	struct TTask *self = TFindTask(TNULL), *task = ctx->task;
	union TTaskRequest *req = &self->tsk_Request;
	TBOOL abort = TFALSE;
	int nres = 0;
	if (!task)
		return 0;
	
	TDBPRINTF(TDB_TRACE,("child_join sig=%d sigparent=%d\n", sig, sigparent));
	
	/* signal task */
	TSignal(task, sig);
	/* prepare destroy request */
	self->tsk_ReqCode = TTREQ_DESTROYTASK;
	req->trq_Task.trt_Task = task;
	/* send to exec */
	TPutMsg(TExecBase->texb_ExecPort, &self->tsk_SyncPort, self);
	for (;;)
	{
		/* wait for return of request or receiving abort ourselves: */
		TUINT sig = TWait(TTASK_SIG_SINGLE | TTASK_SIG_ABORT);
		if (sig & TTASK_SIG_SINGLE)
			break;
		if (sig & TTASK_SIG_ABORT)
		{
			/* forward to child task */
			TSignal(task, TTASK_SIG_ABORT);
			if (sigparent)
			{
				/* also forward to own parent task */
				struct LuaExecTask *parent = getparent(TExecBase);
				if (parent)
					TSignal(parent->task, TTASK_SIG_ABORT);
				abort = TTRUE;
			}
		}
	}
	/* take delivery of replied destroy request */
	TGetMsg(&self->tsk_SyncPort);
	/* free task */	
	TFreeTask(task);
	
	ctx->task = TNULL;
	tek_lib_exec_freectxargs(ctx);
	if (!abort && do_results)
	{
		int i;
		nres = ctx->numres + 1;
		lua_pushboolean(L, ctx->luastatus == 0);
		for (i = 0; i < ctx->numres; ++i)
			lua_pushlstring(L, ctx->results[i].arg, ctx->results[i].len);
	}
	tek_lib_exec_freeargs(TExecBase, ctx->results, ctx->numres);
	luaL_unref(L, lua_upvalueindex(1), ctx->ref);
	if (abort)
		luaL_error(L, "received abort signal");
	return nres;
}
示例#21
0
文件: xfs_fsr.c 项目: crossmeta/sgi
/*
 * Sets up the defragmentation of a file based on the 
 * filepath.  It collects the bstat information, does 
 * an open on the file and passes this all to fsrfile_common.
 */
static int
fsrfile(char *fname, xfs_ino_t ino)
{
	xfs_bstat_t	statbuf;
	jdm_fshandle_t	*fshandlep;
	int	fd, fsfd;
	int	error = 0;
	char	*tname;

	fshandlep = jdm_getfshandle(getparent (fname) );
	if (! fshandlep) {
		fsrprintf(
		  "unable to construct sys handle for %s: %s\n",
		  fname, strerror(errno));
		return -1;
	}

	/*
	 * Need to open something on the same filesystem as the
	 * file.  Open the parent.
	 */
	fsfd = open(getparent(fname), O_RDONLY);
	if (fsfd < 0) {
		fsrprintf(
		  "unable to open sys handle for %s: %s\n",
		  fname, strerror(errno));
		return -1;
	}
	
	if ((xfs_bulkstat_single(fsfd, &ino, &statbuf)) < 0) {
		fsrprintf(
		  "unable to get bstat on %s: %s\n",
		  fname, strerror(errno));
		close(fsfd);
		return -1;
	}
		
	fd = jdm_open( fshandlep, &statbuf, O_RDWR);
	if (fd < 0) {
		fsrprintf(
		  "unable to open handle %s: %s\n",
		  fname, strerror(errno));
		close(fsfd);
		return -1;
	}

	/* Get the fs geometry */
	if (xfs_getgeom(fsfd, &fsgeom) < 0 ) {
		fsrprintf("Unable to get geom on fs for: %s\n", fname);
		close(fsfd);
		return -1;
	}

	close(fsfd);

	tname = gettmpname(fname);

	if (tname)
		error = fsrfile_common(fname, tname, NULL, fd, &statbuf);

	close(fd);

	return error;
}
示例#22
0
bool gui_filterbar_c::update_filter(const ts::wstr_c & e)
{
    ts::wstrings_c ospl( found_stuff.fsplit );
    found_stuff.fsplit.split<ts::wchar>(e, ' ');
    found_stuff.fsplit.trim();
    found_stuff.fsplit.kill_empty_fast();
    found_stuff.fsplit.case_down();

    // kill dups
    for(int i = found_stuff.fsplit.size() - 1;i>=0;--i)
    {
        for(int j = i-1;j>=0;--j)
            if ( found_stuff.fsplit.get(j).equals( found_stuff.fsplit.get(i) ) )
            {
                found_stuff.fsplit.remove_fast(i);
                break;
            }
    }

    // sort by length
    found_stuff.fsplit.sort([](const ts::wstr_c &s1,const ts::wstr_c &s2)->bool { return s1.get_length() == s2.get_length() ? (ts::wstr_c::compare(s1,s2) > 0) : s1.get_length() > s2.get_length(); });

    if (!tagschanged && found_stuff.fsplit == ospl)
        return true;

    if (current_search)
    {
        current_search->no_need = true;
        current_search = nullptr;
    }

    show_options(0 != found_stuff.fsplit.size());

    if (!tagschanged && is_all())
    {
        found_stuff.items.clear();
        gui_contactlist_c &cl = HOLD(getparent()).as<gui_contactlist_c>();
        cl.on_filter_deactivate(RID(),nullptr);
        return true;
    }

    if (search_in_messages && found_stuff.fsplit.size())
    {
        current_search = TSNEW( full_search_s, prf().get_db(), this, found_stuff.fsplit );
        found_stuff.items.clear();
        g_app->add_task( current_search );
    } else
        found_stuff.items.clear();


    active = g_app->active_contact_item ? &g_app->active_contact_item->getengine() : nullptr;

    if (!active)
    {
        gui_contactlist_c &cl = HOLD(getparent()).as<gui_contactlist_c>();
        active = cl.get_first_contact_item();
    }

    tagschanged = false;
    contact_index = 1;
    do_contact_check(RID(),nullptr);
    return true;
}
示例#23
0
文件: mfuns.c 项目: rhencke/fuzzball
const char *
mfn_select(MFUNARGS)
{
	char origprop[BUFFER_LEN];
	char propname[BUFFER_LEN];
	char bestname[BUFFER_LEN];
	dbref obj = what;
	dbref bestobj = 0;
	char *pname;
	const char *ptr;
	char *out, *in;
	int i, targval, bestval;
	int baselen;
	int limit;
	int blessed = 0;

	pname = argv[1];
	if (argc == 3) {
		obj = mesg_dbref(descr, player, what, perms, argv[2], mesgtyp);
	}
	if (obj == PERMDENIED)
		ABORT_MPI("SELECT", "Permission denied.");
	if (obj == UNKNOWN || obj == AMBIGUOUS || obj == NOTHING || obj == HOME)
		ABORT_MPI("SELECT", "Match failed.");

	/*
	 * Search contiguously for a bit, looking for a best match.
	 * This allows fast hits on LARGE lists.
	 */

	limit = 18;
	i = targval = atoi(argv[0]);
	do {
		ptr = get_list_item(player, obj, perms, (char *)pname, i--, mesgtyp, &blessed);
	} while (limit-->0 && i >= 0 && ptr && !*ptr);
	if (ptr == NULL)
		ABORT_MPI("SELECT", "Failed list read.");
	if (*ptr != '\0')
		return ptr;

	/*
	 * If we didn't find it before, search only existing props.
	 * This gets fast hits on very SPARSE lists.
	 */

	/* First, normalize the base propname */
	out = origprop;
	in = argv[1];
	while (*in != '\0') {
		*out++ = PROPDIR_DELIMITER;
		while (*in == PROPDIR_DELIMITER) in++;
		while (*in && *in != PROPDIR_DELIMITER) *out++ = *in++;
	}
	*out++ = '\0';

	i = targval;
	bestname[0] = '\0';
	bestval = 0;
	baselen = strlen(origprop);
	for (; obj != NOTHING; obj = getparent(obj)) {
		pname = next_prop_name(obj, propname, sizeof(propname), origprop);
		while (pname && string_prefix(pname, origprop)) {
			ptr = pname + baselen;
			if (*ptr == NUMBER_TOKEN) ptr++;
			if (!*ptr && is_propdir(obj, pname)) {
				char propname2[BUFFER_LEN];
				char *pname2;
				int sublen = strlen(pname);

				pname2 = strcpyn(propname2, sizeof(propname2), pname);
				propname2[sublen++] = PROPDIR_DELIMITER;
				propname2[sublen] = '\0';

				pname2 = next_prop_name(obj, propname2, sizeof(propname2), pname2);
				while (pname2) {
					ptr = pname2 + sublen;
					if (number(ptr)) {
						i = atoi(ptr);
						if (bestval < i && i <= targval) {
							bestval = i;
							bestobj = obj;
							strcpyn(bestname, sizeof(bestname), pname2);
						}
					}
					pname2 = next_prop_name(obj, propname2, sizeof(propname2), pname2);
				}
			}
			ptr = pname + baselen;
			if (number(ptr)) {
				i = atoi(ptr);
				if (bestval < i && i <= targval) {
					bestval = i;
					bestobj = obj;
					strcpyn(bestname, sizeof(bestname), pname);
				}
			}
			pname = next_prop_name(obj, propname, sizeof(propname), pname);
		}
	}
	
	if (*bestname) {
		ptr = safegetprop_strict(player, bestobj, perms, bestname, mesgtyp, &blessed);
		if (!ptr)
			ABORT_MPI("SELECT", "Failed property read.");
	} else {
		ptr = "";
	}
	return ptr;
}
	value_type path_compression(const value_type& x) {
		if (getparent(x) != x)
			setparent(x, path_compression(getparent(x)));
		return getparent(x);
	}