public void ReentrantConstructors () { ArrayList user_ids = new ArrayList (4); IList users = UnixUserInfo.GetLocalUsers (); foreach (UnixUserInfo user in users) { try { UnixUserInfo byName = new UnixUserInfo (user.UserName); Assert.AreEqual (user, byName, "#TRC: construct by name"); if (! user_ids.Contains (user.UserId)) user_ids.Add (user.UserId); } catch (Exception e) { Assert.Fail ( string.Format ("#TRC: Exception constructing UnixUserInfo (string): {0}", e.ToString())); } } foreach (uint uid in user_ids) { try { UnixUserInfo byId = new UnixUserInfo (uid); Assert.IsTrue (users.Contains (byId), "TRC: construct by uid"); } catch (Exception e) { Assert.Fail ( string.Format ("#TRC: Exception constructing UnixUserInfo (uint): {0}", e.ToString())); } } }
public static void DropRoot(String username, ILogger <BackgroundService> logger) { Mono.Unix.UnixUserInfo unixUser = null; try { unixUser = new UnixUserInfo(username); logger.LogDebug("Target user ID is: " + unixUser.UserId); if (Mono.Unix.Native.Syscall.getuid() == 0) { // we're root, we need to drop privileges Mono.Unix.Native.Syscall.setuid((uint)unixUser.UserId); logger.LogDebug("Dropping root privileges for process. Setting process uid to " + unixUser.UserId); } else { logger.LogDebug("We're not root, we cannot change user id."); } } catch (ArgumentException e) { logger.LogCritical("User " + username + " does not exist. Cannot change user id. Exiting."); Environment.Exit(1); } catch (Exception e) { logger.LogCritical(e.Message); Environment.Exit(1); } }
static uint GetUid (string user) { var info = new UnixUserInfo (user); long uid = info.UserId; if (uid > UInt32.MaxValue || uid <= 0) throw new ArgumentOutOfRangeException ("user", String.Format ("Uid for {0} ({1}) not in range for suid", user, uid)); return (uint)uid; }
public void SetOwner(UnixUserInfo owner) { long uid, gid; uid = gid = -1; if (owner != null) { uid = owner.UserId; gid = owner.GroupId; } SetOwner(uid, gid); }
public Conf() { // initialises variables // _homedir = Environment.GetEnvironmentVariable ("HOME") + "/.MonoGnomeArt/"; // Recovers path of the personal repertory of the user long CurrentUserID = UnixEnvironment.RealUserId; UnixUserInfo CurrentUser = new UnixUserInfo (CurrentUserID); _homedir = CurrentUser.HomeDirectory + "/.MonoGnomeArt/"; Console.WriteLine(_homedir); // create home dirs if they not exists create_home_dirs (); }
public void SetOwner(UnixUserInfo owner) { long num = (long)-1; long groupId = num; long userId = num; if (owner != null) { userId = owner.UserId; groupId = owner.GroupId; } this.SetOwner(userId, groupId); }
public void SetOwner(UnixUserInfo owner, UnixGroupInfo group) { long uid, gid; uid = gid = -1; if (owner != null) { uid = owner.UserId; } if (group != null) { gid = owner.GroupId; } SetOwner(uid, gid); }
public void SetOwner(string owner, string group) { long uid = -1; if (owner != null) { uid = new UnixUserInfo(owner).UserId; } long gid = -1; if (group != null) { gid = new UnixGroupInfo(group).GroupId; } SetOwner(uid, gid); }
// Gets the user's name, example: "User Name" public string GetUserName() { string user_name; Process process = new Process (); process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = "git"; process.StartInfo.WorkingDirectory = LocalPath; process.StartInfo.Arguments = "config --get user.name"; process.Start (); user_name = process.StandardOutput.ReadToEnd ().Trim (); if (user_name.Equals ("")) { UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName); if (unix_user_info.RealName.Equals ("")) user_name = "Mysterious Stranger"; else user_name = unix_user_info.RealName; } return user_name; }
public void ShowAccountForm() { Reset (); Header = "Welcome to SparkleShare!"; Description = "Before we can create a SparkleShare folder on this " + "computer, we need some information from you."; UserInfoForm = new NSForm (new RectangleF (250, 115, 350, 64)); UserInfoForm.AddEntry ("Full Name:"); UserInfoForm.AddEntry ("Email Address:"); UserInfoForm.CellSize = new SizeF (280, 22); UserInfoForm.IntercellSpacing = new SizeF (4, 4); string full_name = new UnixUserInfo (UnixEnvironment.UserName).RealName; if (string.IsNullOrEmpty (full_name)) full_name = ""; UserInfoForm.Cells [0].StringValue = full_name.TrimEnd (",".ToCharArray());; UserInfoForm.Cells [1].StringValue = SparkleShare.Controller.UserEmail; ContinueButton = new NSButton () { Title = "Continue", Enabled = false }; ContinueButton.Activated += delegate { SparkleShare.Controller.UserName = UserInfoForm.Cells [0].StringValue.Trim (); SparkleShare.Controller.UserEmail = UserInfoForm.Cells [1].StringValue.Trim (); SparkleShare.Controller.GenerateKeyPair (); SparkleShare.Controller.FirstRun = false; InvokeOnMainThread (delegate { ShowServerForm (); }); }; // TODO: Ugly hack, do properly with events Timer timer = new Timer () { Interval = 50 }; timer.Elapsed += delegate { InvokeOnMainThread (delegate { bool name_is_correct = !UserInfoForm.Cells [0].StringValue.Trim ().Equals (""); bool email_is_correct = SparkleShare.Controller.IsValidEmail (UserInfoForm.Cells [1].StringValue.Trim ()); ContinueButton.Enabled = (name_is_correct && email_is_correct); }); }; timer.Start (); ContentView.AddSubview (UserInfoForm); Buttons.Add (ContinueButton); ShowAll (); }
public UnixUserInfo(Passwd passwd) { this.passwd = UnixUserInfo.CopyPasswd(passwd); }
public void ShowAccountForm() { Reset (); VBox layout_vertical = new VBox (false, 0); DeleteEvent += PreventClose; Label header = new Label ("<span size='x-large'><b>" + _("Welcome to SparkleShare!") + "</b></span>") { UseMarkup = true, Xalign = 0 }; Label information = new Label (_("Before we can create a SparkleShare folder on this " + "computer, we need a few bits of information from you.")) { Xalign = 0, Wrap = true }; Table table = new Table (4, 2, true) { RowSpacing = 6 }; UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName); Label name_label = new Label ("<b>" + _("Full Name:") + "</b>") { UseMarkup = true, Xalign = 0 }; NameEntry = new Entry (unix_user_info.RealName); NameEntry.Changed += delegate { CheckAccountForm (); }; EmailEntry = new Entry (SparkleShare.Controller.UserEmail); EmailEntry.Changed += delegate { CheckAccountForm (); }; Label email_label = new Label ("<b>" + _("Email:") + "</b>") { UseMarkup = true, Xalign = 0 }; table.Attach (name_label, 0, 1, 0, 1); table.Attach (NameEntry, 1, 2, 0, 1); table.Attach (email_label, 0, 1, 1, 2); table.Attach (EmailEntry, 1, 2, 1, 2); NextButton = new Button (_("Next")) { Sensitive = false }; NextButton.Clicked += delegate (object o, EventArgs args) { NextButton.Remove (NextButton.Child); NextButton.Add (new Label (_("Configuring…"))); NextButton.Sensitive = false; table.Sensitive = false; NextButton.ShowAll (); SparkleShare.Controller.UserName = NameEntry.Text; SparkleShare.Controller.UserEmail = EmailEntry.Text; SparkleShare.Controller.GenerateKeyPair (); SparkleShare.Controller.AddKey (); SparkleShare.Controller.FirstRun = false; DeleteEvent += PreventClose; ShowServerForm (); }; AddButton (NextButton); layout_vertical.PackStart (header, false, false, 0); layout_vertical.PackStart (information, false, false, 21); layout_vertical.PackStart (new Label (""), false, false, 0); layout_vertical.PackStart (table, false, false, 0); Add (layout_vertical); CheckAccountForm (); ShowAll (); }
public void SetOwner(string user, string group) { AssertNotDisposed (); long uid = new UnixUserInfo (user).UserId; long gid = new UnixGroupInfo (group).GroupId; SetOwner (uid, gid); }
public static void Main(string [] args) { // Use translations Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR); UnixUserInfo user_info = new UnixUserInfo (UnixEnvironment.UserName); // Don't allow running as root if (user_info.UserId == 0) { Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions.")); Console.WriteLine (_("Things would go utterly wrong.")); Environment.Exit (0); } bool hide_ui = false; bool show_help = false; var p = new OptionSet () { { "d|disable-gui", _("Don't show the notification icon"), v => hide_ui = v != null }, { "v|version", _("Show this help text"), v => { PrintVersion (); } }, { "h|help", _("Print version information"), v => show_help = v != null } }; try { p.Parse (args); } catch (OptionException e) { Console.Write ("SparkleShare: "); Console.WriteLine (e.Message); Console.WriteLine ("Try `sparkleshare --help' for more information."); } if (show_help) ShowHelp (p); Controller = new SparkleController (); if (!hide_ui){ UI = new SparkleUI (); UI.Run (); } }
public FaceCollection() { UnixUserInfo unix_user_info = new UnixUserInfo (UnixEnvironment.UserName); string default_theme_path = CombineMore (unix_user_info.HomeDirectory, ".icons"); new FaceCollection (default_theme_path); }
public Passwd ToPasswd() { return(UnixUserInfo.CopyPasswd(this.passwd)); }
public static UnixUserInfo GetRealUser() { return(new UnixUserInfo(UnixUserInfo.GetRealUserId())); }
[Category ("AndroidNotWorking")] // setpwent is missing from bionic public void NonReentrantSyscalls () { ArrayList user_ids = new ArrayList (4); IList users = UnixUserInfo.GetLocalUsers (); foreach (UnixUserInfo user in users) { try { Passwd byName = Syscall.getpwnam (user.UserName); Assert.IsNotNull (byName, "#TNRS: access by name"); UnixUserInfo n = new UnixUserInfo (byName); Assert.AreEqual (user, n, "#TNRS: construct by name"); if (! user_ids.Contains (user.UserId)) user_ids.Add (user.UserId); } catch (Exception e) { Assert.Fail ( string.Format ("#TNRS: Exception constructing UnixUserInfo (string): {0}", e.ToString())); } } foreach (long uid in user_ids) { try { Passwd byId = Syscall.getpwuid (Convert.ToUInt32 (uid)); Assert.IsNotNull (byId, "#TNRS: access by uid"); UnixUserInfo u = new UnixUserInfo (byId); Assert.IsTrue (users.Contains (u), "TNRS: construct by uid"); } catch (Exception e) { Assert.Fail ( string.Format ("#TNRS: Exception constructing UnixUserInfo (uint): {0}", e.ToString())); } } }
public void SetOwner(UnixUserInfo owner) { long uid, gid; uid = gid = -1; if (owner != null) { uid = owner.UserId; gid = owner.GroupId; } SetOwner (uid, gid); }
public static void Main(string [] args) { // Use translations Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR); // Check whether git is installed Process process = new Process (); process.StartInfo.FileName = "git"; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.Start (); if (process.StandardOutput.ReadToEnd ().IndexOf ("version") == -1) { Console.WriteLine (_("Git wasn't found.")); Console.WriteLine (_("You can get Git from http://git-scm.com/.")); Environment.Exit (0); } UnixUserInfo user_info = new UnixUserInfo (UnixEnvironment.UserName); // Don't allow running as root if (user_info.UserId == 0) { Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions.")); Console.WriteLine (_("Things would go utterly wrong.")); Environment.Exit (0); } bool HideUI = false; bool ShowHelp = false; var p = new OptionSet () { { "d|disable-gui", _("Don't show the notification icon"), v => HideUI = v != null }, { "v|version", _("Show this help text"), v => { PrintVersion (); Environment.Exit (0); } }, { "h|help", _("Print version information"), v=> ShowHelp = v != null } }; try { p.Parse (args); } catch (OptionException e) { Console.Write ("SparkleShare: "); Console.WriteLine (e.Message); Console.WriteLine ("Try `sparkleshare --help' for more information."); } if (ShowHelp) DisplayHelp(p); SparkleUI = new SparkleUI (HideUI); SparkleUI.Run(); }
public void SetOwner(string owner, string group) { long uid = -1; if (owner != null) uid = new UnixUserInfo (owner).UserId; long gid = -1; if (group != null) gid = new UnixGroupInfo (group).GroupId; SetOwner (uid, gid); }
private void CreateInitialConfig() { string user_name = "Unknown"; if (SparkleBackend.Platform == PlatformID.Unix || SparkleBackend.Platform == PlatformID.MacOSX) { user_name = new UnixUserInfo (UnixEnvironment.UserName).RealName; if (string.IsNullOrEmpty (user_name)) user_name = UnixEnvironment.UserName; else user_name = user_name.TrimEnd (",".ToCharArray()); } else { user_name = Environment.UserName; } if (string.IsNullOrEmpty (user_name)) user_name = "Unknown"; TextWriter writer = new StreamWriter (Path); string n = Environment.NewLine; writer.Write ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + n + "<sparkleshare>" + n + " <user>" + n + " <name>" + user_name + "</name>" + n + " <email>Unknown</email>" + n + " </user>" + n + "</sparkleshare>"); writer.Close (); SparkleHelpers.DebugInfo ("Config", "Created \"" + Path + "\""); }
public void SetOwner(UnixUserInfo owner, UnixGroupInfo group) { long uid, gid; uid = gid = -1; if (owner != null) uid = owner.UserId; if (group != null) gid = owner.GroupId; SetOwner (uid, gid); }
public static void Main(string [] args) { Catalog.Init (Defines.GETTEXT_PACKAGE, Defines.LOCALE_DIR); // Check whether git is installed Process Process = new Process (); Process.StartInfo.FileName = "git"; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; Process.Start (); if (Process.StandardOutput.ReadToEnd ().IndexOf ("version") == -1) { Console.WriteLine (_("Git wasn't found.")); Console.WriteLine (_("You can get Git from http://git-scm.com/.")); Environment.Exit (0); } UnixUserInfo UnixUserInfo = new UnixUserInfo (UnixEnvironment.UserName); // Don't allow running as root if (UnixUserInfo.UserId == 0) { Console.WriteLine (_("Sorry, you can't run SparkleShare with these permissions.")); Console.WriteLine (_("Things would go utterly wrong.")); Environment.Exit (0); } if (args.Length > 0) { if (args [0].Equals ("--help") || args [0].Equals ("-h")) { ShowHelp (); Environment.Exit (0); } string file_path = System.IO.Path.GetFullPath (args [0]); if (File.Exists (file_path)) { Gtk.Application.Init (); string [] revisions = GetRevisionsForFilePath (file_path); // Quit if the given file doesn't have any history if (revisions.Length < 2) { Console.WriteLine ("SparkleDiff: " + file_path + ": File has no history."); Environment.Exit (-1); } SparkleDiffWindow sparkle_diff_window; sparkle_diff_window = new SparkleDiffWindow (file_path, revisions); sparkle_diff_window.ShowAll (); // The main loop Gtk.Application.Run (); } else { Console.WriteLine ("SparkleDiff: " + file_path + ": No such file or directory."); Environment.Exit (-1); } } else { ShowHelp (); } }