From d7840e0ccf3f1e527992e871ecf59cea081b9d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Mon, 16 Jul 2018 16:20:22 +0000 Subject: [PATCH] Start reading users from /etc/passwd --- lewdfingerd.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lewdfingerd.c b/lewdfingerd.c index 2ffce40..8a80ce8 100644 --- a/lewdfingerd.c +++ b/lewdfingerd.c @@ -135,10 +135,27 @@ ssize_t writeall(int fd, const char *buf, size_t amount) { } void handle_userlist(int sock) { - const char *response = "Who do you want to finger?\r\n"; - if(writeall(sock, response, strlen(response)) < 0) { - log_perror("write"); + // Go over users' home dirs and see if .finger-response is present + FILE *passwd = fopen("/etc/passwd", "r"); + + while(!feof(passwd)) { + char *line = NULL; + size_t line_length; + + // FIXME: Funkiness with eof + if(getline(&line, &line_length, passwd) < 0) { + // Bail out on error + perror("getline"); + free(line); + return; + } + + printf("%s", line); //debg + + free(line); } + + fclose(passwd); } void handle_query(int sock, const char *username) {