chiark / gitweb /
Do not use ports >512 even if configured. (rshd)
[authbind.git] / authbind.c
1 /*
2  *  authbind.c - main invoker program
3  *
4  *  authbind is Copyright (C) 1998 Ian Jackson
5  * 
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  * 
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  * 
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software Foundation,
18  *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
19  * 
20  */
21
22 #include <stdlib.h>
23 #include <string.h>
24 #include <stdio.h>
25 #include <unistd.h>
26
27 static const char *rcsid="$Id$";
28
29 #ifndef LIBAUTHBIND
30 # define "/usr/local/lib/authbind/libauthbind.so." MAJOR_VER
31 #endif
32
33 #define PRELOAD_VAR "LD_PRELOAD"
34 #define AUTHBINDLIB_VAR "AUTHBIND_LIB"
35
36 int main(int argc, char *const *argv) {
37   const char *expreload, *authbindlib, *preload;
38   char *newpreload;
39
40   if (argc<2 || argv[1][0]=='-') {
41     fprintf(stderr,"authbind: usage: authbind program arg arg ...\n %s\n",rcsid);
42     exit(-1);
43   }
44
45   authbindlib= getenv(AUTHBINDLIB_VAR);
46   if (!authbindlib) authbindlib= LIBAUTHBIND;
47     
48   if ((expreload= getenv(PRELOAD_VAR))) {
49     newpreload= malloc(strlen(expreload)+strlen(authbindlib)+2);
50     strcpy(newpreload,expreload);
51     strcat(newpreload,":");
52     strcat(newpreload,authbindlib);
53     preload= newpreload;
54   } else {
55     preload= authbindlib;
56   }
57   if (setenv(PRELOAD_VAR,preload,1)) { perror("authbind: setenv"); exit(-1); }
58
59   execvp(argv[1],argv+1);
60   perror(argv[1]); exit(-1);
61 }