source: emailtotracscript/trunk/run_email2trac.c @ 24

Last change on this file since 24 was 24, checked in by bas, 17 years ago

EmailtoTracScript?:

email2trac:

  • we can now set the default poth for the config file with configure for email2trac.py
  • Added svn keywords for all the files
  • Updated the install doc
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1/*
2        run_email2trac.c
3        Authors: Bas van der Vlies, Walter de Jong and Michel Jouvin
4        SVN Info:
5                $Id: run_email2trac.c 24 2006-01-15 12:46:09Z bas $
6
7        Only nobody can become the user www-data. Postfix uses this
8        user to start an program
9
10# Copyright (C) 2002
11#
12# This file is part of the email2trac utils
13#
14# This program is free software; you can redistribute it and/or modify it
15# under the terms of the GNU General Public License as published by the
16# Free Software Foundation; either version 2, or (at your option) any
17# later version.
18#
19# This program is distributed in the hope that it will be useful,
20# but WITHOUT ANY WARRANTY; without even the implied warranty of
21# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22# GNU General Public License for more details.
23#
24# You should have received a copy of the GNU General Public License
25# along with this program; if not, write to the Free Software
26# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
27#
28*/
29#include <stdlib.h>
30#include <unistd.h>
31#include <pwd.h>
32#include <sys/stat.h>
33#include <string.h>
34#include "run_email2trac.h"
35
36#ifndef DEBUG
37#define DEBUG 0
38#endif
39
40int main(int argc, char** argv) {
41
42  int i,j;
43  int caller = getuid();
44  int status;
45  char trac_script[255];
46  char** trac_script_args;
47  struct passwd *TRAC; 
48  struct passwd *MTA;
49  struct stat script_attrs;
50 
51  strcat(trac_script,TRAC_SCRIPT_PATH);
52  strcat(trac_script,"/");
53  strcat(trac_script,TRAC_SCRIPT_NAME);
54
55  /* First copy arguments passed to the wrapper as scripts arguments
56     after filtering out some of the possible script options */
57  trac_script_args = (char**) malloc((argc+1)*sizeof(char*));
58  trac_script_args[0] = TRAC_SCRIPT_NAME;
59  for (i=j=1; i<argc; i++) {
60    if ( (strcmp(argv[i],"--file") == 0) || 
61         (strcmp(argv[i],"-f") == 0) ) {
62      i++;
63      continue;
64    }
65   
66    trac_script_args[j] = argv[i];
67    j++;
68  }
69  trac_script_args[j] = NULL;
70
71 
72  /* Check caller */
73 
74  MTA = getpwnam(MTA_USER);
75  if ( caller !=  MTA->pw_uid ) {
76    if ( DEBUG ) printf("Invalid caller UID (%d)\n",caller);
77    return -2;     /* 254 : Invalid caller */
78  }
79 
80 
81  /* set UID/GID to Trac (or apache) user */
82  if ( TRAC = getpwnam(TRAC_USER) ) {
83    setuid(TRAC->pw_uid);
84    setgid(TRAC->pw_gid);
85  } else {
86    if ( DEBUG ) printf("Invalid Trac user (%s)\n",TRAC_USER);
87    return -3;     /* 253 : Trac user not found */
88  }
89         
90  /* Check that script exists */
91  if ( stat(trac_script,&script_attrs) ) {
92    if ( DEBUG ) printf("Script not found (%s)\n",trac_script);
93    return -4;    /* 252 : script not found */
94  }
95 
96  /* Execute script */
97  status = execv(trac_script, trac_script_args);
98  if ( DEBUG ) printf("Script %s execution failure (error=%d). Check permission and interpreter path.\n",trac_script,status);
99  return -1;     /* 255 : should never reach this point */
100
101}
102
103/* EOB */
Note: See TracBrowser for help on using the repository browser.