From 4b14c575b58bd47fcd2a2c57383a3127f3fbb2ed Mon Sep 17 00:00:00 2001 From: Manohar Date: Tue, 28 Feb 2006 10:58:02 +0000 Subject: [PATCH] FireFox functionality --- c_adlib/ad_ff/AssemblyInfo.cs | 80 ++++++++ c_adlib/ad_ff/FireFox.cs | 356 ++++++++++++++++++++++++++++++++++ c_adlib/ad_ff/Makefile | 20 ++ c_adlib/ad_ff/objs.lux | 3 + c_adlib/ad_ff/src.lux | 3 + 5 files changed, 462 insertions(+) create mode 100644 c_adlib/ad_ff/AssemblyInfo.cs create mode 100644 c_adlib/ad_ff/FireFox.cs create mode 100644 c_adlib/ad_ff/Makefile create mode 100644 c_adlib/ad_ff/objs.lux create mode 100644 c_adlib/ad_ff/src.lux diff --git a/c_adlib/ad_ff/AssemblyInfo.cs b/c_adlib/ad_ff/AssemblyInfo.cs new file mode 100644 index 00000000..cb959b5f --- /dev/null +++ b/c_adlib/ad_ff/AssemblyInfo.cs @@ -0,0 +1,80 @@ +/*********************************************************************** + * + * 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.Reflection; +using System.Runtime.CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("Novell.CASA.DataEngines.FireFox.dll")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Novell, Inc")] +[assembly: AssemblyProduct("CASA")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.6.*")] + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project output directory which is +// %Project Directory%\obj\. For example, if your KeyFile is +// located in the project directory, you would specify the AssemblyKeyFile +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] +[assembly: AssemblyKeyName("")] diff --git a/c_adlib/ad_ff/FireFox.cs b/c_adlib/ad_ff/FireFox.cs new file mode 100644 index 00000000..aa3c1455 --- /dev/null +++ b/c_adlib/ad_ff/FireFox.cs @@ -0,0 +1,356 @@ +/*********************************************************************** + * + * 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.Runtime.InteropServices; +using System.Collections.Specialized; +using System.Collections; + + +namespace Novell.CASA.DataEngines.FF +{ + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] +public class Host +{ + public IntPtr hostName; + public IntPtr hostElement; + public IntPtr next; + public Host() + { + hostName = Marshal.AllocHGlobal(128); + } + ~Host() + { + Marshal.FreeHGlobal(hostName); + } +}; + + +[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] +public class HostElement +{ + public IntPtr name; + public IntPtr value; + public int isPassword; + public IntPtr next; + public HostElement() + { + name = Marshal.AllocHGlobal(128); + value = Marshal.AllocHGlobal(128); + } + ~HostElement() + { + Marshal.FreeHGlobal(name); + Marshal.FreeHGlobal(value); + } +}; + + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public class KeyringInfo + { + public int lockOnIdle; + public uint lockTimeout; + public uint mTime; + public uint cTime; + public int isLocked; + } + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public class NativeItemInfo + { + public int itemType; + public IntPtr displayName; + public IntPtr secret; + public int mTime; + public int cTime; + public NativeItemInfo() + { + displayName = Marshal.AllocHGlobal(128); + secret = Marshal.AllocHGlobal(128); + } + ~NativeItemInfo() + { + Marshal.FreeHGlobal(displayName); + Marshal.FreeHGlobal(secret); + } + } + + public class ItemInfo + { + public string itemType; + public string displayName; + public string secret; + public int mTime; + public int cTime; + } + + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public class NativeAttribute + { + public uint type; + public IntPtr key; + public IntPtr value; + } + + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] + public class Attribute + { + public uint type; + public string key; + public string value; + + } + + public class FireFox + { + private static int MAX_PROFILES = 5; //FIXME:Maximum Profiles for Firefox - To be removed when done dynamically via a native api + private static int LOAD_PROFILE_ALWAYSFROM_FILE = 1; + + + //Initialization functions + [DllImport("libad_ff.so.1.1.1")] + public static extern int FPM_GetProfileList(out IntPtr[] profileList, out IntPtr[] profileFlag); + + [DllImport("libad_ff.so.1.1.1")] + public static extern int FPM_FirefoxProfileInit(string profileName); + + [DllImport("libad_ff.so.1.1.1")] + public static extern int FPM_FirefoxProfileExit(string profileName); + + //Master Password functions + [DllImport("libad_ff.so.1.1.1")] + public static extern int FPM_IsMasterPasswordSet(string profileName); + + [DllImport("libad_ff.so.1.1.1")] + public static extern int FPM_CheckMasterPassword(string profileName, string masterPassword); + + //Signon functions + [DllImport("libad_ff.so.1.1.1")] + public static extern int FPM_GetSignonData(string profileName,out IntPtr host,int doRefresh); + //TBD + //int FPM_WriteSignonData(char *profileName) + //int FPM_AddHost(char *profileName, struct Host *host, int doUpdate) + //int FPM_ModifyHost(char *profileName, struct Host *host, int doUpdate) + //int FPM_RemoveHost(char *profileName, char *hostname, int doUpdate) + + + //-------------------------------------------------------------- + //GetDefaultProfileName + //@param None + //@return Default ProfileName on success + // else null if not retrivable + //-------------------------------------------------------------- + public static String GetDefaultProfileName() + { + + IntPtr[] profileListIntPtr=new IntPtr[MAX_PROFILES];; + IntPtr[] profileFlagsIntPtr=new IntPtr[MAX_PROFILES];; + String[] profileList=null; + int[] profileFlags=null; + String profileName=null; + int profileFlag=0; + int profCount=0; + String defaultProfileName=null; + + Console.WriteLine("FireFox:Invoking FPM_GetProfileList:"); + profCount=FPM_GetProfileList(out profileListIntPtr,out profileFlagsIntPtr); + Console.WriteLine("FireFox:No of Profiles found= "+profCount); + + for(int i=0; i< profCount; i++) + { + profileName=Marshal.PtrToStringAnsi(profileListIntPtr[i]); + profileFlag=(int)profileFlagsIntPtr[i]; + Console.WriteLine("FireFox:Iter="+i+"profileName="+profileName); + Console.WriteLine("FireFox:Iter="+i+"profileFlag="+profileFlag); + if(profileFlag==1) + defaultProfileName=profileName; //Get the default profile name to init later + } + + + return defaultProfileName; + } + + + //-------------------------------------------------------------- + //GetAllProfileNames + //@param None + //@return ProfileNames (String[]) - List of all Profile Names + // else null + //-------------------------------------------------------------- + public static String[] GetAllProfileNames() + { + //TBD:To be implemented if\when required + return null; + } + + + + + //-------------------------------------------------------------- + //GetProfileData + //GetProfileData for the specified profile + //@param + // profileName (string) + // + //@return hostList (Host) on success + // else null + //-------------------------------------------------------------- + public static Host GetProfileData(string profileName) + { + Host hostList = new Host(); + int methodStatusCode=-1; + + //Console.WriteLine("FireFox:Initializing the Profile "+profileName); + //methodStatusCode=InitProfile(profileName); + //Console.WriteLine("FireFox:InitProfile returned "+methodStatusCode); + + //if(methodStatusCode==1) + {//If Init of the profile was sucessfull, get the sigon data to complete the aggregation + IntPtr hostListIntPtr = new IntPtr(); + try + { + Console.WriteLine("FireFox:Getting Data for profile "+profileName); + methodStatusCode=-1; + methodStatusCode = FPM_GetSignonData(profileName,out hostListIntPtr,LOAD_PROFILE_ALWAYSFROM_FILE); + if( 1 != methodStatusCode ) + { + Console.WriteLine("FireFox:Getting Data for profile Failed with error "+methodStatusCode); + hostList = null; + } + + } + catch(Exception e) + { + Console.WriteLine("FireFox:Exception during invokation of FPM_GetSignonData"); + Console.WriteLine(e.ToString()); + hostList = null; + } + + hostList = (Host)Marshal.PtrToStructure(hostListIntPtr, typeof(Host)); + //This can be Null only when nothing is aggregated. + if (((String)Marshal.PtrToStringAnsi(hostList.hostName)) == null ) + { + //TBD: Log that there are no secrets to aggregate + Console.WriteLine("FireFox:no secrets to aggregate"); + hostList = null; + } + + //Uninitialize the profile + //Console.WriteLine("FireFox:UnInitializing the Profile "+profileName); + //UninitProfile(profileName); + } + + return hostList; + } + + //-------------------------------------------------------------- + //InitFFProfile + //@param profileName name of the profile + //@return 1 on success + // <=0 on error + //-------------------------------------------------------------- + public static int InitProfile(string profileName) + { + return FPM_FirefoxProfileInit(profileName); + } + + + //================================================================= + + //-------------------------------------------------------------- + //UninitProfile + //UninitProfile for the specified profile + //@param + // profileName (string) + // + //@return 1 on success + // <=0 on error + //-------------------------------------------------------------- + public static int UninitProfile(string profileName) + { + int methodStatusCode=-1; + + Console.WriteLine("FireFox:UninitProfile for "+profileName); + methodStatusCode=-1; + methodStatusCode = FPM_FirefoxProfileExit(profileName); + if( 1 != methodStatusCode ) + { + Console.WriteLine("FireFox:UninitProfile Failed with error "+methodStatusCode); + } + + return methodStatusCode; + } + + + //-------------------------------------------------------------- + //isMasterPasswordSetFor + //Is MasterPassword Set For specified profile + //@param + // profileName (string) + // + //@param profileName name of the profile + // @return 1 if master password is set + // 0 if master password not set + //-------------------------------------------------------------- + public static int isMasterPasswordSetFor(string profileName) + { + int methodStatusCode=0; + + Console.WriteLine("FireFox:isMasterPasswordSetFor "+profileName); + methodStatusCode = FPM_IsMasterPasswordSet(profileName); + + return methodStatusCode; + } + + //-------------------------------------------------------------- + //checkMasterPassword + //Check if the specified master password is correct or not. + //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 + // profileName (string) + // masterPassword (string) + // + // @return 1 if the specified master password is correct + // 0 if the master password is wrong. + //-------------------------------------------------------------- + public static int checkMasterPassword(string profileName,string masterPassword) + { + int methodStatusCode=0; + + Console.WriteLine("FireFox:checking MasterPassword for "+profileName); + methodStatusCode = FPM_CheckMasterPassword(profileName,masterPassword); + + return methodStatusCode; + } + + //=================Local Methods==================================== + + + + + + } +} diff --git a/c_adlib/ad_ff/Makefile b/c_adlib/ad_ff/Makefile new file mode 100644 index 00000000..952a5f8d --- /dev/null +++ b/c_adlib/ad_ff/Makefile @@ -0,0 +1,20 @@ +# +# configure environment +# +TARGET = Novell.CASA.DataEngines.FireFox +CS_NAME = $(TARGET)$(xtra).$(EXE) +include global.mak +include defaults.$(PLAT) +include rules.mak + + +# +# target object and source files +# +include src.$(PLAT) +include objs.$(PLAT) + +# +# targets +# +include target.cs diff --git a/c_adlib/ad_ff/objs.lux b/c_adlib/ad_ff/objs.lux new file mode 100644 index 00000000..00431716 --- /dev/null +++ b/c_adlib/ad_ff/objs.lux @@ -0,0 +1,3 @@ +OBJS=\ + AssembyInfo\ + FireFox diff --git a/c_adlib/ad_ff/src.lux b/c_adlib/ad_ff/src.lux new file mode 100644 index 00000000..41edb539 --- /dev/null +++ b/c_adlib/ad_ff/src.lux @@ -0,0 +1,3 @@ +SRC=\ + AssemblyInfo.cs\ + FireFox.cs