/[LeafOK_CVS]/lbbs/src/net_server.c
ViewVC logotype

Diff of /lbbs/src/net_server.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.74 by sysadm, Sat Oct 25 03:11:11 2025 UTC Revision 1.81 by sysadm, Tue Nov 11 00:28:05 2025 UTC
# Line 1  Line 1 
1  /***************************************************************************  /* SPDX-License-Identifier: GPL-3.0-or-later */
2                                                    net_server.c  -  description  /*
3                                                           -------------------   * net_server
4          Copyright            : (C) 2004-2025 by Leaflet   *   - network server with SSH support
5          Email                : leaflet@leafok.com   *
6   ***************************************************************************/   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>
7     */
8  /***************************************************************************  
9   *                                                                         *  #ifdef HAVE_CONFIG_H
10   *   This program is free software; you can redistribute it and/or modify  *  #include "config.h"
11   *   it under the terms of the GNU General Public License as published by  *  #endif
  *   the Free Software Foundation; either version 3 of the License, or     *  
  *   (at your option) any later version.                                   *  
  *                                                                         *  
  ***************************************************************************/  
12    
13  #include "bbs.h"  #include "bbs.h"
14  #include "bbs_main.h"  #include "bbs_main.h"
15    #include "bwf.h"
16  #include "common.h"  #include "common.h"
17  #include "database.h"  #include "database.h"
18  #include "file_loader.h"  #include "file_loader.h"
# Line 47  Line 44 
44  #include <sys/wait.h>  #include <sys/wait.h>
45  #include <systemd/sd-daemon.h>  #include <systemd/sd-daemon.h>
46    
47  #define WAIT_CHILD_PROCESS_EXIT_TIMEOUT 5 // second  enum _net_server_constant_t
48  #define WAIT_CHILD_PROCESS_KILL_TIMEOUT 1 // second  {
49            WAIT_CHILD_PROCESS_EXIT_TIMEOUT = 5, // second
50            WAIT_CHILD_PROCESS_KILL_TIMEOUT = 1, // second
51    
52            SSH_AUTH_MAX_DURATION = 60 * 1000, // milliseconds
53    };
54    
55  struct process_sockaddr_t  struct process_sockaddr_t
56  {  {
# Line 59  typedef struct process_sockaddr_t PROCES Line 61  typedef struct process_sockaddr_t PROCES
61    
62  static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT];  static PROCESS_SOCKADDR process_sockaddr_pool[MAX_CLIENT_LIMIT];
63    
64  #define SSH_AUTH_MAX_DURATION (60 * 1000) // milliseconds  static const char SFTP_SERVER_PATH[] = "/usr/lib/sftp-server";
   
 #define SFTP_SERVER_PATH "/usr/lib/sftp-server"  
65    
66  /* A userdata struct for session. */  /* A userdata struct for session. */
67  struct session_data_struct  struct session_data_struct
# Line 333  static int fork_server(void) Line 333  static int fork_server(void)
333    
334                  ssh_bind_free(sshbind);                  ssh_bind_free(sshbind);
335    
                 ssh_callbacks_init(&channel_cb);  
                 ssh_callbacks_init(&server_cb);  
   
                 ssh_set_server_callbacks(SSH_session, &server_cb);  
   
336                  ssh_timeout = 60; // second                  ssh_timeout = 60; // second
337                  if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)                  if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)
338                  {                  {
# Line 345  static int fork_server(void) Line 340  static int fork_server(void)
340                          goto cleanup;                          goto cleanup;
341                  }                  }
342    
343                    ssh_set_auth_methods(SSH_session, SSH_AUTH_METHOD_PASSWORD);
344    
345                    ssh_callbacks_init(&server_cb);
346                    ssh_callbacks_init(&channel_cb);
347    
348                    ssh_set_server_callbacks(SSH_session, &server_cb);
349    
350                  if (ssh_handle_key_exchange(SSH_session))                  if (ssh_handle_key_exchange(SSH_session))
351                  {                  {
352                          log_error("ssh_handle_key_exchange() error: %s\n", ssh_get_error(SSH_session));                          log_error("ssh_handle_key_exchange() error: %s\n", ssh_get_error(SSH_session));
353                          goto cleanup;                          goto cleanup;
354                  }                  }
                 ssh_set_auth_methods(SSH_session, SSH_AUTH_METHOD_PASSWORD);  
355    
356                  event = ssh_event_new();                  event = ssh_event_new();
357                  ssh_event_add_session(event, SSH_session);                  ssh_event_add_session(event, SSH_session);
# Line 375  static int fork_server(void) Line 376  static int fork_server(void)
376    
377                  ssh_set_channel_callbacks(SSH_channel, &channel_cb);                  ssh_set_channel_callbacks(SSH_channel, &channel_cb);
378    
379                    do
380                    {
381                            ret = ssh_event_dopoll(event, 100); // 0.1 second
382                            if (ret == SSH_ERROR)
383                            {
384                                    ssh_channel_close(SSH_channel);
385                            }
386    
387                            if (ret == SSH_AGAIN) // loop until SSH connection is fully established
388                            {
389                                    /* Executed only once, once the child process starts. */
390                                    cdata.event = event;
391                                    break;
392                            }
393                    } while (ssh_channel_is_open(SSH_channel));
394    
395                  ssh_timeout = 0;                  ssh_timeout = 0;
396                  if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)                  if (ssh_options_set(SSH_session, SSH_OPTIONS_TIMEOUT, &ssh_timeout) < 0)
397                  {                  {
# Line 641  int net_server(const char *hostaddr, in_ Line 658  int net_server(const char *hostaddr, in_
658                                  log_error("Reload conf failed\n");                                  log_error("Reload conf failed\n");
659                          }                          }
660    
661                            // Reload BWF config
662                            if (bwf_load(CONF_BWF) < 0)
663                            {
664                                    log_error("Reload BWF conf failed\n");
665                            }
666    
667                          if (load_menu(&bbs_menu_new, CONF_MENU) < 0)                          if (load_menu(&bbs_menu_new, CONF_MENU) < 0)
668                          {                          {
669                                  unload_menu(&bbs_menu_new);                                  unload_menu(&bbs_menu_new);
# Line 670  int net_server(const char *hostaddr, in_ Line 693  int net_server(const char *hostaddr, in_
693                          {                          {
694                                  if (load_file(data_files_load_startup[i]) < 0)                                  if (load_file(data_files_load_startup[i]) < 0)
695                                  {                                  {
696                                          log_error("load_file_mmap(%s) error\n", data_files_load_startup[i]);                                          log_error("load_file(%s) error\n", data_files_load_startup[i]);
697                                  }                                  }
698                          }                          }
699                          log_common("Reload data files successfully\n");                          log_common("Reload data files successfully\n");


Legend:
Removed lines/characters  
Changed lines/characters
  Added lines/characters

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1