source: emailtotracscript/trunk/run_email2trac.c @ 13

Last change on this file since 13 was 5, checked in by bas, 18 years ago

EmailtoTracScript?:

First release and import to track_hacks

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