Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.2 KiB

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. void MakeKey(char *, int);
  6. void usage( void )
  7. {
  8. printf( "Usage:\n\n\tkeymake ( -s | -c ) file1 [file2]\n\n" );
  9. printf( "\tParameters:\n\t-s : ISP\n\t-c : Corp\n\tfile1 : input file\n\tfile2 : output file\n\n" );
  10. printf( "\tNote: if file2 is left out, output is directed to stdout\n\n" );
  11. printf( "\tExample: keymake -s isps.txt keys.txt\n\n" );
  12. }
  13. int RemoveSpaces( char *szBuffer, int isize )
  14. {
  15. int i;
  16. int nRemoved = 0;
  17. for( i = 0; i < (isize - nRemoved); i++ )
  18. {
  19. if( szBuffer[i] == ' ' )
  20. {
  21. nRemoved++;
  22. memcpy( &szBuffer[i], &szBuffer[i] + 1, isize - i);
  23. }
  24. }
  25. szBuffer[isize - nRemoved] = '\0';
  26. return nRemoved;
  27. }
  28. void OutputKeys( FILE *ofile, char *szBuffer, int isize, char *szName, int itype )
  29. {
  30. int i;
  31. int itemp = 0;
  32. int itemp2 = 0;
  33. int keycount = 0;
  34. char szTemp[80] = {0};
  35. char szClean[10] = {0};
  36. for( i = 0; i < isize; i++ )
  37. {
  38. if( szBuffer[i] != '\n' )
  39. {
  40. szTemp[itemp] = szBuffer[i];
  41. itemp++;
  42. }
  43. else
  44. {
  45. itemp = 0;
  46. szTemp[7] = '\0';
  47. strupr( szTemp );
  48. MakeKey( szTemp, itype );
  49. fprintf( ofile, "%s,%s\n", szName, szTemp );
  50. while( szName[0] != '\0' )
  51. *szName++;
  52. *szName++;
  53. szTemp[0] = '\0';
  54. memcpy( &szTemp, &szClean, 10 );
  55. keycount++;
  56. }
  57. }
  58. }
  59. int __cdecl main(int argc, char *argv[])
  60. {
  61. char buf[80];
  62. char filebuffer[16384] = {0};
  63. char namebuffer[16384] = {0};
  64. int isize;
  65. int nSpaces;
  66. int itype;
  67. int i;
  68. FILE *ifile;
  69. FILE *ofile;
  70. if( argc < 3 )
  71. {
  72. usage();
  73. goto get_out;
  74. }
  75. if ((argv[1][0] != '-') && (argv[1][0] != '/')) goto badparm;
  76. if (strlen(argv[1]) != 2) goto badparm;
  77. switch (argv[1][1])
  78. {
  79. case 's':
  80. case 'S':
  81. itype = 0;
  82. break;
  83. case 'c':
  84. case 'C':
  85. itype = 1;
  86. break;
  87. default:
  88. badparm:
  89. printf( "\ninvalid parameter: %s\n\n", argv[1] );
  90. usage();
  91. goto get_out;
  92. }
  93. if( (ifile = fopen( argv[2], "r" )) != NULL )
  94. {
  95. isize = fread( filebuffer, sizeof(char), 16384, ifile );
  96. }
  97. else
  98. {
  99. printf( "Could not open input file: %s", argv[2] );
  100. goto get_out;
  101. }
  102. strcpy( namebuffer, filebuffer );
  103. for( i = 0; i < isize; i++ )
  104. {
  105. if( namebuffer[i] == '\n' )
  106. namebuffer[i] = '\0';
  107. }
  108. namebuffer[isize + 1] = '\0';
  109. nSpaces = RemoveSpaces( filebuffer, isize );
  110. if( argc > 3 )
  111. {
  112. if( (ofile = fopen( argv[3], "w" )) != NULL )
  113. {
  114. OutputKeys( ofile, filebuffer, isize - nSpaces, namebuffer, itype );
  115. }
  116. else
  117. {
  118. printf( "Could not open output file: %s", argv[3] );
  119. goto get_out;
  120. }
  121. }
  122. else
  123. {
  124. OutputKeys( stdout, filebuffer, isize - nSpaces, namebuffer, itype );
  125. }
  126. get_out:
  127. _fcloseall();
  128. exit(0);
  129. return 0;
  130. }