From bcc9c73b9fa61b14221ad62b89ecf31cc38f9f94 Mon Sep 17 00:00:00 2001 From: spiralvoice Date: Tue, 25 Oct 2011 17:40:45 +0000 Subject: [PATCH] patch 7641 --- distrib/ChangeLog | 1 + src/networks/direct_connect/dcClients.ml | 6 +++--- src/networks/direct_connect/dcComplexOptions.ml | 2 +- src/networks/direct_connect/dcGlobals.ml | 20 ++++++++++++-------- src/networks/direct_connect/dcInteractive.ml | 11 ++++++----- src/networks/direct_connect/dcMain.ml | 2 +- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/distrib/ChangeLog b/distrib/ChangeLog index 01ce694f..340df90f 100644 --- a/distrib/ChangeLog +++ b/distrib/ChangeLog @@ -15,6 +15,7 @@ ChangeLog ========= 2011/10/25 +7641: DC: fix ownership for downloads by non-admin users (ygrek) 7593: Less allocations (ygrek) ------------------------------------------------------------------------------- 2011/08/07: version 3.1.0 = tag release-3-1-0 diff --git a/src/networks/direct_connect/dcClients.ml b/src/networks/direct_connect/dcClients.ml index 7829e64d..7bcbba3c 100644 --- a/src/networks/direct_connect/dcClients.ml +++ b/src/networks/direct_connect/dcClients.ml @@ -1203,7 +1203,7 @@ let rec client_reader c t sock = let file_fd = Unix32.create_ro fname in c.client_state <- DcUploadList file_fd; c.client_endpos <- Unix32.getsize64 file_fd; - let file = new_upfile None file_fd in + let file = new_upfile None file_fd (CommonUserDb.admin_user ()) in (* FIXME user? *) c.client_file <- Some file; set_clients_upload c (as_file file.file_file); | DcUploadStarting (dcsh,start_pos,bytes) -> @@ -1218,8 +1218,8 @@ let rec client_reader c t sock = let file_fd = Unix32.create_ro dcsh.dc_shared_fullname in c.client_state <- DcUpload (dcsh,file_fd,start_pos,bytes); c.client_endpos <- endpos; - let file = new_upfile (Some dcsh) file_fd in - c.client_file <- Some file; + let file = new_upfile (Some dcsh) file_fd (CommonUserDb.admin_user ()) in (* FIXME user? *) + c.client_file <- Some file; set_clients_upload c (as_file file.file_file); | _ -> failwith "Wrong client state in Send" ); diff --git a/src/networks/direct_connect/dcComplexOptions.ml b/src/networks/direct_connect/dcComplexOptions.ml index 8451d967..9be6a89e 100644 --- a/src/networks/direct_connect/dcComplexOptions.ml +++ b/src/networks/direct_connect/dcComplexOptions.ml @@ -163,7 +163,7 @@ let value_to_file file_size file_state user group assocs = let f_name = get_value "file_filename" value_to_string in let f_size = get_value "file_size" value_to_int64 in let f_downloaded = get_value "file_downloaded" value_to_int64 in - let f = DcGlobals.new_file f_unchecked_tiger_root f_directory f_name f_size in + let f = DcGlobals.new_file f_unchecked_tiger_root f_directory f_name f_size user group in if (file_downloaded f) <> f_downloaded then failwith "Disk file size don't match downloaded info"; if f_downloaded <> f_size then begin (* check if file is downloaded already *) diff --git a/src/networks/direct_connect/dcGlobals.ml b/src/networks/direct_connect/dcGlobals.ml index 4b4ac119..bcc7e65e 100644 --- a/src/networks/direct_connect/dcGlobals.ml +++ b/src/networks/direct_connect/dcGlobals.ml @@ -471,7 +471,7 @@ let filelist_already_downloading u = let user_has_new_messages user = (List.length user.user_messages) > user.user_read_messages (* file impl for uploading clients *) -let new_upfile dcsh fd = +let new_upfile dcsh fd user = let filename,directory = (match dcsh with | Some dcsh -> @@ -499,11 +499,13 @@ let new_upfile dcsh fd = impl_file_ops = file_ops; impl_file_age = last_time (); impl_file_best_name = filename; + impl_file_owner = user; + impl_file_group = user.user_default_group; } in file (* Return existing file or create new one *) -let new_file tiger_root (directory:string) (filename:string) (file_size:int64) = +let new_file tiger_root (directory:string) (filename:string) (file_size:int64) user group = (try let f = Hashtbl.find dc_files_by_unchecked_hash tiger_root in if !verbose_download then @@ -532,27 +534,29 @@ let new_file tiger_root (directory:string) (filename:string) (file_size:int64) = Int64.zero ) in let rec file = { - file_file = impl; + file_file = impl; file_unchecked_tiger_root = tiger_root; file_directory = directory; file_name = filename; - file_clients = []; + file_clients = []; file_search = None; (*file_tiger_array = [||];*) file_autosearch_count = 0; } and impl = { (dummy_file_impl ()) with - impl_file_fd = Some temp_file; + impl_file_fd = Some temp_file; impl_file_size = file_size; impl_file_downloaded = current_size; - impl_file_received = current_size; + impl_file_received = current_size; impl_file_val = file; impl_file_ops = file_ops; impl_file_age = last_time (); - impl_file_best_name = filename; + impl_file_best_name = filename; + impl_file_owner = user; + impl_file_group = group; } in file_add impl FileNew; (* CommonInteractive.file_add *) - current_files := file :: !current_files; + current_files := file :: !current_files; if tiger_root <> empty_string then Hashtbl.add dc_files_by_unchecked_hash tiger_root file; Hashtbl.add dc_files_by_key key file; if !verbose_download then diff --git a/src/networks/direct_connect/dcInteractive.ml b/src/networks/direct_connect/dcInteractive.ml index d34863c4..59cfb73f 100644 --- a/src/networks/direct_connect/dcInteractive.ml +++ b/src/networks/direct_connect/dcInteractive.ml @@ -54,13 +54,13 @@ let lprintf_nl fmt = lprintf_nl2 log_prefix fmt (* Start new dowload from result *) -let start_new_download u tth fdir fname fsize = +let start_new_download u tth fdir fname fsize user group = try ignore (Hashtbl.find dc_shared_files_by_hash tth); if !verbose_download then lprintf_nl "Shared file with same hash exists (%s) (%s)" fname tth; None with _ -> - let f = new_file tth fdir fname fsize in (* ...create new file *) + let f = new_file tth fdir fname fsize user group in (* ...create new file *) match (file_state f) with | FileDownloaded | FileShared -> if !verbose_download then lprintf_nl "File already downloaded"; None | FileDownloading -> if !verbose_download then lprintf_nl "File being downloaded"; None @@ -82,10 +82,10 @@ let start_new_download u tth fdir fname fsize = Some f (* Start downloading of a file by user selection from resultlist *) -let start_result_download r = +let start_result_download r user group = let filename = List.hd r.result_names in let rinfo = Hashtbl.find dc_result_info r.result_num in - let newfile = start_new_download (Some rinfo.user) rinfo.tth rinfo.directory filename r.result_size in + let newfile = start_new_download (Some rinfo.user) rinfo.tth rinfo.directory filename r.result_size user group in (match newfile with | Some f -> as_file f.file_file (* return CommonFile.file *) | _ -> raise Not_found ) @@ -1020,7 +1020,8 @@ msgWindow.location.reload(); Printf.bprintf buf "Trying to download file: %s from user: %s\n" !sname uname; (try let u = search_user_by_name uname in - ignore (start_new_download (Some u) tth !sdir !sname (Int64.of_string fsize)) + let user = o.conn_user.ui_user in + ignore (start_new_download (Some u) tth !sdir !sname (Int64.of_string fsize) user user.user_default_group) with _ -> if !verbose_download then lprintf_nl "dcloadfile: No user found" ) | _ -> if !verbose_unexpected_messages then diff --git a/src/networks/direct_connect/dcMain.ml b/src/networks/direct_connect/dcMain.ml index 9449d5d7..9d0be128 100644 --- a/src/networks/direct_connect/dcMain.ml +++ b/src/networks/direct_connect/dcMain.ml @@ -216,7 +216,7 @@ let _ = !connected_servers <> [] ); network.op_network_parse_url <- (fun url user group -> DcInteractive.parse_url url user group); - network.op_network_download <- (fun r _ _ -> DcInteractive.start_result_download r); + network.op_network_download <- DcInteractive.start_result_download; network.op_network_ports <- (fun _ -> [ !!dc_port, "client_port TCP+UDP"; -- 2.11.4.GIT