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

Diff of /lbbs/src/login.c

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

Revision 1.74 by sysadm, Tue Dec 2 08:48:05 2025 UTC Revision 1.76 by sysadm, Sun Dec 21 12:45:47 2025 UTC
# Line 155  int check_user(const char *username, con Line 155  int check_user(const char *username, con
155          // Begin transaction          // Begin transaction
156          if (mysql_query(db, "SET autocommit=0") != 0)          if (mysql_query(db, "SET autocommit=0") != 0)
157          {          {
158                  log_error("SET autocommit=0 error: %s\n", mysql_error(db));                  log_error("SET autocommit=0 error: %s", mysql_error(db));
159                  ret = -1;                  ret = -1;
160                  goto cleanup;                  goto cleanup;
161          }          }
162    
163          if (mysql_query(db, "BEGIN") != 0)          if (mysql_query(db, "BEGIN") != 0)
164          {          {
165                  log_error("Begin transaction error: %s\n", mysql_error(db));                  log_error("Begin transaction error: %s", mysql_error(db));
166                  ret = -1;                  ret = -1;
167                  goto cleanup;                  goto cleanup;
168          }          }
# Line 179  int check_user(const char *username, con Line 179  int check_user(const char *username, con
179                           ip_mask(client_addr, 1, '%'));                           ip_mask(client_addr, 1, '%'));
180          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
181          {          {
182                  log_error("Query user_list error: %s\n", mysql_error(db));                  log_error("Query user_list error: %s", mysql_error(db));
183                  ret = -1;                  ret = -1;
184                  goto cleanup;                  goto cleanup;
185          }          }
186          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
187          {          {
188                  log_error("Get user_list data failed\n");                  log_error("Get user_list data failed");
189                  ret = -1;                  ret = -1;
190                  goto cleanup;                  goto cleanup;
191          }          }
# Line 212  int check_user(const char *username, con Line 212  int check_user(const char *username, con
212                           username);                           username);
213          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
214          {          {
215                  log_error("Query user_list error: %s\n", mysql_error(db));                  log_error("Query user_list error: %s", mysql_error(db));
216                  ret = -1;                  ret = -1;
217                  goto cleanup;                  goto cleanup;
218          }          }
219          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
220          {          {
221                  log_error("Get user_list data failed\n");                  log_error("Get user_list data failed");
222                  ret = -1;                  ret = -1;
223                  goto cleanup;                  goto cleanup;
224          }          }
# Line 240  int check_user(const char *username, con Line 240  int check_user(const char *username, con
240                           username, password);                           username, password);
241          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
242          {          {
243                  log_error("Query user_list error: %s\n", mysql_error(db));                  log_error("Query user_list error: %s", mysql_error(db));
244                  ret = -1;                  ret = -1;
245                  goto cleanup;                  goto cleanup;
246          }          }
247          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
248          {          {
249                  log_error("Get user_list data failed\n");                  log_error("Get user_list data failed");
250                  ret = -1;                  ret = -1;
251                  goto cleanup;                  goto cleanup;
252          }          }
# Line 267  int check_user(const char *username, con Line 267  int check_user(const char *username, con
267                                   BBS_uid, hostaddr_client);                                   BBS_uid, hostaddr_client);
268                  if (mysql_query(db, sql) != 0)                  if (mysql_query(db, sql) != 0)
269                  {                  {
270                          log_error("Insert into user_login_log error: %s\n", mysql_error(db));                          log_error("Insert into user_login_log error: %s", mysql_error(db));
271                          ret = -1;                          ret = -1;
272                          goto cleanup;                          goto cleanup;
273                  }                  }
# Line 275  int check_user(const char *username, con Line 275  int check_user(const char *username, con
275                  // Commit transaction                  // Commit transaction
276                  if (mysql_query(db, "COMMIT") != 0)                  if (mysql_query(db, "COMMIT") != 0)
277                  {                  {
278                          log_error("Commit transaction error: %s\n", mysql_error(db));                          log_error("Commit transaction error: %s", mysql_error(db));
279                          ret = -1;                          ret = -1;
280                          goto cleanup;                          goto cleanup;
281                  }                  }
# Line 298  int check_user(const char *username, con Line 298  int check_user(const char *username, con
298                                   username, password, hostaddr_client);                                   username, password, hostaddr_client);
299                  if (mysql_query(db, sql) != 0)                  if (mysql_query(db, sql) != 0)
300                  {                  {
301                          log_error("Insert into user_err_login_log error: %s\n", mysql_error(db));                          log_error("Insert into user_err_login_log error: %s", mysql_error(db));
302                          ret = -1;                          ret = -1;
303                          goto cleanup;                          goto cleanup;
304                  }                  }
# Line 306  int check_user(const char *username, con Line 306  int check_user(const char *username, con
306                  // Commit transaction                  // Commit transaction
307                  if (mysql_query(db, "COMMIT") != 0)                  if (mysql_query(db, "COMMIT") != 0)
308                  {                  {
309                          log_error("Commit transaction error: %s\n", mysql_error(db));                          log_error("Commit transaction error: %s", mysql_error(db));
310                          ret = -1;                          ret = -1;
311                          goto cleanup;                          goto cleanup;
312                  }                  }
# Line 319  int check_user(const char *username, con Line 319  int check_user(const char *username, con
319          // Set AUTOCOMMIT = 1          // Set AUTOCOMMIT = 1
320          if (mysql_query(db, "SET autocommit=1") != 0)          if (mysql_query(db, "SET autocommit=1") != 0)
321          {          {
322                  log_error("SET autocommit=1 error: %s\n", mysql_error(db));                  log_error("SET autocommit=1 error: %s", mysql_error(db));
323                  ret = -1;                  ret = -1;
324                  goto cleanup;                  goto cleanup;
325          }          }
326    
         if (!SSH_v2 && checklevel2(&BBS_priv, P_MAN_S))  
         {  
                 prints("\033[1;31m非普通账户必须使用SSH方式登录\033[m\r\n");  
                 ret = 1;  
                 goto cleanup;  
         }  
   
327          ret = load_user_info(db, BBS_uid);          ret = load_user_info(db, BBS_uid);
328    
329          switch (ret)          switch (ret)
330          {          {
331          case 0: // Login successfully          case 0: // Login successfully
332                    if (!SSH_v2 && checklevel2(&BBS_priv, P_MAN_S))
333                    {
334                            prints("\033[1;31m非普通账户必须使用SSH方式登录\033[m\r\n");
335                            ret = 1;
336                            goto cleanup;
337                    }
338                  break;                  break;
339          case -1: // Load data error          case -1: // Load data error
340                  prints("\033[1;31m读取用户数据错误...\033[m\r\n");                  prints("\033[1;31m读取用户数据错误...\033[m\r\n");
341                  ret = -1;                  ret = -1;
342                  goto cleanup;                  goto cleanup;
343          case -2: // Enforce update user agreement          case -2: // Enforce update user agreement
344                    if (!SSH_v2 && checklevel2(&BBS_priv, P_MAN_S))
345                    {
346                            prints("\033[1;31m非普通账户必须使用SSH方式登录\033[m\r\n");
347                            ret = 1;
348                            goto cleanup;
349                    }
350                  ret = 2;                  ret = 2;
351                  goto cleanup;                  goto cleanup;
352          case -3: // Dead          case -3: // Dead
# Line 359  int check_user(const char *username, con Line 364  int check_user(const char *username, con
364                           BBS_uid);                           BBS_uid);
365          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
366          {          {
367                  log_error("Update user_pubinfo error: %s\n", mysql_error(db));                  log_error("Update user_pubinfo error: %s", mysql_error(db));
368                  ret = -1;                  ret = -1;
369                  goto cleanup;                  goto cleanup;
370          }          }
# Line 381  int check_user(const char *username, con Line 386  int check_user(const char *username, con
386    
387                  if (setenv("TZ", user_tz_env, 1) == -1)                  if (setenv("TZ", user_tz_env, 1) == -1)
388                  {                  {
389                          log_error("setenv(TZ = %s) error %d\n", user_tz_env, errno);                          log_error("setenv(TZ = %s) error %d", user_tz_env, errno);
390                          return -3;                          return -3;
391                  }                  }
392    
# Line 410  int load_user_info(MYSQL *db, int BBS_ui Line 415  int load_user_info(MYSQL *db, int BBS_ui
415                           BBS_uid);                           BBS_uid);
416          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
417          {          {
418                  log_error("Query user_pubinfo error: %s\n", mysql_error(db));                  log_error("Query user_pubinfo error: %s", mysql_error(db));
419                  ret = -1;                  ret = -1;
420                  goto cleanup;                  goto cleanup;
421          }          }
422          if ((rs = mysql_store_result(db)) == NULL)          if ((rs = mysql_store_result(db)) == NULL)
423          {          {
424                  log_error("Get user_pubinfo data failed\n");                  log_error("Get user_pubinfo data failed");
425                  ret = -1;                  ret = -1;
426                  goto cleanup;                  goto cleanup;
427          }          }
# Line 515  int user_online_add(MYSQL *db) Line 520  int user_online_add(MYSQL *db)
520                           hostaddr_client);                           hostaddr_client);
521          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
522          {          {
523                  log_error("Add visit log error: %s\n", mysql_error(db));                  log_error("Add visit log error: %s", mysql_error(db));
524                  return -1;                  return -1;
525          }          }
526    
# Line 530  int user_online_add(MYSQL *db) Line 535  int user_online_add(MYSQL *db)
535                           getpid(), BBS_priv.uid, hostaddr_client);                           getpid(), BBS_priv.uid, hostaddr_client);
536          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
537          {          {
538                  log_error("Add user_online error: %s\n", mysql_error(db));                  log_error("Add user_online error: %s", mysql_error(db));
539                  return -3;                  return -3;
540          }          }
541    
# Line 546  int user_online_del(MYSQL *db) Line 551  int user_online_del(MYSQL *db)
551                           getpid());                           getpid());
552          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
553          {          {
554                  log_error("Delete user_online error: %s\n", mysql_error(db));                  log_error("Delete user_online error: %s", mysql_error(db));
555                  return -1;                  return -1;
556          }          }
557    
# Line 567  int user_online_exp(MYSQL *db) Line 572  int user_online_exp(MYSQL *db)
572                           BBS_priv.uid);                           BBS_priv.uid);
573          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
574          {          {
575                  log_error("Update user_pubinfo error: %s\n", mysql_error(db));                  log_error("Update user_pubinfo error: %s", mysql_error(db));
576                  return -1;                  return -1;
577          }          }
578    
# Line 596  int user_online_update(const char *actio Line 601  int user_online_update(const char *actio
601          db = db_open();          db = db_open();
602          if (db == NULL)          if (db == NULL)
603          {          {
604                  log_error("db_open() error: %s\n", mysql_error(db));                  log_error("db_open() error: %s", mysql_error(db));
605                  return -1;                  return -1;
606          }          }
607    
# Line 606  int user_online_update(const char *actio Line 611  int user_online_update(const char *actio
611                           BBS_current_action, getpid());                           BBS_current_action, getpid());
612          if (mysql_query(db, sql) != 0)          if (mysql_query(db, sql) != 0)
613          {          {
614                  log_error("Update user_online error: %s\n", mysql_error(db));                  log_error("Update user_online error: %s", mysql_error(db));
615                  return -2;                  return -2;
616          }          }
617    
# Line 667  int user_update_agreement(void) Line 672  int user_update_agreement(void)
672                                           BBS_priv.uid);                                           BBS_priv.uid);
673                          if (mysql_query(db, sql) != 0)                          if (mysql_query(db, sql) != 0)
674                          {                          {
675                                  log_error("Update user_pubinfo error: %s\n", mysql_error(db));                                  log_error("Update user_pubinfo error: %s", mysql_error(db));
676                                  ret = -1;                                  ret = -1;
677                                  goto cleanup;                                  goto cleanup;
678                          }                          }


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

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