public static bool add( string user, string passwd, NameValueCollection info, out string reason, string oldpass) { if (Vuser.total > 5 && Vuser.total > MyKey.ulimit_max()) { reason = "Sorry license user limit reached"; return(false); } if (!Vuser.valid_user(user, out reason)) { return(false); } User user1 = UserDb.lookup(user); bool flag = UserDb.add(user, passwd, info, user1 == null ? "" : user1.passwd, out reason); if (flag && user1 == null) { Vuser.total_add(1); } return(flag); }
public static bool delete(string user) { bool flag = UserDb.delete(user); if (flag) { Vuser.total_add(-1); } return(flag); }
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); }
private void cmd_pass(string cmd, string p1) { string reason; if (!Vuser.check(this.user, p1, out reason)) { this.send("530 {0}\r\n", (object)reason); } else { this.send("230 User logged in\r\n"); this.isloggedin = true; this.files = new Files(); this.files.set_profile(this.user, "", 0L); this.files.show_aliases(); } }
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()); }
public bool save(out string reason) { return(Vuser.add(this.user, "", this.info, out reason, "")); }
private void cmd_user(string cmd, string p1) { this.user = Vuser.add_domain(p1); this.isloggedin = false; this.send("331 username ok, need password\r\n"); }
public static void total_add(int x) { Vuser.total += x; Vuser.total_write(); }
public static bool check(string user, string pass, out string reason) { bool flag1 = false; reason = "user doesn't exist or invalid password"; bool flag2 = UserDb.check(user, pass); if (flag2) { User user1 = UserDb.lookup(user); flag1 = user1.isadmin(); switch (user1.info["status"]) { case "pending": reason = "Sorry you must activate using the token from your email first"; return(false); default: string stuff = user1.info["cached"]; if (stuff != null && stuff.Length > 0) { clib.imsg("found cached life of {0}", (object)stuff); if (clib.time() > clib.atoi(stuff)) { clib.imsg("EXPIRED, MAKE HIM CHECK AGAIN age {0} {1}", (object)(clib.time() - clib.atoi(stuff)), (object)stuff); flag2 = false; } } break; } } if (!flag1 && !Vuser.valid_user(user, out reason)) { return(false); } if (!flag2) { string dest = Ini.getstring(En.auth_imap); if (dest.Length > 0) { Imap imap = new Imap(); clib.imsg("auth_imap {0} {1}", (object)user, (object)dest); string result; if (imap.login(dest, 143, "nossl", user, pass, out result)) { NameValueCollection info = new NameValueCollection(); User user1 = UserDb.lookup(user); if (user1 != null && user1.info != null) { info = user1.info; } info.Set("cached", clib.int_to_string(clib.time() + 604800)); clib.imsg("Imap: login worked for that user/pass {0}", (object)user); string reason1; if (!UserDb.add(user, pass, info, "", out reason1)) { clib.imsg("cacheadd: {0}", (object)reason1); } imap.netclose(); flag2 = true; } else { clib.imsg("imap: login failed on remost host {0}", (object)result); } } } return(flag2); }