/[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.112 by sysadm, Fri Dec 19 06:16:27 2025 UTC Revision 1.116 by sysadm, Wed Jan 7 14:37:55 2026 UTC
# Line 3  Line 3 
3   * net_server   * net_server
4   *   - network server with SSH support   *   - network server with SSH support
5   *   *
6   * Copyright (C) 2004-2025  Leaflet <leaflet@leafok.com>   * Copyright (C) 2004-2026  Leaflet <leaflet@leafok.com>
7   */   */
8    
9  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
# Line 56  Line 56 
56    
57  enum _net_server_constant_t  enum _net_server_constant_t
58  {  {
59            SOCKET_LISTEN_BACKLOG = 20,
60          WAIT_CHILD_PROCESS_EXIT_TIMEOUT = 5, // second          WAIT_CHILD_PROCESS_EXIT_TIMEOUT = 5, // second
61          WAIT_CHILD_PROCESS_KILL_TIMEOUT = 1, // second          WAIT_CHILD_PROCESS_KILL_TIMEOUT = 1, // second
62    
# Line 124  static int auth_password(ssh_session ses Line 125  static int auth_password(ssh_session ses
125    
126          if (ret == 0)          if (ret == 0)
127          {          {
128                    log_common("User [%s] authenticated successfully", user);
129                  return SSH_AUTH_SUCCESS;                  return SSH_AUTH_SUCCESS;
130          }          }
131    
# Line 132  static int auth_password(ssh_session ses Line 134  static int auth_password(ssh_session ses
134                  sdata->error = 1;                  sdata->error = 1;
135          }          }
136    
137            log_common("User [%s] authentication failed (%d/%d)", user,
138                              sdata->tries, BBS_login_retry_times);
139          return SSH_AUTH_DENIED;          return SSH_AUTH_DENIED;
140  }  }
141    
# Line 518  int net_server(const char *hostaddr, in_ Line 522  int net_server(const char *hostaddr, in_
522          int ret;          int ret;
523          int flags_server[2];          int flags_server[2];
524          struct sockaddr_in sin;          struct sockaddr_in sin;
525            char local_addr[INET_ADDRSTRLEN];
526    
527  #ifdef HAVE_SYS_EPOLL_H  #ifdef HAVE_SYS_EPOLL_H
528          struct epoll_event ev, events[MAX_EVENTS];          struct epoll_event ev, events[MAX_EVENTS];
# Line 606  int net_server(const char *hostaddr, in_ Line 611  int net_server(const char *hostaddr, in_
611                  sin.sin_addr.s_addr = (hostaddr[0] != '\0' ? inet_addr(hostaddr) : INADDR_ANY);                  sin.sin_addr.s_addr = (hostaddr[0] != '\0' ? inet_addr(hostaddr) : INADDR_ANY);
612                  sin.sin_port = htons(port[i]);                  sin.sin_port = htons(port[i]);
613    
614                    if (inet_ntop(AF_INET, &(sin.sin_addr), local_addr, sizeof(local_addr)) == NULL)
615                    {
616                            log_error("inet_ntop() error (%d)", errno);
617                            return -1;
618                    }
619    
620                  // Reuse address and port                  // Reuse address and port
621                  flags_server[i] = 1;                  flags_server[i] = 1;
622                  if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEADDR, &flags_server[i], sizeof(flags_server[i])) < 0)                  if (setsockopt(socket_server[i], SOL_SOCKET, SO_REUSEADDR, &flags_server[i], sizeof(flags_server[i])) < 0)
# Line 622  int net_server(const char *hostaddr, in_ Line 633  int net_server(const char *hostaddr, in_
633                  if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0)                  if (bind(socket_server[i], (struct sockaddr *)&sin, sizeof(sin)) < 0)
634                  {                  {
635                          log_error("Bind address %s:%u error (%d)",                          log_error("Bind address %s:%u error (%d)",
636                                            inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), errno);                                            local_addr, port[i], errno);
637                          return -1;                          return -1;
638                  }                  }
639    
640                  if (listen(socket_server[i], 10) < 0)                  if (listen(socket_server[i], SOCKET_LISTEN_BACKLOG) < 0)
641                  {                  {
642                          log_error("Telnet socket listen error (%d)", errno);                          log_error("Telnet socket listen error (%d)", errno);
643                          return -1;                          return -1;
644                  }                  }
645    
646                  log_common("Listening at %s:%u", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));                  log_common("Listening at %s:%u", local_addr, port[i]);
647    
648  #ifdef HAVE_SYS_EPOLL_H  #ifdef HAVE_SYS_EPOLL_H
649                  ev.events = EPOLLIN;                  ev.events = EPOLLIN;
# Line 790  int net_server(const char *hostaddr, in_ Line 801  int net_server(const char *hostaddr, in_
801  #endif  #endif
802    
803                          log_common("Reload configuration");                          log_common("Reload configuration");
804                            
805                          // Restart log                          // Restart log
806                          if (log_restart() < 0)                          if (log_restart() < 0)
807                          {                          {
# Line 931  int net_server(const char *hostaddr, in_ Line 942  int net_server(const char *hostaddr, in_
942                                                  }                                                  }
943                                          }                                          }
944    
945                                          strncpy(hostaddr_client, inet_ntoa(sin.sin_addr), sizeof(hostaddr_client) - 1);                                          if (inet_ntop(AF_INET, &(sin.sin_addr), hostaddr_client, sizeof(hostaddr_client)) == NULL)
946                                          hostaddr_client[sizeof(hostaddr_client) - 1] = '\0';                                          {
947                                                    log_error("inet_ntop() error (%d)", errno);
948                                                    close(socket_client);
949                                                    break;
950                                            }
951                                          port_client = ntohs(sin.sin_port);                                          port_client = ntohs(sin.sin_port);
952    
953                                          if (SYS_child_process_count - 1 < BBS_max_client)                                          if (SYS_child_process_count - 1 < BBS_max_client)


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

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