license.c

来自「speech signal process tools」· C语言 代码 · 共 1,055 行 · 第 1/2 页

C
1,055
字号
/* * This material contains unpublished, proprietary software of Entropic * Research Laboratory, Inc. Any reproduction, distribution, or publication * of this work must be authorized in writing by Entropic Research * Laboratory, Inc., and must bear the notice: *  * "Copyright (c) 1986-1990  Entropic Speech, Inc. "Copyright (c) 1990-1991 * Entropic Research Laboratory, Inc. All rights reserved" *  * The copyright notice above does not evidence any actual or intended * publication of this source code. *  * Written by:  Alan Parker Checked by: Revised by: *  * Brief description:  License manager functions *  */static char    *sccs_id = "%W% %G% ERL";#include <stdio.h>#include <pwd.h>#include <sys/types.h>#include <sys/stat.h>#include <esps/esps.h>#include <ctype.h>#include <time.h>#include <esps/unix.h>#include <esps/ss.h>#include <sys/param.h>#include <elm.h>#include <elmlib.h>#include <elm_erl.h>#ifdef DEC_ALPHAchar           *elm_code();int             gethostname();unsigned        sleep();unsigned        usleep();#endifchar           *get_esps_base();static char     alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxzy._012";/* 012345678901234567890123456789012345678901234567890123456 *//* 11111111112222222222333333333344444444445555555 */int           erl_htk[] = {30, 43, 37, 53, 33, 45, 36, -1};int           erl_aligner[] = {30, 43, 37, 53, 26, 37, 34, 32, 39, 30, 43, -1};int           etsm_prefix[] = {30, 45, 44, 38, 52, -1};static int      debug = 0;static char     server_host[ELM_HOST_LEN + 1], *h;static char     this_host[ELM_HOST_LEN + 1];static char     feature[40];static int      waves_running = 0;static int      header_checked = 0;extern long     elm_var;void            exec_command();static void     init();/* #define DEBUG 1 */SOCKET         *sp = SS_NULL;#define SOCK_BUF_LEN 80char            sock_buffer[SOCK_BUF_LEN + 10000];extern short    ech_port;static voidlsleep(){#if defined(HP700) || defined(SG) || defined(DS3100) || defined(M5600)#if defined(HP700) || defined(DS3100) || defined(M5600)   sleep(1);			/* I'd rather not sleep 1 sec, but no usleep */#endif#ifdef SG   sginap(200);#endif#else   (void) usleep(20000);#endif}static intexpired(j)   long            j;{   time_t          now;   time(&now);   return (j && (now > j));}#ifndef WAVES_PROG#define NOLIC_MSG\"Sorry, but there is no ESPS license checked out on this host.\n\You must first run echeckout to get a license for this host.\n\See echeckout(1-ESPS).\n"#else#define NOLIC_MSG\"This program requires either that an ESPS license be checked out, or that\n\the site have a valid waves+ license installed.  If you do not have a waves+\n\license installed then you must first run echeckout to get a license for this\n\host.  See echeckout(1-ESPS).\n"#endif#define NOLIC_MSG_ERS\"This program requires that an ESPS license be checked out, or that the site\n\have a valid ERS or waves+ license.   If your site has ESPS licenses, you \n\can check one out by running echeckout(1-ESPS).\n"#define DOWN_MSG1 \"\nUnable to find an Entropic license server.  You have ELM_HOST defined\n\to %s.  Be sure that elmd is running on host %s, \n\or correct ELM_HOST.  The host that elmd is running on must be the host\n\that the keys were issued for.\n"#define DOWN_MSG2 \"\nUnable to find an Entropic license server.  Be sure elmd is running\n\on the host system for which the license keys were issued for. Set\n\the environment variable ELM_HOST to the name of the host running elmd.\n"#define NOLIC_MSG_HTK \"\nSorry, no HTK licenses are available.\n"char           *ers_license_names[] = {"ers.sc30", "ers.vc30", "ers.s32c", "ers.v32c","ers.s32", "ers.sgi", NULL};voidcheck_header(machine)   int             machine;{   int             i, j, ret;   struct elm_user user;   struct elm_info info;   char            machine_type[100];   if (getenv("no_lic_for_erl"))      return;   if (getenv("ELM_DEBUG"))      debug = 1;#ifdef NO_LIC   return;#endif   if (debug)      fprintf(stderr, "check_header\n");   /*    * assume that the server is on the current host, unless this environment    * variable is set    */   if (waves_running || header_checked)      return;   /* we must have the hostname in order to proceed */   if (gethostname(this_host, MAXHOSTNAMELEN) == -1) {      fprintf(stderr,	"Trouble getting your hostname.  Please have sysadmin check it.\n");      fprintf(stderr,	      "These programs cannot run without the hostname and networking being set up\n\         correctly.\n");      exit(-1);   } /****************************************************************************/   /*    * try and connect to local echeckout.  if it is running ok, then we will    * just assume that we can run    */   if (debug)      fprintf(stderr, "looking for echeckout with ConnectSock\n");   sp = ConnectSock(this_host, ech_port);   if (sp != SS_NULL) {		/* we connected to somebody at that port */      time_t          now;      char            cleartext[SOCK_BUF_LEN], ciphertext[SOCK_BUF_LEN];      time(&now);      sprintf(cleartext, "%x%x", now, 70);      strcpy(ciphertext, (char *) elm_code(ENCRYPT, cleartext));      strcat(ciphertext, "\n");      strcat(cleartext, "\n");      if (SockWrites(cleartext, sp) != 0)	 fprintf(stderr, "Error writing to echeckout.\n");      else {	 sock_buffer[0] = '\0';	 (void) SockGets(sock_buffer, SOCK_BUF_LEN - 1, sp);	 if (strcmp(sock_buffer, ciphertext) == 0) {	    SockClose(sp);	    header_checked = 1;	    if (debug)	       fprintf(stderr, "OK, found it; we are done\n");	    return;		/* ok to continue */	 }      }   }   init();   (void) strcpy(machine_type, machine_codes[machine]);   if (debug)      fprintf(stderr, "calling elm_getulist()\n");   for (i = 1; (i = elm_getulist(&user, ESPS_FEATURE, i)) > 0; i++) {      if ((strcmp(this_host, user.host) == 0)) {	 if (debug)	    fprintf(stderr, "found match, we are done\n");	 header_checked = 1;	 return;      }   }   /*    * if the following code is turned on, then the program will run with    * either a waves+ license present, or an ESPS license out    */#ifdef WAVES_PROG   if (debug)      fprintf(stderr, "calling elm_getulist() for waves-only\n");   ret = elm_getinfo(&info, WAVES_FEATURE, 0);   if (ret > 0 && info.numlic && !expired(info.expiration)) {      if (debug)	 fprintf(stderr, "found waves running, we are done\n");      header_checked = 1;      return;   }#endif	/* WAVES_PROG */#ifdef ERS_PROG   if (debug)      fprintf(stderr, "calling elm_getulist() for ers-only\n");   for (i = 0; ers_license_names[i] != NULL; i++) {      ret = elm_getinfo(&info, ers_license_names[i], 0);      if (ret > 0 && info.numlic && !expired(info.expiration)) {	 header_checked = 1;	 return;      }   }   fprintf(stderr, NOLIC_MSG_ERS);   exit(1);#else#ifndef WAVES_PROG   fprintf(stderr, "No ESPS license checked out. Trying...\n");   exec_command("echeckout");   (void) sleep(1);   for (i = 1; (i = elm_getulist(&user, ESPS_FEATURE, i)) > 0; i++) {      if ((strcmp(this_host, user.host) == 0)	 ) {	 header_checked = 1;	 return;      }   }   fprintf(stderr, NOLIC_MSG);   exit(1);#else   fprintf(stderr, NOLIC_MSG);   exit(1);#endif#endif}static char     expired_feature[ELM_FEATURE_LEN + 1];voidwaves_check(){   int             i, ret;   server_host[0] = '\0';   if ((h = getenv("ELM_HOST")) && h[0])      (void) strcpy(server_host, h);   elm_var = 0;   strcpy(feature, WAVES_FEATURE);   init(NULL);   ret = elm_getlicense(feature, ELM_GETLIC);   switch (ret) {   case ELM_OK:      break;   case ELM_WAIT:      fprintf(stderr,	      "License manager on server %s initializing.\n",	      server_host);      exit(-1);   case ELM_FAIL:      (void) fprintf(stderr,		     "Sorry, no waves+ licenses currently are available.\n");      exit(-1);   case ELM_SRV_DOWN:      if (h && h[0])	 fprintf(stderr, DOWN_MSG1, h, h);      else	 fprintf(stderr, DOWN_MSG2);      exit(-1);   case ELM_EXPIRED:      (void) fprintf(stderr,		     "Sorry, but your waves+ license has expired.\n");      exit(-1);   case ELM_AUTH_FAIL:      (void) fprintf(stderr,		     "Sorry, but the key found is invalid.  It looks like elmd is running on\n");      (void) fprintf(stderr,		     "the wrong host.  elmd must be run on the host that they keys were made for\n");      exit(-1);   case ELM_ERROR:      fprintf(stderr,	      "Sorry, but you do not seem to have a license for waves+.\n");      fprintf(stderr,	      "Is the key file installed and readable?\n");      fprintf(stderr,	      "The key file should be %s/lib/keys/%s\n",	      get_esps_base(NULL), feature);      exit(-1);   default:      (void) fprintf(stderr,		     "Network or system error; code: %d\n", ret);      (void) fprintf(stderr,		     "Perhaps your network is not running? Contact Entropic if you cannot\n");      (void) fprintf(stderr,		     "resolve this.\n");      exit(-1);   }   waves_running = 1;   return;}voidtsm_check(){   int             ret, i, j;   char            machine_type[100];   /*    * assume that the server is on the current host, unless this environment    * variable is set    */   server_host[0] = '\0';   if ((h = getenv("ELM_HOST")) && h[0])      (void) strcpy(server_host, h);   init(NULL);   (void) strcpy(machine_type, machine_codes[MACH_CODE]);   /* new version of ELM require that feature names be lower case */   j = strlen(machine_type);   for (i = 0; i < j; i++)      if (isupper(machine_type[i]))	 machine_type[i] = tolower(machine_type[i]);   i = 0;   while (etsm_prefix[i] != -1) {      feature[i] = alpha[etsm_prefix[i]];      i++;   }   feature[i] = 0;   (void) strcat(feature, machine_type);   ret = elm_getlicense(feature, ELM_GETLIC);   switch (ret) {   case ELM_OK:      break;   case ELM_WAIT:      fprintf(stderr,	      "License manager on server %s initializing.\n",	      server_host);      exit(-1);   case ELM_FAIL:      (void) fprintf(stderr,		     "Sorry, no TSM licenses currently are available.\n");      exit(-1);   case ELM_SRV_DOWN:      if (h && h[0])	 fprintf(stderr, DOWN_MSG1, h, h);      else	 fprintf(stderr, DOWN_MSG2);      exit(-1);   case ELM_AUTH_FAIL:      (void) fprintf(stderr,		     "Sorry, but the key found is invalid.  It looks like elmd is running on\n");      (void) fprintf(stderr,		     "the wrong host.  elmd must be run on the host that they keys were made for\n");      exit(-1);   case ELM_EXPIRED:      (void) fprintf(stderr,		     "Sorry, but your license has expired.\n");      exit(-1);   case ELM_ERROR:      fprintf(stderr,	      "Sorry, but you do not seem to have a license for TSM.\n");      fprintf(stderr,	      "Is the key file installed and readable?\n");      fprintf(stderr,	      "The key file should be %s/lib/keys/%s\n",	      get_esps_base(NULL), feature);      exit(-1);   default:      (void) fprintf(stderr,		     "Network or system error; code: %d\n", ret);      (void) fprintf(stderr,		     "Perhaps your network is not running?\n");      fprintf(stderr,	      "Contact Entropic if you cannot resolve this.\n");      exit(-1);   }   waves_running = 1;   return;}/* * This function is used to check to see if a waves+ or esps license exist. * If it has already been checked, then just return fast. */static          check_header2_called = 0;voidcheck_header2(){   int             i, j, ret;   int             machine = MACH_CODE;   char            machine_type[100];   struct elm_info info;   if (getenv("ELM_DEBUG"))      debug = 1;   if (check_header2_called || waves_running || header_checked)      return;   check_header2_called = 1;   init(NULL);   (void) strcpy(machine_type, machine_codes[machine]);   ret = elm_getinfo(&info, ESPS_FEATURE, 0);	/* check for esps key */   if (ret > 0 && info.numlic && !expired(info.expiration))      return;   if (ret < 0)      switch (ret) {      case ELM_FAIL:      case ELM_ERROR:	 break;      case ELM_SRV_DOWN:	 if (h && h[0])	    fprintf(stderr, DOWN_MSG1, h, h);	 else	    fprintf(stderr, DOWN_MSG2);	 exit(-1);      default:	 (void) fprintf(stderr,		     "Network or system error; (getinfo)  code: %d\n", ret);	 (void) fprintf(stderr,			"Perhaps your network is not running?\n");	 fprintf(stderr,		 "Contact Entropic if you cannot resolve this.\n");	 exit(-1);      }   ret = elm_getinfo(&info, WAVES_FEATURE, 0);	/* check for waves key */   if (ret > 0 && info.numlic && !expired(info.expiration))      return;   if (ret < 0)      switch (ret) {      case ELM_FAIL:      case ELM_ERROR:	 fprintf(stderr,		 "Sorry, you do not have a license for this feature.\n\                  Please contact Entropic if you think this is an error.\n");	 exit(-1);      case ELM_SRV_DOWN:	 if (h && h[0])	    fprintf(stderr, DOWN_MSG1, h, h);	 else	    fprintf(stderr, DOWN_MSG2);	 exit(-1);      default:	 (void) fprintf(stderr,		      "Network or system error; (getinfo) code: %d\n", ret);	 (void) fprintf(stderr,			"Perhaps your network is not running?\n");	 fprintf(stderr,		 "Contact Entropic if you cannot resolve this.\n");	 exit(-1);      }}voiders_check(feature)   char           *feature;{   int             ret;   assert(feature);   init(NULL);   ret = elm_getlicense(feature, ELM_GETLIC);   switch (ret) {   case ELM_OK:      break;   case ELM_WAIT:

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?