17 char *getpass(const char *prompt
)
19 char * (*real_getpass
)(const char *prompt
) = NULL
;
20 //warnx("intercepted \"%s\"", prompt);
22 char *getpass_pwd
= NULL
;
24 if(real_getpass
== NULL
)
26 void *handle
= dlopen("/lib/i386-linux-gnu/libc.so.6", RTLD_LAZY
);
28 errx(1, "dlopen: %s", dlerror());
29 real_getpass
= dlsym(handle
, "getpass");
30 if (real_getpass
== NULL
)
31 errx(1, "dlopen: %s", dlerror());
34 env
= getenv("CUPS_PASSWORD");
37 getpass_pwd
= malloc(PASS_MAX
);
38 strncpy(getpass_pwd
, env
, PASS_MAX
);
42 env
= getenv("CUPS_ASKPASS");
57 char *args
[3] = {NULL
, "stdin", NULL
};
60 dup2(pipe_in
[0], STDIN_FILENO
);
62 dup2(pipe_ex
[1], STDOUT_FILENO
);
63 exit(execvp(env
, args
));
69 pipe_in_1
= fdopen(pipe_in
[1], "w");
70 pipe_ex_0
= fdopen(pipe_ex
[0], "r");
72 fprintf(pipe_in_1
, "prompt=%s\nanswer=password\n", prompt
);
76 getpass_pwd
= malloc(PASS_MAX
);
77 if(fgets(getpass_pwd
, PASS_MAX
, pipe_ex_0
) == NULL
)
82 else if(getpass_pwd
[strlen(getpass_pwd
)-1] == '\n')
84 getpass_pwd
[strlen(getpass_pwd
)-1] = '\0';
88 if(waitpid(pid
, &status
, 0) != -1)
90 if(WEXITSTATUS(status
) == 0)
97 warnx("%s: %s: exited %d", __FILE__
, env
, WEXITSTATUS(status
));
102 warn("%s: waitpid", __FILE__
);
111 warn("%s: fork", __FILE__
);
116 warnx("Neither CUPS_PASSWORD or CUPS_ASKPASS are set.");
117 return real_getpass(prompt
);