mirror of
https://github.com/ps5-payload-dev/ftpsrv.git
synced 2026-10-19 02:10:54 -05:00
fix build for linux systems
This commit is contained in:
1 parent
ff2ffb5eb9
commit
c169aa39ad
11 files changed
+288
-148
No files matched your search
@@ -39,8 +39,8 @@ jobs:
|
||||
|
||||
- name: Build Payload
|
||||
run: |
|
||||
make clean all
|
||||
zip -r Payload.zip ftpsrv.elf
|
||||
make -f Makefile.ps5 clean all
|
||||
zip -r Payload.zip ftpsrv-ps5.elf
|
||||
|
||||
- name: Upload Payload
|
||||
uses: actions/upload-artifact@v4
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
# Copyright (C) 2023 John Törnblom
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
PS5_HOST ?= ps5
|
||||
PS5_PORT ?= 9021
|
||||
|
||||
ifdef PS5_PAYLOAD_SDK
|
||||
include $(PS5_PAYLOAD_SDK)/toolchain/prospero.mk
|
||||
else
|
||||
$(error PS5_PAYLOAD_SDK is undefined)
|
||||
endif
|
||||
|
||||
ELF := ftpsrv.elf
|
||||
|
||||
CFLAGS := -Wall -Werror
|
||||
|
||||
all: $(ELF)
|
||||
|
||||
$(ELF): main.c cmd.c notify.c
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f $(ELF)
|
||||
|
||||
test: $(ELF)
|
||||
$(PS5_DEPLOY) -h $(PS5_HOST) -p $(PS5_PORT) $^
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
# Copyright (C) 2025 John Törnblom
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
ELF := ftpsrv-posix.elf
|
||||
|
||||
CFLAGS := -Wall -Werror
|
||||
|
||||
all: $(ELF)
|
||||
|
||||
$(ELF): main_posix.c srv.c cmd.c notify.c
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f $(ELF)
|
||||
|
||||
test: $(ELF)
|
||||
./$^ &
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
# Copyright (C) 2025 John Törnblom
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
PS5_HOST ?= ps5
|
||||
PS5_PORT ?= 9021
|
||||
|
||||
ifdef PS5_PAYLOAD_SDK
|
||||
include $(PS5_PAYLOAD_SDK)/toolchain/prospero.mk
|
||||
else
|
||||
$(error PS5_PAYLOAD_SDK is undefined)
|
||||
endif
|
||||
|
||||
ELF := ftpsrv-ps5.elf
|
||||
|
||||
CFLAGS := -Wall -Werror
|
||||
|
||||
all: $(ELF)
|
||||
|
||||
$(ELF): main_ps5.c srv.c cmd.c notify.c
|
||||
$(CC) $(CFLAGS) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f $(ELF)
|
||||
|
||||
test: $(ELF)
|
||||
$(PS5_DEPLOY) -h $(PS5_HOST) -p $(PS5_PORT) $^
|
||||
|
||||
@@ -30,8 +30,10 @@ along with this program; see the file COPYING. If not, see
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#include <sys/_iovec.h>
|
||||
#include <sys/mount.h>
|
||||
#endif
|
||||
|
||||
#include "cmd.h"
|
||||
#include "log.h"
|
||||
@@ -42,7 +44,7 @@ along with this program; see the file COPYING. If not, see
|
||||
#define IOVEC_SIZE(x) (sizeof(x) / sizeof(struct iovec))
|
||||
|
||||
|
||||
#ifdef __PROSPERO__
|
||||
#ifdef __SCE__
|
||||
struct tm *localtime_s(const time_t *t, struct tm* tm);
|
||||
#define LOCALTIME_R(t, tm) localtime_s(t, tm)
|
||||
#else
|
||||
@@ -360,7 +362,7 @@ ftp_cmd_DELE(ftp_env_t *env, const char* arg) {
|
||||
**/
|
||||
int
|
||||
ftp_cmd_LIST(ftp_env_t *env, const char* arg) {
|
||||
char pathbuf[PATH_MAX+256+2];
|
||||
char pathbuf[PATH_MAX*3];
|
||||
struct dirent *ent;
|
||||
const char *p = env->cwd;
|
||||
struct stat statbuf;
|
||||
@@ -515,7 +517,7 @@ ftp_cmd_REST(ftp_env_t *env, const char* arg) {
|
||||
int
|
||||
ftp_cmd_RETR(ftp_env_t *env, const char* arg) {
|
||||
char pathbuf[PATH_MAX];
|
||||
uint8_t buf[PAGE_SIZE];
|
||||
uint8_t buf[0x4000];
|
||||
struct stat st;
|
||||
int err = 0;
|
||||
int len;
|
||||
@@ -813,6 +815,7 @@ ftp_cmd_unknown(ftp_env_t *env, const char* arg) {
|
||||
**/
|
||||
int
|
||||
ftp_cmd_MTRW(ftp_env_t *env, const char* arg) {
|
||||
#ifdef __PROSPERO__
|
||||
struct iovec iov_sys[] = {
|
||||
IOVEC_ENTRY("from"), IOVEC_ENTRY("/dev/ssd0.system"),
|
||||
IOVEC_ENTRY("fspath"), IOVEC_ENTRY("/system"),
|
||||
@@ -840,8 +843,10 @@ ftp_cmd_MTRW(ftp_env_t *env, const char* arg) {
|
||||
if(syscall(SYS_nmount, iov_sysex, IOVEC_SIZE(iov_sysex), MNT_UPDATE)) {
|
||||
return ftp_perror(env);
|
||||
}
|
||||
|
||||
return ftp_active_printf(env, "226 /system and /system_ex remounted\r\n");
|
||||
#else
|
||||
return ftp_cmd_unknown(env, arg);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,13 @@ along with this program; see the file COPYING. If not, see
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ps5/klog.h>
|
||||
|
||||
#ifdef __PROSPERO__
|
||||
#include <ps5/klog.h>
|
||||
#else
|
||||
#define klog_puts(s)
|
||||
#define klog_printf(s, ...)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Log to stdout and klog
|
||||
@@ -33,7 +38,7 @@ along with this program; see the file COPYING. If not, see
|
||||
klog_printf(s, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define FTP_LOG_PERROR(s) { \
|
||||
#define FTP_LOG_PERROR(s) { \
|
||||
printf("%s:%d:%s: %s\n", __FILE__, __LINE__, s, strerror(errno)); \
|
||||
klog_printf("%s:%d:%s: %s\n", __FILE__, __LINE__, s, strerror(errno)); \
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* Copyright (C) 2025 John Törnblom
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 3, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING. If not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "srv.h"
|
||||
|
||||
|
||||
int
|
||||
main() {
|
||||
uint16_t port = 2121;
|
||||
|
||||
FTP_LOG_PRINTF("FTP server was compiled at %s %s\n", __DATE__, __TIME__);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
while(1) {
|
||||
ftp_serve(port, 0);
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "gnu"
|
||||
End:
|
||||
*/
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/* Copyright (C) 2025 John Törnblom
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 3, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING. If not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <ps5/kernel.h>
|
||||
|
||||
#include "srv.h"
|
||||
#include "log.h"
|
||||
|
||||
|
||||
/**
|
||||
* Fint the pid of a process with the given name.
|
||||
**/
|
||||
static pid_t
|
||||
find_pid(const char* name) {
|
||||
int mib[4] = {1, 14, 8, 0};
|
||||
pid_t mypid = getpid();
|
||||
pid_t pid = -1;
|
||||
size_t buf_size;
|
||||
uint8_t *buf;
|
||||
|
||||
if(sysctl(mib, 4, 0, &buf_size, 0, 0)) {
|
||||
FTP_LOG_PERROR("sysctl");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(buf=malloc(buf_size))) {
|
||||
FTP_LOG_PERROR("malloc");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(sysctl(mib, 4, buf, &buf_size, 0, 0)) {
|
||||
FTP_LOG_PERROR("sysctl");
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(uint8_t *ptr=buf; ptr<(buf+buf_size);) {
|
||||
int ki_structsize = *(int*)ptr;
|
||||
pid_t ki_pid = *(pid_t*)&ptr[72];
|
||||
char *ki_tdname = (char*)&ptr[447];
|
||||
|
||||
ptr += ki_structsize;
|
||||
if(!strcmp(name, ki_tdname) && ki_pid != mypid) {
|
||||
pid = ki_pid;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Launch payload.
|
||||
**/
|
||||
int
|
||||
main() {
|
||||
uint16_t port = 2121;
|
||||
int notify_user = 1;
|
||||
pid_t pid;
|
||||
|
||||
syscall(SYS_thr_set_name, -1, "ftpsrv.elf");
|
||||
|
||||
FTP_LOG_PRINTF("FTP server was compiled at %s %s\n", __DATE__, __TIME__);
|
||||
|
||||
while((pid=find_pid("ftpsrv.elf")) > 0) {
|
||||
if(kill(pid, SIGKILL)) {
|
||||
FTP_LOG_PERROR("kill");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// change authid so certain character devices can be read, e.g.,
|
||||
// /dev/sflash0
|
||||
pid = getpid();
|
||||
if(kernel_set_ucred_authid(pid, 0x4801000000000013L)) {
|
||||
FTP_LOG_PUTS("Unable to change AuthID");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
ftp_serve(port, notify_user);
|
||||
notify_user = 0;
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "gnu"
|
||||
End:
|
||||
*/
|
||||
@@ -38,5 +38,9 @@ notify(const char *fmt, ...) {
|
||||
vsnprintf(req.message, sizeof req.message, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
#ifdef __SCE__
|
||||
sceKernelSendNotificationRequest(0, &req, sizeof req, 0);
|
||||
#else
|
||||
puts(req.message);
|
||||
#endif
|
||||
}
|
||||
+7
-100
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2023 John Törnblom
|
||||
/* Copyright (C) 2025 John Törnblom
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
@@ -14,25 +14,17 @@ You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING. If not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <ifaddrs.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <ps5/kernel.h>
|
||||
|
||||
#include "cmd.h"
|
||||
#include "log.h"
|
||||
@@ -260,7 +252,7 @@ ftp_thread(void *args) {
|
||||
/**
|
||||
* Serve FTP on a given port.
|
||||
**/
|
||||
static int
|
||||
int
|
||||
ftp_serve(uint16_t port, int notify_user) {
|
||||
struct sockaddr_in server_addr;
|
||||
struct sockaddr_in client_addr;
|
||||
@@ -277,8 +269,6 @@ ftp_serve(uint16_t port, int notify_user) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
// Enumerate all AF_INET IPs
|
||||
for(struct ifaddrs *ifa=ifaddr; ifa!=NULL; ifa=ifa->ifa_next) {
|
||||
if(ifa->ifa_addr == NULL) {
|
||||
@@ -305,7 +295,7 @@ ftp_serve(uint16_t port, int notify_user) {
|
||||
if(notify_user) {
|
||||
notify("Serving FTP on %s:%d (%s)", ip, port, ifa->ifa_name);
|
||||
}
|
||||
FTP_LOG_PRINTF("Serving FTP on %s:%d (%s)\n", ip, port, ifa->ifa_name);
|
||||
|
||||
ifaddr_wait = 0;
|
||||
}
|
||||
|
||||
@@ -355,89 +345,6 @@ ftp_serve(uint16_t port, int notify_user) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fint the pid of a process with the given name.
|
||||
**/
|
||||
static pid_t
|
||||
find_pid(const char* name) {
|
||||
int mib[4] = {1, 14, 8, 0};
|
||||
pid_t mypid = getpid();
|
||||
pid_t pid = -1;
|
||||
size_t buf_size;
|
||||
uint8_t *buf;
|
||||
|
||||
if(sysctl(mib, 4, 0, &buf_size, 0, 0)) {
|
||||
FTP_LOG_PERROR("sysctl");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!(buf=malloc(buf_size))) {
|
||||
FTP_LOG_PERROR("malloc");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(sysctl(mib, 4, buf, &buf_size, 0, 0)) {
|
||||
FTP_LOG_PERROR("sysctl");
|
||||
free(buf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(uint8_t *ptr=buf; ptr<(buf+buf_size);) {
|
||||
int ki_structsize = *(int*)ptr;
|
||||
pid_t ki_pid = *(pid_t*)&ptr[72];
|
||||
char *ki_tdname = (char*)&ptr[447];
|
||||
|
||||
ptr += ki_structsize;
|
||||
if(!strcmp(name, ki_tdname) && ki_pid != mypid) {
|
||||
pid = ki_pid;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Launch payload.
|
||||
**/
|
||||
int
|
||||
main() {
|
||||
uint16_t port = 2121;
|
||||
int notify_user = 1;
|
||||
pid_t pid;
|
||||
|
||||
syscall(SYS_thr_set_name, -1, "ftpsrv.elf");
|
||||
|
||||
FTP_LOG_PRINTF("FTP server was compiled at %s %s\n", __DATE__, __TIME__);
|
||||
|
||||
while((pid=find_pid("ftpsrv.elf")) > 0) {
|
||||
if(kill(pid, SIGKILL)) {
|
||||
FTP_LOG_PERROR("kill");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// change authid so certain character devices can be read, e.g.,
|
||||
// /dev/sflash0
|
||||
pid = getpid();
|
||||
if(kernel_set_ucred_authid(pid, 0x4801000000000013L)) {
|
||||
FTP_LOG_PUTS("Unable to change AuthID");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
ftp_serve(port, notify_user);
|
||||
notify_user = 0;
|
||||
sleep(3);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "gnu"
|
||||
@@ -0,0 +1,21 @@
|
||||
/* Copyright (C) 2025 John Törnblom
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 3, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; see the file COPYING. If not, see
|
||||
<http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
int ftp_serve(uint16_t port, int notify_user);
|
||||
Reference in new issue
Block a user