wrapper.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* --- BEGIN COPYRIGHT BLOCK ---
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2005 Red Hat, Inc.
  35. * All rights reserved.
  36. * --- END COPYRIGHT BLOCK --- */
  37. /***********************************************************************
  38. ** Includes
  39. ***********************************************************************/
  40. #include <stdlib.h>
  41. #include <limits.h>
  42. #include <string.h>
  43. #include <sys/types.h>
  44. #include <sys/stat.h>
  45. /*#include "libadmin/libadmin.h"*/
  46. #ifdef XP_UNIX
  47. #include <unistd.h>
  48. #define PERL "../../bin/slapd/admin/bin/perl"
  49. #define PATH_SEP '/'
  50. #ifndef PATH_MAX
  51. #define PATH_MAX 512
  52. #endif
  53. #else
  54. #include <direct.h>
  55. #include <process.h>
  56. #define PERL "..\\..\\bin\\slapd\\admin\\bin\\perl.exe"
  57. #define PATH_SEP '\\'
  58. #define PATH_MAX 512
  59. #endif
  60. char *get_perl_file(char *);
  61. /*
  62. * Use environment to figure out what admin perl script to execute
  63. */
  64. void
  65. main( int argc, char **argv )
  66. {
  67. char script[PATH_MAX];
  68. struct stat statbuf;
  69. printf("Content-type:text/html;charset=UTF-8\n\n<html>Hi\n");
  70. get_perl_file(script);
  71. if (strchr(script, '/') != NULL || strchr(script, '\\') != NULL) {
  72. printf("Paths not allowed. Filenames only.\n");
  73. exit(0);
  74. }
  75. printf("<br>script:%s</html>\n", script);
  76. if (stat(script, &statbuf) != 0) {
  77. printf("Can't find %s\n", script);
  78. exit(0);
  79. }
  80. execl( PERL, script, script, 0 );
  81. }
  82. char *
  83. get_perl_file(char *script) {
  84. char *qs = getenv("QUERY_STRING");
  85. char *p1 = NULL;
  86. char *p2 = NULL;
  87. if (qs == NULL || *qs == '\0') {
  88. printf("No QUERY_STRING found\n");
  89. exit(0);
  90. }
  91. p1 = strstr(qs, "file=");
  92. if (p1 == NULL) {
  93. printf("No file variable in QUERY_STRING found.\n");
  94. exit(0);
  95. }
  96. p1 += 5;
  97. for (p2 = p1; *p2 != '\0' && *p2 != '&'; p2++);
  98. strncpy(script, p1, p2-p1);
  99. script[p2-p1] = '\0';
  100. }