From 051ac812dbd196233c3e81116e7bec60ff9e5141 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 5 Mar 2026 18:09:12 +0100 Subject: [PATCH] examples: Add warning about example code Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- examples/sample_sftpserver.c | 24 +++++++++++++++++++++++- examples/samplesshd-cb.c | 17 +++++++++++++++++ examples/ssh_server.c | 17 +++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/examples/sample_sftpserver.c b/examples/sample_sftpserver.c index ced99318..169d2311 100644 --- a/examples/sample_sftpserver.c +++ b/examples/sample_sftpserver.c @@ -1,4 +1,4 @@ -/* This is a sample implementation of a libssh based SSH server */ +/* This is a sample implementation of a libssh based SFTP server */ /* Copyright 2014 Audrius Butkevicius @@ -9,6 +9,28 @@ domain. This does not apply to the rest of the library though, but it is allowed to cut-and-paste working code from this file to any license of program. The goal is to show the API in action. + +!!! WARNING / ACHTUNG !!! + +This is not a production-ready SFTP server implementation. While it demonstrates +how an SFTP server can be implemented on the SFTP layer and integrated into +existing SSH server, it lacks many steps int the authentication and +session establishment! + +It allows to log in any user with hardcoded credentials below or with public +key provided from authorized keys file. + +The resulting SFTP session keeps running under original user who runs the +example server and therefore the SFTP session has access to all files that are +accessible to the user running the server. + +Real-world servers should at very least switch the user to unprivileged one +after authentication using setuid(). If some more restrictions are needed, +generally limiting what files should and should not be accessible, it is +recommended to use chroot() as handling symlinks can be tricky in the SFTP +callbacks. + +!!! WARNING / ACHTUNG !!! */ #include "config.h" diff --git a/examples/samplesshd-cb.c b/examples/samplesshd-cb.c index 31e035ff..447cc714 100644 --- a/examples/samplesshd-cb.c +++ b/examples/samplesshd-cb.c @@ -10,6 +10,23 @@ allowed to cut-and-paste working code from this file to any license of program. The goal is to show the API in action. It's not a reference on how terminal clients must be made or how a client should react. + +!!! WARNING / ACHTUNG !!! + +This is not a production-ready SSH server implementation. While it demonstrates +how an SSH server can be implemented, it lacks many steps during +the authentication and session establishment! + +It allows to log in any user with hardcoded credentials below or with public +key provided from authorized keys file. + +The resulting session keeps running under original user who runs the example +server and therefore it retains the same permissions. + +Real-world servers should at very least switch the user to unprivileged one +after authentication using setuid(). + +!!! WARNING / ACHTUNG !!! */ #include "config.h" diff --git a/examples/ssh_server.c b/examples/ssh_server.c index 592ce445..94e679bb 100644 --- a/examples/ssh_server.c +++ b/examples/ssh_server.c @@ -9,6 +9,23 @@ domain. This does not apply to the rest of the library though, but it is allowed to cut-and-paste working code from this file to any license of program. The goal is to show the API in action. + +!!! WARNING / ACHTUNG !!! + +This is not a production-ready SSH server implementation. While it demonstrates +how an SSH server can be implemented, it lacks many steps during +the authentication and session establishment! + +It allows to log in any user with hardcoded credentials below or with public +key provided from authorized keys file. + +The resulting session keeps running under original user who runs the example +server and therefore it retains the same permissions. + +Real-world servers should at very least switch the user to unprivileged one +after authentication using setuid(). + +!!! WARNING / ACHTUNG !!! */ #include "config.h"