示例#1
0
/** Remove a message from the lookup trie.
 * @param[in,out] mtree_p Trie node to remove command from.
 * @param[in] cmd Text of command to remove.
 */
struct MessageTree *
del_msg_element(struct MessageTree *mtree_p, char *cmd)
{
  int slot = *cmd & (MAXPTRLEN-1);

  /* Either remove leaf message or from appropriate child. */
  if (*cmd == '\0')
    mtree_p->msg = NULL;
  else
    mtree_p->pointers[slot] = del_msg_element(mtree_p->pointers[slot], cmd + 1);

  /* If current message or any child still exists, keep this node. */
  if (mtree_p->msg)
    return mtree_p;
  for (slot = 0; slot < MAXPTRLEN; ++slot)
    if (mtree_p->pointers[slot])
      return mtree_p;

  /* Otherwise, if we're not a root node, free it and return null. */
  if (mtree_p != &msg_tree && mtree_p != &tok_tree)
    MyFree(mtree_p);
  return NULL;
}
/*
 * auth_timeout - timeout a given auth request
 */
static void auth_timeout_callback(struct Event* ev)
{
  struct AuthRequest* auth;

  assert(0 != ev_timer(ev));
  assert(0 != t_data(ev_timer(ev)));

  auth = t_data(ev_timer(ev));

  if (ev_type(ev) == ET_DESTROY) { /* being destroyed */
    auth->flags &= ~AM_TIMEOUT;

    if (!(auth->flags & AM_FREE_MASK)) {
      Debug((DEBUG_LIST, "Freeing auth from timeout callback; %p [%p]", auth,
	     ev_timer(ev)));
      MyFree(auth); /* done with it, finally */
    }
  } else {
    assert(ev_type(ev) == ET_EXPIRE);

    destroy_auth_request(auth, 1);
  }
}
示例#3
0
文件: uping.c 项目: DamnIO/DamnIRCd
/** Timer callback to stop upings.
 * @param[in] ev Event for uping expiration.
 */
static void uping_killer_callback(struct Event* ev)
{
  struct UPing *pptr;

  assert(0 != ev_timer(ev));
  assert(0 != t_data(ev_timer(ev)));

  pptr = (struct UPing*) t_data(ev_timer(ev));

  Debug((DEBUG_SEND, "uping_killer_callback called, %p (%d)", pptr,
	 ev_type(ev)));

  if (ev_type(ev) == ET_DESTROY) { /* being destroyed */
    pptr->freeable &= ~UPING_PENDING_KILLER;

    if (!pptr->freeable)
      MyFree(pptr); /* done with it, finally */
  } else {
    assert(ev_type(ev) == ET_EXPIRE);

    uping_end(pptr); /* <FUDD>kill the uping, kill the uping!</FUDD> */
  }
}
示例#4
0
文件: uping.c 项目: DamnIO/DamnIRCd
/** Callback for socket activity on an outbound uping socket.
 * @param[in] ev I/O event for socket.
 */
static void uping_read_callback(struct Event* ev)
{
  struct UPing *pptr;

  assert(0 != ev_socket(ev));
  assert(0 != s_data(ev_socket(ev)));

  pptr = (struct UPing*) s_data(ev_socket(ev));

  Debug((DEBUG_SEND, "uping_read_callback called, %p (%d)", pptr,
	 ev_type(ev)));

  if (ev_type(ev) == ET_DESTROY) { /* being destroyed */
    pptr->freeable &= ~UPING_PENDING_SOCKET;

    if (!pptr->freeable)
      MyFree(pptr); /* done with it, finally */
  } else {
    assert(ev_type(ev) == ET_READ || ev_type(ev) == ET_ERROR);

    uping_read(pptr); /* read uping response */
  }
}
示例#5
0
文件: dde.c 项目: chunhualiu/OpenNT
/****************************************************************************
 *                                                                          *
 *  FUNCTION   : CompleteTransaction()                                      *
 *                                                                          *
 *  PURPOSE    : This handles completed synchronous and asynchronous        *
 *               transactions as well as failed attempted transactions.     *
 *                                                                          *
 *  RETURNS    : TRUE  - If successful.                                     *
 *               FALSE - otherwise.                                         *
 *                                                                          *
 ****************************************************************************/
VOID CompleteTransaction(
HWND hwndInfoCtrl,
XACT *pxact)
{
    PSTR psz;
    
    if (pxact->ret) {
        /*
         * Successful transaction case
         */
        SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_LL,
                (DWORD)(LPSTR)"Completed");
    
        if (pxact->wType == XTYP_REQUEST) {
            /*
             * Show resulting data
             */
            psz = GetTextData((HDDEDATA)pxact->ret);
            SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_CENTER,
                    (DWORD)(LPSTR)psz);
            MyFree(psz);
            /*
             * free returned data since it is displayed.
             */
            DdeFreeDataHandle(pxact->ret);
            pxact->ret = 0L;
            SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_UR, NULL);
        }
    } else {
        /*
         * failed - show error result.
         */
        SendMessage(hwndInfoCtrl, ICM_SETSTRING, ICSID_LL,
                (DWORD)(LPSTR)Error2String(DdeGetLastError(idInst)));
    }
    pxact->fsOptions |= XOPT_COMPLETED;
}
示例#6
0
static int init_finish(adns_state ads) {
  struct in_addr ia;
  int r;
  
  if (!ads->nservers) {
    if (ads->diagfile && ads->iflags & adns_if_debug)
      fprintf(ads->diagfile,"adns: no nameservers, using localhost\n");
    ia.s_addr= htonl(INADDR_LOOPBACK);
    addserver(ads,ia);
  }
  ads->udpsocket= socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
  if (ads->udpsocket<0) { r= errno; goto x_free; }

  r= adns__setnonblock(ads,ads->udpsocket);
  if (r) { r= errno; goto x_closeudp; }
  
  return 0;

 x_closeudp:
  close(ads->udpsocket);
 x_free:
  MyFree(ads);
  return r;
}
示例#7
0
void EDA_LibComponentStruct::SortDrawItems(void)
/*******************************************/
/* Trie les éléments graphiques d'un composant lib pour améliorer
le tracé:
items remplis en premier, pins en dernier
En cas de superposition d'items, c'est plus lisible
*/
{
LibEDA_BaseStruct ** Bufentry, ** BufentryBase, *Entry = m_Drawings;
int ii, nbitems;

	if(Entry == NULL ) return; /* Pas d'alias pour ce composant */
	/* calcul du nombre d'items */
	for( nbitems = 0; Entry != NULL; Entry = Entry->Next()) nbitems++;

	BufentryBase =
		(LibEDA_BaseStruct **) MyZMalloc( (nbitems+1) * sizeof(LibEDA_BaseStruct *));
	/* memorisation du chainage : */
	for( Entry = m_Drawings, ii = 0; Entry != NULL; Entry = Entry->Next())
		BufentryBase[ii++] = Entry;

	/* Tri du chainage */
	qsort(BufentryBase, nbitems, sizeof(LibEDA_BaseStruct *), SortItemsFct);

	/* Mise a jour du chainage. Remarque:
	le dernier element de BufEntryBase (BufEntryBase[nbitems]) est NULL*/
	m_Drawings = * BufentryBase;
	Bufentry = BufentryBase;
	for (ii = 0 ; ii < nbitems; ii++)
	{
		(* Bufentry)->Pnext = * (Bufentry+1);
		Bufentry++;
	}

	MyFree(BufentryBase);
}
示例#8
0
CDynLimBuf &CDynLimBuf::operator+=(const char *s) throw()
{
  if (_error)
    return *this;
  unsigned len = MyStringLen(s);
  size_t rem = _sizeLimit - _pos;
  if (rem < len)
  {
    len = (unsigned)rem;
    _error = true;
  }
  if (_size - _pos < len)
  {
    size_t n = _pos + len;
    if (n - _size < _size)
    {
      n = _sizeLimit;
      if (n - _size > _size)
        n = _size * 2;
    }

    Byte *newBuf = (Byte *)MyAlloc(n);
    if (!newBuf)
    {
      _error = true;
      return *this;
    }
    memcpy(newBuf, _chars, _pos);
    MyFree(_chars);
    _chars = newBuf;
    _size = n;
  }
  memcpy(_chars + _pos, s, len);
  _pos += len;
  return *this;
}
示例#9
0
void UmodeDel(Umode *umode)
{
	if (loop.ircd_rehashing)
		umode->unloaded = 1;
	else	
	{
		aClient *cptr;
		for (cptr = client; cptr; cptr = cptr->next)
		{
			long oldumode = 0;
			if (!IsPerson(cptr))
				continue;
			oldumode = cptr->umodes;
			cptr->umodes &= ~umode->mode;
			if (MyClient(cptr))
				send_umode_out(cptr, cptr, oldumode);
		}
		umode->flag = '\0';
		AllUmodes &= ~(umode->mode);
		SendUmodes &= ~(umode->mode);
		make_umodestr();
	}

	if (umode->owner) {
		ModuleObject *umodeobj;
		for (umodeobj = umode->owner->objects; umodeobj; umodeobj = umodeobj->next) {
			if (umodeobj->type == MOBJ_UMODE && umodeobj->object.umode == umode) {
				DelListItem(umodeobj, umode->owner->objects);
				MyFree(umodeobj);
				break;
			}
		}
		umode->owner = NULL;
	}
	return;
}
示例#10
0
文件: Lzma86Enc.c 项目: borneq/bind7z
int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
    int level, UInt32 dictSize, int filterMode)
{
  ISzAlloc g_Alloc = { SzAlloc, SzFree };
  size_t outSize2 = *destLen;
  Byte *filteredStream;
  Bool useFilter;
  int mainResult = SZ_ERROR_OUTPUT_EOF;
  CLzmaEncProps props;
  LzmaEncProps_Init(&props);
  props.level = level;
  props.dictSize = dictSize;

  *destLen = 0;
  if (outSize2 < LZMA86_HEADER_SIZE)
    return SZ_ERROR_OUTPUT_EOF;

  {
    int i;
    UInt64 t = srcLen;
    for (i = 0; i < 8; i++, t >>= 8)
      dest[LZMA86_SIZE_OFFSET + i] = (Byte)t;
  }

  filteredStream = 0;
  useFilter = (filterMode != SZ_FILTER_NO);
  if (useFilter)
  {
    if (srcLen != 0)
    {
      filteredStream = (Byte *)MyAlloc(srcLen);
      if (filteredStream == 0)
        return SZ_ERROR_MEM;
      memcpy(filteredStream, src, srcLen);
    }
    {
      UInt32 x86State;
      x86_Convert_Init(x86State);
      x86_Convert(filteredStream, srcLen, 0, &x86State, 1);
    }
  }

  {
    size_t minSize = 0;
    Bool bestIsFiltered = False;

    /* passes for SZ_FILTER_AUTO:
        0 - BCJ + LZMA
        1 - LZMA
        2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.
    */
    int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;

    int i;
    for (i = 0; i < numPasses; i++)
    {
      size_t outSizeProcessed = outSize2 - LZMA86_HEADER_SIZE;
      size_t outPropsSize = 5;
      SRes curRes;
      Bool curModeIsFiltered = (numPasses > 1 && i == numPasses - 1);
      if (curModeIsFiltered && !bestIsFiltered)
        break;
      if (useFilter && i == 0)
        curModeIsFiltered = True;

      curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,
          curModeIsFiltered ? filteredStream : src, srcLen,
          &props, dest + 1, &outPropsSize, 0,
          NULL, &g_Alloc, &g_Alloc);

      if (curRes != SZ_ERROR_OUTPUT_EOF)
      {
        if (curRes != SZ_OK)
        {
          mainResult = curRes;
          break;
        }
        if (outSizeProcessed <= minSize || mainResult != SZ_OK)
        {
          minSize = outSizeProcessed;
          bestIsFiltered = curModeIsFiltered;
          mainResult = SZ_OK;
        }
      }
    }
    dest[0] = (Byte)(bestIsFiltered ? 1 : 0);
    *destLen = LZMA86_HEADER_SIZE + minSize;
  }
  if (useFilter)
    MyFree(filteredStream);
  return mainResult;
}
示例#11
0
/*
** m_nick
**	parv[0] = sender prefix
**	parv[1] = nickname
**  if from new client  -taz
**	parv[2] = nick password
**  if from server:
**      parv[2] = hopcount
**      parv[3] = timestamp
**      parv[4] = username
**      parv[5] = hostname
**      parv[6] = servername
**  if NICK version 1:
**      parv[7] = servicestamp
**	parv[8] = info
**  if NICK version 2:
**	parv[7] = servicestamp
**      parv[8] = umodes
**	parv[9] = virthost, * if none
**	parv[10] = info
**  if NICKIP:
**      parv[10] = ip
**      parv[11] = info
*/
DLLFUNC CMD_FUNC(m_nick)
{
	aTKline *tklban;
	int ishold;
	aClient *acptr, *serv = NULL;
	aClient *acptrs;
	char nick[NICKLEN + 2], *s;
	Membership *mp;
	time_t lastnick = (time_t) 0;
	int  differ = 1, update_watch = 1;
	unsigned char newusr = 0, removemoder = 1;
	/*
	 * If the user didn't specify a nickname, complain
	 */
	if (parc < 2)
	{
		sendto_one(sptr, err_str(ERR_NONICKNAMEGIVEN),
		    me.name, parv[0]);
		return 0;
	}

	strncpyzt(nick, parv[1], NICKLEN + 1);

	if (MyConnect(sptr) && sptr->user && !IsAnOper(sptr))
	{
		if ((sptr->user->flood.nick_c >= NICK_COUNT) && 
		    (TStime() - sptr->user->flood.nick_t < NICK_PERIOD))
		{
			/* Throttle... */
			sendto_one(sptr, err_str(ERR_NCHANGETOOFAST), me.name, sptr->name, nick,
				(int)(NICK_PERIOD - (TStime() - sptr->user->flood.nick_t)));
			return 0;
		}
	}

	/* For a local clients, do proper nickname checking via do_nick_name()
	 * and reject the nick if it returns false.
	 * For remote clients, do a quick check by using do_remote_nick_name(),
	 * if this returned false then reject and kill it. -- Syzop
	 */
	if ((IsServer(cptr) && !do_remote_nick_name(nick)) ||
	    (!IsServer(cptr) && !do_nick_name(nick)))
	{
		sendto_one(sptr, err_str(ERR_ERRONEUSNICKNAME),
		    me.name, parv[0], parv[1], "Illegal characters");

		if (IsServer(cptr))
		{
			ircstp->is_kill++;
			sendto_failops("Bad Nick: %s From: %s %s",
			    parv[1], parv[0], get_client_name(cptr, FALSE));
			sendto_one(cptr, ":%s KILL %s :%s (%s <- %s[%s])",
			    me.name, parv[1], me.name, parv[1],
			    nick, cptr->name);
			if (sptr != cptr)
			{	/* bad nick change */
				sendto_serv_butone(cptr,
				    ":%s KILL %s :%s (%s <- %s!%s@%s)",
				    me.name, parv[0], me.name,
				    get_client_name(cptr, FALSE),
				    parv[0],
				    sptr->user ? sptr->username : "",
				    sptr->user ? sptr->user->server :
				    cptr->name);
				sptr->flags |= FLAGS_KILLED;
				return exit_client(cptr, sptr, &me, "BadNick");
			}
		}
		return 0;
	}

	/* Kill quarantined opers early... */
	if (IsServer(cptr) && (sptr->from->flags & FLAGS_QUARANTINE) &&
	    (parc >= 11) && strchr(parv[8], 'o'))
	{
		ircstp->is_kill++;
		/* Send kill to uplink only, hasn't been broadcasted to the rest, anyway */
		sendto_one(cptr, ":%s KILL %s :%s (Quarantined: no global oper privileges allowed)",
			me.name, parv[1], me.name);
		sendto_realops("QUARANTINE: Oper %s on server %s killed, due to quarantine",
			parv[1], sptr->name);
		/* (nothing to exit_client or to free, since user was never added) */
		return 0;
	}

	/*
	   ** Protocol 4 doesn't send the server as prefix, so it is possible
	   ** the server doesn't exist (a lagged net.burst), in which case
	   ** we simply need to ignore the NICK. Also when we got that server
	   ** name (again) but from another direction. --Run
	 */
	/*
	   ** We should really only deal with this for msgs from servers.
	   ** -- Aeto
	 */
	if (IsServer(cptr) &&
	    (parc > 7
	    && (!(serv = (aClient *)find_server_b64_or_real(parv[6]))
	    || serv->from != cptr->from)))
	{
		sendto_realops("Cannot find server %s (%s)", parv[6],
		    backupbuf);
		return 0;
	}
	/*
	   ** Check against nick name collisions.
	   **
	   ** Put this 'if' here so that the nesting goes nicely on the screen :)
	   ** We check against server name list before determining if the nickname
	   ** is present in the nicklist (due to the way the below for loop is
	   ** constructed). -avalon
	 */
	/* I managed to f**k this up i guess --stskeeps */
	if ((acptr = find_server(nick, NULL)))
	{
		if (MyConnect(sptr))
		{
#ifdef GUEST
			if (IsUnknown(sptr))
			{
				RunHook4(HOOKTYPE_GUEST, cptr, sptr, parc, parv);
				return 0;
			}
#endif
			sendto_one(sptr, err_str(ERR_NICKNAMEINUSE), me.name,
			    BadPtr(parv[0]) ? "*" : parv[0], nick);
			return 0;	/* NICK message ignored */
		}
	}

	/*
	   ** Check for a Q-lined nickname. If we find it, and it's our
	   ** client, just reject it. -Lefler
	   ** Allow opers to use Q-lined nicknames. -Russell
	 */
	if (!stricmp("ircd", nick))
	{
		sendto_one(sptr, err_str(ERR_ERRONEUSNICKNAME), me.name,
		    BadPtr(parv[0]) ? "*" : parv[0], nick,
		    "Reserved for internal IRCd purposes");
		return 0;
	}
	if (!stricmp("irc", nick))
	{
		sendto_one(sptr, err_str(ERR_ERRONEUSNICKNAME), me.name,
		    BadPtr(parv[0]) ? "*" : parv[0], nick,
		    "Reserved for internal IRCd purposes");
		return 0;
	}
	if (MyClient(sptr)) /* local client changin nick afterwards.. */
	{
		int xx;
		spamfilter_build_user_string(spamfilter_user, nick, sptr);
		xx = dospamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, NULL);
		if (xx < 0)
			return xx;
	}
	if (!IsULine(sptr) && (tklban = find_qline(sptr, nick, &ishold)))
	{
		if (IsServer(sptr) && !ishold) /* server introducing new client */
		{
			acptrs =
			    (aClient *)find_server_b64_or_real(sptr->user ==
			    NULL ? (char *)parv[6] : (char *)sptr->user->
			    server);
			/* (NEW: no unregistered q:line msgs anymore during linking) */
			if (!acptrs || (acptrs->serv && acptrs->serv->flags.synced))
				sendto_snomask(SNO_QLINE, "Q:lined nick %s from %s on %s", nick,
				    (*sptr->name != 0
				    && !IsServer(sptr) ? sptr->name : "<unregistered>"),
				    acptrs ? acptrs->name : "unknown server");
		}
		
		if (IsServer(cptr) && IsPerson(sptr) && !ishold) /* remote user changing nick */
		{
			sendto_snomask(SNO_QLINE, "Q:lined nick %s from %s on %s", nick,
				sptr->name, sptr->srvptr ? sptr->srvptr->name : "<unknown>");
		}

		if (!IsServer(cptr)) /* local */
		{
			if (ishold)
			{
				sendto_one(sptr, err_str(ERR_ERRONEUSNICKNAME),
				    me.name, BadPtr(parv[0]) ? "*" : parv[0],
				    nick, tklban->reason);
				return 0;
			}
			if (!IsOper(cptr))
			{
				sptr->since += 4; /* lag them up */
				sendto_one(sptr, err_str(ERR_ERRONEUSNICKNAME),
				    me.name, BadPtr(parv[0]) ? "*" : parv[0],
				    nick, tklban->reason);
				sendto_snomask(SNO_QLINE, "Forbidding Q-lined nick %s from %s.",
				    nick, get_client_name(cptr, FALSE));
				return 0;	/* NICK message ignored */
			}
		}
	}
	/*
	   ** acptr already has result from previous find_server()
	 */
	if (acptr)
	{
		/*
		   ** We have a nickname trying to use the same name as
		   ** a server. Send out a nick collision KILL to remove
		   ** the nickname. As long as only a KILL is sent out,
		   ** there is no danger of the server being disconnected.
		   ** Ultimate way to jupiter a nick ? >;-). -avalon
		 */
		sendto_failops("Nick collision on %s(%s <- %s)",
		    sptr->name, acptr->from->name,
		    get_client_name(cptr, FALSE));
		ircstp->is_kill++;
		sendto_one(cptr, ":%s KILL %s :%s (%s <- %s)",
		    me.name, sptr->name, me.name, acptr->from->name,
		    /* NOTE: Cannot use get_client_name
		       ** twice here, it returns static
		       ** string pointer--the other info
		       ** would be lost
		     */
		    get_client_name(cptr, FALSE));
		sptr->flags |= FLAGS_KILLED;
		return exit_client(cptr, sptr, &me, "Nick/Server collision");
	}

	if (MyClient(cptr) && !IsOper(cptr))
		cptr->since += 3;	/* Nick-flood prot. -Donwulff */

	if (!(acptr = find_client(nick, NULL)))
		goto nickkilldone;	/* No collisions, all clear... */
	/*
	   ** If the older one is "non-person", the new entry is just
	   ** allowed to overwrite it. Just silently drop non-person,
	   ** and proceed with the nick. This should take care of the
	   ** "dormant nick" way of generating collisions...
	 */
	/* Moved before Lost User Field to fix some bugs... -- Barubary */
	if (IsUnknown(acptr) && MyConnect(acptr))
	{
		/* This may help - copying code below */
		if (acptr == cptr)
			return 0;
		acptr->flags |= FLAGS_KILLED;
		exit_client(NULL, acptr, &me, "Overridden");
		goto nickkilldone;
	}
	/* A sanity check in the user field... */
	if (acptr->user == NULL)
	{
		/* This is a Bad Thing */
		sendto_failops("Lost user field for %s in change from %s",
		    acptr->name, get_client_name(cptr, FALSE));
		ircstp->is_kill++;
		sendto_one(acptr, ":%s KILL %s :%s (Lost user field!)",
		    me.name, acptr->name, me.name);
		acptr->flags |= FLAGS_KILLED;
		/* Here's the previous versions' desynch.  If the old one is
		   messed up, trash the old one and accept the new one.
		   Remember - at this point there is a new nick coming in!
		   Handle appropriately. -- Barubary */
		exit_client(NULL, acptr, &me, "Lost user field");
		goto nickkilldone;
	}
	/*
	   ** If acptr == sptr, then we have a client doing a nick
	   ** change between *equivalent* nicknames as far as server
	   ** is concerned (user is changing the case of his/her
	   ** nickname or somesuch)
	 */
	if (acptr == sptr) {
		if (strcmp(acptr->name, nick) != 0)
		{
			/* Allows change of case in his/her nick */
			removemoder = 0; /* don't set the user -r */
			goto nickkilldone;	/* -- go and process change */
		} else
			/*
			 ** This is just ':old NICK old' type thing.
			 ** Just forget the whole thing here. There is
			 ** no point forwarding it to anywhere,
			 ** especially since servers prior to this
			 ** version would treat it as nick collision.
			 */
			return 0;	/* NICK Message ignored */
	}
	/*
	   ** Note: From this point forward it can be assumed that
	   ** acptr != sptr (point to different client structures).
	 */
	/*
	   ** Decide, we really have a nick collision and deal with it
	 */
	if (!IsServer(cptr))
	{
		/*
		   ** NICK is coming from local client connection. Just
		   ** send error reply and ignore the command.
		 */
#ifdef GUEST
		if (IsUnknown(sptr))
		{
			RunHook4(HOOKTYPE_GUEST, cptr, sptr, parc, parv);
			return 0;
		}
#endif
		sendto_one(sptr, err_str(ERR_NICKNAMEINUSE),
		    /* parv[0] is empty when connecting */
		    me.name, BadPtr(parv[0]) ? "*" : parv[0], nick);
		return 0;	/* NICK message ignored */
	}
	/*
	   ** NICK was coming from a server connection.
	   ** This means we have a race condition (two users signing on
	   ** at the same time), or two net fragments reconnecting with
	   ** the same nick.
	   ** The latter can happen because two different users connected
	   ** or because one and the same user switched server during a
	   ** net break.
	   ** If we have the old protocol (no TimeStamp and no user@host)
	   ** or if the TimeStamps are equal, we kill both (or only 'new'
	   ** if it was a "NICK new"). Otherwise we kill the youngest
	   ** when user@host differ, or the oldest when they are the same.
	   ** --Run
	   **
	 */
	if (IsServer(sptr))
	{
		/*
		   ** A new NICK being introduced by a neighbouring
		   ** server (e.g. message type "NICK new" received)
		 */
		if (parc > 3)
		{
			lastnick = TS2ts(parv[3]);
			if (parc > 5)
				differ = (mycmp(acptr->user->username, parv[4])
				    || mycmp(acptr->user->realhost, parv[5]));
		}
		sendto_failops("Nick collision on %s (%s %ld <- %s %ld)",
		    acptr->name, acptr->from->name, acptr->lastnick,
		    cptr->name, lastnick);
		/*
		   **    I'm putting the KILL handling here just to make it easier
		   ** to read, it's hard to follow it the way it used to be.
		   ** Basically, this is what it will do.  It will kill both
		   ** users if no timestamp is given, or they are equal.  It will
		   ** kill the user on our side if the other server is "correct"
		   ** (user@host differ and their user is older, or user@host are
		   ** the same and their user is younger), otherwise just kill the
		   ** user an reintroduce our correct user.
		   **    The old code just sat there and "hoped" the other server
		   ** would kill their user.  Not anymore.
		   **                                               -- binary
		 */
		if (!(parc > 3) || (acptr->lastnick == lastnick))
		{
			ircstp->is_kill++;
			sendto_serv_butone(NULL,
			    ":%s KILL %s :%s (Nick Collision)",
			    me.name, acptr->name, me.name);
			acptr->flags |= FLAGS_KILLED;
			(void)exit_client(NULL, acptr, &me,
			    "Nick collision with no timestamp/equal timestamps");
			return 0;	/* We killed both users, now stop the process. */
		}

		if ((differ && (acptr->lastnick > lastnick)) ||
		    (!differ && (acptr->lastnick < lastnick)) || acptr->from == cptr)	/* we missed a QUIT somewhere ? */
		{
			ircstp->is_kill++;
			sendto_serv_butone(cptr,
			    ":%s KILL %s :%s (Nick Collision)",
			    me.name, acptr->name, me.name);
			acptr->flags |= FLAGS_KILLED;
			(void)exit_client(NULL, acptr, &me, "Nick collision");
			goto nickkilldone;	/* OK, we got rid of the "wrong" user,
						   ** now we're going to add the user the
						   ** other server introduced.
						 */
		}

		if ((differ && (acptr->lastnick < lastnick)) ||
		    (!differ && (acptr->lastnick > lastnick)))
		{
			/*
			 * Introduce our "correct" user to the other server
			 */

			sendto_one(cptr, ":%s KILL %s :%s (Nick Collision)",
			    me.name, parv[1], me.name);
			send_umode(NULL, acptr, 0, SEND_UMODES, buf);
			sendto_one_nickcmd(cptr, acptr, buf);
			if (acptr->user->away)
				sendto_one(cptr, ":%s AWAY :%s", acptr->name,
				    acptr->user->away);
			send_user_joins(cptr, acptr);
			return 0;	/* Ignore the NICK */
		}
		return 0;
	}
	else
	{
		/*
		   ** A NICK change has collided (e.g. message type ":old NICK new").
		 */
		if (parc > 2)
			lastnick = TS2ts(parv[2]);
		differ = (mycmp(acptr->user->username, sptr->user->username) ||
		    mycmp(acptr->user->realhost, sptr->user->realhost));
		sendto_failops
		    ("Nick change collision from %s to %s (%s %ld <- %s %ld)",
		    sptr->name, acptr->name, acptr->from->name, acptr->lastnick,
		    sptr->from->name, lastnick);
		if (!(parc > 2) || lastnick == acptr->lastnick)
		{
			ircstp->is_kill += 2;
			sendto_serv_butone(NULL,	/* First kill the new nick. */
			    ":%s KILL %s :%s (Self Collision)",
			    me.name, acptr->name, me.name);
			sendto_serv_butone(cptr,	/* Tell my servers to kill the old */
			    ":%s KILL %s :%s (Self Collision)",
			    me.name, sptr->name, me.name);
			sptr->flags |= FLAGS_KILLED;
			acptr->flags |= FLAGS_KILLED;
			(void)exit_client(NULL, sptr, &me, "Self Collision");
			(void)exit_client(NULL, acptr, &me, "Self Collision");
			return 0;	/* Now that I killed them both, ignore the NICK */
		}
		if ((differ && (acptr->lastnick > lastnick)) ||
		    (!differ && (acptr->lastnick < lastnick)))
		{
			/* sptr (their user) won, let's kill acptr (our user) */
			ircstp->is_kill++;
			sendto_serv_butone(cptr,
			    ":%s KILL %s :%s (Nick collision: %s <- %s)",
			    me.name, acptr->name, me.name,
			    acptr->from->name, sptr->from->name);
			acptr->flags |= FLAGS_KILLED;
			(void)exit_client(NULL, acptr, &me, "Nick collision");
			goto nickkilldone;	/* their user won, introduce new nick */
		}
		if ((differ && (acptr->lastnick < lastnick)) ||
		    (!differ && (acptr->lastnick > lastnick)))
		{
			/* acptr (our user) won, let's kill sptr (their user),
			   ** and reintroduce our "correct" user
			 */
			ircstp->is_kill++;
			/* Kill the user trying to change their nick. */
			sendto_serv_butone(cptr,
			    ":%s KILL %s :%s (Nick collision: %s <- %s)",
			    me.name, sptr->name, me.name,
			    sptr->from->name, acptr->from->name);
			sptr->flags |= FLAGS_KILLED;
			(void)exit_client(NULL, sptr, &me, "Nick collision");
			/*
			 * Introduce our "correct" user to the other server
			 */
			/* Kill their user. */
			sendto_one(cptr, ":%s KILL %s :%s (Nick Collision)",
			    me.name, parv[1], me.name);
			send_umode(NULL, acptr, 0, SEND_UMODES, buf);
			sendto_one_nickcmd(cptr, acptr, buf);
			if (acptr->user->away)
				sendto_one(cptr, ":%s AWAY :%s", acptr->name,
				    acptr->user->away);

			send_user_joins(cptr, acptr);
			return 0;	/* their user lost, ignore the NICK */
		}

	}
	return 0;		/* just in case */
      nickkilldone:
	if (IsServer(sptr))
	{
		/* A server introducing a new client, change source */

		sptr = make_client(cptr, serv);
		add_client_to_list(sptr);
		if (parc > 2)
			sptr->hopcount = TS2ts(parv[2]);
		if (parc > 3)
			sptr->lastnick = TS2ts(parv[3]);
		else		/* Little bit better, as long as not all upgraded */
			sptr->lastnick = TStime();
		if (sptr->lastnick < 0)
		{
			sendto_realops
			    ("Negative timestamp recieved from %s, resetting to TStime (%s)",
			    cptr->name, backupbuf);
			sptr->lastnick = TStime();
		}
		newusr = 1;
	}
	else if (sptr->name[0] && IsPerson(sptr))
	{
		/*
		   ** If the client belongs to me, then check to see
		   ** if client is currently on any channels where it
		   ** is currently banned.  If so, do not allow the nick
		   ** change to occur.
		   ** Also set 'lastnick' to current time, if changed.
		 */
		if (MyClient(sptr))
		{
			for (mp = sptr->user->channel; mp; mp = mp->next)
			{
				if (!is_skochanop(sptr, mp->chptr) && is_banned(sptr, mp->chptr, BANCHK_NICK))
				{
					sendto_one(sptr,
					    err_str(ERR_BANNICKCHANGE),
					    me.name, parv[0],
					    mp->chptr->chname);
					return 0;
				}
				if (CHECK_TARGET_NICK_BANS && !is_skochanop(sptr, mp->chptr) && is_banned_with_nick(sptr, mp->chptr, BANCHK_NICK, nick))
				{
					sendto_one(sptr,
					    ":%s 437 %s %s :Cannot change to a nickname banned on channel",
					    me.name, parv[0],
					    mp->chptr->chname);
					return 0;
				}
				if (!IsOper(sptr) && !IsULine(sptr)
				    && mp->chptr->mode.mode & MODE_NONICKCHANGE
				    && !is_chanownprotop(sptr, mp->chptr))
				{
					sendto_one(sptr,
					    err_str(ERR_NONICKCHANGE),
					    me.name, parv[0],
					    mp->chptr->chname);
					return 0;
				}
			}

			if (TStime() - sptr->user->flood.nick_t >= NICK_PERIOD)
			{
				sptr->user->flood.nick_t = TStime();
				sptr->user->flood.nick_c = 1;
			} else
				sptr->user->flood.nick_c++;

			sendto_snomask(SNO_NICKCHANGE, "*** Notice -- %s (%s@%s) has changed his/her nickname to %s",
				sptr->name, sptr->user->username, sptr->user->realhost, nick);

			RunHook2(HOOKTYPE_LOCAL_NICKCHANGE, sptr, nick);
		} else {
			if (!IsULine(sptr))
				sendto_snomask(SNO_FNICKCHANGE, "*** Notice -- %s (%s@%s) has changed his/her nickname to %s",
					sptr->name, sptr->user->username, sptr->user->realhost, nick);

			RunHook3(HOOKTYPE_REMOTE_NICKCHANGE, cptr, sptr, nick);
		}
		/*
		 * Client just changing his/her nick. If he/she is
		 * on a channel, send note of change to all clients
		 * on that channel. Propagate notice to other servers.
		 */
		if (mycmp(parv[0], nick) ||
		    /* Next line can be removed when all upgraded  --Run */
		    (!MyClient(sptr) && parc > 2
		    && TS2ts(parv[2]) < sptr->lastnick))
			sptr->lastnick = (MyClient(sptr)
			    || parc < 3) ? TStime() : TS2ts(parv[2]);
		if (sptr->lastnick < 0)
		{
			sendto_realops("Negative timestamp (%s)", backupbuf);
			sptr->lastnick = TStime();
		}
		add_history(sptr, 1);
		sendto_common_channels(sptr, ":%s NICK :%s", parv[0], nick);
		sendto_serv_butone_token(cptr, parv[0], MSG_NICK, TOK_NICK,
		    "%s %ld", nick, sptr->lastnick);
		if (removemoder)
			sptr->umodes &= ~UMODE_REGNICK;
	}
	else if (!sptr->name[0])
	{
#ifdef NOSPOOF
		/*
		 * Client setting NICK the first time.
		 *
		 * Generate a random string for them to pong with.
		 */
		sptr->nospoof = getrandom32();

		if (PINGPONG_WARNING)
			sendto_one(sptr, ":%s NOTICE %s :*** If you are having problems"
			    " connecting due to ping timeouts, please"
			    " type /quote pong %X or /raw pong %X now.",
			    me.name, nick, sptr->nospoof, sptr->nospoof);

		sendto_one(sptr, "PING :%X", sptr->nospoof);
#endif /* NOSPOOF */
#ifdef CONTACT_EMAIL
		sendto_one(sptr,
		    ":%s NOTICE %s :*** If you need assistance with a"
		    " connection problem, please email " CONTACT_EMAIL
		    " with the name and version of the client you are"
		    " using, and the server you tried to connect to: %s",
		    me.name, nick, me.name);
#endif /* CONTACT_EMAIL */
#ifdef CONTACT_URL
		sendto_one(sptr,
		    ":%s NOTICE %s :*** If you need assistance with"
		    " connecting to this server, %s, please refer to: "
		    CONTACT_URL, me.name, nick, me.name);
#endif /* CONTACT_URL */

		/* Copy password to the passwd field if it's given after NICK
		 * - originally by taz, modified by Wizzu
		 */
		if ((parc > 2) && (strlen(parv[2]) <= PASSWDLEN)
		    && !(sptr->listener->umodes & LISTENER_JAVACLIENT))
		{
			if (sptr->passwd)
				MyFree(sptr->passwd);
			sptr->passwd = MyMalloc(strlen(parv[2]) + 1);
			(void)strcpy(sptr->passwd, parv[2]);
		}
		/* This had to be copied here to avoid problems.. */
		(void)strcpy(sptr->name, nick);
		if (sptr->user && IsNotSpoof(sptr))
		{
			/*
			   ** USER already received, now we have NICK.
			   ** *NOTE* For servers "NICK" *must* precede the
			   ** user message (giving USER before NICK is possible
			   ** only for local client connection!). register_user
			   ** may reject the client and call exit_client for it
			   ** --must test this and exit m_nick too!!!
			 */
#ifndef NOSPOOF
			if (USE_BAN_VERSION && MyConnect(sptr))
				sendto_one(sptr, ":IRC!IRC@%s PRIVMSG %s :\1VERSION\1",
					me.name, nick);
#endif
			sptr->lastnick = TStime();	/* Always local client */
			if (register_user(cptr, sptr, nick,
			    sptr->user->username, NULL, NULL, NULL) == FLUSH_BUFFER)
				return FLUSH_BUFFER;
			strcpy(nick, sptr->name); /* don't ask, but I need this. do not remove! -- Syzop */
			update_watch = 0;
			newusr = 1;
		}
	}
	/*
	 *  Finally set new nick name.
	 */
	if (update_watch && sptr->name[0])
	{
		(void)del_from_client_hash_table(sptr->name, sptr);
		if (IsPerson(sptr))
			hash_check_watch(sptr, RPL_LOGOFF);
	}
	(void)strcpy(sptr->name, nick);
	(void)add_to_client_hash_table(nick, sptr);
	if (IsServer(cptr) && parc > 7)
	{
		parv[3] = nick;
		do_cmd(cptr, sptr, "USER", parc - 3, &parv[3]);
		if (GotNetInfo(cptr) && !IsULine(sptr))
			sendto_fconnectnotice(sptr->name, sptr->user, sptr, 0, NULL);
	}
	else if (IsPerson(sptr) && update_watch)
		hash_check_watch(sptr, RPL_LOGON);

#ifdef NEWCHFLOODPROT
	if (sptr->user && !newusr && !IsULine(sptr))
	{
		for (mp = sptr->user->channel; mp; mp = mp->next)
		{
			aChannel *chptr = mp->chptr;
			if (chptr && !(mp->flags & (CHFL_CHANOP|CHFL_VOICE|CHFL_CHANOWNER|CHFL_HALFOP|CHFL_CHANPROT)) &&
			    chptr->mode.floodprot && do_chanflood(chptr->mode.floodprot, FLD_NICK) && MyClient(sptr))
			{
				do_chanflood_action(chptr, FLD_NICK, "nick");
			}
		}	
	}
#endif
	if (newusr && !MyClient(sptr) && IsPerson(sptr))
	{
		RunHook(HOOKTYPE_REMOTE_CONNECT, sptr);
	}

	return 0;
}
示例#12
0
/*
 * m_challenge - generate RSA challenge for wouldbe oper
 * parv[0] = sender prefix
 * parv[1] = operator to challenge for, or +response
 *
 */
static void
m_challenge(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
{
	char *challenge;
	dlink_node *ptr;
	struct ConfItem *aconf, *oconf;
	if(!(source_p->user) || !source_p->localClient)
		return;

	/* if theyre an oper, reprint oper motd and ignore */
	if(IsOper(source_p))
	{
		sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, parv[0]);
		SendMessageFile(source_p, &ConfigFileEntry.opermotd);
		return;
	}

	if(*parv[1] == '+')
	{
		/* Ignore it if we aren't expecting this... -A1kmm */
		if(!source_p->user->response)
			return;

		if(irccmp(source_p->user->response, ++parv[1]))
		{
			sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name);
			log_foper(source_p, source_p->user->auth_oper);

			if(ConfigFileEntry.failed_oper_notice)
				sendto_realops_flags(UMODE_ALL, L_ALL,
						     "Failed OPER attempt by %s (%s@%s)",
						     source_p->name, source_p->username,
						     source_p->host);
			return;
		}

		if((aconf = find_conf_by_name(source_p->user->auth_oper, CONF_OPERATOR)) == NULL)
		{
			sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
			log_foper(source_p, source_p->user->auth_oper);

			if(ConfigFileEntry.failed_oper_notice)
				sendto_realops_flags(UMODE_ALL, L_ALL,
						     "Failed CHALLENGE attempt - host mismatch by %s (%s@%s)",
						     source_p->name, source_p->username,
						     source_p->host);
			return;
		}

		ptr = source_p->localClient->confs.head;
		oconf = ptr->data;
		detach_conf(source_p, oconf);

		if(attach_conf(source_p, aconf) != 0)
		{
			sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!",
				   me.name, source_p->name);
			sendto_realops_flags(UMODE_ALL, L_ALL,
					     "Failed CHALLENGE attempt by %s (%s@%s) can't attach conf!",
					     source_p->name, source_p->username, source_p->host);
			log_foper(source_p, source_p->user->auth_oper);

			attach_conf(source_p, oconf);
			return;
		}

		oper_up(source_p, aconf);

		ilog(L_TRACE, "OPER %s by %s!%s@%s",
		     source_p->user->auth_oper, source_p->name, source_p->username, source_p->host);
		log_oper(source_p, source_p->user->auth_oper);

		MyFree(source_p->user->response);
		MyFree(source_p->user->auth_oper);
		source_p->user->response = NULL;
		source_p->user->auth_oper = NULL;
		return;
	}

	MyFree(source_p->user->response);
	MyFree(source_p->user->auth_oper);
	source_p->user->response = NULL;
	source_p->user->auth_oper = NULL;

	if(!(aconf = find_conf_exact(parv[1], source_p->username, source_p->host,
				     CONF_OPERATOR)) &&
	   !(aconf = find_conf_exact(parv[1], source_p->username,
				     source_p->localClient->sockhost, CONF_OPERATOR)))
	{
		sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
		log_foper(source_p, parv[1]);

		if(ConfigFileEntry.failed_oper_notice)
			sendto_realops_flags(UMODE_ALL, L_ALL,
					     "Failed CHALLENGE attempt - host mismatch by %s (%s@%s)",
					     source_p->name, source_p->username, source_p->host);
		return;
	}

	if(!aconf->rsa_public_key)
	{
		sendto_one(source_p, ":%s NOTICE %s :I'm sorry, PK authentication "
			   "is not enabled for your oper{} block.", me.name, parv[0]);
		return;
	}

	if(!generate_challenge(&challenge, &(source_p->user->response), aconf->rsa_public_key))
	{
		sendto_one(source_p, form_str(RPL_RSACHALLENGE), me.name, parv[0], challenge);
	}

	DupString(source_p->user->auth_oper, aconf->name);
	MyFree(challenge);
	return;
}
示例#13
0
static void SzFree(void *, void *address) { MyFree(address); }
示例#14
0
/*
 * m_challenge - generate RSA challenge for wouldbe oper
 * parv[0] = sender prefix
 * parv[1] = operator to challenge for, or +response
 *
 */
static void
m_challenge(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
{
	char *challenge = NULL;
	struct ConfItem *conf = NULL;
	struct AccessItem *aconf = NULL;

	/* if theyre an oper, reprint oper motd and ignore */
	if(IsOper(source_p))
	{
		sendto_one(source_p, form_str(RPL_YOUREOPER), me.name, parv[0]);
		send_message_file(source_p, &ConfigFileEntry.opermotd);
		return;
	}

	if(*parv[1] == '+')
	{
		/* Ignore it if we aren't expecting this... -A1kmm */
		if(source_p->localClient->response == NULL)
			return;

		if(svsnoop)
		{
			sendto_one(source_p,
				   ":%s NOTICE %s :*** This server is in NOOP mode, you cannot /oper",
				   me.name, source_p->name);
			failed_challenge_notice(source_p, source_p->localClient->auth_oper,
						"This server is in NOOP mode");
			log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
					source_p->localClient->auth_oper);
			return;
		}

		if(irccmp(source_p->localClient->response, ++parv[1]))
		{
			sendto_one(source_p, form_str(ERR_PASSWDMISMATCH), me.name, source_p->name);
			failed_challenge_notice(source_p, source_p->localClient->auth_oper,
						"challenge failed");
			return;
		}

		conf = find_exact_name_conf(OPER_TYPE,
					    source_p->localClient->auth_oper,
					    source_p->username, source_p->host);
		if(conf == NULL)
			conf = find_exact_name_conf(OPER_TYPE,
						    source_p->localClient->auth_oper,
						    source_p->username, source_p->realhost);
		if(conf == NULL)
			conf = find_exact_name_conf(OPER_TYPE,
						    source_p->localClient->auth_oper,
						    source_p->username, source_p->sockhost);
		if(conf == NULL)
		{
			sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
			log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
					source_p->localClient->auth_oper);
			return;
		}

		if(attach_conf(source_p, conf) != 0)
		{
			sendto_one(source_p, ":%s NOTICE %s :Can't attach conf!",
				   me.name, source_p->name);
			failed_challenge_notice(source_p, conf->name, "can't attach conf!");
			log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n",
					source_p->localClient->auth_oper);
			return;
		}

		oper_up(source_p);

		ilog(L_TRACE, "OPER %s by %s!%s@%s",
		     source_p->localClient->auth_oper, source_p->name, source_p->username,
		     source_p->realhost);
		log_oper_action(LOG_OPER_TYPE, source_p, "%s\n", source_p->localClient->auth_oper);

		MyFree(source_p->localClient->response);
		MyFree(source_p->localClient->auth_oper);
		source_p->localClient->response = NULL;
		source_p->localClient->auth_oper = NULL;
		return;
	}

	MyFree(source_p->localClient->response);
	MyFree(source_p->localClient->auth_oper);
	source_p->localClient->response = NULL;
	source_p->localClient->auth_oper = NULL;

	if((conf = find_conf_exact(OPER_TYPE, parv[1], source_p->username, source_p->host)) != NULL)
		aconf = map_to_conf(conf);
	else if((conf = find_conf_exact(OPER_TYPE,
					parv[1], source_p->username, source_p->realhost)) != NULL)
		aconf = map_to_conf(conf);
	else if((conf = find_conf_exact(OPER_TYPE,
					parv[1], source_p->username, source_p->sockhost)) != NULL)
		aconf = map_to_conf(conf);

	if(aconf == NULL)
	{
		sendto_one(source_p, form_str(ERR_NOOPERHOST), me.name, parv[0]);
		conf = find_exact_name_conf(OPER_TYPE, parv[1], NULL, NULL);
		failed_challenge_notice(source_p, parv[1], (conf != NULL)
					? "host mismatch" : "no oper {} block");
		log_oper_action(LOG_FAILED_OPER_TYPE, source_p, "%s\n", parv[1]);
		return;
	}

	if(aconf->rsa_public_key == NULL)
	{
		sendto_one(source_p, ":%s NOTICE %s :I'm sorry, PK authentication "
			   "is not enabled for your oper{} block.", me.name, parv[0]);
		return;
	}

	if(!generate_challenge(&challenge, &(source_p->localClient->response),
			       aconf->rsa_public_key))
		sendto_one(source_p, form_str(RPL_RSACHALLENGE), me.name, parv[0], challenge);

	DupString(source_p->localClient->auth_oper, conf->name);
	MyFree(challenge);
}
示例#15
0
int
CheckJuped(char *name)

{
	struct Jupe *tempjupe;
	struct Server *tempserv;
	char sendstr[MAXLINE + 1], **arv;

	for (tempjupe = JupeList; tempjupe; tempjupe = tempjupe->next)
	{
		if (match(tempjupe->name, name))
		{
			if (tempjupe->isnick)
			{
				struct Luser *lptr;

				if (!(lptr = FindClient(name)))
					return 0;

				/* its a nick jupe, not a server jupe */

#ifdef DANCER

				ircsprintf(sendstr,
				           "NICK %s 1 %ld +i juped juped.com %s %lu :%s\r\n",
				           tempjupe->name,
#ifdef NICKSERVICES
				           (long) (lptr->nick_ts - 1),
#else
				           (long) (lptr->since - 1),
#endif /* NICKSERVICES */
				           Me.name, 0xffffffffL, tempjupe->reason ?
				           tempjupe->reason : "Jupitered Nickname");
#else
				/* collide the nickname */
				ircsprintf(sendstr, "NICK %s 1 %ld +i %s %s %s :%s\r\n",
				           tempjupe->name,
#ifdef NICKSERVICES
				           (long) (lptr->nick_ts - 1),
#else
				(long) (lptr->since - 1),
#endif /* NICKSERVICES */
				           JUPED_USERNAME, JUPED_HOSTNAME, Me.name,
				           tempjupe->reason ? tempjupe->reason :
				           "Jupitered Nickname");
#endif /* DANCER */

				toserv("%s", sendstr);

				DeleteClient(lptr);

				SplitBuf(sendstr, &arv);
				AddClient(arv);
				MyFree(arv);

				if (Me.sptr)
					Me.sptr->numoperkills++;
				Network->TotalOperKills++;
#ifdef STATSERVICES

				if (Network->TotalOperKills > Network->OperKillsT)
					Network->OperKillsT = Network->TotalOperKills;
#endif

			}
			else
			{
				toserv("SQUIT %s :Juped: %s (%s)\r\n", name,
				       tempjupe->reason, tempjupe->who);

				tempserv = FindServer(name);
				DeleteServer(tempserv);

			/* If the fake server is introduced before the remote server has quited,
			 * we get "server already exists" and services get SQUIT'ed,
			 * so we'll introduce it in s_squit()
			 */


			}
			return 1;
		}
	}
	return 0;
} /* CheckJuped */
示例#16
0
void
DeleteClient(struct Luser *user)

{
	struct UserChannel *chnext;

#ifdef NICKSERVICES

	struct NickInfo *nptr, *realptr;

#ifdef CHANNELSERVICES

	struct aChannelPtr *fnext;
#endif

#endif /* NICKSERVICES */

	if (user == NULL)
		return;

	SendUmode(OPERUMODE_CAPE,
	          "*** Client exit: %s!%s@%s [%s]",
	          user->nick,
	          user->username,
	          user->hostname,
	          user->server ? user->server->name : "*unknown*");

#ifdef NICKSERVICES

	realptr = FindNick(user->nick);
	nptr = GetMaster(realptr);
	if (nptr && realptr)
	{

		if (LastSeenInfo && (realptr->flags & NS_IDENTIFIED))
		{
			/*
			 * Update last seen user@host info
			 */

			if (realptr->lastu)
				MyFree(realptr->lastu);
			if (realptr->lasth)
				MyFree(realptr->lasth);
			realptr->lastu = MyStrdup(user->username);
			realptr->lasth = MyStrdup(user->hostname);
		}

		/*
		 * they're quitting - unmark them as identified
		 */
		realptr->flags &= ~NS_IDENTIFIED;
	}

#ifdef CHANNELSERVICES
	while (user->founder_channels)
	{
		fnext = user->founder_channels->next;
		RemFounder(user, user->founder_channels->cptr);
		user->founder_channels = fnext;
	}
#endif

#endif /* NICKSERVICES */

#ifdef ALLOW_FUCKOVER
	/* check if user was a target of o_fuckover() */
	CheckFuckoverTarget(user, NULL);
#endif

	if (user->server)
		user->server->numusers--;

	while (user->firstchan)
	{
		chnext = user->firstchan->next;
		RemoveFromChannel(user->firstchan->chptr, user);
		user->firstchan = chnext;
	}

	HashDelClient(user, 0);

	/* keep oper count updated */
	if (user->umodes & UMODE_O)
	{
		Network->TotalOperators--;
		if (user->server)
			user->server->numopers--;
	}

#ifndef BLOCK_ALLOCATION
	MyFree(user->nick);
	MyFree(user->username);
	MyFree(user->hostname);
	MyFree(user->realname);
#endif /* BLOCK_ALLOCATION */

	if (user->prev)
		user->prev->next = user->next;
	else
		ClientList = user->next;

	if (user->next)
		user->next->prev = user->prev;

#ifdef BLOCK_ALLOCATION

	BlockSubFree(ClientHeap, user);

#else

	MyFree(user);

#endif /* BLOCK_ALLOCATION */

	Network->TotalUsers--;
} /* DeleteClient() */
示例#17
0
/***************************************************************************************************
*FunctionName: activityBufferFree
*Description: 界面内存释放
*Input: 
*Output: 
*Return: 
*Author: xsx
*Date: 2016年12月21日09:03:10
***************************************************************************************************/
static void activityBufferFree(void)
{
	MyFree(S_WaitPageData);
	S_WaitPageData = NULL;
}
示例#18
0
/*****************************************************************************
* Routine to save an EESchema file.											 *
* FileSave controls how the file is to be saved - under what name.			 *
* Returns TRUE if the file has been saved.									 *
*****************************************************************************/
bool WinEDA_SchematicFrame::SaveEEFile(BASE_SCREEN *Window, int FileSave)
{
wxString msg;
wxString Name, BakName;
const wxChar **LibNames;
char * layer, *width;
int ii, shape;
bool Failed = FALSE;
EDA_BaseStruct *Phead;
Ki_PageDescr * PlotSheet;
FILE *f;
wxString dirbuf;

	if ( Window == NULL ) Window = ActiveScreen;

	/* If no name exists in the window yet - save as new. */
	if( Window->m_FileName.IsEmpty() ) FileSave = FILE_SAVE_NEW;

	switch (FileSave)
	{
		case FILE_SAVE_AS:
			dirbuf = wxGetCwd() + STRING_DIR_SEP;
			Name = MakeFileName(dirbuf, Window->m_FileName, g_SchExtBuffer);
			/* Rename the old file to a '.bak' one: */
			BakName = Name;
			if ( wxFileExists(Name) )
			{
				ChangeFileNameExt(BakName, wxT(".bak"));
				wxRemoveFile(BakName);	/* delete Old .bak file */
				if( ! wxRenameFile(Name, BakName) )
				{
					DisplayError(this, wxT("Warning: unable to rename old file"), 10);
				}
			}
			break;

		case FILE_SAVE_NEW:
		{
			wxString mask = wxT("*") + g_SchExtBuffer;
			Name = EDA_FileSelector(_("Schematic files:"),
					wxEmptyString,					/* Chemin par defaut */
					Window->m_FileName,				/* nom fichier par defaut, et resultat */
					g_SchExtBuffer,		/* extension par defaut */
					mask,				/* Masque d'affichage */
					this,
					wxSAVE,
					FALSE
					);
			if ( Name.IsEmpty() ) return FALSE;

			Window->m_FileName = Name;
			dirbuf = wxGetCwd() + STRING_DIR_SEP;
			Name = MakeFileName(dirbuf, Name, g_SchExtBuffer);

			break;
		}

		default: break;
	}

	if ((f = wxFopen(Name, wxT("wt"))) == NULL)
	{
		msg = _("Failed to create file ") + Name;
		DisplayError(this, msg);
		return FALSE;
	}

	msg = _("Save file ") + Name;
	Affiche_Message(msg);

	LibNames = GetLibNames();
	BakName.Empty();	// temporary buffer!
	for (ii = 0; LibNames[ii] != NULL; ii++)
	{
		if (ii > 0) BakName += wxT(",");
		BakName += LibNames[ii];
	}
	MyFree( LibNames);

	if (fprintf(f, "%s %s %d\n", EESCHEMA_FILE_STAMP,
		SCHEMATIC_HEAD_STRING, EESCHEMA_VERSION) == EOF ||
		fprintf(f, "LIBS:%s\n", CONV_TO_UTF8(BakName)) == EOF)
	{
		DisplayError(this, _("File write operation failed."));
		fclose(f);
		return FALSE;
	}

	Window->ClrModify();

	SaveLayers(f);
	/* Sauvegarde des dimensions du schema, des textes du cartouche.. */
	
	PlotSheet = Window->m_CurrentSheet;
	fprintf(f,"$Descr %s %d %d\n",CONV_TO_UTF8(PlotSheet->m_Name),
			PlotSheet->m_Size.x, PlotSheet->m_Size.y);

	fprintf(f,"Sheet %d %d\n",Window->m_SheetNumber, Window->m_NumberOfSheet);
	fprintf(f,"Title \"%s\"\n",CONV_TO_UTF8(Window->m_Title));
	fprintf(f,"Date \"%s\"\n",CONV_TO_UTF8(Window->m_Date));
	fprintf(f,"Rev \"%s\"\n",CONV_TO_UTF8(Window->m_Revision));
	fprintf(f,"Comp \"%s\"\n",CONV_TO_UTF8(Window->m_Company));
	fprintf(f,"Comment1 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire1));
	fprintf(f,"Comment2 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire2));
	fprintf(f,"Comment3 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire3));
	fprintf(f,"Comment4 \"%s\"\n", CONV_TO_UTF8(Window->m_Commentaire4));

	fprintf(f,"$EndDescr\n");

	/* Sauvegarde des elements du dessin */
	Phead = Window->EEDrawList;
	while (Phead)
		{
		switch(Phead->m_StructType)
			{
			case DRAW_LIB_ITEM_STRUCT_TYPE:		  /* Its a library item. */
				SavePartDescr( f, (EDA_SchComponentStruct *) Phead);
				break;

			case DRAW_SHEET_STRUCT_TYPE:	   /* Its a Sheet item. */
				SaveSheetDescr( f, (DrawSheetStruct *) Phead);
				break;

			case DRAW_SEGMENT_STRUCT_TYPE:		 /* Its a Segment item. */
				#undef STRUCT
				#define STRUCT ((EDA_DrawLineStruct *) Phead)
				layer = "Notes"; width = "Line";
				if (STRUCT->m_Layer == LAYER_WIRE) layer = "Wire";
				if (STRUCT->m_Layer == LAYER_BUS) layer = "Bus";
				if( STRUCT->m_Width != GR_NORM_WIDTH) layer = "Bus";
				if (fprintf(f, "Wire %s %s\n", layer, width ) == EOF)
					{
					Failed = TRUE; break;
					}
				if (fprintf(f, "\t%-4d %-4d %-4d %-4d\n",
						STRUCT->m_Start.x,STRUCT->m_Start.y,
						STRUCT->m_End.x,STRUCT->m_End.y) == EOF)
					{
					Failed = TRUE; break;
					}
				break;

			case DRAW_BUSENTRY_STRUCT_TYPE:		 /* Its a Raccord item. */
				#undef STRUCT
				#define STRUCT ((DrawBusEntryStruct *) Phead)
				layer = "Wire"; width = "Line";
				if (STRUCT->m_Layer == LAYER_BUS)
					{
					layer = "Bus"; width = "Bus";
					}

				if (fprintf(f, "Entry %s %s\n", layer, width) == EOF)
					{
					Failed = TRUE; break;
					}
				if( fprintf(f, "\t%-4d %-4d %-4d %-4d\n",
						STRUCT->m_Pos.x,STRUCT->m_Pos.y,
						STRUCT->m_End().x,STRUCT->m_End().y) == EOF)
						{
						Failed = TRUE; break;
						}
				break;

			case DRAW_POLYLINE_STRUCT_TYPE:		  /* Its a polyline item. */
				#undef STRUCT
				#define STRUCT ((DrawPolylineStruct *) Phead)
				layer = "Notes"; width = "Line";
				if (STRUCT->m_Layer == LAYER_WIRE) layer = "Wire";
				if (STRUCT->m_Layer == LAYER_BUS) layer = "Bus";
				if( STRUCT->m_Width != GR_NORM_WIDTH) width = "Bus";
				if (fprintf(f, "Poly %s %s %d\n",
							width, layer, STRUCT->m_NumOfPoints) == EOF)
					{
					Failed = TRUE; break;
					}
				for (ii = 0; ii < STRUCT->m_NumOfPoints; ii++)
					{
					if (fprintf(f, "\t%-4d %-4d\n",
						STRUCT->m_Points[ii*2],
						STRUCT->m_Points[ii*2+1]) == EOF)
						{
						Failed = TRUE;
						break;
						}
					}
				break;

			case DRAW_JUNCTION_STRUCT_TYPE:	/* Its a connection item. */
				#undef STRUCT
				#define STRUCT ((DrawJunctionStruct *) Phead)
				if (fprintf(f, "Connection ~ %-4d %-4d\n",
					STRUCT->m_Pos.x, STRUCT->m_Pos.y) == EOF)
					{
					Failed = TRUE;
					}
				break;

			case DRAW_NOCONNECT_STRUCT_TYPE:	/* Its a NoConnection item. */
				#undef STRUCT
				#define STRUCT ((DrawNoConnectStruct *) Phead)
				if (fprintf(f, "NoConn ~ %-4d %-4d\n",
					STRUCT->m_Pos.x, STRUCT->m_Pos.y) == EOF)
					{
					Failed = TRUE;
					}
				break;

			case DRAW_TEXT_STRUCT_TYPE:			/* Its a text item. */
				#undef STRUCT
				#define STRUCT ((DrawTextStruct *) Phead)
				if (fprintf(f, "Text Notes %-4d %-4d %-4d %-4d ~\n%s\n",
						STRUCT->m_Pos.x, STRUCT->m_Pos.y,
						STRUCT->m_Orient, STRUCT->m_Size.x,
						CONV_TO_UTF8(STRUCT->m_Text)) == EOF)
					Failed = TRUE;
				break;


			case DRAW_LABEL_STRUCT_TYPE:		/* Its a label item. */
				#undef STRUCT
				#define STRUCT ((DrawLabelStruct *) Phead)
				shape = '~';
				if (fprintf(f, "Text Label %-4d %-4d %-4d %-4d %c\n%s\n",
						STRUCT->m_Pos.x, STRUCT->m_Pos.y,
						STRUCT->m_Orient, STRUCT->m_Size.x, shape,
						CONV_TO_UTF8(STRUCT->m_Text)) == EOF)
					Failed = TRUE;
				break;


			case DRAW_GLOBAL_LABEL_STRUCT_TYPE: /* Its a Global label item. */
				#undef STRUCT
				#define STRUCT ((DrawGlobalLabelStruct *) Phead)
				shape = STRUCT->m_Shape;
			if (fprintf(f, "Text GLabel %-4d %-4d %-4d %-4d %s\n%s\n",
						STRUCT->m_Pos.x, STRUCT->m_Pos.y,
						STRUCT->m_Orient,	STRUCT->m_Size.x,
						SheetLabelType[shape],
						CONV_TO_UTF8(STRUCT->m_Text)) == EOF)
					Failed = TRUE;
				break;

			case DRAW_MARKER_STRUCT_TYPE:	/* Its a marker item. */
				#undef STRUCT
				#define STRUCT ((DrawMarkerStruct *) Phead)
				if( STRUCT->GetComment() ) msg = STRUCT->GetComment();
				else msg.Empty();
				if (fprintf(f, "Kmarq %c %-4d %-4d \"%s\" F=%X\n",
								(int) STRUCT->m_Type + 'A',
								STRUCT->m_Pos.x, STRUCT->m_Pos.y,
								CONV_TO_UTF8(msg), STRUCT->m_MarkFlags) == EOF)
					{
					Failed = TRUE;
					}
				break;

			case DRAW_SHEETLABEL_STRUCT_TYPE :
			case DRAW_PICK_ITEM_STRUCT_TYPE :
				break;

			default:
				break;
			}

		if (Failed)
			{
			DisplayError(this, _("File write operation failed."));
			break;
			}

		Phead = Phead->Pnext;
		}
	if (fprintf(f, "$EndSCHEMATC\n") == EOF) Failed = TRUE;

	fclose(f);

	if (FileSave == FILE_SAVE_NEW) Window->m_FileName = Name;

	return !Failed;
}
示例#19
0
int
ss_loaddata()

{
	FILE *fp;
	char line[MAXLINE + 1], **av;
	char *keyword;
	int ac, ret = 1, cnt;

	if ((fp = fopen(StatServDB, "r")) == NULL)
	{
		/* StatServ data file doesn't exist */
		return (-1);
	}

	cnt = 0;
	/* load data into list */
	while (fgets(line, sizeof(line), fp))
	{
		cnt++;
		ac = SplitBuf(line, &av);
		if (!ac)
		{
			/* probably a blank line */
			MyFree(av);
			continue;
		}

		if (av[0][0] == ';')
		{
			MyFree(av);
			continue;
		}

		if (!ircncmp("->", av[0], 2))
		{
			/*
			 * check if there are enough args
			 */
			if (ac < 3)
			{
				fatal(1, "%s:%d Invalid database format (FATAL)",
				      StatServDB,
				      cnt);
				ret = -2;
				MyFree(av);
				continue;
			}

			keyword = av[0] + 2;
			if (!ircncmp(keyword, "USERS", 5))
			{
				if (Network->TotalUsers <= atol(av[1]))
				{
					Network->MaxUsers = atol(av[1]);
					Network->MaxUsers_ts = atol(av[2]);
				}
			}
			else if (!ircncmp(keyword, "OPERS", 5))
			{
				if (Network->TotalOperators <= atol(av[1]))
				{
					Network->MaxOperators = atol(av[1]);
					Network->MaxOperators_ts = atol(av[2]);
				}
			}
			else if (!ircncmp(keyword, "CHANS", 5))
			{
				if (Network->TotalChannels <= atol(av[1]))
				{
					Network->MaxChannels = atol(av[1]);
					Network->MaxChannels_ts = atol(av[2]);
				}
			}
			else if (!ircncmp(keyword, "SERVS", 5))
			{
				if (Network->TotalServers <= atol(av[1]))
				{
					Network->MaxServers = atol(av[1]);
					Network->MaxServers_ts = atol(av[2]);
				}
			}
		}

		MyFree(av);
	} /* while */

	fclose(fp);

	return (ret);
} /* ss_loaddata */
示例#20
0
// This is the task-bar wndproc. 
LRESULT CALLBACK TaskBarWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
	DEBUGMSG(ZONE_TRACEMSGHF, (TEXT("Taskbar Window Msg=%x wp=%x lp=%x\r\n"), msg, wp, lp));

	switch(msg)
	{
		// 5sec housekeeping timer
		case WM_TIMER:
			DoHibernate(); // check free-memory level & notify apps if neccesary
			DoPowerCheck(hwnd); // check battery levels & pop-up warning if reqd
			break;

		case WM_SYSKEYDOWN:
		case WM_KEYDOWN:
		{
			DEBUGMSG(ZONE_TRACEMSG, (TEXT("Taskbar Window WM_KEYDOWN\r\n")));
			// For now we're sending Ctrl-Esc, Alt-Esc, Alt-Tab, Ctrl-Alt-Del/Bksp all to TaskMan
			// A fuller shell would implement a Start-Menu on Alt-Esc for example.
			switch (wp) 
			{
				case VK_DELETE:
				case VK_BACK:
					// Send Ctrl-Alt-Bksp to Taskman. NOTE: GWES doesn't send us Ctrl-Alt-Del
					DEBUGMSG(ZONE_TRACEMSG, (TEXT("Taskbar Window WM_KEYDOWN, VK_BACK or VK_DELETE\r\n")));
					if (GetKeyState(VK_CONTROL) && GetKeyState(VK_MENU)) 
						Show_TaskMan();
					break;

				case VK_TAB:
					// Send Alt-Tab to TaskMan
					DEBUGMSG(ZONE_TRACEMSG, (TEXT("Taskbar Window WM_KEYDOWN, VK_TAB\r\n")));
					if (GetKeyState(VK_MENU)) 
						Show_TaskMan();
					break;
					
				case VK_ESCAPE:
					// Send Ctrl-Esc & Alt-Esc to TaskMan
					DEBUGMSG(ZONE_TRACEMSG, (TEXT("Taskbar Window WM_KEYDOWN, VK_ESCAPE\r\n")));
					if(GetKeyState(VK_CONTROL) || GetKeyState(VK_MENU))
						Show_TaskMan();
					break;

				default:
					return DefWindowProc(hwnd, msg, wp, lp);
			}
		}
		break;
		case WM_HANDLESHELLNOTIFYICON:
			// Private message posted by the callback in minserver.cpp when it
			// gets a Shell_NotifyIcon call. wParam is NIM_ADD/DELETE etc
			// lParam is a PNOTIFYICONDATA (we are responsible for freeing)
			// For now just print a debug message to show we got the data 
			// correctly.
			PNOTIFYICONDATA pnid;
			pnid = (PNOTIFYICONDATA)lp;
			RETAILMSG(1, (L"got Shell_NotifyIcon(nim=%d, nid(hwnd=0x%08x uId=%d uFlags=%d uCBMsg=%d hIcon=0x%08x, szTip=%s\r\n",
				wp, pnid->hWnd, pnid->uID, pnid->uFlags, pnid->uCallbackMessage, pnid->hIcon, (pnid->szTip ? pnid->szTip : L"null")));
			// ----- Insert real processing of this API here -----
			MyFree(pnid);
			break;
			
		case WM_HANDLESHADDTORECENTDOCS:
			// Private message posted by the callback in minserver.cpp when it
			// gets a SHAddToRecentDocs call. wParam is SHARD_PATH
			// lParam is a the path (we are responsible for freeing)
			// For now just print a debug message to show we got the data 
			// correctly
			RETAILMSG(1, (L"got SHAddToRecentDocs(uFlags=%d, path=%s)\r\n", wp, (lp ? (PTSTR)lp : L"null")));
			// ----- Insert real processing of this API here -----
			MyFree((PVOID)lp);
			break;

		default:
			// This window will get GWE messages on window-create/delete etc. 
			// If it wants to display Win9x/NT-like task buttons etc., it 
			// should handle these messages
			return DefWindowProc(hwnd, msg, wp, lp);
	}
	return 0;
}
示例#21
0
int
m_scan_unklines(struct Client *cptr, struct Client *sptr, int parc, char *parv[], char *varparv[])
{
  char *mask = NULL;
  int list = 1, count = 0, listed_so_far = 0;
  int list_max = 100;
  int i;
  struct unkline_record **ukr, *ukr2;

  if (!HasUmode(sptr,UMODE_SEEKLINES))
    {
      if (SeesOperMessages(sptr))
	sendto_one(sptr,":%s NOTICE %s :You have no 2 umode", me.name, parv[0]);
      else
	sendto_one(sptr, form_str(ERR_NOPRIVILEGES), me.name, parv[0]);
      return 0;
    }

  if (parc < 2)
    {
      if (!IsServer(sptr))
	sendto_one(sptr, form_str(ERR_NEEDMOREPARAMS),
		   me.name, parv[0], "SCAN UNKLINES");
      return 0;
    }

  for (i = 2; i < parc; i++)
    {
      if (!irccmp(parv[i], "no-list"))
	list = 0;
      else if (!irccmp(parv[i], "list"))
	list = 1;
      else if (i < (parc - 1))
	{
	  if (!irccmp(parv[i], "list-max"))
	    {
	      list_max = atoi(parv[++i]);
	    }
	  else if (!irccmp(parv[i], "mask"))
	    {
	      mask = parv[++i];
	    }
	}
    }

  for (ukr = &recorded_unklines; (ukr2 = *ukr); ukr = &ukr2->next)
    {
      if ((ukr2->placed + UNKLINE_CACHE_TIME) < CurrentTime)
	  {
	    *ukr = ukr2->next;
	    MyFree(ukr2->mask);
	    MyFree(ukr2);
	    /* And put stuff back, safety in case we can't loop again */
	    if (!(ukr2 = *ukr))
	      break;
	  }
      else
        {
          if (mask && !match(mask, ukr2->mask))
            continue;
          count++;
          if (list && (list_max > ++listed_so_far))
/*             send_markup(sptr, &me, "SCAN-UNKLINE", */
/*                         "!begin<1>%s!end<1> unklined at !begin<2>!date<%ld>!end<2> (!begin<3>!time<%ld>!end<3>)", */
/*                         ukr2->mask, ukr2->placed, ukr2->placed - CurrentTime); */
            send_markup(sptr, &me, "SCAN-UNKLINE",
                        "%s unklined at %s (%s)",
                        ukr2->mask, smalldate(ukr2->placed), smalltime(ukr2->placed - CurrentTime));
        }
    }

  send_markup(sptr, &me, "UNKLINE-END", "End of unkline list");
/*   send_markup(sptr, &me, "SCAN-SUMMARY", "!begin<1>%d!end<1> matched", count); */
  send_markup(sptr, &me, "SCAN-SUMMARY", "%d matched", count);

  return 0;
}
示例#22
0
/***************************************************************************************************
*FunctionName: activityBufferFree
*Description: 界面内存释放
*Input: 
*Output: 
*Return: 
*Author: xsx
*Date: 2016年12月21日09:03:10
***************************************************************************************************/
static void activityBufferFree(void)
{
	MyFree(S_OtherSetPageBuffer);
	S_OtherSetPageBuffer = NULL;
}
示例#23
0
static void connect_dns_callback(void* vptr, adns_answer* reply)
#endif
{
  struct ConfItem* aconf = (struct ConfItem*) vptr;
  aconf->dns_pending = 0;
#ifndef USE_ADNS
  if (reply) {
#ifdef IPV6
    char name[HOSTLEN];
    inet_ntop(AF_INET, reply->hp->h_addr, name, HOSTLEN);
    inetpton(AFINET, name, &aconf->ipnum);
#else
    memcpy(&aconf->ipnum, reply->hp->h_addr, sizeof(struct in_addr));
#endif
    connect_server(aconf, 0, reply);
#else  
  if (reply && reply->status == adns_s_ok) {
#ifdef IPV6  
	/* IPV6 connect lookup not working with ADNS  -FIX- */
#else
    aconf->ipnum.s_addr = reply->rrs.addr->addr.inet.sin_addr.s_addr;
#endif
    MyFree(reply);
    connect_server(aconf, 0, NULL);
#endif        
  }
  else
    sendto_realops("Connect to %s failed: host lookup", aconf->host);
}

/*
 * set_sock_buffers - set send and receive buffers for socket
 * returns true (1) if successful, false (0) otherwise
 */
int set_sock_buffers(int fd, int size)
{
  if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*) &size, sizeof(size)) ||
      setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char*) &size, sizeof(size)))
    return 0;
  return 1;
}

/*
 * disable_sock_options - if remote has any socket options set, disable them 
 * returns true (1) if successful, false (0) otherwise
 */
static int disable_sock_options(int fd)
{
#if defined(IP_OPTIONS) && defined(IPPROTO_IP)
/* Broken on ipv6 - stu */
#ifndef IPV6
    if (setsockopt(fd, IPPROTO_IP, IP_OPTIONS, NULL, 0))
      return 0;
#endif /* IPv6 */ 
#endif
  return 1;
}

/*
 * set_non_blocking - Set the client connection into non-blocking mode. 
 * If your system doesn't support this, you're screwed, ircd will run like
 * crap.
 * returns true (1) if successful, false (0) otherwise
 */
int set_non_blocking(int fd)
{
  /*
   * NOTE: consult ALL your relevant manual pages *BEFORE* changing
   * these ioctl's.  There are quite a few variations on them,
   * as can be seen by the PCS one.  They are *NOT* all the same.
   * Heed this well. - Avalon.
   */
  /* This portion of code might also apply to NeXT.  -LynX */
#ifdef NBLOCK_SYSV
  int res = 1;

  if (ioctl(fd, FIONBIO, &res) == -1)
    return 0;

#else /* !NBLOCK_SYSV */
  int nonb = 0;
  int res;

#ifdef NBLOCK_POSIX
  nonb |= O_NONBLOCK;
#endif
#ifdef NBLOCK_BSD
  nonb |= O_NDELAY;
#endif

  res = fcntl(fd, F_GETFL, 0);
  if (-1 == res || fcntl(fd, F_SETFL, res | nonb) == -1)
    return 0;
#endif /* !NBLOCK_SYSV */
  return 1;
}
示例#24
0
int
WriteChans()

{
  FILE *fp;
  char tempname[MAXLINE];
  struct ChanInfo *cptr, *cnext;
  int ii,
      ccnt;

  ircsprintf(tempname, "%s.tmp", ChanServDB);
  fp = CreateDatabase(tempname, "ChanServ Database");
  if (!fp)
  {
    putlog(LOG1, "Error writing ChanServ Database (%s): %s",
      ChanServDB,
      strerror(errno));
    return 0;
  }

  ccnt = 0;

  for (ii = 0; ii < CHANLIST_MAX; ++ii)
  {
    for (cptr = chanlist[ii]; cptr; cptr = cnext)
    {
      cnext = cptr->next;

      if (!GetLink(cptr->contact))
      {
        /*
         * There is no contact - check if there is an alternate contact.  If
         * so, make them contact, otherwise delete the channel.
         */
        if (cptr->alternate && GetLink(cptr->alternate))
        {
          /*
           * There is a valid alternate contact - make them contact
           */
          MakeContact(cptr);
        }
        else
        {
          putlog(LOG2,
            "%s: dropping channel [%s] (no contact)",
            n_ChanServ,
            cptr->name);

          DeleteChan(cptr);

          continue;
        }
      }

      if (cptr->alternate)
      {
        if (!GetLink(cptr->alternate))
        {
          /* alternate contact's nickname has expired - erase it */
          putlog(LOG2,
            "%s: Alternate contact [%s] for channel [%s] expired, removing",
            n_ChanServ,
            cptr->alternate,
            cptr->name);

          MyFree(cptr->alternate);
          cptr->alternate = NULL;
        }
      }

      ++ccnt;

      /*
       * format: channel-name flags ts_created ts_lastused
       */
      fprintf(fp, "%s %ld %ld %ld\n",
	      cptr->name,
	      cptr->flags,
	      (long) cptr->created,
	      (long) cptr->lastused);

      {
        struct ChanAccess *ca;
        struct AutoKick *ak;
        int jj;

        /* write contact */
        fprintf(fp, "->FNDR %s %ld\n",
		cptr->contact,
		(long) cptr->last_contact_active);

        /* write password */
        fprintf(fp, "->PASS %s\n",
          cptr->password);

        if (cptr->alternate)
          fprintf(fp, "->SUCCESSOR %s %ld\n",
		  cptr->alternate,
		  (long) cptr->last_alternate_active);

        if (cptr->topic)
          fprintf(fp, "->TOPIC :%s\n",
            cptr->topic);

        if (cptr->limit)
          fprintf(fp, "->LIMIT %ld\n",
            cptr->limit);

        if (cptr->key)
          fprintf(fp, "->KEY %s\n",
            cptr->key);

        if (cptr->forward)
          fprintf(fp, "->FORWARD %s\n",
            cptr->forward);

        if (cptr->throttle)
          fprintf(fp, "->THROTTLE %s\n",
            cptr->throttle);

        if (cptr->dline)
          fprintf(fp, "->DLINE %s\n",
            cptr->dline);

        if (cptr->modes_on)
          fprintf(fp, "->MON %d\n",
            cptr->modes_on);

        if (cptr->modes_off)
          fprintf(fp, "->MOFF %d\n",
            cptr->modes_off);

        if (cptr->entrymsg)
          fprintf(fp, "->ENTRYMSG :%s\n",
            cptr->entrymsg);

        if (cptr->email)
          fprintf(fp, "->EMAIL %s\n",
            cptr->email);

        if (cptr->url)
          fprintf(fp, "->URL %s\n",
            cptr->url);

        fprintf(fp, "->ALVL");
        for (jj = 0; jj <= CA_CONTACT; ++jj)
          fprintf(fp, " %d",
            cptr->access_lvl[jj]);
        fprintf(fp, "\n");

        for (ca = cptr->access; ca; ca = ca->next)
          fprintf(fp, "->ACCESS %s %d %ld %ld\n",
		  ca->nptr ? ca->nptr->nick : stripctrlsymbols(ca->hostmask),
		  ca->level,
		  (long) ca->created, (long) ca->last_used);

        for (ak = cptr->akick; ak; ak = ak->next)
          fprintf(fp, "->AKICK %s :%s\n",
            stripctrlsymbols(ak->hostmask),
            ak->reason ? stripctrlsymbols(ak->reason) : "");
      }
    } /* for (cptr = chanlist[ii]; cptr; cptr = cnext) */
  } /* for (ii = 0; ii < CHANLIST_MAX; ++ii) */

  fclose(fp);

  rename(tempname, ChanServDB);

  putlog(LOG3, "Wrote %s (%d registered channels)",
    ChanServDB,
    ccnt);

  return (1);
} /* WriteChans() */
示例#25
0
/*
** m_away
**      parv[0] = sender prefix
**      parv[1] = away message
*/
static void
m_away(struct Client *client_p, struct Client *source_p, int parc, char *parv[])
{
	char *away, *awy2 = parv[1];

	if(MyClient(source_p) && !IsFloodDone(source_p))
		flood_endgrace(source_p);

	if(!IsClient(source_p))
		return;

	away = source_p->user->away;

	if(parc < 2 || !*awy2)
	{
		/* Marking as not away */

		if(away)
		{
			/* we now send this only if they were away before --is */
			sendto_server(client_p, NULL, NOCAPS, NOCAPS, ":%s AWAY", source_p->name);
			MyFree(away);
			source_p->user->away = NULL;
		}
		if(MyConnect(source_p))
			sendto_one(source_p, form_str(RPL_UNAWAY), me.name, parv[0]);
		return;
	}

	/* Marking as away */

	if(MyConnect(source_p) && !IsOper(source_p) &&
	   (CurrentTime - source_p->user->last_away) < ConfigFileEntry.pace_wait)
	{
		sendto_one(source_p, form_str(RPL_LOAD2HI),
			   me.name, parv[0], "AWAY");
		return;
	}

	source_p->user->last_away = CurrentTime;

	if(strlen(awy2) > (size_t) TOPICLEN)
		awy2[TOPICLEN] = '\0';

	/* we now send this only if they weren't away already --is */
	if(!away)
	{
		sendto_server(client_p, NULL, NOCAPS, NOCAPS,
			      ":%s AWAY :%s", source_p->name, awy2);
	}
	else
		MyFree(away);

	away = (char *) MyMalloc(strlen(awy2) + 1);
	strcpy(away, awy2);

	source_p->user->away = away;

	if(MyConnect(source_p))
		sendto_one(source_p, form_str(RPL_NOWAWAY), me.name, parv[0]);
}
示例#26
0
static void
ss_stats(struct Luser *lptr, int ac, char **av)

{
	float avgops, avguc, avgus;
	struct tm *tmp_tm;
	char str[MAXLINE + 1], tmp[MAXLINE + 1];
	char **tav;
	time_t currtime;

	RecordCommand("%s: %s!%s@%s STATS",
	              n_StatServ,
	              lptr->nick,
	              lptr->username,
	              lptr->hostname);

	avgops = Network->TotalOperators / Network->TotalServers;
	if (Network->TotalChannels > 0.0)
		avguc = Network->TotalUsers / Network->TotalChannels;
	else
		avguc = 0;
	avgus = Network->TotalUsers / Network->TotalServers;

	notice(n_StatServ, lptr->nick,
	       "Current Users:              %1.0f (avg. %1.2f users per server)",
	       Network->TotalUsers,
	       avgus);
	notice(n_StatServ, lptr->nick,
	       "Current Operators:          %1.0f (avg. %1.2f operators per server)",
	       Network->TotalOperators,
	       avgops);
	notice(n_StatServ, lptr->nick,
	       "Current Channels:           %1.0f (avg. %1.2f users per channel)",
	       Network->TotalChannels,
	       avguc);
	notice(n_StatServ, lptr->nick,
	       "Current Servers:            %1.0f",
	       Network->TotalServers);

	strlcpy(str, ctime(&Network->MaxUsers_ts), sizeof(str));
	str[strlen(str) - 1] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Users:                  %ld on %s",
	       Network->MaxUsers,
	       str);

	if (Network->MaxOperators_ts)
	{
		strlcpy(str, "on ", sizeof(str));
		strlcat(str, ctime(&Network->MaxOperators_ts), sizeof(str));
		str[strlen(str) - 1] = '\0';
	}
	else
		str[0] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Operators:              %ld %s",
	       Network->MaxOperators,
	       str);

	if (Network->MaxChannels_ts)
	{
		strlcpy(str, "on ", sizeof(str));
		strlcat(str, ctime(&Network->MaxChannels_ts), sizeof(str));
		str[strlen(str) - 1] = '\0';
	}
	else
		str[0] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Channels:               %ld %s",
	       Network->MaxChannels,
	       str);

	strlcpy(str, ctime(&Network->MaxServers_ts), sizeof(str));
	str[strlen(str) - 1] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Servers:                %ld on %s",
	       Network->MaxServers,
	       str);

	notice(n_StatServ, lptr->nick,
	       "Identd Users:               %ld",
	       Network->Identd);
	notice(n_StatServ, lptr->nick,
	       "Non-Identd Users:           %ld",
	       Network->NonIdentd);
	notice(n_StatServ, lptr->nick,
	       "Resolving Host Users:       %ld",
	       Network->ResHosts);
	notice(n_StatServ, lptr->nick,
	       "Non-Resolving Host Users:   %ld",
	       (long) Network->TotalUsers - Network->ResHosts);

	currtime = current_ts;
	strlcpy(tmp, ctime(&currtime), sizeof(tmp));
	SplitBuf(tmp, &tav);
	ircsprintf(str, "%s %s %s, %s", tav[0], tav[1], tav[2], tav[4]);
	notice(n_StatServ, lptr->nick,
	       "-- \002So far today:\002 (%s) --",
	       str);
	MyFree(tav);

	if (Network->MaxUsersT_ts)
	{
		tmp_tm = localtime(&Network->MaxUsersT_ts);
		ircsprintf(str, "at %d:%02d:%02d", tmp_tm->tm_hour, tmp_tm->tm_min,
		           tmp_tm->tm_sec);
	}
	else
		str[0] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Users:                  %ld %s",
	       Network->MaxUsersT,
	       str);

	if (Network->MaxOperatorsT_ts)
	{
		tmp_tm = localtime(&Network->MaxOperatorsT_ts);
		ircsprintf(str, "at %d:%02d:%02d", tmp_tm->tm_hour, tmp_tm->tm_min,
		           tmp_tm->tm_sec);
	}
	else
		str[0] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Operators:              %ld %s",
	       Network->MaxOperatorsT,
	       str);

	if (Network->MaxChannelsT_ts)
	{
		tmp_tm = localtime(&Network->MaxChannelsT_ts);
		ircsprintf(str, "at %d:%02d:%02d", tmp_tm->tm_hour, tmp_tm->tm_min,
		           tmp_tm->tm_sec);
	}
	else
		str[0] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Channels:               %ld %s",
	       Network->MaxChannelsT,
	       str);

	if (Network->MaxServersT_ts)
	{
		tmp_tm = localtime(&Network->MaxServersT_ts);
		ircsprintf(str, "at %d:%02d:%02d", tmp_tm->tm_hour, tmp_tm->tm_min,
		           tmp_tm->tm_sec);
	}
	else
		str[0] = '\0';
	notice(n_StatServ, lptr->nick,
	       "Max Servers:                %ld %s",
	       Network->MaxServersT,
	       str);

	notice(n_StatServ, lptr->nick,
	       "Operator Kills:             %ld",
	       Network->OperKillsT);
	notice(n_StatServ, lptr->nick,
	       "Server Kills:               %ld",
	       Network->ServKillsT);
} /* ss_stats() */
示例#27
0
static void activityBufferFree(void)
{
	MyFree(S_AdjustLedPageBuffer);
	S_AdjustLedPageBuffer = NULL;
}
示例#28
0
CDecoder::~CDecoder()
{
  LzmaDec_Free(&_state, &g_Alloc);
  MyFree(_inBuf);
}
示例#29
0
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
示例#30
0
/**************************************************************************
 * IsUserAdmin [SETUPAPI.@]
 *
 * Checks whether the current user is a member of the Administrators group.
 *
 * PARAMS
 *     None
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */
BOOL WINAPI IsUserAdmin(VOID)
{
    SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
    HANDLE hToken;
    DWORD dwSize;
    PTOKEN_GROUPS lpGroups;
    PSID lpSid;
    DWORD i;
    BOOL bResult = FALSE;

    TRACE("\n");

    if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
    {
        return FALSE;
    }

    if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
    {
        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
        {
            CloseHandle(hToken);
            return FALSE;
        }
    }

    lpGroups = MyMalloc(dwSize);
    if (lpGroups == NULL)
    {
        CloseHandle(hToken);
        return FALSE;
    }

    if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
    {
        MyFree(lpGroups);
        CloseHandle(hToken);
        return FALSE;
    }

    CloseHandle(hToken);

    if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
                                  DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
                                  &lpSid))
    {
        MyFree(lpGroups);
        return FALSE;
    }

    for (i = 0; i < lpGroups->GroupCount; i++)
    {
        if (EqualSid(lpSid, lpGroups->Groups[i].Sid))
        {
            bResult = TRUE;
            break;
        }
    }

    FreeSid(lpSid);
    MyFree(lpGroups);

    return bResult;
}