]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
net_ip2addr() changed to return "" instead of NULL on failure.
authorTimo Sirainen <tss@iki.fi>
Tue, 6 Aug 2013 11:53:23 +0000 (14:53 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 6 Aug 2013 11:53:23 +0000 (14:53 +0300)
Pretty much everything in the code assumed that it would never fail, which
it normally doesn't except if the ip_addr was created for UNIX sockets.

src/auth/auth-request.c
src/auth/passdb-pam.c
src/auth/passdb-vpopmail.c
src/lib/net.c
src/lib/net.h
src/lib/uri-util.c
src/lmtp/client.c
src/login-common/main.c

index 8cbe7a2ad04913eea5dd48d53dd33d8ba03e72d1..9ce62fc3ad8ed1a7008a5f8518a8b0a36e182971 100644 (file)
@@ -2021,7 +2021,7 @@ static void get_log_prefix(string_t *str, struct auth_request *auth_request,
        }
 
        ip = net_ip2addr(&auth_request->remote_ip);
-       if (ip != NULL) {
+       if (ip[0] != '\0') {
                str_append_c(str, ',');
                str_append(str, ip);
        }
index 0b0ff1c0b499f76acbf64e189c6e5639e85649e8..0c15bf86fce58d105440250fbd111b5a842b89b0 100644 (file)
@@ -238,7 +238,7 @@ static void set_pam_items(struct auth_request *request, pam_handle_t *pamh)
 
        /* These shouldn't fail, and we don't really care if they do. */
        host = net_ip2addr(&request->remote_ip);
-       if (host != NULL)
+       if (host[0] != '\0')
                (void)pam_set_item(pamh, PAM_RHOST, host);
        (void)pam_set_item(pamh, PAM_RUSER, request->user);
        /* TTY is needed by eg. pam_access module */
index 37b3ff5ac7a5324ebd1172ffc8ba3fced412e17a..1124132e7baea88c6d1c6f5055c8100910ec443a 100644 (file)
@@ -153,7 +153,7 @@ vpopmail_verify_plain(struct auth_request *request, const char *password,
            strcasecmp(request->service, "IMAP") == 0) {
                const char *host = net_ip2addr(&request->remote_ip);
                /* vpopmail 5.4 does not understand IPv6 */
-               if (host != NULL && IPADDR_IS_V4(&request->remote_ip)) {
+               if (host[0] != '\0' && IPADDR_IS_V4(&request->remote_ip)) {
                        /* use putenv() directly rather than env_put() which
                           would leak memory every time we got here. use a
                           static buffer for putenv() as SUSv2 requirements
index e3623b16ea083ed38c9c079b25c6e6d77e5b5ee9..b2e9a09c9a6b830cc33fa5f5e2a159918da601e5 100644 (file)
@@ -870,14 +870,14 @@ const char *net_ip2addr(const struct ip_addr *ip)
 
        addr[MAX_IP_LEN] = '\0';
        if (inet_ntop(ip->family, &ip->u.ip6, addr, MAX_IP_LEN) == NULL)
-               return NULL;
+               return "";
 
        return t_strdup(addr);
 #else
        unsigned long ip4;
 
        if (ip->family != AF_INET)
-               return NULL;
+               return "";
 
        ip4 = ntohl(ip->u.ip4.s_addr);
        return t_strdup_printf("%lu.%lu.%lu.%lu",
index 276285db8b57b15848bea684ef45a1155e491d06..2b21bde8fa735aeeb4c5f19d8d0b844f12f04f6a 100644 (file)
@@ -133,7 +133,7 @@ int net_getunixname(int fd, const char **name_r);
    unavailable. */
 int net_getunixcred(int fd, struct net_unix_cred *cred_r);
 
-/* Returns ip_addr as string, or NULL if ip is invalid. */
+/* Returns ip_addr as string, or "" if ip isn't valid IPv4 or IPv6 address. */
 const char *net_ip2addr(const struct ip_addr *ip);
 /* char* -> struct ip_addr translation. */
 int net_addr2ip(const char *addr, struct ip_addr *ip);
index b0fd3ecf073509deb9891e8d1460e9c3ecd33088..7b224c2ac4a1cb2a39486d94d76b2b8632bd006e 100644 (file)
@@ -799,8 +799,6 @@ void uri_append_host_ip(string_t *out, const struct ip_addr *host_ip)
 {
        const char *addr = net_ip2addr(host_ip);
 
-       i_assert(addr != NULL);
-
        if (host_ip->family == AF_INET) {
                str_append(out, addr);
                return;
index 67c368533993fa82473b95e5482b8f50bc298c6a..3b63758d7d1300d22137ccffb47a65d5f02bf2cb 100644 (file)
@@ -195,7 +195,7 @@ const char *client_remote_id(struct client *client)
        const char *addr;
 
        addr = net_ip2addr(&client->remote_ip);
-       if (addr == NULL)
+       if (addr[0] == '\0')
                addr = "local";
        return addr;
 }
index 9711b5fcb9d03bce3a765d2fe09ff5e65306300d..0ab48cbcd4ff0f61a1607c61419950fc26c5df6b 100644 (file)
@@ -64,11 +64,14 @@ void login_refresh_proctitle(void)
        } else if (clients_get_count() > 1 || client == NULL) {
                process_title_set(t_strdup_printf("[%u connections (%u TLS)]",
                        clients_get_count(), ssl_proxy_get_count()));
-       } else if ((addr = net_ip2addr(&client->ip)) != NULL) {
-               process_title_set(t_strdup_printf(client->tls ?
-                                                 "[%s TLS]" : "[%s]", addr));
        } else {
-               process_title_set(client->tls ? "[TLS]" : "");
+               addr = net_ip2addr(&client->ip);
+               if (addr[0] != '\0') {
+                       process_title_set(t_strdup_printf(client->tls ?
+                               "[%s TLS]" : "[%s]", addr));
+               } else {
+                       process_title_set(client->tls ? "[TLS]" : "");
+               }
        }
 }