16 static void check_new_user(void *data
);
17 mapi_hfn_list_av1 sasl_usercloak_hfnlist
[] = {
18 { "new_local_user", (hookfn
) check_new_user
},
22 DECLARE_MODULE_AV1(sasl_usercloak
, NULL
, NULL
, NULL
, NULL
,
23 sasl_usercloak_hfnlist
, "$Revision: 3526 $");
32 notify_banned_client(struct Client
*client_p
, struct ConfItem
*aconf
, int ban
)
34 static const char conn_closed
[] = "Connection closed";
35 static const char d_lined
[] = "D-lined";
36 static const char k_lined
[] = "K-lined";
37 const char *reason
= NULL
;
38 const char *exit_reason
= conn_closed
;
40 if(ConfigFileEntry
.kline_with_reason
)
42 reason
= get_user_ban_reason(aconf
);
47 reason
= aconf
->status
== D_LINED
? d_lined
: k_lined
;
50 if(ban
== D_LINED
&& !IsPerson(client_p
))
51 sendto_one(client_p
, "NOTICE DLINE :*** You have been D-lined");
53 sendto_one(client_p
, form_str(ERR_YOUREBANNEDCREEP
),
54 me
.name
, client_p
->name
, reason
);
56 exit_client(client_p
, client_p
, &me
,
57 EmptyString(ConfigFileEntry
.kline_reason
) ? exit_reason
:
58 ConfigFileEntry
.kline_reason
);
61 unsigned int fnv_hash_string(char *str
)
63 unsigned int hash
= 0x811c9dc5; // Magic value for 32-bit fnv1 hash initialisation.
64 unsigned char *p
= (unsigned char *)str
;
67 hash
+= (hash
<<1) + (hash
<<4) + (hash
<<7) + (hash
<<8) + (hash
<<24);
74 check_new_user(void *vdata
)
76 struct Client
*source_p
= (void *)vdata
;
78 if (!IsIPSpoof(source_p
))
81 if (EmptyString(source_p
->user
->suser
))
84 char *accountpart
= strstr(source_p
->orighost
, "account");
89 memset(buf
, 0, sizeof(buf
));
92 strncpy(buf
, source_p
->orighost
, accountpart
- source_p
->orighost
);
93 dst
+= accountpart
- source_p
->orighost
;
97 for (char *src
= source_p
->user
->suser
; *src
; src
++ )
99 if (dst
>= buf
+ sizeof(buf
))
101 /* Doesn't fit. Warn opers and bail. */
102 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
103 "Couldn't fit account name part %s in hostname for %s!%s@%s",
104 source_p
->user
->suser
, source_p
->name
, source_p
->username
, source_p
->orighost
);
108 char c
= ToLower(*src
);
118 if (dst
> buf
+ sizeof(buf
) - 12) /* '/x-' plus eight digit hash plus null terminator */
120 /* Doesn't fit. Warn opers and bail. */
121 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
122 "Couldn't fit account name part %s in hostname for %s!%s@%s",
123 source_p
->user
->suser
, source_p
->name
, source_p
->username
, source_p
->orighost
);
131 unsigned int hashval
= fnv_hash_string(source_p
->user
->suser
);
132 hashval
%= 100000000; // eight digits only please.
133 snprintf(dst
, 9, "%08ud", hashval
);
137 buf
[HOSTLEN
-1] = '\0';
139 /* If hostname has been changed already (probably by services cloak on SASL login), then
140 * leave it intact. If not, change it. In either case, update the original hostname.
142 if (0 == irccmp(source_p
->host
, source_p
->orighost
))
143 change_nick_user_host(source_p
, source_p
->name
, source_p
->username
, buf
, 0, "Changing host");
144 strncpy(source_p
->orighost
, buf
, HOSTLEN
);
147 struct ConfItem
*aconf
= find_kline(source_p
);
152 if(IsExemptKline(source_p
))
154 sendto_realops_snomask(SNO_GENERAL
, L_NETWIDE
,
155 "KLINE over-ruled for %s, client is kline_exempt [%s@%s]",
156 get_client_name(source_p
, HIDE_IP
),
157 aconf
->user
, aconf
->host
);
161 sendto_realops_snomask(SNO_GENERAL
, L_ALL
,
162 "KLINE active for %s",
163 get_client_name(source_p
, HIDE_IP
));
165 notify_banned_client(source_p
, aconf
, K_LINED
);