+let write_ft uid ft =
+ let ft_ch = open_out (config_path () ^ "/ft_" ^ uid ^ ".dump") in
+ Marshal.to_channel ft_ch ft [];
+ close_out ft_ch;
+;;
+
+let read_ft uid =
+ try
+ let ft_ch = open_in (config_path () ^ "/ft_" ^ uid ^ ".dump") in
+ let ft = Marshal.from_channel ft_ch in
+ close_in ft_ch;
+ ft
+ with
+ | Sys_error _ ->
+ (* this is an error, we should rebuild the table by a diff of
+ the directory listing and svn stat *)
+ []
+;;
+
+let set_file_flag uid files_flags =
+ let ft = read_ft uid in
+ let files = List.map fst files_flags in
+ let ft = List.filter (fun (x,_) -> not (List.mem x files)) ft in
+ let ft' = List.fold_left (fun acc (filename,flag) ->
+ let filename = MatitaFilesystem.normalize_qfn filename in
+ try
+ (filename,HExtlib.unopt flag)::acc
+ with Failure _ -> acc) [] files_flags
+ in
+ write_ft uid (ft'@ft)
+;;
+
+let add_user uid pw cp =
+ try
+ let _ = lookup_user uid in
+ raise (UsernameCollision uid)
+ with Not_found ->
+ let ft = MatitaFilesystem.checkout uid in
+ (* use a 8 byte salt *)
+ let salt = Cryptokit.Random.string Cryptokit.Random.secure_rng 8 in
+ let sha256 = Cryptokit.Hash.sha256 () in
+ sha256#add_string (salt ^ pw);
+ let crypto_pw = sha256#result in
+ (if cp then
+ user_tbl := (uid,(salt,crypto_pw,None))::!user_tbl
+ else
+ luser_tbl := (uid,(salt,crypto_pw,None))::!luser_tbl);
+ write_ft uid ft;
+ serialize ()
+;;
+
+let add_user_no_checkout uid pw cp =