コード例 #1
0
ファイル: m_operlevels.cpp プロジェクト: TuSuNaMi/ircd-sakura
		virtual int OnKill(userrec* source, userrec* dest, const std::string &reason)
		{
			long dest_level = 0,source_level = 0;

			// oper killing an oper?
			if (IS_OPER(dest) && IS_OPER(source))
			{
				for (int j =0; j < conf->Enumerate("type"); j++)
				{
					std::string typen = conf->ReadValue("type","name",j);
					if (!strcmp(typen.c_str(),dest->oper))
					{
						dest_level = conf->ReadInteger("type","level",j,true);
						break;
					}
				}
				for (int k =0; k < conf->Enumerate("type"); k++)
				{
					std::string typen = conf->ReadValue("type","name",k);
					if (!strcmp(typen.c_str(),source->oper))
					{
						source_level = conf->ReadInteger("type","level",k,true);
						break;
					}
				}
				if (dest_level > source_level)
				{
					ServerInstance->WriteOpers("Oper %s (level %d) attempted to /kill a higher oper: %s (level %d): Reason: %s",source->nick,source_level,dest->nick,dest_level,reason.c_str());
					dest->WriteServ("NOTICE %s :Oper %s attempted to /kill you!",dest->nick,source->nick);
					source->WriteServ("481 %s :Permission Denied - Oper %s is a higher level than you",source->nick,dest->nick);
					return 1;
				}
			}
			return 0;
		}
コード例 #2
0
ファイル: m_helpop.cpp プロジェクト: TuSuNaMi/ircd-sakura
		virtual void ReadConfig()
		{
			ConfigReader *MyConf = new ConfigReader(ServerInstance);

			helpop_map.clear();

			for (int i = 0; i < MyConf->Enumerate("helpop"); i++)
			{
				irc::string key = assign(MyConf->ReadValue("helpop", "key", i));
				std::string value = MyConf->ReadValue("helpop", "value", i, true); /* Linefeeds allowed! */

				if (key == "index")
				{
					throw ModuleException("m_helpop: The key 'index' is reserved for internal purposes. Please remove it.");
				}

				helpop_map[key] = value;
			}

			if (helpop_map.find("start") == helpop_map.end())
			{
				// error!
				throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
			}
			else if (helpop_map.find("nohelp") == helpop_map.end())
			{
				// error!
				throw ModuleException("m_helpop: Helpop file is missing important entries. Please check the example conf.");
			}

		}
コード例 #3
0
ファイル: m_filter.cpp プロジェクト: mikebryant/inspircd
	virtual void OnRehash(const std::string &parameter)
	{
		// reload our config file on rehash - we must destroy and re-allocate the classes
		// to call the constructor again and re-read our data.
		ConfigReader* Conf = new ConfigReader(ServerInstance);
		std::string filterfile = Conf->ReadValue("filter","file",0);
		// this automatically re-reads the configuration file into the class
		ConfigReader* MyConf = new ConfigReader(ServerInstance, filterfile);
		if ((filterfile == "") || (!MyConf->Verify()))
		{
			// bail if the user forgot to create a config file
			FilterException e;
			throw(e);
		}
		for (filter_t::iterator n = filters.begin(); n != filters.end(); n++)
		{
			DELETE(n->second);
		}
		filters.clear();
		for (int index = 0; index < MyConf->Enumerate("keyword"); index++)
		{
			std::string pattern = MyConf->ReadValue("keyword","pattern",index);
			std::string reason = MyConf->ReadValue("keyword","reason",index);
			std::string do_action = MyConf->ReadValue("keyword","action",index);
			if (do_action == "")
				do_action = "none";
			Filter* x = new Filter;
			x->reason = reason;
			x->action = do_action;
			filters[pattern] = x;
		}
		ServerInstance->Log(DEFAULT,"m_filter: read configuration from "+filterfile);
		DELETE(Conf);
		DELETE(MyConf);
	}
コード例 #4
0
ファイル: m_vhost.cpp プロジェクト: thepaul/inspircd-deb
    CmdResult Handle (const std::vector<std::string> &parameters, User *user)
    {
        ConfigReader *Conf = new ConfigReader(ServerInstance);

        for (int index = 0; index < Conf->Enumerate("vhost"); index++)
        {
            std::string mask = Conf->ReadValue("vhost","host",index);
            std::string username = Conf->ReadValue("vhost","user",index);
            std::string pass = Conf->ReadValue("vhost","pass",index);
            std::string hash = Conf->ReadValue("vhost","hash",index);

            if ((!strcmp(parameters[0].c_str(),username.c_str())) && !ServerInstance->PassCompare(user, pass.c_str(), parameters[1].c_str(), hash.c_str()))
            {
                if (!mask.empty())
                {
                    user->WriteServ("NOTICE "+std::string(user->nick)+" :Setting your VHost: " + mask);
                    user->ChangeDisplayedHost(mask.c_str());
                    delete Conf;
                    return CMD_LOCALONLY;
                }
            }
        }

        user->WriteServ("NOTICE "+std::string(user->nick)+" :Invalid username or password.");
        delete Conf;
        return CMD_FAILURE;
    }
コード例 #5
0
	void ReadConfig()
	{
		ConfigReader* MyConf = new ConfigReader(ServerInstance);
		allowchans.clear();
		for (int i = 0; i < MyConf->Enumerate("allowchannel"); i++)
		{
			std::string txt;
			txt = MyConf->ReadValue("allowchannel", "name", i);
			irc::string channel = txt.c_str();
			allowchans[channel] = 1;
		}
		DELETE(MyConf);
	}
コード例 #6
0
	virtual void OnRehash(User* user)
	{
		/*
		 * reload our config file on rehash - we must destroy and re-allocate the classes
		 * to call the constructor again and re-read our data.
		 */
		ConfigReader* MyConf = new ConfigReader(ServerInstance);
		censors.clear();

		for (int index = 0; index < MyConf->Enumerate("badword"); index++)
		{
			irc::string pattern = (MyConf->ReadValue("badword","text",index)).c_str();
			irc::string replace = (MyConf->ReadValue("badword","replace",index)).c_str();
			censors[pattern] = replace;
		}

		delete MyConf;
	}
コード例 #7
0
ファイル: m_rewrite.cpp プロジェクト: xxgrunge/anope196
	void OnReload()
	{
		ConfigReader config;

		this->rewrites.clear();

		for (int i = 0; i < config.Enumerate("rewrite"); ++i)
		{
			Rewrite rw;

			rw.client = config.ReadValue("rewrite", "client", "", i);
			rw.source_message = config.ReadValue("rewrite", "source_message", "", i),
			rw.target_message = config.ReadValue("rewrite", "target_message", "", i);

			if (rw.client.empty() || rw.source_message.empty() || rw.target_message.empty())
				continue;

			this->rewrites.push_back(rw);
		}
	}
コード例 #8
0
ファイル: m_hostchange.cpp プロジェクト: mikebryant/inspircd
	virtual void OnRehash(const std::string &parameter)
	{
		DELETE(Conf);
		Conf = new ConfigReader(ServerInstance);
		MySuffix = Conf->ReadValue("host","suffix",0);
		for (hostchanges_t::iterator i = hostchanges.begin(); i != hostchanges.end(); i++)
		{
			DELETE(i->second);
		}
		hostchanges.clear();
		for (int index = 0; index < Conf->Enumerate("hostchange"); index++)
		{
			std::string mask = Conf->ReadValue("hostchange","mask",index);
			std::string action = Conf->ReadValue("hostchange","action",index);
			std::string newhost = Conf->ReadValue("hostchange","value",index);
			Host* x = new Host;
			x->action = action;
			x->newhost = newhost;
			hostchanges[mask] = x;
		}
	}
コード例 #9
0
		virtual int OnPreCommand(std::string &command, std::vector<std::string>& parameters, User* user, bool validated, const std::string &original_line)
		{
			if (!validated)
				return 0;

			if (command != "OPER")
				return 0;

			std::string *account, currentaccount=user->nick.c_str();
			user->GetExt("accountname", account);

			if (account)
				currentaccount=account->c_str();

			else if (!user->IsModeSet('r') && !account)
			{
				user->WriteServ("491 %s :Invalid oper credentials",user->nick.c_str());
				return 1;
			}

			for (int j = 0; j < Conf->Enumerate("oper"); j++)
			{
				std::string opername = Conf->ReadValue("oper", "name", j);
				if (opername==parameters[0])
				{
					std::string registerednick = Conf->ReadValue("oper", "registerednick", "", j);

					if (registerednick.empty() || InspIRCd::Match(registerednick,currentaccount))
						break;
					else
					{
						user->WriteServ("491 %s :Invalid oper credentials",user->nick.c_str());
						return 1;
					}
				}
			}

			return 0;
		}
コード例 #10
0
ファイル: m_ssl_openssl.cpp プロジェクト: mikebryant/inspircd
	virtual void OnRehash(const std::string &param)
	{
		if(param != "ssl")
			return;
	
		Conf = new ConfigReader(ServerInstance);
			
		for(unsigned int i = 0; i < listenports.size(); i++)
		{
			ServerInstance->Config->DelIOHook(listenports[i]);
		}
		
		listenports.clear();
		
		for(int i = 0; i < Conf->Enumerate("bind"); i++)
		{
			// For each <bind> tag
			if(((Conf->ReadValue("bind", "type", i) == "") || (Conf->ReadValue("bind", "type", i) == "clients")) && (Conf->ReadValue("bind", "ssl", i) == "openssl"))
			{
				// Get the port we're meant to be listening on with SSL
				unsigned int port = Conf->ReadInteger("bind", "port", i, true);
				if (ServerInstance->Config->AddIOHook(port, this))
				{
					// We keep a record of which ports we're listening on with SSL
					listenports.push_back(port);
				
					ServerInstance->Log(DEFAULT, "m_ssl_openssl.so: Enabling SSL for port %d", port);
				}
				else
				{
					ServerInstance->Log(DEFAULT, "m_ssl_openssl.so: FAILED to enable SSL on port %d, maybe you have another ssl or similar module loaded?", port);
				}
			}
		}
		
		std::string confdir(CONFIG_FILE);
		// +1 so we the path ends with a /
		confdir = confdir.substr(0, confdir.find_last_of('/') + 1);
		
		cafile	= Conf->ReadValue("openssl", "cafile", 0);
		// crlfile	= Conf->ReadValue("openssl", "crlfile", 0);
		certfile	= Conf->ReadValue("openssl", "certfile", 0);
		keyfile	= Conf->ReadValue("openssl", "keyfile", 0);
		dhfile	= Conf->ReadValue("openssl", "dhfile", 0);
		
		// Set all the default values needed.
		if(cafile == "")
			cafile = "ca.pem";
			
		//if(crlfile == "")
		//	crlfile = "crl.pem";
			
		if(certfile == "")
			certfile = "cert.pem";
			
		if(keyfile == "")
			keyfile = "key.pem";
			
		if(dhfile == "")
			dhfile = "dhparams.pem";
			
		// Prepend relative paths with the path to the config directory.	
		if(cafile[0] != '/')
			cafile = confdir + cafile;
		
		//if(crlfile[0] != '/')
		//	crlfile = confdir + crlfile;
			
		if(certfile[0] != '/')
			certfile = confdir + certfile;
			
		if(keyfile[0] != '/')
			keyfile = confdir + keyfile;
			
		if(dhfile[0] != '/')
			dhfile = confdir + dhfile;

		/* Load our keys and certificates*/
		if(!SSL_CTX_use_certificate_chain_file(ctx, certfile.c_str()))
		{
			ServerInstance->Log(DEFAULT, "m_ssl_openssl.so: Can't read certificate file %s", certfile.c_str());
		}

		if(!SSL_CTX_use_PrivateKey_file(ctx, keyfile.c_str(), SSL_FILETYPE_PEM))
		{
			ServerInstance->Log(DEFAULT, "m_ssl_openssl.so: Can't read key file %s", keyfile.c_str());
		}

		/* Load the CAs we trust*/
		if(!SSL_CTX_load_verify_locations(ctx, cafile.c_str(), 0))
		{
			ServerInstance->Log(DEFAULT, "m_ssl_openssl.so: Can't read CA list from ", cafile.c_str());
		}

		FILE* dhpfile = fopen(dhfile.c_str(), "r");
		DH* ret;

		if(dhpfile == NULL)
		{
			ServerInstance->Log(DEFAULT, "m_ssl_openssl.so Couldn't open DH file %s: %s", dhfile.c_str(), strerror(errno));
			throw ModuleException();
		}
		else
		{
			ret = PEM_read_DHparams(dhpfile, NULL, NULL, NULL);
		
			if(SSL_CTX_set_tmp_dh(ctx, ret) < 0)
			{
				ServerInstance->Log(DEFAULT, "m_ssl_openssl.so: Couldn't set DH parameters");
			}
		}
		
		fclose(dhpfile);

		DELETE(Conf);
	}