Beispiel #1
0
        private void cmd_stor_real(string cmd, string p1, bool isappend)
        {
            bool flag = false;
            int  max  = 10000;

            byte[] bf = new byte[max];
            if (p1.Length == 0)
            {
                this.send("500 file name not specified\r\n");
            }
            else
            {
                string       str = this.apply_path(p1);
                string       reason;
                SimpleStream simpleStream = this.files.open(str, false, isappend, out reason);
                if (simpleStream == null)
                {
                    this.send("550 store: open failed {0} {1} mode={2}\r\n", (object)str, (object)reason, isappend ? (object)"Append" : (object)"Write");
                }
                else
                {
                    Ftplink dataLink = this.get_data_link();
                    if (dataLink == null)
                    {
                        return;
                    }
                    if (this.restart != 0L)
                    {
                        simpleStream.seek(this.restart);
                    }
                    this.restart = 0L;
                    int sz;
                    do
                    {
                        sz = dataLink.read_bytes(bf, max, 30000, out bool _, out reason);
                        if (sz <= 0)
                        {
                            goto label_11;
                        }
                    }while (simpleStream.write(bf, 0, sz) == sz);
                    flag = true;
label_11:
                    dataLink.netclose();
                    simpleStream.close();
                    if (flag)
                    {
                        this.send("550 Failed writing data\r\n");
                    }
                    else
                    {
                        this.send("226 Transfer complete {0} stored {1}\r\n", (object)str, isappend ? (object)"Append" : (object)"Write");
                        if (this.files.get_run().Length <= 0)
                        {
                            return;
                        }
                        MyMain.spawn(this.files.get_run(), this.files.apply_profile(str));
                    }
                }
            }
        }
Beispiel #2
0
        public static string digest_passwd(string user, string passwd)
        {
            string sessionkey;

            AuthDigest.digest_ha1(user, MyMain.realm(), passwd, out sessionkey);
            return("{dig}" + sessionkey);
        }
Beispiel #3
0
        private static void CurrentDomain_UnhandledException(
            object sender,
            UnhandledExceptionEventArgs e)
        {
            Exception exceptionObject = e.ExceptionObject as Exception;

            MyMain.record_crash(exceptionObject.Message, exceptionObject.ToString());
        }
Beispiel #4
0
        public static bool check_basic_digest(
            string method_name,
            string hdr,
            out string auth_user,
            out string reason)
        {
            auth_user = "";
            reason    = "";
            if (hdr == null || hdr.Length == 0)
            {
                return(false);
            }
            if (hdr.StartsWith("digest ", StringComparison.OrdinalIgnoreCase))
            {
                auth_user = hdr.get_param("username");
                string user = Vuser.add_domain(auth_user);
                string pass = Vuser.get_pass(user);
                if (pass.Length == 0)
                {
                    reason = "No account or no password set";
                    return(false);
                }
                string sessionkey;
                AuthDigest.digest_ha1(hdr.get_param("username"), MyMain.realm(), pass, out sessionkey);
                string response;
                AuthDigest.digest_response(sessionkey, hdr.get_param("nonce"), hdr.get_param("nc"), hdr.get_param("cnonce"), hdr.get_param("qop"), method_name, hdr.get_param("uri"), "", out response);
                if (response == hdr.get_param("response"))
                {
                    auth_user = user;
                    return(true);
                }
                clib.imsg("Authorization failed {0} {1} {2}", (object)hdr.get_param("username"), (object)response, (object)hdr.get_param("response"));
                reason = "digest didn't match";
                return(false);
            }
            int num = hdr.IndexOf("basic ", StringComparison.OrdinalIgnoreCase);

            if (num >= 0)
            {
                string str    = clib.decode_base64(hdr.Substring(num + 6));
                int    length = str.IndexOf(":");
                if (length < 0)
                {
                    return(false);
                }
                auth_user = str.Substring(0, length);
                string pass = str.Substring(length + 1);
                auth_user = Vuser.add_domain(auth_user);
                return(Vuser.check(auth_user, pass, out reason));
            }
            clib.imsg("NO AUTHENTICATION HEADER");
            return(false);
        }
Beispiel #5
0
        public static int Main(string[] args)
        {
            foreach (string str in args)
            {
                if (str == "-debug")
                {
                    MyMain.set_debug(true);
                }
            }
            string str1;
            string str2;

            if (!clib.IsLinux)
            {
                str1           = "/" + clib.Product_Name();
                clib.root_path = "\\ftpusers";
                str2           = str1 + "\\log";
            }
            else
            {
                str1           = "/var/ftpdav";
                clib.root_path = "/home/ftpusers";
                str2           = str1 + "/log";
            }
            Directory.CreateDirectory(str1);
            Directory.CreateDirectory(str2);
            if (!clib.IsLinux)
            {
                Directory.SetCurrentDirectory(clib.app("."));
            }
            clib.set_work(str1);
            clib.set_log(str2);
            if (clib.IsLinux)
            {
                MyMain.console_main(true);
                return(0);
            }
            if (!Environment.UserInteractive)
            {
                ProgramPlatform.svc_main();
            }
            else
            {
                MyMain.console_main(true);
            }
            return(0);
        }
Beispiel #6
0
        public static void need_auth(Websvc w)
        {
            Random random = new Random();

            byte[] numArray = new byte[10];
            random.NextBytes(numArray);
            Web.any_header(w, "text/plain", "401 Authorization required");
            Web.wh(w, "WWW-Authenticate: Basic realm=\"{0}\"\r\n", (object)MyMain.realm());
            Web.wh(w, "WWW-Authenticate: Digest");
            Web.wh(w, " realm=\"{0}\",", (object)MyMain.realm());
            Web.wh(w, " qop=\"auth\",");
            Web.wh(w, " nonce=\"{0}\",", (object)clib.byte_to_hex(numArray, ((IEnumerable <byte>)numArray).Count <byte>()));
            Web.wh(w, " opaque=\"placeholder\"\r\n");
            Web.wp(w, "Authorization required");
            w.body_send();
            if (!Ini.istrue(En.debug_http))
            {
                return;
            }
            clib.imsg("http: requesting authentication");
        }
Beispiel #7
0
        public static void console_main(bool block)
        {
            MyMain.start_time = DateTime.Now;
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyMain.CurrentDomain_UnhandledException);
            Timer timer = new Timer(new TimerCallback(MyMain.tsecond_Elapsed), (object)null, 0, 1000);

            clib.init_log_files();
            clib.set_debug(true);
            clib.imsg("Logging home {0}", (object)clib.log_file("imsg.log"));
            clib.imsg("Starting FTPDAV Version {0} Build {1}", (object)clib.Version(), (object)clib.Build());
            clib.startstop("Starting FTPDAV Version {0} {1}", (object)clib.Version(), (object)clib.Build());
            Ini.init(clib.work("config.ini"));
            clib.set_debug(MyMain.main_debug);
            clib.log_idle();
            Quota.init();
            clib.set_tmp(clib.work("tmp"));
            Directory.CreateDirectory(clib.tmp());
            Directory.CreateDirectory(clib.work("userdb"));
            Directory.CreateDirectory(clib.work("spawn"));
            Directory.CreateDirectory(clib.work("log"));
            Vuser.init(clib.work("userdb"));
            Link.set_paths(clib.work(""), clib.app(""));
            Profile.load();
            SimpleHash.unit_test();
            Link.set_ssl_password(Ini.getstring(En.ssl_password));
            clib.set_debug(true);
            MyMain.startListeners();
            if (!MyMain.main_debug)
            {
                clib.imsg("Going quiet now as no -debug switch on command line...");
            }
            clib.set_debug(MyMain.main_debug);
            MyKey.init(clib.work("key.dat"));
            try
            {
                File.Delete(clib.work("ftpdav.exit"));
            }
            catch
            {
                clib.imsg("FAILED TO DELETE FTPDAV.EXIT");
            }
            if (!block)
            {
                return;
            }
            while (true)
            {
                try
                {
                    File.WriteAllText(clib.work("main.running"), "running");
                    if (File.Exists(clib.work("ftpdav.exit")))
                    {
                        clib.imsg("Exiting because ftpdav.exit found");
                        try
                        {
                            File.Delete(clib.work("ftpdav.exit"));
                            goto label_18;
                        }
                        catch (Exception ex)
                        {
                            clib.imsg("Delete failed {0}", (object)ex.Message);
                            goto label_18;
                        }
                    }
                }
                catch
                {
                }
                Thread.Sleep(1000);
                if (!MyMain.shutdown)
                {
                    if (clib.time() - MyMain.last > 60)
                    {
                        MyMain.last = clib.time();
                        Quota.save();
                    }
                }
                else
                {
                    break;
                }
            }
            clib.imsg("Exiting because shutdown flag true");
label_18:
            File.Delete(clib.work("main.running"));
            clib.imsg("Key pressed or ftpdav.exit found ==============================");
            Quota.save();
            clib.startstop("Clean shutdown FTPDAV Version {0}", (object)clib.Version());
        }
Beispiel #8
0
 public static void console_main()
 {
     MyMain.console_main(true);
 }
Beispiel #9
0
        private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
        {
            Exception exception = e.Exception;

            MyMain.record_crash(exception.Message, exception.ToString());
        }