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
|
|
|
|
2006-10-26 00:48:00 +00:00
|
|
|
|
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 "globals.h"
|
2007-12-06 23:50:14 +00:00
|
|
|
#include "compose.hpp"
|
2002-10-03 10:51:59 +00:00
|
|
|
|
2005-09-15 01:10:01 +00:00
|
|
|
#include <wfmath/MersenneTwister.h>
|
|
|
|
|
|
2009-09-18 12:19:21 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
|
#undef DATADIR
|
2009-09-19 19:19:32 +01:00
|
|
|
#endif // _WIN32
|
2009-09-18 12:19:21 +01:00
|
|
|
|
2005-09-15 01:10:01 +00:00
|
|
|
#include <gcrypt.h>
|
2003-03-22 17:00:04 +00:00
|
|
|
|
2005-09-15 01:10:01 +00:00
|
|
|
#include <iostream>
|
2003-03-22 17:00:04 +00:00
|
|
|
|
2008-04-19 03:44:06 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2002-10-03 10:51:59 +00:00
|
|
|
extern "C" {
|
2006-11-02 02:38:15 +00:00
|
|
|
#ifdef HAVE_SYS_UTSNAME_H
|
|
|
|
|
#endif // HAVE_SYS_UTSNAME_H
|
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
2002-10-03 10:51:59 +00:00
|
|
|
#include <sys/wait.h>
|
2006-11-02 02:38:15 +00:00
|
|
|
#endif // HAVE_SYS_WAIT_H
|
2017-03-19 21:36:52 +01:00
|
|
|
#include <fcntl.h>
|
2002-10-03 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-12 18:43:14 +01:00
|
|
|
#ifdef HAVE_WINSOCK_H
|
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
#endif // HAVE_WINSOCK_H
|
|
|
|
|
|
2009-09-18 12:19:21 +01:00
|
|
|
#ifdef ERROR
|
|
|
|
|
#undef ERROR
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-11-03 17:12:31 +00:00
|
|
|
unsigned int security_init()
|
|
|
|
|
{
|
2018-10-30 19:31:27 +01:00
|
|
|
gcry_check_version(nullptr);
|
2008-11-03 17:12:31 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-19 03:44:06 +00:00
|
|
|
static int security_new_key(const std::string & key_filename)
|
|
|
|
|
{
|
|
|
|
|
FILE * key_file = ::fopen(key_filename.c_str(), "wx");
|
|
|
|
|
|
2018-10-30 19:31:27 +01:00
|
|
|
if (key_file == nullptr) {
|
2008-04-19 03:44:06 +00:00
|
|
|
log(CRITICAL, String::compose("Unable to open file %1 to store server"
|
|
|
|
|
" identity", key_filename));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-13 02:22:21 +00:00
|
|
|
gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
|
|
|
|
|
|
|
|
|
|
gcry_sexp_t key_parameters, key;
|
|
|
|
|
|
2018-10-30 19:31:27 +01:00
|
|
|
gcry_error_t ret = gcry_sexp_build(&key_parameters, nullptr,
|
2008-04-13 02:22:21 +00:00
|
|
|
"(genkey(dsa(nbits %d)))", 1024);
|
|
|
|
|
|
|
|
|
|
if (gcry_err_code(ret) != GPG_ERR_NO_ERROR) {
|
|
|
|
|
std::cout << "SEXP FAIL" << std::endl << std::flush;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = gcry_pk_genkey(&key, key_parameters);
|
|
|
|
|
|
|
|
|
|
if (gcry_err_code(ret) != GPG_ERR_NO_ERROR) {
|
|
|
|
|
std::cout << "GENKEY FAIL" << std::endl << std::flush;
|
2008-04-19 03:44:06 +00:00
|
|
|
return -1;
|
2008-04-13 02:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gcry_sexp_release(key_parameters);
|
|
|
|
|
|
|
|
|
|
ret = gcry_pk_testkey(key);
|
|
|
|
|
|
|
|
|
|
if (gcry_err_code(ret) != GPG_ERR_NO_ERROR) {
|
|
|
|
|
std::cout << "TESTKEY FAIL" << std::endl << std::flush;
|
2008-04-19 03:44:06 +00:00
|
|
|
return -1;
|
2008-04-13 02:22:21 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-30 19:31:27 +01:00
|
|
|
size_t ktxtlen = gcry_sexp_sprint(key, GCRYSEXP_FMT_CANON, nullptr, 0);
|
2008-04-13 02:22:21 +00:00
|
|
|
char * key_text = new char[ktxtlen];
|
|
|
|
|
gcry_sexp_sprint(key, GCRYSEXP_FMT_CANON, key_text, ktxtlen);
|
|
|
|
|
|
2008-11-07 01:41:54 +00:00
|
|
|
if (fwrite(key_text, ktxtlen, 1, key_file) != ktxtlen) {
|
|
|
|
|
log(ERROR, String::compose("Unable to write key to %1.", key_filename));
|
|
|
|
|
}
|
2008-04-19 03:44:06 +00:00
|
|
|
|
|
|
|
|
fclose(key_file);
|
2008-04-13 02:22:21 +00:00
|
|
|
|
|
|
|
|
// gcry_sexp_dump(key);
|
|
|
|
|
gcry_sexp_release(key);
|
|
|
|
|
|
2008-04-19 03:44:06 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int security_load_key(const std::string & key_filename, size_t len)
|
|
|
|
|
{
|
|
|
|
|
FILE * key_file = ::fopen(key_filename.c_str(), "r");
|
|
|
|
|
|
2018-10-30 19:31:27 +01:00
|
|
|
if (key_file == nullptr) {
|
2008-04-19 03:44:06 +00:00
|
|
|
log(CRITICAL, String::compose("Unable to open file %1 to read server"
|
|
|
|
|
" identity", key_filename));
|
|
|
|
|
perror("ARSE!");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char * key_text = new char[len];
|
|
|
|
|
|
|
|
|
|
size_t records = fread(key_text, len, 1, key_file);
|
|
|
|
|
if (records != 1) {
|
|
|
|
|
log(CRITICAL, String::compose("Unable to load identity information"
|
|
|
|
|
" from file %1", key_filename));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gcry_sexp_t key;
|
|
|
|
|
|
|
|
|
|
gcry_error_t ret = gcry_sexp_new(&key, key_text, len, 0);
|
|
|
|
|
|
|
|
|
|
if (gcry_err_code(ret) != GPG_ERR_NO_ERROR) {
|
|
|
|
|
log(CRITICAL, String::compose("Malformed identity information"
|
|
|
|
|
" from file %1", key_filename));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = gcry_pk_testkey(key);
|
|
|
|
|
|
|
|
|
|
if (gcry_err_code(ret) != GPG_ERR_NO_ERROR) {
|
|
|
|
|
std::cout << "TESTKEY FAIL" << std::endl << std::flush;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned int security_setup()
|
|
|
|
|
{
|
|
|
|
|
std::string key_filename;
|
|
|
|
|
char * home = getenv("HOME");
|
2018-10-30 19:31:27 +01:00
|
|
|
if (home == nullptr) {
|
2008-04-19 03:44:06 +00:00
|
|
|
std::cout << "No home" << std::endl << std::flush;
|
|
|
|
|
key_filename = String::compose("%1/tmp/cyphesis_%2_id_dsa",
|
|
|
|
|
var_directory, instance);
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "home" << std::endl << std::flush;
|
|
|
|
|
key_filename = String::compose("%1/.cyphesis_%2_id_dsa",
|
|
|
|
|
home, instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cout << "KEY: " << key_filename << std::endl << std::flush;
|
|
|
|
|
|
2018-10-30 19:31:27 +01:00
|
|
|
struct stat key_stat{};
|
2008-04-19 03:44:06 +00:00
|
|
|
|
|
|
|
|
if (::stat(key_filename.c_str(), &key_stat) != 0) {
|
|
|
|
|
std::cout << "not yet" << std::endl << std::flush;
|
|
|
|
|
security_new_key(key_filename);
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "loading" << std::endl << std::flush;
|
2018-10-30 19:31:27 +01:00
|
|
|
security_load_key(key_filename, static_cast<size_t>(key_stat.st_size));
|
2008-04-19 03:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
2006-03-25 10:55:53 +00:00
|
|
|
return SECURITY_OKAY;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-19 03:44:06 +00:00
|
|
|
|
2006-05-11 23:33:58 +00:00
|
|
|
void reduce_priority(int p)
|
2006-05-02 14:06:35 +00:00
|
|
|
{
|
2006-11-02 02:38:15 +00:00
|
|
|
#ifdef HAVE_NICE
|
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");
|
|
|
|
|
}
|
2006-11-02 02:38:15 +00:00
|
|
|
#endif // HAVE_NICE
|
2006-05-02 14:06:35 +00:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 15:56:46 +01:00
|
|
|
|
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)
|
2018-10-30 19:31:27 +01:00
|
|
|
struct sigaction action{};
|
2002-10-03 10:51:59 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(signo, &action, nullptr);
|
2002-10-03 10:51:59 +00:00
|
|
|
#else
|
|
|
|
|
signal(signo, SIG_IGN);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-21 20:53:40 +02:00
|
|
|
extern "C" void soft_shutdown_on_signal(int signo)
|
|
|
|
|
{
|
|
|
|
|
//If we've already received one call to shut down softly we should elevate
|
|
|
|
|
//it to a hard shutdown.
|
|
|
|
|
//This also happens if "soft" exit isn't enabled.
|
|
|
|
|
if (exit_flag_soft || !exit_soft_enabled) {
|
|
|
|
|
exit_flag = true;
|
|
|
|
|
} else {
|
|
|
|
|
exit_flag_soft = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if defined(HAVE_SIGACTION)
|
2018-10-30 19:31:27 +01:00
|
|
|
struct sigaction action{};
|
2013-08-21 20:53:40 +02:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(signo, &action, nullptr);
|
2013-08-21 20:53:40 +02:00
|
|
|
#else
|
|
|
|
|
signal(signo, SIG_IGN);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-01 19:36:11 +02:00
|
|
|
extern "C" void report_segfault(int)
|
2004-05-06 23:41:10 +00:00
|
|
|
{
|
2014-06-04 10:26:33 +02:00
|
|
|
//Don't print to the log at segfault, as that involves memory allocation.
|
|
|
|
|
//And with a segfault we might have gotten a tainted stack, which might cause that call to hang.
|
|
|
|
|
fprintf(stderr, "Segmentation fault");
|
|
|
|
|
fprintf(stderr, "Please report this bug to " PACKAGE_BUGREPORT);
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-01 19:36:11 +02:00
|
|
|
extern "C" void report_abort(int)
|
2004-05-07 00:03:25 +00:00
|
|
|
{
|
2015-04-09 13:44:26 +02:00
|
|
|
//Don't print to the log in signal handler, as that involves memory allocation.
|
|
|
|
|
fprintf(stderr, "Aborted");
|
|
|
|
|
fprintf(stderr, "Please report this bug to " PACKAGE_BUGREPORT);
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-30 15:14:05 +00:00
|
|
|
extern "C" void report_status(int)
|
2007-05-31 05:03:38 +00:00
|
|
|
{
|
|
|
|
|
if (exit_flag) {
|
|
|
|
|
log(NOTICE, "Shutting down");
|
|
|
|
|
} else {
|
|
|
|
|
log(NOTICE, "Running");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-30 15:14:05 +00:00
|
|
|
extern "C" void rotate_logs(int)
|
2006-09-24 23:10:08 +00:00
|
|
|
{
|
|
|
|
|
rotateLogger();
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-03 10:51:59 +00:00
|
|
|
void interactive_signals()
|
|
|
|
|
{
|
|
|
|
|
#if defined(HAVE_SIGACTION)
|
2018-10-30 19:31:27 +01:00
|
|
|
struct sigaction action{};
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2013-08-21 20:53:40 +02:00
|
|
|
action.sa_handler = soft_shutdown_on_signal;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGINT, &action, nullptr);
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2013-08-21 20:53:40 +02:00
|
|
|
action.sa_handler = soft_shutdown_on_signal;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGTERM, &action, nullptr);
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2003-07-20 17:47:51 +00:00
|
|
|
action.sa_handler = shutdown_on_signal;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGQUIT, &action, nullptr);
|
2002-10-17 23:07:52 +00:00
|
|
|
|
2003-07-20 17:47:51 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2013-08-21 20:53:40 +02:00
|
|
|
action.sa_handler = soft_shutdown_on_signal;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGHUP, &action, nullptr);
|
2003-07-20 17:47:51 +00:00
|
|
|
|
2002-10-17 23:07:52 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGPIPE, &action, nullptr);
|
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;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGSEGV, &action, nullptr);
|
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;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGABRT, &action, nullptr);
|
2007-05-31 05:03:38 +00:00
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
|
#warning Apple
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = report_status;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGINFO, &action, nullptr);
|
2007-05-31 05:03:38 +00:00
|
|
|
#endif // __APPLE__
|
|
|
|
|
|
|
|
|
|
#else // defined(HAVE_SIGACTION)
|
2003-07-20 17:47:51 +00:00
|
|
|
signal(SIGINT, shutdown_on_signal);
|
|
|
|
|
signal(SIGTERM, shutdown_on_signal);
|
2006-11-02 02:38:15 +00:00
|
|
|
#ifndef _WIN32
|
2003-07-20 17:47:51 +00:00
|
|
|
signal(SIGQUIT, shutdown_on_signal);
|
|
|
|
|
signal(SIGHUP, shutdown_on_signal);
|
2002-10-17 23:07:52 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2006-11-02 02:38:15 +00:00
|
|
|
#endif // _WIN32
|
2004-05-06 23:41:10 +00:00
|
|
|
signal(SIGSEGV, report_segfault);
|
2004-05-07 00:03:25 +00:00
|
|
|
signal(SIGABRT, report_abort);
|
2007-05-31 05:03:38 +00:00
|
|
|
#endif // defined(HAVE_SIGACTION)
|
2002-10-03 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void daemon_signals()
|
|
|
|
|
{
|
|
|
|
|
#if defined(HAVE_SIGACTION)
|
2018-10-30 19:31:27 +01:00
|
|
|
struct sigaction action{};
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGINT, &action, nullptr);
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2013-08-21 20:53:40 +02:00
|
|
|
action.sa_handler = soft_shutdown_on_signal;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGTERM, &action, nullptr);
|
2002-10-03 10:51:59 +00:00
|
|
|
|
|
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGQUIT, &action, nullptr);
|
2002-10-17 23:07:52 +00:00
|
|
|
|
2003-07-20 17:47:51 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2006-09-24 23:10:08 +00:00
|
|
|
action.sa_handler = rotate_logs;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGHUP, &action, nullptr);
|
2003-07-20 17:47:51 +00:00
|
|
|
|
2002-10-17 23:07:52 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGPIPE, &action, nullptr);
|
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;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGSEGV, &action, nullptr);
|
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;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGABRT, &action, nullptr);
|
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);
|
2006-11-02 02:38:15 +00:00
|
|
|
#ifndef _WIN32
|
2002-10-03 10:51:59 +00:00
|
|
|
signal(SIGQUIT, SIG_IGN);
|
2006-09-24 23:10:08 +00:00
|
|
|
signal(SIGHUP, rotate_logs);
|
2003-07-20 17:47:51 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
2006-11-02 02:38:15 +00:00
|
|
|
#endif // _WIN32
|
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()
|
|
|
|
|
{
|
2006-11-02 02:38:15 +00:00
|
|
|
#ifdef HAVE_FORK
|
2002-10-03 10:51:59 +00:00
|
|
|
int pid = fork();
|
|
|
|
|
int new_stdio;
|
|
|
|
|
int status = 0;
|
|
|
|
|
int running = false;
|
|
|
|
|
|
|
|
|
|
switch (pid) {
|
|
|
|
|
case 0:
|
|
|
|
|
// Child
|
2006-09-20 01:48:30 +00:00
|
|
|
// Get rid of controlling tty, and start new session
|
|
|
|
|
setsid();
|
2002-10-03 10:51:59 +00:00
|
|
|
// Switch signal behavoir
|
|
|
|
|
daemon_signals();
|
2006-09-20 01:48:30 +00:00
|
|
|
// Change current working directory to /
|
|
|
|
|
if (chdir("/") != 0) {
|
|
|
|
|
log(ERROR, "Unable to change current working directory to /");
|
|
|
|
|
}
|
2002-10-03 10:51:59 +00:00
|
|
|
// Get rid if stdio
|
|
|
|
|
close(STDIN_FILENO);
|
|
|
|
|
close(STDOUT_FILENO);
|
|
|
|
|
close(STDERR_FILENO);
|
|
|
|
|
// 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)
|
2018-10-30 19:31:27 +01:00
|
|
|
struct sigaction action{};
|
2002-10-03 10:51:59 +00:00
|
|
|
sigemptyset(&action.sa_mask);
|
|
|
|
|
action.sa_flags = 0;
|
2013-08-21 20:53:40 +02:00
|
|
|
action.sa_handler = soft_shutdown_on_signal;
|
2018-01-30 16:54:49 +01:00
|
|
|
sigaction(SIGUSR1, &action, nullptr);
|
2002-10-03 10:51:59 +00:00
|
|
|
#else
|
2013-08-21 20:53:40 +02:00
|
|
|
signal(SIGUSR1, soft_shutdown_on_signal);
|
2002-10-03 10:51:59 +00:00
|
|
|
#endif
|
|
|
|
|
|
2018-01-30 16:54:49 +01:00
|
|
|
if (wait4(pid, &status, 0, nullptr) < 0) {
|
2002-10-03 10:51:59 +00:00
|
|
|
running = true;
|
2002-10-10 10:42:10 +00:00
|
|
|
} else {
|
|
|
|
|
pid = -1;
|
2002-10-03 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-01 19:36:11 +02:00
|
|
|
if (running) {
|
2002-10-03 10:51:59 +00:00
|
|
|
log(INFO, "Running");
|
|
|
|
|
} else {
|
2003-07-20 17:47:51 +00:00
|
|
|
int estatus = WEXITSTATUS(status);
|
|
|
|
|
if (estatus == EXIT_SUCCESS) {
|
2014-02-04 15:56:46 +01:00
|
|
|
log(ERROR, "Cyphesis exited normally at initialization.");
|
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.");
|
2007-12-06 23:50:14 +00:00
|
|
|
} else if (estatus == EXIT_PORT_ERROR) {
|
|
|
|
|
log(ERROR, "Could not find free client listen socket. "
|
|
|
|
|
"Init failed.");
|
|
|
|
|
log(INFO, String::compose("To allocate 8 more ports please"
|
|
|
|
|
" run:\n\n cyconfig "
|
|
|
|
|
"--cyphesis:dynamic_port_end=%1"
|
|
|
|
|
"\n\n", dynamic_port_end + 8));
|
2003-07-20 17:47:51 +00:00
|
|
|
} else {
|
2014-02-04 15:56:46 +01:00
|
|
|
log(ERROR, "Cyphesis exited unexpectedly at initialization.");
|
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;
|
2006-11-02 02:38:15 +00:00
|
|
|
#else // HAVE_FORK
|
|
|
|
|
// On systems where we can't fork, fool the original process into thinking
|
|
|
|
|
// it is now the child.
|
|
|
|
|
return 0;
|
|
|
|
|
#endif // HAVE_FORK
|
2002-10-03 10:51:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void running()
|
|
|
|
|
{
|
2006-11-02 02:38:15 +00:00
|
|
|
#ifdef HAVE_FORK
|
2002-10-03 10:51:59 +00:00
|
|
|
if (daemon_flag) {
|
|
|
|
|
kill(getppid(), SIGUSR1);
|
|
|
|
|
}
|
2006-11-02 02:38:15 +00:00
|
|
|
#endif // HAVE_FORK
|
2002-10-03 10:51:59 +00:00
|
|
|
}
|
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);
|
2018-10-30 19:31:27 +01:00
|
|
|
auto* buf = new unsigned char[digest_length];
|
|
|
|
|
assert(buf != nullptr);
|
2005-09-15 01:10:01 +00:00
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
}
|
2008-11-01 02:38:32 +00:00
|
|
|
delete [] buf;
|
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) {
|
2018-10-30 19:31:27 +01:00
|
|
|
auto b = static_cast<unsigned char>(rng.randInt() & 0xff);
|
2005-09-15 01:10:01 +00:00
|
|
|
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();
|
|
|
|
|
|
2007-07-30 Al Riddoch <alriddoch@zepler.org>
* client/Py_CreatorClient.cpp, common/Database.cpp,
common/accountbase.cpp, common/system.cpp, rulesets/Character.cpp,
rulesets/Motion.cpp, rulesets/Plant.cpp, rulesets/Py_Location.cpp,
rulesets/Py_Mind.cpp, rulesets/Py_Operation.cpp,
rulesets/Py_Point3D.cpp, rulesets/Py_Statistics.cpp,
rulesets/Py_Task.cpp, rulesets/Py_TerrainProperty.cpp,
rulesets/Py_Thing.cpp, rulesets/Py_Vector3D.cpp,
rulesets/Py_WorldTime.cpp, rulesets/Python_API.cpp,
rulesets/TerrainProperty.cpp, server/Admin.cpp,
server/CommServer.cpp, server/Connection.cpp,
server/EntityFactory.cpp, server/WorldRouter.cpp,
tools/cycmd.cpp, tools/cyconvertrules.cpp, tools/cyctrl.cpp:
Remove unnecessary () from conditional expressions, where operator
binding is clear.
2007-07-30 18:12:50 +00:00
|
|
|
if (hash_size < (digest_length * 2 + 5) || hash.substr(0, 3) != "$1$") {
|
2005-09-15 01:10:01 +00:00
|
|
|
// 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) {
|
2006-11-02 02:38:15 +00:00
|
|
|
log(CYLOG_ERROR, "Password hash has no $ symbol after the salt.");
|
2005-09-15 01:10:01 +00:00
|
|
|
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
|
|
|
}
|
2006-11-03 18:55:40 +00:00
|
|
|
|
2008-08-12 20:40:14 +00:00
|
|
|
int getfiletime(const std::string & filename, time_t & t)
|
|
|
|
|
{
|
2018-10-30 19:31:27 +01:00
|
|
|
struct stat sbuf{};
|
2008-08-12 20:40:14 +00:00
|
|
|
|
|
|
|
|
int ret = ::stat(filename.c_str(), &sbuf);
|
|
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t = sbuf.st_mtime;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-11-03 18:55:40 +00:00
|
|
|
#ifndef HAVE_GETTIMEOFDAY
|
|
|
|
|
|
|
|
|
|
int gettimeofday(struct timeval * tv, struct timezone * tz)
|
|
|
|
|
{
|
|
|
|
|
assert(tz == 0);
|
|
|
|
|
|
|
|
|
|
SYSTEMTIME localtime;
|
|
|
|
|
struct tm unix_time;
|
|
|
|
|
|
|
|
|
|
GetLocalTime(&localtime);
|
|
|
|
|
|
|
|
|
|
unix_time.tm_sec = localtime.wSecond;
|
|
|
|
|
unix_time.tm_min = localtime.wMinute;
|
|
|
|
|
unix_time.tm_hour = localtime.wHour;
|
|
|
|
|
unix_time.tm_mday = localtime.wDay;
|
|
|
|
|
unix_time.tm_mon = localtime.wMonth - 1;
|
|
|
|
|
unix_time.tm_year = localtime.wYear - 1900;
|
|
|
|
|
|
|
|
|
|
tv->tv_usec = localtime.wMilliseconds * 1000;
|
|
|
|
|
|
|
|
|
|
tv->tv_sec = mktime(&unix_time);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|