| 27 |
#include <errno.h> |
#include <errno.h> |
| 28 |
#include <ctype.h> |
#include <ctype.h> |
| 29 |
#include <string.h> |
#include <string.h> |
|
#include <mysql.h> |
|
| 30 |
#include <regex.h> |
#include <regex.h> |
| 31 |
#include <stdlib.h> |
#include <stdlib.h> |
| 32 |
#include <unistd.h> |
#include <unistd.h> |
| 33 |
|
#include <mysql/mysql.h> |
| 34 |
|
|
| 35 |
int bbs_login(MYSQL *db) |
int bbs_login(void) |
| 36 |
{ |
{ |
| 37 |
char username[BBS_username_max_len + 1]; |
char username[BBS_username_max_len + 1]; |
| 38 |
char password[BBS_password_max_len + 1]; |
char password[BBS_password_max_len + 1]; |
| 39 |
int count = 0; |
int i = 0; |
| 40 |
int ok = 0; |
int ok = 0; |
| 41 |
|
|
| 42 |
for (; !SYS_server_exit && !ok && count < 3; count++) |
for (; !SYS_server_exit && !ok && i < BBS_login_retry_times; i++) |
| 43 |
{ |
{ |
| 44 |
prints("\033[1;33m请输入帐号\033[m(试用请输入`\033[1;36mguest\033[m', " |
prints("\033[1;33m请输入帐号\033[m(试用请输入`\033[1;36mguest\033[m', " |
| 45 |
"注册请输入`\033[1;31mnew\033[m'): "); |
"注册请输入`\033[1;31mnew\033[m'): "); |
| 52 |
|
|
| 53 |
if (strcmp(username, "guest") == 0) |
if (strcmp(username, "guest") == 0) |
| 54 |
{ |
{ |
| 55 |
load_guest_info(db); |
load_guest_info(); |
| 56 |
|
|
| 57 |
return 0; |
return 0; |
| 58 |
} |
} |
| 59 |
|
|
| 60 |
if (strcmp(username, "new") == 0) |
if (strcmp(username, "new") == 0) |
| 61 |
{ |
{ |
| 62 |
display_file_ex(DATA_REGISTER, 1, 1); |
display_file(DATA_REGISTER, 1); |
| 63 |
|
|
| 64 |
return 0; |
return 0; |
| 65 |
} |
} |
| 74 |
continue; |
continue; |
| 75 |
} |
} |
| 76 |
|
|
| 77 |
ok = (check_user(db, username, password) == 0); |
ok = (check_user(username, password) == 0); |
| 78 |
iflush(); |
iflush(); |
| 79 |
} |
} |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
if (!ok) |
if (!ok) |
| 83 |
{ |
{ |
| 84 |
display_file_ex(DATA_LOGIN_ERROR, 1, 1); |
display_file(DATA_LOGIN_ERROR, 1); |
| 85 |
return -1; |
return -1; |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
log_std("User \"%s\"(%ld) login from %s:%d\n", |
log_common("User \"%s\"(%ld) login from %s:%d\n", |
| 89 |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
BBS_username, BBS_priv.uid, hostaddr_client, port_client); |
| 90 |
|
|
| 91 |
return 0; |
return 0; |
| 92 |
} |
} |
| 93 |
|
|
| 94 |
int check_user(MYSQL *db, char *username, char *password) |
int check_user(const char *username, const char *password) |
| 95 |
{ |
{ |
| 96 |
MYSQL_RES *rs; |
MYSQL *db = NULL; |
| 97 |
|
MYSQL_RES *rs = NULL; |
| 98 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 99 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 100 |
int ret; |
int ret = 0; |
| 101 |
long BBS_uid = 0; |
int BBS_uid = 0; |
| 102 |
char client_addr[IP_ADDR_LEN]; |
char client_addr[IP_ADDR_LEN]; |
| 103 |
int i; |
int i; |
| 104 |
int ok = 1; |
int ok = 1; |
| 105 |
char user_tz_env[BBS_user_tz_max_len + 2]; |
char user_tz_env[BBS_user_tz_max_len + 2]; |
| 106 |
|
|
| 107 |
|
db = db_open(); |
| 108 |
|
if (db == NULL) |
| 109 |
|
{ |
| 110 |
|
ret = -1; |
| 111 |
|
goto cleanup; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
// Verify format |
// Verify format |
| 115 |
for (i = 0; ok && username[i] != '\0'; i++) |
for (i = 0; ok && username[i] != '\0'; i++) |
| 116 |
{ |
{ |
| 138 |
if (!ok) |
if (!ok) |
| 139 |
{ |
{ |
| 140 |
prints("\033[1;31m用户名或密码格式错误...\033[m\r\n"); |
prints("\033[1;31m用户名或密码格式错误...\033[m\r\n"); |
| 141 |
return 1; |
ret = 1; |
| 142 |
|
goto cleanup; |
| 143 |
} |
} |
| 144 |
|
|
| 145 |
// Begin transaction |
// Begin transaction |
| 146 |
if (mysql_query(db, "SET autocommit=0") != 0) |
if (mysql_query(db, "SET autocommit=0") != 0) |
| 147 |
{ |
{ |
| 148 |
log_error("SET autocommit=0 error: %s\n", mysql_error(db)); |
log_error("SET autocommit=0 error: %s\n", mysql_error(db)); |
| 149 |
return -1; |
ret = -1; |
| 150 |
|
goto cleanup; |
| 151 |
} |
} |
| 152 |
|
|
| 153 |
if (mysql_query(db, "BEGIN") != 0) |
if (mysql_query(db, "BEGIN") != 0) |
| 154 |
{ |
{ |
| 155 |
log_error("Begin transaction error: %s\n", mysql_error(db)); |
log_error("Begin transaction error: %s\n", mysql_error(db)); |
| 156 |
return -1; |
ret = -1; |
| 157 |
|
goto cleanup; |
| 158 |
} |
} |
| 159 |
|
|
| 160 |
// Failed login attempts from the same source (subnet /24) during certain time period |
// Failed login attempts from the same source (subnet /24) during certain time period |
| 163 |
|
|
| 164 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 165 |
"SELECT COUNT(*) AS err_count FROM user_err_login_log " |
"SELECT COUNT(*) AS err_count FROM user_err_login_log " |
| 166 |
"WHERE login_dt >= SUBDATE(NOW(), INTERVAL 10 MINUTE) " |
"WHERE login_dt >= SUBDATE(NOW(), INTERVAL %d MINUTE) " |
| 167 |
"AND login_ip LIKE '%s'", |
"AND login_ip LIKE '%s'", |
| 168 |
|
BBS_login_failures_count_interval, |
| 169 |
ip_mask(client_addr, 1, '%')); |
ip_mask(client_addr, 1, '%')); |
| 170 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 171 |
{ |
{ |
| 172 |
log_error("Query user_list error: %s\n", mysql_error(db)); |
log_error("Query user_list error: %s\n", mysql_error(db)); |
| 173 |
return -1; |
ret = -1; |
| 174 |
|
goto cleanup; |
| 175 |
} |
} |
| 176 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 177 |
{ |
{ |
| 178 |
log_error("Get user_list data failed\n"); |
log_error("Get user_list data failed\n"); |
| 179 |
return -1; |
ret = -1; |
| 180 |
|
goto cleanup; |
| 181 |
} |
} |
| 182 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 183 |
{ |
{ |
| 184 |
if (atoi(row[0]) >= 2) |
if (atoi(row[0]) > BBS_allowed_login_failures_within_interval) |
| 185 |
{ |
{ |
|
mysql_free_result(rs); |
|
|
|
|
| 186 |
prints("\033[1;31m来源存在多次失败登陆尝试,请稍后再试\033[m\r\n"); |
prints("\033[1;31m来源存在多次失败登陆尝试,请稍后再试\033[m\r\n"); |
| 187 |
|
ret = 1; |
| 188 |
return 1; |
goto cleanup; |
| 189 |
} |
} |
| 190 |
} |
} |
| 191 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 192 |
|
rs = NULL; |
| 193 |
|
|
| 194 |
// Failed login attempts against the current username during certain time period |
// Failed login attempts against the current username during certain time period |
| 195 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 199 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 200 |
{ |
{ |
| 201 |
log_error("Query user_list error: %s\n", mysql_error(db)); |
log_error("Query user_list error: %s\n", mysql_error(db)); |
| 202 |
return -1; |
ret = -1; |
| 203 |
|
goto cleanup; |
| 204 |
} |
} |
| 205 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 206 |
{ |
{ |
| 207 |
log_error("Get user_list data failed\n"); |
log_error("Get user_list data failed\n"); |
| 208 |
return -1; |
ret = -1; |
| 209 |
|
goto cleanup; |
| 210 |
} |
} |
| 211 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 212 |
{ |
{ |
| 213 |
if (atoi(row[0]) >= 5) |
if (atoi(row[0]) >= 5) |
| 214 |
{ |
{ |
|
mysql_free_result(rs); |
|
|
|
|
| 215 |
prints("\033[1;31m账户存在多次失败登陆尝试,请使用Web方式登录\033[m\r\n"); |
prints("\033[1;31m账户存在多次失败登陆尝试,请使用Web方式登录\033[m\r\n"); |
| 216 |
|
ret = 1; |
| 217 |
return 1; |
goto cleanup; |
| 218 |
} |
} |
| 219 |
} |
} |
| 220 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 221 |
|
rs = NULL; |
| 222 |
|
|
| 223 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 224 |
"SELECT UID, username, p_login FROM user_list " |
"SELECT UID, username, p_login FROM user_list " |
| 227 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 228 |
{ |
{ |
| 229 |
log_error("Query user_list error: %s\n", mysql_error(db)); |
log_error("Query user_list error: %s\n", mysql_error(db)); |
| 230 |
return -1; |
ret = -1; |
| 231 |
|
goto cleanup; |
| 232 |
} |
} |
| 233 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 234 |
{ |
{ |
| 235 |
log_error("Get user_list data failed\n"); |
log_error("Get user_list data failed\n"); |
| 236 |
return -1; |
ret = -1; |
| 237 |
|
goto cleanup; |
| 238 |
} |
} |
| 239 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 240 |
{ |
{ |
| 241 |
BBS_uid = atol(row[0]); |
BBS_uid = atoi(row[0]); |
| 242 |
strncpy(BBS_username, row[1], sizeof(BBS_username) - 1); |
strncpy(BBS_username, row[1], sizeof(BBS_username) - 1); |
| 243 |
BBS_username[sizeof(BBS_username) - 1] = '\0'; |
BBS_username[sizeof(BBS_username) - 1] = '\0'; |
| 244 |
int p_login = atoi(row[2]); |
int p_login = atoi(row[2]); |
| 245 |
|
|
| 246 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 247 |
|
rs = NULL; |
| 248 |
|
|
| 249 |
// Add user login log |
// Add user login log |
| 250 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 251 |
"INSERT INTO user_login_log(UID, login_dt, login_ip) " |
"INSERT INTO user_login_log(UID, login_dt, login_ip) " |
| 252 |
"VALUES(%ld, NOW(), '%s')", |
"VALUES(%d, NOW(), '%s')", |
| 253 |
BBS_uid, hostaddr_client); |
BBS_uid, hostaddr_client); |
| 254 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 255 |
{ |
{ |
| 256 |
log_error("Insert into user_login_log error: %s\n", mysql_error(db)); |
log_error("Insert into user_login_log error: %s\n", mysql_error(db)); |
| 257 |
return -1; |
ret = -1; |
| 258 |
|
goto cleanup; |
| 259 |
} |
} |
| 260 |
|
|
| 261 |
// Commit transaction |
// Commit transaction |
| 262 |
if (mysql_query(db, "COMMIT") != 0) |
if (mysql_query(db, "COMMIT") != 0) |
| 263 |
{ |
{ |
| 264 |
log_error("Commit transaction error: %s\n", mysql_error(db)); |
log_error("Commit transaction error: %s\n", mysql_error(db)); |
| 265 |
return -1; |
ret = -1; |
| 266 |
|
goto cleanup; |
| 267 |
} |
} |
| 268 |
|
|
| 269 |
if (p_login == 0) |
if (p_login == 0) |
| 270 |
{ |
{ |
|
mysql_free_result(rs); |
|
|
|
|
| 271 |
prints("\033[1;31m您目前无权登陆...\033[m\r\n"); |
prints("\033[1;31m您目前无权登陆...\033[m\r\n"); |
| 272 |
return 1; |
ret = 1; |
| 273 |
|
goto cleanup; |
| 274 |
} |
} |
| 275 |
} |
} |
| 276 |
else |
else |
| 277 |
{ |
{ |
| 278 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 279 |
|
rs = NULL; |
| 280 |
|
|
| 281 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 282 |
"INSERT INTO user_err_login_log(username, password, login_dt, login_ip) " |
"INSERT INTO user_err_login_log(username, password, login_dt, login_ip) " |
| 285 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 286 |
{ |
{ |
| 287 |
log_error("Insert into user_err_login_log error: %s\n", mysql_error(db)); |
log_error("Insert into user_err_login_log error: %s\n", mysql_error(db)); |
| 288 |
return -1; |
ret = -1; |
| 289 |
|
goto cleanup; |
| 290 |
} |
} |
| 291 |
|
|
| 292 |
// Commit transaction |
// Commit transaction |
| 293 |
if (mysql_query(db, "COMMIT") != 0) |
if (mysql_query(db, "COMMIT") != 0) |
| 294 |
{ |
{ |
| 295 |
log_error("Commit transaction error: %s\n", mysql_error(db)); |
log_error("Commit transaction error: %s\n", mysql_error(db)); |
| 296 |
return -1; |
ret = -1; |
| 297 |
|
goto cleanup; |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
prints("\033[1;31m错误的用户名或密码...\033[m\r\n"); |
prints("\033[1;31m错误的用户名或密码...\033[m\r\n"); |
| 301 |
return 1; |
ret = 1; |
| 302 |
|
goto cleanup; |
| 303 |
} |
} |
| 304 |
|
|
| 305 |
// Set AUTOCOMMIT = 1 |
// Set AUTOCOMMIT = 1 |
| 306 |
if (mysql_query(db, "SET autocommit=1") != 0) |
if (mysql_query(db, "SET autocommit=1") != 0) |
| 307 |
{ |
{ |
| 308 |
log_error("SET autocommit=1 error: %s\n", mysql_error(db)); |
log_error("SET autocommit=1 error: %s\n", mysql_error(db)); |
| 309 |
return -1; |
ret = -1; |
| 310 |
|
goto cleanup; |
| 311 |
} |
} |
| 312 |
|
|
| 313 |
ret = load_user_info(db, BBS_uid); |
ret = load_user_info(db, BBS_uid); |
| 318 |
break; |
break; |
| 319 |
case -1: // Load data error |
case -1: // Load data error |
| 320 |
prints("\033[1;31m读取用户数据错误...\033[m\r\n"); |
prints("\033[1;31m读取用户数据错误...\033[m\r\n"); |
| 321 |
return -1; |
ret = -1; |
| 322 |
|
goto cleanup; |
| 323 |
case -2: // Unused |
case -2: // Unused |
| 324 |
prints("\033[1;31m请通过Web登录更新用户许可协议...\033[m\r\n"); |
prints("\033[1;31m请通过Web登录更新用户许可协议...\033[m\r\n"); |
| 325 |
return 1; |
ret = 1; |
| 326 |
|
goto cleanup; |
| 327 |
case -3: // Dead |
case -3: // Dead |
| 328 |
prints("\033[1;31m很遗憾,您已经永远离开了我们的世界!\033[m\r\n"); |
prints("\033[1;31m很遗憾,您已经永远离开了我们的世界!\033[m\r\n"); |
| 329 |
return 1; |
ret = 1; |
| 330 |
|
goto cleanup; |
| 331 |
default: |
default: |
| 332 |
return -2; |
ret = -2; |
| 333 |
|
goto cleanup; |
| 334 |
} |
} |
| 335 |
|
|
| 336 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 337 |
"UPDATE user_pubinfo SET visit_count = visit_count + 1, " |
"UPDATE user_pubinfo SET visit_count = visit_count + 1, " |
| 338 |
"last_login_dt = NOW() WHERE UID = %ld", |
"last_login_dt = NOW() WHERE UID = %d", |
| 339 |
BBS_uid); |
BBS_uid); |
| 340 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 341 |
{ |
{ |
| 342 |
log_error("Update user_pubinfo error: %s\n", mysql_error(db)); |
log_error("Update user_pubinfo error: %s\n", mysql_error(db)); |
| 343 |
return -1; |
ret = -1; |
| 344 |
|
goto cleanup; |
| 345 |
} |
} |
| 346 |
|
|
| 347 |
if (user_online_add(db) != 0) |
if (user_online_add(db) != 0) |
| 348 |
{ |
{ |
| 349 |
return -1; |
ret = -1; |
| 350 |
|
goto cleanup; |
| 351 |
} |
} |
| 352 |
|
|
| 353 |
BBS_last_access_tm = BBS_login_tm = time(0); |
BBS_last_access_tm = BBS_login_tm = time(0); |
| 368 |
tzset(); |
tzset(); |
| 369 |
} |
} |
| 370 |
|
|
| 371 |
return 0; |
cleanup: |
| 372 |
|
mysql_free_result(rs); |
| 373 |
|
mysql_close(db); |
| 374 |
|
|
| 375 |
|
return ret; |
| 376 |
} |
} |
| 377 |
|
|
| 378 |
int load_user_info(MYSQL *db, long int BBS_uid) |
int load_user_info(MYSQL *db, int BBS_uid) |
| 379 |
{ |
{ |
| 380 |
MYSQL_RES *rs; |
MYSQL_RES *rs = NULL; |
| 381 |
MYSQL_ROW row; |
MYSQL_ROW row; |
| 382 |
char sql[SQL_BUFFER_LEN]; |
char sql[SQL_BUFFER_LEN]; |
| 383 |
int life; |
int life; |
| 384 |
time_t last_login_dt; |
time_t last_login_dt; |
| 385 |
|
int ret = 0; |
| 386 |
|
|
| 387 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 388 |
"SELECT life, UNIX_TIMESTAMP(last_login_dt), user_timezone " |
"SELECT life, UNIX_TIMESTAMP(last_login_dt), user_timezone, exp, nickname " |
| 389 |
"FROM user_pubinfo WHERE UID = %ld", |
"FROM user_pubinfo WHERE UID = %d", |
| 390 |
BBS_uid); |
BBS_uid); |
| 391 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 392 |
{ |
{ |
| 393 |
log_error("Query user_pubinfo error: %s\n", mysql_error(db)); |
log_error("Query user_pubinfo error: %s\n", mysql_error(db)); |
| 394 |
return -1; |
ret = -1; |
| 395 |
|
goto cleanup; |
| 396 |
} |
} |
| 397 |
if ((rs = mysql_store_result(db)) == NULL) |
if ((rs = mysql_store_result(db)) == NULL) |
| 398 |
{ |
{ |
| 399 |
log_error("Get user_pubinfo data failed\n"); |
log_error("Get user_pubinfo data failed\n"); |
| 400 |
return -1; |
ret = -1; |
| 401 |
|
goto cleanup; |
| 402 |
} |
} |
| 403 |
if ((row = mysql_fetch_row(rs))) |
if ((row = mysql_fetch_row(rs))) |
| 404 |
{ |
{ |
| 407 |
|
|
| 408 |
strncpy(BBS_user_tz, row[2], sizeof(BBS_user_tz) - 1); |
strncpy(BBS_user_tz, row[2], sizeof(BBS_user_tz) - 1); |
| 409 |
BBS_user_tz[sizeof(BBS_user_tz) - 1] = '\0'; |
BBS_user_tz[sizeof(BBS_user_tz) - 1] = '\0'; |
| 410 |
|
|
| 411 |
|
BBS_user_exp = atoi(row[3]); |
| 412 |
|
|
| 413 |
|
strncpy(BBS_nickname, row[4], sizeof(BBS_nickname)); |
| 414 |
|
BBS_nickname[sizeof(BBS_nickname) - 1] = '\0'; |
| 415 |
} |
} |
| 416 |
else |
else |
| 417 |
{ |
{ |
| 418 |
mysql_free_result(rs); |
ret = -1; // Data not found |
| 419 |
return -1; // Data not found |
goto cleanup; |
| 420 |
} |
} |
| 421 |
mysql_free_result(rs); |
mysql_free_result(rs); |
| 422 |
|
rs = NULL; |
| 423 |
|
|
| 424 |
if (life != 333 && life != 365 && life != 666 && life != 999 && // Not immortal |
if (life != 333 && life != 365 && life != 666 && life != 999 && // Not immortal |
| 425 |
time(0) - last_login_dt > 60 * 60 * 24 * life) |
time(0) - last_login_dt > 60 * 60 * 24 * life) |
| 426 |
{ |
{ |
| 427 |
return -3; // Dead |
ret = -3; // Dead |
| 428 |
|
goto cleanup; |
| 429 |
} |
} |
| 430 |
|
|
| 431 |
if (load_priv(db, &BBS_priv, BBS_uid) != 0) |
if (load_priv(db, &BBS_priv, BBS_uid) != 0) |
| 432 |
{ |
{ |
| 433 |
return -1; |
ret = -1; |
| 434 |
|
goto cleanup; |
| 435 |
} |
} |
| 436 |
|
|
| 437 |
return 0; |
cleanup: |
| 438 |
|
mysql_free_result(rs); |
| 439 |
|
|
| 440 |
|
return ret; |
| 441 |
} |
} |
| 442 |
|
|
| 443 |
int load_guest_info(MYSQL *db) |
int load_guest_info(void) |
| 444 |
{ |
{ |
| 445 |
|
MYSQL *db = NULL; |
| 446 |
|
int ret = 0; |
| 447 |
|
|
| 448 |
|
db = db_open(); |
| 449 |
|
if (db == NULL) |
| 450 |
|
{ |
| 451 |
|
ret = -1; |
| 452 |
|
goto cleanup; |
| 453 |
|
} |
| 454 |
|
|
| 455 |
strncpy(BBS_username, "guest", sizeof(BBS_username) - 1); |
strncpy(BBS_username, "guest", sizeof(BBS_username) - 1); |
| 456 |
BBS_username[sizeof(BBS_username) - 1] = '\0'; |
BBS_username[sizeof(BBS_username) - 1] = '\0'; |
| 457 |
|
|
| 458 |
|
BBS_user_exp = 0; |
| 459 |
|
|
| 460 |
|
strncpy(BBS_nickname, "Guest", sizeof(BBS_nickname)); |
| 461 |
|
BBS_nickname[sizeof(BBS_nickname) - 1] = '\0'; |
| 462 |
|
|
| 463 |
if (load_priv(db, &BBS_priv, 0) != 0) |
if (load_priv(db, &BBS_priv, 0) != 0) |
| 464 |
{ |
{ |
| 465 |
return -1; |
ret = -1; |
| 466 |
|
goto cleanup; |
| 467 |
} |
} |
| 468 |
|
|
| 469 |
if (user_online_add(db) != 0) |
if (user_online_add(db) != 0) |
| 470 |
{ |
{ |
| 471 |
return -1; |
ret = -1; |
| 472 |
|
goto cleanup; |
| 473 |
} |
} |
| 474 |
|
|
| 475 |
BBS_last_access_tm = BBS_login_tm = time(0); |
BBS_last_access_tm = BBS_login_tm = time(0); |
| 476 |
|
|
| 477 |
return 0; |
cleanup: |
| 478 |
|
mysql_close(db); |
| 479 |
|
|
| 480 |
|
return ret; |
| 481 |
} |
} |
| 482 |
|
|
| 483 |
int user_online_add(MYSQL *db) |
int user_online_add(MYSQL *db) |
| 491 |
|
|
| 492 |
snprintf(sql, sizeof(sql), |
snprintf(sql, sizeof(sql), |
| 493 |
"INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) " |
"INSERT INTO user_online(SID, UID, ip, login_tm, last_tm) " |
| 494 |
"VALUES('Telnet_Process_%d', %ld, '%s', NOW(), NOW())", |
"VALUES('Telnet_Process_%d', %d, '%s', NOW(), NOW())", |
| 495 |
getpid(), BBS_priv.uid, hostaddr_client); |
getpid(), BBS_priv.uid, hostaddr_client); |
| 496 |
if (mysql_query(db, sql) != 0) |
if (mysql_query(db, sql) != 0) |
| 497 |
{ |
{ |