Check if user has .finger-response
This commit is contained in:
parent
9f057f691f
commit
4365a00b2a
|
@ -1,7 +1,9 @@
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
#define _BSD_SOURCE
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -135,38 +137,77 @@ ssize_t writeall(int fd, const char *buf, size_t amount) {
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ssize_t writeall_str(int fd, const char *s) {
|
||||||
|
return writeall(fd, s, strlen(s));
|
||||||
|
}
|
||||||
|
|
||||||
void handle_userlist(int sock) {
|
void handle_userlist(int sock) {
|
||||||
// Go over users' home dirs and see if .finger-response is present
|
// Go over users' home dirs and see if .finger-response is present
|
||||||
FILE *passwd = fopen("/etc/passwd", "r");
|
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
char *line = NULL;
|
|
||||||
size_t line_length;
|
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if(getline(&line, &line_length, passwd) < 0) {
|
struct passwd *passwd_entry = getpwent();
|
||||||
|
if(passwd_entry == NULL) {
|
||||||
if(errno == 0) {
|
if(errno == 0) {
|
||||||
// EOF reached
|
// End of file
|
||||||
|
endpwent();
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
perror("getline");
|
log_perror("getpwent");
|
||||||
free(line);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s", line); //debg
|
char *finger_response_file;
|
||||||
|
if(asprintf(&finger_response_file, "%s/.finger-response", passwd_entry->pw_dir) < 0) {
|
||||||
|
log_perror("asprintf");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
free(line);
|
if(access(finger_response_file, F_OK) == 0) {
|
||||||
|
if(writeall_str(sock, passwd_entry->pw_name) < 0) {
|
||||||
|
log_perror("writeall_str");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(writeall_str(sock, "\r\n") < 0) {
|
||||||
|
log_perror("writeall_str");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(passwd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_query(int sock, const char *username) {
|
void handle_query(int sock, const char *username) {
|
||||||
const char *response = "Lewd.\r\n";
|
errno = 0;
|
||||||
if(writeall(sock, response, strlen(response)) < 0) {
|
struct passwd *passwd_entry = getpwnam(username);
|
||||||
log_perror("write");
|
if(passwd_entry == NULL) {
|
||||||
|
if(errno == 0) {
|
||||||
|
if(writeall_str(sock, "Can't finger\r\n") < 0) {
|
||||||
|
log_perror("writeall_str");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log_perror("getpwent");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *finger_response_file;
|
||||||
|
if(asprintf(&finger_response_file, "%s/.finger-response", passwd_entry->pw_dir) < 0) {
|
||||||
|
log_perror("asprintf");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(access(finger_response_file, F_OK) != 0) {
|
||||||
|
if(writeall_str(sock, "Can't finger\r\n") < 0) {
|
||||||
|
log_perror("writeall_str");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const char *response = "Lewd.\r\n";
|
||||||
|
if(writeall(sock, response, strlen(response)) < 0) {
|
||||||
|
log_perror("write");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue