unrealircd/src/modules/operinfo.c

100 lines
2.1 KiB
C
Raw Normal View History

2022-01-14 21:16:34 -08:00
/*
* Store oper login in ModData, used by WHOIS and for auditting purposes.
* (C) Copyright 2021-.. Syzop and The UnrealIRCd Team
2022-11-19 20:12:40 -08:00
* License: GPLv2 or later
2022-01-14 21:16:34 -08:00
*/
#include "unrealircd.h"
ModuleHeader MOD_HEADER
= {
"operinfo",
"5.0",
"Store oper login in ModData",
"UnrealIRCd Team",
"unrealircd-6",
};
/* Forward declarations */
2022-11-19 20:12:40 -08:00
int operinfo_local_oper(Client *client, int up, const char *oper_block, const char *operclass);
2022-01-14 21:16:34 -08:00
void operinfo_free(ModData *m);
const char *operinfo_serialize(ModData *m);
void operinfo_unserialize(const char *str, ModData *m);
ModDataInfo *operlogin_md = NULL; /* Module Data structure which we acquire */
ModDataInfo *operclass_md = NULL; /* Module Data structure which we acquire */
MOD_INIT()
{
ModDataInfo mreq;
MARK_AS_OFFICIAL_MODULE(modinfo);
memset(&mreq, 0, sizeof(mreq));
mreq.name = "operlogin";
mreq.free = operinfo_free;
mreq.serialize = operinfo_serialize;
mreq.unserialize = operinfo_unserialize;
mreq.sync = MODDATA_SYNC_EARLY;
mreq.type = MODDATATYPE_CLIENT;
operlogin_md = ModDataAdd(modinfo->handle, mreq);
if (!operlogin_md)
abort();
memset(&mreq, 0, sizeof(mreq));
mreq.name = "operclass";
mreq.free = operinfo_free;
mreq.serialize = operinfo_serialize;
mreq.unserialize = operinfo_unserialize;
mreq.sync = MODDATA_SYNC_EARLY;
mreq.type = MODDATATYPE_CLIENT;
operclass_md = ModDataAdd(modinfo->handle, mreq);
if (!operclass_md)
abort();
HookAdd(modinfo->handle, HOOKTYPE_LOCAL_OPER, 0, operinfo_local_oper);
return MOD_SUCCESS;
}
MOD_LOAD()
{
return MOD_SUCCESS;
}
MOD_UNLOAD()
{
return MOD_SUCCESS;
}
2022-11-19 20:12:40 -08:00
int operinfo_local_oper(Client *client, int up, const char *oper_block, const char *operclass)
2022-01-14 21:16:34 -08:00
{
if (up)
{
2022-11-19 20:12:40 -08:00
moddata_client_set(client, "operlogin", oper_block);
moddata_client_set(client, "operclass", operclass);
2022-01-14 21:16:34 -08:00
} else {
moddata_client_set(client, "operlogin", NULL);
moddata_client_set(client, "operclass", NULL);
}
return 0;
}
void operinfo_free(ModData *m)
{
safe_free(m->str);
}
const char *operinfo_serialize(ModData *m)
{
if (!m->str)
return NULL;
return m->str;
}
void operinfo_unserialize(const char *str, ModData *m)
{
safe_strdup(m->str, str);
}