/* An Example application that uses a vendor defined encryption routine */ /* Modified from the SDK version of lmflex.c by: Amante4 1/8/00 */ #include #if (defined( __STDC__) || defined(_WINDOWS)) && !defined(apollo) #include #endif #include #include "lmclient.h" #include "lm_code.h" #include "lm_attr.h" #define LICPATH "license.dat;." #define FEATURE "f1" LM_CODE(code, ENCRYPTION_SEED1, ENCRYPTION_SEED2, VENDOR_KEY1, VENDOR_KEY2, VENDOR_KEY3, VENDOR_KEY4, VENDOR_KEY5); main() { char feature[MAX_FEATURE_LEN+1]; LM_HANDLE *lm_job; char *my_crypt(LM_HANDLE *, CONFIG *, char *, VENDORCODE *); // prototype for my encryption function if (lc_init((LM_HANDLE *)0, VENDOR_NAME, &code, &lm_job)) { lc_perror(lm_job, "lc_init failed"); exit(lc_get_errno(lm_job)); } lc_set_attr(lm_job, LM_A_USER_CRYPT,(LM_A_VAL_TYPE)my_crypt); // Tell FlexLM I'm using a vendor defined routine printf("Enter feature to checkout [default: \"%s\"]: ", FEATURE); fgets(feature, MAX_FEATURE_LEN, stdin); feature[strlen(feature)-1] = '\0'; /* truncate trailing newline */ if (!*feature) strcpy(feature, FEATURE); lc_set_attr(lm_job, LM_A_LICENSE_DEFAULT, (LM_A_VAL_TYPE)LICPATH); if (lc_checkout(lm_job, feature, "1.0", 1, LM_CO_NOWAIT, &code, LM_DUP_NONE)) { printf("checkout failed... press return to exit...\n"); getchar(); lc_perror(lm_job, "checkout failed"); lc_free_job(lm_job); exit(lc_get_errno(lm_job)); } printf("%s checked out...press return to exit...", feature); /* * Wait till user hits return * getchar may be interrupted by SIGALRM, so we loop if necessary */ getchar(); lc_checkin(lm_job, feature ,0); lc_free_job(lm_job); return(0); } /* My vendor defined encryption routine */ char *my_crypt(LM_HANDLE *job, CONFIG *conf, char *sdate, VENDORCODE *key) { char *lic_key; char *modify_key(char *); // prototype lc_set_attr(job, LM_A_USER_CRYPT, (LM_A_VAL_TYPE)0); lic_key = lc_crypt(job, conf, sdate, key); // This is the normal way to get the license key lc_set_attr(job, LM_A_USER_CRYPT,(LM_A_VAL_TYPE)my_crypt); /* modify the license-key */ return(modify_key(lic_key)); } char *modify_key(char *key) { return ("123456789123"); // just return a constant string // This function could contain a really complicated algorithm // to change the normal license key in some way // but who cares. }