summaryrefslogtreecommitdiffstats
path: root/ldap/clients/orgchart/wrapper.c
blob: 1cead680cd9504a03ecfa7d67fc492245f070623 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/***********************************************************************
** Copyright 1996 - Netscape Communications Corporation
**
** Contact:	Fred Cox <flc@netscape.com>
**
** Name: perl.c
***********************************************************************/

/***********************************************************************
** Includes
***********************************************************************/

#include	<stdlib.h>
#include	<limits.h>
#include	<string.h>
#include <sys/types.h>
#include <sys/stat.h>

/*#include "libadmin/libadmin.h"*/

#ifdef XP_UNIX
#include	<unistd.h>
#define PERL "../../bin/slapd/admin/bin/perl"
#define PATH_SEP '/'
#ifndef PATH_MAX
#define PATH_MAX 512
#endif
#else
#include	<direct.h>
#include	<process.h>
#define PERL "..\\..\\bin\\slapd\\admin\\bin\\perl.exe"
#define PATH_SEP '\\'
#define PATH_MAX 512
#endif

char *get_perl_file(char *);


/*
 * Use environment to figure out what admin perl script to execute
 */

void
main( int argc, char **argv )
{
  char	script[PATH_MAX];
  struct stat statbuf;

  printf("Content-type:text/html;charset=UTF-8\n\n<html>Hi\n");

  get_perl_file(script);
  
  if (strchr(script, '/') != NULL || strchr(script, '\\') != NULL) {
    printf("Paths not allowed. Filenames only.\n");
    exit(0);
  }

  printf("<br>script:%s</html>\n", script);
  if (stat(script, &statbuf) != 0) {
    printf("Can't find %s\n", script);
    exit(0);
  }

  execl( PERL, script, script, 0 );
}

char *
get_perl_file(char *script) {
  char *qs = getenv("QUERY_STRING");
  char *p1 = NULL;
  char *p2 = NULL;
  
  if (qs == NULL || *qs == '\0') {
    printf("No QUERY_STRING found\n");
    exit(0);
  }
  p1 = strstr(qs, "file=");
  if (p1 == NULL) {
    printf("No file variable in QUERY_STRING found.\n");
    exit(0);
  }

  p1 += 5;

  for (p2 = p1; *p2 != '\0' && *p2 != '&'; p2++);

  strncpy(script, p1, p2-p1);
  script[p2-p1] = '\0';
}