commit - 528c8fc244cb689d83d10203330718ba6b593458
commit + cde2e8a2775e8b01266627a60a08e2560eac42c8
blob - 0f617b8213d1ff3fe56a5cbf9babf58265080df9
blob + 800e99353647f8758488a30db2d8f41259dc1129
--- src/ngircd/class.c
+++ src/ngircd/class.c
struct list_head My_Classes[CLASS_COUNT];
-char Reject_Reason[COMMAND_LEN];
-
GLOBAL void
Class_Init(void)
{
for (i = 0; i < CLASS_COUNT; Lists_Free(&My_Classes[i++]));
}
-GLOBAL char *
-Class_GetMemberReason(const int Class, CLIENT *Client)
+GLOBAL bool
+Class_GetMemberReason(const int Class, CLIENT *Client, char *reason, size_t len)
{
- char *reason;
+ char str[COMMAND_LEN] = "listed";
assert(Class < CLASS_COUNT);
assert(Client != NULL);
- reason = Lists_CheckReason(&My_Classes[Class], Client);
- if (!reason)
- return NULL;
+ if (!Lists_CheckReason(&My_Classes[Class], Client, str, sizeof(str)))
+ return false;
- if (!*reason)
- reason = "listed";
-
switch(Class) {
case CLASS_GLINE:
- snprintf(Reject_Reason, sizeof(Reject_Reason),
- "\"%s\" (G-Line)", reason);
- return Reject_Reason;
+ snprintf(reason, len, "\"%s\" (G-Line)", str);
+ break;
case CLASS_KLINE:
- snprintf(Reject_Reason, sizeof(Reject_Reason),
- "\"%s\" (K-Line)", reason);
- return Reject_Reason;
+ snprintf(reason, len, "\"%s\" (K-Line)", str);
+ break;
+ default:
+ snprintf(reason, len, "%s", str);
+ break;
}
- return reason;
+ return true;
}
/**
GLOBAL bool
Class_HandleServerBans(CLIENT *Client)
{
- char *rejectptr;
+ char reject[COMMAND_LEN];
assert(Client != NULL);
- rejectptr = Class_GetMemberReason(CLASS_GLINE, Client);
- if (!rejectptr)
- rejectptr = Class_GetMemberReason(CLASS_KLINE, Client);
- if (rejectptr) {
- Client_Reject(Client, rejectptr, true);
+ if (Class_GetMemberReason(CLASS_GLINE, Client, reject, sizeof(reject)) ||
+ Class_GetMemberReason(CLASS_KLINE, Client, reject, sizeof(reject))) {
+ Client_Reject(Client, reject, true);
return DISCONNECTED;
}
blob - 2a9dbba76a88db4276099e4525bab5f32fd56314
blob + ba2e16069def9e0ad4abb365a97462cef3c46ec9
--- src/ngircd/class.h
+++ src/ngircd/class.h
const time_t ValidUntil, const char *Reason));
GLOBAL void Class_DeleteMask PARAMS((const int Class, const char *Mask));
-GLOBAL char *Class_GetMemberReason PARAMS((const int Class, CLIENT *Client));
+GLOBAL bool Class_GetMemberReason PARAMS((const int Class, CLIENT *Client,
+ char *reason, size_t len));
GLOBAL bool Class_HandleServerBans PARAMS((CLIENT *Client));
GLOBAL struct list_head *Class_GetList PARAMS((const int Class));
blob - 21058a03116298b6cc81ff98f40b40d0c9caa502
blob + bab30f221be15766267347cf2a0f9f14ae5e92de
--- src/ngircd/lists.c
+++ src/ngircd/lists.c
if (e) {
e->valid_until = ValidUntil;
if (Reason) {
- free(e->reason);
+ if (e->reason)
+ free(e->reason);
e->reason = strdup(Reason);
}
return true;
bool
Lists_Check(struct list_head *h, CLIENT *Client)
{
- return Lists_CheckReason(h, Client) != NULL;
+ return Lists_CheckReason(h, Client, NULL, 0);
}
/**
- * Check if a client is listed in a list and return the "reason".
+ * Check if a client is listed in a list and store the reason if a buffer
+ * is provided.
*
- * @param h List head.
+ * @param h List head.
* @param Client Client to check.
+ * @param reason Result buffer to store the reason.
+ * @param len Size of the buffer.
* @return true if client is listed, false if not.
*/
-char *
-Lists_CheckReason(struct list_head *h, CLIENT *Client)
+bool
+Lists_CheckReason(struct list_head *h, CLIENT *Client, char *reason, size_t len)
{
struct list_elem *e, *last, *next;
while (e) {
next = e->next;
if (Match(e->mask, Client_MaskCloaked(Client))) {
+ if (len && e->reason)
+ strlcpy(reason, e->reason, len);
if (e->valid_until == 1) {
/* Entry is valid only once, delete it */
LogDebug("Deleted \"%s\" from list (used).",
e->mask);
Lists_Unlink(h, last, e);
}
- return e->reason ? e->reason : "";
+ return true;
}
last = e;
e = next;
}
- return NULL;
+ return false;
}
/**
blob - 24504dfab9d11860a2c8459b12e7ff5e22a211b0
blob + eb863db9f0a08c02aa6740a46f2547ae3761ea5e
--- src/ngircd/lists.h
+++ src/ngircd/lists.h
GLOBAL struct list_elem *Lists_GetNext PARAMS((const struct list_elem *));
GLOBAL bool Lists_Check PARAMS((struct list_head *head, CLIENT *client));
-GLOBAL char *Lists_CheckReason PARAMS((struct list_head *head, CLIENT *client));
+GLOBAL bool Lists_CheckReason PARAMS((struct list_head *head, CLIENT *client,
+ char *reason, size_t len));
GLOBAL struct list_elem *Lists_CheckDupeMask PARAMS((const struct list_head *head,
const char *mask));