예제 #1
0
		public UnixUserInfo (uint user)
		{
			passwd = new Passwd ();
			Passwd pw;
			int r = Syscall.getpwuid_r (user, passwd, out pw);
			if (r != 0 || pw == null)
				throw new ArgumentException (Locale.GetText ("invalid user id"), "user");
		}
예제 #2
0
		public UnixUserInfo (Passwd passwd)
		{
			this.passwd = passwd;
		}
예제 #3
0
		public void Equality ()
		{
			Passwd orig = new Passwd ();
			Passwd mod  = new Passwd ();
			mod.pw_name   = orig.pw_name   = "some name";
			mod.pw_passwd = orig.pw_passwd = "some passwd";
			mod.pw_uid    = orig.pw_uid    = 500;
			mod.pw_gid    = orig.pw_gid    = 500;
			mod.pw_gecos  = orig.pw_gecos  = "some gecos";
			mod.pw_dir    = orig.pw_dir    = "/some/dir";
			mod.pw_shell  = orig.pw_shell  = "/some/shell";

			Assert.AreEqual (orig, mod, "#TE: copies should be equal");

			mod.pw_name = "another name";
			Assert.IsFalse (orig.Equals (mod), "#TE: changes should be reflected");
		}
예제 #4
0
		public static Passwd fgetpwent (IntPtr stream)
		{
			_Passwd passwd;
			int r;
			lock (pwd_lock) {
				r = sys_fgetpwent (stream, out passwd);
			}
			if (r != 0)
				return null;
			Passwd pw = new Passwd ();
			CopyPasswd (pw, ref passwd);
			return pw;
		}
예제 #5
0
		public static Passwd getpwent ()
		{
			_Passwd passwd;
			int r;
			lock (pwd_lock) {
				r = sys_getpwent (out passwd);
			}
			if (r != 0)
				return null;
			Passwd pw = new Passwd ();
			CopyPasswd (pw, ref passwd);
			return pw;
		}
예제 #6
0
		public static int getpwuid_r (uint uid, Passwd pwbuf, out Passwd pwbufp)
		{
			pwbufp = null;
			_Passwd passwd;
			IntPtr _pwbufp;
			int r = sys_getpwuid_r (uid, out passwd, out _pwbufp);
			if (r == 0 && _pwbufp != IntPtr.Zero) {
				CopyPasswd (pwbuf, ref passwd);
				pwbufp = pwbuf;
			}
			return r;
		}
예제 #7
0
		public static Passwd getpwnam (string name)
		{
			_Passwd passwd;
			int r;
			lock (pwd_lock) {
				r = sys_getpwnam (name, out passwd);
			}
			if (r != 0)
				return null;
			Passwd pw = new Passwd ();
			CopyPasswd (pw, ref passwd);
			return pw;
		}
예제 #8
0
		private static void CopyPasswd (Passwd to, ref _Passwd from)
		{
			try {
				to.pw_name   = UnixMarshal.PtrToString (from.pw_name);
				to.pw_passwd = UnixMarshal.PtrToString (from.pw_passwd);
				to.pw_uid    = from.pw_uid;
				to.pw_gid    = from.pw_gid;
				to.pw_gecos  = UnixMarshal.PtrToString (from.pw_gecos);
				to.pw_dir    = UnixMarshal.PtrToString (from.pw_dir);
				to.pw_shell  = UnixMarshal.PtrToString (from.pw_shell);
			}
			finally {
				Stdlib.free (from._pw_buf_);
				from._pw_buf_ = IntPtr.Zero;
			}
		}