예제 #1
0
		public static void SetItemAttributes (string keyring, int id, Hashtable atts)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.StartOperation (Operation.SetItemAttributes);
			req.Write (keyring);
			req.Write (id);
			req.WriteAttributes (atts);
			req.EndOperation ();
			SendRequest (req.Stream);
		}
예제 #2
0
		public static void SetItemInfo (string keyring, int id, ItemType type, string displayName, string secret)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.StartOperation (Operation.SetItemInfo);
			req.Write (keyring);
			req.Write (id);
			req.Write ((int) type);
			req.Write (displayName);
			req.Write (secret);
			req.EndOperation ();
			SendRequest (req.Stream);
		}
예제 #3
0
		public static Hashtable GetItemAttributes (string keyring, int id)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.GetItemAttributes, keyring, id);
			ResponseMessage resp = SendRequest (req.Stream);
			Hashtable tbl = new Hashtable ();
			resp.ReadAttributes (tbl);
			return tbl;
		}
예제 #4
0
		public static void DeleteItem (string keyring, int id)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.DeleteItem, keyring, id);
			SendRequest (req.Stream);
		}
예제 #5
0
		public static ItemData GetItemInfo (string keyring, int id)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.GetItemInfo, keyring, id);
			ResponseMessage resp = SendRequest (req.Stream);
			ItemType itype = (ItemType) resp.GetInt32 ();
			ItemData item = ItemData.GetInstanceFromItemType (itype);
			string name = resp.GetString ();
			string secret = resp.GetString ();
			DateTime mtime = resp.GetDateTime ();
			DateTime ctime =  resp.GetDateTime ();
			item.Keyring = keyring;
			item.ItemID = id;
			item.Secret = secret;
			Hashtable tbl = new Hashtable ();
			tbl ["name"] = name;
			tbl ["keyring_ctime"] = ctime;
			tbl ["keyring_mtime"] = mtime;
			item.Attributes = tbl;
			item.SetValuesFromAttributes ();
			return item;
		}
예제 #6
0
		public static ArrayList GetItemACL (string keyring, int id)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.GetItemACL, keyring, id);
			ResponseMessage resp = SendRequest (req.Stream);
			int count = resp.GetInt32 ();
			ArrayList list = new ArrayList (count);
			for (int i = 0; i < count; i++) {
				list.Add (new ItemACL (resp.GetString (), resp.GetString (), (AccessRights) resp.GetInt32 ()));
			}
			return list;
		}
예제 #7
0
		public static void SetDefaultKeyring (string newKeyring)
		{
			if (newKeyring == null)
				throw new ArgumentNullException ("newKeyring");
			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.SetDefaultKeyring, newKeyring);
			SendRequest (req.Stream);
		}
예제 #8
0
		public static int [] ListItemIDs (string keyring)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.ListItems, keyring);
			ResponseMessage resp = SendRequest (req.Stream);
			int len = resp.GetInt32 ();
			int [] result = new int [len];
			for (int i = 0; i < len; i++) {
				result [i] = resp.GetInt32 ();
			}

			return result;
		}
예제 #9
0
		public static ItemData [] Find (ItemType type, Hashtable atts)
		{
			if (atts == null)
				throw new ArgumentNullException ("atts");
			RequestMessage req = new RequestMessage ();
			req.StartOperation (Operation.Find);
			req.Write ((int) type);
			req.WriteAttributes (atts);
			req.EndOperation ();

			ResponseMessage resp = null;
			try {
				resp = SendRequest (req.Stream);
			} catch (KeyringException ke) {
				if (ke.ResultCode == ResultCode.Denied ||
				    ke.ResultCode == ResultCode.NoMatch)
					return empty_item_data;
				throw;
			}

			ArrayList list = new ArrayList ();
			while (resp.DataAvailable) {
				ItemData found = ItemData.GetInstanceFromItemType (type);
				found.Keyring = resp.GetString ();
				found.ItemID = resp.GetInt32 ();
				found.Secret = resp.GetString ();
				found.Attributes = new Hashtable ();
				resp.ReadAttributes (found.Attributes);
				found.SetValuesFromAttributes ();
				list.Add (found);
			}

			return (ItemData []) list.ToArray (typeof (ItemData));
		}
예제 #10
0
		public static void Lock (string keyring)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.LockKeyring, keyring);
			SendRequest (req.Stream);
		}
예제 #11
0
		public static void Unlock (string keyring, string password)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			if (password == null)
				throw new ArgumentNullException ("password");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.UnlockKeyring, keyring, password);
			try {
				SendRequest (req.Stream);
			} catch (KeyringException ke) {
				if (ke.ResultCode != ResultCode.AlreadyUnlocked)
					throw;
			}
		}
예제 #12
0
		public static void CreateKeyring (string name, string password)
		{
			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.CreateKeyring, name, password);
			SendRequest (req.Stream);
		}
예제 #13
0
		public static string [] GetKeyrings ()
		{
			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.ListKeyrings);
			ResponseMessage resp = SendRequest (req.Stream);
			return resp.GetStringList ();
		}
예제 #14
0
		public static string GetDefaultKeyring ()
		{
			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.GetDefaultKeyring);
			ResponseMessage resp = SendRequest (req.Stream);
			return resp.GetString ();
		}
예제 #15
0
		public static KeyringInfo GetKeyringInfo (string keyring)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.GetKeyringInfo, keyring);
			ResponseMessage resp = SendRequest (req.Stream);
			return new KeyringInfo (keyring, (resp.GetInt32 () != 0),
							resp.GetInt32 (),
							resp.GetDateTime (),
							resp.GetDateTime (),
							(resp.GetInt32 () != 0));
		}
예제 #16
0
		public static NetItemData [] FindNetworkPassword (string user, string domain, string server, string obj,
									string protocol, string authtype, int port)
		{
			RequestMessage req = new RequestMessage ();
			req.StartOperation (Operation.Find);
			req.Write ((int) ItemType.NetworkPassword);
			Hashtable tbl = new Hashtable ();
			tbl ["user"] = user;
			tbl ["domain"] = domain;
			tbl ["server"] = server;
			tbl ["object"] = obj;
			tbl ["protocol"] = protocol;
			tbl ["authtype"] = authtype;
			if (port != 0)
				tbl ["port"] = port;
			req.WriteAttributes (tbl);
			req.EndOperation ();

			ResponseMessage resp = null;
			try {
				resp = SendRequest (req.Stream);
			} catch (KeyringException ke) {
				if (ke.ResultCode == ResultCode.Denied ||
				    ke.ResultCode == ResultCode.NoMatch)
					return empty_net_item_data;
				throw;
			}
			ArrayList list = new ArrayList ();
			while (resp.DataAvailable) {
				NetItemData found = new NetItemData ();
				found.Keyring = resp.GetString ();
				found.ItemID = resp.GetInt32 ();
				found.Secret = resp.GetString ();
				found.Attributes = new Hashtable ();
				resp.ReadAttributes (found.Attributes);
				found.SetValuesFromAttributes ();
				list.Add (found);
			}

			return (NetItemData []) list.ToArray (typeof (NetItemData));
		}
예제 #17
0
		public static void SetKeyringInfo (string keyring, KeyringInfo info)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			if (info == null)
				throw new ArgumentNullException ("info");

			RequestMessage req = new RequestMessage ();
			req.StartOperation (Operation.SetKeyringInfo);
			req.Write (keyring);
			req.Write (info.LockOnIdle ? 1 : 0);
			req.Write (info.LockTimeoutSeconds);
			req.EndOperation ();
			SendRequest (req.Stream);
		}
예제 #18
0
		public static int CreateItem (string keyring, ItemType type, string displayName, Hashtable attributes,
						string secret, bool updateIfExists)
		{
			RequestMessage req = new RequestMessage ();
			req.StartOperation (Operation.CreateItem);
			req.Write (keyring);
			req.Write (displayName);
			req.Write (secret);
			req.WriteAttributes (attributes);
			req.Write ((int) type);
			req.Write (updateIfExists ? 1 : 0);
			req.EndOperation ();
			ResponseMessage resp = SendRequest (req.Stream);
			return resp.GetInt32 ();
		}
예제 #19
0
		public static void SetItemACL (string keyring, int id, ItemACL [] acls)
		{
			if (keyring == null)
				throw new ArgumentNullException ("keyring");

			if (acls == null)
				throw new ArgumentNullException ("acls");

			if (acls.Length == 0)
				throw new ArgumentException ("Empty ACL set.", "acls");

			RequestMessage req = new RequestMessage ();
			req.StartOperation (Operation.SetItemACL);
			req.Write (keyring);
			req.Write (id);
			req.Write (acls.Length);
			foreach (ItemACL acl in acls) {
				req.Write (acl.DisplayName);
				req.Write (acl.FullPath);
				req.Write ((int) acl.Access);
			}
			req.EndOperation ();
			SendRequest (req.Stream);
		}
예제 #20
0
		public static void LockAll ()
		{
			RequestMessage req = new RequestMessage ();
			req.CreateSimpleOperation (Operation.LockAll);
			SendRequest (req.Stream);
		}