using System; using System.Text; using System.Runtime.InteropServices; using PersistentSecurity; //********************************************************** // Description: //********************************************************** class Vendorid { public delegate int DelmyID(StringBuilder id); static void Main() { StringBuilder szMessage = new StringBuilder(1024); DelmyID myID = GetMyVendorID; // make this application use an external license file PSProlibProxy.sgSetAttrInt(PSProlibProxy.SG_ATTRTYPE.SG_ATTR_LICENSETYPE,(int)PSProlibProxy.SG_LICENSETYPE.SG_LICENSETYPE_EXTERNAL); // set the vendor function via function pointer PSProlibProxy.sgSetVendor(myID); Console.WriteLine("Note: if you are running the demo version of SafeGuard LM, the only idtype supported is \"any\""); if (PSProlibProxy.sgAuthorized("vendor.lic","monitor","6.0") != PSProlibProxy.SG_AUTHORIZED) { // tell the user they are not licensed for the application and exit gracefully PSProlibProxy.sgGetLastErrorString(szMessage); Console.WriteLine("{0}",szMessage); Environment.Exit(1); } Console.WriteLine("Running the monitor application...."); Environment.Exit(0); } //*********************************************** //* //* The vendor hostid function //* //*********************************************** static int GetMyVendorID(StringBuilder id) { StringBuilder hostname = new StringBuilder(256); StringBuilder username = new StringBuilder(64); StringBuilder key = new StringBuilder(32); StringBuilder instr = new StringBuilder(512); StringBuilder outstr = new StringBuilder(512); // this is an example of a 'composite' ID where we use more than // one ID type to build a unique 'hostid'. // allow these just in case they have been disabled somewhere else PSProlibProxy.sgSetAttrInt(PSProlibProxy.SG_ATTRTYPE.SG_ATTR_ALLOW_IDTYPE,(int)PSProlibProxy.SG_IDTYPE.SG_IDTYPE_USERNAME); PSProlibProxy.sgSetAttrInt(PSProlibProxy.SG_ATTRTYPE.SG_ATTR_ALLOW_IDTYPE,(int)PSProlibProxy.SG_IDTYPE.SG_IDTYPE_HOSTNAME); PSProlibProxy.sgGetAttrStr(PSProlibProxy.SG_ATTRTYPE.SG_ATTR_USERNAME_ID,username); PSProlibProxy.sgGetAttrStr(PSProlibProxy.SG_ATTRTYPE.SG_ATTR_HOSTNAME_ID,hostname); instr.Append(username.ToString()); instr.Append("-"); instr.Append(hostname.ToString()); // use RC4 to encrypt the hostid so that it is not obvious what it // consists of. This RC4 encrypted string *is* the unique hostid // pick your own encryption key. PSProlibProxy.sgArc4(1,"qwerty",instr.ToString(),outstr); // always encrypt the ID between function calls. The receiving // code will decrypt it. PSProlibProxy.sgCrypt(outstr,1); id.Clear(); id.Append(outstr.ToString()); return(0); } }