Read the .finger-response file if not executable
This commit is contained in:
parent
3178216ade
commit
ba4b7e126d
|
@ -1,5 +1,6 @@
|
|||
#define _GNU_SOURCE
|
||||
#define _BSD_SOURCE
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <poll.h>
|
||||
|
@ -142,17 +143,57 @@ ssize_t writeall_str(int fd, const char *s) {
|
|||
return writeall(fd, s, strlen(s));
|
||||
}
|
||||
|
||||
bool handle_finger_response(int sock, const char *finger_response_file) {
|
||||
bool execute_finger_response(int sock, const char *finger_response_file) {
|
||||
// TODO: Execute the file
|
||||
(void)sock;
|
||||
(void)finger_response_file;
|
||||
// TODO: Handle .finger-response
|
||||
if(writeall_str(sock, "Lewd.\r\n") < 0) {
|
||||
log_perror("writeall_str (lewd)");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_finger_response(int sock, const char *finger_response_file) {
|
||||
FILE *f = fopen(finger_response_file, "r");
|
||||
if(f == NULL) {
|
||||
log_perror("fopen");
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t line_size = 0;
|
||||
char *line = NULL;
|
||||
ssize_t line_len;
|
||||
while((line_len = getline(&line, &line_size, f)) > 0) {
|
||||
// Strip the newline
|
||||
if(line[line_len - 1] == '\n') {
|
||||
line[line_len - 1] = '\0';
|
||||
line_len--;
|
||||
}
|
||||
|
||||
// Send the line along with the correct newline
|
||||
if(writeall(sock, line, line_len) < 0 || writeall_str(sock, "\r\n") < 0) {
|
||||
log_perror("writeall / writeall_str");
|
||||
free(line);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!feof(f)) {
|
||||
log_perror("getline");
|
||||
free(line);
|
||||
return false;
|
||||
}
|
||||
|
||||
free(line);
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool handle_finger_response(int sock, const char *finger_response_file) {
|
||||
if(access(finger_response_file, X_OK) == 0) {
|
||||
return execute_finger_response(sock, finger_response_file);
|
||||
} else {
|
||||
return read_finger_response(sock, finger_response_file);
|
||||
}
|
||||
}
|
||||
|
||||
void handle_userlist(int sock, bool force_multiline) {
|
||||
// Go over users' home dirs and see if .finger-response is present
|
||||
bool first_line = true;
|
||||
|
|
Loading…
Reference in New Issue