Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
杨赫然
e023126793 Adjust size of max_download_dir_size and max_upload_size 2025-02-24 09:53:26 +08:00
feiniks
fde8864542
Return error message when failed to check file access (#737)
* Return error message when failed to check file access

* Update python to 3.12.9

* Update ci python

* Set error_msg to error_str

---------

Co-authored-by: 杨赫然 <heran.yang@seafile.com>
2025-02-14 14:39:19 +08:00
10 changed files with 27 additions and 18 deletions

View file

@ -12,7 +12,7 @@ jobs:
fetch-depth: 1
- uses: actions/setup-python@v1
with:
python-version: "3.12.8"
python-version: "3.12.9"
- name: install dependencies and test
run: |
cd $GITHUB_WORKSPACE

View file

@ -54,7 +54,7 @@ def make_build_env():
_env_add('PATH', join(PREFIX, 'bin'))
if on_github_actions():
_env_add('PYTHONPATH', join(os.environ.get('RUNNER_TOOL_CACHE'), 'Python/3.12.8/x64/lib/python3.12/site-packages'))
_env_add('PYTHONPATH', join(os.environ.get('RUNNER_TOOL_CACHE'), 'Python/3.12.9/x64/lib/python3.12/site-packages'))
_env_add('PYTHONPATH', join(PREFIX, 'lib/python3.12/site-packages'))
_env_add('PKG_CONFIG_PATH', join(PREFIX, 'lib', 'pkgconfig'))
_env_add('PKG_CONFIG_PATH', join(PREFIX, 'lib64', 'pkgconfig'))

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

@ -28,7 +28,6 @@ var (
Host string
Port uint32
MaxUploadSize uint64
MaxDownloadDirSize uint64
FsIdListRequestTimeout int64
// Block size for indexing uploaded files
FixedBlockSize uint64
@ -73,7 +72,6 @@ var (
func initDefaultOptions() {
Host = "0.0.0.0"
Port = 8082
MaxDownloadDirSize = 100 * (1 << 20)
FixedBlockSize = 1 << 23
MaxIndexingThreads = 1
WebTokenExpireTime = 7200
@ -161,7 +159,7 @@ func parseFileServerSection(section *ini.Section) {
if key, err := section.GetKey("max_upload_size"); err == nil {
size, err := key.Uint()
if err == nil {
MaxUploadSize = uint64(size) * (1 << 20)
MaxUploadSize = uint64(size) * 1000000
}
}
if key, err := section.GetKey("max_indexing_threads"); err == nil {

View file

@ -69,15 +69,15 @@ MAX_UPLOAD_FILE_SIZE = None # Defaults to no limit
try:
max_upload_size_mb = int(get_fileserver_option('max_upload_size', 0))
if max_upload_size_mb > 0:
MAX_UPLOAD_FILE_SIZE = max_upload_size_mb * (2 ** 20)
MAX_UPLOAD_FILE_SIZE = max_upload_size_mb * 1000000
except ValueError:
pass
MAX_DOWNLOAD_DIR_SIZE = 100 * (2 ** 20) # Default max size of a downloadable dir
MAX_DOWNLOAD_DIR_SIZE = 100 * 1000000 # Default max size of a downloadable dir
try:
max_download_dir_size_mb = int(get_fileserver_option('max_download_dir_size', 0))
if max_download_dir_size_mb > 0:
MAX_DOWNLOAD_DIR_SIZE = max_download_dir_size_mb * (2 ** 20)
MAX_DOWNLOAD_DIR_SIZE = max_download_dir_size_mb * 1000000
except ValueError:
pass

View file

@ -1496,6 +1496,7 @@ access_v2_cb(evhtp_request_t *req, void *arg)
{
SeafRepo *repo = NULL;
char *error_str = NULL;
char *err_msg = NULL;
char *token = NULL;
char *user = NULL;
char *dec_path = NULL;
@ -1555,9 +1556,15 @@ 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;
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) {
error_str = err_msg;
error_code = status;
} else {
error_str = "Internal server error\n";
error_code = EVHTP_RES_SERVERR;
}
goto out;
}
@ -1633,6 +1640,7 @@ out:
evbuffer_add_printf(req->buffer_out, "%s\n", error_str);
evhtp_send_reply(req, error_code);
}
g_free (err_msg);
}
static int

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

View file

@ -241,7 +241,7 @@ check_tmp_file_list (GList *tmp_files, int *error_code)
max_upload_size = seaf_cfg_manager_get_config_int64 (seaf->cfg_mgr, "fileserver",
"max_upload_size");
if (max_upload_size > 0)
max_upload_size = max_upload_size * ((gint64)1 << 20);
max_upload_size = max_upload_size * 1000000;
else
max_upload_size = -1;

View file

@ -16,7 +16,7 @@
#define MAX_ZIP_THREAD_NUM 5
#define SCAN_PROGRESS_INTERVAL 24 * 3600 // 1 day
#define PROGRESS_TTL 5 * 3600 // 5 hours
#define DEFAULT_MAX_DOWNLOAD_DIR_SIZE 100 * ((gint64)1 << 20) /* 100MB */
#define DEFAULT_MAX_DOWNLOAD_DIR_SIZE 100 * 1000000 /* 100MB */
typedef struct ZipDownloadMgrPriv {
pthread_mutex_t progress_lock;
@ -471,7 +471,7 @@ validate_download_size (DownloadObj *obj, GError **error)
max_download_dir_size = seaf_cfg_manager_get_config_int64 (seaf->cfg_mgr, "fileserver",
"max_download_dir_size");
if (max_download_dir_size > 0)
max_download_dir_size = max_download_dir_size * ((gint64)1 << 20);
max_download_dir_size = max_download_dir_size * 1000000;
else
max_download_dir_size = DEFAULT_MAX_DOWNLOAD_DIR_SIZE;