Auth Module

These are old archives. They are kept for historic purposes only.
Post Reply
almirdj
Posts: 6
Joined: Fri Jul 17, 2009 5:10 pm

Auth Module

Post by almirdj »

Ok i have searched forums and find out that there was a simple request by the user [dx] exept that the module need to be payed, i have tried this module but i think it has some bugs, so if anyone knows to work with the code it would be great to fix it a little bit.So what do u think

Code: Select all

/*
 * f_auth.c
 * by fez (c) 2007 - provides authentication requirement for IRC
 * this module is only a proof of concept.  It should be expanded for
 * specific authentication schema.  f_auth_local_connect() and
 * f_auth_command() would be the places to do those.
 */

// includes
#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "proto.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif

// ***** module-specific defines *****
#define MOD_AUTH_NAME		"f_auth"
#define MOD_AUTH_VERS		"$Id: f_auth.c, v1.0.2 2007/10/16 20:43:00 fez Exp $"
#define MOD_AUTH_DESC		"require AUTH before registering"
// defines:
#define MSG_AUTH		"AUTH"
#define TOK_AUTH		NULL
#define AUTH_DIRECTIVE		"require-auth"
#define MSG_NOTICE		"NOTICE"

// ***** Function Declarations *****
// config loading hook functions
DLLFUNC int f_auth_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs);
DLLFUNC int f_auth_config_posttest(int *errs);
DLLFUNC int f_auth_config_run(ConfigFile *cf, ConfigEntry *ce, int type);
DLLFUNC int f_auth_config_rehash();
// Hook functions:
DLLFUNC int f_auth_local_connect(aClient *sptr);
// commands:
DLLFUNC int f_auth_command(aClient *cptr, aClient *sptr, int parc, char *parv[]);

// ***** Global Variables *****
ModuleInfo *AuthModInfo = NULL;		// for local storage of modinfo
static int auth_conf_counter = 0;	// for config file
static Hook *AuthHookTest = NULL;	// for config hashiing
static Hook *AuthHookPosttest = NULL;	//
static Hook *AuthHookRun = NULL;	//
static Hook *AuthHookRehash = NULL;	//
static Hook *AuthHookLocalConnect = NULL;	// for local connection hook
static Command *AuthCmd;		// to store command hook status
static int auth_require = 0;		// whether to require AUTH

// a description of this module
ModuleHeader MOD_HEADER(f_auth)
  = {
	MOD_AUTH_NAME,
	MOD_AUTH_VERS,
	MOD_AUTH_DESC,
	"3.2.3",
	NULL
  };

// called before config test
DLLFUNC int MOD_TEST(f_auth)(ModuleInfo *modinfo)
{
	int ret = MOD_SUCCESS;
	AuthHookTest = HookAddEx(modinfo->handle, HOOKTYPE_CONFIGTEST, f_auth_config_test);
	AuthHookPosttest = HookAddEx(modinfo->handle, HOOKTYPE_CONFIGPOSTTEST, f_auth_config_posttest);
	auth_conf_counter = 0;
	return ret;
}

// called during module initialization
DLLFUNC int MOD_INIT(f_auth)(ModuleInfo *modinfo)
{
	int ret = MOD_SUCCESS;
	AuthModInfo = modinfo;
	AuthHookRun = HookAddEx(modinfo->handle, HOOKTYPE_CONFIGRUN, f_auth_config_run);
	AuthHookRehash = HookAddEx(modinfo->handle, HOOKTYPE_REHASH, f_auth_config_rehash);
	AuthHookLocalConnect = HookAddEx(modinfo->handle, HOOKTYPE_LOCAL_CONNECT, f_auth_local_connect);
	AuthCmd = CommandAdd(modinfo->handle, MSG_AUTH, TOK_AUTH, f_auth_command, MAXPARA, M_UNREGISTERED|M_USER);
	if (!AuthCmd)
		ret = MOD_FAILED;
	return ret;
}

// called when ircd is 100% ready
DLLFUNC int MOD_LOAD(f_auth)(int module_load)
{
	int ret = MOD_SUCCESS;
	return ret;
}

// called when unloading a module
DLLFUNC int MOD_UNLOAD(f_auth)(int module_unload)
{
	int ret = MOD_SUCCESS;
	CommandDel(AuthCmd);
	HookDel(AuthHookTest);
	HookDel(AuthHookPosttest);
	HookDel(AuthHookRun);
	HookDel(AuthHookRehash);
	HookDel(AuthHookLocalConnect);
	AuthCmd = NULL;
	AuthHookLocalConnect =
	AuthHookTest = AuthHookPosttest = AuthHookRun = AuthHookRehash = NULL;
	return ret;
}

// this is where we TEST the config file
DLLFUNC int f_auth_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
{
	int errors = 0;
	if (type != CONFIG_SET)
		return 0;
	if (!strcmp(ce->ce_varname, AUTH_DIRECTIVE))
	{
		if (ce->ce_vardata)
		{
			config_error("%s:%i: set::%s with unnecessary value",
				ce->ce_fileptr->cf_filename,
				ce->ce_varlinenum, ce->ce_varname );
			errors++;
		}
		else if (auth_conf_counter)
		{
			config_error("%s:%i: set::%s already defined on line %i",
				ce->ce_fileptr->cf_filename,
				ce->ce_varlinenum, ce->ce_varname,
				auth_conf_counter );
				errors++;
		}
		else
		{
			auth_conf_counter = ce->ce_varlinenum;
			!auth_conf_counter && ++auth_conf_counter;
		}
		*errs = errors;
		return errors ? -1 : 1;
	}
	return 0;
}

// this is run AFTER testing the config file
DLLFUNC int f_auth_config_posttest(int *errs)
{
	int errors = 0;
	if (!auth_conf_counter)
	{
		//config_error("set::%s not set.", AUTH_DIRECTIVE );
		//errors++;
		////or...
		auth_require = 0;
	}
	*errs = errors;
	return errors ? -1 : 1;
}

// this is run WHEN LOADING SETTINGS from the config file
DLLFUNC int f_auth_config_run(ConfigFile *cf, ConfigEntry *ce, int type)
{
	if (type != CONFIG_SET)
		return 0;
	if (!strcmp(ce->ce_varname, AUTH_DIRECTIVE))
	{
		auth_require = 1;
		return 1;
	}
	return 0;
}

// this is run when REHASHING the config file
DLLFUNC int f_auth_config_rehash()
{
	auth_conf_counter = 0;
	return 1;
}

// this is the local connect hook function
DLLFUNC int f_auth_local_connect(aClient *sptr)
{
	if (!auth_require || !MyConnect(sptr) || !IsClient(sptr))
		return 0;
	sendto_one(sptr, "%s %s %s :To connect please type /quote %s %X",
		me.name, MSG_NOTICE, sptr->name,
		MSG_AUTH, sptr->firsttime );
	SetUnknown(sptr);
	IRCstats.unknown++;
	IRCstats.clients--;
	IRCstats.me_clients--;
	me.serv->users--;
	return 0;
}

// this is the AUTH command
DLLFUNC int f_auth_command(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	char authcode[32];
	if (!auth_require || !MyConnect(sptr) || !IsUnknown(sptr))
		return 0;
	sprintf(authcode, "%X", sptr->firsttime);
	if (parc > 1 && !strcmp(parv[1], authcode))
	{
		sendto_one(sptr, "%s %s %s :%s code accepted.",
			me.name, MSG_NOTICE, sptr->name, MSG_AUTH );
		SetClient(sptr);
		IRCstats.unknown--;
		IRCstats.clients++;
		IRCstats.me_clients++;
		me.serv->users++;
	}
	else
	{
		sendto_one(sptr, "%s %s %s :%s code invalid.",
			me.name, MSG_NOTICE, sptr->name, MSG_AUTH );
	}
	return 0;
}

/* end of code */
katsklaw
Posts: 1124
Joined: Sun Apr 18, 2004 5:06 pm
Contact:

Re: Auth Module

Post by katsklaw »

If you suspect bugs, you should supply the reason why you think there is bugs and what you think the bug is. It' makes troubleshooting a lot easier.
almirdj
Posts: 6
Joined: Fri Jul 17, 2009 5:10 pm

Re: Auth Module

Post by almirdj »

It`s not like a bug, when i use this script you connect at the server and you see motd and everything is would be more better

Code: Select all

 |00:01:54| -irc.**********- *** Looking up your hostname...
-
|00:01:54| -irc.*********.cc- *** Checking ident...
-
* Identd request from *********
* Identd replied: 1162, 6666 : USERID : UNIX : god
-
|00:01:55| -irc.*********- *** Couldn't resolve your hostname; using your IP address instead
-
|00:01:55| -irc.*********- *** Received identd response 
it would be better to receive the msg please enter code to enter this server,and if the code is ok then to display the motd and to connect it at server,the way that script works for example if u had put in unrealircd.conf a line so on connect users join a channel, no matter do you type the auth code u will join that channel and have + but u will not be able to join other channels unless you tupe the code,and then u have to part that channel u have got + if u wanna see the other users that or on that channel othervise you see only your self,and in your mirc when someone gives +o or +v it seams like he did that twice..i mean that is what you get.

Code: Select all

 Nick sets mode: +o Nick2
Nick sets mode: +o Nick2 
And the auth code is always the same..its not random numbers and letters.
So it would be ok to make this module after this

Code: Select all

 |00:01:54| -irc.**********- *** Looking up your hostname...
-
|00:01:54| -irc.*********.cc- *** Checking ident...
-
* Identd request from *********
* Identd replied: 1162, 6666 : USERID : UNIX : god
-
|00:01:55| -irc.*********- *** Couldn't resolve your hostname; using your IP address instead
-
|00:01:55| -irc.*********- *** Received identd response 
to get a msg please type /quote pass random code to connect and that code to be random that would be that.
katsklaw
Posts: 1124
Joined: Sun Apr 18, 2004 5:06 pm
Contact:

Re: Auth Module

Post by katsklaw »

try to replicate it without any scripts loaded. Scripts are often the point of failure when bug hunting.
almirdj
Posts: 6
Joined: Fri Jul 17, 2009 5:10 pm

Re: Auth Module

Post by almirdj »

katsklaw wrote:try to replicate it without any scripts loaded. Scripts are often the point of failure when bug hunting.
I don`t know how to work with that, i dont understand the code that is the reason i registered here and posted about this, i also think that many people whould use it, it would prevent a lot of clones, and etc.(please don`t start the story you can use bopm and opsb,I`m already using them) Just saying it`s a good module.
Izv143
Posts: 17
Joined: Fri Feb 13, 2009 11:50 pm

Re: Auth Module

Post by Izv143 »

Would be good with this auth module to work with nickserv. If is user registered and join irc network ask him for auth but if users identify to nickserv allow them to join channels without typing auth code. But this would be module for services.
4mIRC
Posts: 63
Joined: Sat Mar 13, 2010 8:24 pm

Re: Auth Module

Post by 4mIRC »

hello almirdj

sorry to reply for old post

i added this module to my ircd but nothing happen :(

can any one help me how to make it work ?

thanks
4mIRC
Posts: 63
Joined: Sat Mar 13, 2010 8:24 pm

Re: Auth Module

Post by 4mIRC »

hello

can any one post the correct auth module ?

i wanna ask almirdj if he fixied it or not

and sorry to open old post
Post Reply