]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/client.c
Fix C syntax: duplicate ";;" should be ";"
[ngircd-alex.git] / src / ngircd / client.c
index 16c551f97a89b422bf356465f45b0cc85a522e11..7e28e8fb1035006d540e9f3e4b7ba7d720944662 100644 (file)
@@ -186,7 +186,6 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer,
 
        assert(Idx >= NONE);
        assert(Introducer != NULL);
-       assert(Hostname != NULL);
 
        client = New_Client_Struct();
        if (!client)
@@ -313,16 +312,29 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
 } /* Client_Destroy */
 
 
+/**
+ * Set client hostname.
+ *
+ * If global hostname cloaking is in effect, don't set the real hostname
+ * but the configured one.
+ *
+ * @param Client The client of which the hostname should be set.
+ * @param Hostname The new hostname.
+ */
 GLOBAL void
 Client_SetHostname( CLIENT *Client, const char *Hostname )
 {
-       assert( Client != NULL );
-       assert( Hostname != NULL );
+       assert(Client != NULL);
+       assert(Hostname != NULL);
 
        if (strlen(Conf_CloakHost)) {
-               strlcpy( Client->host, Conf_CloakHost, sizeof( Client->host ));
+               LogDebug("Updating hostname of \"%s\": \"%s\" -> \"%s\"",
+                        Client_ID(Client), Client->host, Conf_CloakHost);
+               strlcpy(Client->host, Conf_CloakHost, sizeof(Client->host));
        } else {
-               strlcpy( Client->host, Hostname, sizeof( Client->host ));
+               LogDebug("Updating hostname of \"%s\": \"%s\" -> \"%s\"",
+                        Client_ID(Client), Client->host, Hostname);
+               strlcpy(Client->host, Hostname, sizeof(Client->host));
        }
 } /* Client_SetHostname */
 
@@ -768,7 +780,7 @@ Client_NextHop( CLIENT *Client )
  * Return ID of a client: "client!user@host"
  * This client ID is used for IRC prefixes, for example.
  * Please note that this function uses a global static buffer, so you can't
- * nest invocations without overwriting erlier results!
+ * nest invocations without overwriting earlier results!
  * @param Client Pointer to client structure
  * @return Pointer to global buffer containing the client ID
  */
@@ -793,7 +805,7 @@ Client_Mask( CLIENT *Client )
  * Return ID of a client with cloaked hostname: "client!user@server-name"
  * This client ID is used for IRC prefixes, for example.
  * Please note that this function uses a global static buffer, so you can't
- * nest invocations without overwriting erlier results!
+ * nest invocations without overwriting earlier results!
  * If the client has not enabled cloaking, the real hostname is used.
  * @param Client Pointer to client structure
  * @return Pointer to global buffer containing the client ID
@@ -1097,6 +1109,39 @@ Client_StartTime(CLIENT *Client)
 } /* Client_Uptime */
 
 
+/**
+ * Reject a client when logging in.
+ *
+ * This function is called when a client isn't allowed to connect to this
+ * server. Possible reasons are bad server password, bad PAM password,
+ * or that the client is G/K-Line'd.
+ *
+ * After calling this function, the client isn't connected any more.
+ *
+ * @param Client The client to reject.
+ * @param Reason The reason why the client has been rejected.
+ * @param InformClient If true, send the exact reason to the client.
+ */
+GLOBAL void
+Client_Reject(CLIENT *Client, const char *Reason, bool InformClient)
+{
+       char info[COMMAND_LEN];
+
+       assert(Client != NULL);
+       assert(Reason != NULL);
+
+       if (InformClient)
+               snprintf(info, sizeof(info), "Access denied: %s", Reason);
+       else
+               strcpy(info, "Access denied: Bad password?");
+
+       Log(LOG_ERR,
+           "User \"%s\" rejected (connection %d): %s!",
+           Client_Mask(Client), Client_Conn(Client), Reason);
+       Conn_Close(Client_Conn(Client), Reason, info, true);
+}
+
+
 static unsigned long
 Count( CLIENT_TYPE Type )
 {