--- lbbs/src/user_priv.c 2025/04/28 04:23:38 1.6 +++ lbbs/src/user_priv.c 2025/04/28 12:45:57 1.7 @@ -85,53 +85,52 @@ int load_priv(MYSQL *db, BBS_user_priv * if (db == NULL) return 1; - // Admin - sprintf(sql, "select aid,major from admin_config where UID=%ld" - " and enable and (now() between begin_dt and end_dt)", + // Permission + sprintf(sql, "SELECT p_post, p_msg FROM user_list WHERE UID = %ld AND verified", uid); if (mysql_query(db, sql) != 0) { - log_error("Query admin_config failed\n"); + log_error("Query user_list failed\n"); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get admin_config data failed\n"); + log_error("Get user_list data failed\n"); return -1; } if (row = mysql_fetch_row(rs)) { - p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S); - p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN); + p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0); + p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0); } mysql_free_result(rs); - // Permission - sprintf(sql, "select p_post,p_msg,p_mail " - "from user_list where UID=%ld", + // Admin + sprintf(sql, "SELECT major FROM admin_config WHERE UID = %ld " + "AND enable AND (NOW() BETWEEN begin_dt AND end_dt)", uid); if (mysql_query(db, sql) != 0) { - log_error("Query user_list failed\n"); + log_error("Query admin_config failed\n"); return -1; } if ((rs = mysql_store_result(db)) == NULL) { - log_error("Get user_list data failed\n"); + log_error("Get admin_config data failed\n"); return -1; } if (row = mysql_fetch_row(rs)) { - p_priv->g_priv |= (atoi(row[0]) ? S_POST : 0); - p_priv->g_priv |= (atoi(row[1]) ? S_MSG : 0); - p_priv->g_priv |= (atoi(row[2]) ? S_MAIL : 0); + p_priv->level |= (atoi(row[1]) ? P_ADMIN_M : P_ADMIN_S); + p_priv->g_priv |= (atoi(row[1]) ? S_ALL : S_ADMIN); } mysql_free_result(rs); // Section Master - sprintf(sql, "select SID,major from section_master where" - " UID=%ld and enable and (now() between begin_dt and" - " end_dt)", + sprintf(sql, "SELECT section_master.SID, major FROM section_master " + "INNER JOIN section_config ON section_master.SID = section_config.SID " + "WHERE UID = %ld AND section_master.enable AND section_config.enable " + "AND (NOW() BETWEEN begin_dt AND end_dt)", uid); if (mysql_query(db, sql) != 0) { @@ -151,11 +150,10 @@ int load_priv(MYSQL *db, BBS_user_priv * mysql_free_result(rs); // Section status - sprintf(sql, "select SID,exp_get,read_user_level," - "write_user_level from section_config" - " left join section_class on section_config.CID=" - "section_class.CID where section_config.enable and" - " section_class.enable order by SID"); + sprintf(sql, "SELECT SID, exp_get, read_user_level, write_user_level FROM section_config " + "INNER JOIN section_class ON section_config.CID = section_class.CID " + "WHERE section_config.enable AND section_class.enable " + "ORDER BY SID"); if (mysql_query(db, sql) != 0) { log_error("Query section_config failed\n"); @@ -168,47 +166,26 @@ int load_priv(MYSQL *db, BBS_user_priv * } while (row = mysql_fetch_row(rs)) { + int priv = getpriv(p_priv, atoi(row[0])); if (p_priv->level < atoi(row[2])) - setpriv(p_priv, atoi(row[0]), - getpriv(p_priv, atoi(row[0])) & (~S_LIST)); + { + priv &= (~S_LIST); + } if (p_priv->level < atoi(row[3])) - setpriv(p_priv, atoi(row[0]), - getpriv(p_priv, atoi(row[0])) & (~S_POST)); + { + priv &= (~S_POST); + } if (!atoi(row[1])) - setpriv(p_priv, atoi(row[0]), - getpriv(p_priv, atoi(row[0])) & (~S_GETEXP)); - } - mysql_free_result(rs); - - // Section User priv - sprintf(sql, "select SID,`read`,`write` from section_user_priv" - " where UID=%ld order by SID", - uid); - if (mysql_query(db, sql) != 0) - { - log_error("Query section_user_priv failed\n"); - return -1; - } - if ((rs = mysql_store_result(db)) == NULL) - { - log_error("Get section_user_priv data failed\n"); - return -1; - } - while (row = mysql_fetch_row(rs)) - { - setpriv(p_priv, atoi(row[0]), - atoi(row[1]) ? (getpriv(p_priv, atoi(row[0])) | S_LIST) - : (getpriv(p_priv, atoi(row[0])) & ~S_LIST)); - setpriv(p_priv, atoi(row[0]), - atoi(row[2]) ? (getpriv(p_priv, atoi(row[0])) | S_POST) - : (getpriv(p_priv, atoi(row[0])) & ~S_POST)); + { + priv &= (~S_GETEXP); + } + setpriv(p_priv, atoi(row[0]), priv); } mysql_free_result(rs); // Section ban - sprintf(sql, "select SID from ban_user_list where" - " UID=%ld and enable and unban_UID=0 and" - " (now() between ban_dt and unban_dt)", + sprintf(sql, "SELECT SID FROM ban_user_list WHERE UID = %ld AND enable " + "AND (NOW() BETWEEN ban_dt AND unban_dt)", uid); if (mysql_query(db, sql) != 0) {