home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / ircd4652.zip / ircd-df-4.6.5-os2 / src / Config.c < prev    next >
C/C++ Source or Header  |  1997-12-28  |  13KB  |  457 lines

  1. #include <stdio.h>
  2. #include <io.h>
  3. #include <fcntl.h>
  4. #include <sys\stat.h>
  5. #include <time.h>
  6.  
  7. int _FD_SETSIZE = 1024;
  8. char _NS_ADDRESS[256], _KLINE_ADDRESS[256];
  9.  
  10. char Makefile[] =
  11. "CC=cl\n"
  12. "FD_SETSIZE=/D FD_SETSIZE=$FD_SETSIZE\n"
  13. "NS_ADDRESS=/D NS_ADDRESS=\"\\\"$NS_ADDRESS\\\"\"\n"
  14. "KLINE_ADDRESS=/D KLINE_ADDRESS=\"\\\"$KLINE_ADDRESS\\\"\"\n"
  15. "CFLAGS=/MT /O2 /I ./INCLUDE /Fosrc/ /nologo $(FD_SETSIZE) $(NS_ADDRESS) $(KLINE_ADDRESS) /D NOSPOOF=1 /c\n"
  16. "INCLUDES=./include/struct.h ./include/config.h ./include/sys.h \\\n"
  17. " ./include/common.h ./include/patchlevel.h ./include/h.h ./include/numeric.h \\\n"
  18. " ./include/msg.h ./include/setup.h\n"
  19. "LINK=link.exe\n"
  20. "LFLAGS=kernel32.lib user32.lib gdi32.lib shell32.lib wsock32.lib \\\n"
  21. " oldnames.lib libcmt.lib /nodefaultlib /nologo /out:SRC/WIRCD.EXE\n"
  22. "OBJ_FILES=SRC/CHANNEL.OBJ SRC/USERLOAD.OBJ SRC/SEND.OBJ SRC/BSD.OBJ \\\n"
  23. " SRC/CIO_MAIN.OBJ SRC/S_CONF.OBJ SRC/DBUF.OBJ SRC/RES.OBJ \\\n"
  24. " SRC/HASH.OBJ SRC/CIO_INIT.OBJ SRC/PARSE.OBJ SRC/IRCD.OBJ \\\n"
  25. " SRC/S_NUMERIC.OBJ SRC/WHOWAS.OBJ SRC/RES_COMP.OBJ SRC/S_AUTH.OBJ \\\n"
  26. " SRC/HELP.OBJ SRC/S_MISC.OBJ SRC/MATCH.OBJ SRC/CRULE.OBJ \\\n"
  27. " SRC/S_DEBUG.OBJ SRC/RES_INIT.OBJ SRC/SUPPORT.OBJ SRC/LIST.OBJ \\\n"
  28. " SRC/S_ERR.OBJ SRC/PACKET.OBJ SRC/CLASS.OBJ SRC/S_BSD.OBJ \\\n"
  29. " SRC/MD5.OBJ SRC/S_SERV.OBJ SRC/S_USER.OBJ SRC/WIN32.OBJ \\\n"
  30. " SRC/VERSION.OBJ SRC/WIN32.RES\n"
  31. "RC=rc.exe\n"
  32. "\n"
  33. "ALL: SRC/WIRCD.EXE SRC/CHKCONF.EXE\n"
  34. "        @echo Please, please REMEMBER to add those U lines!\n"
  35. "        @echo Read the file READTHIS.NOW formore info\n"
  36. "\n"
  37. "CLEAN:\n"
  38. "        -@erase src\\*.exe 2>NUL\n"
  39. "        -@erase src\\*.obj 2>NUL\n"
  40. "        -@erase src\\win32.res 2>NUL\n"
  41. "        -@erase src\\version.c 2>NUL\n"
  42. "\n"
  43. "include/setup.h:\n"
  44. "        @echo Hmm...doesn't look like you've run Config...\n"
  45. "        @echo Doing so now.\n"
  46. "        @config.exe\n"
  47. "\n"
  48. "src/version.c: dummy\n"
  49. "        @config.exe -v\n"
  50. "\n"
  51. "src/version.obj: src/version.c\n"
  52. "        $(CC) $(CFLAGS) src/version.c\n"
  53. "\n"
  54. "SRC/WIRCD.EXE: $(OBJ_FILES) src/version.obj\n"
  55. "        $(LINK) $(LFLAGS) $(OBJ_FILES)\n"
  56. "\n"
  57. "SRC/CHKCONF.EXE: ./include/struct.h ./include/config.h ./include/sys.h \\\n"
  58. "                 ./include/common.h ./src/crule.c ./src/match.c ./src/chkconf.c\n"
  59. "        $(CC) /nologo /I ./include /D CR_CHKCONF /Fosrc/chkcrule.obj /c src/crule.c\n"
  60. "        $(CC) /nologo /I ./include /D CR_CHKCONF /Fosrc/chkmatch.obj /c src/match.c\n"
  61. "        $(CC) /nologo /I ./include /D CR_CHKCONF /Fosrc/chkconf.obj /c src/chkconf.c\n"
  62. "        $(LINK) /nologo /out:src/chkconf.exe src/chkconf.obj src/chkmatch.obj \\\n"
  63. "                src/chkcrule.obj\n"
  64. "\n"
  65. "src/parse.obj: src/parse.c $(INCLUDES)\n"
  66. "        $(CC) $(CFLAGS) src/parse.c\n"
  67. "\n"
  68. "src/bsd.obj: src/bsd.c $(INCLUDES)\n"
  69. "        $(CC) $(CFLAGS) src/bsd.c\n"
  70. "\n"
  71. "src/dbuf.obj: src/dbuf.c $(INCLUDES) ./include/dbuf.h\n"
  72. "        $(CC) $(CFLAGS) src/dbuf.c\n"
  73. "\n"
  74. "src/packet.obj: src/packet.c $(INCLUDES)\n"
  75. "        $(CC) $(CFLAGS) src/packet.c\n"
  76. "\n"
  77. "src/send.obj: src/send.c $(INCLUDES)\n"
  78. "        $(CC) $(CFLAGS) src/send.c\n"
  79. "\n"
  80. "src/match.obj: src/match.c $(INCLUDES)\n"
  81. "        $(CC) $(CFLAGS) src/match.c\n"
  82. "\n"
  83. "src/support.obj: src/support.c $(INCLUDES)\n"
  84. "        $(CC) $(CFLAGS) src/support.c\n"
  85. "\n"
  86. "src/channel.obj: src/channel.c $(INCLUDES) ./include/channel.h\n"
  87. "        $(CC) $(CFLAGS) src/channel.c\n"
  88. "\n"
  89. "src/class.obj: src/class.c $(INCLUDES) ./include/class.h\n"
  90. "        $(CC) $(CFLAGS) src/class.c\n"
  91. "\n"
  92. "src/ircd.obj: src/ircd.c $(INCLUDES)\n"
  93. "        $(CC) $(CFLAGS) src/ircd.c\n"
  94. "\n"
  95. "src/list.obj: src/list.c $(INCLUDES)\n"
  96. "        $(CC) $(CFLAGS) src/list.c\n"
  97. "\n"
  98. "src/res.obj: src/res.c $(INCLUDES)\n"
  99. "        $(CC) $(CFLAGS) src/res.c\n"
  100. "\n"
  101. "src/s_bsd.obj: src/s_bsd.c $(INCLUDES)\n"
  102. "        $(CC) $(CFLAGS) src/s_bsd.c\n"
  103. "\n"
  104. "src/s_auth.obj: src/s_auth.c $(INCLUDES)\n"
  105. "        $(CC) $(CFLAGS) src/s_auth.c\n"
  106. "\n"
  107. "src/s_conf.obj: src/s_conf.c $(INCLUDES)\n"
  108. "        $(CC) $(CFLAGS) src/s_conf.c\n"
  109. "\n"
  110. "src/s_debug.obj: src/s_debug.c $(INCLUDES)\n"
  111. "        $(CC) $(CFLAGS) src/s_debug.c\n"
  112. "\n"
  113. "src/s_err.obj: src/s_err.c $(INCLUDES)\n"
  114. "        $(CC) $(CFLAGS) src/s_err.c\n"
  115. "\n"
  116. "src/s_misc.obj: src/s_misc.c $(INCLUDES) ./include/dbuf.h\n"
  117. "        $(CC) $(CFLAGS) src/s_misc.c\n"
  118. "\n"
  119. "src/s_user.obj: src/s_user.c $(INCLUDES) ./include/dbuf.h \\\n"
  120. "                ./include/channel.h ./include/whowas.h\n"
  121. "        $(CC) $(CFLAGS) src/s_user.c\n"
  122. "\n"
  123. "src/s_serv.obj: src/s_serv.c $(INCLUDES) ./include/dbuf.h ./include/whowas.h\n"
  124. "        $(CC) $(CFLAGS) src/s_serv.c\n"
  125. "\n"
  126. "src/s_numeric.obj: src/s_numeric.c $(INCLUDES) ./include/dbuf.h\n"
  127. "        $(CC) $(CFLAGS) src/s_numeric.c\n"
  128. "\n"
  129. "src/whowas.obj: src/whowas.c $(INCLUDES) ./include/dbuf.h ./include/whowas.h\n"
  130. "        $(CC) $(CFLAGS) src/whowas.c\n"
  131. "\n"
  132. "src/hash.obj: src/hash.c $(INCLUDES) ./include/hash.h\n"
  133. "        $(CC) $(CFLAGS) src/hash.c\n"
  134. "\n"
  135. "src/crule.obj: src/crule.c $(INCLUDES)\n"
  136. "        $(CC) $(CFLAGS) src/crule.c\n"
  137. "\n"
  138. "src/win32.obj: src/win32.c $(INCLUDES) ./include/resource.h\n"
  139. "        $(CC) $(CFLAGS) src/win32.c\n"
  140. "\n"
  141. "src/cio_main.obj: src/cio_main.c $(INCLUDES) ./include/cio.h ./include/ciofunc.h\n"
  142. "        $(CC) $(CFLAGS) src/cio_main.c\n"
  143. "\n"
  144. "src/cio_init.obj: src/cio_init.c $(INCLUDES) ./include/cio.h ./include/ciofunc.h\n"
  145. "        $(CC) $(CFLAGS) src/cio_init.c\n"
  146. "\n"
  147. "src/res_comp.obj: src/res_comp.c $(INCLUDES)\n"
  148. "        $(CC) $(CFLAGS) src/res_comp.c\n"
  149. "\n"
  150. "src/res_init.obj: src/res_init.c $(INCLUDES)\n"
  151. "        $(CC) $(CFLAGS) src/res_init.c\n"
  152. "\n"
  153. "src/help.obj: src/help.c $(INCLUDES)\n"
  154. "        $(CC) $(CFLAGS) src/help.c\n"
  155. "\n"
  156. "src/md5.obj: src/md5.c $(INCLUDES)\n"
  157. "        $(CC) $(CFLAGS) src/md5.c\n"
  158. "\n"
  159. "src/win32.res: src/win32.rc\n"
  160. "        $(RC) /l 0x409 /fosrc/win32.res /i ./include /i ./src \\\n"
  161. "              /d NDEBUG src/win32.rc\n"
  162. "\n"
  163. "dummy:\n"
  164. "\n";
  165.  
  166.  
  167. char SetupH[] =
  168. "#ifndef __setup_include__\n"
  169. "#define __setup_include__\n"
  170. "#undef  PARAMH\n"
  171. "#undef  UNISTDH\n"
  172. "#define STRINGH\n"
  173. "#undef  STRINGSH\n"
  174. "#define STDLIBH\n"
  175. "#undef  STDDEFH\n"
  176. "#undef  SYSSYSLOGH\n"
  177. "#define NOINDEX\n"
  178. "#define NOBCOPY\n"
  179. "#define NEED_STRERROR\n"
  180. "#define NEED_STRTOKEN\n"
  181. "#undef  NEED_STRTOK\n"
  182. "#undef  NEED_INET_ADDR\n"
  183. "#undef  NEED_INET_NTOA\n"
  184. "#define NEED_INET_NETOF\n"
  185. "#define GETTIMEOFDAY\n"
  186. "#undef  LRAND48\n"
  187. "#define MALLOCH <malloc.h>\n"
  188. "#undef  NBLOCK_POSIX\n"
  189. "#undef  POSIX_SIGNALS\n"
  190. "#undef  TIMES_2\n"
  191. "#undef  GETRUSAGE_2\n"
  192. "\n"
  193. "#define NO_U_TYPES\n"
  194. "#define NEED_U_INT32_T\n"
  195. "#endif\n";
  196.  
  197.  
  198.  
  199. int     main(int argc, char *argv[])
  200. {
  201.     if (argc>1)
  202.         {
  203.         if (!strcmp(argv[1], "-v"))
  204.             return do_version();
  205.  
  206.         if (!strcmp(argv[1], "-n"))
  207.             return do_config(1);
  208.         }
  209.  
  210.     return do_config(0);
  211. }
  212.  
  213.  
  214. int     do_config(int autoconf)
  215. {
  216.     int     fd;
  217.     char    str[128];
  218.  
  219.  
  220.     if ((fd = open("include\\setup.h", O_CREAT|O_TRUNC|O_WRONLY|O_TEXT,
  221.                S_IREAD|S_IWRITE)) == -1)
  222.         printf("Error opening include\\setup.h\n\r");
  223.     else
  224.         {
  225.         write(fd, SetupH, strlen(SetupH));
  226.         close(fd);
  227.         }
  228.  
  229.     while (1)
  230.         {
  231.         /*
  232.          * FD_SETSIZE
  233.          */
  234.         printf("\n");
  235.         printf("How many file descriptors (or sockets) can the irc server use?");
  236.         printf("\n");
  237.         printf("[%d] -> ", _FD_SETSIZE);
  238.         gets(str);
  239.         if (*str != '\n' && *str != '\r')
  240.             sscanf(str, "%d", &_FD_SETSIZE);
  241.  
  242.         if (_FD_SETSIZE >= 100)
  243.             {
  244.             printf("\n");
  245.             printf("FD_SETSIZE will be overridden using -D "
  246.                    "FD_SETSIZE=%d when compiling ircd.", _FD_SETSIZE);
  247.             printf("\n");
  248.             break;
  249.             }
  250.         printf("\n");
  251.         printf("You need to enter a number here, greater or equal to 100.\n");
  252.         }
  253.  
  254.     while (1)
  255.         {
  256.         /*
  257.          * NS_ADDRESS
  258.          */
  259.         printf("\n");
  260.         printf("What is the contact address for connect problems due to the\n\r");
  261.         printf("anti-spoof system, shown to the user when they connect?\n\r");
  262.         printf("For DALnet, this is nospoof@dal.net.  If your server is not\n\r");
  263.         printf("part of DALnet, please choose some other email address.\n\r");
  264.         printf("\n");
  265.         printf("[] -> ");
  266.         gets(str);
  267.         if (*str != '\n' && *str != '\r')
  268.             {
  269.             sscanf(str, "%s", _NS_ADDRESS);
  270.             break;
  271.             }
  272.  
  273.         printf("\n");
  274.         printf("You must enter a valid e-mail address.\n");
  275.         }
  276.  
  277.     while (1)
  278.         {
  279.         /*
  280.          * KLINE_ADDRESS
  281.          */
  282.         printf("\n");
  283.         printf("What is the contact address for connect problems due to the\n\r");
  284.         printf("user being K:lined, shown to the user when they attempt to\n\r");
  285.         printf("connect?  This should be a valid email address.\n\r");
  286.         printf("\n\r");
  287.         printf("For DALnet servers, note that this message is displayed when\n\r");
  288.         printf("the user is affected by a local K:line or k:line.  With\n\r");
  289.         printf("Services-based autokills, the message is set up automatically\n\r");
  290.         printf("by Services to ask the user to email kline@dal.net.  It is\n\r");
  291.         printf("recommended that you set this up to give a valid email address\n\r");
  292.         printf("for the server's admin, not kline@dal.net.\n\r");
  293.         printf("\n");
  294.         printf("[] -> ");
  295.         gets(str);
  296.         if (*str != '\n' && *str != '\r')
  297.             {
  298.             sscanf(str, "%s", _KLINE_ADDRESS);
  299.             if (stricmp(_KLINE_ADDRESS, "kline@dal.net"))
  300.                 break;
  301.             printf("Please note that kline@dal.net does not handle server-specific\n\r");
  302.             printf("K:lines.\n\r");
  303.             printf("Are you sure you want to set the address to kline@dal.net?\n\r");
  304.             printf("[No] -> ");
  305.             gets(str);
  306.             if (*str == 'y' || *str == 'Y')
  307.                 break;
  308.             }
  309.  
  310.         printf("\n");
  311.         printf("You must enter a valid e-mail address.\n");
  312.         }
  313.  
  314.     /*
  315.      * Now write the makefile out.
  316.      */
  317.     write_makefile();
  318.  
  319.     return 0;
  320. }
  321.  
  322.  
  323. int     write_makefile(void)
  324. {
  325.     int     fd, makfd, len;
  326.     char    *buffer, *s;
  327.  
  328.     buffer = (char *)malloc(strlen(Makefile)+4096);
  329.     memcpy(buffer, Makefile, strlen(Makefile)+1);
  330.  
  331.     s = (char *)strstr(buffer, "$FD_SETSIZE");
  332.     if (s)
  333.         {
  334.         itoa(_FD_SETSIZE, s, 10);
  335.         memmove(s+strlen(s), s+11, strlen(s+11)+1);
  336.         }
  337.  
  338.     s = (char *)strstr(buffer, "$NS_ADDRESS");
  339.     if (s)
  340.         {
  341.         memmove(s+strlen(_NS_ADDRESS), s+11, strlen(s+11)+1);
  342.         memmove(s, _NS_ADDRESS, strlen(_NS_ADDRESS));
  343.         }
  344.  
  345.     s = (char *)strstr(buffer, "$KLINE_ADDRESS");
  346.     if (s)
  347.         {
  348.         memmove(s+strlen(_KLINE_ADDRESS), s+14, strlen(s+14)+1);
  349.         memmove(s, _KLINE_ADDRESS, strlen(_KLINE_ADDRESS));
  350.         }
  351.  
  352.     if ((makfd = open("Makefile", O_CREAT|O_TRUNC|O_WRONLY|O_TEXT,
  353.                S_IREAD|S_IWRITE)) == -1)
  354.         {
  355.         printf("Error creating Makefile\n\r");
  356.         return 1;
  357.         }
  358.     write(makfd, buffer, strlen(buffer));
  359.     close(makfd);
  360.  
  361.     free(buffer);
  362.     return 0;
  363. }
  364.  
  365.  
  366. int     do_version(void)
  367. {
  368.     int     fd, verfd, generation=0, len, doingvernow=0;
  369.     char    buffer[16384], *s;
  370.  
  371.     if ((verfd = open("src\\version.c", O_RDONLY | O_TEXT)) != -1)
  372.         {
  373.         while (!eof(verfd))
  374.             {
  375.             len = read(verfd, buffer, sizeof(buffer)-1);
  376.             if (len == -1)
  377.                 break;
  378.             buffer[len] = 0;
  379.             s = (char *)strstr(buffer, "char *generation = \"");
  380.             if (s)
  381.                 {
  382.                 s += 20;
  383.                 generation = atoi(s);
  384.                 break;
  385.                 }
  386.             }
  387.  
  388.             close(verfd);
  389.         }
  390.  
  391.     if ((fd = open("src\\version.c.SH", O_RDONLY | O_TEXT)) == -1)
  392.         {
  393.         printf("Error opening src\\version.c.SH\n\r");
  394.         return 1;
  395.         }
  396.  
  397.     if ((verfd = open("src\\version.c", O_CREAT|O_TRUNC|O_WRONLY|O_TEXT,
  398.                S_IREAD|S_IWRITE)) == -1)
  399.         {
  400.         printf("Error opening src\\version.c\n\r");
  401.         return 1;
  402.         }
  403.  
  404.     generation++;
  405.  
  406.     printf("Extracting IRC/ircd/version.c...\n\r");
  407.  
  408.     while (!eof(fd))
  409.         {
  410.         len = read(fd, buffer, sizeof(buffer)-1);
  411.         if (len == -1)
  412.             break;
  413.         buffer[len] = 0;
  414.         if (!doingvernow)
  415.             {
  416.             s = (char *)strstr(buffer, "/*");
  417.             if (!s)
  418.                 continue;
  419.             memmove(buffer, s, strlen(s)+1);
  420.             doingvernow=1;
  421.             }
  422.         s = (char *)strstr(buffer, "$generation");
  423.         if (s)
  424.             {
  425.             itoa(generation, s, 10);
  426.             memmove(s+strlen(s), s+11, strlen(s+11)+1);
  427.             }
  428.         s = (char *)strstr(buffer, "$creation");
  429.         if (s)
  430.             {
  431.             time_t  t = time(0);
  432.             char    *ct = ctime(&t);
  433.  
  434.             memmove(s+strlen(ct)-1, s+9, strlen(s+9)+1);
  435.             memmove(s, ct, strlen(ct)-1);
  436.             }
  437.         s = (char *)strstr(buffer, "$package");
  438.         if (s)
  439.             {
  440.             memmove(s, "IRC", 3);
  441.             memmove(s+3, s+8, strlen(s+8)+1);
  442.             }
  443.  
  444.         s = (char *)strstr(buffer, "!SUB!THIS!");
  445.         if (s)
  446.             *s = 0;
  447.  
  448.         write(verfd, buffer, strlen(buffer));
  449.         }
  450.  
  451.     close(fd);
  452.     close(verfd);
  453.     return 0;
  454. }
  455.  
  456.  
  457.