summaryrefslogtreecommitdiff
path: root/checkpasswd/pathexec_run.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-06-03 01:38:28 (GMT)
committerJohn Denker <jsd@av8n.com>2012-06-03 01:38:28 (GMT)
commit78488dc84afac1398e582ae6bbaf9606d07afa1e (patch)
tree71723e916f23a6a07422587de275dece3ea60252 /checkpasswd/pathexec_run.c
parent81b5f8f3ab26a7969956faef29a90499ece40ff5 (diff)
checkpassword ... as downloaded
Diffstat (limited to 'checkpasswd/pathexec_run.c')
-rw-r--r--checkpasswd/pathexec_run.c46
1 files changed, 46 insertions, 0 deletions
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;
+ }
+}