From 78488dc84afac1398e582ae6bbaf9606d07afa1e Mon Sep 17 00:00:00 2001 From: John Denker Date: Sat, 2 Jun 2012 18:38:28 -0700 Subject: checkpassword ... as downloaded --- checkpasswd/pathexec_run.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 checkpasswd/pathexec_run.c (limited to 'checkpasswd/pathexec_run.c') diff --git a/checkpasswd/pathexec_run.c b/checkpasswd/pathexec_run.c new file mode 100644 index 0000000..17837eb --- /dev/null +++ b/checkpasswd/pathexec_run.c @@ -0,0 +1,46 @@ +#include "error.h" +#include "stralloc.h" +#include "str.h" +#include "env.h" +#include "pathexec.h" + +static stralloc tmp; + +void pathexec_run(char *file,char **argv,char **envp) +{ + char *path; + unsigned int split; + int savederrno; + + if (file[str_chr(file,'/')]) { + execve(file,argv,envp); + return; + } + + path = env_get("PATH"); + if (!path) path = "/bin:/usr/bin"; + + savederrno = 0; + for (;;) { + split = str_chr(path,':'); + if (!stralloc_copyb(&tmp,path,split)) return; + if (!split) + if (!stralloc_cats(&tmp,".")) return; + if (!stralloc_cats(&tmp,"/")) return; + if (!stralloc_cats(&tmp,file)) return; + if (!stralloc_0(&tmp)) return; + + execve(tmp.s,argv,envp); + if (errno != error_noent) { + savederrno = errno; + if ((errno != error_acces) && (errno != error_perm) && (errno != error_isdir)) return; + } + + if (!path[split]) { + if (savederrno) errno = savederrno; + return; + } + path += split; + path += 1; + } +} -- cgit v1.2.3