Page 2 of 3

Re: Opers still seeing notices on log out

Posted: Sat Jul 14, 2012 8:14 pm
by cards
Try this module:

put it in a file called m_kickoper.c placed in the src/modules

then from main Unreal directory: make custommodule MODULEFILE=m_kickoper
add a loadmodule directive to the .so file and rehash. I have tested it on Win32, so It should work on linux as well.

Code: Select all

/*
 * =================================================================
 * Filename:          m_kickoper.c
 * Description:       Hooks Umode and checks if Oper uses /mode -o
 * Author:            Cards <[email protected]
 * Version: 1.0
 * Documentation:    
 *		This Module hooks UMODE_CHANGE and detects if an oper deops
 * themselves.  If so, it removed them from all AdminOnly and 
 * OperOnly Channels.  Tested on Win32.
 * =================================================================
 */

#include "config.h"
#include "struct.h"
#include "common.h"
#include "channel.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

extern void             sendto_one(aClient *to, char *pattern, ...);
DLLFUNC char *check_oper(aClient *sptr, long oldflags, long newflags);

//Hook *HookDeop = NULL;
#define DelCommand(x)	if (x) CommandDel(x); x = NULL


ModuleHeader MOD_HEADER(m_kickoper)
  = {
	"check_oper",
	"$Id: m_checkoper.c,v 1..0 2012/07/13 cards",
	"hook UMODE",
	"3.2-b8-1",
	NULL 
    };

DLLFUNC int MOD_INIT(m_kickoper)(ModuleInfo *modinfo)
{
	HookAddPCharEx(modinfo->handle, HOOKTYPE_UMODE_CHANGE, check_oper);
        return MOD_SUCCESS;
}

DLLFUNC int MOD_LOAD(m_kickoper)(int module_load)
{
	return MOD_SUCCESS;
}

DLLFUNC int MOD_UNLOAD(m_kickoper)(int module_unload)
{
	//DelCommand(HookDeop);
	return MOD_SUCCESS;
}

/*  This is the command to execute on Umode2 */
DLLFUNC char *check_oper(aClient *sptr, long oldflags, long newflags)
{
	aClient *cptr;
	Membership *lp;
	aChannel *chptr;
	aChannel *kchan[50];  // Max 50 channels.  Not really needing this many, but they are opers
	int count = 0;
	int c;
	if (oldflags & UMODE_OPER){
		if (newflags & UMODE_OPER) {
			return HOOK_CONTINUE;
		}
		for (lp = sptr->user->channel; lp; lp = lp->next)
			{
				chptr = lp->chptr;
				if (chptr->mode.mode & MODE_OPERONLY || chptr->mode.mode & MODE_ADMONLY)
				{
					//Build list of channels the user is on that they need to be removed from.  We cannot remove here due to read-after-free issues
						kchan[count] = chptr;
						++count;
				}
				
			}
		for (c=0; c<count; c++) { 
			//send kick to client and remove them from channel list
			sendnotice(sptr, "You are being removed from the Oper/Admin Only Channels");
			sendto_prefix_one(sptr, sptr, ":%s KICK %s %s :You are no longer an oper!", me.name, kchan[c]->chname, sptr->name);
			remove_user_from_channel(sptr, kchan[c]);
		} 
		
		return HOOK_CONTINUE;
	} else {
		return HOOK_CONTINUE;
	}
return HOOK_CONTINUE;
}

Re: Opers still seeing notices on log out

Posted: Sat Jul 14, 2012 9:42 pm
by Stealth
As Syzop mentioned, a few examples of the notices the user is still receiving would be nice.

He also mentioned that users can use +k and +s snomasks, and these will stay set when the user de-opers. +k will send all KILL notices, and +s will send general server notices.

As for the oper still being in #opers when +O is set, that relates back to what was mentioned about +O being like +k or +i. It only checks user access when a user joins. This is just how modes that restrict joins work. Without a 3rd part module there is no way to have the sever automatically remove a user from the channel (with the exception of +f).

If you don't want your opers to see any information or be in oper-only channels when they are not logged in, you should make that the oper's responsibility to do themselves.

It may be possible to create a module to provide a deoper command that removes all oper-related usermodes and parts from +O channels, it would also be extremely easy to write a script to do the same for mIRC:

Code: Select all

alias deoper {
  mode $me -o+s -ks
  var %x = 1
  while ($chan(%x)) {
    if (O isincs $chan(%x).mode) { part $chan(%x) }
    inc %x
  }
}

Re: Opers still seeing notices on log out

Posted: Sun Jul 15, 2012 7:09 am
by cheiron
thanks Stealth but i have an equivalent already on my windows box :D

.. sadly .. my windows box is minus a mobo having blown the bios... so i am stuck on xchat which i am unfamiliar with and irssi .. also unfamiliar with

Re: Opers still seeing notices on log out

Posted: Mon Jul 16, 2012 4:05 am
by cards
Do you need a dll version of the mod as well?

Re: Opers still seeing notices on log out

Posted: Mon Jul 16, 2012 4:09 am
by cards
http://schaffner.org/m_kickoper.c
http://schaffner.org/m_kickoper.dll

Code is above. DLL is compile on VS2008, so it is compatible with Unreal's build

Re: Opers still seeing notices on log out

Posted: Mon Jul 16, 2012 5:54 am
by cheiron
I am on a debian 6 vps so no dll version needed. what i would like though .. re the kickoper.. they only need to be taken from 1 channel on deoper.. as the force join on oper takes them to 3.. main channel, help channel and #opers <--- that's the one they need to leave only

Re: Opers still seeing notices on log out

Posted: Mon Jul 16, 2012 8:09 pm
by cards
The Modules is only going to remove the user from channels that are /mode #chan +O or /mode #chan +A. You are not going to set your main channel or help channels as oper only, as it would be pointless. So it should work just fine for you.

Re: Opers still seeing notices on log out

Posted: Tue Jul 17, 2012 8:20 pm
by cheiron
ok compiled it and ran it.

*** check_oper - $Id: m_checkoper.c,v 1..0 2012/07/13 cards (hook UMODE) [3RD]
from /module so you can see its loaded

from my messages
<Global> UserMode: WhiteWolf[s] (~[email protected] => [email protected]) is no longer a Global IRC Operator (-o)

he got kicked... but for some reason xchat doesnt show kicks...

he still saw the oper notices when i rehashed during the time he was deopered....

how does that get fixed ?

Re: Opers still seeing notices on log out

Posted: Wed Jul 18, 2012 12:28 am
by Stealth
Stealth wrote:He also mentioned that users can use +k and +s snomasks, and these will stay set when the user de-opers. +k will send all KILL notices, and +s will send general server notices.

Re: Opers still seeing notices on log out

Posted: Wed Jul 18, 2012 6:06 am
by cheiron
hah.. sorry for being a bit slow :) i had added the sk to restrict "usermodes" instead of commenting out the snomask on connect lol
thanks guys :)

Re: Opers still seeing notices on log out

Posted: Sat Jul 21, 2012 5:49 pm
by cheiron
would it be possible please to have the check_oper module modified to remove +k and +s snomasks from deopering opers please :)
that will be the module perfect then :)

cheers

Re: Opers still seeing notices on log out

Posted: Sat Jul 21, 2012 5:50 pm
by cards
I will see what I can do for you

Re: Opers still seeing notices on log out

Posted: Sat Jul 21, 2012 7:40 pm
by cards
Version 1.1 Release. It now removes +s (SnoMasks) from non-opers. This removes the kill notices ans server notices per your request, although normal members are allowed to see if by default. YOu must Restrict mode (s), in order for this to work.

http://schaffner.org/m_kickoper.c

Re: Opers still seeing notices on log out

Posted: Sun Jul 22, 2012 6:49 pm
by cheiron
Works a treat cards :)
nice job and a job well done.
you should publish this on the unrealircd modules page as a functional module to the masses :)

Re: Opers still seeing notices on log out

Posted: Mon Jul 23, 2012 11:47 pm
by cards
Sure will. As soon as Syzop allows me to open it up :)