File tree Expand file tree Collapse file tree 4 files changed +41
-2
lines changed
Expand file tree Collapse file tree 4 files changed +41
-2
lines changed Original file line number Diff line number Diff line change 2121#include "sftpcommon.h"
2222#include "types.h"
2323#include "globals.h"
24+ #include "thread.h"
25+ #include "utils.h"
26+ #include <stdlib.h>
27+ #include <string.h>
2428
2529#if NTHREADS > 1
2630struct queue * workqueue = 0 ;
2731#endif
2832
33+ static pthread_mutex_t state_lock = PTHREAD_MUTEX_INITIALIZER ;
34+ static enum sftp_state state ;
35+
36+ void sftp_state_set (enum sftp_state s ) {
37+ ferrcheck (pthread_mutex_lock (& state_lock ));
38+ state = s ;
39+ ferrcheck (pthread_mutex_unlock (& state_lock ));
40+ }
41+
42+ enum sftp_state sftp_state_get (void ) {
43+ enum sftp_state r ;
44+ ferrcheck (pthread_mutex_lock (& state_lock ));
45+ r = state ;
46+ ferrcheck (pthread_mutex_unlock (& state_lock ));
47+ return r ;
48+ }
49+
2950/*
3051Local Variables:
3152c-basic-offset:2
Original file line number Diff line number Diff line change @@ -94,6 +94,22 @@ struct stat;
9494 */
9595const char * status_to_string (uint32_t status );
9696
97+ /** @brief Possible SFTP service states */
98+ enum sftp_state {
99+ sftp_state_run = 0 ,
100+ sftp_state_stop = 1 ,
101+ };
102+
103+ /** @brief Get the current SFTP service state
104+ * @return State value
105+ */
106+ enum sftp_state sftp_state_get (void );
107+
108+ /** @brief Set the SFTP service state
109+ * @param s New state value
110+ */
111+ void sftp_state_set (enum sftp_state s );
112+
97113#endif /* SFTPCOMMON_H */
98114
99115/*
Original file line number Diff line number Diff line change @@ -658,7 +658,7 @@ static void sftp_service(void) {
658658 /* draft -13 s7.6 "The server SHOULD NOT apply a 'umask' to the mode
659659 * bits". */
660660 umask (0 );
661- while (!do_read (0 , & len , sizeof len )) {
661+ while (sftp_state_get () != sftp_state_stop && !do_read (0 , & len , sizeof len )) {
662662 job = xmalloc (sizeof * job );
663663 job -> len = ntohl (len );
664664 if (!job -> len || job -> len > MAXREQUEST )
Original file line number Diff line number Diff line change 2828#include "debug.h"
2929#include "utils.h"
3030#include "globals.h"
31+ #include "queue.h"
3132#include <unistd.h>
3233#include <string.h>
3334#include <errno.h>
@@ -178,7 +179,8 @@ uint32_t sftp_v6_version_select(struct sftpjob *job) {
178179 sftp_send_status (job , SSH_FX_INVALID_PARAMETER ,
179180 "badly timed version-select" );
180181 /* We MUST close the channel. (-13, s5.5). */
181- exit (-1 );
182+ sftp_state_set (sftp_state_stop );
183+ return HANDLER_RESPONDED ; /* even though we sent nothing */
182184}
183185
184186static const struct sftpcmd sftpv6tab [] = {
You can’t perform that action at this time.
0 commit comments