Пример #1
0
        public static NetItemData[] FindNetworkPassword(string user, string domain, string server, string obj,
                                                        string protocol, string authtype, int port)
        {
            IntPtr passwordList;

            ResultCode result = gnome_keyring_find_network_password_sync(user, domain, server, obj, protocol, authtype, (uint)port, out passwordList);

            if (result == ResultCode.Denied || result == ResultCode.NoMatch)
            {
                return(empty_net_item_data);
            }

            if (result != ResultCode.Ok)
            {
                throw new KeyringException(result);
            }

            IntPtr[] passwordStructs = (IntPtr[])GLib.Marshaller.ListPtrToArray(passwordList, typeof(GLib.List), false, false, typeof(IntPtr));
            List <GnomeKeyringNetworkPasswordData> passwords = new List <GnomeKeyringNetworkPasswordData> ();

            foreach (IntPtr ptr in passwordStructs)
            {
                passwords.Add((GnomeKeyringNetworkPasswordData)Marshal.PtrToStructure(ptr, typeof(GnomeKeyringNetworkPasswordData)));
            }

            ArrayList list = new ArrayList();

            foreach (var password in passwords)
            {
                NetItemData found = new NetItemData();
                found.Keyring    = Marshal.PtrToStringAnsi(password.keyring);
                found.ItemID     = (int)password.item_id;
                found.Secret     = Marshal.PtrToStringAnsi(password.password);
                found.Attributes = new Hashtable();

                SetAttributeIfNonNull(found.Attributes, "protocol", password.protocol);
                SetAttributeIfNonNull(found.Attributes, "server", password.server);
                SetAttributeIfNonNull(found.Attributes, "object", password.@object);
                SetAttributeIfNonNull(found.Attributes, "authtype", password.authtype);
                SetAttributeIfNonNull(found.Attributes, "user", password.user);
                SetAttributeIfNonNull(found.Attributes, "domain", password.domain);

                if (password.port != 0)
                {
                    found.Attributes["port"] = (int)password.port;
                }

                found.SetValuesFromAttributes();
                list.Add(found);
            }

            return((NetItemData [])list.ToArray(typeof(NetItemData)));
        }
Пример #2
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)));
        }
Пример #3
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));
		}
Пример #4
0
		public static NetItemData[] FindNetworkPassword (string user, string domain, string server, string obj,
									string protocol, string authtype, int port)
		{
			IntPtr passwordList;
			
			ResultCode result = gnome_keyring_find_network_password_sync (user, domain, server, obj, protocol, authtype, (uint)port, out passwordList);
			
			if (result == ResultCode.Denied || result == ResultCode.NoMatch) {
				return empty_net_item_data;
			}
			
			if (result != ResultCode.Ok) {
				throw new KeyringException (result);
			}
			
			IntPtr[] passwordStructs = (IntPtr[])GLib.Marshaller.ListPtrToArray (passwordList, typeof(GLib.List), false, false, typeof(IntPtr));
			List<GnomeKeyringNetworkPasswordData> passwords = new List<GnomeKeyringNetworkPasswordData> ();
			
			foreach (IntPtr ptr in passwordStructs) {
				passwords.Add ((GnomeKeyringNetworkPasswordData)Marshal.PtrToStructure (ptr, typeof(GnomeKeyringNetworkPasswordData)));
			}
			
			ArrayList list = new ArrayList ();
			foreach (var password in passwords) {
				NetItemData found = new NetItemData ();
				found.Keyring = Marshal.PtrToStringAnsi (password.keyring);
				found.ItemID = (int)password.item_id;
				found.Secret = Marshal.PtrToStringAnsi (password.password);
				found.Attributes = new Hashtable ();
				
				SetAttributeIfNonNull (found.Attributes, "protocol", password.protocol);
				SetAttributeIfNonNull (found.Attributes, "server", password.server);
				SetAttributeIfNonNull (found.Attributes, "object", password.@object);
				SetAttributeIfNonNull (found.Attributes, "authtype", password.authtype);
				SetAttributeIfNonNull (found.Attributes, "user", password.user);
				SetAttributeIfNonNull (found.Attributes, "domain", password.domain);

				if (password.port != 0) {
					found.Attributes["port"] = (int)password.port;
				}
				
				found.SetValuesFromAttributes ();
				list.Add (found);
			}

			return (NetItemData []) list.ToArray (typeof (NetItemData));
		}