]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm who -1: Fixed filtering.
authorTimo Sirainen <tss@iki.fi>
Fri, 23 Oct 2009 01:18:09 +0000 (21:18 -0400)
committerTimo Sirainen <tss@iki.fi>
Fri, 23 Oct 2009 01:18:09 +0000 (21:18 -0400)
--HG--
branch : HEAD

src/doveadm/doveadm-who.c

index 2ead831cfb6342917deaf67f8cccac734cb9e9ee..e1af804dd96d103a32822616e50d75be942e46e6 100644 (file)
@@ -156,8 +156,8 @@ static void who_lookup(struct who_context *ctx, who_callback_t *callback)
        i_stream_destroy(&input);
 }
 
-static bool who_filter_match(const struct who_user *user,
-                            const struct who_filter *filter)
+static bool who_user_filter_match(const struct who_user *user,
+                                 const struct who_filter *filter)
 {
        if (filter->username != NULL) {
                if (strstr(user->username, filter->username) == NULL)
@@ -194,7 +194,7 @@ static void who_print(struct who_context *ctx)
                const pid_t *pid;
                bool first = TRUE;
 
-               if (!who_filter_match(user, &ctx->filter))
+               if (!who_user_filter_match(user, &ctx->filter))
                        continue;
 
                printf("%-30s %2u %-5s ", user->username,
@@ -222,11 +222,29 @@ static void who_print(struct who_context *ctx)
        hash_table_iterate_deinit(&iter);
 }
 
-static void who_print_line(struct who_context *ctx ATTR_UNUSED,
+static bool who_line_filter_match(const struct who_line *line,
+                                 const struct who_filter *filter)
+{
+       if (filter->username != NULL) {
+               if (strstr(line->username, filter->username) == NULL)
+                       return FALSE;
+       }
+       if (filter->net_bits > 0) {
+               if (!net_is_in_network(&line->ip, &filter->net_ip,
+                                      filter->net_bits))
+                       return FALSE;
+       }
+       return TRUE;
+}
+
+static void who_print_line(struct who_context *ctx,
                           const struct who_line *line)
 {
        unsigned int i;
 
+       if (!who_line_filter_match(line, &ctx->filter))
+               return;
+
        for (i = 0; i < line->refcount; i++) T_BEGIN {
                printf("%-30s %-15s %-5s %ld\n", line->username,
                       net_ip2addr(&line->ip), line->service, (long)line->pid);