示例#1
0
		++provider_it;
	}
	PyTuple_SET_ITEM(tuple, 0, service_list);
	PyTuple_SET_ITEM(tuple, 1, provider_list);
	PyTuple_SET_ITEM(tuple, 2, caid_list);
	return tuple;
}

const char *PyObject_TypeStr(PyObject *o)
{
	return o->ob_type && o->ob_type->tp_name ? o->ob_type->tp_name : "unknown object type";
}

RESULT eDVBCIInterfaces::setDescrambleRules(int slotid, SWIG_PYOBJECT(ePyObject) obj )
{
	eDVBCISlot *slot = getSlot(slotid);
	if (!slot)
	{
		char tmp[255];
		snprintf(tmp, 255, "eDVBCIInterfaces::setDescrambleRules try to set rules for CI Slot %d... but just %zd slots are available", slotid, m_slots.size());
		PyErr_SetString(PyExc_StandardError, tmp);
		return -1;
	}
	if (!PyTuple_Check(obj))
	{
		char tmp[255];
		snprintf(tmp, 255, "2nd argument of setDescrambleRules is not a tuple.. it is a '%s'!!", PyObject_TypeStr(obj));
		PyErr_SetString(PyExc_StandardError, tmp);
		return -1;
	}
	if (PyTuple_Size(obj) != 3)
// ES5 8.10.5 ToPropertyDescriptor
static bool toPropertyDescriptor(ExecState* exec, JSValue in, PropertyDescriptor& desc)
{
    if (!in.isObject()) {
        throwError(exec, TypeError, "Property description must be an object.");
        return false;
    }
    JSObject* description = asObject(in);

    PropertySlot enumerableSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().enumerable, enumerableSlot)) {
        desc.setEnumerable(enumerableSlot.getValue(exec, exec->propertyNames().enumerable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    PropertySlot configurableSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().configurable, configurableSlot)) {
        desc.setConfigurable(configurableSlot.getValue(exec, exec->propertyNames().configurable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    JSValue value;
    PropertySlot valueSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().value, valueSlot)) {
        desc.setValue(valueSlot.getValue(exec, exec->propertyNames().value));
        if (exec->hadException())
            return false;
    }

    PropertySlot writableSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().writable, writableSlot)) {
        desc.setWritable(writableSlot.getValue(exec, exec->propertyNames().writable).toBoolean(exec));
        if (exec->hadException())
            return false;
    }

    PropertySlot getSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().get, getSlot)) {
        JSValue get = getSlot.getValue(exec, exec->propertyNames().get);
        if (exec->hadException())
            return false;
        if (!get.isUndefined()) {
            CallData callData;
            if (get.getCallData(callData) == CallTypeNone) {
                throwError(exec, TypeError, "Getter must be a function.");
                return false;
            }
        } else
            get = JSValue();
        desc.setGetter(get);
    }

    PropertySlot setSlot(description);
    if (description->getPropertySlot(exec, exec->propertyNames().set, setSlot)) {
        JSValue set = setSlot.getValue(exec, exec->propertyNames().set);
        if (exec->hadException())
            return false;
        if (!set.isUndefined()) {
            CallData callData;
            if (set.getCallData(callData) == CallTypeNone) {
                throwError(exec, TypeError, "Setter must be a function.");
                return false;
            }
        } else
            set = JSValue();

        desc.setSetter(set);
    }

    if (!desc.isAccessorDescriptor())
        return true;

    if (desc.value()) {
        throwError(exec, TypeError, "Invalid property.  'value' present on property with getter or setter.");
        return false;
    }

    if (desc.writablePresent()) {
        throwError(exec, TypeError, "Invalid property.  'writable' present on property with getter or setter.");
        return false;
    }
    return true;
}
示例#3
0
文件: page.cpp 项目: bdmeyer2/B-Tree
void Page::deleteRecord(const RecordId& record_id,
                        const bool allow_slot_compaction) {
  validateRecordId(record_id);
  PageSlot* slot = getSlot(record_id.slot_number);

	for(int i = 0; i < slot->item_length; i++)
		data_[i + slot->item_offset] = '\0';

  //data_.replace(slot->item_offset, slot->item_length, slot->item_length, '\0');

  // Compact the data by removing the hole left by this record (if necessary).
  std::uint16_t move_offset = slot->item_offset; 
  std::size_t move_bytes = 0;
  for (SlotId i = 1; i <= header_.num_slots; ++i) {
    PageSlot* other_slot = getSlot(i);
    if (other_slot->used && other_slot->item_offset < slot->item_offset) {
      if (other_slot->item_offset < move_offset) {
        move_offset = other_slot->item_offset;
      }
      move_bytes += other_slot->item_length;
      // Update the slot for the other data to reflect the soon-to-be-new
      // location.
      other_slot->item_offset += slot->item_length;
    }
  }
  // If we have data to move, shift it to the right.
  if (move_bytes > 0) {
    const std::string& data_to_move = std::string(data_, DATA_SIZE).substr(move_offset, move_bytes);

		for(std::uint16_t i = 0; i < move_bytes; i++)
			data_[i + move_offset + slot->item_length] = data_to_move[i];

    //data_.replace(move_offset + slot->item_length, move_bytes, data_to_move);
  }
  header_.free_space_upper_bound += slot->item_length;

  // Mark slot as unused.
  slot->used = false;
  slot->item_offset = 0;
  slot->item_length = 0;
  ++header_.num_free_slots;

  if (allow_slot_compaction && record_id.slot_number == header_.num_slots) {
    // Last slot in the list, so we need to free any unused slots that are at
    // the end of the slot list.
    int num_slots_to_delete = 1;
    for (SlotId i = 1; i < header_.num_slots; ++i) {
      // Traverse list backwards, looking for unused slots.
      const PageSlot* other_slot = getSlot(header_.num_slots - i);
      if (!other_slot->used) {
        ++num_slots_to_delete;
      } else {
        // Stop at the first used slot we find, since we can't move used slots
        // without affecting record IDs.
        break;
      }
    }
    header_.num_slots -= num_slots_to_delete;
    header_.num_free_slots -= num_slots_to_delete;
    header_.free_space_lower_bound -= sizeof(PageSlot) * num_slots_to_delete;
  }
}
示例#4
0
bool Inventory::pickUp(World& world, Unit& unit, WorldItem* item, bool forced) {

    assert(item != 0 && "Picking up an item failed: Nullpointer!");

    if(!forced) {
        if(last_pickup_time + 13 > world.currentWorldFrame) return false;
        last_pickup_time = world.currentWorldFrame;
    }

    unsigned slot = getSlot(item);


    // armor slot, easy
    if(slot < 6) {
        // if wearing something already, THROW IT ON THE GROUND!!11!
        if(this->wieldedItems[slot] != 0) {
            this->dropItemSlot(world, unit.getEyePosition(), slot);
        }

        this->pickUpHelper(world, unit, item, slot);
        return true;
    }

    // weapon item, a bit more difficult
    if(slot >= 6 && slot < this->small_items_begin) {
        // if there is a weapon slot that is empty, then place the item there.
        if(this->wieldedItems[6] == 0) {
            this->pickUpHelper(world, unit, item, 6);
            return true;
        }

        if(this->wieldedItems[7] == 0) {
            this->pickUpHelper(world, unit, item, 7);
            return true;
        }


        // if a weapon is selected, then replace that weapon
        if(this->active_item >= 6u && this->active_item < this->small_items_begin) {
            this->dropItemSlot(world, unit.getEyePosition(), (int)this->active_item);
            this->pickUpHelper(world, unit, item, active_item);
            return true;
        }

        // replace first weapon item
        this->dropItemSlot(world, unit.getEyePosition(), 6);
        this->pickUpHelper(world, unit, item, 6);
        return true;
    }


    // small item
    if(slot == 8) {
        for(unsigned i=this->small_items_begin; i<this->max_items; ++i) {
            if(this->wieldedItems[i] == 0) {
                this->pickUpHelper(world, unit, item, i);
                return true;
            }
        }

        if(this->active_item >= this->small_items_begin) {
            if(this->wieldedItems[active_item] != 0) {
                this->dropItemSlot(world, unit.getEyePosition(), active_item);
            }
            this->pickUpHelper(world, unit, item, active_item);
            return true;
        }

        // world.add_message("^YInventory full! Make room in the inventory first.");
        return false;
    }

    if(slot == 9) {
        world.add_message("^RWARNING: ^YOperator pick-up not implemented.");
    }
    else {
        world.add_message("^RWARNING: ^YUnrecognized item type. Interaction not allowed.");
    }

    return false;
}
bool AutoBan::hasPerm(long ip, 
		      char *code, long codeLen, 
		      char *uip,  long uipLen, 
		      TcpSocket   *s,
		      HttpRequest *r,
		      SafeBuf* testBuf,
		      bool justCheck ) {
	char *reqStr = r->getRequest();
	long  reqLen  = r->getRequestLen();
	long raw = r->getLong("xml", 0);
	long isHuman = 0;
	if(code && hasCode(code, codeLen, ip )) {
		//don't close client's sockets
		if(s) s->m_prefLevel++;

		//no ip, but valid code, let them through.
		if(!uip) return true;
		ip = atoip(uip, uipLen);
		//	log(LOG_WARN, "has uip %s", uip);
		if(!ip) return true;
		//has code and uip, do the check.
		//the front end can administer a turing test
		//and tell us to unban them
		isHuman = r->getLong("ishuman", 0);
	}

	// if ip is local and uip is there, use it
	if ( uip && r->isLocal() ) {
		// it's local, let it through
		if( ! uip ) return true;
		// get the new ip then
		ip = atoip(uip, uipLen);
		//	log(LOG_WARN, "has uip %s", uip);
		if ( !ip ) return true;
		//has code and uip, do the check.
	}

	//now we check the ip block which the ip is in.
	unsigned long ipBlock = (unsigned long)ip & 0x0000ffff;
	unsigned long i = getSlot((unsigned long)ipBlock);
	if((unsigned long)m_detectKeys[i] == ipBlock) {
		if(m_detectVals[i].m_flags & ALLOW) {
			if ( justCheck ) return true;
			m_detectVals[i].m_dayCount++;
			if(s) s->m_prefLevel++;
			return true;
		}
		if(m_detectVals[i].m_flags & DENY) {
			if ( justCheck ) return false;
			m_detectVals[i].m_dayCount++;
			return false;
		}
	}

	//now we check the ip group which the ip is in.
	unsigned long ipGroup = (unsigned long)ip & 0x00ffffff;
	i = getSlot((unsigned long)ipGroup);
	if((unsigned long)m_detectKeys[i] == ipGroup) {
		if(m_detectVals[i].m_flags & ALLOW) {
			if ( justCheck ) return true;
			m_detectVals[i].m_dayCount++;
			if(s) s->m_prefLevel++;
			return true;
		}
		if(m_detectVals[i].m_flags & DENY) {
			if ( justCheck ) return false;
			m_detectVals[i].m_dayCount++;
			return false;
		}
	}


	i = getSlot((unsigned long)ip);
	long now = getTime();

	long banTest = r->getLong("bantest",0);
	if ( banTest ) {
		log("autoban: doing ban test");
		goto doTuringTest;
	}

	
	if(m_detectKeys[i] == ip) {
		if(m_detectVals[i].m_flags & ALLOW) {
			// do not inc if just checking, like for a gif file
			if ( justCheck ) return true;
			//explicitly allowed.
			//log(LOG_WARN,"autoban: %li allowed.", ip);
			m_detectVals[i].m_dayCount++;
			if(s) s->m_prefLevel++;
			return true;
		}
		if(m_detectVals[i].m_flags & DENY) {
			// do not inc if just checking, like for a gif file
			if ( justCheck ) return false;
			//banned by autoban, or explicity banned by matt.
			long explicitBan = m_detectVals[i].m_flags & FROMCONF;
			//log(LOG_WARN,"autoban: %li rejected.", ip);
			if(!explicitBan &&
			   // MDW yippy project - no! don't unban bots!
			   //(m_detectVals[i].m_dayExpires < now || isHuman)) {
			   (isHuman)) {
				//they are unbanned for now, I guess.
				m_detectVals[i].m_flags &= ~DENY; 
				m_detectVals[i].m_dayExpires = now + ONE_DAY;
				m_detectVals[i].m_minuteExpires = now + 60;
				m_detectVals[i].m_dayCount = 1;
				m_detectVals[i].m_minuteCount = 1;
				log("autoban: auto-unbanning %s",iptoa(ip));
				//return true;
				goto checkSubstr;
			}

			m_detectVals[i].m_dayCount++;
			if(explicitBan) return false;
			
			if(uip) return false;
			goto doTuringTest;

		}

		// do not inc if just checking, like a gif file
		if ( justCheck ) return true;

		/*
		if( m_detectVals[i].m_minuteCount > 0 &&
		    // two requests in one second?
		    now == m_detectVals[i].m_minuteExpires - 60 ) {
			m_detectVals[i].m_flags |= DENY;
			log("autoban: second-banning %s",iptoa(ip));
			long banUntil = now + 
				(ONE_DAY * 
				 (m_detectVals[i].m_timesBanned + 1));
			if(banUntil < 0 || 
			   m_detectVals[i].m_timesBanned == 255 ) {
				m_detectVals[i].m_dayExpires = 
					0x7fffffff;
			}
			else {
				m_detectVals[i].m_timesBanned++;
				m_detectVals[i].m_dayExpires =banUntil;
			}
			return false;
		}
		*/

		if(m_detectVals[i].m_minuteCount >= 
		   g_conf.m_numFreeQueriesPerMinute) {
			if(m_detectVals[i].m_minuteExpires > now) {
				//ban 'em, they are a cowbot, so they
				//don't get the turing test
				m_detectVals[i].m_flags |= DENY;
				log("autoban: minute-banning %s",iptoa(ip));
				long banUntil = now + 
					(ONE_DAY * 
					 (m_detectVals[i].m_timesBanned + 1));
				if(banUntil < 0 || m_detectVals[i].m_timesBanned == 255 ) {
					m_detectVals[i].m_dayExpires = 0x7fffffff;
				}
				else {
					m_detectVals[i].m_timesBanned++;
					m_detectVals[i].m_dayExpires = banUntil;
				}
				return false;
				//goto doTuringTest;
			}
			else {
				m_detectVals[i].m_minuteExpires = now + 60;
				m_detectVals[i].m_minuteCount  = 0;
			}
		}
		if((unsigned long)m_detectVals[i].m_dayCount >= 
		   g_conf.m_numFreeQueriesPerDay) {
			if(m_detectVals[i].m_dayExpires > now) {
				//ban 'em
				log("autoban: day-banning %s",iptoa(ip));
				m_detectVals[i].m_flags |= DENY;
				if(m_detectVals[i].m_timesBanned != 255)
					m_detectVals[i].m_timesBanned++;
				m_detectVals[i].m_dayExpires = now + 
					(ONE_DAY * m_detectVals[i].
					 m_timesBanned);

				if(uip) return false;
				goto doTuringTest;
			}
			else {
				m_detectVals[i].m_dayExpires = now + ONE_DAY;
				m_detectVals[i].m_dayCount  = 0;
			}
		}
		m_detectVals[i].m_minuteCount++;
		m_detectVals[i].m_dayCount++;
		//return true;
		goto checkSubstr;
	}

	// do not inc if just checking, like for a gif file
	if ( justCheck ) return true;

	if(m_detectKeys[i] == 0) {
		if(m_numEntries * 1.2 > m_tableSize ) {
			//here we grow the table and adjust i to an 
			//empty slot in the new (bigger) table
			if(!growTable()) 
				//return true;
				goto checkSubstr;

			i = getSlot(ip);
		}
			
		
		m_detectKeys[i] = ip;
		m_detectVals[i].m_flags = 0;
		m_detectVals[i].m_minuteCount = 1;
		m_detectVals[i].m_dayCount    = 1;
		m_detectVals[i].m_minuteExpires = now + 60;
		m_detectVals[i].m_dayExpires = now + ONE_DAY;
		m_detectVals[i].m_timesBanned = 0;
		++m_numEntries;

		//log(LOG_WARN,"autoban: %li adding to empty slot.", 
		//ip);
		//return true;
		goto checkSubstr;
	}
	
	//we go here if someone is banned and they are trying to search
 doTuringTest:

	// sanity!
	if ( justCheck ) { char *xx=NULL;*xx=0; }

	if( raw == 0 ) {
		// did we get a good response from the turing test?
		if( g_turingTest.isHuman(r)) {
			m_detectVals[i].m_flags &= ~DENY; 
			//log("autoban: turing-unbanning %s",iptoa(ip));
			m_detectVals[i].m_dayExpires = now + ONE_DAY;
			m_detectVals[i].m_minuteExpires = now + 60;
			m_detectVals[i].m_dayCount = 1;
			m_detectVals[i].m_minuteCount = 1;
			log(LOG_INFO, "autoban: ip %s has unbanned "
			    "themselves", iptoa(ip));
			return true;
		}
		testBuf->safePrintf("<form method=get>");
		long queryLen = 0;
		char* query = r->getValue("q" , &queryLen);
		long start = r->getLong("s" , 0);
		if ( query )
			testBuf->safePrintf("<input type=hidden name=\"q\" "
					    "value=\"%s\">\n", query);
		if ( start > 0 )
			testBuf->safePrintf("<input type=hidden name=\"s\" "
					    "value=\"%li\">\n", start);
		long gigabits = r->getLong("gigabits",0);
		if ( gigabits )
			testBuf->safePrintf("<input type=hidden name=gigabits "
					    "value=1>\n");

		//
		// yippy parms
		//
		char *ifs = r->getString("input-form",NULL);
		if ( ifs )
			testBuf->safePrintf("<input type=hidden "
					    "name=\"input-form\" "
					    "value=\"%s\">\n", ifs );
		char *vs = r->getString("v:sources",NULL);
		if ( vs )
			testBuf->safePrintf("<input type=hidden "
					    "name=\"v:sources\" "
					    "value=\"%s\">\n", vs );
		char *vp = r->getString("v:project",NULL);
		if ( vp )
			testBuf->safePrintf("<input type=hidden "
					    "name=\"v:project\" "
					    "value=\"%s\">\n", vp );
		char *qp = r->getString("query",NULL);
		if ( qp )
			testBuf->safePrintf("<input type=hidden "
					    "name=\"query\" "
					    "value=\"%s\">\n", qp);

		if ( banTest )
			testBuf->safePrintf("<input type=hidden "
					    "name=\"bantest\" "
					    "value=\"1\">\n");
			
		//
		// end yippy parms
		//

		// display the turing test so they can unban themselves
		g_turingTest.printTest(testBuf);
		testBuf->safePrintf("<br><center><input type=submit "
				    "value=\"submit\"></center><br>");
		testBuf->safePrintf("</form>");
	}
	return false;

checkSubstr:

	// sanity!
	if ( justCheck ) { char *xx=NULL;*xx=0; }

	// Look for regular expressions that may serve as a signature of 
	// a botnet attack

	char *banRegex = g_conf.m_banRegex;
	long banRegexLen = g_conf.m_banRegexLen;
	if (!banRegex || !banRegexLen) return true;


	
	// Don't do regex...look for comma-separated lists of substrings
	long start = 0;
	bool gotMatch = false;
	bool missedMatch = false;

	for (long i=0;i<= banRegexLen;i++) {
		if (i != banRegexLen && 
		    banRegex[i] && banRegex[i] != '\n' && banRegex[i] != '\r'
		    && banRegex[i] != ',')
			continue;
		
		char c = banRegex[i];
		// NULL terminate
		banRegex[i] = '\0';
		// search for substr (must be longer than 2 chars
		if ( i - start > 2){
			if (strnstr2(reqStr, reqLen, &banRegex[start])) 
				gotMatch = true;
			else missedMatch = true;
		}
		banRegex[i] = c;
		start = i+1;
		// check the next substr if we're not at the 
		// end of line or end of buffer
		if (c != '\n' && c != '\r' && c != '\0') continue;
		
		// did we get all the substrings?
		if (gotMatch && !missedMatch) return false;
		// reset for the next set of substrings
		gotMatch = false;
		missedMatch = false;
	}
	
	return true;
}