unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

operinfo.c (2185B)

      1 /*
      2  * Store oper login in ModData, used by WHOIS and for auditting purposes.
      3  * (C) Copyright 2021-.. Syzop and The UnrealIRCd Team
      4  * License: GPLv2 or later
      5  */
      6 
      7 #include "unrealircd.h"
      8 
      9 ModuleHeader MOD_HEADER
     10   = {
     11 	"operinfo",
     12 	"5.0",
     13 	"Store oper login in ModData",
     14 	"UnrealIRCd Team",
     15 	"unrealircd-6",
     16     };
     17 
     18 /* Forward declarations */
     19 int operinfo_local_oper(Client *client, int up, const char *oper_block, const char *operclass);
     20 void operinfo_free(ModData *m);
     21 const char *operinfo_serialize(ModData *m);
     22 void operinfo_unserialize(const char *str, ModData *m);
     23 
     24 ModDataInfo *operlogin_md = NULL; /* Module Data structure which we acquire */
     25 ModDataInfo *operclass_md = NULL; /* Module Data structure which we acquire */
     26 
     27 MOD_INIT()
     28 {
     29 	ModDataInfo mreq;
     30 
     31 	MARK_AS_OFFICIAL_MODULE(modinfo);
     32 
     33 	memset(&mreq, 0, sizeof(mreq));
     34 	mreq.name = "operlogin";
     35 	mreq.free = operinfo_free;
     36 	mreq.serialize = operinfo_serialize;
     37 	mreq.unserialize = operinfo_unserialize;
     38 	mreq.sync = MODDATA_SYNC_EARLY;
     39 	mreq.type = MODDATATYPE_CLIENT;
     40 	operlogin_md = ModDataAdd(modinfo->handle, mreq);
     41 	if (!operlogin_md)
     42 		abort();
     43 
     44 	memset(&mreq, 0, sizeof(mreq));
     45 	mreq.name = "operclass";
     46 	mreq.free = operinfo_free;
     47 	mreq.serialize = operinfo_serialize;
     48 	mreq.unserialize = operinfo_unserialize;
     49 	mreq.sync = MODDATA_SYNC_EARLY;
     50 	mreq.type = MODDATATYPE_CLIENT;
     51 	operclass_md = ModDataAdd(modinfo->handle, mreq);
     52 	if (!operclass_md)
     53 		abort();
     54 
     55 	HookAdd(modinfo->handle, HOOKTYPE_LOCAL_OPER, 0, operinfo_local_oper);
     56 
     57 	return MOD_SUCCESS;
     58 }
     59 
     60 MOD_LOAD()
     61 {
     62 	return MOD_SUCCESS;
     63 }
     64 
     65 
     66 MOD_UNLOAD()
     67 {
     68 	return MOD_SUCCESS;
     69 }
     70 
     71 int operinfo_local_oper(Client *client, int up, const char *oper_block, const char *operclass)
     72 {
     73 	if (up)
     74 	{
     75 		moddata_client_set(client, "operlogin", oper_block);
     76 		moddata_client_set(client, "operclass", operclass);
     77 	} else {
     78 		moddata_client_set(client, "operlogin", NULL);
     79 		moddata_client_set(client, "operclass", NULL);
     80 	}
     81 	return 0;
     82 }
     83 
     84 void operinfo_free(ModData *m)
     85 {
     86 	safe_free(m->str);
     87 }
     88 
     89 const char *operinfo_serialize(ModData *m)
     90 {
     91 	if (!m->str)
     92 		return NULL;
     93 	return m->str;
     94 }
     95 
     96 void operinfo_unserialize(const char *str, ModData *m)
     97 {
     98 	safe_strdup(m->str, str);
     99 }