1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-05-12 02:01:34 +00:00

Return error message when failed to check file access

This commit is contained in:
杨赫然 2025-02-13 15:22:31 +08:00
parent 29829b5dca
commit a6c7b60b19
4 changed files with 19 additions and 7 deletions

View File

@ -372,8 +372,7 @@ func checkFileAccess(repoID, token, cookie, filePath, op, ipAddr, userAgent stri
status, body, err := utils.HttpCommon("POST", url, header, bytes.NewReader(msg))
if err != nil {
if status != http.StatusInternalServerError {
msg := "No permission to access file\n"
return "", &appError{nil, msg, http.StatusForbidden}
return "", &appError{nil, string(body), status}
} else {
err := fmt.Errorf("failed to get access token info: %v", err)
return "", &appError{err, "", http.StatusInternalServerError}

View File

@ -1555,9 +1555,18 @@ access_v2_cb(evhtp_request_t *req, void *arg)
error_str = "Both token and cookie are not set\n";
goto out;
}
if (http_tx_manager_check_file_access (repo_id, token, cookie, dec_path, "download", ip_addr, user_agent, &user) < 0) {
error_str = "No permission to access file\n";
error_code = EVHTP_RES_FORBIDDEN;
int status = HTTP_OK;
char *err_msg = NULL;
if (http_tx_manager_check_file_access (repo_id, token, cookie, dec_path, "download", ip_addr, user_agent, &user, &status, &err_msg) < 0) {
if (status != HTTP_OK) {
evbuffer_add_printf(req->buffer_out, "%s\n", err_msg);
evhtp_send_reply(req, status);
error_code = EVHTP_RES_OK;
} else {
error_str = "Internal server error\n";
error_code = EVHTP_RES_SERVERR;
}
g_free (err_msg);
goto out;
}

View File

@ -706,7 +706,8 @@ out:
int
http_tx_manager_check_file_access (const char *repo_id, const char *token, const char *cookie,
const char *path, const char *op, const char *ip_addr,
const char *user_agent, char **user)
const char *user_agent, char **user,
int *status, char **err_msg)
{
Connection *conn = NULL;
char *cookie_header;
@ -765,7 +766,9 @@ http_tx_manager_check_file_access (const char *repo_id, const char *token, const
goto out;
}
*status = rsp_status;
if (rsp_status != HTTP_OK) {
*err_msg = parse_error_message (rsp_content, rsp_size);
ret = -1;
goto out;
}

View File

@ -57,5 +57,6 @@ http_tx_manager_query_share_link_info (const char *token, const char *cookie, co
int
http_tx_manager_check_file_access (const char *repo_id, const char *token, const char *cookie,
const char *path, const char *op, const char *ip_addr,
const char *user_agent, char **user);
const char *user_agent, char **user,
int *status, char **err_msg);
#endif