mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-08-28 19:40:47 +00:00
Return error message when failed to check file access
This commit is contained in:
parent
29829b5dca
commit
a6c7b60b19
@ -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))
|
status, body, err := utils.HttpCommon("POST", url, header, bytes.NewReader(msg))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if status != http.StatusInternalServerError {
|
if status != http.StatusInternalServerError {
|
||||||
msg := "No permission to access file\n"
|
return "", &appError{nil, string(body), status}
|
||||||
return "", &appError{nil, msg, http.StatusForbidden}
|
|
||||||
} else {
|
} else {
|
||||||
err := fmt.Errorf("failed to get access token info: %v", err)
|
err := fmt.Errorf("failed to get access token info: %v", err)
|
||||||
return "", &appError{err, "", http.StatusInternalServerError}
|
return "", &appError{err, "", http.StatusInternalServerError}
|
||||||
|
@ -1555,9 +1555,18 @@ access_v2_cb(evhtp_request_t *req, void *arg)
|
|||||||
error_str = "Both token and cookie are not set\n";
|
error_str = "Both token and cookie are not set\n";
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (http_tx_manager_check_file_access (repo_id, token, cookie, dec_path, "download", ip_addr, user_agent, &user) < 0) {
|
int status = HTTP_OK;
|
||||||
error_str = "No permission to access file\n";
|
char *err_msg = NULL;
|
||||||
error_code = EVHTP_RES_FORBIDDEN;
|
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;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -706,7 +706,8 @@ out:
|
|||||||
int
|
int
|
||||||
http_tx_manager_check_file_access (const char *repo_id, const char *token, const char *cookie,
|
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 *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;
|
Connection *conn = NULL;
|
||||||
char *cookie_header;
|
char *cookie_header;
|
||||||
@ -765,7 +766,9 @@ http_tx_manager_check_file_access (const char *repo_id, const char *token, const
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*status = rsp_status;
|
||||||
if (rsp_status != HTTP_OK) {
|
if (rsp_status != HTTP_OK) {
|
||||||
|
*err_msg = parse_error_message (rsp_content, rsp_size);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -57,5 +57,6 @@ http_tx_manager_query_share_link_info (const char *token, const char *cookie, co
|
|||||||
int
|
int
|
||||||
http_tx_manager_check_file_access (const char *repo_id, const char *token, const char *cookie,
|
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 *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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user