2006-01-19 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientAccount.cpp, aiclient/ClientAccount.h,
aiclient/ClientConnection.cpp, aiclient/ClientConnection.h,
aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp,
client/BaseClient.h, client/CharacterClient.cpp,
client/CharacterClient.h, client/ClientConnection.cpp,
client/ClientConnection.h, client/CreatorClient.cpp,
client/CreatorClient.h, client/ObserverClient.cpp,
client/ObserverClient.h, client/Py_CreatorClient.cpp,
client/Py_CreatorClient.h, client/client.cpp,
client/define_world.cpp, client/define_world.h, common/Add.h,
common/Affect.h, common/AtlasFileLoader.cpp,
common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp,
common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h,
common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp,
common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h,
common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h,
common/Eat.h, common/FormattedXMLWriter.cpp,
common/FormattedXMLWriter.h, common/Generic.h, common/Load.h,
common/Monitor.h, common/Mow.h, common/Nourish.h,
common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp,
common/Property.h, common/Property_impl.h, common/Save.h,
common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h,
common/Use.h, common/Wield.h, common/accountbase.cpp,
common/accountbase.h, common/const.cpp, common/const.h,
common/custom.cpp, common/debug.h, common/globals.cpp,
common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp,
common/inheritance.h, common/inheritance_impl.h, common/log.cpp,
common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h,
common/operations.cpp, common/operations.h, common/random.h,
common/refno.h, common/serialno.cpp, common/serialno.h,
common/system.cpp, common/system.h, common/terrain_utils.cpp,
common/terrain_utils.h, common/type_utils.h, common/types.h,
common/utility.cpp, common/utility.h, modules/DateTime.cpp,
modules/DateTime.h, modules/Location.cpp, modules/Location.h,
modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp,
physics/BBox.h, physics/Collision.cpp, physics/Collision.h,
physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp,
physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp,
rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h,
rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h,
rulesets/BaseMind.cpp, rulesets/BaseMind.h,
rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h,
rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp,
rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h,
rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp,
rulesets/Entity.h, rulesets/EntityProperties.cpp,
rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h,
rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp,
rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h,
rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp,
rulesets/MemMap.h, rulesets/MemMap_methods.h,
rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h,
rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp,
rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h,
rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp,
rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h,
rulesets/Py_Location.cpp, rulesets/Py_Location.h,
rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp,
rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Operation.h,
rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp,
rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h,
rulesets/Py_Property.cpp, rulesets/Py_Property.h,
rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h,
rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h,
rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h,
rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp,
rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp,
rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h,
rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h,
rulesets/PythonArithmeticScript.cpp,
rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp,
rulesets/PythonMindScript.h, rulesets/PythonScript.cpp,
rulesets/PythonScript.h, rulesets/PythonThingScript.cpp,
rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp,
rulesets/PythonWrapper.h, rulesets/Python_API.cpp,
rulesets/Python_API.h, rulesets/Python_Script_Utils.h,
rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp,
rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h,
rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h,
rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp,
rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h,
rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h,
rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp,
rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h,
rulesets/attributes.h, server/Account.cpp, server/Account.h,
server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp,
server/ArithmeticFactory.h, server/CommClient.cpp,
server/CommClient.h, server/CommIdleSocket.cpp,
server/CommIdleSocket.h, server/CommListener.cpp,
server/CommListener.h, server/CommLocalClient.cpp,
server/CommLocalClient.h, server/CommMDNSPublisher.cpp,
server/CommMDNSPublisher.h, server/CommMaster.cpp,
server/CommMaster.h, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommPeer.cpp,
server/CommPeer.h, server/CommPeerListener.cpp,
server/CommPeerListener.h, server/CommRemoteClient.cpp,
server/CommRemoteClient.h, server/CommServer.cpp,
server/CommServer.h, server/CommSlaveClient.cpp,
server/CommSlaveClient.h, server/CommSlaveListener.cpp,
server/CommSlaveListener.h, server/CommSocket.cpp,
server/CommSocket.h, server/CommUnixListener.cpp,
server/CommUnixListener.h, server/Connection.cpp,
server/Connection.h, server/Connection_methods.h,
server/EntityFactory.cpp, server/EntityFactory.h,
server/ExternalMind.cpp, server/ExternalMind.h,
server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h,
server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h,
server/Persistance.cpp, server/Persistance.h,
server/PersistantThingFactory.cpp, server/PersistantThingFactory.h,
server/PersistantThingFactory_impl.h, server/Persistor.cpp,
server/Persistor.h, server/Persistor_impl.h,
server/Player.cpp, server/Player.h, server/Restoration.cpp,
server/Restoration.h, server/Restorer.cpp, server/Restorer.h,
server/Restorer_impl.h, server/ScriptFactory.cpp,
server/ScriptFactory.h, server/ServerRouting.cpp,
server/ServerRouting.h, server/ServerRouting_methods.h,
server/SlaveClientConnection.cpp, server/SlaveClientConnection.h,
server/TaskFactory.cpp, server/TaskFactory.h,
server/TrustedConnection.cpp, server/TrustedConnection.h,
server/WorldRouter.cpp, server/WorldRouter.h,
server/server.cpp, server/server.h, server/slave.cpp,
tests/Areatest.cpp, tests/BaseEntitytest.cpp,
tests/Charactertest.cpp, tests/Containertest.cpp,
tests/Creatortest.cpp, tests/EntityExerciser.h,
tests/EntityFactorytest.cpp, tests/Entitytest.cpp,
tests/Foodtest.cpp, tests/IGEntityExerciser.h,
tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp,
tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp,
tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h,
tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp,
tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp,
tests/distancetest.cpp, tests/emergencetest.cpp,
tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp,
tests/systemtest.cpp, tests/transformtest.cpp,
tests/type_utilstest.cpp, tests/utilitytest.cpp,
tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp,
tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp,
tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp,
tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp,
tools/cywatchdog.cpp: Replace the copyright and license statements
with new versions that include disclaimer of warranty, and
permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
|
|
|
// Cyphesis Online RPG Server and AI Engine
|
2004-11-29 Al Riddoch <alriddoch@zepler.org>
* common/BaseEntity.cpp, common/BaseEntity.h, common/BaseWorld.cpp,
common/BaseWorld.h, common/Burn.h, common/Chop.h, common/Cut.h,
common/Database.cpp, common/Database.h, common/Eat.h,
common/Generic.h, common/Load.h, common/Nourish.h,
common/OOGThing.cpp, common/OOGThing.h, common/Save.h,
common/Setup.h, common/Tick.h, common/accountbase.cpp,
common/accountbase.h, common/const.cpp, common/const.h,
common/custom.cpp, common/debug.h, common/globals.cpp,
common/globals.h, common/inheritance.cpp, common/inheritance.h,
common/log.cpp, common/log.h, common/op_switch.h, common/random.h,
common/serialno.h, common/system.cpp, common/system.h,
common/type_utils.h, common/types.h, common/utility.cpp,
common/utility.h: Update copyright dates in files as appropriate.
2004-11-29 21:42:00 +00:00
|
|
|
// Copyright (C) 2000-2004 Alistair Riddoch
|
2006-01-19 Al Riddoch <alriddoch@zepler.org>
* aiclient/ClientAccount.cpp, aiclient/ClientAccount.h,
aiclient/ClientConnection.cpp, aiclient/ClientConnection.h,
aiclient/client.cpp, aiclient/client.h, client/BaseClient.cpp,
client/BaseClient.h, client/CharacterClient.cpp,
client/CharacterClient.h, client/ClientConnection.cpp,
client/ClientConnection.h, client/CreatorClient.cpp,
client/CreatorClient.h, client/ObserverClient.cpp,
client/ObserverClient.h, client/Py_CreatorClient.cpp,
client/Py_CreatorClient.h, client/client.cpp,
client/define_world.cpp, client/define_world.h, common/Add.h,
common/Affect.h, common/AtlasFileLoader.cpp,
common/AtlasFileLoader.h, common/Attack.h, common/BaseEntity.cpp,
common/BaseEntity.h, common/BaseWorld.cpp, common/BaseWorld.h,
common/Burn.h, common/Chop.h, common/Connect.h, common/CustomOp.cpp,
common/CustomOp.h, common/CustomOp_impl.h, common/Cut.h,
common/Database.cpp, common/Database.h, common/Delve.h, common/Dig.h,
common/Eat.h, common/FormattedXMLWriter.cpp,
common/FormattedXMLWriter.h, common/Generic.h, common/Load.h,
common/Monitor.h, common/Mow.h, common/Nourish.h,
common/OOGThing.cpp, common/OOGThing.h, common/Property.cpp,
common/Property.h, common/Property_impl.h, common/Save.h,
common/Setup.h, common/Tick.h, common/Unseen.h, common/Update.h,
common/Use.h, common/Wield.h, common/accountbase.cpp,
common/accountbase.h, common/const.cpp, common/const.h,
common/custom.cpp, common/debug.h, common/globals.cpp,
common/globals.h, common/id.cpp, common/id.h, common/inheritance.cpp,
common/inheritance.h, common/inheritance_impl.h, common/log.cpp,
common/log.h, common/newid.cpp, common/nls.h, common/op_switch.h,
common/operations.cpp, common/operations.h, common/random.h,
common/refno.h, common/serialno.cpp, common/serialno.h,
common/system.cpp, common/system.h, common/terrain_utils.cpp,
common/terrain_utils.h, common/type_utils.h, common/types.h,
common/utility.cpp, common/utility.h, modules/DateTime.cpp,
modules/DateTime.h, modules/Location.cpp, modules/Location.h,
modules/WorldTime.cpp, modules/WorldTime.h, physics/BBox.cpp,
physics/BBox.h, physics/Collision.cpp, physics/Collision.h,
physics/Quaternion.cpp, physics/Quaternion.h, physics/Vector3D.cpp,
physics/Vector3D.h, physics/VectorPol.h, rulesets/Area.cpp,
rulesets/Area.h, rulesets/AreaProperty.cpp, rulesets/AreaProperty.h,
rulesets/ArithmeticScript.cpp, rulesets/ArithmeticScript.h,
rulesets/BaseMind.cpp, rulesets/BaseMind.h,
rulesets/CalendarProperty.cpp, rulesets/CalendarProperty.h,
rulesets/Character.cpp, rulesets/Character.h, rulesets/Combat.cpp,
rulesets/Combat.h, rulesets/Container.cpp, rulesets/Container.h,
rulesets/Creator.cpp, rulesets/Creator.h, rulesets/Entity.cpp,
rulesets/Entity.h, rulesets/EntityProperties.cpp,
rulesets/Entity_getLocation.h, rulesets/Fell.cpp, rulesets/Fell.h,
rulesets/Food.cpp, rulesets/Food.h, rulesets/Line.cpp,
rulesets/Line.h, rulesets/LineProperty.cpp, rulesets/LineProperty.h,
rulesets/MemEntity.cpp, rulesets/MemEntity.h, rulesets/MemMap.cpp,
rulesets/MemMap.h, rulesets/MemMap_methods.h,
rulesets/MindFactory.cpp, rulesets/MindFactory.h, rulesets/Missile.h,
rulesets/Motion.cpp, rulesets/Motion.h, rulesets/Movement.cpp,
rulesets/Movement.h, rulesets/Pedestrian.cpp, rulesets/Pedestrian.h,
rulesets/Plant.cpp, rulesets/Plant.h, rulesets/Py_BBox.cpp,
rulesets/Py_BBox.h, rulesets/Py_EntityWrapper.h,
rulesets/Py_Location.cpp, rulesets/Py_Location.h,
rulesets/Py_Map.cpp, rulesets/Py_Map.h, rulesets/Py_Mind.cpp,
rulesets/Py_Mind.h, rulesets/Py_Object.cpp, rulesets/Py_Object.h,
rulesets/Py_Operation.cpp, rulesets/Py_Operation.h,
rulesets/Py_Oplist.cpp, rulesets/Py_Oplist.h, rulesets/Py_Optime.cpp,
rulesets/Py_Optime.h, rulesets/Py_Point3D.cpp, rulesets/Py_Point3D.h,
rulesets/Py_Property.cpp, rulesets/Py_Property.h,
rulesets/Py_Quaternion.cpp, rulesets/Py_Quaternion.h,
rulesets/Py_RootEntity.cpp, rulesets/Py_RootEntity.h,
rulesets/Py_Statistics.cpp, rulesets/Py_Statistics.h,
rulesets/Py_Task.cpp, rulesets/Py_Task.h, rulesets/Py_Thing.cpp,
rulesets/Py_Thing.h, rulesets/Py_Vector3D.cpp,
rulesets/Py_Vector3D.h, rulesets/Py_World.cpp, rulesets/Py_World.h,
rulesets/Py_WorldTime.cpp, rulesets/Py_WorldTime.h,
rulesets/PythonArithmeticScript.cpp,
rulesets/PythonArithmeticScript.h, rulesets/PythonMindScript.cpp,
rulesets/PythonMindScript.h, rulesets/PythonScript.cpp,
rulesets/PythonScript.h, rulesets/PythonThingScript.cpp,
rulesets/PythonThingScript.h, rulesets/PythonWrapper.cpp,
rulesets/PythonWrapper.h, rulesets/Python_API.cpp,
rulesets/Python_API.h, rulesets/Python_Script_Utils.h,
rulesets/Script.cpp, rulesets/Script.h, rulesets/Stackable.cpp,
rulesets/Stackable.h, rulesets/Statistics.cpp, rulesets/Statistics.h,
rulesets/StatisticsProperty.cpp, rulesets/StatisticsProperty.h,
rulesets/Structure.cpp, rulesets/Structure.h, rulesets/Task.cpp,
rulesets/Task.h, rulesets/TaskScript.cpp, rulesets/TaskScript.h,
rulesets/TerrainProperty.cpp, rulesets/TerrainProperty.h,
rulesets/Thing.cpp, rulesets/Thing.h, rulesets/ThingFactory.cpp,
rulesets/ThingFactory.h, rulesets/World.cpp, rulesets/World.h,
rulesets/attributes.h, server/Account.cpp, server/Account.h,
server/Admin.cpp, server/Admin.h, server/ArithmeticFactory.cpp,
server/ArithmeticFactory.h, server/CommClient.cpp,
server/CommClient.h, server/CommIdleSocket.cpp,
server/CommIdleSocket.h, server/CommListener.cpp,
server/CommListener.h, server/CommLocalClient.cpp,
server/CommLocalClient.h, server/CommMDNSPublisher.cpp,
server/CommMDNSPublisher.h, server/CommMaster.cpp,
server/CommMaster.h, server/CommMetaClient.cpp,
server/CommMetaClient.h, server/CommPSQLSocket.cpp,
server/CommPSQLSocket.h, server/CommPeer.cpp,
server/CommPeer.h, server/CommPeerListener.cpp,
server/CommPeerListener.h, server/CommRemoteClient.cpp,
server/CommRemoteClient.h, server/CommServer.cpp,
server/CommServer.h, server/CommSlaveClient.cpp,
server/CommSlaveClient.h, server/CommSlaveListener.cpp,
server/CommSlaveListener.h, server/CommSocket.cpp,
server/CommSocket.h, server/CommUnixListener.cpp,
server/CommUnixListener.h, server/Connection.cpp,
server/Connection.h, server/Connection_methods.h,
server/EntityFactory.cpp, server/EntityFactory.h,
server/ExternalMind.cpp, server/ExternalMind.h,
server/Idle.cpp, server/Idle.h, server/Lobby.cpp, server/Lobby.h,
server/Master.cpp, server/Master.h, server/Peer.cpp, server/Peer.h,
server/Persistance.cpp, server/Persistance.h,
server/PersistantThingFactory.cpp, server/PersistantThingFactory.h,
server/PersistantThingFactory_impl.h, server/Persistor.cpp,
server/Persistor.h, server/Persistor_impl.h,
server/Player.cpp, server/Player.h, server/Restoration.cpp,
server/Restoration.h, server/Restorer.cpp, server/Restorer.h,
server/Restorer_impl.h, server/ScriptFactory.cpp,
server/ScriptFactory.h, server/ServerRouting.cpp,
server/ServerRouting.h, server/ServerRouting_methods.h,
server/SlaveClientConnection.cpp, server/SlaveClientConnection.h,
server/TaskFactory.cpp, server/TaskFactory.h,
server/TrustedConnection.cpp, server/TrustedConnection.h,
server/WorldRouter.cpp, server/WorldRouter.h,
server/server.cpp, server/server.h, server/slave.cpp,
tests/Areatest.cpp, tests/BaseEntitytest.cpp,
tests/Charactertest.cpp, tests/Containertest.cpp,
tests/Creatortest.cpp, tests/EntityExerciser.h,
tests/EntityFactorytest.cpp, tests/Entitytest.cpp,
tests/Foodtest.cpp, tests/IGEntityExerciser.h,
tests/Linetest.cpp, tests/Locationtest.cpp, tests/OOGThingtest.cpp,
tests/Planttest.cpp, tests/Propertytest.cpp, tests/Stackabletest.cpp,
tests/Structuretest.cpp, tests/Tasktest.cpp, tests/TestWorld.h,
tests/Thingtest.cpp, tests/WorldTimetest.cpp, tests/Worldtest.cpp,
tests/allOperations.h, tests/collisiontest.cpp, tests/consttest.cpp,
tests/distancetest.cpp, tests/emergencetest.cpp,
tests/inheritancetest.cpp, tests/logtest.cpp, tests/randomtest.cpp,
tests/systemtest.cpp, tests/transformtest.cpp,
tests/type_utilstest.cpp, tests/utilitytest.cpp,
tools/AdminClient.cpp, tools/AdminClient.h, tools/cyaddrules.cpp,
tools/cycmd.cpp, tools/cyconfig.cpp, tools/cyconvertrules.cpp,
tools/cyctrl.cpp, tools/cydbload.cpp, tools/cydumprules.cpp,
tools/cyisoload.cpp, tools/cyloadrules.cpp, tools/cypasswd.cpp,
tools/cywatchdog.cpp: Replace the copyright and license statements
with new versions that include disclaimer of warranty, and
permit distribution under later versions of the GPL.
2006-01-19 02:17:06 +00:00
|
|
|
//
|
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "system.h"
|
|
|
|
|
|
2003-03-07 00:22:12 +00:00
|
|
|
#include "log.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "globals.h"
|
2002-10-03 10:51:59 +00:00
|
|
|
|
2005-09-15 01:10:01 +00:00
|
|
|
#include <wfmath/MersenneTwister.h>
|
|
|
|
|
|
|
|
|
|
#include <gcrypt.h>
|
2003-03-22 17:00:04 +00:00
|
|
|
|
2005-09-20 16:50:30 +00:00
|
|
|
#include <cassert>
|
|
|
|
|
|
2005-09-15 01:10:01 +00:00
|
|
|
#include <iostream>
|
2003-03-22 17:00:04 +00:00
|
|
|
|
2002-10-03 10:51:59 +00:00
|
|
|
extern "C" {
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const bool debug_flag = false;
|
|
|
|
|
|
|
|
|
|
const std::string get_hostname()
|
|
|
|
|
{
|
|
|
|
|
struct utsname host_ident;
|
|
|
|
|
if (uname(&host_ident) != 0) {
|
|
|
|
|
return "UNKNOWN";
|
|
|
|
|
}
|
|
|
|
|
return std::string(host_ident.nodename);
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-02 14:06:35 +00:00
|
|
|
unsigned int security_check()
|
2006-03-25 10:55:53 +00:00
|
|
|
{
|
|
|
|
|
if (getuid() == 0 || geteuid() == 0) {
|
|
|
|
|
log(ERROR, "Running cyphesis as the superuser is dangerous.");
|
2006-05-16 21:44:26 +00:00
|
|
|
return 0;
|
2006-03-25 10:55:53 +00:00
|
|
|
}
|
|
|
|
|
return SECURITY_OKAY;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-11 23:33:58 +00:00
|
|
|
void reduce_priority(int p)
|
2006-05-02 14:06:35 +00:00
|
|
|
{
|
2006-05-11 23:33:58 +00:00
|
|
|
if (nice(p) < 0) {
|
2006-05-02 14:06:35 +00:00
|
|
|
log(ERROR, "Unable to increase nice level to reduce priority");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-20 17:47:51 +00:00
|
|
|
extern "C" void shutdown_on_signal(int signo)
|
2002-10-03 10:51:59 +00:00
|
|
|
{
|
|
|
|
|
exit_flag = true;
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_SIGACTION)
|
|
|
|
|
struct sigaction action;
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
|
sigaction(signo, &action, NULL);
|
|
|
|
|
#else
|
|
|
|
|
signal(signo, SIG_IGN);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-06 23:41:10 +00:00
|
|
|
extern "C" void report_segfault(int signo)
|
|
|
|
|
{
|
|
|
|
|
log(CRITICAL, "Segmentation fault");
|
2006-06-08 20:45:00 +00:00
|
|
|
log(NOTICE, "Please report this bug to alriddoch@zepler.org");
|
2004-05-06 23:41:10 +00:00
|
|
|
|
2004-05-08 18:44:34 +00:00
|
|
|
#if !defined(HAVE_SIGACTION)
|
2004-05-06 23:41:10 +00:00
|
|
|
signal(signo, SIG_DFL);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-07 00:03:25 +00:00
|
|
|
extern "C" void report_abort(int signo)
|
|
|
|
|
{
|
|
|
|
|
log(CRITICAL, "Aborted");
|
2006-06-08 20:45:00 +00:00
|
|
|
log(NOTICE, "Please report this bug to alriddoch@zepler.org");
|
2004-05-07 00:03:25 +00:00
|
|
|
|
2004-05-08 18:44:34 +00:00
|
|
|
#if !defined(HAVE_SIGACTION)
|
2004-05-07 00:03:25 +00:00
|
|
|
signal(signo, SIG_DFL);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 10:51:59 +00:00
|
|
|
void interactive_signals()
|
|
|
|
|
{
|
|
|
|
|
#if defined(HAVE_SIGACTION)
|
|
|
|
|
struct sigaction action;
|
|
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2003-07-20 17:47:51 +00:00
|
|
|
action.sa_handler = shutdown_on_signal;
|
2002-10-03 10:51:59 +00:00
|
|
|
sigaction(SIGINT, &action, NULL);
|
|
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2003-07-20 17:47:51 +00:00
|
|
|
action.sa_handler = shutdown_on_signal;
|
2002-10-03 10:51:59 +00:00
|
|
|
sigaction(SIGTERM, &action, NULL);
|
|
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2003-07-20 17:47:51 +00:00
|
|
|
action.sa_handler = shutdown_on_signal;
|
2002-10-03 10:51:59 +00:00
|
|
|
sigaction(SIGQUIT, &action, NULL);
|
2002-10-17 23:07:52 +00:00
|
|
|
|
2003-07-20 17:47:51 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = shutdown_on_signal;
|
|
|
|
|
sigaction(SIGHUP, &action, NULL);
|
|
|
|
|
|
2002-10-17 23:07:52 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
|
sigaction(SIGPIPE, &action, NULL);
|
2004-05-06 23:41:10 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
2005-10-05 21:48:38 +00:00
|
|
|
action.sa_flags = SA_RESETHAND;
|
2004-05-06 23:41:10 +00:00
|
|
|
action.sa_handler = report_segfault;
|
|
|
|
|
sigaction(SIGSEGV, &action, NULL);
|
2004-05-07 00:03:25 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
2005-10-05 21:48:38 +00:00
|
|
|
action.sa_flags = SA_RESETHAND;
|
2004-05-07 00:03:25 +00:00
|
|
|
action.sa_handler = report_abort;
|
|
|
|
|
sigaction(SIGABRT, &action, NULL);
|
2002-10-03 10:51:59 +00:00
|
|
|
#else
|
2003-07-20 17:47:51 +00:00
|
|
|
signal(SIGINT, shutdown_on_signal);
|
|
|
|
|
signal(SIGTERM, shutdown_on_signal);
|
|
|
|
|
signal(SIGQUIT, shutdown_on_signal);
|
|
|
|
|
signal(SIGHUP, shutdown_on_signal);
|
2002-10-17 23:07:52 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2004-05-06 23:41:10 +00:00
|
|
|
signal(SIGSEGV, report_segfault);
|
2004-05-07 00:03:25 +00:00
|
|
|
signal(SIGABRT, report_abort);
|
2002-10-03 10:51:59 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void daemon_signals()
|
|
|
|
|
{
|
|
|
|
|
#if defined(HAVE_SIGACTION)
|
|
|
|
|
struct sigaction action;
|
|
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
|
sigaction(SIGINT, &action, NULL);
|
|
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2003-07-20 17:47:51 +00:00
|
|
|
action.sa_handler = shutdown_on_signal;
|
2002-10-03 10:51:59 +00:00
|
|
|
sigaction(SIGTERM, &action, NULL);
|
|
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
|
sigaction(SIGQUIT, &action, NULL);
|
2002-10-17 23:07:52 +00:00
|
|
|
|
2003-07-20 17:47:51 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
|
sigaction(SIGHUP, &action, NULL);
|
|
|
|
|
|
2002-10-17 23:07:52 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
|
sigaction(SIGPIPE, &action, NULL);
|
2004-05-06 23:41:10 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
2005-10-05 21:48:38 +00:00
|
|
|
action.sa_flags = SA_RESETHAND;
|
2004-05-06 23:41:10 +00:00
|
|
|
action.sa_handler = report_segfault;
|
|
|
|
|
sigaction(SIGSEGV, &action, NULL);
|
2004-05-07 00:03:25 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
2005-10-05 21:48:38 +00:00
|
|
|
action.sa_flags = SA_RESETHAND;
|
2004-05-07 00:03:25 +00:00
|
|
|
action.sa_handler = report_abort;
|
|
|
|
|
sigaction(SIGABRT, &action, NULL);
|
2002-10-03 10:51:59 +00:00
|
|
|
#else
|
|
|
|
|
signal(SIGINT, SIG_IGN);
|
2003-07-20 17:47:51 +00:00
|
|
|
signal(SIGTERM, shutdown_on_signal);
|
2002-10-03 10:51:59 +00:00
|
|
|
signal(SIGQUIT, SIG_IGN);
|
2003-07-20 17:47:51 +00:00
|
|
|
signal(SIGHUP, SIG_IGN);
|
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2004-05-06 23:41:10 +00:00
|
|
|
signal(SIGSEGV, report_segfault);
|
2004-05-07 00:03:25 +00:00
|
|
|
signal(SIGABRT, report_abort);
|
2002-10-03 10:51:59 +00:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int daemonise()
|
|
|
|
|
{
|
|
|
|
|
int pid = fork();
|
|
|
|
|
int new_stdio;
|
|
|
|
|
int status = 0;
|
|
|
|
|
int running = false;
|
|
|
|
|
|
|
|
|
|
switch (pid) {
|
|
|
|
|
case 0:
|
|
|
|
|
// Child
|
|
|
|
|
// Switch signal behavoir
|
|
|
|
|
daemon_signals();
|
|
|
|
|
// Get rid if stdio
|
|
|
|
|
close(STDIN_FILENO);
|
|
|
|
|
close(STDOUT_FILENO);
|
|
|
|
|
close(STDERR_FILENO);
|
|
|
|
|
// Get rid of controlling tty, and start new session
|
|
|
|
|
setsid();
|
|
|
|
|
// Open /dev/null on the stdio file descriptors to avoid problems
|
|
|
|
|
new_stdio = open("/dev/null", O_RDWR);
|
|
|
|
|
dup2(new_stdio, STDIN_FILENO);
|
|
|
|
|
dup2(new_stdio, STDOUT_FILENO);
|
|
|
|
|
dup2(new_stdio, STDERR_FILENO);
|
|
|
|
|
break;
|
|
|
|
|
case -1:
|
|
|
|
|
// Error
|
|
|
|
|
|
|
|
|
|
// We are not the daemon process
|
2003-07-20 17:47:51 +00:00
|
|
|
daemon_flag = false;
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
log(ERROR, "Failed to fork() to go to the background.");
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2003-07-20 17:47:51 +00:00
|
|
|
// Parent
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
// We are not the daemon process
|
|
|
|
|
daemon_flag = false;
|
|
|
|
|
|
2003-07-20 17:47:51 +00:00
|
|
|
// Install handler for SIGUSR1
|
2002-10-03 10:51:59 +00:00
|
|
|
#if defined(HAVE_SIGACTION)
|
|
|
|
|
struct sigaction action;
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2003-07-20 17:47:51 +00:00
|
|
|
action.sa_handler = shutdown_on_signal;
|
2002-10-03 10:51:59 +00:00
|
|
|
sigaction(SIGUSR1, &action, NULL);
|
|
|
|
|
#else
|
2003-07-20 17:47:51 +00:00
|
|
|
signal(SIGUSR1, shutdown_on_signal);
|
2002-10-03 10:51:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (wait4(pid, &status, 0, NULL) < 0) {
|
|
|
|
|
running = true;
|
2002-10-10 10:42:10 +00:00
|
|
|
} else {
|
|
|
|
|
pid = -1;
|
2002-10-03 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (running == true) {
|
|
|
|
|
log(INFO, "Running");
|
|
|
|
|
} else {
|
2003-07-20 17:47:51 +00:00
|
|
|
int estatus = WEXITSTATUS(status);
|
|
|
|
|
if (estatus == EXIT_SUCCESS) {
|
2002-10-03 10:51:59 +00:00
|
|
|
log(ERROR, "Cyphesis exited normally at initialisation.");
|
2003-07-20 17:47:51 +00:00
|
|
|
} else if (estatus == EXIT_DATABASE_ERROR) {
|
|
|
|
|
log(ERROR, "Cyphesis was unable to connect to the database.");
|
|
|
|
|
} else if (estatus == EXIT_SOCKET_ERROR) {
|
2002-10-03 10:51:59 +00:00
|
|
|
log(ERROR, "Cyphesis was unable to open a listen socket.");
|
2003-07-20 17:47:51 +00:00
|
|
|
} else {
|
2002-10-03 10:51:59 +00:00
|
|
|
log(ERROR, "Cyphesis exited unexpectedly at initialisation.");
|
2003-07-20 17:47:51 +00:00
|
|
|
}
|
2002-10-03 10:51:59 +00:00
|
|
|
log(ERROR, "See syslog for details.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return pid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void running()
|
|
|
|
|
{
|
|
|
|
|
if (daemon_flag) {
|
|
|
|
|
kill(getppid(), SIGUSR1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-22 17:00:04 +00:00
|
|
|
|
|
|
|
|
static const char hex_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
|
|
|
|
|
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
|
|
|
|
|
2005-09-15 01:10:01 +00:00
|
|
|
static const int hash_algorithm = GCRY_MD_MD5;
|
|
|
|
|
static const int hash_salt_size = 8;
|
|
|
|
|
|
|
|
|
|
void hash_password(const std::string & pwd, const std::string & salt,
|
|
|
|
|
std::string & hash)
|
2003-03-22 17:00:04 +00:00
|
|
|
{
|
2005-09-15 01:10:01 +00:00
|
|
|
unsigned int digest_length = gcry_md_get_algo_dlen(hash_algorithm);
|
|
|
|
|
unsigned char * buf = new unsigned char[digest_length];
|
|
|
|
|
assert(buf != 0);
|
|
|
|
|
|
|
|
|
|
std::string passwd_and_salt = pwd + salt;
|
|
|
|
|
|
|
|
|
|
// Generate an MD% hash of the password and salt concatenated
|
|
|
|
|
gcry_md_hash_buffer(hash_algorithm, buf,
|
|
|
|
|
(const unsigned char *)passwd_and_salt.c_str(),
|
|
|
|
|
passwd_and_salt.size());
|
|
|
|
|
// Build a string containing the salt and hash together
|
|
|
|
|
// hash = String::compose("$1$%1$", salt);
|
|
|
|
|
if (!salt.empty()) {
|
|
|
|
|
hash = "$1$";
|
|
|
|
|
hash += salt;
|
|
|
|
|
hash += "$";
|
|
|
|
|
} else {
|
|
|
|
|
hash.clear();
|
|
|
|
|
}
|
|
|
|
|
for(unsigned int i = 0; i < digest_length; ++i) {
|
2003-03-22 17:00:04 +00:00
|
|
|
hash.push_back(hex_table[buf[i] & 0xf]);
|
|
|
|
|
hash.push_back(hex_table[(buf[i] & 0xf0) >> 4]);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2005-09-15 01:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void encrypt_password(const std::string & pwd, std::string & hash)
|
|
|
|
|
{
|
|
|
|
|
std::string salt;
|
|
|
|
|
WFMath::MTRand rng;
|
|
|
|
|
|
|
|
|
|
// Generate 8 bytes of salt
|
|
|
|
|
for (int i = 0; i < hash_salt_size; ++i) {
|
|
|
|
|
unsigned char b = rng.randInt() & 0xff;
|
|
|
|
|
salt.push_back(hex_table[b & 0xf]);
|
|
|
|
|
salt.push_back(hex_table[(b & 0xf0) >> 4]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get a hash of password and salt
|
|
|
|
|
hash_password(pwd, salt, hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int check_password(const std::string & pwd, const std::string & hash)
|
|
|
|
|
{
|
|
|
|
|
unsigned int digest_length = gcry_md_get_algo_dlen(hash_algorithm);
|
|
|
|
|
std::string new_hash;
|
|
|
|
|
size_t hash_size = hash.size();
|
|
|
|
|
|
|
|
|
|
if ((hash_size < (digest_length * 2 + 5)) || (hash.substr(0, 3) != "$1$")) {
|
|
|
|
|
// Get a hash of password with no salt
|
|
|
|
|
hash_password(pwd, "", new_hash);
|
|
|
|
|
} else {
|
|
|
|
|
// Extract the salt from the hash string
|
|
|
|
|
size_t dp = hash.find('$', 3);
|
|
|
|
|
if (dp == std::string::npos) {
|
|
|
|
|
log(ERROR, "Password hash has no $ symbol after the salt.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
assert(dp > 3);
|
|
|
|
|
std::string salt = hash.substr(3, dp - 3);
|
|
|
|
|
// Get a has of password and salt
|
|
|
|
|
hash_password(pwd, salt, new_hash);
|
|
|
|
|
}
|
|
|
|
|
// Check if the generated hash matches the reference hash
|
|
|
|
|
return hash == new_hash ? 0 : -1;
|
2003-03-22 17:00:04 +00:00
|
|
|
}
|