home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / k95inst.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  73KB  |  2,472 lines

  1. #include <windows.h>
  2. #define TAPI_CURRENT_VERSION 0x00010004
  3. #include <tapi.h>
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. #ifndef NULL
  10. #define NULL 0L
  11. #endif /* NULL */
  12.  
  13. #define _PROTOTYP( func, parms ) func parms
  14.  
  15. void Blowfish_encipher(unsigned long *xl, unsigned long *xr);
  16. void Blowfish_decipher(unsigned long *xl, unsigned long *xr);
  17. short InitializeBlowfish(unsigned char key[], short keybytes);
  18.  
  19. static char hexdigits[16] = {
  20.     '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  21. };
  22.  
  23. static long crcta[16] = { 0L, 010201L, 020402L, 030603L, 041004L,
  24.   051205L, 061406L, 071607L, 0102010L, 0112211L, 0122412L, 0132613L, 0143014L,
  25.   0153215L, 0163416L, 0173617L };
  26.  
  27. static long crctb[16] = { 0L, 010611L, 021422L, 031233L, 043044L,
  28.   053655L, 062466L, 072277L, 0106110L, 0116701L, 0127532L, 0137323L, 0145154L,
  29.   0155745L, 0164576L, 0174367L };
  30.  
  31.  
  32. /* 16-bit CRC */
  33.  
  34. unsigned int
  35. chk3(register unsigned char *pkt, register int len)  {
  36.     register long c, crc;
  37.     for (crc = 0; len-- > 0; pkt++) {
  38.     c = crc ^ (long)(*pkt);
  39.     crc = (crc >> 8) ^ (crcta[(c & 0xF0) >> 4] ^ crctb[c & 0x0F]);
  40.     }
  41.     return((unsigned int) (crc & 0xFFFF));
  42. }
  43.  
  44. int
  45. isWin95( void ) {
  46.     int OSVer = 0;
  47.     OSVERSIONINFO osverinfo ;
  48.     osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
  49.     GetVersionEx( &osverinfo ) ;
  50.     OSVer = osverinfo.dwPlatformId ;
  51.     return(OSVer==VER_PLATFORM_WIN32_WINDOWS);
  52. }
  53.  
  54. #define PRODUCT "K95-"            /* Must be 4 chars   */
  55. #define REVCODE "-1.1"            /* Must be 4 chars   */
  56. #define XOFFSET 37            /* Never change this */
  57.  
  58. struct
  59. ck_registration {            /* Registration structure */
  60.     char ident[32] ;
  61.     int is_set;
  62.     char serial[32];
  63.     char name[32];
  64.     char corp[32];
  65.     unsigned int crc;
  66.     unsigned long time;
  67. };
  68.  
  69. struct ck_sn {                /* Serial number structure */
  70.     int ok;
  71.     char product[5];
  72.     char serial[10];
  73.     char revcode[5];
  74. };
  75.  
  76. /*
  77.  This is the real registration struct that will be written over
  78.  in the registration procedure.
  79. */
  80. static struct                           /* A pre-Initialized */
  81. ck_registration ck_reg = {              /* registration structure */
  82. #ifdef COMMENT
  83.   "====758914360207174068160528073",    /* Ident */
  84.   0,                                    /* Recognizable strings... */
  85.   "^H^H^H^H^H^H^_{({({({(^^^^^^^^^",    /* Serial number */
  86.   "^C^C^C____^_^_^_^____)})})})})}",    /* Name */
  87.   "$(((((((((((())))))))))))^@^@^@",    /* Company */
  88.   0x5555,                               /* Dummy (and invalid) CRC */
  89.   0,                                    /* Install Time */
  90. #else
  91.     "",0,"","","",0,0
  92. #endif
  93. };
  94.  
  95. static char snbuf[32]="";               /* Serial number buffer */
  96.  
  97. /*
  98.   M A K S N
  99.  
  100.   Given a numeric serial number (long), make a Kermit product serial number.
  101.   Returns a pointer to the Kermit serial number, or a null pointer if
  102.   there is any error.
  103.  
  104.   The format of the Kermit product serial number is:
  105.  
  106.     PPPPnnnnXnnYnnnVVVV
  107.  
  108.   where:
  109.  
  110.     PPPP = 4-character product ID
  111.     nnnnnnnnn = 9-digit sequential serial number (decimal)
  112.     X = final digit of decimal 16-bit CRC
  113.     Y = penultimate digit of decimal 16-bit CRC
  114.     VVVV = 4-character revision ID
  115.  
  116.   The CRC is taken on PPPPnnnnnnnnn, and starts with the magic OFFSET.
  117. */
  118. char *
  119. maksn(char * product, long n, char * revcode) { /* Make serial number */
  120.     char tmpbuf[32];
  121.     unsigned int sum = XOFFSET;
  122.     int x, y;
  123.     if (n < 1L)
  124.       return(NULL);
  125.     sprintf(tmpbuf,"%4s%09ld",product,n);
  126.     sum += chk3(tmpbuf,strlen(tmpbuf));
  127.     x = sum % 10;
  128.     y = (sum / 10) % 10;
  129.     strncpy(snbuf,tmpbuf,8);
  130.     snbuf[8] = x + '0';
  131.     snbuf[9] = tmpbuf[8];
  132.     snbuf[10] = tmpbuf[9];
  133.     snbuf[11] = y + '0';
  134.     strncpy(snbuf+12,tmpbuf+10,3);
  135.     strncpy(snbuf+15,revcode,4);
  136.     return((char *)snbuf);
  137. }
  138.  
  139. /*
  140.   C H K S N
  141.  
  142.   Given a Kermit serial number, checks to see if it is valid.
  143.   Returns a pointer to struct ck_sn, in which the ok member is
  144.   set to 0 if the serial number is not valid, and nonzero if it is valid,
  145.   with the other members set to the product code, sequential serial number,
  146.   and revision code.
  147. */
  148. static struct ck_sn sn;
  149.  
  150. struct ck_sn *
  151. chksn(char * s) {
  152.     char tmpbuf[32];
  153.     int x=0, y=0;
  154.     int sum = XOFFSET;
  155.     static struct ck_sn * p=NULL;
  156.  
  157.     if (!s)
  158.         return(NULL);
  159.     if (!*s)
  160.         return(NULL);
  161.     if (strlen(s) != 19)
  162.         return(NULL);
  163.  
  164.     p = &sn;
  165.  
  166.     memset(tmpbuf,0,32) ;
  167.     strncpy(tmpbuf,s,8);
  168.     x = s[8] - '0';
  169.     tmpbuf[8] = s[9];
  170.     tmpbuf[9] = s[10];
  171.     y = s[11] - '0';
  172.     strncpy(tmpbuf+10,s+12,3);
  173.     sum += chk3(tmpbuf,strlen(tmpbuf));
  174.     sn.ok = 0;
  175.     if (x != sum % 10)
  176.         return(NULL);
  177.     if (y != (sum / 10) % 10)
  178.         return(NULL);
  179.     sn.ok = 1;
  180.     strncpy(sn.product,s,3);
  181.     strncpy(sn.serial,tmpbuf+4,9);
  182.     strncpy(sn.revcode,s+16,3);
  183.  
  184.     return(p);
  185. }
  186.  
  187. /*
  188.   C K _ E N C R Y P T
  189.  
  190.   Encrypt a string in place.
  191.   If given only 7-bit ascii graphic characters, this will produce a
  192.   string that still contains only 7-bit ascii graphic characters --
  193.   no control or 8-bit characters.
  194. */
  195. void
  196. ck_encrypt(char * s) {
  197.     while (*s) {
  198.         if (*s != 'p' && *s != '\\' && *s != 'S')
  199.           *s ^= 0x0F;
  200.         s++;
  201.     }
  202. }
  203.  
  204. /*   C K _ D E C R Y P T  -  Decrypt a string in place */
  205.  
  206. void
  207. ck_decrypt(char * s) {
  208.     while (*s) {
  209.         if (*s != 'p' && *s != '\\' && *s != 'S')
  210.           *s ^= 0x0F;
  211.         s++;
  212.     }
  213. }
  214.  
  215. /*  S E T C R C  -  Puts the CRC into the registration struct.  */
  216. /* This function is called after the ck_registration structure  */
  217. /* has been encrypted. */
  218.  
  219. int
  220. setcrc(struct ck_registration * r) {
  221.     char * p;
  222.     p = malloc(94);
  223.     memset( p, 0, 94 ) ;
  224.     if (p) {
  225.        strcpy(p,r->serial);
  226.        strcpy(p+31,r->name);
  227.        strcpy(p+62,r->corp);
  228.        r->crc = chk3(p,strlen(p));
  229.        free(p);
  230.        return(1);
  231.     } else r->crc = 0;
  232.     return(0);
  233. }
  234.  
  235. /*
  236.   I S R E G I S T E R E D
  237.  
  238.   Call with pointer to a registration struct.
  239.   Returns:
  240.    0 if not set
  241.   -2 if set but crc is bad
  242.   -1 if set but serial number is invalid
  243.    >0 if set and serial number is valid and crc is good
  244.      return value is decoded serial sequence number ;
  245. */
  246.  
  247. #ifdef NT
  248.     extern unsigned char (*xls[MAXTCSETS+1][MAXFCSETS+1])(unsigned char);  /* Character set xlate */
  249.     extern unsigned char (*xlr[MAXTCSETS+1][MAXFCSETS+1])(unsigned char);  /* functions. */
  250.     extern int tcsr, tcsl;          /* Terminal character sets, remote & local. */
  251. #endif /* NT */
  252.  
  253. char *
  254. get_reg_name(void) {
  255.     static char reg_name[32];
  256. #ifdef NT
  257.     int i;
  258.     unsigned char (*cs)(unsigned char) = xlr[(tcsl == TX_CP852) ? TC_2LATIN : TC_1LATIN][tx2fc(tcsl)];
  259. #endif
  260.    strncpy( reg_name, (char *) ck_reg.name, 32 ) ;
  261.    ck_decrypt( reg_name ) ;
  262. #ifdef NT
  263. #ifndef COMMENT
  264.    if (cs != NULL) {
  265.       for ( i=0;i<32;i++ )
  266.           reg_name[i] = (*cs)(reg_name[i]);
  267.    }
  268. #else
  269.     CharToOemBuff( reg_name, reg_name, 32 );
  270. #endif
  271. #endif
  272.    return(reg_name);
  273. }
  274. char *
  275. get_reg_corp(void) {
  276.    static char reg_corp[32] ;
  277. #ifdef NT
  278.     int i;
  279.     unsigned char (*cs)(unsigned char) = xlr[tcsl == TX_CP852 ? TC_2LATIN : TC_1LATIN][tx2fc(tcsl)];
  280. #endif
  281.    strncpy( reg_corp, (char *) ck_reg.corp, 32 ) ;
  282.    ck_decrypt( reg_corp ) ;
  283. #ifdef NT
  284.    if (cs != NULL) {
  285.     for ( i=0;i<32;i++ )
  286.         reg_corp[i] = (*cs)(reg_corp[i]);
  287.    }
  288. #endif
  289.    return(reg_corp);
  290. }
  291. char *
  292. get_reg_sn(void) {
  293.    static char serial[32] ;
  294. #ifdef NT
  295.     int i;
  296.     unsigned char (*cs)(unsigned char) = xlr[tcsl == TX_CP852 ? TC_2LATIN : TC_1LATIN][tx2fc(tcsl)];
  297. #endif
  298.    strncpy( serial, (char *) ck_reg.serial, 32 ) ;
  299.    ck_decrypt( serial ) ;
  300. #ifdef NT
  301.    if (cs != NULL) {
  302.     for ( i=0;i<32;i++ )
  303.         serial[i] = (*cs)(serial[i]);
  304.    }
  305. #endif
  306.    return(serial);
  307. }
  308.  
  309. int
  310. get_reg_count(void) {
  311.    return ck_reg.is_set ;
  312. }
  313.  
  314. int
  315. isregistered(struct ck_registration * r) {
  316.     unsigned int crc = 0;
  317.     char * p;
  318.     struct ck_sn * sn ;
  319.     char serial[32] ;
  320.  
  321.     if (!r) r = &ck_reg;
  322.     if (!(r->is_set))
  323.       return(0);
  324.     strncpy( serial, (char *) r->serial, 32 ) ;
  325.     ck_decrypt( serial ) ;
  326.     if (!(sn = chksn(serial)))
  327.       return(-1);
  328.     p = malloc(94);
  329.     memset( p, 0, 94 ) ;
  330.     if (p) {
  331.        strcpy(p,r->serial);
  332.        strcpy(p+31,r->name);
  333.        strcpy(p+62,r->corp);
  334.        crc = chk3(p,strlen(p));
  335.        free(p);
  336.     }
  337.     if (crc != r->crc)
  338.       return(-2);
  339.     return( atol( sn->serial ) );
  340. }
  341.  
  342. unsigned long
  343. regtime(struct ck_registration * r) {
  344.     if (!r) r = &ck_reg;
  345.     return(r->time);
  346. }
  347.  
  348. #define MAXELENGTH 511
  349. unsigned char ibuf[MAXELENGTH+1];
  350. unsigned char ebuf[MAXELENGTH+MAXELENGTH+5];
  351. unsigned char dbuf[MAXELENGTH+1];
  352.  
  353. unsigned char *
  354. ck_oox(s, key) char * s; char * key; {
  355.  
  356.     unsigned long left, right;
  357.     unsigned int i, k, l, n;
  358.     unsigned char *p, *q;
  359.  
  360.     if (!key) key = "";
  361.     if (!s) s = "";
  362.  
  363.     if ((k = (int)strlen(s)) > MAXELENGTH)
  364.       return((unsigned char *)"");
  365.  
  366.     memset(ibuf,'\0',MAXELENGTH+1);     /* 0-padded source buffer */
  367.     memset(ebuf,'\0',MAXELENGTH+MAXELENGTH+5); /* Clear destination buffer */
  368.     InitializeBlowfish((unsigned char *)key, (short)strlen(key));
  369.     strncpy(ibuf,(unsigned char *)s,MAXELENGTH); /* Copy source to padded cell */
  370.     p = ibuf;                           /* Point to padded source string */
  371.     n = k / 8;                          /* Number of 64-bit blocks */
  372.     if (k % 8) n++;                     /* Including possibly padded last */
  373.     q = ebuf;                           /* Pointer to destination buffer */
  374.     for (l = 0; l < n; l++) {           /* Loop for each block */
  375.         left = right = 0;               /* Init to all 0's */
  376. #ifdef COMMENT
  377.         memcpy((unsigned char *)&left,  p,   4);
  378.         memcpy((unsigned char *)&right, p+4, 4);
  379. #else
  380.         left  = *p + (*(p+1)<<8) + (*(p+2)<<16) + (*(p+3)<<24);
  381.         right = *(p+4) + (*(p+5)<<8) + (*(p+6)<<16) + (*(p+7)<<24);
  382. #endif
  383.         Blowfish_encipher(&left, &right); /* Output in hex because  */
  384.  
  385.  
  386.         for (i = 0; i < 8; i++) {         /* it might contain zeros */
  387.             *(q+i)   = hexdigits[(left  >> (4 * (7 - i))) & 0x0f];
  388.             *(q+i+8) = hexdigits[(right >> (4 * (7 - i))) & 0x0f];
  389.         }
  390.         p += 8;
  391.         q += 16;
  392.     }
  393.     return ((unsigned char *) ebuf);
  394. }
  395.  
  396. /*
  397.   Blowfish algorithm and code by Bruce Schneier, used by permission.
  398.   Adapted & fixed by fdc, Jan 96.
  399. */
  400. #define ORDER_DCBA
  401. #define inline _inline
  402.  
  403. #define MAXKEYBYTES   56                /* = 448 bits */
  404. #define bf_N          16
  405.  
  406. #define UWORD_32bits  unsigned long
  407. #define UBYTE_08bits  unsigned char
  408.  
  409. static UWORD_32bits bf_P[bf_N + 2];
  410. static UWORD_32bits bf_P_Init[bf_N + 2] = {
  411.   0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  412.   0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  413.   0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  414.   0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  415.   0x9216d5d9, 0x8979fb1b
  416. };
  417.  
  418. static UWORD_32bits bf_S[4][256];
  419. static UWORD_32bits bf_S_Init[4][256] = {
  420.   0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  421.   0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  422.   0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  423.   0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  424.   0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  425.   0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  426.   0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  427.   0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  428.   0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  429.   0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  430.   0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  431.   0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  432.   0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  433.   0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  434.   0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  435.   0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  436.   0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  437.   0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  438.   0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  439.   0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  440.   0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  441.   0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  442.   0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  443.   0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  444.   0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  445.   0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  446.   0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  447.   0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  448.   0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  449.   0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  450.   0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  451.   0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  452.   0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  453.   0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  454.   0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  455.   0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  456.   0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  457.   0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  458.   0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  459.   0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  460.   0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  461.   0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  462.   0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  463.   0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  464.   0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  465.   0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  466.   0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  467.   0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  468.   0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  469.   0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  470.   0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  471.   0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  472.   0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  473.   0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  474.   0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  475.   0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  476.   0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  477.   0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  478.   0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  479.   0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  480.   0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  481.   0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  482.   0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  483.   0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  484.   0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  485.   0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  486.   0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  487.   0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  488.   0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  489.   0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  490.   0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  491.   0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  492.   0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  493.   0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  494.   0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  495.   0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  496.   0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  497.   0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  498.   0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  499.   0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  500.   0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  501.   0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  502.   0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  503.   0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  504.   0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  505.   0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  506.   0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  507.   0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  508.   0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  509.   0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  510.   0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  511.   0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  512.   0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  513.   0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  514.   0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  515.   0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  516.   0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  517.   0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  518.   0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  519.   0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  520.   0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  521.   0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  522.   0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  523.   0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  524.   0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  525.   0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  526.   0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  527.   0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  528.   0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  529.   0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  530.   0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  531.   0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  532.   0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  533.   0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  534.   0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  535.   0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  536.   0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  537.   0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  538.   0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  539.   0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  540.   0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  541.   0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  542.   0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  543.   0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  544.   0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  545.   0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  546.   0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  547.   0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  548.   0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  549.   0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  550.   0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  551.   0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  552.   0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  553.   0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  554.   0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  555.   0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  556.   0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  557.   0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  558.   0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  559.   0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  560.   0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  561.   0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  562.   0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  563.   0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  564.   0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  565.   0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  566.   0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  567.   0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  568.   0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  569.   0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  570.   0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  571.   0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  572.   0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  573.   0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  574.   0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  575.   0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  576.   0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  577.   0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  578.   0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  579.   0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  580.   0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  581.   0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  582.   0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  583.   0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  584.   0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  585.   0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  586.   0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  587.   0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  588.   0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  589.   0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  590.   0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  591.   0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  592.   0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  593.   0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  594.   0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  595.   0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  596.   0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  597.   0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  598.   0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  599.   0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  600.   0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  601.   0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  602.   0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  603.   0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  604.   0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  605.   0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  606.   0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  607.   0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  608.   0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  609.   0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  610.   0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  611.   0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  612.   0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  613.   0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  614.   0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  615.   0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  616.   0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  617.   0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  618.   0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  619.   0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  620.   0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  621.   0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  622.   0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  623.   0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  624.   0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  625.   0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  626.   0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  627.   0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  628.   0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  629.   0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  630.   0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  631.   0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  632.   0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  633.   0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  634.   0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  635.   0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  636.   0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  637.   0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  638.   0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  639.   0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  640.   0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  641.   0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  642.   0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  643.   0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  644.   0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  645.   0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  646.   0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  647.   0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  648.   0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  649.   0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  650.   0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  651.   0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  652.   0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  653.   0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  654.   0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  655.   0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  656.   0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  657.   0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  658.   0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  659.   0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  660.   0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  661.   0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  662.   0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  663.   0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  664.   0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  665.   0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  666.   0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  667.   0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  668.   0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  669.   0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  670.   0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  671.   0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  672.   0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  673.   0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  674.   0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  675.   0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  676. };
  677.  
  678. /* Choose a byte order for your hardware */
  679.  
  680. union aword {
  681.     UWORD_32bits word;
  682.     UBYTE_08bits byte [4];
  683.     struct {
  684. #ifdef ORDER_ABCD                       /* ABCD - Big endian - Motorola */
  685.         UBYTE_08bits byte0;
  686.         UBYTE_08bits byte1;
  687.         UBYTE_08bits byte2;
  688.         UBYTE_08bits byte3;
  689. #else
  690. #ifdef ORDER_DCBA                       /* DCBA - Little endian - Intel */
  691.         UBYTE_08bits byte3;
  692.         UBYTE_08bits byte2;
  693.         UBYTE_08bits byte1;
  694.         UBYTE_08bits byte0;
  695. #else
  696. #ifdef ORDER_BADC               /* BADC - VAX */
  697.         UBYTE_08bits byte1;
  698.         UBYTE_08bits byte0;
  699.         UBYTE_08bits byte3;
  700.         UBYTE_08bits byte2;
  701. #else
  702. #ifdef ORDER_CDAB               /* CDAB - who knows */
  703.         UBYTE_08bits byte2;
  704.         UBYTE_08bits byte3;
  705.         UBYTE_08bits byte0;
  706.         UBYTE_08bits byte1;
  707. #else
  708.         BYTE_ORDER_IS_NOT_DEFINED
  709. #endif  /* ORDER_CDAB */
  710. #endif  /* ORDER_BADC */
  711. #endif  /* ORDER_DCBA */
  712. #endif  /* ORDER_ABCD */
  713.     } w;
  714. };
  715.  
  716.  
  717. /*********************blowfish.c*********************/
  718.  
  719. #define S(x,i) (bf_S[i][(x.word>>(24-8*i))&(0x00FF)])
  720. #define bf_F(x) (((S(x,0) + S(x,1)) ^ S(x,2)) + S(x,3))
  721. #define ROUND(a,b,n) (a.word ^= bf_F(b) ^ bf_P[n])
  722.  
  723. void
  724. Blowfish_encipher(UWORD_32bits *xl, UWORD_32bits *xr) {
  725.     union aword Xl;
  726.     union aword Xr;
  727.  
  728.     Xl.word = *xl;
  729.     Xr.word = *xr;
  730.     Xl.word ^= bf_P[0];
  731.  
  732.     ROUND (Xr, Xl, 1);
  733.     ROUND (Xl, Xr, 2);
  734.     ROUND (Xr, Xl, 3);
  735.     ROUND (Xl, Xr, 4);
  736.     ROUND (Xr, Xl, 5);
  737.     ROUND (Xl, Xr, 6);
  738.     ROUND (Xr, Xl, 7);
  739.     ROUND (Xl, Xr, 8);
  740.     ROUND (Xr, Xl, 9);
  741.     ROUND (Xl, Xr, 10);
  742.     ROUND (Xr, Xl, 11);
  743.     ROUND (Xl, Xr, 12);
  744.     ROUND (Xr, Xl, 13);
  745.     ROUND (Xl, Xr, 14);
  746.     ROUND (Xr, Xl, 15);
  747.     ROUND (Xl, Xr, 16);
  748.     Xr.word ^= bf_P[17];
  749.  
  750.     *xr = Xl.word;
  751.     *xl = Xr.word;
  752. }
  753.  
  754. void
  755. Blowfish_decipher(UWORD_32bits *xl, UWORD_32bits *xr) {
  756.     union aword  Xl;
  757.     union aword  Xr;
  758.  
  759.     Xl.word = *xl;
  760.     Xr.word = *xr;
  761.     Xl.word ^= bf_P[17];
  762.  
  763.     ROUND (Xr, Xl, 16);  ROUND (Xl, Xr, 15);
  764.     ROUND (Xr, Xl, 14);  ROUND (Xl, Xr, 13);
  765.     ROUND (Xr, Xl, 12);  ROUND (Xl, Xr, 11);
  766.     ROUND (Xr, Xl, 10);  ROUND (Xl, Xr, 9);
  767.     ROUND (Xr, Xl, 8);   ROUND (Xl, Xr, 7);
  768.     ROUND (Xr, Xl, 6);   ROUND (Xl, Xr, 5);
  769.     ROUND (Xr, Xl, 4);   ROUND (Xl, Xr, 3);
  770.     ROUND (Xr, Xl, 2);   ROUND (Xl, Xr, 1);
  771.     Xr.word ^= bf_P[0];
  772.  
  773.     *xl = Xr.word;
  774.     *xr = Xl.word;
  775. }
  776.  
  777. short
  778. InitializeBlowfish(UBYTE_08bits key[], short keybytes) {
  779.     short         i;
  780.     short         j;
  781.     UWORD_32bits  data;
  782.     UWORD_32bits  datal;
  783.     UWORD_32bits  datar;
  784.     union aword   temp;
  785.  
  786.     if (keybytes < 1) keybytes = 1;
  787.     memcpy(bf_P,bf_P_Init,sizeof(bf_P_Init));
  788.     memcpy(bf_S,bf_S_Init,sizeof(bf_S_Init));
  789.  
  790.     j = 0;
  791.     for (i = 0; i < bf_N + 2; ++i) {
  792.         temp.word = 0;
  793.         temp.w.byte0 = key[j];
  794.         temp.w.byte1 = key[(j+1)%keybytes];
  795.         temp.w.byte2 = key[(j+2)%keybytes];
  796.         temp.w.byte3 = key[(j+3)%keybytes];
  797.         data = temp.word;
  798.         bf_P[i] = bf_P[i] ^ data;
  799.         j = (j + 4) % keybytes;
  800.     }
  801.     datal = 0x00000000;
  802.     datar = 0x00000000;
  803.  
  804.     for (i = 0; i < bf_N + 2; i += 2) {
  805.         Blowfish_encipher(&datal, &datar);
  806.         bf_P[i] = datal;
  807.         bf_P[i + 1] = datar;
  808.     }
  809.     for (i = 0; i < 4; ++i) {
  810.         for (j = 0; j < 256; j += 2) {
  811.             Blowfish_encipher(&datal, &datar);
  812.             bf_S[i][j] = datal;
  813.             bf_S[i][j + 1] = datar;
  814.         }
  815.     }
  816.     return 0;
  817. }
  818.  
  819. /* START EXPORTED FUNCTIONS */
  820.  
  821. __declspec(dllexport) DWORD _stdcall
  822. validate_serial_no(char * serialno) 
  823. {
  824.     struct ck_sn * sn;
  825.  
  826.     if ( sn = chksn(serialno) ) {
  827.         if (sn->ok && !strcmp("K95",sn->product) && !strcmp("1.1",sn->revcode) )
  828.             return(1);
  829.     }
  830.     return(0);
  831. }       
  832.  
  833. #ifdef COMMENT
  834. typedef struct _PRINTER_INFO_2 { // pri2
  835.     LPTSTR    pServerName;
  836.     LPTSTR    pPrinterName;
  837.     LPTSTR    pShareName;
  838.     LPTSTR    pPortName;
  839.     LPTSTR    pDriverName;
  840.     LPTSTR    pComment;
  841.     LPTSTR    pLocation;
  842.     LPDEVMODE pDevMode;
  843.     LPTSTR    pSepFile;
  844.     LPTSTR    pPrintProcessor;
  845.     LPTSTR    pDatatype;
  846.     LPTSTR    pParameters;
  847.     PSECURITY_DESCRIPTOR pSecurityDescriptor;
  848.     DWORD     Attributes;
  849.     DWORD     Priority;
  850.     DWORD     DefaultPriority;
  851.     DWORD     StartTime;
  852.     DWORD     UntilTime;
  853.     DWORD     Status;
  854.     DWORD     cJobs;
  855.     DWORD     AveragePPM;
  856. } PRINTER_INFO_2;
  857. #endif
  858.  
  859. static char ** printer_list = NULL;
  860. static int     printer_cnt  = 0;
  861.  
  862. __declspec(dllexport) DWORD _stdcall
  863. init_printer_list(void)
  864. {
  865.     DWORD  dwBytesNeeded;
  866.     DWORD  dwPrtRet2;
  867.     LPTSTR lpName = NULL;
  868.     DWORD  dwEnumFlags = PRINTER_ENUM_LOCAL;
  869.     DWORD  dwLevel =2;
  870.     LPPRINTER_INFO_2 pPrtInfo2=NULL;
  871.     int i;
  872.  
  873.     if ( printer_list )
  874.     {
  875.         for ( i=0 ; i < printer_cnt ; i++ )
  876.             free( printer_list[i] ) ;
  877.         free ( printer_list )  ;
  878.     }
  879.     printer_list = NULL;
  880.     printer_cnt = 0;
  881.  
  882.     if ( !isWin95() )
  883.         dwEnumFlags |= PRINTER_ENUM_CONNECTIONS;
  884.  
  885.     //
  886.     // get byte count needed for buffer, alloc buffer, the enum the printers
  887.     //
  888.  
  889.     EnumPrinters (dwEnumFlags, lpName, dwLevel, NULL, 0, &dwBytesNeeded,
  890.                    &dwPrtRet2);
  891.  
  892.     //
  893.     // (simple error checking, if these work assume rest will too)
  894.     //
  895.  
  896.     if (!(pPrtInfo2 = (LPPRINTER_INFO_2) LocalAlloc (LPTR, dwBytesNeeded)))
  897.     {
  898.         return(0);
  899.     }
  900.  
  901.     if (!EnumPrinters (dwEnumFlags, lpName, dwLevel,
  902.                       (LPBYTE) pPrtInfo2,
  903.                         dwBytesNeeded, &dwBytesNeeded, &dwPrtRet2))
  904.     {
  905.         LocalFree( (LPBYTE) pPrtInfo2 );
  906.         return(0);
  907.     }
  908.  
  909.     /* we now have an enumeration of all printer names */
  910.  
  911.     printer_list = (char **) malloc( dwPrtRet2 * sizeof(char *) );
  912.     if ( !printer_list )
  913.     {
  914.         LocalFree( (LPBYTE) pPrtInfo2 );
  915.         return(0);
  916.     }
  917.  
  918.     for ( i=0 ; i<dwPrtRet2 ; i++ )
  919.          printer_list[i] = strdup( pPrtInfo2[i].pPrinterName );
  920.     printer_cnt = dwPrtRet2 ;
  921.  
  922.     LocalFree( (LPBYTE) pPrtInfo2 );
  923.     return(printer_cnt);
  924. }
  925.  
  926. __declspec(dllexport) DWORD _stdcall
  927. get_printer_display_string(int index, char * str, int len)
  928. {
  929.     if ( index < 0 || index >= printer_cnt || !printer_list )
  930.         return(0);
  931.  
  932.     if ( len < strlen(printer_list[index]) + 1 )
  933.         return(-(long)strlen(printer_list[index]));
  934.  
  935.     strncpy(str,printer_list[index],len);
  936.     str[len-1] = '\0';
  937.     return(1);
  938. }
  939.  
  940. __declspec(dllexport) DWORD _stdcall
  941. get_printer_config_string(int index, char * str, int len)
  942. {
  943.     char * s;
  944.  
  945.     if ( index < 0 || index >= printer_cnt || !printer_list )
  946.         return(0);
  947.  
  948.     if ( len < strlen(printer_list[index]) + 1 )
  949.         return(-(long)strlen(printer_list[index]));
  950.  
  951.     strncpy(str,printer_list[index],len);
  952.     str[len-1] = '\0';
  953.  
  954.     for (s = str; *s; s++) {
  955.         switch ( *s ) {
  956.         case ' ':
  957.             *s = '_';
  958.             break;
  959.         case ',':
  960.             *s = '.';
  961.             break;
  962.         case ';':
  963.             *s = ':';
  964.             break;
  965.         case '\\':
  966.             *s = '/';
  967.             break;
  968.         case '?':
  969.             *s = '!';
  970.             break;
  971.         case '{':
  972.             *s = '[';
  973.             break;
  974.         case '}':
  975.             *s = ']';
  976.             break;
  977.         default:
  978.             *s = tolower(*s);
  979.         }
  980.     }
  981.     return(1);
  982. }
  983.  
  984.  
  985. /* BEGIN TAPI CODE */
  986.  
  987. LONG (WINAPI *cklineInitialize)(LPHLINEAPP, HINSTANCE, LINECALLBACK, LPCSTR, LPDWORD ) = NULL ;
  988. LONG (WINAPI *cklineNegotiateAPIVersion)(HLINEAPP, DWORD, DWORD, DWORD, LPDWORD, LPLINEEXTENSIONID) = NULL ;
  989. LONG (WINAPI *cklineGetDevCaps)(HLINEAPP, DWORD, DWORD, DWORD, LPLINEDEVCAPS) = NULL ;
  990. LONG (WINAPI *cklineShutdown)(HLINEAPP) = NULL ;
  991. LONG (WINAPI *cklineOpen)(HLINEAPP, DWORD, LPHLINE, DWORD, DWORD, DWORD, DWORD, DWORD, 
  992.                   LPLINECALLPARAMS) = NULL ;
  993. LONG (WINAPI *cklineMakeCall)(HLINE hLine, LPHCALL lphCall, LPCSTR lpszDestAddress, 
  994.                       DWORD dwCountryCode, LPLINECALLPARAMS const lpCallParams) = NULL ;
  995. LONG (WINAPI *cklineDial)(HCALL hCall, LPCSTR lpszDestAddress, DWORD dwCountryCode) = NULL ;
  996. LONG (WINAPI *cklineDrop)(HCALL hCall, LPCSTR lpsUserUserInfo, DWORD dwSize) = NULL ;
  997. LONG (WINAPI *cklineAnswer)(HCALL hCall, LPCSTR lpsUserUserInfo, DWORD dwSize) = NULL ;
  998. LONG (WINAPI *cklineAccept)(HCALL hCall, LPCSTR lpsUserUserInfo, DWORD dwSize) = NULL ;
  999. LONG (WINAPI *cklineDeallocateCall)(HCALL hCall) = NULL ;
  1000. LONG (WINAPI *cklineSetCallPrivilege)(HCALL,DWORD) = NULL ;
  1001. LONG (WINAPI *cklineClose)(HLINE hLine) = NULL ;
  1002. LONG (WINAPI *cklineHandoff)(HCALL,LPCSTR,DWORD) = NULL ;
  1003. LONG (WINAPI *cklineGetID)(HLINE hLine, DWORD dwAddressID, HCALL hCall, 
  1004.                DWORD dwSelect, LPVARSTRING lpDeviceID, LPCSTR lpszDeviceClass) = NULL ;
  1005. LONG (WINAPI *cklineGetTranslateCaps)( HLINEAPP hLineApp, DWORD, 
  1006.                                        LPLINETRANSLATECAPS lpLineTranslateCaps) = NULL ;
  1007. LONG (WINAPI *cklineSetCurrentLocation)( HLINEAPP hLineApp, DWORD dwLocationID ) = NULL ;
  1008. LONG (WINAPI *cklineSetStatusMessages)( HLINE hLine, DWORD dwLineStates, 
  1009.                                         DWORD dwAddressStates ) = NULL ;
  1010. LONG (WINAPI *cklineConfigDialog)( DWORD dwLine, HWND hwin, LPCSTR lpszTypes ) = NULL ;
  1011. LONG (WINAPI *cklineTranslateDialog)( HLINEAPP hTAPI, DWORD dwLine, DWORD dwVersionToUse,
  1012.                       HWND hwndOwner, LPCSTR lpszAddressIn ) = NULL ;
  1013. LONG (WINAPI *cklineTranslateAddress)( HLINEAPP hTAPI, DWORD dwLine, DWORD dwVersionToUse,
  1014.                        LPCSTR lpszAddressIn, DWORD dwCard,
  1015.                        DWORD dwTranslateOptions,
  1016.                        LPLINETRANSLATEOUTPUT lpTranslateOutput) = NULL ;
  1017. LONG (WINAPI *cklineGetCountry)( DWORD, DWORD, LPLINECOUNTRYLIST ) = NULL;
  1018. LONG (WINAPI *cklineGetDevConfig)(DWORD, LPVARSTRING, LPCSTR) = NULL;
  1019. LONG (WINAPI *cklineGetLineDevStatus)(HLINE hLine,LPLINEDEVSTATUS lpLineDevStatus)=NULL;
  1020. LONG (WINAPI *cklineSetDevConfig)(DWORD,LPVOID const,DWORD,LPCSTR)=NULL;
  1021. LONG (WINAPI *cklineGetCallInfo)(HCALL, LPLINECALLINFO)=NULL;
  1022. LONG (WINAPI *cklineMonitorMedia)(HCALL,DWORD)=NULL;
  1023. LONG (WINAPI *cklineGetAppPriority)(LPCSTR,DWORD,LPLINEEXTENSIONID,
  1024.                      DWORD,LPVARSTRING,LPDWORD)=NULL;
  1025. LONG (WINAPI *cklineSetAppPriority)(LPCSTR,DWORD,LPLINEEXTENSIONID,
  1026.                      DWORD,LPCSTR,DWORD)=NULL;
  1027. LONG (WINAPI *cklineGetNumRings)(HLINE,DWORD,LPDWORD)=NULL;
  1028. LONG (WINAPI *cklineSetNumRings)(HLINE,DWORD,DWORD)=NULL;
  1029. LONG (WINAPI *cklineSetCallParams)(HCALL,DWORD,DWORD,DWORD,LPLINEDIALPARAMS)=NULL;
  1030.  
  1031. void 
  1032. CALLBACK
  1033. cklineCallbackFunc( DWORD dwDevice, DWORD dwMsg, 
  1034.                     DWORD dwCallbackInstance,
  1035.                     DWORD dwParam1, DWORD dwParam2, DWORD dwParam3)
  1036. {
  1037.     return;
  1038. }
  1039.  
  1040. void
  1041. OutputDebugLastError( DWORD x, char * string )
  1042. {
  1043.     return;
  1044. }
  1045.  
  1046. void
  1047. HandleNoMem( ) 
  1048. {
  1049.     return;
  1050. }
  1051.  
  1052. void 
  1053. OutputDebugLineError( long param, char * str )
  1054. {
  1055.     return;
  1056. }
  1057.  
  1058. BOOL 
  1059. HandleLineErr(long lLineErr)
  1060. {
  1061.     if ( lLineErr )
  1062.     return FALSE;
  1063.     else 
  1064.         return TRUE ;
  1065. }
  1066.  
  1067. BOOL 
  1068. HandleNoDevicesInstalled(void)
  1069. {
  1070.     return FALSE;
  1071. }
  1072.  
  1073.  
  1074. HINSTANCE hLib = NULL ;
  1075. HLINEAPP g_hLineApp = NULL;
  1076. BOOL     g_bInitializing = FALSE;
  1077. BOOL     g_bClosing = FALSE;
  1078. int tapiopen = 0 ;
  1079. int ttyfd=-1 ; /* this holds the HLINE hLine */
  1080. #define MAXDEVS 64
  1081. LPLINEDEVCAPS g_lpLineDevCaps[64] ;
  1082. DWORD   g_dwNumDevs = -1;
  1083. HLINE g_hLine = NULL;
  1084.  
  1085. int 
  1086. cktapiunload(void)
  1087. {
  1088.     FreeLibrary( hLib ) ;
  1089.     hLib = NULL ;
  1090.     cklineInitialize = NULL ;
  1091.     return TRUE ;
  1092. }
  1093.  
  1094.  
  1095. int cktapiload(void) 
  1096. {
  1097.    DWORD rc = 0 ;
  1098.     hLib = LoadLibrary("tapi32") ;
  1099.    if ( !hLib )
  1100.    {
  1101.       rc = GetLastError() ;
  1102.       return FALSE;
  1103.    }
  1104.  
  1105.    if (((FARPROC) cklineInitialize = GetProcAddress( hLib, "lineInitialize" )) == NULL )
  1106.    {
  1107.       rc = GetLastError() ;
  1108.       return FALSE;
  1109.    }
  1110.    if (((FARPROC) cklineNegotiateAPIVersion = GetProcAddress( hLib, "lineNegotiateAPIVersion" )) == NULL )
  1111.    {
  1112.       rc = GetLastError() ;
  1113.       return FALSE;
  1114.    }
  1115.    if (((FARPROC) cklineGetDevCaps = GetProcAddress( hLib, "lineGetDevCaps" )) == NULL )
  1116.    {
  1117.       rc = GetLastError() ;
  1118.       return FALSE;
  1119.    }
  1120.    if (((FARPROC) cklineShutdown = GetProcAddress( hLib, "lineShutdown" )) == NULL )
  1121.    {
  1122.       rc = GetLastError() ;
  1123.       return FALSE;
  1124.    }
  1125.    if (((FARPROC) cklineOpen = GetProcAddress( hLib, "lineOpen" )) == NULL )
  1126.    {
  1127.       rc = GetLastError() ;
  1128.       return FALSE;
  1129.    }
  1130.    if (((FARPROC) cklineMakeCall = GetProcAddress( hLib, "lineMakeCall" )) == NULL )
  1131.    {
  1132.       rc = GetLastError() ;
  1133.       return FALSE;
  1134.    }
  1135.    if (((FARPROC) cklineDial = GetProcAddress( hLib, "lineDial" )) == NULL )
  1136.    {
  1137.       rc = GetLastError() ;
  1138.       return FALSE;
  1139.    }
  1140.    if (((FARPROC) cklineDrop = GetProcAddress( hLib, "lineDrop" )) == NULL )
  1141.    {
  1142.       rc = GetLastError() ;
  1143.       return FALSE;
  1144.    }
  1145.     if (((FARPROC) cklineAnswer = GetProcAddress( hLib, "lineAnswer" )) == NULL )
  1146.     {
  1147.     rc = GetLastError() ;
  1148.         return FALSE;
  1149.     }
  1150.     if (((FARPROC) cklineAccept = GetProcAddress( hLib, "lineAccept" )) == NULL )
  1151.     {
  1152.     rc = GetLastError() ;
  1153.     return FALSE;
  1154.     }
  1155.     if (((FARPROC) cklineDeallocateCall = GetProcAddress( hLib, "lineDeallocateCall" )) == NULL )
  1156.     {
  1157.     rc = GetLastError() ;
  1158.     return FALSE;
  1159.     }
  1160.     if (((FARPROC) cklineClose = GetProcAddress( hLib, "lineClose" )) == NULL )
  1161.    {
  1162.       rc = GetLastError() ;
  1163.       return FALSE;
  1164.    }
  1165.    if (((FARPROC) cklineGetID = GetProcAddress( hLib, "lineGetID" )) == NULL )
  1166.    {
  1167.       rc = GetLastError() ;
  1168.       return FALSE;
  1169.    }
  1170.    if (((FARPROC) cklineGetTranslateCaps = GetProcAddress( hLib, "lineGetTranslateCaps" )) == NULL )
  1171.    {
  1172.       rc = GetLastError() ;
  1173.       return FALSE;
  1174.    }
  1175.    if (((FARPROC) cklineSetCurrentLocation = GetProcAddress( hLib, "lineSetCurrentLocation" )) == NULL )
  1176.    {
  1177.       rc = GetLastError() ;
  1178.       return FALSE;
  1179.    }
  1180.    if (((FARPROC) cklineSetStatusMessages = GetProcAddress( hLib, "lineSetStatusMessages" )) == NULL )
  1181.    {
  1182.       rc = GetLastError() ;
  1183.       return FALSE;
  1184.    }
  1185.     if (((FARPROC) cklineConfigDialog = GetProcAddress( hLib, "lineConfigDialog" )) == NULL )
  1186.     {
  1187.     rc = GetLastError() ;
  1188.     return FALSE;
  1189.     }
  1190.     if (((FARPROC) cklineTranslateDialog = GetProcAddress( hLib, "lineTranslateDialog" )) == NULL )
  1191.     {
  1192.     rc = GetLastError() ;
  1193.     return FALSE;
  1194.     }
  1195.     if (((FARPROC) cklineTranslateAddress = 
  1196.       GetProcAddress( hLib, "lineTranslateAddress" )) == NULL )
  1197.     {
  1198.     rc = GetLastError() ;
  1199.     return FALSE;
  1200.     }
  1201.     if (((FARPROC) cklineGetCountry = 
  1202.       GetProcAddress( hLib, "lineGetCountry" )) == NULL )
  1203.     {
  1204.     rc = GetLastError() ;
  1205.     return FALSE;
  1206.     }
  1207.     if (((FARPROC) cklineGetLineDevStatus = 
  1208.       GetProcAddress( hLib, "lineGetLineDevStatus" )) == NULL )
  1209.     {
  1210.     rc = GetLastError() ;
  1211.     return FALSE;
  1212.     }
  1213.     if (((FARPROC) cklineGetDevConfig = 
  1214.       GetProcAddress( hLib, "lineGetDevConfig" )) == NULL )
  1215.     {
  1216.     rc = GetLastError() ;
  1217.     return FALSE;
  1218.     }
  1219.     if (((FARPROC) cklineSetDevConfig = 
  1220.       GetProcAddress( hLib, "lineSetDevConfig" )) == NULL )
  1221.     {
  1222.     rc = GetLastError() ;
  1223.     return FALSE;
  1224.     }
  1225.     if (((FARPROC) cklineHandoff = 
  1226.       GetProcAddress( hLib, "lineHandoff" )) == NULL )
  1227.     {
  1228.     rc = GetLastError() ;
  1229.     return FALSE;
  1230.     }
  1231.     if (((FARPROC) cklineSetCallPrivilege = 
  1232.       GetProcAddress( hLib, "lineSetCallPrivilege" )) == NULL )
  1233.     {
  1234.     rc = GetLastError() ;
  1235.     return FALSE;
  1236.     }
  1237.     if (((FARPROC) cklineGetCallInfo = 
  1238.       GetProcAddress( hLib, "lineGetCallInfo" )) == NULL )
  1239.     {
  1240.     rc = GetLastError() ;
  1241.     return FALSE;
  1242.     }
  1243.     if (((FARPROC) cklineMonitorMedia = 
  1244.       GetProcAddress( hLib, "lineMonitorMedia" )) == NULL )
  1245.     {
  1246.     rc = GetLastError() ;
  1247.     return FALSE;
  1248.     }
  1249.     if (((FARPROC) cklineGetAppPriority = 
  1250.       GetProcAddress( hLib, "lineGetAppPriority" )) == NULL )
  1251.     {
  1252.     rc = GetLastError() ;
  1253.     return FALSE;
  1254.     }
  1255.     if (((FARPROC) cklineSetAppPriority = 
  1256.       GetProcAddress( hLib, "lineSetAppPriority" )) == NULL )
  1257.     {
  1258.     rc = GetLastError() ;
  1259.     return FALSE;
  1260.     }
  1261.     if (((FARPROC) cklineGetNumRings = 
  1262.       GetProcAddress( hLib, "lineGetNumRings" )) == NULL )
  1263.     {
  1264.     rc = GetLastError() ;
  1265.     return FALSE;
  1266.     }
  1267.     if (((FARPROC) cklineSetNumRings = 
  1268.       GetProcAddress( hLib, "lineSetNumRings" )) == NULL )
  1269.     {
  1270.     rc = GetLastError() ;
  1271.     return FALSE;
  1272.     }
  1273.     if (((FARPROC) cklineSetCallParams = 
  1274.       GetProcAddress( hLib, "lineSetCallParams" )) == NULL )
  1275.     {
  1276.     rc = GetLastError() ;
  1277.     return FALSE;
  1278.     }
  1279.     return TRUE;
  1280. }
  1281.  
  1282. BOOL g_bLineInitialized = FALSE;
  1283. void
  1284. wintapiinit( void )
  1285. {
  1286.     long lReturn;
  1287.     BOOL bTryReInit = TRUE ;
  1288.     
  1289.     // Initialize TAPI
  1290.     do
  1291.     {
  1292.         lReturn = (*cklineInitialize)(&g_hLineApp, GetModuleHandle(NULL), 
  1293.              cklineCallbackFunc, "K95 Setup", &g_dwNumDevs);
  1294.     OutputDebugLastError(lReturn,"lineInitialize:");
  1295.  
  1296.         // If we get this error, its because some other app has yet
  1297.         // to respond to the REINIT message.  Wait 5 seconds and try
  1298.         // again.  If it still doesn't respond, tell the user.
  1299.         if (lReturn == LINEERR_REINIT)
  1300.         {
  1301.             if (bTryReInit)
  1302.             {
  1303.         Sleep(5000);    /* wait 5 secs, try again */
  1304.                 bTryReInit = FALSE;
  1305.                 continue;
  1306.             }
  1307.             else
  1308.             {
  1309.                 g_bInitializing = FALSE;
  1310.                 return;
  1311.             }
  1312.         }
  1313.  
  1314.         if (lReturn == LINEERR_NODEVICE)
  1315.         {
  1316.             if (HandleNoDevicesInstalled())
  1317.                 continue;
  1318.             else
  1319.             {
  1320.                 g_bInitializing = FALSE;
  1321.                 return;
  1322.             }
  1323.         }
  1324.  
  1325.         if (HandleLineErr(lReturn))
  1326.             continue;
  1327.         else
  1328.         {
  1329.             OutputDebugLineError(lReturn, 
  1330.                 "lineInitialize unhandled error: ");
  1331.             g_bInitializing = FALSE;
  1332.             return;
  1333.         }
  1334.     }
  1335.     while(lReturn != 0);
  1336.  
  1337.     g_bLineInitialized = TRUE;
  1338. }
  1339.  
  1340. int 
  1341. cktapiopen(void)
  1342. {
  1343.     if ( g_bClosing ) {
  1344.     while ( g_bClosing )
  1345.         Sleep(500);
  1346.     }
  1347.     if ( tapiopen )
  1348.     {
  1349.     tapiopen++ ;
  1350.     return TRUE ;
  1351.     }
  1352.  
  1353.     g_bLineInitialized = FALSE;
  1354.     wintapiinit();
  1355.  
  1356.     if ( !g_bLineInitialized )
  1357.     return FALSE;
  1358.  
  1359.     tapiopen++;
  1360.     return TRUE;
  1361. }
  1362.  
  1363. int 
  1364. cktapidevenum( void )
  1365. {
  1366.     int i = 0 ;
  1367.     DWORD dwAPIVersion ;                    
  1368.     LINEEXTENSIONID ExtensionID ;
  1369.     int datalines = 0 ;
  1370.     LONG rc;
  1371.  
  1372.  
  1373.     /* Free existing LineDevCaps */
  1374.     for ( i = 0 ; i < g_dwNumDevs ; i++ )
  1375.     {
  1376.     if ( g_lpLineDevCaps[i] )
  1377.     {
  1378.         free( g_lpLineDevCaps[i] ) ;
  1379.         g_lpLineDevCaps[i] = NULL ;
  1380.     }
  1381.     }
  1382.  
  1383.     /* Enumerate current LineDevCaps */
  1384.     for ( i=0 ; i < g_dwNumDevs ; i++ )
  1385.     {
  1386.     g_lpLineDevCaps[i] = (LPLINEDEVCAPS) malloc (sizeof(LINEDEVCAPS)) ;
  1387.     g_lpLineDevCaps[i]->dwTotalSize = sizeof(LINEDEVCAPS) ;
  1388.     if ( rc = (*cklineNegotiateAPIVersion)(g_hLineApp, i, 
  1389.                        TAPI_CURRENT_VERSION, 
  1390.                        TAPI_CURRENT_VERSION,
  1391.                        &dwAPIVersion, &ExtensionID))
  1392.     {
  1393.         OutputDebugLastError(rc,"lineNegotiateAPIVersion:");
  1394.         free(g_lpLineDevCaps[i]);
  1395.         g_lpLineDevCaps[i] = NULL ;
  1396.         continue;
  1397.     }
  1398.     if (rc = (*cklineGetDevCaps)(g_hLineApp, i,
  1399.                  dwAPIVersion, 0, g_lpLineDevCaps[i]))
  1400.     {
  1401.         OutputDebugLastError(rc,"lineGetDevCaps:");
  1402.         free(g_lpLineDevCaps[i]);
  1403.         g_lpLineDevCaps[i] = NULL ;
  1404.         continue;
  1405.     }
  1406.  
  1407.     if ( g_lpLineDevCaps[i]->dwNeededSize > g_lpLineDevCaps[i]->dwTotalSize )
  1408.     {
  1409.         DWORD NeededSize = g_lpLineDevCaps[i]->dwNeededSize;
  1410.         free(g_lpLineDevCaps[i]) ;
  1411.         g_lpLineDevCaps[i] = (LPLINEDEVCAPS) malloc (NeededSize) ;
  1412.         g_lpLineDevCaps[i]->dwTotalSize = NeededSize ;
  1413.  
  1414.         if ((*cklineGetDevCaps)(g_hLineApp, i,
  1415.                                dwAPIVersion, 0, g_lpLineDevCaps[i]))
  1416.         {
  1417.         OutputDebugLastError(rc,"lineGetDevCaps:");
  1418.         free(g_lpLineDevCaps[i]);
  1419.         g_lpLineDevCaps[i] = NULL ;
  1420.         continue;
  1421.         }
  1422.     }
  1423.  
  1424.       /* We now have a successful LineDevCaps structure */
  1425.     if ( g_lpLineDevCaps[i]->dwMediaModes & LINEMEDIAMODE_DATAMODEM )
  1426.     {
  1427.          /* then this is a valid line to use for data connections */
  1428.         datalines++ ;
  1429.     }
  1430.     }
  1431.     return datalines ;
  1432. }
  1433.  
  1434. int 
  1435. cktapiclose(void)
  1436. {
  1437.     DWORD rc ;
  1438.  
  1439.     if ( g_bClosing ) {
  1440.     while ( g_bClosing )
  1441.         Sleep(500);
  1442.     return TRUE;
  1443.     }
  1444.  
  1445.     if ( tapiopen > 0 )
  1446.     {
  1447.     tapiopen-- ;
  1448.  
  1449.     if ( tapiopen == 1 ) {
  1450.         g_bClosing = TRUE;
  1451.         if ( g_hLine )
  1452.         {    
  1453.         rc = (*cklineClose)( g_hLine );
  1454.         OutputDebugLastError(rc,"lineClose:");
  1455.         g_hLine = NULL ;
  1456.         ttyfd = -1;
  1457.         }
  1458.     }
  1459.     if ( tapiopen == 0 ) {
  1460.         rc = (*cklineShutdown)( g_hLineApp ) ;
  1461.         OutputDebugLastError(rc,"lineShutdown:");
  1462.         g_hLineApp = NULL ;
  1463.     }
  1464.     g_bClosing = FALSE;
  1465.     }
  1466.     return TRUE;
  1467. }
  1468.  
  1469. static char ** tapi_list = NULL;
  1470. static int     tapi_cnt  = 0;
  1471.  
  1472. __declspec(dllexport) DWORD _stdcall
  1473. init_tapi_list(void)
  1474. {
  1475.     int i, n ;
  1476.     if ( tapi_list )
  1477.     {
  1478.         for ( i=0 ; i < tapi_cnt ; i++ )
  1479.             free( tapi_list[i] ) ;
  1480.         free ( tapi_list )  ;
  1481.     }
  1482.  
  1483.     tapi_list = NULL ;
  1484.     tapi_cnt = 0 ;
  1485.  
  1486.     if (!cktapiload())
  1487.         return(0);
  1488.  
  1489.     cktapiopen() ;
  1490.     n = cktapidevenum() ;
  1491.     cktapiclose() ;
  1492.  
  1493.     if ( n )
  1494.     {
  1495.         tapi_list = malloc( sizeof(char *) * n ) ;
  1496.  
  1497.         for ( i=0 ; i < g_dwNumDevs ; i++ ) {
  1498.             if ( g_lpLineDevCaps[i] && (g_lpLineDevCaps[i]->dwMediaModes & LINEMEDIAMODE_DATAMODEM) )
  1499.             {
  1500.                 tapi_list[tapi_cnt++] = _strdup( ((char *)(g_lpLineDevCaps[i]))+g_lpLineDevCaps[i]->dwLineNameOffset) ;
  1501.             }
  1502.        }
  1503.  
  1504.        if ( tapi_cnt == 0 ) {
  1505.            /* TAPI Devices exist, but none can be used by Kermit */
  1506.            free ( tapi_list )  ;
  1507.            tapi_list = NULL;
  1508.        }
  1509.     }
  1510.  
  1511.     cktapiunload();
  1512.     return(tapi_cnt);
  1513. }
  1514.  
  1515. __declspec(dllexport) DWORD _stdcall
  1516. get_tapi_display_string(int index, char * str, int len)
  1517. {
  1518.     if ( index < 0 || index >= tapi_cnt || !tapi_list )
  1519.         return(0);
  1520.  
  1521.     if ( len < strlen(tapi_list[index]) + 1 )
  1522.         return(-(long)strlen(tapi_list[index]));
  1523.  
  1524.     strncpy(str,tapi_list[index],len);
  1525.     str[len-1] = '\0';
  1526.     return(1);
  1527. }
  1528.  
  1529. __declspec(dllexport) DWORD _stdcall
  1530. get_tapi_config_string(int index, char * str, int len)
  1531. {
  1532.     char * s;
  1533.  
  1534.     if ( index < 0 || index >= tapi_cnt || !tapi_list )
  1535.         return(0);
  1536.  
  1537.     if ( len < strlen(tapi_list[index]) + 1 )
  1538.         return(-(long)strlen(tapi_list[index]));
  1539.  
  1540.     strncpy(str,tapi_list[index],len);
  1541.     str[len-1] = '\0';
  1542.  
  1543.     for (s = str; *s; s++) {
  1544.         switch ( *s ) {
  1545.         case ' ':
  1546.             *s = '_';
  1547.             break;
  1548.         case ',':
  1549.             *s = '.';
  1550.             break;
  1551.         case ';':
  1552.             *s = ':';
  1553.             break;
  1554.         case '\\':
  1555.             *s = '/';
  1556.             break;
  1557.         case '?':
  1558.             *s = '!';
  1559.             break;
  1560.         case '{':
  1561.             *s = '[';
  1562.             break;
  1563.         case '}':
  1564.             *s = ']';
  1565.             break;
  1566.         default:
  1567.             *s = tolower(*s);
  1568.         }
  1569.     }
  1570.     return(1);
  1571. }
  1572.  
  1573.  
  1574. /* BEGIN MODEM CODE */
  1575. struct mdm {                /* Modem info */
  1576.     char * menuname;            /* Name to print in menu */
  1577.     char * kermitname;            /* Kermit SET MODEM TYPE name */
  1578.     long speed;                /* Default speed */
  1579. } mdmtab[] = {
  1580.     "3COM US Robotics/Megahertz 56K", "3com-usr-megahertz-56k", 115200L,
  1581.     "Atlas Newcom 33,600ifxC", "atlas-newcom-33600ifxC", 57600L,
  1582.     "AT&T 1900 STU III",    "att-1900-stu-iii",     57600L,
  1583.     "AT&T 1910 STU III",    "att-1910-stu-iii",     57600L,
  1584.     "AT&T 7300",            "att-7300",         57600L,
  1585.     "AT&T Dataport",        "att-dataport",     57600L,
  1586.     "AT&T DTDM",            "att-dtdm",         57600L,
  1587.     "AT&T ISN",             "att-isn",          57600L,
  1588.     "AT&T KeepInTouch",     "att-keepintouch",  57600L,
  1589.     "AT&T Switched Net",    "att-switched-net", 57600L,
  1590.     "Best Data",            "bestdata",         57600L,
  1591.     "Boca",                 "boca",             57600L,
  1592.     "Cardinal",            "cardinal",         57600L,
  1593.     "Compaq Data+Fax (Presario)",
  1594.                             "compaq",           57600L,
  1595.     "Digitel DT22",         "digitel-dt22",      2400L,
  1596.     "Fujitsu",              "fujitsu",          57600L,
  1597.     "Gateway Telepath",     "gateway-telepath", 57600L,
  1598.     "Generic High Speed",   "generic-high-speed", 57600L,
  1599.     "Hayes 1200",           "hayes-1200",        1200L,
  1600.     "Hayes 2400",           "hayes-2400",        2400L,
  1601.     "Hayes Ultra, Optima, or Accura",
  1602.                             "hayes-high-speed", 57600L,
  1603.     "IBM Mwave",            "mwave",            57600L,
  1604.     "Intel 14400 Faxmodem", "intel",            57600L,
  1605.     "ITU-T (CCITT) V25bis", "itu-t-v25bis",             2400L,
  1606.     "ITU-T (CCITT) V25ter/v250", "itu-t-v25ter/v250", 2400L,
  1607.     "Maxtech",              "maxtech",          57600L,
  1608.     "Megahertz AT&T V.34",  "megahertz-att-v34",57600L,
  1609.     "Megahertz XJack 33.6", "megahertz-xjack-33.6",  57600L,
  1610.     "Megahertz XJack 56k",  "megahertz-xjack-56k",  115200L,
  1611.     "Microcom in AT mode",  "microcom-at",      57600L,
  1612.     "Microcom in SX mode",  "microcom-sx",      57600L,
  1613.     "Microlink",            "microlink",        57600L,
  1614.     "Microlink V250",       "microlink-v250",        57600L,
  1615.     "Motorola Codex",       "motorola-codex",   57600L,
  1616.     "Motorola Fastalk",     "motorola-fastalk", 57600L,
  1617.     "Motorola Lifestyle",   "motorola-lifestyle", 57600L,
  1618.     "Motorola Montana",     "motorola-montana", 57600L,
  1619.     "Multitech",            "multitech",        57600L,
  1620.     "Practical Peripherals","ppi",              57600L,
  1621.     "QuickComm Spirit II",  "spirit-ii",        57600L,
  1622.     "Rockwell V32",         "rockwell-v32",     57600L,
  1623.     "Rockwell V32bis",      "rockwell-v32bis",  57600L,
  1624.     "Rockwell V34",         "rockwell-v34",     57600L,
  1625.     "Rockwell V90",         "rockwell-v90",    115200L,
  1626.     "Rolm 244pc",           "rolm-244pc",       19200L,
  1627.     "Rolm 600 series",      "rolm-600-series",  19200L,
  1628.     "Rolm DCM",             "rolm-dcm",         19200L,
  1629.     "Supra Fax Modem",      "suprafaxmodem",    57600L,
  1630.     "SupraSonic 288+",      "suprasonic",       57600L,
  1631.     "Telebit (old models)", "old-telebit",      19200L,
  1632.     "Telebit (newer models)","telebit",         38400L,
  1633.     "Unknown",              "unknown",           2400L,
  1634.     "US Robotics/Megahertz 56k", "usr-megahertz-56k", 115200L,
  1635.     "US Robotics Sportster or Courier",
  1636.                             "usrobotics",       57600L,
  1637.     "Zoltrix",              "zoltrix",          57600L,
  1638.     "Zoom",                 "zoom",             57600L,
  1639.     "Zyxel",                "zyxel",            57600L
  1640. };
  1641. int modems = (sizeof(mdmtab) / sizeof(struct mdm));
  1642.  
  1643. char * speedtab[] = {            /* Legal speeds */
  1644.     "110",
  1645.     "300",
  1646.     "1200",
  1647.     "2400",
  1648.     "3600",
  1649.     "7200",
  1650.     "9600",
  1651.     "14400",
  1652.     "19200",
  1653.     "28800",
  1654.     "38400",
  1655.     "57600",
  1656.     "76800",
  1657.     "115200",
  1658.     "230400",
  1659.     "460800"
  1660. };
  1661. int speeds = (sizeof(speedtab) / sizeof(long));
  1662.  
  1663. char * printers[] = {
  1664.     "PRN", "LPT1", "LPT2", "LPT3", "NUL", "KERMIT.PRN"
  1665. };
  1666. int nprinters = (sizeof(printers)/sizeof(char *));
  1667.  
  1668. __declspec(dllexport) DWORD _stdcall
  1669. init_modem_list(void)
  1670. {
  1671.     return(modems);
  1672. }
  1673.  
  1674. __declspec(dllexport) DWORD _stdcall
  1675. get_modem_display_string(int index, char * str, int len)
  1676. {
  1677.     if ( index < 0 || index >= modems )
  1678.         return(0);
  1679.  
  1680.     if ( len < strlen(mdmtab[index].menuname) + 1 )
  1681.         return(-(long)strlen(mdmtab[index].menuname));
  1682.  
  1683.     strncpy(str,mdmtab[index].menuname,len);
  1684.     str[len-1] = '\0';
  1685.     return(1);
  1686. }
  1687.  
  1688. __declspec(dllexport) DWORD _stdcall
  1689. get_modem_config_string(int index, char * str, int len)
  1690. {
  1691.     if ( index < 0 || index >= modems )
  1692.         return(0);
  1693.  
  1694.     if ( len < strlen(mdmtab[index].kermitname) + 1 )
  1695.         return(-(long)strlen(mdmtab[index].kermitname));
  1696.  
  1697.     strncpy(str,mdmtab[index].kermitname,len);
  1698.     str[len-1] = '\0';
  1699.     return(1);
  1700. }
  1701.  
  1702. __declspec(dllexport) DWORD _stdcall
  1703. get_modem_baud_rate(int index)
  1704. {
  1705.     if ( index < 0 || index >= modems )
  1706.         return(0);
  1707.  
  1708.     return(mdmtab[index].speed);
  1709. }
  1710.  
  1711.  
  1712. __declspec(dllexport) DWORD _stdcall
  1713. init_baud_rate_list(void)
  1714. {
  1715.     return(speeds);
  1716. }
  1717.  
  1718. __declspec(dllexport) DWORD _stdcall
  1719. get_baud_rate_display_string(int index, char * str, int len)
  1720. {
  1721.     if ( index < 0 || index >= speeds )
  1722.         return(0);
  1723.  
  1724.     if ( len < strlen(speedtab[index]) + 1 )
  1725.         return(-(long)strlen(speedtab[index]));
  1726.  
  1727.     strncpy(str,speedtab[index],len);
  1728.     str[len-1] = '\0';
  1729.     return(1);
  1730. }
  1731.  
  1732. __declspec(dllexport) DWORD _stdcall
  1733. get_baud_rate_config_string(int index, char * str, int len)
  1734. {
  1735.     return(get_baud_rate_display_string(index,str,len));
  1736. }
  1737.  
  1738. static char ** serial_list = NULL;
  1739. static int     serial_cnt  = 0;
  1740.  
  1741. __declspec(dllexport) DWORD _stdcall
  1742. init_serial_port_list(void)
  1743. {
  1744.     HKEY  hk=0;
  1745.     DWORD dwType=0;
  1746.     DWORD dwValueSize=0, dwDataSize=0;
  1747.     CHAR *lpszValueName=NULL;
  1748.     char  serialdevice[64]="";
  1749.     char  dosname[12]="";
  1750.     int i;
  1751.     DWORD rc;
  1752.  
  1753.     if ( serial_list )
  1754.     {
  1755.         for ( i=0 ; i < serial_cnt ; i++ )
  1756.             free( serial_list[i] ) ;
  1757.         free ( serial_list )  ;
  1758.     }
  1759.     serial_list = NULL;
  1760.     serial_cnt = 0;
  1761.  
  1762.     if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  1763.                        "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0,
  1764.                         KEY_READ, &hk) )
  1765.         goto init_exit;
  1766.  
  1767.     for ( ;; ) {
  1768.         dwValueSize = sizeof(serialdevice);
  1769.         dwDataSize = sizeof(dosname);
  1770.         rc = RegEnumValue(hk, serial_cnt, serialdevice, &dwValueSize, 0,
  1771.                            &dwType, dosname, &dwDataSize);
  1772.         if ( rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA )
  1773.             serial_cnt++;
  1774.         else 
  1775.             break;
  1776.     }
  1777.     if (serial_cnt == 0)
  1778.         goto init_exit;
  1779.  
  1780.     serial_list = (char **) malloc( serial_cnt * sizeof(char *) );
  1781.     if ( !serial_list ) {
  1782.         serial_cnt = 0;
  1783.         goto init_exit;
  1784.     }
  1785.  
  1786.     for ( i=0;i<serial_cnt;i++ ) {
  1787.         dwValueSize = sizeof(serialdevice);
  1788.         dwDataSize = sizeof(dosname);
  1789.         rc = RegEnumValue(hk, i, serialdevice, &dwValueSize, 0,
  1790.                            &dwType, dosname, &dwDataSize);
  1791.         if ( rc == ERROR_SUCCESS || rc == ERROR_MORE_DATA ) {
  1792.             serial_list[i] = strdup(dosname);
  1793.         }
  1794.     }
  1795.  
  1796.   init_exit:
  1797.     RegCloseKey( hk );
  1798.     return(serial_cnt);
  1799. }
  1800.  
  1801. __declspec(dllexport) DWORD _stdcall
  1802. get_serial_port_display_string(int index, char * str, int len)
  1803. {
  1804.     if ( index < 0 || index >= serial_cnt || !serial_list )
  1805.         return(0);
  1806.  
  1807.     if ( len < strlen(serial_list[index]) + 1 )
  1808.         return(-(long)strlen(serial_list[index]));
  1809.  
  1810.     strncpy(str,serial_list[index],len);
  1811.     str[len-1] = '\0';
  1812.     return(1);
  1813. }
  1814.  
  1815. __declspec(dllexport) DWORD _stdcall
  1816. get_serial_port_config_string(int index, char * str, int len)
  1817. {
  1818.     return(get_serial_port_display_string(index,str,len));
  1819. }
  1820.  
  1821.  
  1822. __declspec(dllexport) DWORD _stdcall
  1823. init_dos_printer_list(void)
  1824. {
  1825.     return(nprinters);
  1826. }
  1827.  
  1828. __declspec(dllexport) DWORD _stdcall
  1829. get_dos_printer_display_string(int index, char * str, int len)
  1830. {
  1831.     if ( index < 0 || index >= nprinters )
  1832.         return(0);
  1833.  
  1834.     if ( len < strlen(printers[index]) + 1 )
  1835.         return(-(long)strlen(printers[index]));
  1836.  
  1837.     strncpy(str,printers[index],len);
  1838.     str[len-1] = '\0';
  1839.     return(1);
  1840. }
  1841.  
  1842. __declspec(dllexport) DWORD _stdcall
  1843. get_dos_printer_config_string(int index, char * str, int len)
  1844. {
  1845.     return(get_dos_printer_display_string(index,str,len));
  1846. }
  1847. /* END MODEM CODE */
  1848.  
  1849. /* BEGIN REGISTER EXE CODE */
  1850.  
  1851. #define FILECOUNT 4
  1852. #define FILECOUNT_REQUIRED 2
  1853.  
  1854. CHAR * FileName[FILECOUNT] ;
  1855. struct ck_registration * RegBlock[FILECOUNT] ;
  1856. HANDLE hFile[FILECOUNT] ;
  1857. HANDLE hFileMapping[FILECOUNT] ;
  1858. CHAR * pView[FILECOUNT] ;
  1859. FILETIME ftLastAccess[FILECOUNT], ftCreation[FILECOUNT], ftLastWrite[FILECOUNT] ;
  1860.  
  1861. static void
  1862. reg_init(char * installdir) {
  1863.     int i;
  1864.     static int init = 0;
  1865.  
  1866.     if (init)
  1867.         return;
  1868.  
  1869.     if (installdir == NULL || installdir[0] == '\0')
  1870.         installdir = ".";
  1871.  
  1872.     for ( i=0 ; i < FILECOUNT ; i++ )
  1873.     {
  1874.         FileName[i] = (char *)malloc(strlen(installdir) + 32);
  1875.         if (FileName[i] == NULL)
  1876.             return;
  1877.     hFile[i]        = NULL ;
  1878.     hFileMapping[i] = NULL ;
  1879.     pView[i]        = NULL ;
  1880.     RegBlock[i] = NULL ;
  1881.     }
  1882.  
  1883.     sprintf(FileName[0],"%s\\%s",installdir,"k95.exe");
  1884.     sprintf(FileName[1],"%s\\%s",installdir,"k95dial.exe");
  1885.     sprintf(FileName[2],"%s\\%s",installdir,"k95g.exe");
  1886.     sprintf(FileName[3],"%s\\%s",installdir,"k95c.exe");
  1887.  
  1888.     init = 1;
  1889. }
  1890.  
  1891. static int
  1892. openfile(int i)
  1893. {
  1894.    hFile[i] = CreateFile(
  1895.                    FileName[i],    // address of name of the file 
  1896.                    GENERIC_READ | GENERIC_WRITE,
  1897.                    0,     // share mode 
  1898.                    NULL,// address of security descriptor 
  1899.                    OPEN_EXISTING,    // how to create 
  1900.                    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,    // file attributes 
  1901.                    NULL     // handle of file with attributes to copy  
  1902.    );
  1903.  
  1904.    if ( !hFile[i] )
  1905.       return 0;
  1906.     
  1907.    GetFileTime( hFile[i], &ftCreation[i], &ftLastAccess[i], &ftLastWrite[i] ) ;
  1908.    hFileMapping[i] = CreateFileMapping( hFile[i],
  1909.                                             NULL,
  1910.                                             PAGE_READWRITE,
  1911.                                             0,
  1912.                                             0,
  1913.                                             NULL );
  1914.  
  1915.    pView[i] = (CHAR *) MapViewOfFile( hFileMapping[i],
  1916.                                  FILE_MAP_WRITE,
  1917.                                  0,0,0);
  1918.  
  1919.    if ( !pView[i] )
  1920.       return 0;
  1921.    return 1;
  1922. }
  1923.  
  1924. static int 
  1925. closefile( int i ) 
  1926. {
  1927.    if (pView[i])
  1928.       UnmapViewOfFile( pView[i] ) ;
  1929.    if (hFileMapping[i])
  1930.       CloseHandle( hFileMapping[i] ) ;
  1931.    if (hFile[i])
  1932.    {
  1933.       SetFileTime( hFile[i], &ftCreation[i], &ftLastAccess[i], &ftLastWrite[i] ) ;
  1934.       CloseHandle( hFile[i] ) ;
  1935.    }
  1936.    return 1;
  1937. }
  1938.  
  1939. static int 
  1940. SearchForRegBlock( int i ) 
  1941. {
  1942.     CHAR * SearchString =  
  1943. #ifdef COMMENT
  1944.         "====758914360207174068160528073\0\0\0\0\0^H^H^H^H^H^H^_{({({({(^^^^^^^^^\0^C^C^C____^_^_^_^____)})})})})}\0$(((((((((((())))))))))))^@^@^@"
  1945. #else
  1946.         "====758914360207174068160528073"
  1947. #endif
  1948.         ;
  1949.  
  1950.     //  sizeof ck_registration struct is 140 bytes.
  1951.     int SearchLength = strlen(SearchString) ;
  1952.     BY_HANDLE_FILE_INFORMATION fileInfo ;
  1953.     CHAR * start;
  1954.     CHAR * p;
  1955.     int found;
  1956.     ULONG k;
  1957.  
  1958.     GetFileInformationByHandle( hFile[i], &fileInfo ) ;
  1959.  
  1960.     //  We only search for the first null terminated portion of the search string 
  1961.     //  because we want to be able to find a pre-registered copy
  1962.  
  1963.     if ( !pView[i] )
  1964.         return 0 ;
  1965.  
  1966.     start = pView[i] ;
  1967.     p = pView[i] ;
  1968.     found = 0 ;
  1969.  
  1970.     k = 0 ;
  1971.     while ( !found && k < fileInfo.nFileSizeLow )
  1972.     {
  1973.         LONG j = 0 ;
  1974.         if ( p[k] == SearchString[0] )
  1975.         {
  1976.             start = &p[k] ;
  1977.             for ( j = 0 ; j < SearchLength ; j++ )
  1978.             {
  1979.                 if ( start[j] != SearchString[j] )
  1980.                     break;
  1981.             }
  1982.             if ( j == SearchLength )
  1983.                 found = 1 ;
  1984.         }
  1985.         k++ ;
  1986.     }
  1987.  
  1988.     if ( found )
  1989.     RegBlock[i] = (struct ck_registration *) start ;
  1990.     return found;
  1991. }
  1992.  
  1993. static int
  1994. RegisterExe( struct ck_registration * ck_reg, int i )
  1995. {
  1996. #ifdef COMMENT
  1997.     if ( isregistered( RegBlock[i] ) > 0 )
  1998.     {
  1999.         // Do nothing, already registered.
  2000.         return 0;
  2001.     }
  2002. #endif /* COMMENT */
  2003.     memcpy( RegBlock[i], ck_reg, sizeof(struct ck_registration) ) ;
  2004.     return (1) ;
  2005. }
  2006.  
  2007. /*
  2008.  *  Return 0 - success
  2009.  *  Return 1 - Invalid Product Prefix in Serial Number
  2010.  *  Return 2 - Invalid Name
  2011.  *  Return 3 - Invalid Corp
  2012.  *  Return 4 - Invalid Serial Number
  2013.  *  Return 5 - Unable to store registration info
  2014.  */
  2015.  
  2016. __declspec(dllexport) DWORD _stdcall
  2017. register_k95(char * installdir, char * serial, char * name, char * corp, int license )
  2018. {
  2019.     struct ck_registration ri ;
  2020.     int x;
  2021.  
  2022.     reg_init(installdir);
  2023.  
  2024.     memset(&ri,0,sizeof(ri));
  2025.  
  2026.     ri.is_set = 0 ;
  2027.     memset(ri.serial,' ',96) ;
  2028.  
  2029.     if ( !serial || strncmp( serial, "K95", 3 )) {
  2030.         return 1;
  2031.     }
  2032.  
  2033.     if ( !name || strlen(name) == 0 ) {
  2034.         return 2;
  2035.     }
  2036.  
  2037.     ck_encrypt( name ) ;
  2038.     strncpy( ri.name, name, 31 ) ;
  2039.     ri.name[31] = '\0' ;
  2040.     for ( x = strlen(ri.name) ; x < 31 ; x++ )
  2041.         ri.name[x] = '\0' ;
  2042.     ri.name[31] = '\0' ;
  2043.  
  2044.     if ( !corp || strlen(corp) == 0 )
  2045.     {
  2046.         return 3;
  2047.     }
  2048.  
  2049.  
  2050.     ck_encrypt( corp ) ;
  2051.     strncpy( ri.corp, corp, 31 ) ;
  2052.     ri.corp[31] = '\0' ;
  2053.     for ( x = strlen(ri.corp) ; x < 31 ; x++ )
  2054.         ri.corp[x] = '\0' ;
  2055.     ri.corp[31] = '\0' ;
  2056.  
  2057.     strncpy( ri.ident, "====758914360207174068160528073", 32 ) ;
  2058.  
  2059.     if ( !chksn( serial ) ) {
  2060.         return(4);
  2061.     } else {
  2062.         int regd, i;
  2063.  
  2064.         ck_encrypt( serial ) ;
  2065.         strncpy( ri.serial, serial, 31 ) ;
  2066.         for ( x = strlen(ri.serial) ; x < 31 ; x++ )
  2067.             ri.serial[x] = '\0' ;
  2068.         ri.serial[31] = '\0' ;
  2069.  
  2070.         ri.is_set = license ? license : 1 ;
  2071.         setcrc( &ri );
  2072.         regd = 0 ;
  2073.         for ( i=0 ; i<FILECOUNT ; i++ )
  2074.         {
  2075.             if ( !openfile(i) )
  2076.             {
  2077.                 if ( i >= FILECOUNT_REQUIRED )
  2078.                     continue;
  2079.                 else
  2080.                     break;
  2081.             }
  2082.             SearchForRegBlock(i) ;
  2083.             if (RegBlock[i])
  2084.                 regd += RegisterExe( &ri, i ) ;
  2085.             closefile(i) ;
  2086.         }
  2087.  
  2088.         if ( !regd )
  2089.         {
  2090.             return(5);
  2091.         }
  2092.     }
  2093.     return(0);
  2094. }
  2095.  
  2096. /* 
  2097.  *  Return 0 - success
  2098.  *  Return 1 - not registered
  2099.  *  Return 2 - unable to find required files
  2100.  *  Return 3 - invalid file
  2101.  *  Return 4 - invalid parameters
  2102.  *  
  2103.  *  Bulk License has numbers: 100 -> 10000 || > 10000000
  2104.  */
  2105. __declspec(dllexport) DWORD _stdcall
  2106. get_reg_info(char * installdir, 
  2107.              char * serial, int serial_len,
  2108.              char * name, int name_len,
  2109.              char * corp, int corp_len )
  2110. {
  2111.     int registered = 0, i ;
  2112.  
  2113.     reg_init(installdir);
  2114.  
  2115.     if ( !name || !serial || !corp ||
  2116.          !name_len || !serial_len || !corp_len )
  2117.         return(4);
  2118.  
  2119.     for ( i=0 ; registered == 0 && i < FILECOUNT ; i++ )
  2120.     {
  2121.         int dsn;
  2122.  
  2123.     if ( !openfile(i) )
  2124.     {
  2125.             if ( i >= FILECOUNT_REQUIRED )
  2126.                 continue;
  2127.         return 2;
  2128.     }
  2129.  
  2130.     SearchForRegBlock(i) ;
  2131.     if ( !RegBlock[i] )
  2132.     {
  2133.         return 3 ;
  2134.     }
  2135.  
  2136.         dsn = isregistered( RegBlock[i] );
  2137.     if ( dsn > 0 && dsn != 98 )
  2138.     {
  2139.         char temp[32] ;
  2140.  
  2141.             registered++;
  2142.  
  2143.         strcpy( temp, RegBlock[i]->name ) ;
  2144.         ck_decrypt( temp );
  2145.             strncpy(name,temp,name_len);
  2146.             name[name_len-1] = 0;
  2147.  
  2148.         strcpy( temp, RegBlock[i]->corp ) ;
  2149.         ck_decrypt( temp ) ;
  2150.             strncpy(corp,temp,corp_len);
  2151.             corp[corp_len-1] = 0;
  2152.  
  2153.         strcpy( temp, RegBlock[i]->serial ) ;
  2154.         ck_decrypt( temp ) ;
  2155.             strncpy(serial,temp,serial_len);
  2156.             serial[serial_len-1] = 0;
  2157.     }
  2158.  
  2159.         closefile(i);
  2160.     }
  2161.     return (registered ? 0 : 1);
  2162. }
  2163.  
  2164. #define K95_APPID "Kermit.Script"
  2165. #define K95_APPID_DEFAULT "Columbia University Kermit 95 Script"
  2166. #define K95_MIME  "application/kermit"
  2167. #define K95_MIME_PATH  "MIME\\Database\\Content Type\\application/kermit"
  2168.  
  2169. __declspec(dllexport) int _stdcall
  2170. assoc_k95_with_telnet(char * K95Path)
  2171. {
  2172.     HKEY  hkCommandKey=0;
  2173.     HKEY  hkSubKey=0,hkSubKey2=0,hkSubKey3=0,hkSubKey4=0;
  2174.     CHAR  lpszKeyValue[256];
  2175.     DWORD dwType=0;
  2176.     DWORD dwSize=0;
  2177.     DWORD dwDisposition=0;
  2178.     char *lpszValueName=NULL;
  2179.     unsigned char rc = FALSE;
  2180.  
  2181.     /* Telnet */
  2182.     if ( RegOpenKeyEx(HKEY_CLASSES_ROOT,
  2183.                        "telnet", 0,
  2184.                        KEY_READ | KEY_WRITE, &hkCommandKey) ) {
  2185.         /* Key does not already exist */
  2186.         if ( RegCreateKeyEx(HKEY_CLASSES_ROOT,
  2187.                              "telnet",0,0,REG_OPTION_NON_VOLATILE,
  2188.                              KEY_READ | KEY_WRITE,0,
  2189.                              &hkCommandKey, &dwDisposition) )
  2190.             return FALSE;
  2191.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2192.             RegCloseKey( hkCommandKey );
  2193.             return FALSE;
  2194.         }
  2195.     }
  2196.  
  2197.     RegSetValueEx(hkCommandKey, "", 0, REG_SZ, 
  2198.                    (unsigned char*)K95_APPID_DEFAULT, 
  2199.                    sizeof(K95_APPID_DEFAULT));
  2200.     sprintf((char*)lpszKeyValue,"%s,%d",K95Path,1);
  2201.     RegSetValueEx(hkCommandKey, "DefaultIcon", 0, REG_SZ, 
  2202.                    (unsigned char *)lpszKeyValue, sizeof(lpszKeyValue));
  2203.  
  2204.  
  2205.     if ( RegOpenKeyEx(hkCommandKey,
  2206.                        "shell", 0,
  2207.                        KEY_READ | KEY_WRITE, &hkSubKey) ) {
  2208.         /* Key does not already exist */
  2209.         if ( RegCreateKeyEx(hkCommandKey,
  2210.                              "shell",0,0,REG_OPTION_NON_VOLATILE,
  2211.                              KEY_READ | KEY_WRITE,0,
  2212.                              &hkSubKey, &dwDisposition) )
  2213.             return FALSE;
  2214.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2215.             RegCloseKey( hkSubKey );
  2216.             RegCloseKey( hkCommandKey );
  2217.             return FALSE;
  2218.         }
  2219.     }
  2220.  
  2221.     if ( RegOpenKeyEx(hkSubKey,
  2222.                        "open", 0,
  2223.                        KEY_READ | KEY_WRITE, &hkSubKey2) ) {
  2224.         /* Key does not already exist */
  2225.         if ( RegCreateKeyEx(hkSubKey,
  2226.                              "open",0,0,REG_OPTION_NON_VOLATILE,
  2227.                              KEY_READ | KEY_WRITE,0,
  2228.                              &hkSubKey2, &dwDisposition) )
  2229.             return FALSE;
  2230.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2231.             RegCloseKey( hkSubKey2 );
  2232.             RegCloseKey( hkSubKey );
  2233.             RegCloseKey( hkCommandKey );
  2234.             return FALSE;
  2235.         }
  2236.     }
  2237.  
  2238.     if ( RegOpenKeyEx(hkSubKey2,
  2239.                        "command", 0,
  2240.                        KEY_READ | KEY_WRITE, &hkSubKey3) ) {
  2241.         /* Key does not already exist */
  2242.         if ( RegCreateKeyEx(hkSubKey2,
  2243.                              "command",0,0,REG_OPTION_NON_VOLATILE,
  2244.                              KEY_READ | KEY_WRITE,0,
  2245.                              &hkSubKey3, &dwDisposition) )
  2246.             return FALSE;
  2247.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2248.             RegCloseKey( hkSubKey3 );
  2249.             RegCloseKey( hkSubKey2 );
  2250.             RegCloseKey( hkSubKey );
  2251.             RegCloseKey( hkCommandKey );
  2252.             return FALSE;
  2253.         }
  2254.     }
  2255.  
  2256.     sprintf((char*)lpszKeyValue,"%s -J \"%%1\"",K95Path);
  2257.     RegSetValueEx(hkSubKey3, "", 0, REG_SZ, 
  2258.                    (unsigned char *)lpszKeyValue, 
  2259.                    strlen((char*)lpszKeyValue));
  2260.  
  2261.     RegCloseKey( hkSubKey3 );
  2262.     RegCloseKey( hkSubKey2 );
  2263.     RegCloseKey( hkSubKey );
  2264.     RegCloseKey( hkCommandKey );
  2265.  
  2266.     return TRUE;
  2267. }
  2268.  
  2269. __declspec(dllexport) int _stdcall
  2270. assoc_k95_with_ksc(char * K95Path)
  2271. {
  2272.     HKEY  hkCommandKey=0;
  2273.     HKEY  hkSubKey=0,hkSubKey2=0,hkSubKey3=0,hkSubKey4=0;
  2274.     CHAR  lpszKeyValue[256];
  2275.     DWORD dwType=0;
  2276.     DWORD dwSize=0;
  2277.     DWORD dwDisposition=0;
  2278.     char *lpszValueName=NULL;
  2279.     unsigned char rc = FALSE;
  2280.  
  2281.     /* .KSC */
  2282.     if ( RegOpenKeyEx(HKEY_CLASSES_ROOT,
  2283.                        ".ksc", 0,
  2284.                        KEY_READ | KEY_WRITE, &hkCommandKey) ) {
  2285.         /* Key does not already exist */
  2286.         if ( RegCreateKeyEx(HKEY_CLASSES_ROOT,
  2287.                              ".ksc",0,0,REG_OPTION_NON_VOLATILE,
  2288.                              KEY_READ | KEY_WRITE,0,
  2289.                              &hkCommandKey, &dwDisposition) )
  2290.             return FALSE;
  2291.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2292.             RegCloseKey( hkCommandKey );
  2293.             return FALSE;
  2294.         }
  2295.     }
  2296.  
  2297.     RegSetValueEx(hkCommandKey, "", 0, REG_SZ, 
  2298.                    (unsigned char*)K95_APPID, sizeof(K95_APPID));
  2299.     RegSetValueEx(hkCommandKey, "Content Type", 0, REG_SZ, 
  2300.                    (unsigned char*)K95_MIME, sizeof(K95_MIME));
  2301.  
  2302.     RegCloseKey( hkCommandKey );
  2303.  
  2304.     /* MIME: application/kermit */
  2305.     if ( RegOpenKeyEx(HKEY_CLASSES_ROOT,
  2306.                        K95_MIME_PATH, 0,
  2307.                        KEY_READ | KEY_WRITE, &hkCommandKey) ) {
  2308.         /* Key does not already exist */
  2309.         if ( RegCreateKeyEx(HKEY_CLASSES_ROOT,
  2310.                              K95_MIME_PATH,0,0,REG_OPTION_NON_VOLATILE,
  2311.                              KEY_READ | KEY_WRITE,0,
  2312.                              &hkCommandKey, &dwDisposition) )
  2313.             return FALSE;
  2314.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2315.             RegCloseKey( hkCommandKey );
  2316.             return FALSE;
  2317.         }
  2318.     }
  2319.  
  2320.     RegSetValueEx(hkCommandKey, "Extension", 0, REG_SZ, 
  2321.                    (unsigned char *)".KSC", 4);
  2322.     RegCloseKey( hkCommandKey );
  2323.  
  2324.     /* Kermit.Script */
  2325.     if ( RegOpenKeyEx(HKEY_CLASSES_ROOT,
  2326.                        "Kermit.Script", 0,
  2327.                        KEY_READ | KEY_WRITE, &hkCommandKey) ) {
  2328.         /* Key does not already exist */
  2329.         if ( RegCreateKeyEx(HKEY_CLASSES_ROOT,
  2330.                              "Kermit.Script",0,0,REG_OPTION_NON_VOLATILE,
  2331.                              KEY_READ | KEY_WRITE,0,
  2332.                              &hkCommandKey, &dwDisposition) )
  2333.             return FALSE;
  2334.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2335.             RegCloseKey( hkCommandKey );
  2336.             return FALSE;
  2337.         }
  2338.     }
  2339.  
  2340.     RegSetValueEx(hkCommandKey, "", 0, REG_SZ, 
  2341.                    (unsigned char*)K95_APPID_DEFAULT, 
  2342.                    sizeof(K95_APPID_DEFAULT));
  2343.     sprintf((char*)lpszKeyValue,"%s,%d",K95Path,3);
  2344.     RegSetValueEx(hkCommandKey, "DefaultIcon", 0, REG_SZ, 
  2345.                    (unsigned char *)lpszKeyValue, sizeof(lpszKeyValue));
  2346.  
  2347.  
  2348.     if ( RegOpenKeyEx(hkCommandKey,
  2349.                        "shell", 0,
  2350.                        KEY_READ | KEY_WRITE, &hkSubKey) ) {
  2351.         /* Key does not already exist */
  2352.         if ( RegCreateKeyEx(hkCommandKey,
  2353.                              "shell",0,0,REG_OPTION_NON_VOLATILE,
  2354.                              KEY_READ | KEY_WRITE,0,
  2355.                              &hkSubKey, &dwDisposition) )
  2356.             return FALSE;
  2357.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2358.             RegCloseKey( hkSubKey );
  2359.             RegCloseKey( hkCommandKey );
  2360.             return FALSE;
  2361.         }
  2362.     }
  2363.  
  2364.     if ( RegOpenKeyEx(hkSubKey,
  2365.                        "open", 0,
  2366.                        KEY_READ | KEY_WRITE, &hkSubKey2) ) {
  2367.         /* Key does not already exist */
  2368.         if ( RegCreateKeyEx(hkSubKey,
  2369.                              "open",0,0,REG_OPTION_NON_VOLATILE,
  2370.                              KEY_READ | KEY_WRITE,0,
  2371.                              &hkSubKey2, &dwDisposition) )
  2372.             return FALSE;
  2373.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2374.             RegCloseKey( hkSubKey2 );
  2375.             RegCloseKey( hkSubKey );
  2376.             RegCloseKey( hkCommandKey );
  2377.             return FALSE;
  2378.         }
  2379.     }
  2380.  
  2381.     if ( RegOpenKeyEx(hkSubKey2,
  2382.                        "command", 0,
  2383.                        KEY_READ | KEY_WRITE, &hkSubKey3) ) {
  2384.         /* Key does not already exist */
  2385.         if ( RegCreateKeyEx(hkSubKey2,
  2386.                              "command",0,0,REG_OPTION_NON_VOLATILE,
  2387.                              KEY_READ | KEY_WRITE,0,
  2388.                              &hkSubKey3, &dwDisposition) )
  2389.             return FALSE;
  2390.         if ( dwDisposition != REG_CREATED_NEW_KEY ) {
  2391.             RegCloseKey( hkSubKey3 );
  2392.             RegCloseKey( hkSubKey2 );
  2393.             RegCloseKey( hkSubKey );
  2394.             RegCloseKey( hkCommandKey );
  2395.             return FALSE;
  2396.         }
  2397.     }
  2398.  
  2399.     sprintf((char*)lpszKeyValue,"%s \"%%1\"",K95Path);
  2400.     RegSetValueEx(hkSubKey3, "", 0, REG_SZ, 
  2401.                    (unsigned char *)lpszKeyValue, 
  2402.                    strlen((char*)lpszKeyValue));
  2403.  
  2404.     RegCloseKey( hkSubKey3 );
  2405.     RegCloseKey( hkSubKey2 );
  2406.     RegCloseKey( hkSubKey );
  2407.     RegCloseKey( hkCommandKey );
  2408.  
  2409.     return TRUE;
  2410. }
  2411.  
  2412. __declspec(dllexport) int _stdcall
  2413. delete_associations(void)
  2414. {
  2415.     HKEY  hkCommandKey=0;
  2416.     HKEY  hkSubKey=0,hkSubKey2=0,hkSubKey3=0,hkSubKey4=0;
  2417.     DWORD dwType=0;
  2418.     DWORD dwSize=0;
  2419.     DWORD dwDisposition=0;
  2420.     char *lpszValueName=NULL;
  2421.     unsigned char rc = FALSE;
  2422.  
  2423.     /* .KSC */
  2424.     RegDeleteKey(HKEY_CLASSES_ROOT, ".ksc");
  2425.  
  2426.     /* MIME: application/kermit */
  2427.     RegDeleteKey(HKEY_CLASSES_ROOT, K95_MIME_PATH);
  2428.  
  2429.     /* Kermit.Script */
  2430.     if ( !RegOpenKeyEx(HKEY_CLASSES_ROOT,
  2431.                        "Kermit.Script", 0,
  2432.                        KEY_READ | KEY_WRITE, &hkCommandKey) ) {
  2433.         /* Key exists */
  2434.         if ( !RegOpenKeyEx(hkCommandKey,
  2435.                             "shell", 0,
  2436.                             KEY_READ | KEY_WRITE, &hkSubKey) ) {
  2437.             /* Key exists */
  2438.             if ( !RegOpenKeyEx(hkSubKey,
  2439.                                "open", 0,
  2440.                                KEY_READ | KEY_WRITE, &hkSubKey2) ) {
  2441.                 /* Key exists */
  2442.                 RegDeleteKey( hkSubKey2, "command" );
  2443.                 RegCloseKey( hkSubKey2 );
  2444.             }
  2445.             RegDeleteKey( hkSubKey, "open" );
  2446.             if ( !RegOpenKeyEx(hkSubKey,
  2447.                                "print", 0,
  2448.                                KEY_READ | KEY_WRITE, &hkSubKey2) ) {
  2449.                 /* Key exists */
  2450.                 RegDeleteKey( hkSubKey2, "command" );
  2451.                 RegCloseKey( hkSubKey2 );
  2452.             }
  2453.             RegDeleteKey( hkSubKey, "print" );
  2454.             if ( !RegOpenKeyEx(hkSubKey,
  2455.                                "edit", 0,
  2456.                                KEY_READ | KEY_WRITE, &hkSubKey2) ) {
  2457.                 /* Key exists */
  2458.                 RegDeleteKey( hkSubKey2, "command" );
  2459.                 RegCloseKey( hkSubKey2 );
  2460.             }
  2461.             RegDeleteKey( hkSubKey, "edit" );
  2462.             RegCloseKey( hkSubKey );
  2463.         }
  2464.         RegDeleteKey( hkCommandKey, "shell");
  2465.         RegCloseKey( hkCommandKey );
  2466.     }
  2467.     RegDeleteKey(HKEY_CLASSES_ROOT,"Kermit.Script");
  2468.  
  2469.     return TRUE;
  2470. }
  2471.  
  2472.