From 832a3c5e9762a8e5e16df56171b925f19c5615d0 Mon Sep 17 00:00:00 2001 From: Manohar Date: Tue, 28 Feb 2006 11:28:32 +0000 Subject: [PATCH] --- c_adlib/Common.cs | 5 +- c_adlib/FFEngine.cs | 373 ++++++++++++++++++++++++++++++++++++++++++++ c_adlib/objs.lux | 1 + c_adlib/src.lux | 1 + 4 files changed, 379 insertions(+), 1 deletion(-) create mode 100644 c_adlib/FFEngine.cs diff --git a/c_adlib/Common.cs b/c_adlib/Common.cs index dc436a23..c0a04de6 100644 --- a/c_adlib/Common.cs +++ b/c_adlib/Common.cs @@ -40,6 +40,7 @@ namespace Novell.CASA.DataEngines.Common public static string KW = "KDE KWallet"; public static string GK = "GNOME Keyring"; public static string PM = "Password Manager"; + public static string FF = "Firefox"; //Store Types public static int CASA_STORE_MICASA = 0; @@ -74,7 +75,9 @@ namespace Novell.CASA.DataEngines.Common public static string CCF_ZONE = "Zone"; public static string CCF_SYNCH = "Synch"; public static string CCF_NAME = "Name"; - + public static string CCF_FFTAG = "FireFox"; + public static string CCF_FFPROFILE = "Profile"; + //Add Operation Types on CCF public static int OPERATION_ADD_SECRET = 0; public static int OPERATION_MODIFY_SECRET = 2; diff --git a/c_adlib/FFEngine.cs b/c_adlib/FFEngine.cs new file mode 100644 index 00000000..147baeb6 --- /dev/null +++ b/c_adlib/FFEngine.cs @@ -0,0 +1,373 @@ +/*********************************************************************** + * + * Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, Novell, Inc. + * + * To contact Novell about this file by physical or electronic mail, + * you may find current contact information at www.novell.com. + * + ***********************************************************************/ + +using System; +using System.Collections; +using System.Xml; +using System.IO; +using System.Collections.Specialized; +using System.Runtime.InteropServices; +using Novell.CASA.DataEngines.Common; +using Novell.CASA.DataEngines.FF; + + +namespace Novell.CASA.DataEngines +{ + + /* + * This class is implementation of Data engine for FireFox. + */ + + class FFEngine : DataEngine + { + private static string XML_FIRFOXSECRET_TYPE_SIGNON = "Signon"; + + private String defaultProfileName=null; + private int initProfileStatus=-1; + + enum FireFoxResultExtended { + FIREFOX_RESULT_SUCESS = 1, + FIREFOX_RESULT_ERROR_UNKNOWN = 128 + }; + + public FFEngine() + { + //Get Profile Names + Console.WriteLine("FFEngine Constructor:Invoking GetDefaultProfileName:"); + defaultProfileName=FireFox.GetDefaultProfileName(); + //This can be extended to get all profiles : Use FireFox.GetAllProfileNames() + //Currently we support only the default profile. + + if(defaultProfileName!=null) + { + Console.WriteLine("FFEngine Constructor:Initializing the Profile "+defaultProfileName); + initProfileStatus=FireFox.InitProfile(defaultProfileName); + Console.WriteLine("FFEngine Constructor:InitProfile returned "+initProfileStatus); + } + else + Console.WriteLine("FFEngine Constructor:Could not get a Default Profile Name"); + } + + ~FFEngine() + { + //Uninitialize the profile + //FIXME:- CURRENTLY NOT IVOKED SINCE THERES IS A BUG WHICH NEEDS TO BE FIXED IN FF NATIVE + //Console.WriteLine("FFEngine Destructor:UnInitializing the Profile "+profileName); + //FireFox.UninitProfile(profileName); + } + + public XmlNode Aggregate() + { + //String defaultProfileName=null; + + //Get Profile Names + //Console.WriteLine("FFEngine:Invoking GetDefaultProfileName:"); + //defaultProfileName=FireFox.GetDefaultProfileName(); + //This can be extended to get all profiles : Use FireFox.GetAllProfileNames() + //Currently we support only the default profile. + + + //Init XML Document + XmlDocument doc = new XmlDocument(); + XmlNode rootElem = doc.CreateElement(ConstStrings.CCF_FFTAG); + doc.AppendChild(rootElem); + + //Initialize & Aggregate DefaultProfile from Firefox + readProfileToCCF(doc,rootElem,defaultProfileName); + + //Initialize & Aggregate any other profiles here if required.... + + Console.WriteLine("FFEngine:Returning Aggregated Node for FireFox:"); + return rootElem; + + } + + + + public int SetSecret(XmlNode secret) + { + return (int)FireFoxResultExtended.FIREFOX_RESULT_ERROR_UNKNOWN; + } + + + public int SetSecret(XmlNode secret, int opnType) + { + return (int)FireFoxResultExtended.FIREFOX_RESULT_ERROR_UNKNOWN; + } + + public int GetSecret(XmlNode secret) + { + return ConstStrings.CASA_SUCCESS; + } + + public int Remove(XmlNode secret) + { + return (int)FireFoxResultExtended.FIREFOX_RESULT_ERROR_UNKNOWN; + } + + //-------------------------------------------------------------- + //isMasterPasswordSet + //Is MasterPassword Set For the specified (Currently-Default) profile + //@param + // None ; For supporting multiple profiles, + // this needs to be extended to pass profile names + // + // @return 1 if master password is set + // 0 if master password not set + //-------------------------------------------------------------- + public int isMasterPasswordSet() + { + return (int)FireFox.isMasterPasswordSetFor(defaultProfileName); + } + + //-------------------------------------------------------------- + //verifyMasterPassword + //Check if the specified master password is correct or not for the (Currently-Default) profile. + //If it is correct then password is stored to the internal store for later use. + //If it is wrong then nothing is stored and 0 will be returned. + // + //@param + // masterPassword (string) + // ; For supporting multiple profiles, this needs to be extended to pass profile names + // + // @return 1 if the specified master password is correct + // 0 if the master password is wrong. + //-------------------------------------------------------------- + public int verifyMasterPassword(string masterPassword) + { + return (int)FireFox.checkMasterPassword(defaultProfileName,masterPassword); + } + + + //=================Local Methods==================================== + + //-------------------------------------------------------------- + //readProfileToCCF + //@param + // doc (XmlDocument) XML CCF Document for Firefox + // profileName (string) name of the profile to be read + //@return 1 on success + // <=0 on error + //   + // + // + // + // user1 + // + // + // password value + // + // + // + //  + //-------------------------------------------------------------- + public int readProfileToCCF(XmlDocument doc,XmlNode rootElement,string profileName) + { + int methodStatusCode=-1; + + if((profileName!=null) && (initProfileStatus==(int)FireFoxResultExtended.FIREFOX_RESULT_SUCESS)) + { + Host hostList = null; + + Console.WriteLine("FireFox:Getting Data for profile "+profileName); + hostList=FireFox.GetProfileData(profileName); + + if(hostList!=null) + {// Something to Aggregate + XmlElement xmlProfileElement; + + String hostName; + String name; + String value; + int isPassword; + + methodStatusCode=1; + xmlProfileElement = doc.CreateElement(ConstStrings.CCF_FFPROFILE); // + XmlAttribute idAttr = doc.CreateAttribute(ConstStrings.CCF_ID); //-ID + idAttr.Value = profileName; + xmlProfileElement.SetAttributeNode(idAttr); + + while (hostList != null) + { + HostElement hostElementList; + + + XmlElement xmlSecretElement = doc.CreateElement(ConstStrings.CCF_SECRET); // + + + hostName = (String)Marshal.PtrToStringAnsi(hostList.hostName); + Console.WriteLine("--------------------------------------------"); + Console.WriteLine("FFEngine::hostName="+hostName); + XmlAttribute secIdAttr = doc.CreateAttribute(ConstStrings.CCF_ID); //-ID + secIdAttr.Value = hostName; + xmlSecretElement.SetAttributeNode(secIdAttr); + + XmlAttribute typeAttr = doc.CreateAttribute(ConstStrings.CCF_TYPE); //-Type + typeAttr.Value = XML_FIRFOXSECRET_TYPE_SIGNON; + xmlSecretElement.SetAttributeNode(typeAttr); + + + //hostElementList = new HostElement(); + hostElementList = (HostElement)Marshal.PtrToStructure(hostList.hostElement, typeof(HostElement)); + while (hostElementList != null) + { + + XmlElement xmlKeyElement = null; + XmlAttribute keyIdAttr = null; + XmlElement xmlValueElement = null; + + name = (String)Marshal.PtrToStringAnsi(hostElementList.name); + Console.WriteLine("FFEngine::name="+name); + value = (String)Marshal.PtrToStringAnsi(hostElementList.value); + Console.WriteLine("FFEngine::value="+value); + isPassword = hostElementList.isPassword; + Console.WriteLine("FFEngine::isPassword="+isPassword); + + xmlKeyElement = doc.CreateElement(ConstStrings.CCF_KEY); //-ID + keyIdAttr.Value = name; + xmlKeyElement.SetAttributeNode(keyIdAttr); + + xmlValueElement = doc.CreateElement(ConstStrings.CCF_VALUE); // + xmlValueElement.InnerText = value; + xmlKeyElement.AppendChild(xmlValueElement); // + xmlSecretElement.AppendChild(xmlKeyElement); // + + //OUTERLOOP-Loop for hostList + if (hostList.next == IntPtr.Zero) + { + Console.WriteLine("FFEngine::End of all Data Items##"); + break; + } + + hostList = (Host)Marshal.PtrToStructure(hostList.next, typeof(Host)); + } + + rootElement.AppendChild(xmlProfileElement); // + + + } + + }//~Aggregate profileName + + return methodStatusCode; + } + + + + public static Boolean IsStoreAvailable() + { + try + { + System.Runtime.InteropServices.Marshal.PrelinkAll(typeof(FireFox)); + return true; + } + catch(DllNotFoundException d) + { + //Console.WriteLine("Store Not Available Exception = " + d.ToString()); + return false; + } + catch(Exception e) + { + //Console.WriteLine("Store Not Available Exception = " + e.ToString()); + return false; + } + } + +//#if TEST + public static void Main() + { + + + FFEngine ff = new FFEngine(); + + + Console.WriteLine(); + Console.WriteLine("********** Menu ***********"); + Console.WriteLine("* 5. Refresh *"); + Console.WriteLine("* 6. Is Store Avail *"); + Console.WriteLine("* 7. Quit *"); + Console.WriteLine("***************************"); + Console.WriteLine("For all options the input is the file /root/fftest.xml"); + + Console.WriteLine("Select option and Press enter"); + String line = Console.ReadLine(); + int res = 0; + + if (line.Length > 0) + { + char[] c = line.Substring(0, 1).ToCharArray(); + if (c.Length > 0) + { + if (c[0].Equals('7')) + return; + if (c[0].Equals('6')) + { + Console.WriteLine("Store Available is = " + FFEngine.IsStoreAvailable()); + return; + } + if (c[0].Equals('5')) + { + Console.WriteLine("FFEngine:Main:Aggregating:"); + XmlNode node = ff.Aggregate (); + XmlDocument doc = node.OwnerDocument; + XmlTextWriter writer = new XmlTextWriter("/root/fftest.xml",null); + writer.Formatting = Formatting.Indented; + doc.Save(writer); + writer.Close(); + } + else + { + + XmlDocument xmlDoc = new XmlDocument(); + XmlTextReader tr = new XmlTextReader("/root/fftest.xml"); + tr.Read(); + xmlDoc.Load(tr); + XmlNode root = xmlDoc.LastChild; + if (root == null) + { + Console.WriteLine("Root is null"); + } + + XmlNode secret = root.ChildNodes[0].ChildNodes[0]; + Console.WriteLine("secret Name \n" + secret.Name); + } + } + } + Console.WriteLine("Result of Operation = " + res); + + } +//#endif + + } +} diff --git a/c_adlib/objs.lux b/c_adlib/objs.lux index 0a1e84f6..1c137075 100644 --- a/c_adlib/objs.lux +++ b/c_adlib/objs.lux @@ -6,5 +6,6 @@ OBJS=\ AD_Facade\ KWalletEngine\ GKEngine \ + FFEngine \ ../c_gui/Logger diff --git a/c_adlib/src.lux b/c_adlib/src.lux index 5a7dd4aa..7838f7fd 100644 --- a/c_adlib/src.lux +++ b/c_adlib/src.lux @@ -6,4 +6,5 @@ SRC=\ AD_Facade.cs\ KWalletEngine.cs\ GKEngine.cs \ + FFEngine.cs \ ../c_gui/Logger.cs