2 * authbind.c - main invoker program
4 * authbind is Copyright (C) 1998 Ian Jackson
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)
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.
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.
30 static const char *rcsid="$Id$";
32 static void printusage(FILE *f) {
34 "usage: authbind [<options>] <program> <arg> <arg> ...\n"
35 "options: --deep --depth <levels>\n"
36 "version: " MAJOR_VER "." MINOR_VER " %s\n",
37 rcsid) == EOF) { perror("printf usage"); exit(-1); }
40 static void usageerror(const char *msg) {
41 fprintf(stderr,"usage error: %s\n",msg);
46 static void mustsetenv(const char *var, const char *val) {
47 if (setenv(var,val,1)) { perror("authbind: setenv"); exit(-1); }
50 int main(int argc, char *const *argv) {
51 const char *expreload, *authbindlib, *preload;
52 char *newpreload, *ep;
57 while (argc>1 && argv[1][0]=='-') {
59 if (!argv[0][1]) break;
60 if (!strcmp("--deep",argv[0])) { depth= 0; }
61 else if (!strcmp("--depth",argv[0])) {
62 if (argc<=1) usageerror("--depth requires a value");
64 depth= strtoul(argv[0],&ep,10);
65 if (*ep || depth<=0 || depth>100) usageerror("--depth value is not valid");
66 } else if (!strcmp("--help",argv[0]) || !strcmp("--help",argv[0])) {
71 if (argc<2) usageerror("need program name");
73 authbindlib= getenv(AUTHBINDLIB_VAR);
75 authbindlib= LIBAUTHBIND;
76 mustsetenv(AUTHBINDLIB_VAR,authbindlib);
79 if ((expreload= getenv(PRELOAD_VAR))) {
80 newpreload= malloc(strlen(expreload)+strlen(authbindlib)+2);
81 strcpy(newpreload,expreload);
82 strcat(newpreload,":");
83 strcat(newpreload,authbindlib);
88 mustsetenv(PRELOAD_VAR,preload);
91 sprintf(buf,"%ld",depth-1);
92 mustsetenv(AUTHBIND_LEVELS_VAR,buf);
93 } else if (depth == 0) {
94 mustsetenv(AUTHBIND_LEVELS_VAR,"y");
99 execvp(argv[1],argv+1);
100 perror(argv[1]); exit(-1);