| 40 |
|
#include "modules.h" |
| 41 |
|
|
| 42 |
|
static void m_accept(struct Client *, struct Client *, int, char *[]); |
| 43 |
– |
static void build_nicklist(struct Client *, char *, char *, char *); |
| 44 |
– |
static void add_accept(struct Client *, struct Client *); |
| 43 |
|
static void list_accepts(struct Client *); |
| 44 |
|
|
| 45 |
|
struct Message accept_msgtab = { |
| 46 |
|
"ACCEPT", 0, 0, 0, 0, MFLG_SLOW, 0, |
| 47 |
< |
{m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore} |
| 47 |
> |
{ m_unregistered, m_accept, m_ignore, m_ignore, m_accept, m_ignore } |
| 48 |
|
}; |
| 49 |
|
|
| 50 |
|
#ifndef STATIC_MODULES |
| 63 |
|
const char *_version = "$Revision$"; |
| 64 |
|
#endif |
| 65 |
|
|
| 66 |
< |
/* |
| 67 |
< |
* m_accept - ACCEPT command handler |
| 68 |
< |
* parv[0] = sender prefix |
| 69 |
< |
* parv[1] = servername |
| 66 |
> |
|
| 67 |
> |
/* add_accept() |
| 68 |
> |
* |
| 69 |
> |
* input - pointer to preallocated nick |
| 70 |
> |
* - pointer to preallocated username |
| 71 |
> |
* - pointer to preallocated host |
| 72 |
> |
* - pointer to client to add to acceptlist |
| 73 |
> |
* output - none |
| 74 |
> |
* side effects - target is added to clients list |
| 75 |
|
*/ |
| 76 |
|
static void |
| 77 |
< |
m_accept(struct Client *client_p, struct Client *source_p, |
| 75 |
< |
int parc, char *parv[]) |
| 77 |
> |
add_accept(const struct split_nuh_item *nuh, struct Client *source_p) |
| 78 |
|
{ |
| 79 |
< |
char *nick; |
| 78 |
< |
char *p = NULL; |
| 79 |
< |
char addbuf[IRCD_BUFSIZE] = { '\0' }; |
| 80 |
< |
char delbuf[IRCD_BUFSIZE] = { '\0' }; |
| 81 |
< |
struct Client *target_p = NULL; |
| 82 |
< |
int accept_num; |
| 83 |
< |
|
| 84 |
< |
if ((parc < 2) || (*parv[1] == '*')) |
| 85 |
< |
{ |
| 86 |
< |
list_accepts(source_p); |
| 87 |
< |
return; |
| 88 |
< |
} |
| 79 |
> |
struct split_nuh_item *accept_p = MyMalloc(sizeof(*accept_p)); |
| 80 |
|
|
| 81 |
< |
build_nicklist(source_p, addbuf, delbuf, parv[1]); |
| 81 |
> |
DupString(accept_p->nickptr, nuh->nickptr); |
| 82 |
> |
DupString(accept_p->userptr, nuh->userptr); |
| 83 |
> |
DupString(accept_p->hostptr, nuh->hostptr); |
| 84 |
|
|
| 85 |
< |
/* parse the delete list */ |
| 93 |
< |
for (nick = strtoken(&p, delbuf, ","); nick != NULL; |
| 94 |
< |
nick = strtoken(&p, NULL, ",")) |
| 95 |
< |
{ |
| 96 |
< |
/* shouldnt happen, but lets be paranoid */ |
| 97 |
< |
if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p)) |
| 98 |
< |
{ |
| 99 |
< |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
| 100 |
< |
me.name, source_p->name, nick); |
| 101 |
< |
continue; |
| 102 |
< |
} |
| 103 |
< |
|
| 104 |
< |
/* user isnt on clients accept list */ |
| 105 |
< |
if (!accept_message(target_p, source_p)) |
| 106 |
< |
{ |
| 107 |
< |
sendto_one(source_p, form_str(ERR_ACCEPTNOT), |
| 108 |
< |
me.name, source_p->name, target_p->name); |
| 109 |
< |
continue; |
| 110 |
< |
} |
| 111 |
< |
|
| 112 |
< |
del_from_accept(target_p, source_p); |
| 113 |
< |
} |
| 85 |
> |
dlinkAdd(accept_p, &accept_p->node, &source_p->localClient->acceptlist); |
| 86 |
|
|
| 87 |
< |
/* get the number of accepts they have */ |
| 116 |
< |
accept_num = dlink_list_length(&source_p->allow_list); |
| 117 |
< |
|
| 118 |
< |
/* parse the add list */ |
| 119 |
< |
for (nick = strtoken(&p, addbuf, ","); nick; |
| 120 |
< |
nick = strtoken(&p, NULL, ","), accept_num++) |
| 121 |
< |
{ |
| 122 |
< |
/* shouldnt happen, but lets be paranoid */ |
| 123 |
< |
if (((target_p = find_client(nick)) == NULL) || !IsClient(target_p)) |
| 124 |
< |
{ |
| 125 |
< |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
| 126 |
< |
me.name, source_p->name, nick); |
| 127 |
< |
continue; |
| 128 |
< |
} |
| 129 |
< |
|
| 130 |
< |
/* user is already on clients accept list */ |
| 131 |
< |
if (accept_message(target_p, source_p)) |
| 132 |
< |
{ |
| 133 |
< |
sendto_one(source_p, form_str(ERR_ACCEPTEXIST), |
| 134 |
< |
me.name, source_p->name, target_p->name); |
| 135 |
< |
continue; |
| 136 |
< |
} |
| 137 |
< |
|
| 138 |
< |
if (accept_num >= ConfigFileEntry.max_accept) |
| 139 |
< |
{ |
| 140 |
< |
sendto_one(source_p, form_str(ERR_ACCEPTFULL), |
| 141 |
< |
me.name, source_p->name); |
| 142 |
< |
return; |
| 143 |
< |
} |
| 144 |
< |
|
| 145 |
< |
/* why is this here? */ |
| 146 |
< |
/* del_from accept(target_p, source_p); */ |
| 147 |
< |
add_accept(source_p, target_p); |
| 148 |
< |
} |
| 87 |
> |
list_accepts(source_p); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
< |
/* build_nicklist() |
| 90 |
> |
/*! \brief ACCEPT command handler |
| 91 |
|
* |
| 92 |
< |
* input - pointer to client |
| 93 |
< |
* - pointer to addbuffer |
| 94 |
< |
* - pointer to remove buffer |
| 95 |
< |
* - pointer to list of nicks |
| 96 |
< |
* output - |
| 97 |
< |
* side effects - addbuf/delbuf are modified to give valid nicks |
| 92 |
> |
* \param client_p Pointer to allocated Client struct with physical connection |
| 93 |
> |
* to this server, i.e. with an open socket connected. |
| 94 |
> |
* \param source_p Pointer to allocated Client struct from which the message |
| 95 |
> |
* originally comes from. This can be a local or remote client. |
| 96 |
> |
* \param parc Integer holding the number of supplied arguments. |
| 97 |
> |
* \param parv Argument vector where parv[0] .. parv[parc-1] are non-NULL |
| 98 |
> |
* pointers. |
| 99 |
> |
* \note Valid arguments for this command are: |
| 100 |
> |
* - parv[0] = sender prefix |
| 101 |
> |
* - parv[1] = list of masks to be accepted or removed (optional) |
| 102 |
|
*/ |
| 103 |
|
static void |
| 104 |
< |
build_nicklist(struct Client *source_p, char *addbuf, |
| 105 |
< |
char *delbuf, char *nicks) |
| 104 |
> |
m_accept(struct Client *client_p, struct Client *source_p, |
| 105 |
> |
int parc, char *parv[]) |
| 106 |
|
{ |
| 107 |
< |
char *name = NULL; |
| 107 |
> |
char *mask = NULL; |
| 108 |
|
char *p = NULL; |
| 109 |
< |
char *buf_p = NULL; |
| 110 |
< |
struct Client *target_p = NULL; |
| 109 |
> |
char nick[NICKLEN + 1]; |
| 110 |
> |
char user[USERLEN + 1]; |
| 111 |
> |
char host[HOSTLEN + 1]; |
| 112 |
> |
struct split_nuh_item nuh; |
| 113 |
> |
struct split_nuh_item *accept_p = NULL; |
| 114 |
|
|
| 115 |
< |
/* build list of clients to add into addbuf, clients to remove in delbuf */ |
| 170 |
< |
for (name = strtoken(&p, nicks, ","); name; |
| 171 |
< |
name = strtoken(&p, NULL, ",")) |
| 115 |
> |
if (EmptyString(parv[1]) || !irccmp(parv[1], "*")) |
| 116 |
|
{ |
| 117 |
< |
if (*name == '-') |
| 118 |
< |
buf_p = delbuf, ++name; |
| 119 |
< |
else |
| 176 |
< |
buf_p = addbuf; |
| 117 |
> |
list_accepts(source_p); |
| 118 |
> |
return; |
| 119 |
> |
} |
| 120 |
|
|
| 121 |
< |
if (((target_p = find_client(name)) == NULL) || !IsClient(target_p)) |
| 121 |
> |
for (mask = strtoken(&p, parv[1], ","); mask != NULL; |
| 122 |
> |
mask = strtoken(&p, NULL, ",")) |
| 123 |
> |
{ |
| 124 |
> |
if (*mask == '-' && *++mask != '\0') |
| 125 |
|
{ |
| 126 |
< |
sendto_one(source_p, form_str(ERR_NOSUCHNICK), |
| 127 |
< |
me.name, source_p->name, name); |
| 128 |
< |
continue; |
| 129 |
< |
} |
| 126 |
> |
nuh.nuhmask = mask; |
| 127 |
> |
nuh.nickptr = nick; |
| 128 |
> |
nuh.userptr = user; |
| 129 |
> |
nuh.hostptr = host; |
| 130 |
> |
|
| 131 |
> |
nuh.nicksize = sizeof(nick); |
| 132 |
> |
nuh.usersize = sizeof(user); |
| 133 |
> |
nuh.hostsize = sizeof(host); |
| 134 |
> |
|
| 135 |
> |
split_nuh(&nuh); |
| 136 |
> |
|
| 137 |
> |
if ((accept_p = find_accept(nick, user, host, source_p, 0)) == NULL) |
| 138 |
> |
{ |
| 139 |
> |
sendto_one(source_p, form_str(ERR_ACCEPTNOT), |
| 140 |
> |
me.name, source_p->name, nick, user, host); |
| 141 |
> |
continue; |
| 142 |
> |
} |
| 143 |
> |
|
| 144 |
> |
del_accept(accept_p, source_p); |
| 145 |
> |
} |
| 146 |
> |
else if (*mask != '\0') |
| 147 |
> |
{ |
| 148 |
> |
if (dlink_list_length(&source_p->localClient->acceptlist) >= |
| 149 |
> |
ConfigFileEntry.max_accept) |
| 150 |
> |
{ |
| 151 |
> |
sendto_one(source_p, form_str(ERR_ACCEPTFULL), |
| 152 |
> |
me.name, source_p->name); |
| 153 |
> |
return; |
| 154 |
> |
} |
| 155 |
> |
|
| 156 |
> |
nuh.nuhmask = mask; |
| 157 |
> |
nuh.nickptr = nick; |
| 158 |
> |
nuh.userptr = user; |
| 159 |
> |
nuh.hostptr = host; |
| 160 |
> |
|
| 161 |
> |
nuh.nicksize = sizeof(nick); |
| 162 |
> |
nuh.usersize = sizeof(user); |
| 163 |
> |
nuh.hostsize = sizeof(host); |
| 164 |
> |
|
| 165 |
> |
split_nuh(&nuh); |
| 166 |
> |
|
| 167 |
> |
if ((accept_p = find_accept(nick, user, host, source_p, 0)) != NULL) |
| 168 |
> |
{ |
| 169 |
> |
sendto_one(source_p, form_str(ERR_ACCEPTEXIST), |
| 170 |
> |
me.name, source_p->name, nick, user, host); |
| 171 |
> |
continue; |
| 172 |
> |
} |
| 173 |
|
|
| 174 |
< |
if (*buf_p) |
| 175 |
< |
strlcat(buf_p, ",", IRCD_BUFSIZE); |
| 187 |
< |
strlcat(buf_p, name, IRCD_BUFSIZE); |
| 174 |
> |
add_accept(&nuh, source_p); |
| 175 |
> |
} |
| 176 |
|
} |
| 177 |
|
} |
| 178 |
|
|
| 191 |
– |
/* add_accept() |
| 192 |
– |
* |
| 193 |
– |
* input - pointer to clients accept list to add to |
| 194 |
– |
* - pointer to client to add |
| 195 |
– |
* output - none |
| 196 |
– |
* side effects - target is added to clients list |
| 197 |
– |
*/ |
| 198 |
– |
static void |
| 199 |
– |
add_accept(struct Client *source_p, struct Client *target_p) |
| 200 |
– |
{ |
| 201 |
– |
dlinkAdd(target_p, make_dlink_node(), &source_p->allow_list); |
| 202 |
– |
dlinkAdd(source_p, make_dlink_node(), &target_p->on_allow_list); |
| 203 |
– |
list_accepts(source_p); |
| 204 |
– |
} |
| 205 |
– |
|
| 179 |
|
/* list_accepts() |
| 180 |
|
* |
| 181 |
|
* input - pointer to client |
| 192 |
|
|
| 193 |
|
len = strlen(me.name) + strlen(source_p->name) + 12; |
| 194 |
|
|
| 195 |
< |
DLINK_FOREACH(ptr, source_p->allow_list.head) |
| 195 |
> |
DLINK_FOREACH(ptr, source_p->localClient->acceptlist.head) |
| 196 |
|
{ |
| 197 |
< |
const struct Client *target_p = ptr->data; |
| 197 |
> |
const struct split_nuh_item *accept_p = ptr->data; |
| 198 |
> |
size_t masklen = strlen(accept_p->nickptr) + |
| 199 |
> |
strlen(accept_p->userptr) + |
| 200 |
> |
strlen(accept_p->hostptr) + 2 /* !@ */ ; |
| 201 |
|
|
| 202 |
< |
if ((t - nicks) + strlen(target_p->name) + len > IRCD_BUFSIZE) |
| 202 |
> |
if ((t - nicks) + masklen + len > IRCD_BUFSIZE) |
| 203 |
|
{ |
| 204 |
|
*(t - 1) = '\0'; |
| 205 |
|
sendto_one(source_p, form_str(RPL_ACCEPTLIST), |
| 207 |
|
t = nicks; |
| 208 |
|
} |
| 209 |
|
|
| 210 |
< |
t += ircsprintf(t, "%s ", target_p->name); |
| 210 |
> |
t += ircsprintf(t, "%s!%s@%s ", |
| 211 |
> |
accept_p->nickptr, |
| 212 |
> |
accept_p->userptr, accept_p->hostptr); |
| 213 |
|
} |
| 214 |
|
|
| 215 |
|
if (nicks[0] != '\0') |